]> git.ipfire.org Git - thirdparty/linux.git/blob - tools/testing/selftests/lkdtm/run.sh
io_uring: reset -EBUSY error when io sq thread is waken up
[thirdparty/linux.git] / tools / testing / selftests / lkdtm / run.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # This reads tests.txt for the list of LKDTM tests to invoke. Any marked
5 # with a leading "#" are skipped. The rest of the line after the
6 # test name is either the text to look for in dmesg for a "success",
7 # or the rationale for why a test is marked to be skipped.
8 #
9 set -e
10 TRIGGER=/sys/kernel/debug/provoke-crash/DIRECT
11 KSELFTEST_SKIP_TEST=4
12
13 # Verify we have LKDTM available in the kernel.
14 if [ ! -r $TRIGGER ] ; then
15 /sbin/modprobe -q lkdtm || true
16 if [ ! -r $TRIGGER ] ; then
17 echo "Cannot find $TRIGGER (missing CONFIG_LKDTM?)"
18 else
19 echo "Cannot write $TRIGGER (need to run as root?)"
20 fi
21 # Skip this test
22 exit $KSELFTEST_SKIP_TEST
23 fi
24
25 # Figure out which test to run from our script name.
26 test=$(basename $0 .sh)
27 # Look up details about the test from master list of LKDTM tests.
28 line=$(egrep '^#?'"$test"'\b' tests.txt)
29 if [ -z "$line" ]; then
30 echo "Skipped: missing test '$test' in tests.txt"
31 exit $KSELFTEST_SKIP_TEST
32 fi
33 # Check that the test is known to LKDTM.
34 if ! egrep -q '^'"$test"'$' "$TRIGGER" ; then
35 echo "Skipped: test '$test' missing in $TRIGGER!"
36 exit $KSELFTEST_SKIP_TEST
37 fi
38
39 # Extract notes/expected output from test list.
40 test=$(echo "$line" | cut -d" " -f1)
41 if echo "$line" | grep -q ' ' ; then
42 expect=$(echo "$line" | cut -d" " -f2-)
43 else
44 expect=""
45 fi
46
47 # If the test is commented out, report a skip
48 if echo "$test" | grep -q '^#' ; then
49 test=$(echo "$test" | cut -c2-)
50 if [ -z "$expect" ]; then
51 expect="crashes entire system"
52 fi
53 echo "Skipping $test: $expect"
54 exit $KSELFTEST_SKIP_TEST
55 fi
56
57 # If no expected output given, assume an Oops with back trace is success.
58 if [ -z "$expect" ]; then
59 expect="call trace:"
60 fi
61
62 # Clear out dmesg for output reporting
63 dmesg -c >/dev/null
64
65 # Prepare log for report checking
66 LOG=$(mktemp --tmpdir -t lkdtm-XXXXXX)
67 cleanup() {
68 rm -f "$LOG"
69 }
70 trap cleanup EXIT
71
72 # Most shells yell about signals and we're expecting the "cat" process
73 # to usually be killed by the kernel. So we have to run it in a sub-shell
74 # and silence errors.
75 ($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true
76
77 # Record and dump the results
78 dmesg -c >"$LOG"
79 cat "$LOG"
80 # Check for expected output
81 if egrep -qi "$expect" "$LOG" ; then
82 echo "$test: saw '$expect': ok"
83 exit 0
84 else
85 if egrep -qi XFAIL: "$LOG" ; then
86 echo "$test: saw 'XFAIL': [SKIP]"
87 exit $KSELFTEST_SKIP_TEST
88 else
89 echo "$test: missing '$expect': [FAIL]"
90 exit 1
91 fi
92 fi