Skip to contentSkip to conversation

ftracetest: Add ftrace tests to ftracetests

PATCH In review Steven Rostedt 3 participants 8 messages Nov 4, 2014 – Nov 6, 2014

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

v3 cover ftracetest: Add ftrace tests to ftracetests

Third attempt. Moved helper functions into a single patch. Removed the extra check of schedule in the trace file.

Not an RFC this time. I'm hoping this is "good enough" ;-)

Steven Rostedt (Red Hat) (2):
ftracetest: Add functions file that holds helper functions
ftracetest: Add a couple of ftrace test cases

----

 tools/testing/selftests/ftrace/ftracetest          |  3 +
 .../ftrace/test.d/ftrace/fgraph-filter-stack.tc    | 88 ++++++++++++++++++++++
 .../ftrace/test.d/ftrace/fgraph-filter.tc          | 49 ++++++++++++
 .../ftrace/test.d/ftrace/func_profiler.tc          | 76 +++++++++++++++++++
 tools/testing/selftests/ftrace/test.d/functions    | 16 ++++
 5 files changed, 232 insertions(+)
author maintainer
#1 lore raw

PATCH v3 1/2 ftracetest: Add functions file that holds helper functions

From: "Steven Rostedt (Red Hat)" <[email protected]>

Created the file tools/testing/ftrace/test.d/functions that will hold helper functions.

Current helper functions include:

Add clear_trace() helper to reset the trace file

Used as a descriptive name to show that "echo > trace" is clearing the trace file.

Add disable/enable_tracing() helper calls

Add calls that disable and enable tracing respectively by echoing 0 or 1 into tracing_on.

Add helper reset_tracer() function

Add a helper function reset_tracer() that will clear the current_tracer (echo nop > current_tracer).

---
 tools/testing/selftests/ftrace/ftracetest       |  3 +++
 tools/testing/selftests/ftrace/test.d/functions | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/functions
tools/testing/selftests/ftrace/ftracetest +3 -0
index f15c0da07aca..c6381a9faf83 100755
@@ -235,6 +235,9 @@ run_test() { # testfile
   fi
 }
 
+# load in the helper functions
+. $TEST_DIR/functions
+
 # Main loop
 for t in $TEST_CASES; do
   run_test $t
tools/testing/selftests/ftrace/test.d/functions new file +16 -0
new file mode 100644
index 000000000000..5d8cd06d920f
@@ -0,0 +1,16 @@
+
+clear_trace() { # reset trace output
+    echo > trace
+}
+
+disable_tracing() { # stop trace recording
+    echo 0 > tracing_on
+}
+
+enable_tracing() { # start trace recording
+    echo 1 > tracing_on
+}
+
+reset_tracer() { # reset the current tracer
+    echo nop > current_tracer
+}
Signature · 1 line
2.1.1
author maintainer
#2 lore raw

PATCH v3 2/2 ftracetest: Add a couple of ftrace test cases

In reply to Steven Rostedt

From: "Steven Rostedt (Red Hat)" <[email protected]>

Added three test cases to get the feel of adding tests to ftracetest. The three cases are:

function profiling test, to make sure function profiling still works
with function tracing (was a regression)

function graph filter test to make sure that function graph filtering works.

function graph filter with stack tracing test to make sure that the function
graph filter does filter and also continues to filter when another function tracer is running (like the stack tracer)

---
 .../ftrace/test.d/ftrace/fgraph-filter-stack.tc    | 88 ++++++++++++++++++++++
 .../ftrace/test.d/ftrace/fgraph-filter.tc          | 49 ++++++++++++
 .../ftrace/test.d/ftrace/func_profiler.tc          | 76 +++++++++++++++++++
 3 files changed, 213 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc new file +88 -0
new file mode 100644
index 000000000000..216d5c55776a
@@ -0,0 +1,88 @@
+#!/bin/sh
+# description: ftrace - function graph filters with stack tracer
+
+# Make sure that function graph filtering works, and is not
+# affected by other tracers enabled (like stack tracer)
+
+if ! grep -q function_graph available_tracers; then
+    echo "no function graph tracer configured"
+    exit_unsupported
+fi
+
+if [ ! -f set_ftrace_filter ]; then
+    echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
+    exit_unsupported
+fi
+
+do_reset() {
+    reset_tracer
+    echo 0 > /proc/sys/kernel/stack_tracer_enabled
+    enable_tracing
+    clear_trace
+    echo > set_ftrace_filter
+}
+
+disable_tracing
+clear_trace;
+
+# filter something, schedule is always good
+if ! echo "schedule" > set_ftrace_filter; then
+    # test for powerpc 64
+    if ! echo ".schedule" > set_ftrace_filter; then
+	echo "can not enable schedule filter"
+	exit -1
+    fi
+fi
+
+echo function_graph > current_tracer
+
+if [ ! -f stack_trace ]; then
+    echo "Stack tracer not configured"
+    do_reset
+    exit_unsupported;
+fi
+
+echo "Now testing with stack tracer"
+
+echo 1 > /proc/sys/kernel/stack_tracer_enabled
+
+disable_tracing
+clear_trace
+enable_tracing
+sleep 1
+
+count=`cat trace | grep '()' | grep -v schedule | wc -l`
+
+if [ $count -ne 0 ]; then
+    echo "Graph filtering not working with stack tracer?"
+    exit -1
+fi
+
+# Make sure we did find something
+count=`cat trace | grep 'schedule()' | wc -l` 
+if [ $count -eq 0 ]; then
+    echo "No schedule traces found?"
+    exit -1
+fi
+
+echo 0 > /proc/sys/kernel/stack_tracer_enabled
+clear_trace
+sleep 1
+
+
+count=`cat trace | grep '()' | grep -v schedule | wc -l`
+
+if [ $count -ne 0 ]; then
+    echo "Graph filtering not working after stack tracer disabled?"
+    exit -1
+fi
+
+count=`cat trace | grep 'schedule()' | wc -l` 
+if [ $count -eq 0 ]; then
+    echo "No schedule traces found?"
+    exit -1
+fi
+
+do_reset
+
+exit 0
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc new file +49 -0

49 lines not on this page · raw message

tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.1.1
#3 lore raw

Re: [PATCH 2/2 v3] ftracetest: Add a couple of ftrace test cases

Hi Steve,

tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc line 83

Quoted 11 lines · Steven Rostedt
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc new file +11 -0
+count=`cat trace | grep '()' | grep -v schedule | wc -l`
+
+if [ $count -ne 0 ]; then
+    echo "Graph filtering not working after stack tracer disabled?"
+    exit -1
+fi
+
+count=`cat trace | grep 'schedule()' | wc -l` 
+if [ $count -eq 0 ]; then
+    echo "No schedule traces found?"
+    exit -1

Hmm.. in this case don't we need to call do_reset especially for the last testcase? Maybe we could define a simple function like:

fail() { # msg

	do_reset
	echo $1
	exit -1
}

Thanks,
Namhyung

Quoted 5 lines
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc new file +5 -0
+fi
+
+do_reset
+
+exit 0
#4 lore raw

Re: [PATCH 2/2 v3] ftracetest: Add a couple of ftrace test cases

Quoted 18 lines · Namhyung Kim

Hi Steve,

tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc line 83

Quoted 11 lines · Steven Rostedt
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc new file +11 -0
+count=`cat trace | grep '()' | grep -v schedule | wc -l`
+
+if [ $count -ne 0 ]; then
+    echo "Graph filtering not working after stack tracer disabled?"
+    exit -1
+fi
+
+count=`cat trace | grep 'schedule()' | wc -l` 
+if [ $count -eq 0 ]; then
+    echo "No schedule traces found?"
+    exit -1

Hmm.. in this case don't we need to call do_reset especially for the last testcase? Maybe we could define a simple function like:

Quoted 5 lines

fail() { # msg

	do_reset
	echo $1
	exit -1
}

If you want to call do_reset always on exit, you can also use "trap do_reset 0" too.

Thank you,

Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
author maintainer
#5 lore raw

Re: [PATCH 2/2 v3] ftracetest: Add a couple of ftrace test cases

Quoted 19 lines · On Wed, 05 Nov 2014 17:41:15 +0900 Masami Hiramatsu…
Quoted 18 lines · Namhyung Kim

Hi Steve,

tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc line 83

Quoted 11 lines · Steven Rostedt
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc new file +11 -0
+count=`cat trace | grep '()' | grep -v schedule | wc -l`
+
+if [ $count -ne 0 ]; then
+    echo "Graph filtering not working after stack tracer disabled?"
+    exit -1
+fi
+
+count=`cat trace | grep 'schedule()' | wc -l` 
+if [ $count -eq 0 ]; then
+    echo "No schedule traces found?"
+    exit -1

Hmm.. in this case don't we need to call do_reset especially for the last testcase? Maybe we could define a simple function like:

Quoted 7 lines
Quoted 5 lines

fail() { # msg

	do_reset
	echo $1
	exit -1
}

If you want to call do_reset always on exit, you can also use "trap do_reset 0" too.

Cool, I didn't know that. But I like the "fail" command, as it is a bit more verbose.

I'll update.

Thanks,

-- Steve

author maintainer
#6 lore raw

PATCH v4 2/2 ftracetest: Add a couple of ftrace test cases

In reply to Masami Hiramatsu

Added three test cases to get the feel of adding tests to ftracetest. The three cases are:

function profiling test, to make sure function profiling still works
with function tracing (was a regression)

function graph filter test to make sure that function graph filtering works.

function graph filter with stack tracing test to make sure that the function
graph filter does filter and also continues to filter when another function tracer is running (like the stack tracer)

---
 .../ftrace/test.d/ftrace/fgraph-filter-stack.tc    | 89 ++++++++++++++++++++++
 .../ftrace/test.d/ftrace/fgraph-filter.tc          | 52 +++++++++++++
 .../ftrace/test.d/ftrace/func_profiler.tc          | 80 +++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter-stack.tc new file +89 -0
new file mode 100644
index 000000000000..c15e018e0220
@@ -0,0 +1,89 @@
+#!/bin/sh
+# description: ftrace - function graph filters with stack tracer
+
+# Make sure that function graph filtering works, and is not
+# affected by other tracers enabled (like stack tracer)
+
+if ! grep -q function_graph available_tracers; then
+    echo "no function graph tracer configured"
+    exit_unsupported
+fi
+
+if [ ! -f set_ftrace_filter ]; then
+    echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
+    exit_unsupported
+fi
+
+do_reset() {
+    reset_tracer
+    echo 0 > /proc/sys/kernel/stack_tracer_enabled
+    enable_tracing
+    clear_trace
+    echo > set_ftrace_filter
+}
+
+fail() { # msg
+    do_reset
+    echo $1
+    exit -1
+}
+
+disable_tracing
+clear_trace;
+
+# filter something, schedule is always good
+if ! echo "schedule" > set_ftrace_filter; then
+    # test for powerpc 64
+    if ! echo ".schedule" > set_ftrace_filter; then
+	fail "can not enable schedule filter"
+    fi
+fi
+
+echo function_graph > current_tracer
+
+if [ ! -f stack_trace ]; then
+    echo "Stack tracer not configured"
+    do_reset
+    exit_unsupported;
+fi
+
+echo "Now testing with stack tracer"
+
+echo 1 > /proc/sys/kernel/stack_tracer_enabled
+
+disable_tracing
+clear_trace
+enable_tracing
+sleep 1
+
+count=`cat trace | grep '()' | grep -v schedule | wc -l`
+
+if [ $count -ne 0 ]; then
+    fail "Graph filtering not working with stack tracer?"
+fi
+
+# Make sure we did find something
+count=`cat trace | grep 'schedule()' | wc -l` 
+if [ $count -eq 0 ]; then
+    fail "No schedule traces found?"
+fi
+
+echo 0 > /proc/sys/kernel/stack_tracer_enabled
+clear_trace
+sleep 1
+
+
+count=`cat trace | grep '()' | grep -v schedule | wc -l`
+
+if [ $count -ne 0 ]; then
+    fail "Graph filtering not working after stack tracer disabled?"
+fi
+
+count=`cat trace | grep 'schedule()' | wc -l` 
+if [ $count -eq 0 ]; then
+    fail "No schedule traces found?"
+fi
+
+do_reset
+
+exit 0
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-filter.tc new file +52 -0

52 lines not on this page · raw message

tools/testing/selftests/ftrace/test.d/ftrace/func_profiler.tc new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
1.8.1.4
Acked-by on v4 2/2
#7 lore raw

Re: [PATCH 2/2 v4] ftracetest: Add a couple of ftrace test cases

Hi Steve,

Quoted 9 lines · Steven Rostedt

Added three test cases to get the feel of adding tests to ftracetest. The three cases are:

function profiling test, to make sure function profiling still works
with function tracing (was a regression)

function graph filter test to make sure that function graph filtering works.

Quoted 8 lines

function graph filter with stack tracing test to make sure that the function
graph filter does filter and also continues to filter when another function tracer is running (like the stack tracer)

For this and previous patch 1/2,

Thanks,
Namhyung