2 # SPDX-License-Identifier: GPL-2.0
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.
10 TRIGGER
=/sys
/kernel
/debug
/provoke-crash
/DIRECT
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?)"
19 echo "Cannot write $TRIGGER (need to run as root?)"
22 exit $KSELFTEST_SKIP_TEST
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
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
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-)
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"
53 echo "Skipping $test: $expect"
54 exit $KSELFTEST_SKIP_TEST
57 # If no expected output given, assume an Oops with back trace is success.
58 if [ -z "$expect" ]; then
62 # Clear out dmesg for output reporting
65 # Prepare log for report checking
66 LOG
=$
(mktemp
--tmpdir -t lkdtm-XXXXXX
)
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
75 ($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev
/null
) || true
77 # Record and dump the results
80 # Check for expected output
81 if egrep -qi "$expect" "$LOG" ; then
82 echo "$test: saw '$expect': ok"
85 if egrep -qi XFAIL
: "$LOG" ; then
86 echo "$test: saw 'XFAIL': [SKIP]"
87 exit $KSELFTEST_SKIP_TEST
89 echo "$test: missing '$expect': [FAIL]"