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

Signed-off-by: Jaewon Jung <[email protected]>
---
 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(-)

diff --git a/tools/testing/selftests/ftrace/test.d/functions 
b/tools/testing/selftests/ftrace/test.d/functions
index 826141e299e5..3cf8ac5fb4d4 100644
--- a/tools/testing/selftests/ftrace/test.d/functions
+++ b/tools/testing/selftests/ftrace/test.d/functions
@@ -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
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc 
b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc
index 9f5d99328086..25f7192f887b 100644
--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_opt_types.tc
@@ -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
diff --git a/tools/testing/selftests/ftrace/test.d/template 
b/tools/testing/selftests/ftrace/test.d/template
index 2cd8947edf72..d4a2500498f6 100644
--- a/tools/testing/selftests/ftrace/test.d/template
+++ b/tools/testing/selftests/ftrace/test.d/template
@@ -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.
 
-- 
2.43.0


Reply via email to