Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ftrace/selftests: Return the skip code when tracing directory not configured in kernel

If the kernel is not configured with ftrace enabled, the ftracetest
selftests should return the error code of "4" as that is the kselftests
"skip" code, and not "1" which means an error.

To determine if ftrace is enabled, first the newer "tracefs" is searched for
in /proc/mounts. If it is not found, then "debugfs" is searched for (as old
kernels do not have tracefs). If that is not found, an attempt to mount the
tracefs or debugfs is performed. This is done by seeing first if the
/sys/kernel/tracing directory exists. If it does than tracefs is configured
in the kernel and an attempt to mount it is performed.

If /sys/kernel/tracing does not exist, then /sys/kernel/debug is tested to
see if that directory exists. If it does, then an attempt to mount debugfs
on that directory is performed. If it does not exist, then debugfs is not
configured in the running kernel and the test exits with the skip code.

If either mount fails, then a normal error is returned as they do exist in
the kernel but something went wrong to mount them.

This changes the test to always try the tracefs file system first as it has
been in the kernel for some time now and it is better to test it if it is
available instead of always testing debugfs.

Link: http://lkml.kernel.org/r/20190702062358.7330-1-po-hsu.lin@canonical.com

Reported-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

+32 -6
+32 -6
tools/testing/selftests/ftrace/ftracetest
··· 23 23 exit $1 24 24 } 25 25 26 + # default error 27 + err_ret=1 28 + 29 + # kselftest skip code is 4 30 + err_skip=4 31 + 26 32 errexit() { # message 27 33 echo "Error: $1" 1>&2 28 - exit 1 34 + exit $err_ret 29 35 } 30 36 31 37 # Ensuring user privilege ··· 122 116 } 123 117 124 118 # Parameters 125 - DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` 126 - if [ -z "$DEBUGFS_DIR" ]; then 127 - TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` 128 - else 129 - TRACING_DIR=$DEBUGFS_DIR/tracing 119 + TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` 120 + if [ -z "$TRACING_DIR" ]; then 121 + DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` 122 + if [ -z "$DEBUGFS_DIR" ]; then 123 + # If tracefs exists, then so does /sys/kernel/tracing 124 + if [ -d "/sys/kernel/tracing" ]; then 125 + mount -t tracefs nodev /sys/kernel/tracing || 126 + errexit "Failed to mount /sys/kernel/tracing" 127 + TRACING_DIR="/sys/kernel/tracing" 128 + # If debugfs exists, then so does /sys/kernel/debug 129 + elif [ -d "/sys/kernel/debug" ]; then 130 + mount -t debugfs nodev /sys/kernel/debug || 131 + errexit "Failed to mount /sys/kernel/debug" 132 + TRACING_DIR="/sys/kernel/debug/tracing" 133 + else 134 + err_ret=$err_skip 135 + errexit "debugfs and tracefs are not configured in this kernel" 136 + fi 137 + else 138 + TRACING_DIR="$DEBUGFS_DIR/tracing" 139 + fi 140 + fi 141 + if [ ! -d "$TRACING_DIR" ]; then 142 + err_ret=$err_skip 143 + errexit "ftrace is not configured in this kernel" 130 144 fi 131 145 132 146 TOP_DIR=`absdir $0`