a8f81c782856270ff559dcf7d48d52aec182df31
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 " -d|--debug Debug mode (trace all shell commands)"
25 # Ensuring user privilege
26 if [ `id -u` -ne 0 ]; then
27 errexit
"this must be run by root user"
31 absdir
() { # file_path
32 (cd `dirname $1`; pwd)
36 echo `absdir $1`/`basename $1`
39 find_testcases
() { #directory
40 echo `find $1 -name \*.tc`
62 OPT_TEST_CASES
="$OPT_TEST_CASES `abspath $1`"
65 usage
1 "$1 is not a testcase"
70 OPT_TEST_DIR
=`abspath $1`
71 OPT_TEST_CASES
="$OPT_TEST_CASES `find_testcases $OPT_TEST_DIR`"
74 usage
1 "Invalid option ($1)"
79 if [ "$OPT_TEST_CASES" ]; then
80 TEST_CASES
=$OPT_TEST_CASES
85 DEBUGFS_DIR
=`grep debugfs /proc/mounts | cut -f2 -d' '`
86 TRACING_DIR
=$DEBUGFS_DIR/tracing
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`/
93 # Parse command-line options
96 [ $DEBUG -ne 0 ] && set -x
99 if [ -z "$DEBUGFS_DIR" -o ! -d "$TRACING_DIR" ]; then
100 errexit
"No ftrace directory found"
104 LOG_FILE
=$LOG_DIR/ftracetest.log
105 mkdir
-p $LOG_DIR || errexit
"Failed to make a log directory: $LOG_DIR"
108 echo "$@" |
tee -a $LOG_FILE
111 cat $1 |
tee -a $LOG_FILE
113 prlog
"=== Ftrace unit tests ==="
116 # Testcase management
117 # Test result codes - Dejagnu extended code
118 PASS
=0 # The test succeeded.
119 FAIL
=1 # The test failed, but was expected to succeed.
120 UNRESOLVED
=2 # The test produced indeterminate results. (e.g. interrupted)
121 UNTESTED
=3 # The test was not run, currently just a placeholder.
122 UNSUPPORTED
=4 # The test failed because of lack of feature.
123 XFAIL
=5 # The test failed, and was expected to fail.
136 testcase
() { # testfile
138 prlog
-n "[$CASENO]"`grep "^#[ \t]*description:" $1 | cut -f2 -d:`
141 eval_result
() { # retval sigval
143 if [ $2 -eq 0 ]; then
144 test $1 -ne 0 && retval
=$FAIL
149 PASSED_CASES
="$PASSED_CASES $CASENO"
154 FAILED_CASES
="$FAILED_CASES $CASENO"
155 return 1 # this is a bug.
158 prlog
" [UNRESOLVED]"
159 UNRESOLVED_CASES
="$UNRESOLVED_CASES $CASENO"
160 return 1 # this is a kind of bug.. something happened.
164 UNTESTED_CASES
="$UNTESTED_CASES $CASENO"
168 prlog
" [UNSUPPORTED]"
169 UNSUPPORTED_CASES
="$UNSUPPORTED_CASES $CASENO"
170 return 1 # this is not a bug, but the result should be reported.
174 XFAILED_CASES
="$XFAILED_CASES $CASENO"
179 UNDEFINED_CASES
="$UNDEFINED_CASES $CASENO"
180 return 1 # this must be a test bug
185 # Signal handling for result codes
187 SIG_BASE
=36 # Use realtime signals
190 SIG_UNRESOLVED
=$
((SIG_BASE
+ UNRESOLVED
))
192 kill -s $SIG_UNRESOLVED $SIG_PID
195 trap 'SIG_RESULT=$UNRESOLVED' $SIG_UNRESOLVED
197 SIG_UNTESTED
=$
((SIG_BASE
+ UNTESTED
))
199 kill -s $SIG_UNTESTED $SIG_PID
202 trap 'SIG_RESULT=$UNTESTED' $SIG_UNTESTED
204 SIG_UNSUPPORTED
=$
((SIG_BASE
+ UNSUPPORTED
))
205 exit_unsupported
() {
206 kill -s $SIG_UNSUPPORTED $SIG_PID
209 trap 'SIG_RESULT=$UNSUPPORTED' $SIG_UNSUPPORTED
211 SIG_XFAIL
=$
((SIG_BASE
+ XFAIL
))
213 kill -s $SIG_XFAIL $SIG_PID
216 trap 'SIG_RESULT=$XFAIL' $SIG_XFAIL
219 run_test
() { # testfile
220 local testname
=`basename $1`
221 local testlog
=`mktemp --tmpdir=$LOG_DIR ${testname}-XXXXXX.log`
223 echo "execute: "$1 > $testlog
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
239 for t
in $TEST_CASES; do
244 prlog
"# of passed: " `echo $PASSED_CASES | wc -w`
245 prlog
"# of failed: " `echo $FAILED_CASES | wc -w`
246 prlog
"# of unresolved: " `echo $UNRESOLVED_CASES | wc -w`
247 prlog
"# of untested: " `echo $UNTESTED_CASES | wc -w`
248 prlog
"# of unsupported: " `echo $UNSUPPORTED_CASES | wc -w`
249 prlog
"# of xfailed: " `echo $XFAILED_CASES | wc -w`
250 prlog
"# of undefined(test bug): " `echo $UNDEFINED_CASES | wc -w`
252 # if no error, return 0
This page took 0.036654 seconds and 4 git commands to generate.