selftests/tracing: Fix flakiness in trigger-hist-poll.tc by waiting for task exit
Masami Hiramatsu (Google)
maintainerPATCH 1/1 selftests/tracing: Fix flakiness in trigger-hist-poll.tc by waiting for task exit
From: Masami Hiramatsu (Google) <[email protected]>
Commit c5c413534d40 ("selftests/tracing: Have trigger-hist-poll.tc use sched_process_exit") changed the target event from sched_process_free to sched_process_exit to avoid timeouts under CONFIG_RCU_LAZY.
However, sched_process_exit fires inside do_exit() before the exiting task completes teardown and before the parent shell reaps it. When poll unblocks upon sched_process_exit, checking whether /proc/${BGPID} exists immediately after poll returns causes a race condition between poll exiting and the parent shell reaping the child process.
Fix this by waiting for the background sleep process (wait ${BGPID}) and removing the fragile /proc/${BGPID} check. Checking whether the event was logged in the trace buffer already verifies that poll did not exit before the event occurred.
--- .../ftrace/test.d/trigger/trigger-hist-poll.tc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc +4 -10
@@ -38,11 +38,7 @@ BGPID=$! ${POLL} -I -t 4000 ${EVENT}/hist echo 0 > tracing_on -if [ -d /proc/${BGPID} ]; then - echo "poll exits too soon" - kill -KILL ${BGPID} ||: - exit_fail -fi +wait ${BGPID} 2>/dev/null ||: if ! grep -qw "sleep" trace; then echo "poll exits before event happens"
@@ -60,11 +56,7 @@ BGPID=$! ${POLL} -P -t 4000 ${EVENT}/hist echo 0 > tracing_on -if [ -d /proc/${BGPID} ]; then - echo "poll exits too soon" - kill -KILL ${BGPID} ||: - exit_fail -fi +wait ${BGPID} 2>/dev/null ||: if ! grep -qw "sleep" trace; then echo "poll exits before event happens"
@@ -72,3 +64,5 @@ if ! grep -qw "sleep" trace; then fi exit_pass + +
Steven Rostedt
maintainerOn Tue, 21 Jul 2026 09:20:36 +0900
I'm finally getting around to looking at this!
Quoted 31 lines · Masami Hiramatsu (Google)
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc +2
-10@@ -38,11 +38,7 @@ BGPID=$! ${POLL} -I -t 4000 ${EVENT}/hist echo 0 > tracing_on -if [ -d /proc/${BGPID} ]; then - echo "poll exits too soon" - kill -KILL ${BGPID} ||: - exit_fail -fi +wait ${BGPID} 2>/dev/null ||: if ! grep -qw "sleep" trace; then echo "poll exits before event happens"@@ -60,11 +56,7 @@ BGPID=$! ${POLL} -P -t 4000 ${EVENT}/hist echo 0 > tracing_on -if [ -d /proc/${BGPID} ]; then - echo "poll exits too soon" - kill -KILL ${BGPID} ||: - exit_fail -fi +wait ${BGPID} 2>/dev/null ||: if ! grep -qw "sleep" trace; then echo "poll exits before event happens"
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc if ! grep -qw "sleep" trace; then · line 68
Quoted 5 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc +2
-0@@ -72,3 +64,5 @@ if ! grep -qw "sleep" trace; then fi exit_pass + +
Hmm, any reason for the two added newlines here?
-- Steve
Masami Hiramatsu (Google)
maintainerQuoted 39 lines · Steven Rostedt
On Tue, 21 Jul 2026 09:20:36 +0900
I'm finally getting around to looking at this!
Quoted 33 lines · Masami Hiramatsu (Google)
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc +2
-10@@ -38,11 +38,7 @@ BGPID=$! ${POLL} -I -t 4000 ${EVENT}/hist echo 0 > tracing_on -if [ -d /proc/${BGPID} ]; then - echo "poll exits too soon" - kill -KILL ${BGPID} ||: - exit_fail -fi +wait ${BGPID} 2>/dev/null ||: if ! grep -qw "sleep" trace; then echo "poll exits before event happens"@@ -60,11 +56,7 @@ BGPID=$! ${POLL} -P -t 4000 ${EVENT}/hist echo 0 > tracing_on -if [ -d /proc/${BGPID} ]; then - echo "poll exits too soon" - kill -KILL ${BGPID} ||: - exit_fail -fi +wait ${BGPID} 2>/dev/null ||: if ! grep -qw "sleep" trace; then echo "poll exits before event happens"@@ -72,3 +64,5 @@ if ! grep -qw "sleep" trace; then fi
Quoted 5 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc if ! grep -qw "sleep" trace; then · line 68
Quoted 3 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-poll.tc +2
-0exit_pass + +Hmm, any reason for the two added newlines here?
Oops, no reason. Maybe typo on the editor...
Thanks,
Quoted 3 lines
-- Steve
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>