mirror of https://gitee.com/openkylin/linux.git
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 <mpe@ellerman.id.au> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
parent
adb571649c
commit
f131d9edc2
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue