[PATCH v4 4/4] selftests/livepatch: run the tests with prebuilt test modules

From
Sasha Levin <sashal@kernel.org>
Date
2026-11-10 16:10:59
Also in
linux-kselftest, lkml
Reply to
Sasha Levin, 2026-11-10
The tests are skipped unless the machine running them has a kernel
build directory, in $KDIR or /lib/modules/$(uname -r)/build. They do
not need one when the test modules were built with the selftests,
because the scripts load the modules from test_modules/.

As a result the tests are skipped on a machine running an installed
selftests tree without the kernel devel files, for example one
installed with

  make O=/tmp/kselftest TARGETS=livepatch kselftest-install

although the modules are there.

Run the tests when the test modules are available, so that they can
run without the kernel devel files. Without the modules, keep skipping
the tests when there is no kernel build directory to build them with.

Fixes: 54ee3526796f ("selftests: livepatch: Avoid running the tests if kernel-devel is missing")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 tools/testing/selftests/livepatch/functions.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index 8b26b70f92d8c..eebd36b0e0eaf 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -44,14 +44,18 @@ function is_root() {
 	fi
 }
 
-# Check if we can compile the modules before loading them
-function has_kdir() {
+# Check that the test modules were built, or that we can compile them
+function has_test_modules() {
+	if compgen -G "test_modules/*.ko" > /dev/null; then
+		return
+	fi
+
 	if [ -z "$KDIR" ]; then
 		KDIR="/lib/modules/$(uname -r)/build"
 	fi
 
 	if [ ! -d "$KDIR" ]; then
-		echo "skip all tests: KDIR ($KDIR) not available to compile modules."
+		echo "skip all tests: test modules are not available and KDIR ($KDIR) is not available to compile them."
 		exit $ksft_skip
 	fi
 }
@@ -151,7 +155,7 @@ function cleanup() {
 function setup_config() {
 	is_root
 	[[ -d "$SYSFS_KLP_DIR" ]] || skip "livepatch is not available"
-	has_kdir
+	has_test_modules
 	push_config
 	set_dynamic_debug
 	set_ftrace_enabled 1
-- 
2.53.0
Thread (7 messages) 7 messages, 2 authors, last reply 5d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help