Skip to contentSkip to conversation

selftests/ftrace: Fix ftracetest testcases for non-function tracer case

PATCH Superseded Masami Hiramatsu 2 participants 9 messages Nov 24, 2019

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

cover selftests/ftrace: Fix ftracetest testcases for non-function tracer case

Hi,

Here is a series of patches to fix some issues which happens on the kernel with CONFIG_FUNCTION_TRACER=n but CONFIG_TRACER=y.

Thank you,

---

Masami Hiramatsu (3):
selftests/ftrace: Fix to check the existence of set_ftrace_filter selftests/ftrace: Fix ftrace test cases to check unsupported selftests/ftrace: Do not to use absolute debugfs path

 .../ftrace/test.d/ftrace/func-filter-stacktrace.tc |    2 ++
 .../selftests/ftrace/test.d/ftrace/func_cpumask.tc |    5 +++++
 tools/testing/selftests/ftrace/test.d/functions    |    4 +++-
 .../inter-event/trigger-action-hist-xfail.tc       |    4 ++--
 .../inter-event/trigger-onchange-action-hist.tc    |    2 +-
 .../inter-event/trigger-snapshot-action-hist.tc    |    4 ++--
 6 files changed, 15 insertions(+), 6 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/3 selftests/ftrace: Fix to check the existence of set_ftrace_filter

If we run ftracetest on the kernel with CONFIG_FUNCTION_TRACER=n, there is no set_ftrace_filter and all test cases are failed, because reset_ftrace_filter returns an error.
Let's check whether set_ftrace_filter exists and remove redundant set_ftrace_filter from initialize_ftrace().

---
 tools/testing/selftests/ftrace/test.d/functions |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/functions +3 -1
index 86986c4bba54..19d288cdf336 100644
@@ -46,6 +46,9 @@ reset_events_filter() { # reset all current setting filters
 }
 
 reset_ftrace_filter() { # reset all triggers in set_ftrace_filter
+    if [ ! -f set_ftrace_filter ]; then
+      return 0
+    fi
     echo > set_ftrace_filter
     grep -v '^#' set_ftrace_filter | while read t; do
 	tr=`echo $t | cut -d: -f2`
@@ -93,7 +96,6 @@ initialize_ftrace() { # Reset ftrace to initial-state
     disable_events
     [ -f set_event_pid ] && echo > set_event_pid
     [ -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
     [ -f kprobe_events ] && echo > kprobe_events
author maintainer
#4 lore raw

PATCH 2/3 selftests/ftrace: Fix ftrace test cases to check unsupported

In reply to Masami Hiramatsu

Since function tracer can be disabled, set_ftrace_filter can be disappeared. The test cases must check whether the set_ftrace_filter exists or not before testing and if not, return it as unsupported.

---
 .../ftrace/test.d/ftrace/func-filter-stacktrace.tc |    2 ++
 .../selftests/ftrace/test.d/ftrace/func_cpumask.tc |    5 +++++
 2 files changed, 7 insertions(+)
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-stacktrace.tc +2 -0
index 36fb59f886ea..1a52f2883fe0 100644
@@ -3,6 +3,8 @@
 # description: ftrace - stacktrace filter command
 # flags: instance
 
+[ ! -f set_ftrace_filter ] && exit_unsupported
+
 echo _do_fork:stacktrace >> set_ftrace_filter
 
 grep -q "_do_fork:stacktrace:unlimited" set_ftrace_filter
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +5 -0
index 86a1f07ef2ca..7757b549f0b6 100644
@@ -15,6 +15,11 @@ if [ $NP -eq 1 ] ;then
   exit_unresolved
 fi
 
+if ! grep -q function available_tracers ; then
+  echo "Function trace is not enabled"
+  exit_unsupported
+fi
+
 ORIG_CPUMASK=`cat tracing_cpumask`
 
 do_reset() {
author maintainer
#7 lore raw

PATCH 3/3 selftests/ftrace: Do not to use absolute debugfs path

In reply to Masami Hiramatsu

Use relative path to trigger file instead of absolute debugfs path, because if the user uses tracefs instead of debugfs, it can be mounted at /sys/kernel/tracing.
Anyway, since the ftracetest is designed to be run at the tracing directory, user doesn't need to use absolute path.

---
 .../inter-event/trigger-action-hist-xfail.tc       |    4 ++--
 .../inter-event/trigger-onchange-action-hist.tc    |    2 +-
 .../inter-event/trigger-snapshot-action-hist.tc    |    4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-action-hist-xfail.tc +2 -2
index 1221240f8cf6..3f2aee115f6e 100644
@@ -21,10 +21,10 @@ grep -q "snapshot()" README || exit_unsupported # version issue
 
 echo "Test expected snapshot action failure"
 
-echo 'hist:keys=comm:onmatch(sched.sched_wakeup).snapshot()' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger && exit_fail
+echo 'hist:keys=comm:onmatch(sched.sched_wakeup).snapshot()' >> events/sched/sched_waking/trigger && exit_fail
 
 echo "Test expected save action failure"
 
-echo 'hist:keys=comm:onmatch(sched.sched_wakeup).save(comm,prio)' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger && exit_fail
+echo 'hist:keys=comm:onmatch(sched.sched_wakeup).save(comm,prio)' >> events/sched/sched_waking/trigger && exit_fail
 
 exit_xfail
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-onchange-action-hist.tc +1 -1
index 064a284e4e75..c80007aa9f86 100644
@@ -16,7 +16,7 @@ grep -q "onchange(var)" README || exit_unsupported # version issue
 
 echo "Test onchange action"
 
-echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio) if comm=="ping"' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
+echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio) if comm=="ping"' >> events/sched/sched_waking/trigger
 
 ping $LOCALHOST -c 3
 nice -n 1 ping $LOCALHOST -c 3
tools/testing/selftests/ftrace/test.d/trigger/inter-event/trigger-snapshot-action-hist.tc +2 -2
index 18fff69fc433..f546c1b66a9b 100644
@@ -23,9 +23,9 @@ grep -q "snapshot()" README || exit_unsupported # version issue
 
 echo "Test snapshot action"
 
-echo 1 > /sys/kernel/debug/tracing/events/sched/enable
+echo 1 > events/sched/enable
 
-echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio):onchange($newprio).snapshot() if comm=="ping"' >> /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
+echo 'hist:keys=comm:newprio=prio:onchange($newprio).save(comm,prio):onchange($newprio).snapshot() if comm=="ping"' >> events/sched/sched_waking/trigger
 
 ping $LOCALHOST -c 3
 nice -n 1 ping $LOCALHOST -c 3
maintainer
#2 lore raw

Re: [BUGFIX PATCH 1/3] selftests/ftrace: Fix to check the existence of set_ftrace_filter

In reply to Masami Hiramatsu
Quoted 2 lines · On Sun, 24 Nov 2019 13:55:39 +0900 Masami Hiramatsu <[email protected]> wrote:

If we run ftracetest on the kernel with CONFIG_FUNCTION_TRACER=n, there is no set_ftrace_filter and all test cases are failed,

Note, that we can have CONFIG_FUNCTION_TRACER=y and there be no set_ftrace_filter. That is determined by CONFIG_DYNAMIC_FTRACE. I guess we should probably still check for that for this test, but I just wanted to state that set_ftrace_filter is not dependent on FUNCTION_TRACER but instead DYNAMIC_FTRACE.

Quoted 24 lines

because reset_ftrace_filter returns an error.
Let's check whether set_ftrace_filter exists and remove redundant set_ftrace_filter from initialize_ftrace().

---
 tools/testing/selftests/ftrace/test.d/functions |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/functions +3 -0
index 86986c4bba54..19d288cdf336 100644
@@ -46,6 +46,9 @@ reset_events_filter() { # reset all current setting filters
 }
 
 reset_ftrace_filter() { # reset all triggers in set_ftrace_filter
+    if [ ! -f set_ftrace_filter ]; then
+      return 0
+    fi
     echo > set_ftrace_filter
     grep -v '^#' set_ftrace_filter | while read t; do
 	tr=`echo $t | cut -d: -f2`

tools/testing/selftests/ftrace/test.d/functions initialize_ftrace() { # Reset ftrace to initial-state · line 96

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/functions +0 -1
@@ -93,7 +96,6 @@ initialize_ftrace() { # Reset ftrace to initial-state
     disable_events
     [ -f set_event_pid ] && echo > set_event_pid
     [ -f set_ftrace_pid ] && echo > set_ftrace_pid
-    [ -f set_ftrace_filter ] && echo | tee set_ftrace_*

This also resets set_ftrace_notrace, which reset_ftrace_filter does not.

-- Steve

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/functions +0 -0
     [ -f set_graph_function ] && echo | tee set_graph_*
     [ -f stack_trace_filter ] && echo > stack_trace_filter
     [ -f kprobe_events ] && echo > kprobe_events
maintainer
#5 lore raw

Re: [BUGFIX PATCH 2/3] selftests/ftrace: Fix ftrace test cases to check unsupported

In reply to Masami Hiramatsu
Quoted 28 lines · On Sun, 24 Nov 2019 13:55:48 +0900 Masami Hiramatsu <[email protected]> wrote:

Since function tracer can be disabled, set_ftrace_filter can be disappeared. The test cases must check whether the set_ftrace_filter exists or not before testing and if not, return it as unsupported.

---
 .../ftrace/test.d/ftrace/func-filter-stacktrace.tc |    2 ++
 .../selftests/ftrace/test.d/ftrace/func_cpumask.tc |    5 +++++
 2 files changed, 7 insertions(+)
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-stacktrace.tc +2 -0
index 36fb59f886ea..1a52f2883fe0 100644
@@ -3,6 +3,8 @@
 # description: ftrace - stacktrace filter command
 # flags: instance
 
+[ ! -f set_ftrace_filter ] && exit_unsupported
+
 echo _do_fork:stacktrace >> set_ftrace_filter
 
 grep -q "_do_fork:stacktrace:unlimited" set_ftrace_filter
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +0 -0
index 86a1f07ef2ca..7757b549f0b6 100644

tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc if [ $NP -eq 1 ] ;then · line 21

Quoted 7 lines
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +4 -0
@@ -15,6 +15,11 @@ if [ $NP -eq 1 ] ;then
   exit_unresolved
 fi
 
+if ! grep -q function available_tracers ; then
+  echo "Function trace is not enabled"
+  exit_unsupported
+fi

This change is not described in the change log.

-- Steve

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +1 -0
+
 ORIG_CPUMASK=`cat tracing_cpumask`
 
 do_reset() {
maintainer Reviewed-by on v1 3/3
#8 lore raw

Re: [BUGFIX PATCH 3/3] selftests/ftrace: Do not to use absolute debugfs path

In reply to Masami Hiramatsu
Quoted 8 lines · On Sun, 24 Nov 2019 13:55:57 +0900 Masami Hiramatsu <[email protected]> wrote:

Use relative path to trigger file instead of absolute debugfs path, because if the user uses tracefs instead of debugfs, it can be mounted at /sys/kernel/tracing.
Anyway, since the ftracetest is designed to be run at the tracing directory, user doesn't need to use absolute path.

-- Steve

author maintainer
#3 lore raw

Re: [BUGFIX PATCH 1/3] selftests/ftrace: Fix to check the existence of set_ftrace_filter

In reply to Steven Rostedt
Quoted 11 lines · On Sun, 24 Nov 2019 16:35:29 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 2 lines · On Sun, 24 Nov 2019 13:55:39 +0900 Masami Hiramatsu <[email protected]> wrote:

If we run ftracetest on the kernel with CONFIG_FUNCTION_TRACER=n, there is no set_ftrace_filter and all test cases are failed,

Note, that we can have CONFIG_FUNCTION_TRACER=y and there be no set_ftrace_filter. That is determined by CONFIG_DYNAMIC_FTRACE. I guess we should probably still check for that for this test, but I just wanted to state that set_ftrace_filter is not dependent on FUNCTION_TRACER but instead DYNAMIC_FTRACE.

Ah, good catch! I always set DYNAMIC_FTRACE=y if FUNCTION_TRACER=y. OK, I'll update the description.

Thank you,

Quoted 40 lines
Quoted 26 lines

because reset_ftrace_filter returns an error.
Let's check whether set_ftrace_filter exists and remove redundant set_ftrace_filter from initialize_ftrace().

---
 tools/testing/selftests/ftrace/test.d/functions |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/functions +3 -0
index 86986c4bba54..19d288cdf336 100644
@@ -46,6 +46,9 @@ reset_events_filter() { # reset all current setting filters
 }
 
 reset_ftrace_filter() { # reset all triggers in set_ftrace_filter
+    if [ ! -f set_ftrace_filter ]; then
+      return 0
+    fi
     echo > set_ftrace_filter
     grep -v '^#' set_ftrace_filter | while read t; do
 	tr=`echo $t | cut -d: -f2`

tools/testing/selftests/ftrace/test.d/functions initialize_ftrace() { # Reset ftrace to initial-state · line 96

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/functions +0 -1
@@ -93,7 +96,6 @@ initialize_ftrace() { # Reset ftrace to initial-state
     disable_events
     [ -f set_event_pid ] && echo > set_event_pid
     [ -f set_ftrace_pid ] && echo > set_ftrace_pid
-    [ -f set_ftrace_filter ] && echo | tee set_ftrace_*

This also resets set_ftrace_notrace, which reset_ftrace_filter does not.

-- Steve

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/functions +0 -0
     [ -f set_graph_function ] && echo | tee set_graph_*
     [ -f stack_trace_filter ] && echo > stack_trace_filter
     [ -f kprobe_events ] && echo > kprobe_events
Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#6 lore raw

Re: [BUGFIX PATCH 2/3] selftests/ftrace: Fix ftrace test cases to check unsupported

In reply to Steven Rostedt
Quoted 34 lines · On Sun, 24 Nov 2019 16:39:57 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 31 lines · On Sun, 24 Nov 2019 13:55:48 +0900 Masami Hiramatsu <[email protected]> wrote:

Since function tracer can be disabled, set_ftrace_filter can be disappeared. The test cases must check whether the set_ftrace_filter exists or not before testing and if not, return it as unsupported.

---
 .../ftrace/test.d/ftrace/func-filter-stacktrace.tc |    2 ++
 .../selftests/ftrace/test.d/ftrace/func_cpumask.tc |    5 +++++
 2 files changed, 7 insertions(+)
tools/testing/selftests/ftrace/test.d/ftrace/func-filter-stacktrace.tc +2 -0
index 36fb59f886ea..1a52f2883fe0 100644
@@ -3,6 +3,8 @@
 # description: ftrace - stacktrace filter command
 # flags: instance
 
+[ ! -f set_ftrace_filter ] && exit_unsupported
+
 echo _do_fork:stacktrace >> set_ftrace_filter
 
 grep -q "_do_fork:stacktrace:unlimited" set_ftrace_filter
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +0 -0
index 86a1f07ef2ca..7757b549f0b6 100644
@@ -15,6 +15,11 @@ if [ $NP -eq 1 ] ;then
   exit_unresolved
 fi
 
Quoted 6 lines

tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc if [ $NP -eq 1 ] ;then · line 21

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +4 -0
+if ! grep -q function available_tracers ; then
+  echo "Function trace is not enabled"
+  exit_unsupported
+fi

This change is not described in the change log.

Oops, my mistake. Thanks!

Quoted 8 lines

-- Steve

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/ftrace/func_cpumask.tc +1 -0
+
 ORIG_CPUMASK=`cat tracing_cpumask`
 
 do_reset() {
Signature · 1 line
Masami Hiramatsu <[email protected]>