[PATCH v2] selftests/ftrace: Account for fprobe attachment before enable

Cao Ruichuang
2026-04-08T04:26:02Z

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)