diff options
-rw-r--r-- | MAINTAINERS | 1 | ||||
-rw-r--r-- | tools/testing/selftests/Makefile | 1 | ||||
-rw-r--r-- | tools/testing/selftests/ftrace/Makefile | 7 | ||||
-rw-r--r-- | tools/testing/selftests/ftrace/README | 45 | ||||
-rwxr-xr-x | tools/testing/selftests/ftrace/ftracetest | 159 | ||||
-rw-r--r-- | tools/testing/selftests/ftrace/test.d/template | 4 |
6 files changed, 217 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 670b3dcce2de..bb455d0ae12a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -9310,6 +9310,7 @@ F: include/*/ftrace.h | |||
9310 | F: include/linux/trace*.h | 9310 | F: include/linux/trace*.h |
9311 | F: include/trace/ | 9311 | F: include/trace/ |
9312 | F: kernel/trace/ | 9312 | F: kernel/trace/ |
9313 | F: tools/testing/selftests/ftrace/ | ||
9313 | 9314 | ||
9314 | TRIVIAL PATCHES | 9315 | TRIVIAL PATCHES |
9315 | M: Jiri Kosina <trivial@kernel.org> | 9316 | M: Jiri Kosina <trivial@kernel.org> |
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 | |||
14 | TARGETS += user | 14 | TARGETS += user |
15 | TARGETS += sysctl | 15 | TARGETS += sysctl |
16 | TARGETS += firmware | 16 | TARGETS += firmware |
17 | TARGETS += ftrace | ||
17 | 18 | ||
18 | TARGETS_HOTPLUG = cpu-hotplug | 19 | TARGETS_HOTPLUG = cpu-hotplug |
19 | TARGETS_HOTPLUG += memory-hotplug | 20 | TARGETS_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 @@ | |||
1 | all: | ||
2 | |||
3 | run_tests: | ||
4 | @/bin/sh ./ftracetest || echo "ftrace selftests: [FAIL]" | ||
5 | |||
6 | clean: | ||
7 | rm -rf logs/* | ||
diff --git a/tools/testing/selftests/ftrace/README b/tools/testing/selftests/ftrace/README new file mode 100644 index 000000000000..b8631f03e754 --- /dev/null +++ b/tools/testing/selftests/ftrace/README | |||
@@ -0,0 +1,45 @@ | |||
1 | Linux Ftrace Testcases | ||
2 | |||
3 | This is a collection of testcases for ftrace tracing feature in the Linux | ||
4 | kernel. Since ftrace exports interfaces via the debugfs, we just need | ||
5 | shell scripts for testing. Feel free to add new test cases. | ||
6 | |||
7 | Running the ftrace testcases | ||
8 | ============================ | ||
9 | |||
10 | At first, you need to be the root user to run this script. | ||
11 | To run all testcases: | ||
12 | |||
13 | $ sudo ./ftracetest | ||
14 | |||
15 | To run specific testcases: | ||
16 | |||
17 | # ./ftracetest test.d/basic3.tc | ||
18 | |||
19 | Or you can also run testcases under given directory: | ||
20 | |||
21 | # ./ftracetest test.d/kprobe/ | ||
22 | |||
23 | Contributing new testcases | ||
24 | ========================== | ||
25 | |||
26 | Copy test.d/template to your testcase (whose filename must have *.tc | ||
27 | extension) 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 | TODO | ||
42 | ==== | ||
43 | |||
44 | * Fancy colored output :) | ||
45 | |||
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest new file mode 100755 index 000000000000..4c6c2fad2cda --- /dev/null +++ b/tools/testing/selftests/ftrace/ftracetest | |||
@@ -0,0 +1,159 @@ | |||
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 | |||
10 | usage() { # errno [message] | ||
11 | [ "$2" ] && echo $2 | ||
12 | echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]" | ||
13 | echo " Options:" | ||
14 | echo " -h|--help Show help message" | ||
15 | echo " -k|--keep Keep passed test logs" | ||
16 | echo " -d|--debug Debug mode (trace all shell commands)" | ||
17 | exit $1 | ||
18 | } | ||
19 | |||
20 | errexit() { # message | ||
21 | echo "Error: $1" 1>&2 | ||
22 | exit 1 | ||
23 | } | ||
24 | |||
25 | # Ensuring user privilege | ||
26 | if [ `id -u` -ne 0 ]; then | ||
27 | errexit "this must be run by root user" | ||
28 | fi | ||
29 | |||
30 | # Utilities | ||
31 | absdir() { # file_path | ||
32 | (cd `dirname $1`; pwd) | ||
33 | } | ||
34 | |||
35 | abspath() { | ||
36 | echo `absdir $1`/`basename $1` | ||
37 | } | ||
38 | |||
39 | find_testcases() { #directory | ||
40 | echo `find $1 -name \*.tc` | ||
41 | } | ||
42 | |||
43 | parse_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 | ||
85 | DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' '` | ||
86 | TRACING_DIR=$DEBUGFS_DIR/tracing | ||
87 | TOP_DIR=`absdir $0` | ||
88 | TEST_DIR=$TOP_DIR/test.d | ||
89 | TEST_CASES=`find_testcases $TEST_DIR` | ||
90 | LOG_DIR=$TOP_DIR/logs/`date +%Y%m%d-%H%M%S`/ | ||
91 | KEEP_LOG=0 | ||
92 | DEBUG=0 | ||
93 | # Parse command-line options | ||
94 | parse_opts $* | ||
95 | |||
96 | [ $DEBUG -ne 0 ] && set -x | ||
97 | |||
98 | # Verify parameters | ||
99 | if [ -z "$DEBUGFS_DIR" -o ! -d "$TRACING_DIR" ]; then | ||
100 | errexit "No ftrace directory found" | ||
101 | fi | ||
102 | |||
103 | # Preparing logs | ||
104 | LOG_FILE=$LOG_DIR/ftracetest.log | ||
105 | mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" | ||
106 | date > $LOG_FILE | ||
107 | prlog() { # messages | ||
108 | echo "$@" | tee -a $LOG_FILE | ||
109 | } | ||
110 | catlog() { #file | ||
111 | cat $1 | tee -a $LOG_FILE | ||
112 | } | ||
113 | prlog "=== Ftrace unit tests ===" | ||
114 | |||
115 | |||
116 | # Testcase management | ||
117 | PASSED_CASES= | ||
118 | FAILED_CASES= | ||
119 | CASENO=0 | ||
120 | testcase() { # testfile | ||
121 | CASENO=$((CASENO+1)) | ||
122 | prlog -n "[$CASENO]"`grep "^#[ \t]*description:" $1 | cut -f2 -d:` | ||
123 | } | ||
124 | failed() { | ||
125 | prlog " [FAIL]" | ||
126 | FAILED_CASES="$FAILED_CASES $CASENO" | ||
127 | } | ||
128 | passed() { | ||
129 | prlog " [PASS]" | ||
130 | PASSED_CASES="$PASSED_CASES $CASENO" | ||
131 | } | ||
132 | |||
133 | |||
134 | # Run one test case | ||
135 | run_test() { # testfile | ||
136 | local testname=`basename $1` | ||
137 | local testlog=`mktemp --tmpdir=$LOG_DIR ${testname}-XXXXXX.log` | ||
138 | testcase $1 | ||
139 | echo "execute: "$1 > $testlog | ||
140 | (cd $TRACING_DIR; set -x ; . $1) >> $testlog 2>&1 | ||
141 | ret=$? | ||
142 | if [ $ret -ne 0 ]; then | ||
143 | failed | ||
144 | catlog $testlog | ||
145 | else | ||
146 | passed | ||
147 | [ $KEEP_LOG -eq 0 ] && rm $testlog | ||
148 | fi | ||
149 | } | ||
150 | |||
151 | # Main loop | ||
152 | for t in $TEST_CASES; do | ||
153 | run_test $t | ||
154 | done | ||
155 | prlog "" | ||
156 | prlog "# of passed: " `echo $PASSED_CASES | wc -w` | ||
157 | prlog "# of failed: " `echo $FAILED_CASES | wc -w` | ||
158 | |||
159 | test -z "$FAILED_CASES" # if no error, return 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..ce5f735b2e65 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/template | |||
@@ -0,0 +1,4 @@ | |||
1 | #!/bin/sh | ||
2 | # description: %HERE DESCRIBE WHAT THIS DOES% | ||
3 | # you have to add ".tc" extention for your testcase file | ||
4 | exit 0 # Return 0 if the test is passed, otherwise return !0 | ||