.. | .. |
---|
1 | 1 | #!/bin/sh |
---|
| 2 | +# SPDX-License-Identifier: GPL-2.0-only |
---|
2 | 3 | |
---|
3 | 4 | # ftracetest - Ftrace test shell scripts |
---|
4 | 5 | # |
---|
5 | 6 | # Copyright (C) Hitachi Ltd., 2014 |
---|
6 | 7 | # Written by Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> |
---|
7 | 8 | # |
---|
8 | | -# Released under the terms of the GPL v2. |
---|
9 | 9 | |
---|
10 | 10 | usage() { # errno [message] |
---|
11 | 11 | [ ! -z "$2" ] && echo $2 |
---|
.. | .. |
---|
17 | 17 | echo " -vv Alias of -v -v (Show all results in stdout)" |
---|
18 | 18 | echo " -vvv Alias of -v -v -v (Show all commands immediately)" |
---|
19 | 19 | echo " --fail-unsupported Treat UNSUPPORTED as a failure" |
---|
| 20 | +echo " --fail-unresolved Treat UNRESOLVED as a failure" |
---|
20 | 21 | echo " -d|--debug Debug mode (trace all shell commands)" |
---|
21 | 22 | echo " -l|--logdir <dir> Save logs on the <dir>" |
---|
22 | 23 | echo " If <dir> is -, all logs output in console only" |
---|
23 | 24 | exit $1 |
---|
24 | 25 | } |
---|
25 | 26 | |
---|
| 27 | +# default error |
---|
| 28 | +err_ret=1 |
---|
| 29 | + |
---|
| 30 | +# kselftest skip code is 4 |
---|
| 31 | +err_skip=4 |
---|
| 32 | + |
---|
| 33 | +# cgroup RT scheduling prevents chrt commands from succeeding, which |
---|
| 34 | +# induces failures in test wakeup tests. Disable for the duration of |
---|
| 35 | +# the tests. |
---|
| 36 | + |
---|
| 37 | +readonly sched_rt_runtime=/proc/sys/kernel/sched_rt_runtime_us |
---|
| 38 | + |
---|
| 39 | +sched_rt_runtime_orig=$(cat $sched_rt_runtime) |
---|
| 40 | + |
---|
| 41 | +setup() { |
---|
| 42 | + echo -1 > $sched_rt_runtime |
---|
| 43 | +} |
---|
| 44 | + |
---|
| 45 | +cleanup() { |
---|
| 46 | + echo $sched_rt_runtime_orig > $sched_rt_runtime |
---|
| 47 | +} |
---|
| 48 | + |
---|
26 | 49 | errexit() { # message |
---|
27 | 50 | echo "Error: $1" 1>&2 |
---|
28 | | - exit 1 |
---|
| 51 | + cleanup |
---|
| 52 | + exit $err_ret |
---|
29 | 53 | } |
---|
30 | 54 | |
---|
31 | 55 | # Ensuring user privilege |
---|
32 | 56 | if [ `id -u` -ne 0 ]; then |
---|
33 | 57 | errexit "this must be run by root user" |
---|
34 | 58 | fi |
---|
| 59 | + |
---|
| 60 | +setup |
---|
35 | 61 | |
---|
36 | 62 | # Utilities |
---|
37 | 63 | absdir() { # file_path |
---|
.. | .. |
---|
60 | 86 | shift 1 |
---|
61 | 87 | ;; |
---|
62 | 88 | --verbose|-v|-vv|-vvv) |
---|
| 89 | + if [ $VERBOSE -eq -1 ]; then |
---|
| 90 | + usage "--console can not use with --verbose" |
---|
| 91 | + fi |
---|
63 | 92 | VERBOSE=$((VERBOSE + 1)) |
---|
64 | 93 | [ $1 = '-vv' ] && VERBOSE=$((VERBOSE + 1)) |
---|
65 | 94 | [ $1 = '-vvv' ] && VERBOSE=$((VERBOSE + 2)) |
---|
| 95 | + shift 1 |
---|
| 96 | + ;; |
---|
| 97 | + --console) |
---|
| 98 | + if [ $VERBOSE -ne 0 ]; then |
---|
| 99 | + usage "--console can not use with --verbose" |
---|
| 100 | + fi |
---|
| 101 | + VERBOSE=-1 |
---|
66 | 102 | shift 1 |
---|
67 | 103 | ;; |
---|
68 | 104 | --debug|-d) |
---|
69 | 105 | DEBUG=1 |
---|
70 | 106 | shift 1 |
---|
71 | 107 | ;; |
---|
| 108 | + --stop-fail) |
---|
| 109 | + STOP_FAILURE=1 |
---|
| 110 | + shift 1 |
---|
| 111 | + ;; |
---|
72 | 112 | --fail-unsupported) |
---|
73 | 113 | UNSUPPORTED_RESULT=1 |
---|
| 114 | + shift 1 |
---|
| 115 | + ;; |
---|
| 116 | + --fail-unresolved) |
---|
| 117 | + UNRESOLVED_RESULT=1 |
---|
74 | 118 | shift 1 |
---|
75 | 119 | ;; |
---|
76 | 120 | --logdir|-l) |
---|
.. | .. |
---|
102 | 146 | } |
---|
103 | 147 | |
---|
104 | 148 | # Parameters |
---|
105 | | -DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` |
---|
106 | | -if [ -z "$DEBUGFS_DIR" ]; then |
---|
107 | | - TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` |
---|
108 | | -else |
---|
109 | | - TRACING_DIR=$DEBUGFS_DIR/tracing |
---|
| 149 | +TRACING_DIR=`grep tracefs /proc/mounts | cut -f2 -d' ' | head -1` |
---|
| 150 | +if [ -z "$TRACING_DIR" ]; then |
---|
| 151 | + DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1` |
---|
| 152 | + if [ -z "$DEBUGFS_DIR" ]; then |
---|
| 153 | + # If tracefs exists, then so does /sys/kernel/tracing |
---|
| 154 | + if [ -d "/sys/kernel/tracing" ]; then |
---|
| 155 | + mount -t tracefs nodev /sys/kernel/tracing || |
---|
| 156 | + errexit "Failed to mount /sys/kernel/tracing" |
---|
| 157 | + TRACING_DIR="/sys/kernel/tracing" |
---|
| 158 | + # If debugfs exists, then so does /sys/kernel/debug |
---|
| 159 | + elif [ -d "/sys/kernel/debug" ]; then |
---|
| 160 | + mount -t debugfs nodev /sys/kernel/debug || |
---|
| 161 | + errexit "Failed to mount /sys/kernel/debug" |
---|
| 162 | + TRACING_DIR="/sys/kernel/debug/tracing" |
---|
| 163 | + else |
---|
| 164 | + err_ret=$err_skip |
---|
| 165 | + errexit "debugfs and tracefs are not configured in this kernel" |
---|
| 166 | + fi |
---|
| 167 | + else |
---|
| 168 | + TRACING_DIR="$DEBUGFS_DIR/tracing" |
---|
| 169 | + fi |
---|
| 170 | +fi |
---|
| 171 | +if [ ! -d "$TRACING_DIR" ]; then |
---|
| 172 | + err_ret=$err_skip |
---|
| 173 | + errexit "ftrace is not configured in this kernel" |
---|
110 | 174 | fi |
---|
111 | 175 | |
---|
112 | 176 | TOP_DIR=`absdir $0` |
---|
.. | .. |
---|
117 | 181 | DEBUG=0 |
---|
118 | 182 | VERBOSE=0 |
---|
119 | 183 | UNSUPPORTED_RESULT=0 |
---|
| 184 | +UNRESOLVED_RESULT=0 |
---|
| 185 | +STOP_FAILURE=0 |
---|
120 | 186 | # Parse command-line options |
---|
121 | 187 | parse_opts $* |
---|
122 | 188 | |
---|
.. | .. |
---|
137 | 203 | date > $LOG_FILE |
---|
138 | 204 | fi |
---|
139 | 205 | |
---|
| 206 | +# Define text colors |
---|
| 207 | +# Check available colors on the terminal, if any |
---|
| 208 | +ncolors=`tput colors 2>/dev/null || echo 0` |
---|
| 209 | +color_reset= |
---|
| 210 | +color_red= |
---|
| 211 | +color_green= |
---|
| 212 | +color_blue= |
---|
| 213 | +# If stdout exists and number of colors is eight or more, use them |
---|
| 214 | +if [ -t 1 -a "$ncolors" -ge 8 ]; then |
---|
| 215 | + color_reset="\033[0m" |
---|
| 216 | + color_red="\033[31m" |
---|
| 217 | + color_green="\033[32m" |
---|
| 218 | + color_blue="\033[34m" |
---|
| 219 | +fi |
---|
| 220 | + |
---|
| 221 | +strip_esc() { |
---|
| 222 | + # busybox sed implementation doesn't accept "\x1B", so use [:cntrl:] instead. |
---|
| 223 | + sed -E "s/[[:cntrl:]]\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" |
---|
| 224 | +} |
---|
| 225 | + |
---|
140 | 226 | prlog() { # messages |
---|
141 | | - [ -z "$LOG_FILE" ] && echo "$@" || echo "$@" | tee -a $LOG_FILE |
---|
| 227 | + newline="\n" |
---|
| 228 | + if [ "$1" = "-n" ] ; then |
---|
| 229 | + newline= |
---|
| 230 | + shift |
---|
| 231 | + fi |
---|
| 232 | + printf "$*$newline" |
---|
| 233 | + [ "$LOG_FILE" ] && printf "$*$newline" | strip_esc >> $LOG_FILE |
---|
142 | 234 | } |
---|
143 | 235 | catlog() { #file |
---|
144 | | - [ -z "$LOG_FILE" ] && cat $1 || cat $1 | tee -a $LOG_FILE |
---|
| 236 | + cat $1 |
---|
| 237 | + [ "$LOG_FILE" ] && cat $1 | strip_esc >> $LOG_FILE |
---|
145 | 238 | } |
---|
146 | 239 | prlog "=== Ftrace unit tests ===" |
---|
147 | 240 | |
---|
.. | .. |
---|
167 | 260 | |
---|
168 | 261 | INSTANCE= |
---|
169 | 262 | CASENO=0 |
---|
| 263 | + |
---|
170 | 264 | testcase() { # testfile |
---|
171 | 265 | CASENO=$((CASENO+1)) |
---|
172 | | - desc=`grep "^#[ \t]*description:" $1 | cut -f2 -d:` |
---|
| 266 | + desc=`grep "^#[ \t]*description:" $1 | cut -f2- -d:` |
---|
173 | 267 | prlog -n "[$CASENO]$INSTANCE$desc" |
---|
| 268 | +} |
---|
| 269 | + |
---|
| 270 | +checkreq() { # testfile |
---|
| 271 | + requires=`grep "^#[ \t]*requires:" $1 | cut -f2- -d:` |
---|
| 272 | + # Use eval to pass quoted-patterns correctly. |
---|
| 273 | + eval check_requires "$requires" |
---|
174 | 274 | } |
---|
175 | 275 | |
---|
176 | 276 | test_on_instance() { # testfile |
---|
.. | .. |
---|
180 | 280 | eval_result() { # sigval |
---|
181 | 281 | case $1 in |
---|
182 | 282 | $PASS) |
---|
183 | | - prlog " [PASS]" |
---|
| 283 | + prlog " [${color_green}PASS${color_reset}]" |
---|
184 | 284 | PASSED_CASES="$PASSED_CASES $CASENO" |
---|
185 | 285 | return 0 |
---|
186 | 286 | ;; |
---|
187 | 287 | $FAIL) |
---|
188 | | - prlog " [FAIL]" |
---|
| 288 | + prlog " [${color_red}FAIL${color_reset}]" |
---|
189 | 289 | FAILED_CASES="$FAILED_CASES $CASENO" |
---|
190 | 290 | return 1 # this is a bug. |
---|
191 | 291 | ;; |
---|
192 | 292 | $UNRESOLVED) |
---|
193 | | - prlog " [UNRESOLVED]" |
---|
| 293 | + prlog " [${color_blue}UNRESOLVED${color_reset}]" |
---|
194 | 294 | UNRESOLVED_CASES="$UNRESOLVED_CASES $CASENO" |
---|
195 | | - return 1 # this is a kind of bug.. something happened. |
---|
| 295 | + return $UNRESOLVED_RESULT # depends on use case |
---|
196 | 296 | ;; |
---|
197 | 297 | $UNTESTED) |
---|
198 | | - prlog " [UNTESTED]" |
---|
| 298 | + prlog " [${color_blue}UNTESTED${color_reset}]" |
---|
199 | 299 | UNTESTED_CASES="$UNTESTED_CASES $CASENO" |
---|
200 | 300 | return 0 |
---|
201 | 301 | ;; |
---|
202 | 302 | $UNSUPPORTED) |
---|
203 | | - prlog " [UNSUPPORTED]" |
---|
| 303 | + prlog " [${color_blue}UNSUPPORTED${color_reset}]" |
---|
204 | 304 | UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO" |
---|
205 | 305 | return $UNSUPPORTED_RESULT # depends on use case |
---|
206 | 306 | ;; |
---|
207 | 307 | $XFAIL) |
---|
208 | | - prlog " [XFAIL]" |
---|
| 308 | + prlog " [${color_green}XFAIL${color_reset}]" |
---|
209 | 309 | XFAILED_CASES="$XFAILED_CASES $CASENO" |
---|
210 | 310 | return 0 |
---|
211 | 311 | ;; |
---|
212 | 312 | *) |
---|
213 | | - prlog " [UNDEFINED]" |
---|
| 313 | + prlog " [${color_blue}UNDEFINED${color_reset}]" |
---|
214 | 314 | UNDEFINED_CASES="$UNDEFINED_CASES $CASENO" |
---|
215 | 315 | return 1 # this must be a test bug |
---|
216 | 316 | ;; |
---|
.. | .. |
---|
262 | 362 | |
---|
263 | 363 | __run_test() { # testfile |
---|
264 | 364 | # setup PID and PPID, $$ is not updated. |
---|
265 | | - (cd $TRACING_DIR; read PID _ < /proc/self/stat; set -e; set -x; initialize_ftrace; . $1) |
---|
| 365 | + (cd $TRACING_DIR; read PID _ < /proc/self/stat; set -e; set -x; |
---|
| 366 | + checkreq $1; initialize_ftrace; . $1) |
---|
266 | 367 | [ $? -ne 0 ] && kill -s $SIG_FAIL $SIG_PID |
---|
267 | 368 | } |
---|
268 | 369 | |
---|
269 | 370 | # Run one test case |
---|
270 | 371 | run_test() { # testfile |
---|
271 | 372 | local testname=`basename $1` |
---|
| 373 | + testcase $1 |
---|
272 | 374 | if [ ! -z "$LOG_FILE" ] ; then |
---|
273 | | - local testlog=`mktemp $LOG_DIR/${testname}-log.XXXXXX` |
---|
| 375 | + local testlog=`mktemp $LOG_DIR/${CASENO}-${testname}-log.XXXXXX` |
---|
274 | 376 | else |
---|
275 | 377 | local testlog=/proc/self/fd/1 |
---|
276 | 378 | fi |
---|
277 | 379 | export TMPDIR=`mktemp -d /tmp/ftracetest-dir.XXXXXX` |
---|
278 | | - testcase $1 |
---|
| 380 | + export FTRACETEST_ROOT=$TOP_DIR |
---|
279 | 381 | echo "execute$INSTANCE: "$1 > $testlog |
---|
280 | 382 | SIG_RESULT=0 |
---|
281 | | - if [ -z "$LOG_FILE" ]; then |
---|
| 383 | + if [ $VERBOSE -eq -1 ]; then |
---|
| 384 | + __run_test $1 |
---|
| 385 | + elif [ -z "$LOG_FILE" ]; then |
---|
282 | 386 | __run_test $1 2>&1 |
---|
283 | 387 | elif [ $VERBOSE -ge 3 ]; then |
---|
284 | 388 | __run_test $1 | tee -a $testlog 2>&1 |
---|
.. | .. |
---|
304 | 408 | # Main loop |
---|
305 | 409 | for t in $TEST_CASES; do |
---|
306 | 410 | run_test $t |
---|
| 411 | + if [ $STOP_FAILURE -ne 0 -a $TOTAL_RESULT -ne 0 ]; then |
---|
| 412 | + echo "A failure detected. Stop test." |
---|
| 413 | + exit 1 |
---|
| 414 | + fi |
---|
307 | 415 | done |
---|
308 | 416 | |
---|
309 | 417 | # Test on instance loop |
---|
.. | .. |
---|
315 | 423 | run_test $t |
---|
316 | 424 | rmdir $TRACING_DIR |
---|
317 | 425 | TRACING_DIR=$SAVED_TRACING_DIR |
---|
| 426 | + if [ $STOP_FAILURE -ne 0 -a $TOTAL_RESULT -ne 0 ]; then |
---|
| 427 | + echo "A failure detected. Stop test." |
---|
| 428 | + exit 1 |
---|
| 429 | + fi |
---|
318 | 430 | done |
---|
| 431 | +(cd $TRACING_DIR; initialize_ftrace) # for cleanup |
---|
319 | 432 | |
---|
320 | 433 | prlog "" |
---|
321 | 434 | prlog "# of passed: " `echo $PASSED_CASES | wc -w` |
---|
.. | .. |
---|
326 | 439 | prlog "# of xfailed: " `echo $XFAILED_CASES | wc -w` |
---|
327 | 440 | prlog "# of undefined(test bug): " `echo $UNDEFINED_CASES | wc -w` |
---|
328 | 441 | |
---|
| 442 | +cleanup |
---|
| 443 | + |
---|
329 | 444 | # if no error, return 0 |
---|
330 | 445 | exit $TOTAL_RESULT |
---|