struct osnoise_params *params;
        struct osnoise_tool *record = NULL;
        struct osnoise_tool *tool = NULL;
+       enum result return_value = ERROR;
        struct trace_instance *trace;
-       int return_value = 1;
        int retval;
 
        params = osnoise_hist_parse_args(argc, argv);
 
        osnoise_print_stats(params, tool);
 
-       return_value = 0;
+       return_value = PASSED;
 
        if (osnoise_trace_is_off(tool, record)) {
                printf("rtla osnoise hit stop tracing\n");
                save_trace_to_file(record ? record->trace.inst : NULL,
                                   params->trace_output);
+               return_value = FAILED;
        }
 
 out_hist:
 
        struct osnoise_params *params;
        struct osnoise_tool *record = NULL;
        struct osnoise_tool *tool = NULL;
+       enum result return_value = ERROR;
        struct trace_instance *trace;
-       int return_value = 1;
        int retval;
 
        params = osnoise_top_parse_args(argc, argv);
 
        osnoise_print_stats(params, tool);
 
-       return_value = 0;
+       return_value = PASSED;
 
        if (osnoise_trace_is_off(tool, record)) {
                printf("osnoise hit stop tracing\n");
                save_trace_to_file(record ? record->trace.inst : NULL,
                                   params->trace_output);
+               return_value = FAILED;
        }
 
 out_top:
 
        struct timerlat_params *params;
        struct osnoise_tool *record = NULL;
        struct timerlat_u_params params_u;
+       enum result return_value = ERROR;
        struct osnoise_tool *tool = NULL;
        struct osnoise_tool *aa = NULL;
        struct trace_instance *trace;
        int dma_latency_fd = -1;
-       int return_value = 1;
        pthread_t timerlat_u;
        int retval;
        int nr_cpus, i;
 
        timerlat_print_stats(params, tool);
 
-       return_value = 0;
+       return_value = PASSED;
 
        if (osnoise_trace_is_off(tool, record) && !stop_tracing) {
                printf("rtla timerlat hit stop tracing\n");
 
                save_trace_to_file(record ? record->trace.inst : NULL,
                                   params->trace_output);
+               return_value = FAILED;
        }
 
 out_hist:
 
        struct timerlat_params *params;
        struct osnoise_tool *record = NULL;
        struct timerlat_u_params params_u;
+       enum result return_value = ERROR;
        struct osnoise_tool *top = NULL;
        struct osnoise_tool *aa = NULL;
        struct trace_instance *trace;
        int dma_latency_fd = -1;
        pthread_t timerlat_u;
-       int return_value = 1;
        char *max_lat;
        int retval;
        int nr_cpus, i;
 
        timerlat_print_stats(params, top);
 
-       return_value = 0;
+       return_value = PASSED;
 
        if (osnoise_trace_is_off(top, record) && !stop_tracing) {
                printf("rtla timerlat hit stop tracing\n");
 
                save_trace_to_file(record ? record->trace.inst : NULL,
                                   params->trace_output);
+               return_value = FAILED;
        } else if (params->aa_only) {
                /*
                 * If the trace did not stop with --aa-only, at least print the
 
 
 #define ns_to_usf(x) (((double)x/1000))
 #define ns_to_per(total, part) ((part * 100) / (double)total)
+
+enum result {
+       PASSED = 0, /* same as EXIT_SUCCESS */
+       ERROR = 1,  /* same as EXIT_FAILURE, an error in arguments */
+       FAILED = 2, /* test hit the stop tracing condition */
+};
 
 }
 
 check() {
+       expected_exitcode=${3:-0}
        # Simple check: run rtla with given arguments and test exit code.
        # If TEST_COUNT is set, run the test. Otherwise, just count.
        ctr=$(($ctr + 1))
                # Run rtla; in case of failure, include its output as comment
                # in the test results.
                result=$(stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
-               if [ $exitcode -eq 0 ]
+               if [ $exitcode -eq $expected_exitcode ]
                then
                        echo "ok $ctr - $1"
                else
        # Save original arguments
        arg1=$1
        arg2=$2
+       arg3=$3
 
        # Apply osnoise options (if not dry run)
        if [ -n "$TEST_COUNT" ]
        then
                [ "$NO_RESET_OSNOISE" == 1 ] || reset_osnoise
                shift
+               shift
                while shift
                do
                        [ "$1" == "" ] && continue
                done
        fi
 
-       NO_RESET_OSNOISE=1 check "$arg1" "$arg2"
+       NO_RESET_OSNOISE=1 check "$arg1" "$arg2" "$arg3"
 }
 
 set_timeout() {
 
 check "detect noise higher than one microsecond" \
        "hwnoise -c 0 -T 1 -d 5s -q"
 check "set the automatic trace mode" \
-       "hwnoise -a 5 -d 30s"
+       "hwnoise -a 5 -d 30s" 2
 check "set scheduling param to the osnoise tracer threads" \
        "hwnoise -P F:1 -c 0 -r 900000 -d 1M -q"
 check "stop the trace if a single sample is higher than 1 us" \
-       "hwnoise -s 1 -T 1 -t -d 30s"
+       "hwnoise -s 1 -T 1 -t -d 30s" 2
 check "enable a trace event trigger" \
        "hwnoise -t -e osnoise:irq_noise trigger=\"hist:key=desc,duration:sort=desc,duration:vals=hitcount\" -d 1m"
 
 
 check "verify the --priority/-P param" \
        "osnoise top -P F:1 -c 0 -r 900000 -d 1M -q"
 check "verify the --stop/-s param" \
-       "osnoise top -s 30 -T 1 -t"
+       "osnoise top -s 30 -T 1 -t" 2
 check "verify the  --trace param" \
-       "osnoise hist -s 30 -T 1 -t"
+       "osnoise hist -s 30 -T 1 -t" 2
 check "verify the --entries/-E param" \
        "osnoise hist -P F:1 -c 0 -r 900000 -d 1M -b 10 -E 25"
 
 # and stopping on threshold.
 # If default period is not set, this will time out.
 check_with_osnoise_options "apply default period" \
-       "osnoise hist -s 1" period_us=600000000
+       "osnoise hist -s 1" 2 period_us=600000000
 
 test_end
 
 check "verify help page" \
        "timerlat --help"
 check "verify -s/--stack" \
-       "timerlat top -s 3 -T 10 -t"
+       "timerlat top -s 3 -T 10 -t" 2
 check "verify -P/--priority" \
        "timerlat top -P F:1 -c 0 -d 1M -q"
 check "test in nanoseconds" \
-       "timerlat top -i 2 -c 0 -n -d 30s"
+       "timerlat top -i 2 -c 0 -n -d 30s" 2
 check "set the automatic trace mode" \
-       "timerlat top -a 5 --dump-tasks"
+       "timerlat top -a 5 --dump-tasks" 2
 check "print the auto-analysis if hits the stop tracing condition" \
-       "timerlat top --aa-only 5"
+       "timerlat top --aa-only 5" 2
 check "disable auto-analysis" \
-       "timerlat top -s 3 -T 10 -t --no-aa"
+       "timerlat top -s 3 -T 10 -t --no-aa" 2
 check "verify -c/--cpus" \
        "timerlat hist -c 0 -d 30s"
 check "hist test in nanoseconds" \
-       "timerlat hist -i 2 -c 0 -n -d 30s"
+       "timerlat hist -i 2 -c 0 -n -d 30s" 2
 done
 
 test_end