public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/ftrace: Account for fprobe attachment at creation
@ 2026-04-07 11:57 Cao Ruichuang
  2026-04-08  0:49 ` Masami Hiramatsu
  2026-04-08  4:25 ` [PATCH v2] selftests/ftrace: Account for fprobe attachment before enable Cao Ruichuang
  0 siblings, 2 replies; 4+ messages in thread
From: Cao Ruichuang @ 2026-04-07 11:57 UTC (permalink / raw)
  To: rostedt, mhiramat, mathieu.desnoyers, shuah
  Cc: linux-kernel, linux-trace-kernel, linux-kselftest

add_remove_fprobe.tc assumes that enabling an fprobe event is what adds
its target function to enabled_functions.

On the current kernel, the fprobe target already appears in
enabled_functions as soon as the event is created, and enabling the
event does not change that count again. That makes the test fail even
though the event lifecycle itself works.

Record the attachment baseline after creating the probe events and only
check that enabling them keeps the expected functions attached. The
cleanup checks still verify that removing the events returns
enabled_functions to its original state.

Signed-off-by: Cao Ruichuang <create0818@163.com>
---
 .../test.d/dynevent/add_remove_fprobe.tc      | 28 +++++++++++++------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
index 47067a5e3..ff08bd1ac 100644
--- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
+++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
@@ -26,23 +26,29 @@ grep -q myevent2 dynamic_events
 grep -q myevent3 dynamic_events
 test -d events/fprobes/myevent1
 test -d events/fprobes/myevent2
-
-echo 1 > events/fprobes/myevent1/enable
-# Make sure the event is attached.
 grep -q $PLACE enabled_functions
+grep -q $PLACE2 enabled_functions
 cnt=`cat enabled_functions | wc -l`
-if [ $cnt -eq $ocnt ]; then
+if [ $cnt -le $ocnt ]; then
+	exit_fail
+fi
+
+echo 1 > events/fprobes/myevent1/enable
+cnt1=`cat enabled_functions | wc -l`
+if [ $cnt1 -ne $cnt ]; then
 	exit_fail
 fi
 
 echo 1 > events/fprobes/myevent2/enable
 cnt2=`cat enabled_functions | wc -l`
+if [ $cnt2 -ne $cnt1 ]; then
+	exit_fail
+fi
 
 echo 1 > events/fprobes/myevent3/enable
-# If the function is different, the attached function should be increased
 grep -q $PLACE2 enabled_functions
 cnt=`cat enabled_functions | wc -l`
-if [ $cnt -eq $cnt2 ]; then
+if [ $cnt -ne $cnt2 ]; then
 	exit_fail
 fi
 
@@ -62,11 +68,15 @@ if [ $cnt -ne $ocnt ]; then
 fi
 
 echo "f:myevent4 $PLACE" >> dynamic_events
+grep -q $PLACE enabled_functions
+cnt=`cat enabled_functions | wc -l`
+if [ $cnt -le $ocnt ]; then
+	exit_fail
+fi
 
 echo 1 > events/fprobes/myevent4/enable
-# Should only have one enabled
-cnt=`cat enabled_functions | wc -l`
-if [ $cnt -ne $((ocnt + 1)) ]; then
+cnt2=`cat enabled_functions | wc -l`
+if [ $cnt2 -ne $cnt ]; then
 	exit_fail
 fi
 
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests/ftrace: Account for fprobe attachment at creation
  2026-04-07 11:57 [PATCH] selftests/ftrace: Account for fprobe attachment at creation Cao Ruichuang
@ 2026-04-08  0:49 ` Masami Hiramatsu
  2026-04-08  4:09   ` Cao Ruichuang
  2026-04-08  4:25 ` [PATCH v2] selftests/ftrace: Account for fprobe attachment before enable Cao Ruichuang
  1 sibling, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2026-04-08  0:49 UTC (permalink / raw)
  To: Cao Ruichuang
  Cc: rostedt, mathieu.desnoyers, shuah, linux-kernel,
	linux-trace-kernel, linux-kselftest

On Tue,  7 Apr 2026 19:57:51 +0800
Cao Ruichuang <create0818@163.com> wrote:

> add_remove_fprobe.tc assumes that enabling an fprobe event is what adds
> its target function to enabled_functions.
> 
> On the current kernel, the fprobe target already appears in
> enabled_functions as soon as the event is created, and enabling the
> event does not change that count again. That makes the test fail even
> though the event lifecycle itself works.
> 
> Record the attachment baseline after creating the probe events and only
> check that enabling them keeps the expected functions attached. The
> cleanup checks still verify that removing the events returns
> enabled_functions to its original state.
> 

Hmm, did you run this test with not clean environment?
It is not designed to do so.
(I think we should not check ocnt, or if there are any entries,
 we should stop this test as unresolved.)

Thank you,

> Signed-off-by: Cao Ruichuang <create0818@163.com>
> ---
>  .../test.d/dynevent/add_remove_fprobe.tc      | 28 +++++++++++++------
>  1 file changed, 19 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
> index 47067a5e3..ff08bd1ac 100644
> --- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
> +++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
> @@ -26,23 +26,29 @@ grep -q myevent2 dynamic_events
>  grep -q myevent3 dynamic_events
>  test -d events/fprobes/myevent1
>  test -d events/fprobes/myevent2
> -
> -echo 1 > events/fprobes/myevent1/enable
> -# Make sure the event is attached.
>  grep -q $PLACE enabled_functions
> +grep -q $PLACE2 enabled_functions
>  cnt=`cat enabled_functions | wc -l`
> -if [ $cnt -eq $ocnt ]; then
> +if [ $cnt -le $ocnt ]; then
> +	exit_fail
> +fi
> +
> +echo 1 > events/fprobes/myevent1/enable
> +cnt1=`cat enabled_functions | wc -l`
> +if [ $cnt1 -ne $cnt ]; then
>  	exit_fail
>  fi
>  
>  echo 1 > events/fprobes/myevent2/enable
>  cnt2=`cat enabled_functions | wc -l`
> +if [ $cnt2 -ne $cnt1 ]; then
> +	exit_fail
> +fi
>  
>  echo 1 > events/fprobes/myevent3/enable
> -# If the function is different, the attached function should be increased
>  grep -q $PLACE2 enabled_functions
>  cnt=`cat enabled_functions | wc -l`
> -if [ $cnt -eq $cnt2 ]; then
> +if [ $cnt -ne $cnt2 ]; then
>  	exit_fail
>  fi
>  
> @@ -62,11 +68,15 @@ if [ $cnt -ne $ocnt ]; then
>  fi
>  
>  echo "f:myevent4 $PLACE" >> dynamic_events
> +grep -q $PLACE enabled_functions
> +cnt=`cat enabled_functions | wc -l`
> +if [ $cnt -le $ocnt ]; then
> +	exit_fail
> +fi
>  
>  echo 1 > events/fprobes/myevent4/enable
> -# Should only have one enabled
> -cnt=`cat enabled_functions | wc -l`
> -if [ $cnt -ne $((ocnt + 1)) ]; then
> +cnt2=`cat enabled_functions | wc -l`
> +if [ $cnt2 -ne $cnt ]; then
>  	exit_fail
>  fi
>  
> -- 
> 2.39.5 (Apple Git-154)
> 


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] selftests/ftrace: Account for fprobe attachment at creation
  2026-04-08  0:49 ` Masami Hiramatsu
@ 2026-04-08  4:09   ` Cao Ruichuang
  0 siblings, 0 replies; 4+ messages in thread
From: Cao Ruichuang @ 2026-04-08  4:09 UTC (permalink / raw)
  To: mhiramat; +Cc: rostedt, linux-kernel, linux-trace-kernel

Thanks, that is a good point.

I need to separate a clean source tree from a clean tracing runtime
environment. I will rerun this in a fresh tracing environment and
re-evaluate the testcase assumption before pushing anything further.

If this testcase is only valid for a clean environment, then an
unresolved check or a different precondition will make more sense
than the current patch.

Thanks,
Cao Ruichuang


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] selftests/ftrace: Account for fprobe attachment before enable
  2026-04-07 11:57 [PATCH] selftests/ftrace: Account for fprobe attachment at creation Cao Ruichuang
  2026-04-08  0:49 ` Masami Hiramatsu
@ 2026-04-08  4:25 ` Cao Ruichuang
  1 sibling, 0 replies; 4+ messages in thread
From: Cao Ruichuang @ 2026-04-08  4:25 UTC (permalink / raw)
  To: rostedt, mhiramat
  Cc: mathieu.desnoyers, shuah, linux-kernel, linux-trace-kernel,
	linux-kselftest

add_remove_fprobe.tc assumes that enabling an fprobe event is what
adds its target function to enabled_functions.

After resetting tracing state with initialize_system(), the current
kernel still attaches the target functions as soon as the probe events
are created. Enabling the three events does not increase the
enabled_functions count further, and the original testcase fails on the
check after enabling myevent3.

Record the baseline after creating the fprobe events and verify that
subsequent enables keep that attachment set unchanged.

Signed-off-by: Cao Ruichuang <create0818@163.com>
---
v2:
- rerun in a reset tracing environment after initialize_system()
- keep the fix focused on the failing myevent3 assumption and drop the
  unnecessary myevent4 changes

 .../ftrace/test.d/dynevent/add_remove_fprobe.tc | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
index 47067a5e3..a55179f5d 100644
--- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
+++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_fprobe.tc
@@ -27,22 +27,29 @@ grep -q myevent3 dynamic_events
 test -d events/fprobes/myevent1
 test -d events/fprobes/myevent2
 
-echo 1 > events/fprobes/myevent1/enable
-# Make sure the event is attached.
 grep -q $PLACE enabled_functions
+grep -q $PLACE2 enabled_functions
 cnt=`cat enabled_functions | wc -l`
-if [ $cnt -eq $ocnt ]; then
+if [ $cnt -le $ocnt ]; then
+	exit_fail
+fi
+
+echo 1 > events/fprobes/myevent1/enable
+cnt1=`cat enabled_functions | wc -l`
+if [ $cnt1 -ne $cnt ]; then
 	exit_fail
 fi
 
 echo 1 > events/fprobes/myevent2/enable
 cnt2=`cat enabled_functions | wc -l`
+if [ $cnt2 -ne $cnt1 ]; then
+	exit_fail
+fi
 
 echo 1 > events/fprobes/myevent3/enable
-# If the function is different, the attached function should be increased
 grep -q $PLACE2 enabled_functions
 cnt=`cat enabled_functions | wc -l`
-if [ $cnt -eq $cnt2 ]; then
+if [ $cnt -ne $cnt2 ]; then
 	exit_fail
 fi
 
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-08  4:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 11:57 [PATCH] selftests/ftrace: Account for fprobe attachment at creation Cao Ruichuang
2026-04-08  0:49 ` Masami Hiramatsu
2026-04-08  4:09   ` Cao Ruichuang
2026-04-08  4:25 ` [PATCH v2] selftests/ftrace: Account for fprobe attachment before enable Cao Ruichuang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox