Skip to content

Commit 3cd6b18

Browse files
crwood-rhrostedt
authored andcommitted
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 <[email protected]> Cc: Costa Shulyupin <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Tomas Glozar <[email protected]> Signed-off-by: Crystal Wood <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent c4e30c2 commit 3cd6b18

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tools/tracing/rtla/tests/engine.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ check() {
4343
tested_command=$1
4444
expected_exitcode=${3:-0}
4545
expected_output=$4
46+
unexpected_output=$5
4647
# Simple check: run rtla with given arguments and test exit code.
4748
# If TEST_COUNT is set, run the test. Otherwise, just count.
4849
ctr=$(($ctr + 1))
@@ -53,24 +54,33 @@ check() {
5354
# Run rtla; in case of failure, include its output as comment
5455
# in the test results.
5556
result=$(eval stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
57+
failbuf=''
58+
fail=0
59+
5660
# Test if the results matches if requested
57-
if [ -n "$expected_output" ]
61+
if [ -n "$expected_output" ] && ! grep -qE "$expected_output" <<< "$result"
5862
then
59-
grep -E "$expected_output" <<< "$result" > /dev/null; grep_result=$?
60-
else
61-
grep_result=0
63+
fail=1
64+
failbuf+=$(printf "# Output match failed: \"%s\"" "$expected_output")
65+
failbuf+=$'\n'
6266
fi
6367

64-
if [ $exitcode -eq $expected_exitcode ] && [ $grep_result -eq 0 ]
68+
if [ -n "$unexpected_output" ] && grep -qE "$unexpected_output" <<< "$result"
69+
then
70+
fail=1
71+
failbuf+=$(printf "# Output non-match failed: \"%s\"" "$unexpected_output")
72+
failbuf+=$'\n'
73+
fi
74+
75+
if [ $exitcode -eq $expected_exitcode ] && [ $fail -eq 0 ]
6576
then
6677
echo "ok $ctr - $1"
6778
else
68-
echo "not ok $ctr - $1"
6979
# Add rtla output and exit code as comments in case of failure
80+
echo "not ok $ctr - $1"
81+
echo -n "$failbuf"
7082
echo "$result" | col -b | while read line; do echo "# $line"; done
7183
printf "#\n# exit code %s\n" $exitcode
72-
[ -n "$expected_output" ] && [ $grep_result -ne 0 ] && \
73-
printf "# Output match failed: \"%s\"\n" "$expected_output"
7484
fi
7585
fi
7686
}

0 commit comments

Comments
 (0)