Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/rtla: Add test engine support for unexpected output

Add a check() parameter to indicate which text must not appear in the
output.

Simplify the code so that we can print failures as they happen rather
than trying to figure out what went wrong after printing "not ok". This
also means that "not ok" gets printed after the info rather than before,
which seems more intuitive anyway.

Cc: John Kacur <jkacur@redhat.com>
Cc: Costa Shulyupin <costa.shul@redhat.com>
Link: https://lore.kernel.org/20250907022325.243930-7-crwood@redhat.com
Reviewed-by: Tomas Glozar <tglozar@redhat.com>
Signed-off-by: Crystal Wood <crwood@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Crystal Wood and committed by
Steven Rostedt (Google)
3cd6b18d c4e30c22

+18 -8
+18 -8
tools/tracing/rtla/tests/engine.sh
··· 43 43 tested_command=$1 44 44 expected_exitcode=${3:-0} 45 45 expected_output=$4 46 + unexpected_output=$5 46 47 # Simple check: run rtla with given arguments and test exit code. 47 48 # If TEST_COUNT is set, run the test. Otherwise, just count. 48 49 ctr=$(($ctr + 1)) ··· 54 53 # Run rtla; in case of failure, include its output as comment 55 54 # in the test results. 56 55 result=$(eval stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$? 56 + failbuf='' 57 + fail=0 58 + 57 59 # Test if the results matches if requested 58 - if [ -n "$expected_output" ] 60 + if [ -n "$expected_output" ] && ! grep -qE "$expected_output" <<< "$result" 59 61 then 60 - grep -E "$expected_output" <<< "$result" > /dev/null; grep_result=$? 61 - else 62 - grep_result=0 62 + fail=1 63 + failbuf+=$(printf "# Output match failed: \"%s\"" "$expected_output") 64 + failbuf+=$'\n' 63 65 fi 64 66 65 - if [ $exitcode -eq $expected_exitcode ] && [ $grep_result -eq 0 ] 67 + if [ -n "$unexpected_output" ] && grep -qE "$unexpected_output" <<< "$result" 68 + then 69 + fail=1 70 + failbuf+=$(printf "# Output non-match failed: \"%s\"" "$unexpected_output") 71 + failbuf+=$'\n' 72 + fi 73 + 74 + if [ $exitcode -eq $expected_exitcode ] && [ $fail -eq 0 ] 66 75 then 67 76 echo "ok $ctr - $1" 68 77 else 69 - echo "not ok $ctr - $1" 70 78 # Add rtla output and exit code as comments in case of failure 79 + echo "not ok $ctr - $1" 80 + echo -n "$failbuf" 71 81 echo "$result" | col -b | while read line; do echo "# $line"; done 72 82 printf "#\n# exit code %s\n" $exitcode 73 - [ -n "$expected_output" ] && [ $grep_result -ne 0 ] && \ 74 - printf "# Output match failed: \"%s\"\n" "$expected_output" 75 83 fi 76 84 fi 77 85 }