selftests: ftrace: Initialize ftrace before each test
authorMasami Hiramatsu <mhiramat@kernel.org>
Wed, 16 Nov 2016 08:13:02 +0000 (17:13 +0900)
committerSteven Rostedt <rostedt@goodmis.org>
Tue, 22 Nov 2016 18:30:58 +0000 (13:30 -0500)
Reset ftrace to initial state before running each test.
This fixes some test cases to enable tracing before starting
trace test. This can avoid false-positive failure when
previous testcase fails while disabling tracing.

Link: http://lkml.kernel.org/r/147928398192.22982.7767460638302113002.stgit@devbox
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
tools/testing/selftests/ftrace/ftracetest
tools/testing/selftests/ftrace/test.d/functions

index 4c6a0bf8ba79971143508580b92534b58eb8df00..a03d366a4a2fc0f86732a6406c57eb78aa4acc0b 100755 (executable)
@@ -228,7 +228,7 @@ trap 'SIG_RESULT=$XFAIL' $SIG_XFAIL
 
 __run_test() { # testfile
   # setup PID and PPID, $$ is not updated.
-  (cd $TRACING_DIR; read PID _ < /proc/self/stat ; set -e; set -x; . $1)
+  (cd $TRACING_DIR; read PID _ < /proc/self/stat; set -e; set -x; initialize_ftrace; . $1)
   [ $? -ne 0 ] && kill -s $SIG_FAIL $SIG_PID
 }
 
index c37262f6c269fecf51c9d3ac664a39bb62700f3d..91de1a8e4f197808215d431d31343071a4c4221f 100644 (file)
@@ -23,3 +23,31 @@ reset_trigger() { # reset all current setting triggers
     done
 }
 
+reset_events_filter() { # reset all current setting filters
+    grep -v ^none events/*/*/filter |
+    while read line; do
+       echo 0 > `echo $line | cut -f1 -d:`
+    done
+}
+
+disable_events() {
+    echo 0 > events/enable
+}
+
+initialize_ftrace() { # Reset ftrace to initial-state
+# As the initial state, ftrace will be set to nop tracer,
+# no events, no triggers, no filters, no function filters,
+# no probes, and tracing on.
+    disable_tracing
+    reset_tracer
+    reset_trigger
+    reset_events_filter
+    disable_events
+    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
+    enable_tracing
+}