diff options
author | Joe Lawrence <joe.lawrence@redhat.com> | 2020-06-18 14:10:38 -0400 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2020-06-19 10:46:42 +0200 |
commit | 2eeb0d457d13ed7b170e13cd99d15509d0dd832d (patch) | |
tree | 2b210a9706d67d8053ebf7c4d9a93449b0c2bbfe /tools/testing/selftests/livepatch/functions.sh | |
parent | 270f7806d3b91b9c71fa8fe66f7dcc2d6587694e (diff) | |
download | linux-2eeb0d457d13ed7b170e13cd99d15509d0dd832d.tar.gz linux-2eeb0d457d13ed7b170e13cd99d15509d0dd832d.tar.bz2 linux-2eeb0d457d13ed7b170e13cd99d15509d0dd832d.zip |
selftests/livepatch: Don't clear dmesg when running tests
Inspired by commit f131d9edc29d ("selftests/lkdtm: Don't clear dmesg
when running tests"), keep a reference dmesg copy when beginning each
test. This way check_result() can compare against the initial copy
rather than relying upon an empty log.
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Reviewed-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Reviewed-by: Yannick Cote <ycote@redhat.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20200618181040.21132-2-joe.lawrence@redhat.com
Diffstat (limited to 'tools/testing/selftests/livepatch/functions.sh')
-rw-r--r-- | tools/testing/selftests/livepatch/functions.sh | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh index 2aab9791791d..bf73ec4f4a71 100644 --- a/tools/testing/selftests/livepatch/functions.sh +++ b/tools/testing/selftests/livepatch/functions.sh @@ -41,6 +41,17 @@ function die() { exit 1 } +# save existing dmesg so we can detect new content +function save_dmesg() { + SAVED_DMESG=$(mktemp --tmpdir -t klp-dmesg-XXXXXX) + dmesg > "$SAVED_DMESG" +} + +# cleanup temporary dmesg file from save_dmesg() +function cleanup_dmesg_file() { + rm -f "$SAVED_DMESG" +} + function push_config() { DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \ awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}') @@ -68,6 +79,11 @@ function set_ftrace_enabled() { echo "livepatch: $result" > /dev/kmsg } +function cleanup() { + pop_config + cleanup_dmesg_file +} + # setup_config - save the current config and set a script exit trap that # restores the original config. Setup the dynamic debug # for verbose livepatching output and turn on @@ -77,7 +93,7 @@ function setup_config() { push_config set_dynamic_debug set_ftrace_enabled 1 - trap pop_config EXIT INT TERM HUP + trap cleanup EXIT INT TERM HUP } # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES, @@ -243,13 +259,26 @@ function set_pre_patch_ret { die "failed to set pre_patch_ret parameter for $mod module" } +function start_test { + local test="$1" + + save_dmesg + echo -n "TEST: $test ... " +} + # check_result() - verify dmesg output # TODO - better filter, out of order msgs, etc? function check_result { local expect="$*" local result - result=$(dmesg | grep -v 'tainting' | grep -e 'livepatch:' -e 'test_klp' | sed 's/^\[[ 0-9.]*\] //') + # Note: when comparing dmesg output, the kernel log timestamps + # help differentiate repeated testing runs. Remove them with a + # post-comparison sed filter. + + result=$(dmesg | diff --changed-group-format='%>' --unchanged-group-format='' "$SAVED_DMESG" - | \ + grep -v 'tainting' | grep -e 'livepatch:' -e 'test_klp' | \ + sed 's/^\[[ 0-9.]*\] //') if [[ "$expect" == "$result" ]] ; then echo "ok" @@ -257,4 +286,6 @@ function check_result { echo -e "not ok\n\n$(diff -upr --label expected --label result <(echo "$expect") <(echo "$result"))\n" die "livepatch kselftest(s) failed" fi + + cleanup_dmesg_file } |