Centos-kernel-stream-9/tools/testing/selftests/livepatch
Denis Aleksandrov 15dc6ddd4a selftests: livepatch: handle PRINTK_CALLER in check_result()
JIRA: https://issues.redhat.com/browse/RHEL-85303

Some arch configs (like ppc64) enable CONFIG_PRINTK_CALLER,
which adds the caller id as part of the dmesg. With recent
util-linux's update 467a5b3192f16 ('dmesg: add caller_id support')
the standard "dmesg" has been enhanced to print PRINTK_CALLER fields.

Due to this, even though the expected vs observed are same,
end testcase results are failed.

 -% insmod test_modules/test_klp_livepatch.ko
 -livepatch: enabling patch 'test_klp_livepatch'
 -livepatch: 'test_klp_livepatch': initializing patching transition
 -livepatch: 'test_klp_livepatch': starting patching transition
 -livepatch: 'test_klp_livepatch': completing patching transition
 -livepatch: 'test_klp_livepatch': patching complete
 -% echo 0 > /sys/kernel/livepatch/test_klp_livepatch/enabled
 -livepatch: 'test_klp_livepatch': initializing unpatching transition
 -livepatch: 'test_klp_livepatch': starting unpatching transition
 -livepatch: 'test_klp_livepatch': completing unpatching transition
 -livepatch: 'test_klp_livepatch': unpatching complete
 -% rmmod test_klp_livepatch
 +[   T3659] % insmod test_modules/test_klp_livepatch.ko
 +[   T3682] livepatch: enabling patch 'test_klp_livepatch'
 +[   T3682] livepatch: 'test_klp_livepatch': initializing patching transition
 +[   T3682] livepatch: 'test_klp_livepatch': starting patching transition
 +[    T826] livepatch: 'test_klp_livepatch': completing patching transition
 +[    T826] livepatch: 'test_klp_livepatch': patching complete
 +[   T3659] % echo 0 > /sys/kernel/livepatch/test_klp_livepatch/enabled
 +[   T3659] livepatch: 'test_klp_livepatch': initializing unpatching transition
 +[   T3659] livepatch: 'test_klp_livepatch': starting unpatching transition
 +[    T789] livepatch: 'test_klp_livepatch': completing unpatching transition
 +[    T789] livepatch: 'test_klp_livepatch': unpatching complete
 +[   T3659] % rmmod test_klp_livepatch

  ERROR: livepatch kselftest(s) failed
 not ok 1 selftests: livepatch: test-livepatch.sh # exit=1

Currently the check_result() handles the "[time]" removal from
the dmesg. Enhance the check to also handle removal of "[Thread Id]"
or "[CPU Id]".

Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20250119163238.749847-1-maddy@linux.ibm.com
Signed-off-by: Petr Mladek <pmladek@suse.com>
(cherry picked from commit 28aecef5b1015bf6023ddc12b1a67f6678271fcb)
Signed-off-by: Denis Aleksandrov <daleksan@redhat.com>
2025-04-03 13:25:50 -04:00
..
.gitignore selftests: livepatch: Add initial .gitignore 2024-10-15 09:54:10 -04:00
Makefile selftests: livepatch: test livepatching a kprobed function 2025-03-06 13:32:22 -05:00
README selftests/livepatch: Don't clear dmesg when running tests 2020-06-19 10:46:42 +02:00
config selftests: livepatch: add missing fragments to config 2019-09-23 08:33:16 -06:00
functions.sh selftests: livepatch: handle PRINTK_CALLER in check_result() 2025-04-03 13:25:50 -04:00
settings selftests/livepatch: Disable the timeout 2019-10-25 19:59:12 +02:00
test-callbacks.sh selftests/livepatch: Replace hardcoded module name with variable in test-callbacks.sh 2025-04-03 13:22:58 -04:00
test-ftrace.sh selftests: livepatch: rename KLP_SYSFS_DIR to SYSFS_KLP_DIR 2025-03-04 14:02:40 -05:00
test-kprobe.sh selftests: livepatch: test livepatching a kprobed function 2025-03-06 13:32:22 -05:00
test-livepatch.sh selftests: livepatch: rename KLP_SYSFS_DIR to SYSFS_KLP_DIR 2025-03-04 14:02:40 -05:00
test-shadow-vars.sh selftests/livepatch: Don't clear dmesg when running tests 2020-06-19 10:46:42 +02:00
test-state.sh selftests: livepatch: rename KLP_SYSFS_DIR to SYSFS_KLP_DIR 2025-03-04 14:02:40 -05:00
test-syscall.sh selftests: livepatch: save and restore kprobe state 2025-03-04 14:08:21 -05:00
test-sysfs.sh selftests: livepatch: add test cases of stack_order sysfs interface 2025-04-03 13:23:38 -04:00
test_klp-call_getpid.c selftests: livepatch: Test livepatching a heavily called syscall 2024-10-15 09:54:10 -04:00

README

====================
Livepatch Self Tests
====================

This is a small set of sanity tests for the kernel livepatching.

The test suite loads and unloads several test kernel modules to verify
livepatch behavior.  Debug information is logged to the kernel's message
buffer and parsed for expected messages.  (Note: the tests will compare
the message buffer for only the duration of each individual test.)


Config
------

Set these config options and their prerequisites:

CONFIG_LIVEPATCH=y
CONFIG_TEST_LIVEPATCH=m


Running the tests
-----------------

Test kernel modules are built as part of lib/ (make modules) and need to
be installed (make modules_install) as the test scripts will modprobe
them.

To run the livepatch selftests, from the top of the kernel source tree:

  % make -C tools/testing/selftests TARGETS=livepatch run_tests


Adding tests
------------

See the common functions.sh file for the existing collection of utility
functions, most importantly setup_config(), start_test() and
check_result().  The latter function greps the kernel's ring buffer for
"livepatch:" and "test_klp" strings, so tests be sure to include one of
those strings for result comparison.  Other utility functions include
general module loading and livepatch loading helpers (waiting for patch
transitions, sysfs entries, etc.)