ftrace/selftest: Fix ftracetest for non existant config and files
Steven Rostedt
maintainercover ftrace/selftest: Fix ftracetest for non existant config and files
Hi Masami,
I worked a bit more on the one issue that Po-Hsu found, and made it use tracefs a bit more aggressively. To test this I ran the test on a 3.5 kernel and found another issue, where it failed because set_event_pid and set_ftrace_pid did not exist.
Can you review these patches. I can take them in my tree, or if Shuah would like, she can take it in hers (after you give a review).
Thanks!
-- Steve
Steven Rostedt (VMware) (2):
ftrace/selftests: Return the skip code when tracing directory not configured in kernel ftrace/selftest: Test if set_event/ftrace_pid exists before writing
----
tools/testing/selftests/ftrace/ftracetest | 38 +++++++++++++++++++++---- tools/testing/selftests/ftrace/test.d/functions | 4 +-- 2 files changed, 34 insertions(+), 8 deletions(-)
Steven Rostedt
maintainerPATCH 1/2 ftrace/selftests: Return the skip code when tracing directory not configured in kernel
From: "Steven Rostedt (VMware)" <[email protected]>
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.
--- tools/testing/selftests/ftrace/ftracetest | 38 +++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-)
tools/testing/selftests/ftrace/ftracetest +32 -6
@@ -23,9 +23,15 @@ echo " If <dir> is -, all logs output in console only" exit $1 } +# default error +err_ret=1 + +# kselftest skip code is 4 +err_skip=4 + errexit() { # message echo "Error: $1" 1>&2 - exit 1 + exit $err_ret } # Ensuring user privilege
@@ -116,11 +122,31 @@ parse_opts() { # opts } # Parameters -DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` -if [ -z "$DEBUGFS_DIR" ]; then - TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` -else - TRACING_DIR=$DEBUGFS_DIR/tracing +TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` +if [ -z "$TRACING_DIR" ]; then + DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` + if [ -z "$DEBUGFS_DIR" ]; then + # If tracefs exists, then so does /sys/kernel/tracing + if [ -d "/sys/kernel/tracing" ]; then + mount -t tracefs nodev /sys/kernel/tracing || + errexit "Failed to mount /sys/kernel/tracing" + TRACING_DIR="/sys/kernel/tracing" + # If debugfs exists, then so does /sys/kernel/debug + elif [ -d "/sys/kernel/debug" ]; then + mount -t debugfs nodev /sys/kernel/debug || + errexit "Failed to mount /sys/kernel/debug" + TRACING_DIR="/sys/kernel/debug/tracing" + else + err_ret=$err_skip + errexit "debugfs and tracefs are not configured in this kernel" + fi + else + TRACING_DIR="$DEBUGFS_DIR/tracing" + fi +fi +if [ ! -d "$TRACING_DIR" ]; then + err_ret=$err_skip + errexit "ftrace is not configured in this kernel" fi TOP_DIR=`absdir $0`
Signature · 1 line
2.20.1
Re: [PATCH 1/2] ftrace/selftests: Return the skip code when tracing directory not configured in kernel
Quoted 58 lines · On Wed, 03 Jul 2019 15:50:00 -0400 Steven Rostedt <[email protected]> wrote:
From: "Steven Rostedt (VMware)" <[email protected]>
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/tracingdirectory exists. If it does than tracefs is configured in the kernel and an attempt to mount it is performed.If
/sys/kernel/tracingdoes not exist, then/sys/kernel/debugis 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.
Reported-by Po-Hsu Lin <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>--- tools/testing/selftests/ftrace/ftracetest | 38 +++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-)tools/testing/selftests/ftrace/ftracetest +7
-1@@ -23,9 +23,15 @@ echo " If <dir> is -, all logs output in console only" exit $1 } +# default error +err_ret=1 + +# kselftest skip code is 4 +err_skip=4 + errexit() { # message echo "Error: $1" 1>&2 - exit 1 + exit $err_ret } # Ensuring user privilege@@ -116,11 +122,31 @@ parse_opts() { # opts } # Parameters
tools/testing/selftests/ftrace/ftracetest parse_opts() { # opts · line 129
Quoted 10 lines
tools/testing/selftests/ftrace/ftracetest +5
-5-DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` -if [ -z "$DEBUGFS_DIR" ]; then - TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` -else - TRACING_DIR=$DEBUGFS_DIR/tracing +TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` +if [ -z "$TRACING_DIR" ]; then + DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` + if [ -z "$DEBUGFS_DIR" ]; then + # If tracefs exists, then so does /sys/kernel/tracing
Ah, indeed. the mount point also may not exist on older kernel.
OK, this looks good to me.
Thank you!
Quoted 27 lines
tools/testing/selftests/ftrace/ftracetest +20
-0+ if [ -d "/sys/kernel/tracing" ]; then + mount -t tracefs nodev /sys/kernel/tracing || + errexit "Failed to mount /sys/kernel/tracing" + TRACING_DIR="/sys/kernel/tracing" + # If debugfs exists, then so does /sys/kernel/debug + elif [ -d "/sys/kernel/debug" ]; then + mount -t debugfs nodev /sys/kernel/debug || + errexit "Failed to mount /sys/kernel/debug" + TRACING_DIR="/sys/kernel/debug/tracing" + else + err_ret=$err_skip + errexit "debugfs and tracefs are not configured in this kernel" + fi + else + TRACING_DIR="$DEBUGFS_DIR/tracing" + fi +fi +if [ ! -d "$TRACING_DIR" ]; then + err_ret=$err_skip + errexit "ftrace is not configured in this kernel" fi TOP_DIR=`absdir $0`Signature · 1 line
2.20.1
Signature · 1 line
Masami Hiramatsu <[email protected]>
Steven Rostedt
maintainerPATCH 2/2 ftrace/selftest: Test if set_event/ftrace_pid exists before writing
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
While testing on a very old kernel (3.5), the tests failed because the write to set_event_pid in the setup code, did not exist. The tests themselves could pass, but the setup failed causing an error.
Other files test for existance before writing to them. Do the same for set_event_pid and set_ftrace_pid.
--- tools/testing/selftests/ftrace/test.d/functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +2 -2
@@ -91,8 +91,8 @@ initialize_ftrace() { # Reset ftrace to initial-state reset_events_filter reset_ftrace_filter disable_events - echo > set_event_pid # event tracer is always on - echo > set_ftrace_pid + [ -f set_event_pid ] && echo > set_event_pid # event tracer is always on + [ -f set_ftrace_pid ] && echo > set_ftrace_pid [ -f set_ftrace_filter ] && echo | tee set_ftrace_* [ -f set_graph_function ] && echo | tee set_graph_* [ -f stack_trace_filter ] && echo > stack_trace_filter
Signature · 1 line
2.20.1
Steven Rostedt
maintainerRe: [PATCH 2/2] ftrace/selftest: Test if set_event/ftrace_pid exists before writing
Quoted 19 lines · On Wed, 03 Jul 2019 15:50:01 -0400 Steven Rostedt <[email protected]> wrote:
From: "Steven Rostedt (VMware)" <[email protected]>
While testing on a very old kernel (3.5), the tests failed because the write to
set_event_pidin the setup code, did not exist. The tests themselves could pass, but the setup failed causing an error.Other files test for existance before writing to them. Do the same for
set_event_pidandset_ftrace_pid.Signed-off-by Steven Rostedt (VMware) <[email protected]>--- tools/testing/selftests/ftrace/test.d/functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/ftrace/test.d/functions +0
-0
tools/testing/selftests/ftrace/test.d/functions initialize_ftrace() { # Reset ftrace to initial-state · line 94
Quoted 6 lines
tools/testing/selftests/ftrace/test.d/functions +1
-2@@ -91,8 +91,8 @@ initialize_ftrace() { # Reset ftrace to initial-state reset_events_filter reset_ftrace_filter disable_events - echo > set_event_pid # event tracer is always on - echo > set_ftrace_pid + [ -f set_event_pid ] && echo > set_event_pid # event tracer is always on
I probably should remove that comment, because I believe that was why it wasn't tested :-/
-- Steve
Quoted 4 lines
tools/testing/selftests/ftrace/test.d/functions +1
-0+ [ -f set_ftrace_pid ] && echo > set_ftrace_pid [ -f set_ftrace_filter ] && echo | tee set_ftrace_* [ -f set_graph_function ] && echo | tee set_graph_* [ -f stack_trace_filter ] && echo > stack_trace_filter
Steven Rostedt
maintainerRe: [PATCH 2/2] ftrace/selftest: Test if set_event/ftrace_pid exists before writing
Quoted 6 lines · On Wed, 3 Jul 2019 16:00:09 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 6 lines
tools/testing/selftests/ftrace/test.d/functions +0
-0@@ -91,8 +91,8 @@ initialize_ftrace() { # Reset ftrace to initial-state reset_events_filter
Quoted 8 lines
tools/testing/selftests/ftrace/test.d/functions initialize_ftrace() { # Reset ftrace to initial-state · line 94
Quoted 5 lines
tools/testing/selftests/ftrace/test.d/functions +1
-2reset_ftrace_filter disable_events - echo > set_event_pid # event tracer is always on - echo > set_ftrace_pid + [ -f set_event_pid ] && echo > set_event_pid # event tracer is always onI probably should remove that comment, because I believe that was why it wasn't tested :-/
Masami,
I'll wait for your review before posting a v2 without this comment.
-- Steve
Masami Hiramatsu
maintainerRe: [PATCH 2/2] ftrace/selftest: Test if set_event/ftrace_pid exists before writing
In reply to Steven RostedtQuoted 17 lines · On Wed, 3 Jul 2019 16:00:09 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 14 lines · On Wed, 03 Jul 2019 15:50:01 -0400 Steven Rostedt <[email protected]> wrote:
From: "Steven Rostedt (VMware)" <[email protected]>
While testing on a very old kernel (3.5), the tests failed because the write to
set_event_pidin the setup code, did not exist. The tests themselves could pass, but the setup failed causing an error.Other files test for existance before writing to them. Do the same for
set_event_pidandset_ftrace_pid.Signed-off-by Steven Rostedt (VMware) <[email protected]>--- tools/testing/selftests/ftrace/test.d/functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines
tools/testing/selftests/ftrace/test.d/functions initialize_ftrace() { # Reset ftrace to initial-state · line 94
Quoted 11 lines
tools/testing/selftests/ftrace/test.d/functions +1
-2@@ -91,8 +91,8 @@ initialize_ftrace() { # Reset ftrace to initial-state reset_events_filter reset_ftrace_filter disable_events - echo > set_event_pid # event tracer is always on - echo > set_ftrace_pid + [ -f set_event_pid ] && echo > set_event_pid # event tracer is always onI probably should remove that comment, because I believe that was why it wasn't tested :-/
Hmm, OK. I think this comment means "the event tracer is always on if clearing set_event_pid filter". Would this need to be removed?
Thank you,
Quoted 9 lines
-- Steve
Quoted 4 lines
tools/testing/selftests/ftrace/test.d/functions +1
-0+ [ -f set_ftrace_pid ] && echo > set_ftrace_pid [ -f set_ftrace_filter ] && echo | tee set_ftrace_* [ -f set_graph_function ] && echo | tee set_graph_* [ -f stack_trace_filter ] && echo > stack_trace_filter
Signature · 1 line
Masami Hiramatsu <[email protected]>
Steven Rostedt
maintainerRe: [PATCH 2/2] ftrace/selftest: Test if set_event/ftrace_pid exists before writing
Quoted 15 lines · On Thu, 4 Jul 2019 10:51:26 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
tools/testing/selftests/ftrace/test.d/functions +0
-0@@ -91,8 +91,8 @@ initialize_ftrace() { # Reset ftrace to initial-state reset_events_filterQuoted 8 lines
tools/testing/selftests/ftrace/test.d/functions initialize_ftrace() { # Reset ftrace to initial-state · line 94
Quoted 5 lines
tools/testing/selftests/ftrace/test.d/functions +1
-2reset_ftrace_filter disable_events - echo > set_event_pid # event tracer is always on - echo > set_ftrace_pid + [ -f set_event_pid ] && echo > set_event_pid # event tracer is always onI probably should remove that comment, because I believe that was why it wasn't tested :-/
Quoted 2 lines
Hmm, OK. I think this comment means "the event tracer is always on if clearing
set_event_pidfilter". Would this need to be removed?
When this was added in commit 131f840d5b7 ("selftests: ftrace:
Initialize ftrace before each test"), we had this:
+ echo > set_event_pid # event tracer is always on + [ -f set_ftrace_filter ] && echo | tee set_ftrace_* + [ -f set_graph_function ] && echo | tee set_graph_* + [ -f stack_trace_filter ] && echo > stack_trace_filter + [ -f kprobe_events ] && echo > kprobe_events + [ -f uprobe_events ] && echo > uprobe_events
Where set_event_pid is the only file not tested for existence. I figured that comment was the reason for not testing it. If that was the case, then adding a test, I would think we should remove the comment.
Do you agree?
-- Steve
Quoted 14 lines
Thank you,
Quoted 9 lines
-- Steve
Quoted 4 lines
tools/testing/selftests/ftrace/test.d/functions +1
-0+ [ -f set_ftrace_pid ] && echo > set_ftrace_pid [ -f set_ftrace_filter ] && echo | tee set_ftrace_* [ -f set_graph_function ] && echo | tee set_graph_* [ -f stack_trace_filter ] && echo > stack_trace_filter
Masami Hiramatsu
maintainerRe: [PATCH 2/2] ftrace/selftest: Test if set_event/ftrace_pid exists before writing
Quoted 31 lines · On Wed, 3 Jul 2019 22:01:05 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 15 lines · On Thu, 4 Jul 2019 10:51:26 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
tools/testing/selftests/ftrace/test.d/functions +0
-0@@ -91,8 +91,8 @@ initialize_ftrace() { # Reset ftrace to initial-state reset_events_filterQuoted 8 lines
tools/testing/selftests/ftrace/test.d/functions initialize_ftrace() { # Reset ftrace to initial-state · line 94
Quoted 5 lines
tools/testing/selftests/ftrace/test.d/functions +1
-2reset_ftrace_filter disable_events - echo > set_event_pid # event tracer is always on - echo > set_ftrace_pid + [ -f set_event_pid ] && echo > set_event_pid # event tracer is always onI probably should remove that comment, because I believe that was why it wasn't tested :-/
Quoted 2 lines
Hmm, OK. I think this comment means "the event tracer is always on if clearing
set_event_pidfilter". Would this need to be removed?When this was added in commit
131f840d5b7("selftests: ftrace:
Initialize ftrace before each test"), we had this:(quoted diff) +6
-0+ echo > set_event_pid # event tracer is always on + [ -f set_ftrace_filter ] && echo | tee set_ftrace_* + [ -f set_graph_function ] && echo | tee set_graph_* + [ -f stack_trace_filter ] && echo > stack_trace_filter + [ -f kprobe_events ] && echo > kprobe_events + [ -f uprobe_events ] && echo > uprobe_events
Quoted 3 lines
Where
set_event_pidis the only file not tested for existence. I figured that comment was the reason for not testing it. If that was the case, then adding a test, I would think we should remove the comment.
Ah, I see.
Quoted 2 lines
Do you agree?
Yes, I agree with removing it.
Thank you!
Quoted 19 lines
-- Steve
Quoted 14 lines
Thank you,
Quoted 9 lines
-- Steve
Quoted 4 lines
tools/testing/selftests/ftrace/test.d/functions +1
-0+ [ -f set_ftrace_pid ] && echo > set_ftrace_pid [ -f set_ftrace_filter ] && echo | tee set_ftrace_* [ -f set_graph_function ] && echo | tee set_graph_* [ -f stack_trace_filter ] && echo > stack_trace_filter
Signature · 1 line
Masami Hiramatsu <[email protected]>
Re: [PATCH 2/2] ftrace/selftest: Test if set_event/ftrace_pid exists before writing
In reply to Steven RostedtQuoted 6 lines · On Wed, 03 Jul 2019 15:50:01 -0400 Steven Rostedt <[email protected]> wrote:
From: "Steven Rostedt (VMware)" <[email protected]>
While testing on a very old kernel (3.5), the tests failed because the write to
set_event_pidin the setup code, did not exist. The tests themselves could pass, but the setup failed causing an error.
Oops, I've missed it.
Quoted 2 lines
Other files test for existance before writing to them. Do the same for
set_event_pidandset_ftrace_pid.
Looks good to me,
Thank you!
Quoted 25 lines
Signed-off-by Steven Rostedt (VMware) <[email protected]>--- tools/testing/selftests/ftrace/test.d/functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/ftrace/test.d/functions +2
-2@@ -91,8 +91,8 @@ initialize_ftrace() { # Reset ftrace to initial-state reset_events_filter reset_ftrace_filter disable_events - echo > set_event_pid # event tracer is always on - echo > set_ftrace_pid + [ -f set_event_pid ] && echo > set_event_pid # event tracer is always on + [ -f set_ftrace_pid ] && echo > set_ftrace_pid [ -f set_ftrace_filter ] && echo | tee set_ftrace_* [ -f set_graph_function ] && echo | tee set_graph_* [ -f stack_trace_filter ] && echo > stack_trace_filterSignature · 1 line
2.20.1
Signature · 1 line
Masami Hiramatsu <[email protected]>