Commit f131d9ed authored by Michael Ellerman's avatar Michael Ellerman Committed by Shuah Khan
Browse files

selftests/lkdtm: Don't clear dmesg when running tests



It is Very Rude to clear dmesg in test scripts. That's because the
script may be part of a larger test run, and clearing dmesg
potentially destroys the output of other tests.

We can avoid using dmesg -c by saving the content of dmesg before the
test, and then using diff to compare that to the dmesg afterward,
producing a log with just the added lines.

Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent adb57164
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -59,23 +59,25 @@ if [ -z "$expect" ]; then
	expect="call trace:"
fi

# Clear out dmesg for output reporting
dmesg -c >/dev/null

# Prepare log for report checking
LOG=$(mktemp --tmpdir -t lkdtm-XXXXXX)
LOG=$(mktemp --tmpdir -t lkdtm-log-XXXXXX)
DMESG=$(mktemp --tmpdir -t lkdtm-dmesg-XXXXXX)
cleanup() {
	rm -f "$LOG"
	rm -f "$LOG" "$DMESG"
}
trap cleanup EXIT

# Save existing dmesg so we can detect new content below
dmesg > "$DMESG"

# Most shells yell about signals and we're expecting the "cat" process
# to usually be killed by the kernel. So we have to run it in a sub-shell
# and silence errors.
($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true

# Record and dump the results
dmesg -c >"$LOG"
dmesg | diff --changed-group-format='%>' --unchanged-group-format='' "$DMESG" - > "$LOG" || true

cat "$LOG"
# Check for expected output
if egrep -qi "$expect" "$LOG" ; then