Skip to content

Commit 2138790

Browse files
rostedtshuahkh
authored andcommitted
selftests/tracing: Fix false failure of subsystem event test
The subsystem event test enables all "sched" events and makes sure there's at least 3 different events in the output. It used to cat the entire trace file to | wc -l, but on slow machines, that could last a very long time. To solve that, it was changed to just read the first 100 lines of the trace file. This can cause false failures as some events repeat so often, that the 100 lines that are examined could possibly be of only one event. Instead, create an awk script that looks for 3 different events and will exit out after it finds them. This will find the 3 events the test looks for (eventually if it works), and still exit out after the test is satisfied and not cause slower machines to run forever. Link: https://lore.kernel.org/r/20250721134212.53c3e140@batman.local.home Reported-by: Tengda Wu <wutengda@huaweicloud.com> Closes: https://lore.kernel.org/all/20250710130134.591066-1-wutengda@huaweicloud.com/ Fixes: 1a4ea83 ("selftests/ftrace: Limit length in subsystem-enable tests") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 661e9cd commit 2138790

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,35 @@ fail() { #msg
1414
exit_fail
1515
}
1616

17+
# As reading trace can last forever, simply look for 3 different
18+
# events then exit out of reading the file. If there's not 3 different
19+
# events, then the test has failed.
20+
check_unique() {
21+
cat trace | grep -v '^#' | awk '
22+
BEGIN { cnt = 0; }
23+
{
24+
for (i = 0; i < cnt; i++) {
25+
if (event[i] == $5) {
26+
break;
27+
}
28+
}
29+
if (i == cnt) {
30+
event[cnt++] = $5;
31+
if (cnt > 2) {
32+
exit;
33+
}
34+
}
35+
}
36+
END {
37+
printf "%d", cnt;
38+
}'
39+
}
40+
1741
echo 'sched:*' > set_event
1842

1943
yield
2044

21-
count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
45+
count=`check_unique`
2246
if [ $count -lt 3 ]; then
2347
fail "at least fork, exec and exit events should be recorded"
2448
fi
@@ -29,7 +53,7 @@ echo 1 > events/sched/enable
2953

3054
yield
3155

32-
count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
56+
count=`check_unique`
3357
if [ $count -lt 3 ]; then
3458
fail "at least fork, exec and exit events should be recorded"
3559
fi

0 commit comments

Comments
 (0)