Lines Matching +full:on +full:- +full:die
2 # SPDX-License-Identifier: GPL-2.0
14 # Kselftest framework requirement - SKIP code is 4
17 # log(msg) - write message to kernel log
18 # msg - insightful words
23 # skip(msg) - testing can't proceed
24 # msg - explanation
33 uid=$(id -u)
34 if [ $uid -ne 0 ]; then
42 if [ -z "$KDIR" ]; then
43 KDIR="/lib/modules/$(uname -r)/build"
46 if [ ! -d "$KDIR" ]; then
52 # die(msg) - game over, man
53 # msg - dying words
54 function die() { function
62 awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
63 FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
68 if [[ -n "$DYNAMIC_DEBUG" ]]; then
69 echo -n "$DYNAMIC_DEBUG" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
71 if [[ -n "$FTRACE_ENABLED" ]]; then
74 if [[ -n "$KPROBE_ENABLED" ]]; then
80 cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
82 func klp_try_switch_task -p
88 if [[ "$1" == "--fail" ]] ; then
93 local err=$(sysctl -q kernel.ftrace_enabled="$1" 2>&1)
94 local result=$(sysctl --values kernel.ftrace_enabled)
97 if [[ $can_fail -eq 1 ]] ; then
112 # setup_config - save the current config and set a script exit trap that
114 # for verbose livepatching output and turn on
125 # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,
127 # cmd - command and its arguments to run
133 [[ $((i++)) -eq $MAX_RETRIES ]] && return 1
141 if [[ ! -f "test_modules/$mod.ko" ]]; then
142 die "Can't find \"test_modules/$mod.ko\", try \"make\""
159 die "$ret"
163 loop_until '[[ -e "/sys/module/$mod" ]]' ||
164 die "failed to load module $mod"
168 # load_mod(modname, params) - load a kernel module
169 # modname - module name to load
170 # params - module parameters to pass to insmod
175 die "use load_lp() to load the livepatch module $mod"
180 # load_lp_nowait(modname, params) - load a kernel module with a livepatch
181 # but do not wait on until the transition finishes
182 # modname - module name to load
183 # params - module parameters to pass to insmod
188 die "module $mod is not a livepatch"
193 loop_until '[[ -e "$SYSFS_KLP_DIR/$mod" ]]' ||
194 die "failed to load module $mod (sysfs)"
197 # load_lp(modname, params) - load a kernel module with a livepatch
198 # modname - module name to load
199 # params - module parameters to pass to insmod
206 loop_until 'grep -q '^0$' $SYSFS_KLP_DIR/$mod/transition' ||
207 die "failed to complete transition"
210 # load_failing_mod(modname, params) - load a kernel module, expect to fail
211 # modname - module name to load
212 # params - module parameters to pass to insmod
220 die "$mod unexpectedly loaded"
225 # unload_mod(modname) - unload a kernel module
226 # modname - module name to unload
232 die "failed to unload module $mod (refcnt)"
237 die "$ret"
241 loop_until '[[ ! -e "/sys/module/$mod" ]]' ||
242 die "failed to unload module $mod (/sys/module)"
245 # unload_lp(modname) - unload a kernel module with a livepatch
246 # modname - module name to unload
251 # disable_lp(modname) - disable a livepatch
252 # modname - module name to unload
261 loop_until '[[ ! -e "$SYSFS_KLP_DIR/$mod" ]]' ||
262 die "failed to disable livepatch $mod"
266 # modname - module name to set
267 # pre_patch_ret - new pre_patch_ret value
277 die "failed to set pre_patch_ret parameter for $mod module"
286 local last_dmesg_msg="livepatch kselftest timestamp: $(date --rfc-3339=ns)"
288 loop_until 'dmesg | grep -q "$last_dmesg_msg"' ||
289 die "buffer busy? can't find canary dmesg message: $last_dmesg_msg"
292 echo -n "TEST: $test ... "
296 # check_result() - verify dmesg output
297 # TODO - better filter, out of order msgs, etc?
303 # - include lines matching keywords
304 # - exclude lines matching keywords
305 # - filter out dmesg timestamp prefixes
306 result=$(dmesg | awk -v last_dmesg="$LAST_DMESG" 'p; $0 == last_dmesg { p=1 }' | \
307 grep -e 'livepatch:' -e 'test_klp' | \
308 grep -v '\(tainting\|taints\) kernel' | \
309 sed 's/^\[[ 0-9.]*\] //' | \
310 sed 's/^\[[ ]*[CT][0-9]*\] //')
315 echo -e "not ok\n\nbuffer overrun? can't find canary dmesg entry: $LAST_DMESG\n"
316 die "livepatch kselftest(s) failed"
318 …echo -e "not ok\n\n$(diff -upr --label expected --label result <(echo "$expect") <(echo "$result")…
319 die "livepatch kselftest(s) failed"
323 # check_sysfs_rights(modname, rel_path, expected_rights) - check sysfs
325 # modname - livepatch module creating the sysfs interface
326 # rel_path - relative path of the sysfs interface
327 # expected_rights - expected access rights
334 local rights=$(/bin/stat --format '%A' "$path")
336 die "Unexpected access rights of $path: $expected_rights vs. $rights"
340 # check_sysfs_value(modname, rel_path, expected_value) - check sysfs value
341 # modname - livepatch module creating the sysfs interface
342 # rel_path - relative path of the sysfs interface
343 # expected_value - expected value read from the file
352 die "Unexpected value in $path: $expected_value vs. $value"