Skip to content

Commit 1868216

Browse files
makelinuxrostedt
authored andcommitted
rtla: Set distinctive exit value for failed tests
A test is considered failed when a sample trace exceeds the threshold. Failed tests return the same exit code as passed tests, requiring test frameworks to determine the result by searching for "hit stop tracing" in the output. Assign a distinct exit code for failed tests to enable the use of shell expressions and seamless integration with testing frameworks without the need to parse output. Add enum type for return value. Update `make check`. Cc: Daniel Bristot de Oliveira <bristot@kernel.org> Cc: John Kacur <jkacur@redhat.com> Cc: "Luis Claudio R. Goncalves" <lgoncalv@redhat.com> Cc: Eder Zulian <ezulian@redhat.com> Cc: Dan Carpenter <dan.carpenter@linaro.org> Cc: Jan Stancek <jstancek@redhat.com> Link: https://lore.kernel.org/20250417185757.2194541-1-costa.shul@redhat.com Signed-off-by: Costa Shulyupin <costa.shul@redhat.com> Reviewed-by: Tomas Glozar <tglozar@redhat.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 92a09c4 commit 1868216

File tree

9 files changed

+34
-21
lines changed

9 files changed

+34
-21
lines changed

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ int osnoise_hist_main(int argc, char *argv[])
766766
struct osnoise_params *params;
767767
struct osnoise_tool *record = NULL;
768768
struct osnoise_tool *tool = NULL;
769+
enum result return_value = ERROR;
769770
struct trace_instance *trace;
770-
int return_value = 1;
771771
int retval;
772772

773773
params = osnoise_hist_parse_args(argc, argv);
@@ -889,12 +889,13 @@ int osnoise_hist_main(int argc, char *argv[])
889889

890890
osnoise_print_stats(params, tool);
891891

892-
return_value = 0;
892+
return_value = PASSED;
893893

894894
if (osnoise_trace_is_off(tool, record)) {
895895
printf("rtla osnoise hit stop tracing\n");
896896
save_trace_to_file(record ? record->trace.inst : NULL,
897897
params->trace_output);
898+
return_value = FAILED;
898899
}
899900

900901
out_hist:

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ int osnoise_top_main(int argc, char **argv)
594594
struct osnoise_params *params;
595595
struct osnoise_tool *record = NULL;
596596
struct osnoise_tool *tool = NULL;
597+
enum result return_value = ERROR;
597598
struct trace_instance *trace;
598-
int return_value = 1;
599599
int retval;
600600

601601
params = osnoise_top_parse_args(argc, argv);
@@ -715,12 +715,13 @@ int osnoise_top_main(int argc, char **argv)
715715

716716
osnoise_print_stats(params, tool);
717717

718-
return_value = 0;
718+
return_value = PASSED;
719719

720720
if (osnoise_trace_is_off(tool, record)) {
721721
printf("osnoise hit stop tracing\n");
722722
save_trace_to_file(record ? record->trace.inst : NULL,
723723
params->trace_output);
724+
return_value = FAILED;
724725
}
725726

726727
out_top:

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,11 @@ int timerlat_hist_main(int argc, char *argv[])
11411141
struct timerlat_params *params;
11421142
struct osnoise_tool *record = NULL;
11431143
struct timerlat_u_params params_u;
1144+
enum result return_value = ERROR;
11441145
struct osnoise_tool *tool = NULL;
11451146
struct osnoise_tool *aa = NULL;
11461147
struct trace_instance *trace;
11471148
int dma_latency_fd = -1;
1148-
int return_value = 1;
11491149
pthread_t timerlat_u;
11501150
int retval;
11511151
int nr_cpus, i;
@@ -1378,7 +1378,7 @@ int timerlat_hist_main(int argc, char *argv[])
13781378

13791379
timerlat_print_stats(params, tool);
13801380

1381-
return_value = 0;
1381+
return_value = PASSED;
13821382

13831383
if (osnoise_trace_is_off(tool, record) && !stop_tracing) {
13841384
printf("rtla timerlat hit stop tracing\n");
@@ -1388,6 +1388,7 @@ int timerlat_hist_main(int argc, char *argv[])
13881388

13891389
save_trace_to_file(record ? record->trace.inst : NULL,
13901390
params->trace_output);
1391+
return_value = FAILED;
13911392
}
13921393

13931394
out_hist:

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,12 +985,12 @@ int timerlat_top_main(int argc, char *argv[])
985985
struct timerlat_params *params;
986986
struct osnoise_tool *record = NULL;
987987
struct timerlat_u_params params_u;
988+
enum result return_value = ERROR;
988989
struct osnoise_tool *top = NULL;
989990
struct osnoise_tool *aa = NULL;
990991
struct trace_instance *trace;
991992
int dma_latency_fd = -1;
992993
pthread_t timerlat_u;
993-
int return_value = 1;
994994
char *max_lat;
995995
int retval;
996996
int nr_cpus, i;
@@ -1197,7 +1197,7 @@ int timerlat_top_main(int argc, char *argv[])
11971197

11981198
timerlat_print_stats(params, top);
11991199

1200-
return_value = 0;
1200+
return_value = PASSED;
12011201

12021202
if (osnoise_trace_is_off(top, record) && !stop_tracing) {
12031203
printf("rtla timerlat hit stop tracing\n");
@@ -1207,6 +1207,7 @@ int timerlat_top_main(int argc, char *argv[])
12071207

12081208
save_trace_to_file(record ? record->trace.inst : NULL,
12091209
params->trace_output);
1210+
return_value = FAILED;
12101211
} else if (params->aa_only) {
12111212
/*
12121213
* If the trace did not stop with --aa-only, at least print the

tools/tracing/rtla/src/utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ int auto_house_keeping(cpu_set_t *monitored_cpus);
8383

8484
#define ns_to_usf(x) (((double)x/1000))
8585
#define ns_to_per(total, part) ((part * 100) / (double)total)
86+
87+
enum result {
88+
PASSED = 0, /* same as EXIT_SUCCESS */
89+
ERROR = 1, /* same as EXIT_FAILURE, an error in arguments */
90+
FAILED = 2, /* test hit the stop tracing condition */
91+
};

tools/tracing/rtla/tests/engine.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ reset_osnoise() {
3939
}
4040

4141
check() {
42+
expected_exitcode=${3:-0}
4243
# Simple check: run rtla with given arguments and test exit code.
4344
# If TEST_COUNT is set, run the test. Otherwise, just count.
4445
ctr=$(($ctr + 1))
@@ -49,7 +50,7 @@ check() {
4950
# Run rtla; in case of failure, include its output as comment
5051
# in the test results.
5152
result=$(stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
52-
if [ $exitcode -eq 0 ]
53+
if [ $exitcode -eq $expected_exitcode ]
5354
then
5455
echo "ok $ctr - $1"
5556
else
@@ -68,12 +69,14 @@ check_with_osnoise_options() {
6869
# Save original arguments
6970
arg1=$1
7071
arg2=$2
72+
arg3=$3
7173

7274
# Apply osnoise options (if not dry run)
7375
if [ -n "$TEST_COUNT" ]
7476
then
7577
[ "$NO_RESET_OSNOISE" == 1 ] || reset_osnoise
7678
shift
79+
shift
7780
while shift
7881
do
7982
[ "$1" == "" ] && continue
@@ -84,7 +87,7 @@ check_with_osnoise_options() {
8487
done
8588
fi
8689

87-
NO_RESET_OSNOISE=1 check "$arg1" "$arg2"
90+
NO_RESET_OSNOISE=1 check "$arg1" "$arg2" "$arg3"
8891
}
8992

9093
set_timeout() {

tools/tracing/rtla/tests/hwnoise.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ check "verify help page" \
1010
check "detect noise higher than one microsecond" \
1111
"hwnoise -c 0 -T 1 -d 5s -q"
1212
check "set the automatic trace mode" \
13-
"hwnoise -a 5 -d 30s"
13+
"hwnoise -a 5 -d 30s" 2
1414
check "set scheduling param to the osnoise tracer threads" \
1515
"hwnoise -P F:1 -c 0 -r 900000 -d 1M -q"
1616
check "stop the trace if a single sample is higher than 1 us" \
17-
"hwnoise -s 1 -T 1 -t -d 30s"
17+
"hwnoise -s 1 -T 1 -t -d 30s" 2
1818
check "enable a trace event trigger" \
1919
"hwnoise -t -e osnoise:irq_noise trigger=\"hist:key=desc,duration:sort=desc,duration:vals=hitcount\" -d 1m"
2020

tools/tracing/rtla/tests/osnoise.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ check "verify help page" \
1010
check "verify the --priority/-P param" \
1111
"osnoise top -P F:1 -c 0 -r 900000 -d 1M -q"
1212
check "verify the --stop/-s param" \
13-
"osnoise top -s 30 -T 1 -t"
13+
"osnoise top -s 30 -T 1 -t" 2
1414
check "verify the --trace param" \
15-
"osnoise hist -s 30 -T 1 -t"
15+
"osnoise hist -s 30 -T 1 -t" 2
1616
check "verify the --entries/-E param" \
1717
"osnoise hist -P F:1 -c 0 -r 900000 -d 1M -b 10 -E 25"
1818

1919
# Test setting default period by putting an absurdly high period
2020
# and stopping on threshold.
2121
# If default period is not set, this will time out.
2222
check_with_osnoise_options "apply default period" \
23-
"osnoise hist -s 1" period_us=600000000
23+
"osnoise hist -s 1" 2 period_us=600000000
2424

2525
test_end

tools/tracing/rtla/tests/timerlat.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ export RTLA_NO_BPF=$option
2121
check "verify help page" \
2222
"timerlat --help"
2323
check "verify -s/--stack" \
24-
"timerlat top -s 3 -T 10 -t"
24+
"timerlat top -s 3 -T 10 -t" 2
2525
check "verify -P/--priority" \
2626
"timerlat top -P F:1 -c 0 -d 1M -q"
2727
check "test in nanoseconds" \
28-
"timerlat top -i 2 -c 0 -n -d 30s"
28+
"timerlat top -i 2 -c 0 -n -d 30s" 2
2929
check "set the automatic trace mode" \
30-
"timerlat top -a 5 --dump-tasks"
30+
"timerlat top -a 5 --dump-tasks" 2
3131
check "print the auto-analysis if hits the stop tracing condition" \
32-
"timerlat top --aa-only 5"
32+
"timerlat top --aa-only 5" 2
3333
check "disable auto-analysis" \
34-
"timerlat top -s 3 -T 10 -t --no-aa"
34+
"timerlat top -s 3 -T 10 -t --no-aa" 2
3535
check "verify -c/--cpus" \
3636
"timerlat hist -c 0 -d 30s"
3737
check "hist test in nanoseconds" \
38-
"timerlat hist -i 2 -c 0 -n -d 30s"
38+
"timerlat hist -i 2 -c 0 -n -d 30s" 2
3939
done
4040

4141
test_end

0 commit comments

Comments
 (0)