[PATCH v2 2/2] selftests/livepatch: skip based on the test modules instead of KDIR

From
Sasha Levin <sashal@kernel.org>
Date
2026-11-03 14:02:24
Also in
linux-kselftest, lkml
Reply to
Sasha Levin, 2026-11-03
setup_config() skips every test when there is no kernel build directory
at $KDIR or /lib/modules/$(uname -r)/build. The test modules are built
together with the selftests and the scripts load them from
test_modules/, so nothing needs a build directory at run time. A
machine running an installed kselftest tree usually has none, and the
tests are skipped there although the modules were built and installed.

Check for the modules that __load_mod() loads instead, and remove
has_kdir(), which has no other users.

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 | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh
index 8b26b70f92d8c..14fc9cade4de3 100644
--- a/tools/testing/selftests/livepatch/functions.sh
+++ b/tools/testing/selftests/livepatch/functions.sh
@@ -44,16 +44,10 @@ function is_root() {
 	fi
 }
 
-# Check if we can compile the modules before loading them
-function has_kdir() {
-	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."
-		exit $ksft_skip
-	fi
+# Check that the test modules were built before loading them
+function has_test_modules() {
+	compgen -G "test_modules/*.ko" > /dev/null ||
+		skip "test modules are not available"
 }
 
 # die(msg) - game over, man
@@ -151,7 +145,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 (4 messages) 4 messages, 2 authors, last reply 13d 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