Lines Matching +full:on +full:- +full:die

2 # SPDX-License-Identifier: GPL-2.0
11 # Kselftest framework requirement - SKIP code is 4
14 # log(msg) - write message to kernel log
15 # msg - insightful words
20 # skip(msg) - testing can't proceed
21 # msg - explanation
30 uid=$(id -u)
31 if [ $uid -ne 0 ]; then
39 if [ -z "$KDIR" ]; then
40 KDIR="/lib/modules/$(uname -r)/build"
43 if [ ! -d "$KDIR" ]; then
49 # die(msg) - game over, man
50 # msg - dying words
51 function die() { function
59 awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
60 FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
64 if [[ -n "$DYNAMIC_DEBUG" ]]; then
65 echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
67 if [[ -n "$FTRACE_ENABLED" ]]; then
73 cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
75 func klp_try_switch_task -p
81 if [[ "$1" == "--fail" ]] ; then
86 local err=$(sysctl -q kernel.ftrace_enabled="$1" 2>&1)
87 local result=$(sysctl --values kernel.ftrace_enabled)
90 if [[ $can_fail -eq 1 ]] ; then
105 # setup_config - save the current config and set a script exit trap that
107 # for verbose livepatching output and turn on
118 # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,
120 # cmd - command and its arguments to run
126 [[ $((i++)) -eq $MAX_RETRIES ]] && return 1
134 if [[ ! -f "test_modules/$mod.ko" ]]; then
135 die "Can't find \"test_modules/$mod.ko\", try \"make\""
152 die "$ret"
156 loop_until '[[ -e "/sys/module/$mod" ]]' ||
157 die "failed to load module $mod"
161 # load_mod(modname, params) - load a kernel module
162 # modname - module name to load
163 # params - module parameters to pass to insmod
168 die "use load_lp() to load the livepatch module $mod"
173 # load_lp_nowait(modname, params) - load a kernel module with a livepatch
174 # but do not wait on until the transition finishes
175 # modname - module name to load
176 # params - module parameters to pass to insmod
181 die "module $mod is not a livepatch"
186 loop_until '[[ -e "/sys/kernel/livepatch/$mod" ]]' ||
187 die "failed to load module $mod (sysfs)"
190 # load_lp(modname, params) - load a kernel module with a livepatch
191 # modname - module name to load
192 # params - module parameters to pass to insmod
199 loop_until 'grep -q '^0$' /sys/kernel/livepatch/$mod/transition' ||
200 die "failed to complete transition"
203 # load_failing_mod(modname, params) - load a kernel module, expect to fail
204 # modname - module name to load
205 # params - module parameters to pass to insmod
213 die "$mod unexpectedly loaded"
218 # unload_mod(modname) - unload a kernel module
219 # modname - module name to unload
225 die "failed to unload module $mod (refcnt)"
230 die "$ret"
234 loop_until '[[ ! -e "/sys/module/$mod" ]]' ||
235 die "failed to unload module $mod (/sys/module)"
238 # unload_lp(modname) - unload a kernel module with a livepatch
239 # modname - module name to unload
244 # disable_lp(modname) - disable a livepatch
245 # modname - module name to unload
254 loop_until '[[ ! -e "/sys/kernel/livepatch/$mod" ]]' ||
255 die "failed to disable livepatch $mod"
259 # modname - module name to set
260 # pre_patch_ret - new pre_patch_ret value
270 die "failed to set pre_patch_ret parameter for $mod module"
279 local last_dmesg_msg="livepatch kselftest timestamp: $(date --rfc-3339=ns)"
281 loop_until 'dmesg | grep -q "$last_dmesg_msg"' ||
282 die "buffer busy? can't find canary dmesg message: $last_dmesg_msg"
285 echo -n "TEST: $test ... "
289 # check_result() - verify dmesg output
290 # TODO - better filter, out of order msgs, etc?
296 # - include lines matching keywords
297 # - exclude lines matching keywords
298 # - filter out dmesg timestamp prefixes
299 result=$(dmesg | awk -v last_dmesg="$LAST_DMESG" 'p; $0 == last_dmesg { p=1 }' | \
300 grep -e 'livepatch:' -e 'test_klp' | \
301 grep -v '\(tainting\|taints\) kernel' | \
302 sed 's/^\[[ 0-9.]*\] //')
307 echo -e "not ok\n\nbuffer overrun? can't find canary dmesg entry: $LAST_DMESG\n"
308 die "livepatch kselftest(s) failed"
310 …echo -e "not ok\n\n$(diff -upr --label expected --label result <(echo "$expect") <(echo "$result")…
311 die "livepatch kselftest(s) failed"
315 # check_sysfs_rights(modname, rel_path, expected_rights) - check sysfs
317 # modname - livepatch module creating the sysfs interface
318 # rel_path - relative path of the sysfs interface
319 # expected_rights - expected access rights
326 local rights=$(/bin/stat --format '%A' "$path")
328 die "Unexpected access rights of $path: $expected_rights vs. $rights"
332 # check_sysfs_value(modname, rel_path, expected_value) - check sysfs value
333 # modname - livepatch module creating the sysfs interface
334 # rel_path - relative path of the sysfs interface
335 # expected_value - expected value read from the file
344 die "Unexpected value in $path: $expected_value vs. $value"