selftests/livepatch: Make dynamic debug setup and restore generic
authorJoe Lawrence <joe.lawrence@redhat.com>
Wed, 16 Oct 2019 11:33:14 +0000 (13:33 +0200)
committerSteven Rostedt <rostedt@goodmis.org>
Mon, 4 Nov 2019 14:33:15 +0000 (09:33 -0500)
Livepatch selftests currently save the current dynamic debug config and
tweak it for the selftests. The config is restored at the end. Make the
infrastructure generic, so that more variables can be saved and
restored.

Link: http://lkml.kernel.org/r/20191016113316.13415-3-mbenes@suse.cz
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
tools/testing/selftests/livepatch/functions.sh
tools/testing/selftests/livepatch/test-callbacks.sh
tools/testing/selftests/livepatch/test-livepatch.sh
tools/testing/selftests/livepatch/test-shadow-vars.sh

index 79b0affd21fbddf6d6075a216b536592f6fc3305..b7e5a67ae434aa48a2fa6fdf1edf6594f1102a41 100644 (file)
@@ -29,29 +29,33 @@ function die() {
        exit 1
 }
 
-function push_dynamic_debug() {
-        DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
-                awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
+function push_config() {
+       DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
+                       awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
 }
 
-function pop_dynamic_debug() {
+function pop_config() {
        if [[ -n "$DYNAMIC_DEBUG" ]]; then
                echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
        fi
 }
 
-# set_dynamic_debug() - save the current dynamic debug config and tweak
-#                      it for the self-tests.  Set a script exit trap
-#                      that restores the original config.
 function set_dynamic_debug() {
-        push_dynamic_debug
-        trap pop_dynamic_debug EXIT INT TERM HUP
         cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
                file kernel/livepatch/* +p
                func klp_try_switch_task -p
                EOF
 }
 
+# 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.
+function setup_config() {
+       push_config
+       set_dynamic_debug
+       trap pop_config EXIT INT TERM HUP
+}
+
 # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,
 #                  sleep $RETRY_INTERVAL between attempts
 #      cmd - command and its arguments to run
index e97a9dcb73c7638c609f0ce33fbc7fbdfd14fb6d..a35289b13c9cb9c9017b2bdf50aa9ff147791952 100755 (executable)
@@ -9,7 +9,7 @@ MOD_LIVEPATCH2=test_klp_callbacks_demo2
 MOD_TARGET=test_klp_callbacks_mod
 MOD_TARGET_BUSY=test_klp_callbacks_busy
 
-set_dynamic_debug
+setup_config
 
 
 # TEST: target module before livepatch
index f05268aea85909272399925c0d27cf6466302394..493e3df415a1f94ffa7c1e2d2890cb576536988b 100755 (executable)
@@ -7,7 +7,7 @@
 MOD_LIVEPATCH=test_klp_livepatch
 MOD_REPLACE=test_klp_atomic_replace
 
-set_dynamic_debug
+setup_config
 
 
 # TEST: basic function patching
index 04a37831e2041d71ca1920d7b7d85fb80668fb65..1aae73299114f3badf371dfdd6677c5f63e5cdfd 100755 (executable)
@@ -6,7 +6,7 @@
 
 MOD_TEST=test_klp_shadow_vars
 
-set_dynamic_debug
+setup_config
 
 
 # TEST: basic shadow variable API