Skip to content

Commit fbb01c5

Browse files
joe-lawrenceshuahkh
authored andcommitted
selftests/livepatch: push and pop dynamic debug config
The livepatching self-tests tweak the dynamic debug config to verify the kernel log during the tests. Enhance set_dynamic_debug() so that the config changes are restored when the script exits. Note this functionality needs to keep in sync with: - dynamic_debug input/output formatting - functions affected by set_dynamic_debug() For example, push_dynamic_debug() transforms: kernel/livepatch/transition.c:530 [livepatch]klp_init_transition =_ "'%s': initializing %s transition\012" to the following: file kernel/livepatch/transition.c line 530 =_ Signed-off-by: Joe Lawrence <[email protected]> Tested-by: Petr Mladek <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent fc2e634 commit fbb01c5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

tools/testing/selftests/livepatch/functions.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,27 @@ function die() {
2929
exit 1
3030
}
3131

32-
# set_dynamic_debug() - setup kernel dynamic debug
33-
# TODO - push and pop this config?
32+
function push_dynamic_debug() {
33+
DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
34+
awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
35+
}
36+
37+
function pop_dynamic_debug() {
38+
if [[ -n "$DYNAMIC_DEBUG" ]]; then
39+
echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
40+
fi
41+
}
42+
43+
# set_dynamic_debug() - save the current dynamic debug config and tweak
44+
# it for the self-tests. Set a script exit trap
45+
# that restores the original config.
3446
function set_dynamic_debug() {
35-
cat << EOF > /sys/kernel/debug/dynamic_debug/control
36-
file kernel/livepatch/* +p
37-
func klp_try_switch_task -p
38-
EOF
47+
push_dynamic_debug
48+
trap pop_dynamic_debug EXIT INT TERM HUP
49+
cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
50+
file kernel/livepatch/* +p
51+
func klp_try_switch_task -p
52+
EOF
3953
}
4054

4155
# loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,

0 commit comments

Comments
 (0)