Skip to content

Commit

Permalink
selftests/lkdtm: Don't clear dmesg when running tests
Browse files Browse the repository at this point in the history
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: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Michael Ellerman authored and Shuah Khan committed May 8, 2020
1 parent adb5716 commit f131d9e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tools/testing/selftests/lkdtm/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f131d9e

Please sign in to comment.