Skip to contentSkip to conversation

selftests/ftrace: Add debugfs requirement suffix

PATCH In review Jaewon Jung 2 participants 2 messages Oct 25 – Oct 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/ftrace: Add debugfs requirement suffix

Add a :debugfs requirement suffix to check interfaces under debugfs. Use it in the kprobe optimization test to report unsupported instead of failed when debugfs is unavailable.

Tested on x86_64 with QEMU:
- debugfs not mounted: UNSUPPORTED
- debugfs mounted: PASS

---
 tools/testing/selftests/ftrace/test.d/functions        | 10 ++++++++++
 .../selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc |  4 ++--
 tools/testing/selftests/ftrace/test.d/template         |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +10 -0
index 826141e299e5..3cf8ac5fb4d4 100644
@@ -145,6 +145,7 @@ check_requires() { # Check required files and tracers
 	p=${i%:program}
         r=${i%:README}
         t=${i%:tracer}
+	d=${i%:debugfs}
 	if [ "$p" != "$i" ]; then
 	    if ! which "$p" ; then
                 echo "Required program $p is not found."
@@ -166,6 +167,15 @@ check_requires() { # Check required files and tracers
                 echo "Required feature pattern \"$r\" is not in README."
                 exit_unsupported
             fi
+	elif [ "$d" != "$i" ]; then
+	    DEBUGFS_DIR=$(awk '$3 == "debugfs" { print $2; exit }' /proc/mounts)
+	    if [ -z "$DEBUGFS_DIR" ]; then
+		echo "Required filesystem debugfs is not mounted."
+		exit_unsupported
+	    elif [ ! -e "$DEBUGFS_DIR/$d" ]; then
+		echo "Required debugfs interface $d doesn't exist."
+		exit_unsupported
+	    fi
         elif [ ! -e "$i" ]; then
             echo "Required feature interface $i doesn't exist."
             exit_unsupported
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc +2 -2
index 9f5d99328086..25f7192f887b 100644
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (C) 2023 Akanksha J N, IBM corporation
 # description: Register/unregister optimized probe
-# requires: kprobe_events
+# requires: kprobe_events kprobes/list:debugfs
 
 case `uname -m` in
 x86_64)
@@ -22,7 +22,7 @@ for i in `seq 0 255`; do
         echo  "p:testprobe $FUNCTION_FORK+${i}" > kprobe_events || continue
         echo 1 > events/kprobes/enable || continue
         (echo "forked")
-	PROBE=$(grep $FUNCTION_FORK /sys/kernel/debug/kprobes/list)
+	PROBE=$(grep $FUNCTION_FORK "$DEBUGFS_DIR/kprobes/list")
         echo 0 > events/kprobes/enable
         echo > kprobe_events
 	if echo $PROBE | grep -q OPTIMIZED; then
tools/testing/selftests/ftrace/test.d/template +1 -0
index 2cd8947edf72..d4a2500498f6 100644
@@ -5,6 +5,7 @@
 # The required tracer needs :tracer suffix, e.g. function:tracer
 # The required README string needs :README suffix, e.g. "x8/16/32/64":README
 # and the README string is treated as a fixed-string instead of regexp pattern.
+# The required debugfs interface needs :debugfs suffix, e.g. kprobes/list:debugfs
 # you have to add ".tc" extention for your testcase file
 # Note that all tests are run with "errexit" option.
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 9 lines · Jaewon Jung

Add a :debugfs requirement suffix to check interfaces under debugfs. Use it in the kprobe optimization test to report unsupported instead of failed when debugfs is unavailable.

Tested on x86_64 with QEMU:
- debugfs not mounted: UNSUPPORTED
- debugfs mounted: PASS

Good improvement! Let me pick it.

Thanks!

Quoted 72 lines
---
 tools/testing/selftests/ftrace/test.d/functions        | 10 ++++++++++
 .../selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc |  4 ++--
 tools/testing/selftests/ftrace/test.d/template         |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +10 -0
index 826141e299e5..3cf8ac5fb4d4 100644
@@ -145,6 +145,7 @@ check_requires() { # Check required files and tracers
 	p=${i%:program}
         r=${i%:README}
         t=${i%:tracer}
+	d=${i%:debugfs}
 	if [ "$p" != "$i" ]; then
 	    if ! which "$p" ; then
                 echo "Required program $p is not found."
@@ -166,6 +167,15 @@ check_requires() { # Check required files and tracers
                 echo "Required feature pattern \"$r\" is not in README."
                 exit_unsupported
             fi
+	elif [ "$d" != "$i" ]; then
+	    DEBUGFS_DIR=$(awk '$3 == "debugfs" { print $2; exit }' /proc/mounts)
+	    if [ -z "$DEBUGFS_DIR" ]; then
+		echo "Required filesystem debugfs is not mounted."
+		exit_unsupported
+	    elif [ ! -e "$DEBUGFS_DIR/$d" ]; then
+		echo "Required debugfs interface $d doesn't exist."
+		exit_unsupported
+	    fi
         elif [ ! -e "$i" ]; then
             echo "Required feature interface $i doesn't exist."
             exit_unsupported
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc +2 -2
index 9f5d99328086..25f7192f887b 100644
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (C) 2023 Akanksha J N, IBM corporation
 # description: Register/unregister optimized probe
-# requires: kprobe_events
+# requires: kprobe_events kprobes/list:debugfs
 
 case `uname -m` in
 x86_64)
@@ -22,7 +22,7 @@ for i in `seq 0 255`; do
         echo  "p:testprobe $FUNCTION_FORK+${i}" > kprobe_events || continue
         echo 1 > events/kprobes/enable || continue
         (echo "forked")
-	PROBE=$(grep $FUNCTION_FORK /sys/kernel/debug/kprobes/list)
+	PROBE=$(grep $FUNCTION_FORK "$DEBUGFS_DIR/kprobes/list")
         echo 0 > events/kprobes/enable
         echo > kprobe_events
 	if echo $PROBE | grep -q OPTIMIZED; then
tools/testing/selftests/ftrace/test.d/template +1 -0
index 2cd8947edf72..d4a2500498f6 100644
@@ -5,6 +5,7 @@
 # The required tracer needs :tracer suffix, e.g. function:tracer
 # The required README string needs :README suffix, e.g. "x8/16/32/64":README
 # and the README string is treated as a fixed-string instead of regexp pattern.
+# The required debugfs interface needs :debugfs suffix, e.g. kprobes/list:debugfs
 # you have to add ".tc" extention for your testcase file
 # Note that all tests are run with "errexit" option.
 
Signature · 1 line
2.43.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>