Lines Matching +full:on +full:- +full:die
2 # SPDX-License-Identifier: GPL-2.0
15 # Kselftest framework requirement - SKIP code is 4
18 # log(msg) - write message to kernel log
19 # msg - insightful words
24 # skip(msg) - testing can't proceed
25 # msg - explanation
34 uid=$(id -u)
35 if [ $uid -ne 0 ]; then
43 if [ -z "$KDIR" ]; then
44 KDIR="/lib/modules/$(uname -r)/build"
47 if [ ! -d "$KDIR" ]; then
53 # die(msg) - game over, man
54 # msg - dying words
55 function die() { function
63 awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
64 FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
72 if [[ -n "$DYNAMIC_DEBUG" ]]; then
73 echo -n "$DYNAMIC_DEBUG" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
75 if [[ -n "$FTRACE_ENABLED" ]]; then
78 if [[ -n "$KPROBE_ENABLED" ]]; then
81 if [[ -n "$TRACING_ON" ]]; then
84 if [[ -n "$CURRENT_TRACER" ]]; then
87 if [[ -n "$FTRACE_FILTER" ]]; then
89 | sed -e "/#### all functions enabled ####/d" \
95 cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
97 func klp_try_switch_task -p
103 if [[ "$1" == "--fail" ]] ; then
108 local err=$(sysctl -q kernel.ftrace_enabled="$1" 2>&1)
109 local result=$(sysctl --values kernel.ftrace_enabled)
112 if [[ $can_fail -eq 1 ]] ; then
127 # setup_config - save the current config and set a script exit trap that
129 # for verbose livepatching output and turn on
140 # loop_until(cmd) - loop a command until it is successful or $MAX_RETRIES,
142 # cmd - command and its arguments to run
148 [[ $((i++)) -eq $MAX_RETRIES ]] && return 1
156 if [[ ! -f "test_modules/$mod.ko" ]]; then
157 die "Can't find \"test_modules/$mod.ko\", try \"make\""
174 die "$ret"
178 loop_until '[[ -e "/sys/module/$mod" ]]' ||
179 die "failed to load module $mod"
183 # load_mod(modname, params) - load a kernel module
184 # modname - module name to load
185 # params - module parameters to pass to insmod
190 die "use load_lp() to load the livepatch module $mod"
195 # load_lp_nowait(modname, params) - load a kernel module with a livepatch
196 # but do not wait on until the transition finishes
197 # modname - module name to load
198 # params - module parameters to pass to insmod
203 die "module $mod is not a livepatch"
208 loop_until '[[ -e "$SYSFS_KLP_DIR/$mod" ]]' ||
209 die "failed to load module $mod (sysfs)"
212 # load_lp(modname, params) - load a kernel module with a livepatch
213 # modname - module name to load
214 # params - module parameters to pass to insmod
221 loop_until 'grep -q '^0$' $SYSFS_KLP_DIR/$mod/transition' ||
222 die "failed to complete transition"
225 # load_failing_mod(modname, params) - load a kernel module, expect to fail
226 # modname - module name to load
227 # params - module parameters to pass to insmod
235 die "$mod unexpectedly loaded"
240 # unload_mod(modname) - unload a kernel module
241 # modname - module name to unload
247 die "failed to unload module $mod (refcnt)"
252 die "$ret"
256 loop_until '[[ ! -e "/sys/module/$mod" ]]' ||
257 die "failed to unload module $mod (/sys/module)"
260 # unload_lp(modname) - unload a kernel module with a livepatch
261 # modname - module name to unload
266 # disable_lp(modname) - disable a livepatch
267 # modname - module name to unload
276 loop_until '[[ ! -e "$SYSFS_KLP_DIR/$mod" ]]' ||
277 die "failed to disable livepatch $mod"
281 # modname - module name to set
282 # pre_patch_ret - new pre_patch_ret value
292 die "failed to set pre_patch_ret parameter for $mod module"
301 local last_dmesg_msg="livepatch kselftest timestamp: $(date --rfc-3339=ns)"
303 loop_until 'dmesg | grep -q "$last_dmesg_msg"' ||
304 die "buffer busy? can't find canary dmesg message: $last_dmesg_msg"
307 echo -n "TEST: $test ... "
311 # check_result() - verify dmesg output
312 # TODO - better filter, out of order msgs, etc?
318 # - include lines matching keywords
319 # - exclude lines matching keywords
320 # - filter out dmesg timestamp prefixes
321 result=$(dmesg | awk -v last_dmesg="$LAST_DMESG" 'p; $0 == last_dmesg { p=1 }' | \
322 grep -e 'livepatch:' -e 'test_klp' | \
323 grep -v '\(tainting\|taints\) kernel' | \
324 sed 's/^\[[ 0-9.]*\] //' | \
325 sed 's/^\[[ ]*[CT][0-9]*\] //')
330 echo -e "not ok\n\nbuffer overrun? can't find canary dmesg entry: $LAST_DMESG\n"
331 die "livepatch kselftest(s) failed"
333 …echo -e "not ok\n\n$(diff -upr --label expected --label result <(echo "$expect") <(echo "$result")…
334 die "livepatch kselftest(s) failed"
338 # check_sysfs_rights(modname, rel_path, expected_rights) - check sysfs
340 # modname - livepatch module creating the sysfs interface
341 # rel_path - relative path of the sysfs interface
342 # expected_rights - expected access rights
349 local rights=$(/bin/stat --format '%A' "$path")
351 die "Unexpected access rights of $path: $expected_rights vs. $rights"
355 # check_sysfs_value(modname, rel_path, expected_value) - check sysfs value
356 # modname - livepatch module creating the sysfs interface
357 # rel_path - relative path of the sysfs interface
358 # expected_value - expected value read from the file
367 die "Unexpected value in $path: $expected_value vs. $value"
371 # cleanup_tracing() - stop and clean up function tracing
379 # trace_function(function) - start tracing of a function
380 # function - to be traced function
391 # check_traced_functions(functions...) - check whether each function appeared in the trace log
392 # functions - list of functions to be checked
397 if ! grep -Fwq "$function" "$SYSFS_TRACING_DIR/trace" ; then
398 die "Function ($function) did not appear in the trace"