Skip to content

Commit 916a9c5

Browse files
lenticularis39rostedt
authored andcommitted
rtla/tests: Check rtla output with grep
Add argument to the check command in the test suite that takes a regular expression that the output of rtla command is checked against. This allows testing for specific information in rtla output in addition to checking the return value. Two minor improvements are included: running rtla with "eval" so that arguments with spaces can be passed to it via shell quotations, and the stdout of pushd and popd is suppressed to clean up the test output. Cc: John Kacur <[email protected]> Cc: Luis Goncalves <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Chang Yin <[email protected]> Cc: Costa Shulyupin <[email protected]> Cc: Crystal Wood <[email protected]> Cc: Gabriele Monaco <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Tomas Glozar <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 3aadb65 commit 916a9c5

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tools/tracing/rtla/tests/engine.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_begin() {
1111
reset_osnoise() {
1212
# Reset osnoise options to default and remove any dangling instances created
1313
# by improperly exited rtla runs.
14-
pushd /sys/kernel/tracing || return 1
14+
pushd /sys/kernel/tracing >/dev/null || return 1
1515

1616
# Remove dangling instances created by previous rtla run
1717
echo 0 > tracing_thresh
@@ -35,11 +35,14 @@ reset_osnoise() {
3535
echo 0 > stop_tracing_us
3636
echo 1000 > timerlat_period_us
3737

38-
popd
38+
popd >/dev/null
3939
}
4040

4141
check() {
42+
test_name=$0
43+
tested_command=$1
4244
expected_exitcode=${3:-0}
45+
expected_output=$4
4346
# Simple check: run rtla with given arguments and test exit code.
4447
# If TEST_COUNT is set, run the test. Otherwise, just count.
4548
ctr=$(($ctr + 1))
@@ -49,15 +52,25 @@ check() {
4952
[ "$NO_RESET_OSNOISE" == 1 ] || reset_osnoise
5053
# Run rtla; in case of failure, include its output as comment
5154
# in the test results.
52-
result=$(stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
53-
if [ $exitcode -eq $expected_exitcode ]
55+
result=$(eval stdbuf -oL $TIMEOUT "$RTLA" $2 2>&1); exitcode=$?
56+
# Test if the results matches if requested
57+
if [ -n "$expected_output" ]
58+
then
59+
grep -E "$expected_output" <<< "$result" > /dev/null; grep_result=$?
60+
else
61+
grep_result=0
62+
fi
63+
64+
if [ $exitcode -eq $expected_exitcode ] && [ $grep_result -eq 0 ]
5465
then
5566
echo "ok $ctr - $1"
5667
else
5768
echo "not ok $ctr - $1"
5869
# Add rtla output and exit code as comments in case of failure
5970
echo "$result" | col -b | while read line; do echo "# $line"; done
6071
printf "#\n# exit code %s\n" $exitcode
72+
[ -n "$expected_output" ] && \
73+
printf "# Output match failed: \"%s\"\n" "$expected_output"
6174
fi
6275
fi
6376
}

0 commit comments

Comments
 (0)