WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / lkdtm / run.sh
blobbb7a1775307b809a2e18254a1b4de01f1c294678
1 #!/bin/sh
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.
9 set -e
10 TRIGGER=/sys/kernel/debug/provoke-crash/DIRECT
11 CLEAR_ONCE=/sys/kernel/debug/clear_warn_once
12 KSELFTEST_SKIP_TEST=4
14 # Verify we have LKDTM available in the kernel.
15 if [ ! -r $TRIGGER ] ; then
16 /sbin/modprobe -q lkdtm || true
17 if [ ! -r $TRIGGER ] ; then
18 echo "Cannot find $TRIGGER (missing CONFIG_LKDTM?)"
19 else
20 echo "Cannot write $TRIGGER (need to run as root?)"
22 # Skip this test
23 exit $KSELFTEST_SKIP_TEST
26 # Figure out which test to run from our script name.
27 test=$(basename $0 .sh)
28 # Look up details about the test from master list of LKDTM tests.
29 line=$(grep -E '^#?'"$test"'\b' tests.txt)
30 if [ -z "$line" ]; then
31 echo "Skipped: missing test '$test' in tests.txt"
32 exit $KSELFTEST_SKIP_TEST
34 # Check that the test is known to LKDTM.
35 if ! grep -E -q '^'"$test"'$' "$TRIGGER" ; then
36 echo "Skipped: test '$test' missing in $TRIGGER!"
37 exit $KSELFTEST_SKIP_TEST
40 # Extract notes/expected output from test list.
41 test=$(echo "$line" | cut -d" " -f1)
42 if echo "$line" | grep -q ' ' ; then
43 expect=$(echo "$line" | cut -d" " -f2-)
44 else
45 expect=""
48 # If the test is commented out, report a skip
49 if echo "$test" | grep -q '^#' ; then
50 test=$(echo "$test" | cut -c2-)
51 if [ -z "$expect" ]; then
52 expect="crashes entire system"
54 echo "Skipping $test: $expect"
55 exit $KSELFTEST_SKIP_TEST
58 # If no expected output given, assume an Oops with back trace is success.
59 if [ -z "$expect" ]; then
60 expect="call trace:"
63 # Prepare log for report checking
64 LOG=$(mktemp --tmpdir -t lkdtm-log-XXXXXX)
65 DMESG=$(mktemp --tmpdir -t lkdtm-dmesg-XXXXXX)
66 cleanup() {
67 rm -f "$LOG" "$DMESG"
69 trap cleanup EXIT
71 # Reset WARN_ONCE counters so we trip it each time this runs.
72 if [ -w $CLEAR_ONCE ] ; then
73 echo 1 > $CLEAR_ONCE
76 # Save existing dmesg so we can detect new content below
77 dmesg > "$DMESG"
79 # Most shells yell about signals and we're expecting the "cat" process
80 # to usually be killed by the kernel. So we have to run it in a sub-shell
81 # and silence errors.
82 ($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true
84 # Record and dump the results
85 dmesg | comm --nocheck-order -13 "$DMESG" - > "$LOG" || true
87 cat "$LOG"
88 # Check for expected output
89 if grep -E -qi "$expect" "$LOG" ; then
90 echo "$test: saw '$expect': ok"
91 exit 0
92 else
93 if grep -E -qi XFAIL: "$LOG" ; then
94 echo "$test: saw 'XFAIL': [SKIP]"
95 exit $KSELFTEST_SKIP_TEST
96 else
97 echo "$test: missing '$expect': [FAIL]"
98 exit 1