mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
selftests/livepatch: Don't clear dmesg when running tests
Inspired by commit f131d9edc2
("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
This commit is contained in:
parent
270f7806d3
commit
2eeb0d457d
7 changed files with 66 additions and 81 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue