]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/testing/selftests/ftrace/ftracetest
52e3c4df28d6ff243a70190592d404eba2be23b7
3 # ftracetest - Ftrace test shell scripts
5 # Copyright (C) Hitachi Ltd., 2014
6 # Written by Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
8 # Released under the terms of the GPL v2.
10 usage
() { # errno [message]
12 echo "Usage: ftracetest [options] [testcase(s)] [testcase-directory(s)]"
14 echo " -h|--help Show help message"
15 echo " -k|--keep Keep passed test logs"
16 echo " -v|--verbose Increase verbosity of test messages"
17 echo " -vv Alias of -v -v (Show all results in stdout)"
18 echo " -d|--debug Debug mode (trace all shell commands)"
27 # Ensuring user privilege
28 if [ `id -u` -ne 0 ]; then
29 errexit
"this must be run by root user"
33 absdir
() { # file_path
34 (cd `dirname $1`; pwd)
38 echo `absdir $1`/`basename $1`
41 find_testcases
() { #directory
42 echo `find $1 -name \*.tc | sort`
59 VERBOSE
=$
((VERBOSE
+ 1))
60 [ $1 == '-vv' ] && VERBOSE
=$
((VERBOSE
+ 1))
69 OPT_TEST_CASES
="$OPT_TEST_CASES `abspath $1`"
72 usage
1 "$1 is not a testcase"
77 OPT_TEST_DIR
=`abspath $1`
78 OPT_TEST_CASES
="$OPT_TEST_CASES `find_testcases $OPT_TEST_DIR`"
81 usage
1 "Invalid option ($1)"
86 if [ "$OPT_TEST_CASES" ]; then
87 TEST_CASES
=$OPT_TEST_CASES
92 DEBUGFS_DIR
=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1`
93 if [ -z "$DEBUGFS_DIR" ]; then
94 TRACING_DIR
=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1`
96 TRACING_DIR
=$DEBUGFS_DIR/tracing
100 TEST_DIR
=$TOP_DIR/test.d
101 TEST_CASES
=`find_testcases $TEST_DIR`
102 LOG_DIR
=$TOP_DIR/logs
/`date +%Y%m%d-%H%M%S`/
106 # Parse command-line options
109 [ $DEBUG -ne 0 ] && set -x
112 if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then
113 errexit
"No ftrace directory found"
117 LOG_FILE
=$LOG_DIR/ftracetest.log
118 mkdir
-p $LOG_DIR || errexit
"Failed to make a log directory: $LOG_DIR"
121 echo "$@" |
tee -a $LOG_FILE
124 cat $1 |
tee -a $LOG_FILE
126 prlog
"=== Ftrace unit tests ==="
129 # Testcase management
130 # Test result codes - Dejagnu extended code
131 PASS
=0 # The test succeeded.
132 FAIL
=1 # The test failed, but was expected to succeed.
133 UNRESOLVED
=2 # The test produced indeterminate results. (e.g. interrupted)
134 UNTESTED
=3 # The test was not run, currently just a placeholder.
135 UNSUPPORTED
=4 # The test failed because of lack of feature.
136 XFAIL
=5 # The test failed, and was expected to fail.
149 testcase
() { # testfile
151 desc
=`grep "^#[ \t]*description:" $1 | cut -f2 -d:`
152 prlog
-n "[$CASENO]$desc"
155 eval_result
() { # sigval
159 PASSED_CASES
="$PASSED_CASES $CASENO"
164 FAILED_CASES
="$FAILED_CASES $CASENO"
165 return 1 # this is a bug.
168 prlog
" [UNRESOLVED]"
169 UNRESOLVED_CASES
="$UNRESOLVED_CASES $CASENO"
170 return 1 # this is a kind of bug.. something happened.
174 UNTESTED_CASES
="$UNTESTED_CASES $CASENO"
178 prlog
" [UNSUPPORTED]"
179 UNSUPPORTED_CASES
="$UNSUPPORTED_CASES $CASENO"
180 return 1 # this is not a bug, but the result should be reported.
184 XFAILED_CASES
="$XFAILED_CASES $CASENO"
189 UNDEFINED_CASES
="$UNDEFINED_CASES $CASENO"
190 return 1 # this must be a test bug
195 # Signal handling for result codes
197 SIG_BASE
=36 # Use realtime signals
200 SIG_FAIL
=$
((SIG_BASE
+ FAIL
))
201 trap 'SIG_RESULT=$FAIL' $SIG_FAIL
203 SIG_UNRESOLVED
=$
((SIG_BASE
+ UNRESOLVED
))
205 kill -s $SIG_UNRESOLVED $SIG_PID
208 trap 'SIG_RESULT=$UNRESOLVED' $SIG_UNRESOLVED
210 SIG_UNTESTED
=$
((SIG_BASE
+ UNTESTED
))
212 kill -s $SIG_UNTESTED $SIG_PID
215 trap 'SIG_RESULT=$UNTESTED' $SIG_UNTESTED
217 SIG_UNSUPPORTED
=$
((SIG_BASE
+ UNSUPPORTED
))
218 exit_unsupported
() {
219 kill -s $SIG_UNSUPPORTED $SIG_PID
222 trap 'SIG_RESULT=$UNSUPPORTED' $SIG_UNSUPPORTED
224 SIG_XFAIL
=$
((SIG_BASE
+ XFAIL
))
226 kill -s $SIG_XFAIL $SIG_PID
229 trap 'SIG_RESULT=$XFAIL' $SIG_XFAIL
231 __run_test
() { # testfile
232 # setup PID and PPID, $$ is not updated.
233 (cd $TRACING_DIR; read PID _
< /proc
/self
/stat
; set -e; set -x; initialize_ftrace
; .
$1)
234 [ $?
-ne 0 ] && kill -s $SIG_FAIL $SIG_PID
238 run_test
() { # testfile
239 local testname
=`basename $1`
240 local testlog
=`mktemp $LOG_DIR/${testname}-log.XXXXXX`
241 export TMPDIR
=`mktemp -d /tmp/ftracetest-dir.XXXXXX`
243 echo "execute: "$1 > $testlog
245 if [ $VERBOSE -ge 2 ]; then
246 __run_test
$1 2>> $testlog |
tee -a $testlog
248 __run_test
$1 >> $testlog 2>&1
250 eval_result
$SIG_RESULT
251 if [ $?
-eq 0 ]; then
252 # Remove test log if the test was done as it was expected.
253 [ $KEEP_LOG -eq 0 ] && rm $testlog
255 [ $VERBOSE -ge 1 ] && catlog
$testlog
261 # load in the helper functions
262 .
$TEST_DIR/functions
265 for t
in $TEST_CASES; do
270 prlog
"# of passed: " `echo $PASSED_CASES | wc -w`
271 prlog
"# of failed: " `echo $FAILED_CASES | wc -w`
272 prlog
"# of unresolved: " `echo $UNRESOLVED_CASES | wc -w`
273 prlog
"# of untested: " `echo $UNTESTED_CASES | wc -w`
274 prlog
"# of unsupported: " `echo $UNSUPPORTED_CASES | wc -w`
275 prlog
"# of xfailed: " `echo $XFAILED_CASES | wc -w`
276 prlog
"# of undefined(test bug): " `echo $UNDEFINED_CASES | wc -w`
278 # if no error, return 0