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

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: 1a4ea83a6e67 ("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>

authored by

Steven Rostedt and committed by
Shuah Khan
21387906 661e9cd1

+26 -2
+26 -2
tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc
··· 14 14 exit_fail 15 15 } 16 16 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 + 17 41 echo 'sched:*' > set_event 18 42 19 43 yield 20 44 21 - count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l` 45 + count=`check_unique` 22 46 if [ $count -lt 3 ]; then 23 47 fail "at least fork, exec and exit events should be recorded" 24 48 fi ··· 53 29 54 30 yield 55 31 56 - count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l` 32 + count=`check_unique` 57 33 if [ $count -lt 3 ]; then 58 34 fail "at least fork, exec and exit events should be recorded" 59 35 fi