testing/selftests: Have instance test stress instances more

Started by Steven Rostedt on Oct 29, 2026 · 6 messages from 2 authors · Last reply Oct 30, 2026

Series

2 patches, 1 file

+31 −15

Subsystems (3)

Maintainers (5)

Show 1 more
COOLING13d

open the first message on its own page

  1. [PATCH 1/2] tracing/selftests: Fix instance test to actually test races
    Related patches
  2. [PATCH 2/2] tracing/selftests: Add reading all instance files to instance test
    Related patches
Message details and related content
I found that the instance test doesn't actually stress the creation
and deletion of instances while reading them as I thought it did.
This was due to the rmdir failing to remove the instance because it
was busy (by the reads that were happening).

Make the tests do 10 creations and removals while reading the instance
and mkae sure the removal succeeds.

Also add reading of more files that were not tested before.

Steven Rostedt (2):
      tracing/selftests: Fix instance test actually test races
      tracing/selftests: Add reading all instance files to instance test

----
 .../ftrace/test.d/instances/instance-event.tc      | 34 ++++++++++++++++------
 1 file changed, 25 insertions(+), 9 deletions(-)

[PATCH 1/2] tracing/selftests: Fix instance test to actually test races

Message details and related content
From: Steven Rostedt <rostedt@goodmis.org>

The instance selftest creates and removes the "foo" instance while
enabling sched_switch event and reading its trace file. The issue is that
the read of the trace file prevents the removal of foo, and it constantly
fails to remove it. The stress test is not really stressing the situation.

Instead of running the creating and deletion in a loop as a separate
process and sleeping for one second, call it directly in a loop that forces
it to happen 10 times.  Also update the removal to keep trying until it
removes the instance, otherwise if it doesn't remove it then the next mkdir
is a nop.

Convert the reading of the trace file to use "head" instead of "cat" so it
is limited in how much it reads and add a .1 sleep in between reads. This
gives the removal of the instance time to succeed.

Fixes: 91e6f1ce86577 ("ftracetest: Add instance created, delete, read and enable event test")
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 .../ftrace/test.d/instances/instance-event.tc | 26 +++++++++----------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
index 42422e425107..b0e9d3abbf2f 100644
--- a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
+++ b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
@@ -25,15 +25,16 @@ if [ $result -ne 0 ]; then
 fi
 
 instance_slam() {
-        while :; do
-                mkdir foo 2> /dev/null
-                rmdir foo 2> /dev/null
-        done
+	mkdir foo 2> /dev/null
+	while ! rmdir foo; do
+		echo could not rmdir foo
+	done
 }
 
 instance_read() {
         while :; do
-                cat foo/trace 1> /dev/null 2>&1
+                head foo/trace 1> /dev/null 2>&1
+		sleep 0.1
         done
 }
 
@@ -43,26 +44,23 @@ instance_set() {
         done 2> /dev/null
 }
 
-instance_slam &
+instance_set &
 p1=$!
 echo $p1
 
-instance_set &
+instance_read &
 p2=$!
 echo $p2
 
-instance_read &
-p3=$!
-echo $p3
-
-sleep 1
+for i in `seq 10`; do
+	instance_slam
+done
 
-kill -1 $p3
 kill -1 $p2
 kill -1 $p1
 
 echo "Wait for processes to finish"
-wait $p1 $p2 $p3
+wait $p1 $p2
 echo "all processes finished, wait for cleanup"
 sleep 1
 
-- 
2.53.0

[PATCH 2/2] tracing/selftests: Add reading all instance files to instance test

Message details and related content
From: Steven Rostedt <rostedt@goodmis.org>

Commit f4a771cc684c7 ("tracing: Have show_event_filters/triggers files take
trace array ref") fixed a bug where the show_event_filters and triggers
did not take a trace array reference allowing an instance to be removed
while active. This would have the reader of these files read data that was
freed by the remove.

Update the instance test to read all the files in the instance,
instance/events, instance/events/sched and
instance/events/sched/sched_switch directories (with the exception of not
reading trace or trace_pipe). This would hopefully catch issues with files
not taking references.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 .../ftrace/test.d/instances/instance-event.tc | 20 ++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
index b0e9d3abbf2f..9374c20c6aaa 100644
--- a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
+++ b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
@@ -44,6 +44,19 @@ instance_set() {
         done 2> /dev/null
 }
 
+instance_cat() {
+        while :; do
+		find instances/foo -maxdepth 1 -type f  ! \( -name trace -o -name trace_pipe \) -exec head {} \;
+		sleep 0.1
+		find instances/foo/events -maxdepth 1 -type f  -exec cat {} \;
+		sleep 0.1
+		find instances/foo/events/sched -maxdepth 1 -type f  -exec cat {} \;
+		sleep 0.1
+		find instances/foo/events/sched/sched_waking -maxdepth 1 -type f  -exec cat {} \;
+		sleep 0.1
+        done 2> /dev/null
+}
+
 instance_set &
 p1=$!
 echo $p1
@@ -52,15 +65,20 @@ instance_read &
 p2=$!
 echo $p2
 
+instance_cat &
+p3=$!
+echo $p3
+
 for i in `seq 10`; do
 	instance_slam
 done
 
+kill -1 $p3
 kill -1 $p2
 kill -1 $p1
 
 echo "Wait for processes to finish"
-wait $p1 $p2
+wait $p1 $p2 $p3
 echo "all processes finished, wait for cleanup"
 sleep 1
 
-- 
2.53.0

Re: [PATCH 1/2] tracing/selftests: Fix instance test to actually test races

Message details and related content
On Thu, 29 Oct 2026 16:28:50 -0400, Steven Rostedt [off-list ref] wrote:
quoted hunk
From: Steven Rostedt <rostedt@goodmis.org>

The instance selftest creates and removes the "foo" instance while
enabling sched_switch event and reading its trace file. The issue is that
the read of the trace file prevents the removal of foo, and it constantly
fails to remove it. The stress test is not really stressing the situation.

Instead of running the creating and deletion in a loop as a separate
process and sleeping for one second, call it directly in a loop that forces
it to happen 10 times.  Also update the removal to keep trying until it
removes the instance, otherwise if it doesn't remove it then the next mkdir
is a nop.

Convert the reading of the trace file to use "head" instead of "cat" so it
is limited in how much it reads and add a .1 sleep in between reads. This
gives the removal of the instance time to succeed.

Fixes: 91e6f1ce86577 ("ftracetest: Add instance created, delete, read and enable event test")
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 .../ftrace/test.d/instances/instance-event.tc | 26 +++++++++----------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
index 42422e425107..b0e9d3abbf2f 100644
--- a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
+++ b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
@@ -25,15 +25,16 @@ if [ $result -ne 0 ]; then
 fi
 
 instance_slam() {
-        while :; do
-                mkdir foo 2> /dev/null
-                rmdir foo 2> /dev/null
-        done
+	mkdir foo 2> /dev/null
+	while ! rmdir foo; do
+		echo could not rmdir foo
nit: If we retry this, do we need to warn it?
(maybe we can add a limitation of continuous failure and make the
test fail if the failure exceeds it.)
+	done
 }
 
Thanks,

-- 
Masami Hiramatsu (Google) [off-list ref]

Re: [PATCH 1/2] tracing/selftests: Fix instance test to actually test races

Message details and related content
On Fri, 30 Oct 2026 10:01:19 +0900
"Masami Hiramatsu (Google)" [off-list ref] wrote:
quoted
 instance_slam() {
-        while :; do
-                mkdir foo 2> /dev/null
-                rmdir foo 2> /dev/null
-        done
+	mkdir foo 2> /dev/null
+	while ! rmdir foo; do
+		echo could not rmdir foo  
nit: If we retry this, do we need to warn it?
(maybe we can add a limitation of continuous failure and make the
test fail if the failure exceeds it.)
Retrying is actually quite normal. The rmdir *should* fail if one of
the instance files is open.

Now perhaps we can add a counter to make it fail if it exceeds a large
threshold?

	let x=0
	while ! rmdir  foo; do
		let x=$x+1
		if [ $x -gt 10000 ]; then
			exit_fail
		fi
	done

?

-- Steve

Re: [PATCH 2/2] tracing/selftests: Add reading all instance files to instance test

Message details and related content
On Thu, 29 Oct 2026 16:28:51 -0400, Steven Rostedt [off-list ref] wrote:
From: Steven Rostedt <rostedt@goodmis.org>

Commit f4a771cc684c7 ("tracing: Have show_event_filters/triggers files take
trace array ref") fixed a bug where the show_event_filters and triggers
did not take a trace array reference allowing an instance to be removed
while active. This would have the reader of these files read data that was
freed by the remove.

Update the instance test to read all the files in the instance,
instance/events, instance/events/sched and
instance/events/sched/sched_switch directories (with the exception of not
reading trace or trace_pipe). This would hopefully catch issues with files
not taking references.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

quoted hunk
---
 .../ftrace/test.d/instances/instance-event.tc | 20 ++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
index b0e9d3abbf2f..9374c20c6aaa 100644
--- a/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
+++ b/tools/testing/selftests/ftrace/test.d/instances/instance-event.tc
@@ -44,6 +44,19 @@ instance_set() {
         done 2> /dev/null
 }
 
+instance_cat() {
+        while :; do
+		find instances/foo -maxdepth 1 -type f  ! \( -name trace -o -name trace_pipe \) -exec head {} \;
+		sleep 0.1
+		find instances/foo/events -maxdepth 1 -type f  -exec cat {} \;
+		sleep 0.1
+		find instances/foo/events/sched -maxdepth 1 -type f  -exec cat {} \;
+		sleep 0.1
+		find instances/foo/events/sched/sched_waking -maxdepth 1 -type f  -exec cat {} \;
+		sleep 0.1
+        done 2> /dev/null
+}
+
 instance_set &
 p1=$!
 echo $p1
@@ -52,15 +65,20 @@ instance_read &
 p2=$!
 echo $p2
 
+instance_cat &
+p3=$!
+echo $p3
+
 for i in `seq 10`; do
 	instance_slam
 done
 

13 more quoted lines

-- 
Masami Hiramatsu (Google) [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help