]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/testing/selftests/ftrace/ftracetest
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 " --fail-unsupported Treat UNSUPPORTED as a failure"
19 echo " -d|--debug Debug mode (trace all shell commands)"
20 echo " -l|--logdir <dir> Save logs on the <dir>"
29 # Ensuring user privilege
30 if [ `id -u` -ne 0 ]; then
31 errexit
"this must be run by root user"
35 absdir
() { # file_path
36 (cd `dirname $1`; pwd)
40 echo `absdir $1`/`basename $1`
43 find_testcases
() { #directory
44 echo `find $1 -name \*.tc | sort`
61 VERBOSE
=$
((VERBOSE
+ 1))
62 [ $1 = '-vv' ] && VERBOSE
=$
((VERBOSE
+ 1))
79 OPT_TEST_CASES
="$OPT_TEST_CASES `abspath $1`"
82 usage
1 "$1 is not a testcase"
87 OPT_TEST_DIR
=`abspath $1`
88 OPT_TEST_CASES
="$OPT_TEST_CASES `find_testcases $OPT_TEST_DIR`"
91 usage
1 "Invalid option ($1)"
96 if [ "$OPT_TEST_CASES" ]; then
97 TEST_CASES
=$OPT_TEST_CASES
102 DEBUGFS_DIR
=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1`
103 if [ -z "$DEBUGFS_DIR" ]; then
104 TRACING_DIR
=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1`
106 TRACING_DIR
=$DEBUGFS_DIR/tracing
110 TEST_DIR
=$TOP_DIR/test.d
111 TEST_CASES
=`find_testcases $TEST_DIR`
112 LOG_DIR
=$TOP_DIR/logs
/`date +%Y%m%d-%H%M%S`/
117 # Parse command-line options
120 [ $DEBUG -ne 0 ] && set -x
123 if [ -z "$TRACING_DIR" -o ! -d "$TRACING_DIR" ]; then
124 errexit
"No ftrace directory found"
128 LOG_FILE
=$LOG_DIR/ftracetest.log
129 mkdir
-p $LOG_DIR || errexit
"Failed to make a log directory: $LOG_DIR"
132 echo "$@" |
tee -a $LOG_FILE
135 cat $1 |
tee -a $LOG_FILE
137 prlog
"=== Ftrace unit tests ==="
140 # Testcase management
141 # Test result codes - Dejagnu extended code
142 PASS
=0 # The test succeeded.
143 FAIL
=1 # The test failed, but was expected to succeed.
144 UNRESOLVED
=2 # The test produced indeterminate results. (e.g. interrupted)
145 UNTESTED
=3 # The test was not run, currently just a placeholder.
146 UNSUPPORTED
=4 # The test failed because of lack of feature.
147 XFAIL
=5 # The test failed, and was expected to fail.
161 testcase
() { # testfile
163 desc
=`grep "^#[ \t]*description:" $1 | cut -f2 -d:`
164 prlog
-n "[$CASENO]$INSTANCE$desc"
167 test_on_instance
() { # testfile
168 grep -q "^#[ \t]*flags:.*instance" $1
171 eval_result
() { # sigval
175 PASSED_CASES
="$PASSED_CASES $CASENO"
180 FAILED_CASES
="$FAILED_CASES $CASENO"
181 return 1 # this is a bug.
184 prlog
" [UNRESOLVED]"
185 UNRESOLVED_CASES
="$UNRESOLVED_CASES $CASENO"
186 return 1 # this is a kind of bug.. something happened.
190 UNTESTED_CASES
="$UNTESTED_CASES $CASENO"
194 prlog
" [UNSUPPORTED]"
195 UNSUPPORTED_CASES
="$UNSUPPORTED_CASES $CASENO"
196 return $UNSUPPORTED_RESULT # depends on use case
200 XFAILED_CASES
="$XFAILED_CASES $CASENO"
205 UNDEFINED_CASES
="$UNDEFINED_CASES $CASENO"
206 return 1 # this must be a test bug
211 # Signal handling for result codes
213 SIG_BASE
=36 # Use realtime signals
216 SIG_FAIL
=$
((SIG_BASE
+ FAIL
))
217 trap 'SIG_RESULT=$FAIL' $SIG_FAIL
219 SIG_UNRESOLVED
=$
((SIG_BASE
+ UNRESOLVED
))
221 kill -s $SIG_UNRESOLVED $SIG_PID
224 trap 'SIG_RESULT=$UNRESOLVED' $SIG_UNRESOLVED
226 SIG_UNTESTED
=$
((SIG_BASE
+ UNTESTED
))
228 kill -s $SIG_UNTESTED $SIG_PID
231 trap 'SIG_RESULT=$UNTESTED' $SIG_UNTESTED
233 SIG_UNSUPPORTED
=$
((SIG_BASE
+ UNSUPPORTED
))
234 exit_unsupported
() {
235 kill -s $SIG_UNSUPPORTED $SIG_PID
238 trap 'SIG_RESULT=$UNSUPPORTED' $SIG_UNSUPPORTED
240 SIG_XFAIL
=$
((SIG_BASE
+ XFAIL
))
242 kill -s $SIG_XFAIL $SIG_PID
245 trap 'SIG_RESULT=$XFAIL' $SIG_XFAIL
247 __run_test
() { # testfile
248 # setup PID and PPID, $$ is not updated.
249 (cd $TRACING_DIR; read PID _
< /proc
/self
/stat
; set -e; set -x; initialize_ftrace
; .
$1)
250 [ $?
-ne 0 ] && kill -s $SIG_FAIL $SIG_PID
254 run_test
() { # testfile
255 local testname
=`basename $1`
256 local testlog
=`mktemp $LOG_DIR/${testname}-log.XXXXXX`
257 export TMPDIR
=`mktemp -d /tmp/ftracetest-dir.XXXXXX`
259 echo "execute$INSTANCE: "$1 > $testlog
261 if [ $VERBOSE -ge 2 ]; then
262 __run_test
$1 2>> $testlog |
tee -a $testlog
264 __run_test
$1 >> $testlog 2>&1
266 eval_result
$SIG_RESULT
267 if [ $?
-eq 0 ]; then
268 # Remove test log if the test was done as it was expected.
269 [ $KEEP_LOG -eq 0 ] && rm $testlog
271 [ $VERBOSE -ge 1 ] && catlog
$testlog
277 # load in the helper functions
278 .
$TEST_DIR/functions
281 for t
in $TEST_CASES; do
285 # Test on instance loop
286 INSTANCE
=" (instance) "
287 for t
in $TEST_CASES; do
288 test_on_instance
$t ||
continue
289 SAVED_TRACING_DIR
=$TRACING_DIR
290 export TRACING_DIR
=`mktemp -d $TRACING_DIR/instances/ftracetest.XXXXXX`
293 TRACING_DIR
=$SAVED_TRACING_DIR
297 prlog
"# of passed: " `echo $PASSED_CASES | wc -w`
298 prlog
"# of failed: " `echo $FAILED_CASES | wc -w`
299 prlog
"# of unresolved: " `echo $UNRESOLVED_CASES | wc -w`
300 prlog
"# of untested: " `echo $UNTESTED_CASES | wc -w`
301 prlog
"# of unsupported: " `echo $UNSUPPORTED_CASES | wc -w`
302 prlog
"# of xfailed: " `echo $XFAILED_CASES | wc -w`
303 prlog
"# of undefined(test bug): " `echo $UNDEFINED_CASES | wc -w`
305 # if no error, return 0