linux/tools/testing/selftests/livepatch
Linus Torvalds dcf9f31c62 Livepatching changes for 6.15
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEESH4wyp42V4tXvYsjUqAMR0iAlPIFAmflMGMACgkQUqAMR0iA
 lPKHhg/8DjxkQ3tvUpW53pfABBdKELJWOl4hH+IMvGcdh2dZrcFf6OkEB4JeXXVn
 duSODaefalrdU0jV21LChYpEkG40wZqStmamH9im+VbyCc8JwMwvWckrw45RNmjO
 AC4oVh0K9SJcrTj7XWsFSeS38KmQKhtp2zTHpSqCW9FZkfn8si11E8Xzue2kTtEH
 7CESq6N0SMahVfiNkLI1n0x0mUyWiTE43hQ3e+tmmBgtmv3gU4FpQqeTGc/MQUxy
 B6AaI1vChovLmfNhw4KM8GvyPCTIn4xRQ09WXZRbK2ZzAxgFfm7QXGL3E93ra929
 juSoIWnNwzw81RB3apzclOHFTbctHJWL+85KEefqCjrCuEbaoLNGoLkVqNuj0U+D
 LmLqmm6NfEtPzDVBY232KepjFUoIb890eKRF3Wq1NnHonaVxmUSMEMRSdlKeHpSo
 uImBhr5XhXDJLHt4+lAa4m0JSm3RH2AK83xIrdJq/YUcKscCzJMHLqqsp8pCa7mb
 L7iOhHFKs2r6GJCt5kLEw1jkNEg5Lpk08fY5AekjScvNcxXWXF8E8Jl9DnBBoz+5
 e15mvqsiQtcAGHyR1Ohmw8UPYnWY2fSZTmru9aClwHCvC0q+cyCxIZgcqLxFYFIr
 TKIgQ6zSepA+j7SzI1SaDY4Z9cNWMTU+9GqrNO3xO4ddpKrp5C8=
 =ggzJ
 -----END PGP SIGNATURE-----

Merge tag 'livepatching-for-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching

Pull livepatching updates from Petr Mladek:

 - Add a selftest for tracing of a livepatched function

 - Skip a selftest when kprobes are not using ftrace

 - Some documentation clean up

* tag 'livepatching-for-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching:
  selftests: livepatch: test if ftrace can trace a livepatched function
  selftests: livepatch: add new ftrace helpers functions
  selftest/livepatch: Only run test-kprobe with CONFIG_KPROBES_ON_FTRACE
  docs: livepatch: move text out of code block
  livepatch: Add comment to clarify klp_add_nops()
2025-03-27 19:26:10 -07:00
..
test_modules selftests: livepatch: test livepatching a kprobed function 2024-10-22 17:13:11 +02:00
.gitignore selftests: livepatch: Add initial .gitignore 2024-02-27 17:03:28 -07:00
config livepatch: Move tests from lib/livepatch to selftests/livepatch 2024-01-22 10:29:47 -07:00
functions.sh Livepatching changes for 6.15 2025-03-27 19:26:10 -07:00
Makefile selftests: livepatch: test livepatching a kprobed function 2024-10-22 17:13:11 +02:00
README livepatch: Move tests from lib/livepatch to selftests/livepatch 2024-01-22 10:29:47 -07:00
settings
test-callbacks.sh selftests/livepatch: Replace hardcoded module name with variable in test-callbacks.sh 2024-12-09 11:12:43 +01:00
test-ftrace.sh selftests: livepatch: test if ftrace can trace a livepatched function 2025-03-25 14:52:32 +01:00
test-kprobe.sh selftest/livepatch: Only run test-kprobe with CONFIG_KPROBES_ON_FTRACE 2025-03-25 13:36:40 +01:00
test-livepatch.sh selftests: livepatch: rename KLP_SYSFS_DIR to SYSFS_KLP_DIR 2024-10-22 17:12:46 +02:00
test-shadow-vars.sh livepatch: Move tests from lib/livepatch to selftests/livepatch 2024-01-22 10:29:47 -07:00
test-state.sh selftests: livepatch: rename KLP_SYSFS_DIR to SYSFS_KLP_DIR 2024-10-22 17:12:46 +02:00
test-syscall.sh selftests: livepatch: save and restore kprobe state 2024-10-22 17:13:11 +02:00
test-sysfs.sh selftests: livepatch: add test cases of stack_order sysfs interface 2024-12-09 11:47:21 +01:00
test_klp-call_getpid.c selftests: livepatch: Test livepatching a heavily called syscall 2024-01-22 10:29:53 -07:00

====================
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 CONFIG_LIVEPATCH=y option and it's prerequisites.


Building the tests
------------------

To only build the tests without running them, run:

  % make -C tools/testing/selftests/livepatch

The command above will compile all test modules and test programs, making them
ready to be packaged if so desired.

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

Test kernel modules are built before running the livepatch selftests.  The
modules are located under test_modules directory, and are built as out-of-tree
modules.  This is specially useful since the same sources can be built and
tested on systems with different kABI, ensuring they the tests are backwards
compatible.  The modules will be loaded by the test scripts using insmod.

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

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

or

  % make kselftest TARGETS=livepatch


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.)