On 6/12/20 5:49 AM, Petr Mladek wrote:
On Wed 2020-06-10 13:20:59, Joe Lawrence wrote:
[ ... snip ... ] +function start_test {
- local test="$1"
- # Save existing dmesg so we can detect new content below
- SAVED_DMESG=$(mktemp --tmpdir -t klp-dmesg-XXXXXX)
There is a nice trick how to remove the temporary files even when the script fails from other reasons. The following should do the job:
function cleanup { rm -f "$SAVED_DMESG" }
trap cleanup EXIT
Right, we currently trap EXIT INT TERM HUP to pop the dynamic debug and kernel.ftrace_enabled sysctl settings. I can add a cleanup() function to take care of both the settings and the tmp file.
- dmesg > "$SAVED_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.]*] //')
- 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 +269,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
- rm -f "$SAVED_DMESG"
This change will not be necessary with the above trap handler.
Well start_test() and check_result() are called multiple times per script. That means that with the original v1 change, we're creating new $SAVED_DMESG files per start_test() since check_result() is comparing only the new entries from test to test.
So I think this particular hunk in the modification would be necessary even with the trap handler. The trap handler would still be nice to have in case the script is interrupted though.
Otherwise, I really like the change. I was always a bit worried that these tests were clearing all other messages.
Yup, we ran into an instance internally where another test was failing because were blowing away the logs :(
-- Joe