aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-10-12 07:33:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-12 07:33:37 -0400
commit90eac7eee2f4257644dcfb9d22348fded7c24afd (patch)
treeea472521485299a830095ea341f263cfb0425f1e /tools/testing
parent6bbcb1d3a2e0a31593e3b7d9bfd112fa7f447141 (diff)
parent89c5497d1f933af56dac617f0fd86150942a7fb6 (diff)
Merge tag 'ftracetest-3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull ftrace test code from Steven Rostedt: "This patch series starts a new selftests section in the tools/testing/selftest directory called "ftrace" that holds tests aimed at testing ftrace and subsystems that use ftrace (like kprobes). So far only a few tests were written (by Masami Hiramatsu), but more will be added in the near future (3.19)" * tag 'ftracetest-3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracing/kprobes: Add selftest scripts testing kprobe-tracer as startup test ftracetest: Add POSIX.3 standard and XFAIL result codes ftracetest: Add kprobe basic testcases ftracetest: Add ftrace basic testcases ftracetest: Initial commit for ftracetest
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/Makefile1
-rw-r--r--tools/testing/selftests/ftrace/Makefile7
-rw-r--r--tools/testing/selftests/ftrace/README82
-rwxr-xr-xtools/testing/selftests/ftrace/ftracetest253
-rw-r--r--tools/testing/selftests/ftrace/samples/fail.tc4
-rw-r--r--tools/testing/selftests/ftrace/samples/pass.tc3
-rw-r--r--tools/testing/selftests/ftrace/samples/unresolved.tc4
-rw-r--r--tools/testing/selftests/ftrace/samples/unsupported.tc3
-rw-r--r--tools/testing/selftests/ftrace/samples/untested.tc3
-rw-r--r--tools/testing/selftests/ftrace/samples/xfail.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/00basic/basic1.tc3
-rw-r--r--tools/testing/selftests/ftrace/test.d/00basic/basic2.tc7
-rw-r--r--tools/testing/selftests/ftrace/test.d/00basic/basic3.tc8
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc11
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc13
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc16
-rw-r--r--tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc15
-rw-r--r--tools/testing/selftests/ftrace/test.d/template9
18 files changed, 445 insertions, 0 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 36ff2e4c7b6f..45f145c6f843 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -14,6 +14,7 @@ TARGETS += powerpc
14TARGETS += user 14TARGETS += user
15TARGETS += sysctl 15TARGETS += sysctl
16TARGETS += firmware 16TARGETS += firmware
17TARGETS += ftrace
17 18
18TARGETS_HOTPLUG = cpu-hotplug 19TARGETS_HOTPLUG = cpu-hotplug
19TARGETS_HOTPLUG += memory-hotplug 20TARGETS_HOTPLUG += memory-hotplug
diff --git a/tools/testing/selftests/ftrace/Makefile b/tools/testing/selftests/ftrace/Makefile
new file mode 100644
index 000000000000..76cc9f156267
--- /dev/null
+++ b/tools/testing/selftests/ftrace/Makefile
@@ -0,0 +1,7 @@
1all:
2
3run_tests:
4 @/bin/sh ./ftracetest || echo "ftrace selftests: [FAIL]"
5
6clean:
7 rm -rf logs/*
diff --git a/tools/testing/selftests/ftrace/README b/tools/testing/selftests/ftrace/README
new file mode 100644
index 000000000000..182e76fa4b82
--- /dev/null
+++ b/tools/testing/selftests/ftrace/README
@@ -0,0 +1,82 @@
1Linux Ftrace Testcases
2
3This is a collection of testcases for ftrace tracing feature in the Linux
4kernel. Since ftrace exports interfaces via the debugfs, we just need
5shell scripts for testing. Feel free to add new test cases.
6
7Running the ftrace testcases
8============================
9
10At first, you need to be the root user to run this script.
11To run all testcases:
12
13 $ sudo ./ftracetest
14
15To run specific testcases:
16
17 # ./ftracetest test.d/basic3.tc
18
19Or you can also run testcases under given directory:
20
21 # ./ftracetest test.d/kprobe/
22
23Contributing new testcases
24==========================
25
26Copy test.d/template to your testcase (whose filename must have *.tc
27extension) and rewrite the test description line.
28
29 * The working directory of the script is <debugfs>/tracing/.
30
31 * Take care with side effects as the tests are run with root privilege.
32
33 * The tests should not run for a long period of time (more than 1 min.)
34 These are to be unit tests.
35
36 * You can add a directory for your testcases under test.d/ if needed.
37
38 * The test cases should run on dash (busybox shell) for testing on
39 minimal cross-build environments.
40
41 * Note that the tests are run with "set -e" (errexit) option. If any
42 command fails, the test will be terminated immediately.
43
44 * The tests can return some result codes instead of pass or fail by
45 using exit_unresolved, exit_untested, exit_unsupported and exit_xfail.
46
47Result code
48===========
49
50Ftracetest supports following result codes.
51
52 * PASS: The test succeeded as expected. The test which exits with 0 is
53 counted as passed test.
54
55 * FAIL: The test failed, but was expected to succeed. The test which exits
56 with !0 is counted as failed test.
57
58 * UNRESOLVED: The test produced unclear or intermidiate results.
59 for example, the test was interrupted
60 or the test depends on a previous test, which failed.
61 or the test was set up incorrectly
62 The test which is in above situation, must call exit_unresolved.
63
64 * UNTESTED: The test was not run, currently just a placeholder.
65 In this case, the test must call exit_untested.
66
67 * UNSUPPORTED: The test failed because of lack of feature.
68 In this case, the test must call exit_unsupported.
69
70 * XFAIL: The test failed, and was expected to fail.
71 To return XFAIL, call exit_xfail from the test.
72
73There are some sample test scripts for result code under samples/.
74You can also run samples as below:
75
76 # ./ftracetest samples/
77
78TODO
79====
80
81 * Fancy colored output :)
82
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest
new file mode 100755
index 000000000000..a8f81c782856
--- /dev/null
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -0,0 +1,253 @@
1#!/bin/sh
2
3# ftracetest - Ftrace test shell scripts
4#
5# Copyright (C) Hitachi Ltd., 2014
6# Written by Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
7#
8# Released under the terms of the GPL v2.
9
10usage() { # errno [message]
11[ "$2" ] && echo $2
12echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
13echo " Options:"
14echo " -h|--help Show help message"
15echo " -k|--keep Keep passed test logs"
16echo " -d|--debug Debug mode (trace all shell commands)"
17exit $1
18}
19
20errexit() { # message
21 echo "Error: $1" 1>&2
22 exit 1
23}
24
25# Ensuring user privilege
26if [ `id -u` -ne 0 ]; then
27 errexit "this must be run by root user"
28fi
29
30# Utilities
31absdir() { # file_path
32 (cd `dirname $1`; pwd)
33}
34
35abspath() {
36 echo `absdir $1`/`basename $1`
37}
38
39find_testcases() { #directory
40 echo `find $1 -name \*.tc`
41}
42
43parse_opts() { # opts
44 local OPT_TEST_CASES=
45 local OPT_TEST_DIR=
46
47 while [ "$1" ]; do
48 case "$1" in
49 --help|-h)
50 usage 0
51 ;;
52 --keep|-k)
53 KEEP_LOG=1
54 shift 1
55 ;;
56 --debug|-d)
57 DEBUG=1
58 shift 1
59 ;;
60 *.tc)
61 if [ -f "$1" ]; then
62 OPT_TEST_CASES="$OPT_TEST_CASES `abspath $1`"
63 shift 1
64 else
65 usage 1 "$1 is not a testcase"
66 fi
67 ;;
68 *)
69 if [ -d "$1" ]; then
70 OPT_TEST_DIR=`abspath $1`
71 OPT_TEST_CASES="$OPT_TEST_CASES `find_testcases $OPT_TEST_DIR`"
72 shift 1
73 else
74 usage 1 "Invalid option ($1)"
75 fi
76 ;;
77 esac
78 done
79 if [ "$OPT_TEST_CASES" ]; then
80 TEST_CASES=$OPT_TEST_CASES
81 fi
82}
83
84# Parameters
85DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' '`
86TRACING_DIR=$DEBUGFS_DIR/tracing
87TOP_DIR=`absdir $0`
88TEST_DIR=$TOP_DIR/test.d
89TEST_CASES=`find_testcases $TEST_DIR`
90LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/
91KEEP_LOG=0
92DEBUG=0
93# Parse command-line options
94parse_opts $*
95
96[ $DEBUG -ne 0 ] && set -x
97
98# Verify parameters
99if [ -z "$DEBUGFS_DIR" -o ! -d "$TRACING_DIR" ]; then
100 errexit "No ftrace directory found"
101fi
102
103# Preparing logs
104LOG_FILE=$LOG_DIR/ftracetest.log
105mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR"
106date > $LOG_FILE
107prlog() { # messages
108 echo "$@" | tee -a $LOG_FILE
109}
110catlog() { #file
111 cat $1 | tee -a $LOG_FILE
112}
113prlog "=== Ftrace unit tests ==="
114
115
116# Testcase management
117# Test result codes - Dejagnu extended code
118PASS=0 # The test succeeded.
119FAIL=1 # The test failed, but was expected to succeed.
120UNRESOLVED=2 # The test produced indeterminate results. (e.g. interrupted)
121UNTESTED=3 # The test was not run, currently just a placeholder.
122UNSUPPORTED=4 # The test failed because of lack of feature.
123XFAIL=5 # The test failed, and was expected to fail.
124
125# Accumulations
126PASSED_CASES=
127FAILED_CASES=
128UNRESOLVED_CASES=
129UNTESTED_CASES=
130UNSUPPORTED_CASES=
131XFAILED_CASES=
132UNDEFINED_CASES=
133TOTAL_RESULT=0
134
135CASENO=0
136testcase() { # testfile
137 CASENO=$((CASENO+1))
138 prlog -n "[$CASENO]"`grep "^#[ \t]*description:" $1 | cut -f2 -d:`
139}
140
141eval_result() { # retval sigval
142 local retval=$2
143 if [ $2 -eq 0 ]; then
144 test $1 -ne 0 && retval=$FAIL
145 fi
146 case $retval in
147 $PASS)
148 prlog " [PASS]"
149 PASSED_CASES="$PASSED_CASES $CASENO"
150 return 0
151 ;;
152 $FAIL)
153 prlog " [FAIL]"
154 FAILED_CASES="$FAILED_CASES $CASENO"
155 return 1 # this is a bug.
156 ;;
157 $UNRESOLVED)
158 prlog " [UNRESOLVED]"
159 UNRESOLVED_CASES="$UNRESOLVED_CASES $CASENO"
160 return 1 # this is a kind of bug.. something happened.
161 ;;
162 $UNTESTED)
163 prlog " [UNTESTED]"
164 UNTESTED_CASES="$UNTESTED_CASES $CASENO"
165 return 0
166 ;;
167 $UNSUPPORTED)
168 prlog " [UNSUPPORTED]"
169 UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO"
170 return 1 # this is not a bug, but the result should be reported.
171 ;;
172 $XFAIL)
173 prlog " [XFAIL]"
174 XFAILED_CASES="$XFAILED_CASES $CASENO"
175 return 0
176 ;;
177 *)
178 prlog " [UNDEFINED]"
179 UNDEFINED_CASES="$UNDEFINED_CASES $CASENO"
180 return 1 # this must be a test bug
181 ;;
182 esac
183}
184
185# Signal handling for result codes
186SIG_RESULT=
187SIG_BASE=36 # Use realtime signals
188SIG_PID=$$
189
190SIG_UNRESOLVED=$((SIG_BASE + UNRESOLVED))
191exit_unresolved () {
192 kill -s $SIG_UNRESOLVED $SIG_PID
193 exit 0
194}
195trap 'SIG_RESULT=$UNRESOLVED' $SIG_UNRESOLVED
196
197SIG_UNTESTED=$((SIG_BASE + UNTESTED))
198exit_untested () {
199 kill -s $SIG_UNTESTED $SIG_PID
200 exit 0
201}
202trap 'SIG_RESULT=$UNTESTED' $SIG_UNTESTED
203
204SIG_UNSUPPORTED=$((SIG_BASE + UNSUPPORTED))
205exit_unsupported () {
206 kill -s $SIG_UNSUPPORTED $SIG_PID
207 exit 0
208}
209trap 'SIG_RESULT=$UNSUPPORTED' $SIG_UNSUPPORTED
210
211SIG_XFAIL=$((SIG_BASE + XFAIL))
212exit_xfail () {
213 kill -s $SIG_XFAIL $SIG_PID
214 exit 0
215}
216trap 'SIG_RESULT=$XFAIL' $SIG_XFAIL
217
218# Run one test case
219run_test() { # testfile
220 local testname=`basename $1`
221 local testlog=`mktemp --tmpdir=$LOG_DIR ${testname}-XXXXXX.log`
222 testcase $1
223 echo "execute: "$1 > $testlog
224 SIG_RESULT=0
225 # setup PID and PPID, $$ is not updated.
226 (cd $TRACING_DIR; read PID _ < /proc/self/stat ;
227 set -e; set -x; . $1) >> $testlog 2>&1
228 eval_result $? $SIG_RESULT
229 if [ $? -eq 0 ]; then
230 # Remove test log if the test was done as it was expected.
231 [ $KEEP_LOG -eq 0 ] && rm $testlog
232 else
233 catlog $testlog
234 TOTAL_RESULT=1
235 fi
236}
237
238# Main loop
239for t in $TEST_CASES; do
240 run_test $t
241done
242
243prlog ""
244prlog "# of passed: " `echo $PASSED_CASES | wc -w`
245prlog "# of failed: " `echo $FAILED_CASES | wc -w`
246prlog "# of unresolved: " `echo $UNRESOLVED_CASES | wc -w`
247prlog "# of untested: " `echo $UNTESTED_CASES | wc -w`
248prlog "# of unsupported: " `echo $UNSUPPORTED_CASES | wc -w`
249prlog "# of xfailed: " `echo $XFAILED_CASES | wc -w`
250prlog "# of undefined(test bug): " `echo $UNDEFINED_CASES | wc -w`
251
252# if no error, return 0
253exit $TOTAL_RESULT
diff --git a/tools/testing/selftests/ftrace/samples/fail.tc b/tools/testing/selftests/ftrace/samples/fail.tc
new file mode 100644
index 000000000000..15e35b956e05
--- /dev/null
+++ b/tools/testing/selftests/ftrace/samples/fail.tc
@@ -0,0 +1,4 @@
1#!/bin/sh
2# description: failure-case example
3cat non-exist-file
4echo "this is not executed"
diff --git a/tools/testing/selftests/ftrace/samples/pass.tc b/tools/testing/selftests/ftrace/samples/pass.tc
new file mode 100644
index 000000000000..d01549370041
--- /dev/null
+++ b/tools/testing/selftests/ftrace/samples/pass.tc
@@ -0,0 +1,3 @@
1#!/bin/sh
2# description: pass-case example
3return 0
diff --git a/tools/testing/selftests/ftrace/samples/unresolved.tc b/tools/testing/selftests/ftrace/samples/unresolved.tc
new file mode 100644
index 000000000000..41e99d3358d1
--- /dev/null
+++ b/tools/testing/selftests/ftrace/samples/unresolved.tc
@@ -0,0 +1,4 @@
1#!/bin/sh
2# description: unresolved-case example
3trap exit_unresolved INT
4kill -INT $PID
diff --git a/tools/testing/selftests/ftrace/samples/unsupported.tc b/tools/testing/selftests/ftrace/samples/unsupported.tc
new file mode 100644
index 000000000000..45910ff13328
--- /dev/null
+++ b/tools/testing/selftests/ftrace/samples/unsupported.tc
@@ -0,0 +1,3 @@
1#!/bin/sh
2# description: unsupported-case example
3exit_unsupported
diff --git a/tools/testing/selftests/ftrace/samples/untested.tc b/tools/testing/selftests/ftrace/samples/untested.tc
new file mode 100644
index 000000000000..35a45946ec60
--- /dev/null
+++ b/tools/testing/selftests/ftrace/samples/untested.tc
@@ -0,0 +1,3 @@
1#!/bin/sh
2# description: untested-case example
3exit_untested
diff --git a/tools/testing/selftests/ftrace/samples/xfail.tc b/tools/testing/selftests/ftrace/samples/xfail.tc
new file mode 100644
index 000000000000..9dd395323259
--- /dev/null
+++ b/tools/testing/selftests/ftrace/samples/xfail.tc
@@ -0,0 +1,3 @@
1#!/bin/sh
2# description: xfail-case example
3cat non-exist-file || exit_xfail
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/basic1.tc b/tools/testing/selftests/ftrace/test.d/00basic/basic1.tc
new file mode 100644
index 000000000000..9980ff14ae44
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/00basic/basic1.tc
@@ -0,0 +1,3 @@
1#!/bin/sh
2# description: Basic trace file check
3test -f README -a -f trace -a -f tracing_on -a -f trace_pipe
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/basic2.tc b/tools/testing/selftests/ftrace/test.d/00basic/basic2.tc
new file mode 100644
index 000000000000..bf9a7b037924
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/00basic/basic2.tc
@@ -0,0 +1,7 @@
1#!/bin/sh
2# description: Basic test for tracers
3test -f available_tracers
4for t in `cat available_tracers`; do
5 echo $t > current_tracer
6done
7echo nop > current_tracer
diff --git a/tools/testing/selftests/ftrace/test.d/00basic/basic3.tc b/tools/testing/selftests/ftrace/test.d/00basic/basic3.tc
new file mode 100644
index 000000000000..bde6625d9785
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/00basic/basic3.tc
@@ -0,0 +1,8 @@
1#!/bin/sh
2# description: Basic trace clock test
3test -f trace_clock
4for c in `cat trace_clock | tr -d \[\]`; do
5 echo $c > trace_clock
6 grep '\['$c'\]' trace_clock
7done
8echo local > trace_clock
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc b/tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
new file mode 100644
index 000000000000..1b8b665ab2b3
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/add_and_remove.tc
@@ -0,0 +1,11 @@
1#!/bin/sh
2# description: Kprobe dynamic event - adding and removing
3
4[ -f kprobe_events ] || exit_unsupported # this is configurable
5
6echo 0 > events/enable
7echo > kprobe_events
8echo p:myevent do_fork > kprobe_events
9grep myevent kprobe_events
10test -d events/kprobes/myevent
11echo > kprobe_events
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc b/tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
new file mode 100644
index 000000000000..b55c84003587
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/busy_check.tc
@@ -0,0 +1,13 @@
1#!/bin/sh
2# description: Kprobe dynamic event - busy event check
3
4[ -f kprobe_events ] || exit_unsupported
5
6echo 0 > events/enable
7echo > kprobe_events
8echo p:myevent do_fork > kprobe_events
9test -d events/kprobes/myevent
10echo 1 > events/kprobes/myevent/enable
11echo > kprobe_events && exit 1 # this must fail
12echo 0 > events/kprobes/myevent/enable
13echo > kprobe_events # this must succeed
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
new file mode 100644
index 000000000000..a603d3f8db7b
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args.tc
@@ -0,0 +1,16 @@
1#!/bin/sh
2# description: Kprobe dynamic event with arguments
3
4[ -f kprobe_events ] || exit_unsupported # this is configurable
5
6echo 0 > events/enable
7echo > kprobe_events
8echo 'p:testprobe do_fork $stack $stack0 +0($stack)' > kprobe_events
9grep testprobe kprobe_events
10test -d events/kprobes/testprobe
11echo 1 > events/kprobes/testprobe/enable
12( echo "forked")
13echo 0 > events/kprobes/testprobe/enable
14echo "-:testprobe" >> kprobe_events
15test -d events/kprobes/testprobe && exit 1 || exit 0
16
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
new file mode 100644
index 000000000000..283c29e7f7c4
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_args.tc
@@ -0,0 +1,15 @@
1#!/bin/sh
2# description: Kretprobe dynamic event with arguments
3
4[ -f kprobe_events ] || exit_unsupported # this is configurable
5
6echo 0 > events/enable
7echo > kprobe_events
8echo 'r:testprobe2 do_fork $retval' > kprobe_events
9grep testprobe2 kprobe_events
10test -d events/kprobes/testprobe2
11echo 1 > events/kprobes/testprobe2/enable
12( echo "forked")
13echo 0 > events/kprobes/testprobe2/enable
14echo '-:testprobe2' >> kprobe_events
15test -d events/kprobes/testprobe2 && exit 1 || exit 0
diff --git a/tools/testing/selftests/ftrace/test.d/template b/tools/testing/selftests/ftrace/test.d/template
new file mode 100644
index 000000000000..5448f7abad5f
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/template
@@ -0,0 +1,9 @@
1#!/bin/sh
2# description: %HERE DESCRIBE WHAT THIS DOES%
3# you have to add ".tc" extention for your testcase file
4# Note that all tests are run with "errexit" option.
5
6exit 0 # Return 0 if the test is passed, otherwise return !0
7# If the test could not run because of lack of feature, call exit_unsupported
8# If the test returned unclear results, call exit_unresolved
9# If the test is a dummy, or a placeholder, call exit_untested