From 131f840d5b7c73cdb928c4dc7afd5120b0154d34 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:13:02 +0900 Subject: selftests: ftrace: Initialize ftrace before each test 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 Suggested-by: Steven Rostedt Signed-off-by: Steven Rostedt --- tools/testing/selftests/ftrace/ftracetest | 2 +- tools/testing/selftests/ftrace/test.d/functions | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest index 4c6a0bf8ba79..a03d366a4a2f 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest @@ -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 } diff --git a/tools/testing/selftests/ftrace/test.d/functions b/tools/testing/selftests/ftrace/test.d/functions index c37262f6c269..91de1a8e4f19 100644 --- a/tools/testing/selftests/ftrace/test.d/functions +++ b/tools/testing/selftests/ftrace/test.d/functions @@ -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 +} -- cgit v1.2.3 From 7786bcca77756b657c28ca7e38600333f5197f9b Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:13:17 +0900 Subject: selftests: ftrace: Add --quiet option not to show error logs on screen Since the verbose error logs scrolls out previous test results --quiet option suppress to show such message. e.g. # ./ftracetest -q === Ftrace unit tests === [1] Basic trace file check [PASS] [2] Basic test for tracers [PASS] [3] Basic trace clock test [PASS] [4] Basic event tracing check [PASS] [5] event tracing - enable/disable with event level files [PASS] [6] event tracing - restricts events based on pid [PASS] [7] event tracing - enable/disable with subsystem level files [PASS] [8] event tracing - enable/disable with top level files [PASS] [9] ftrace - function graph filters with stack tracer [UNSUPPORTED] [10] ftrace - function graph filters [UNSUPPORTED] [11] ftrace - function profiler with function tracing [UNSUPPORTED] [12] Test creation and deletion of trace instances while setting an event [PASS] [13] Test creation and deletion of trace instances [PASS] [14] Kprobe dynamic event - adding and removing [UNSUPPORTED] [15] Kprobe dynamic event - busy event check [UNSUPPORTED] [16] Kprobe dynamic event with arguments [UNSUPPORTED] [17] Kprobe dynamic event with function tracer [UNSUPPORTED] [18] Kretprobe dynamic event with arguments [UNSUPPORTED] [19] event trigger - test event enable/disable trigger [PASS] [20] event trigger - test trigger filter [PASS] [21] event trigger - test histogram modifiers [UNSUPPORTED] [22] event trigger - test histogram trigger [UNSUPPORTED] [23] event trigger - test multiple histogram triggers [UNSUPPORTED] [24] event trigger - test snapshot-trigger [FAIL] [25] event trigger - test stacktrace-trigger [PASS] [26] event trigger - test traceon/off trigger [PASS] # of passed: 14 # of failed: 1 # of unresolved: 0 # of untested: 0 # of unsupported: 11 # of xfailed: 0 # of undefined(test bug): 0 Link: http://lkml.kernel.org/r/147928399712.22982.8284640390982775052.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- tools/testing/selftests/ftrace/ftracetest | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest index a03d366a4a2f..d08235f65202 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest @@ -14,6 +14,7 @@ echo " Options:" echo " -h|--help Show help message" echo " -k|--keep Keep passed test logs" echo " -v|--verbose Show all stdout messages in testcases" +echo " -q|--quiet Do not show error log on stdout" echo " -d|--debug Debug mode (trace all shell commands)" exit $1 } @@ -58,6 +59,10 @@ parse_opts() { # opts VERBOSE=1 shift 1 ;; + --quiet|-q) + BE_QUIET=1 + shift 1 + ;; --debug|-d) DEBUG=1 shift 1 @@ -101,6 +106,7 @@ LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/ KEEP_LOG=0 DEBUG=0 VERBOSE=0 +BE_QUIET=0 # Parse command-line options parse_opts $* @@ -249,7 +255,7 @@ run_test() { # testfile # Remove test log if the test was done as it was expected. [ $KEEP_LOG -eq 0 ] && rm $testlog else - catlog $testlog + [ $BE_QUIET -eq 0 ] && catlog $testlog TOTAL_RESULT=1 fi } -- cgit v1.2.3 From 131c60c39cf05287b07025b5eefac7bc10c086b0 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:13:32 +0900 Subject: selftests: ftrace: Check whether snapshot trigger is supported correctly If "snapshot" special file doesn't exist, that kernel does not support snapshot and snapshot trigger too. In that case snapshot trigger test results to unsupported instead of fail. Link: http://lkml.kernel.org/r/147928401215.22982.10411665829041109794.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc index f84b80d551a2..ed94f0c4e0e4 100644 --- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc +++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-snapshot.tc @@ -23,6 +23,11 @@ if [ ! -f events/sched/sched_process_fork/trigger ]; then exit_unsupported fi +if [ ! -f snapshot ]; then + echo "snapshot is not supported" + exit_unsupported +fi + reset_tracer do_reset -- cgit v1.2.3 From 780ade555a96060bf922a94b6602218fbc19a8e4 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:13:47 +0900 Subject: selftests: ftrace: Fix trigger-mod to run without syscall trace Since histogram trigger id.syscall depends on CONFIG_FTRACE_SYSCALLS, a testcase in trigger-modifier test fails if that config is disabled. Fix this bug by using flexible pattern to check the histogram output. Link: http://lkml.kernel.org/r/147928402670.22982.15589445159052676877.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc index 0bf5085281f3..400e98b64948 100644 --- a/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc +++ b/tools/testing/selftests/ftrace/test.d/trigger/trigger-hist-mod.tc @@ -56,7 +56,7 @@ echo "Test histogram with syscall modifier" echo 'hist:keys=id.syscall' > events/raw_syscalls/sys_exit/trigger for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done -grep "id: sys_" events/raw_syscalls/sys_exit/hist > /dev/null || \ +grep "id: \(unknown_\|sys_\)" events/raw_syscalls/sys_exit/hist > /dev/null || \ fail "syscall modifier on raw_syscalls/sys_exit did not work" -- cgit v1.2.3 From 57209b96951383c8276fe341a60a43c8de0d6b11 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:14:06 +0900 Subject: selftests: ftrace: Hide ftracetest logs from git Hide ftracetest result log directory from git. Link: http://lkml.kernel.org/r/147928404640.22982.13173364949326289032.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- tools/testing/selftests/ftrace/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 tools/testing/selftests/ftrace/.gitignore (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/.gitignore b/tools/testing/selftests/ftrace/.gitignore new file mode 100644 index 000000000000..98d8a5a63049 --- /dev/null +++ b/tools/testing/selftests/ftrace/.gitignore @@ -0,0 +1 @@ +logs -- cgit v1.2.3 From 62197529000aa56d8a1ca397becd58a430cb7409 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:14:21 +0900 Subject: selftests: ftrace: Introduce TMPDIR for temporary files Introduce TMPDIR variable which is removed after each test is done, so that the test script can put their temporary files in that. Link: http://lkml.kernel.org/r/147928406116.22982.8761924340108532378.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- tools/testing/selftests/ftrace/ftracetest | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest index d08235f65202..685376b485a2 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest @@ -242,6 +242,7 @@ __run_test() { # testfile run_test() { # testfile local testname=`basename $1` local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX` + export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX` testcase $1 echo "execute: "$1 > $testlog SIG_RESULT=0 @@ -258,6 +259,7 @@ run_test() { # testfile [ $BE_QUIET -eq 0 ] && catlog $testlog TOTAL_RESULT=1 fi + rm -rf $TMPDIR } # load in the helper functions -- cgit v1.2.3 From 60c1afbf10528f646a6fcae1a2c404d216e594d5 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:14:36 +0900 Subject: selftests: ftrace: Add a testcase for function filter glob match Add function filter glob matching test case. This checks whether the kernel supports glob matching (front match, end match, middle match, side match, character class and '?'). Here is the test result. ----- ./ftracetest test.d/ftrace/func-filter-glob.tc === Ftrace unit tests === [1] ftrace - function glob filters [PASS] # of passed: 1 # of failed: 0 # of unresolved: 0 # of untested: 0 # of unsupported: 0 # of xfailed: 0 # of undefined(test bug): 0 ----- Link: http://lkml.kernel.org/r/147928407589.22982.16364174511117104303.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- .../ftrace/test.d/ftrace/func-filter-glob.tc | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc new file mode 100644 index 000000000000..9dcd0ca1f49c --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/ftrace/func-filter-glob.tc @@ -0,0 +1,49 @@ +#!/bin/sh +# description: ftrace - function glob filters + +# Make sure that function glob matching filter works. + +if ! grep -q function available_tracers; then + echo "no function tracer configured" + exit_unsupported +fi + +disable_tracing +clear_trace + +# filter by ?, schedule is always good +if ! echo "sch?dule" > set_ftrace_filter; then + # test for powerpc 64 + if ! echo ".sch?dule" > set_ftrace_filter; then + fail "can not enable schedule filter" + fi + cat set_ftrace_filter | grep '^.schedule$' +else + cat set_ftrace_filter | grep '^schedule$' +fi + +ftrace_filter_check() { # glob grep + echo "$1" > set_ftrace_filter + cut -f1 -d" " set_ftrace_filter > $TMPDIR/actual + cut -f1 -d" " available_filter_functions | grep "$2" > $TMPDIR/expected + DIFF=`diff $TMPDIR/actual $TMPDIR/expected` + test -z "$DIFF" +} + +# filter by *, front match +ftrace_filter_check '*schedule' '^.*schedule$' + +# filter by *, middle match +ftrace_filter_check '*schedule*' '^.*schedule.*$' + +# filter by *, end match +ftrace_filter_check 'schedule*' '^schedule.*$' + +# filter by *, both side match +ftrace_filter_check 'sch*ule' '^sch.*ule$' + +# filter by char class. +ftrace_filter_check '[Ss]y[Ss]_*' '^[Ss]y[Ss]_.*$' + +echo > set_ftrace_filter +enable_tracing -- cgit v1.2.3 From 153aae5f996d4cb3e8a64990b6b09cde4a1529b0 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Wed, 16 Nov 2016 17:14:50 +0900 Subject: selftests: ftrace: Add a testcase for types of kprobe event Add a testcase for types of kprobe event. This checks kprobe event can accept and correctly expressed the arguments typed as s32, u32, x32 and bitfield. Here is the test result. ----- # ./ftracetest test.d/kprobe/kprobe_args_type.tc === Ftrace unit tests === [1] Kprobes event arguments with types [PASS] # of passed: 1 # of failed: 0 # of unresolved: 0 # of untested: 0 # of unsupported: 0 # of xfailed: 0 # of undefined(test bug): 0 ----- Link: http://lkml.kernel.org/r/147928409063.22982.3499119203875115458.stgit@devbox Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- .../ftrace/test.d/kprobe/kprobe_args_type.tc | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc new file mode 100644 index 000000000000..0a78705b43b2 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc @@ -0,0 +1,37 @@ +#!/bin/sh +# description: Kprobes event arguments with types + +[ -f kprobe_events ] || exit_unsupported # this is configurable + +grep "x8/16/32/64" README > /dev/null || exit_unsupported # version issue + +echo 0 > events/enable +echo > kprobe_events +enable_tracing + +echo 'p:testprobe _do_fork $stack0:s32 $stack0:u32 $stack0:x32 $stack0:b8@4/32' > kprobe_events +grep testprobe kprobe_events +test -d events/kprobes/testprobe + +echo 1 > events/kprobes/testprobe/enable +( echo "forked") +echo 0 > events/kprobes/testprobe/enable +ARGS=`tail -n 1 trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'` + +check_types() { + X1=`printf "%x" $1 | tail -c 8` + X2=`printf "%x" $2` + X3=`printf "%x" $3` + test $X1 = $X2 + test $X2 = $X3 + test 0x$X3 = $3 + + B4=`printf "%x" $4` + B3=`echo -n $X3 | tail -c 3 | head -c 2` + test $B3 = $B4 +} +check_types $ARGS + +echo "-:testprobe" >> kprobe_events +clear_trace +test -d events/kprobes/testprobe && exit 1 || exit 0 -- cgit v1.2.3 From 3dbb16b87b57bb1088044ad2a0432e4769075002 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Fri, 25 Nov 2016 21:58:48 +0900 Subject: selftests: ftrace: Shift down default message verbosity Shift down default message verbosity, where it does not show error results in stdout by default. Since that behavior is the same as giving the --quiet option, this patch removes --quiet and makes --verbose increasing verbosity. In other words, this changes verbosity options as below. ftracetest -q -> ftracetest ftracetest -> ftracetest -v ftracetest -v -> ftracetest -v -v (or -vv) Link: http://lkml.kernel.org/r/148007872763.5917.15256235993753860592.stgit@devbox Acked-by: Shuah Khan Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt --- tools/testing/selftests/ftrace/ftracetest | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest index 685376b485a2..52e3c4df28d6 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest @@ -13,8 +13,8 @@ echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]" echo " Options:" echo " -h|--help Show help message" echo " -k|--keep Keep passed test logs" -echo " -v|--verbose Show all stdout messages in testcases" -echo " -q|--quiet Do not show error log on stdout" +echo " -v|--verbose Increase verbosity of test messages" +echo " -vv Alias of -v -v (Show all results in stdout)" echo " -d|--debug Debug mode (trace all shell commands)" exit $1 } @@ -55,12 +55,9 @@ parse_opts() { # opts KEEP_LOG=1 shift 1 ;; - --verbose|-v) - VERBOSE=1 - shift 1 - ;; - --quiet|-q) - BE_QUIET=1 + --verbose|-v|-vv) + VERBOSE=$((VERBOSE + 1)) + [ $1 == '-vv' ] && VERBOSE=$((VERBOSE + 1)) shift 1 ;; --debug|-d) @@ -106,7 +103,6 @@ LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/ KEEP_LOG=0 DEBUG=0 VERBOSE=0 -BE_QUIET=0 # Parse command-line options parse_opts $* @@ -246,7 +242,7 @@ run_test() { # testfile testcase $1 echo "execute: "$1 > $testlog SIG_RESULT=0 - if [ $VERBOSE -ne 0 ]; then + if [ $VERBOSE -ge 2 ]; then __run_test $1 2>> $testlog | tee -a $testlog else __run_test $1 >> $testlog 2>&1 @@ -256,7 +252,7 @@ run_test() { # testfile # Remove test log if the test was done as it was expected. [ $KEEP_LOG -eq 0 ] && rm $testlog else - [ $BE_QUIET -eq 0 ] && catlog $testlog + [ $VERBOSE -ge 1 ] && catlog $testlog TOTAL_RESULT=1 fi rm -rf $TMPDIR -- cgit v1.2.3