]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/tracing: Fix false failure of subsystem event test
authorSteven Rostedt <rostedt@goodmis.org>
Mon, 21 Jul 2025 17:42:12 +0000 (13:42 -0400)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 24 Jul 2025 21:52:20 +0000 (15:52 -0600)
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>
tools/testing/selftests/ftrace/test.d/event/subsystem-enable.tc

index b7c8f29c09a978895c1176e1a39aeda8c97e8416..65916bb55dfbbffc3283bb44083c6f1cb85532a6 100644 (file)
@@ -14,11 +14,35 @@ fail() { #msg
     exit_fail
 }
 
+# As reading trace can last forever, simply look for 3 different
+# events then exit out of reading the file. If there's not 3 different
+# events, then the test has failed.
+check_unique() {
+    cat trace | grep -v '^#' | awk '
+       BEGIN { cnt = 0; }
+       {
+           for (i = 0; i < cnt; i++) {
+               if (event[i] == $5) {
+                   break;
+               }
+           }
+           if (i == cnt) {
+               event[cnt++] = $5;
+               if (cnt > 2) {
+                   exit;
+               }
+           }
+       }
+       END {
+           printf "%d", cnt;
+       }'
+}
+
 echo 'sched:*' > set_event
 
 yield
 
-count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
+count=`check_unique`
 if [ $count -lt 3 ]; then
     fail "at least fork, exec and exit events should be recorded"
 fi
@@ -29,7 +53,7 @@ echo 1 > events/sched/enable
 
 yield
 
-count=`head -n 100 trace | grep -v ^# | awk '{ print $5 }' | sort -u | wc -l`
+count=`check_unique`
 if [ $count -lt 3 ]; then
     fail "at least fork, exec and exit events should be recorded"
 fi