linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] selftests/lkdtm: Don't clear dmesg when running tests
@ 2020-05-08  6:53 Michael Ellerman
  2020-05-08  6:53 ` [PATCH 2/2] selftests/lkdtm: Use grep -E instead of egrep Michael Ellerman
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Michael Ellerman @ 2020-05-08  6:53 UTC (permalink / raw)
  To: keescook, linux-kselftest; +Cc: linux-kernel

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>
---
 tools/testing/selftests/lkdtm/run.sh | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/lkdtm/run.sh b/tools/testing/selftests/lkdtm/run.sh
index dadf819148a4..0b409e187c7b 100755
--- a/tools/testing/selftests/lkdtm/run.sh
+++ b/tools/testing/selftests/lkdtm/run.sh
@@ -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

base-commit: 192ffb7515839b1cc8457e0a8c1e09783de019d3
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-06-26 15:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08  6:53 [PATCH 1/2] selftests/lkdtm: Don't clear dmesg when running tests Michael Ellerman
2020-05-08  6:53 ` [PATCH 2/2] selftests/lkdtm: Use grep -E instead of egrep Michael Ellerman
2020-05-08  7:30   ` Kees Cook
2020-05-08  7:30 ` [PATCH 1/2] selftests/lkdtm: Don't clear dmesg when running tests Kees Cook
2020-06-22  8:51 ` Naresh Kamboju
2020-06-24  3:48   ` Joe Lawrence
2020-06-24  8:39     ` Petr Mladek
2020-06-24 20:12       ` Joe Lawrence
2020-06-26  8:02         ` Petr Mladek
2020-06-26 13:38           ` Joe Lawrence
2020-06-26 15:51             ` Naresh Kamboju
2020-06-25  6:16   ` Kees Cook
2020-06-26 15:50     ` Naresh Kamboju

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).