brintos

brintos / linux-shallow public Read only

0
0
Text · 3.1 KiB · 95e9049 Raw
113 lines · bash
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.03#4# This reads tests.txt for the list of LKDTM tests to invoke. Any marked5# with a leading "#" are skipped. The rest of the line after the6# 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#9set -e10TRIGGER=/sys/kernel/debug/provoke-crash/DIRECT11CLEAR_ONCE=/sys/kernel/debug/clear_warn_once12KSELFTEST_SKIP_TEST=413 14# Verify we have LKDTM available in the kernel.15if [ ! -r $TRIGGER ] ; then16	/sbin/modprobe -q lkdtm || true17	if [ ! -r $TRIGGER ] ; then18		echo "Cannot find $TRIGGER (missing CONFIG_LKDTM?)"19	else20		echo "Cannot write $TRIGGER (need to run as root?)"21	fi22	# Skip this test23	exit $KSELFTEST_SKIP_TEST24fi25 26# Figure out which test to run from our script name.27test=$(basename $0 .sh)28# Look up details about the test from master list of LKDTM tests.29line=$(grep -E '^#?'"$test"'\b' tests.txt)30if [ -z "$line" ]; then31	echo "Skipped: missing test '$test' in tests.txt"32	exit $KSELFTEST_SKIP_TEST33fi34# Check that the test is known to LKDTM.35if ! grep -E -q '^'"$test"'$' "$TRIGGER" ; then36	echo "Skipped: test '$test' missing in $TRIGGER!"37	exit $KSELFTEST_SKIP_TEST38fi39 40# Extract notes/expected output from test list.41test=$(echo "$line" | cut -d" " -f1)42if echo "$line" | grep -q ' ' ; then43	expect=$(echo "$line" | cut -d" " -f2-)44else45	expect=""46fi47 48# If the test is commented out, report a skip49if echo "$test" | grep -q '^#' ; then50	test=$(echo "$test" | cut -c2-)51	if [ -z "$expect" ]; then52		expect="crashes entire system"53	fi54	echo "Skipping $test: $expect"55	exit $KSELFTEST_SKIP_TEST56fi57 58# If no expected output given, assume an Oops with back trace is success.59repeat=160if [ -z "$expect" ]; then61	expect="call trace:"62else63	if echo "$expect" | grep -q '^repeat:' ; then64		repeat=$(echo "$expect" | cut -d' ' -f1 | cut -d: -f2)65		expect=$(echo "$expect" | cut -d' ' -f2-)66	fi67fi68 69# Prepare log for report checking70LOG=$(mktemp --tmpdir -t lkdtm-log-XXXXXX)71DMESG=$(mktemp --tmpdir -t lkdtm-dmesg-XXXXXX)72cleanup() {73	rm -f "$LOG" "$DMESG"74}75trap cleanup EXIT76 77# Reset WARN_ONCE counters so we trip it each time this runs.78if [ -w $CLEAR_ONCE ] ; then79	echo 1 > $CLEAR_ONCE80fi81 82# Save existing dmesg so we can detect new content below83dmesg > "$DMESG"84 85# Since the kernel is likely killing the process writing to the trigger86# file, it must not be the script's shell itself. i.e. we cannot do:87#     echo "$test" >"$TRIGGER"88# Instead, use "cat" to take the signal. Since the shell will yell about89# the signal that killed the subprocess, we must ignore the failure and90# continue. However we don't silence stderr since there might be other91# useful details reported there in the case of other unexpected conditions.92for i in $(seq 1 $repeat); do93	echo "$test" | cat >"$TRIGGER" || true94done95 96# Record and dump the results97dmesg | comm --nocheck-order -13 "$DMESG" - > "$LOG" || true98 99cat "$LOG"100# Check for expected output101if grep -E -qi "$expect" "$LOG" ; then102	echo "$test: saw '$expect': ok"103	exit 0104else105	if grep -E -qi XFAIL: "$LOG" ; then106		echo "$test: saw 'XFAIL': [SKIP]"107		exit $KSELFTEST_SKIP_TEST108	else109		echo "$test: missing '$expect': [FAIL]"110		exit 1111	fi112fi113