Skip to content

Commit f131d9e

Browse files
mpeshuahkh
authored andcommitted
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: Michael Ellerman <[email protected]> Acked-by: Kees Cook <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent adb5716 commit f131d9e

File tree

1 file changed

+8
-6
lines changed
  • tools/testing/selftests/lkdtm

1 file changed

+8
-6
lines changed

tools/testing/selftests/lkdtm/run.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,25 @@ if [ -z "$expect" ]; then
5959
expect="call trace:"
6060
fi
6161

62-
# Clear out dmesg for output reporting
63-
dmesg -c >/dev/null
64-
6562
# Prepare log for report checking
66-
LOG=$(mktemp --tmpdir -t lkdtm-XXXXXX)
63+
LOG=$(mktemp --tmpdir -t lkdtm-log-XXXXXX)
64+
DMESG=$(mktemp --tmpdir -t lkdtm-dmesg-XXXXXX)
6765
cleanup() {
68-
rm -f "$LOG"
66+
rm -f "$LOG" "$DMESG"
6967
}
7068
trap cleanup EXIT
7169

70+
# Save existing dmesg so we can detect new content below
71+
dmesg > "$DMESG"
72+
7273
# Most shells yell about signals and we're expecting the "cat" process
7374
# to usually be killed by the kernel. So we have to run it in a sub-shell
7475
# and silence errors.
7576
($SHELL -c 'cat <(echo '"$test"') >'"$TRIGGER" 2>/dev/null) || true
7677

7778
# Record and dump the results
78-
dmesg -c >"$LOG"
79+
dmesg | diff --changed-group-format='%>' --unchanged-group-format='' "$DMESG" - > "$LOG" || true
80+
7981
cat "$LOG"
8082
# Check for expected output
8183
if egrep -qi "$expect" "$LOG" ; then

0 commit comments

Comments
 (0)