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

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
...@@ -59,23 +59,25 @@ if [ -z "$expect" ]; then ...@@ -59,23 +59,25 @@ if [ -z "$expect" ]; then
expect="call trace:" expect="call trace:"
fi fi
# Clear out dmesg for output reporting
dmesg -c >/dev/null
# Prepare log for report checking # 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() { cleanup() {
rm -f "$LOG" rm -f "$LOG" "$DMESG"
} }
trap cleanup EXIT 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 # 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 # to usually be killed by the kernel. So we have to run it in a sub-shell
# and silence errors. # and silence errors.
($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true ($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true
# Record and dump the results # Record and dump the results
dmesg -c >"$LOG" dmesg | diff --changed-group-format='%>' --unchanged-group-format='' "$DMESG" - > "$LOG" || true
cat "$LOG" cat "$LOG"
# Check for expected output # Check for expected output
if egrep -qi "$expect" "$LOG" ; then if egrep -qi "$expect" "$LOG" ; then
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment