Skip to content

Commit 54ee352

Browse files
marcospsshuahkh
authored andcommitted
selftests: livepatch: Avoid running the tests if kernel-devel is missing
By checking if KDIR is a valid directory we can safely skip the tests if kernel-devel isn't installed (default value of KDIR), or if KDIR variable passed doesn't exists. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202402191417.XULH88Ct-lkp@intel.com/ Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 8ab37b0 commit 54ee352

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tools/testing/selftests/livepatch/functions.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ function is_root() {
3434
fi
3535
}
3636

37+
# Check if we can compile the modules before loading them
38+
function has_kdir() {
39+
if [ -z "$KDIR" ]; then
40+
KDIR="/lib/modules/$(uname -r)/build"
41+
fi
42+
43+
if [ ! -d "$KDIR" ]; then
44+
echo "skip all tests: KDIR ($KDIR) not available to compile modules."
45+
exit $ksft_skip
46+
fi
47+
}
48+
3749
# die(msg) - game over, man
3850
# msg - dying words
3951
function die() {
@@ -108,6 +120,7 @@ function cleanup() {
108120
# the ftrace_enabled sysctl.
109121
function setup_config() {
110122
is_root
123+
has_kdir
111124
push_config
112125
set_dynamic_debug
113126
set_ftrace_enabled 1

tools/testing/selftests/livepatch/test_modules/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ obj-m += test_klp_atomic_replace.o \
1313
test_klp_shadow_vars.o \
1414
test_klp_syscall.o
1515

16+
# Ensure that KDIR exists, otherwise skip the compilation
1617
modules:
18+
ifneq ("$(wildcard $(KDIR))", "")
1719
$(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR)
20+
endif
1821

22+
# Ensure that KDIR exists, otherwise skip the clean target
1923
clean:
24+
ifneq ("$(wildcard $(KDIR))", "")
2025
$(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR)
26+
endif

0 commit comments

Comments
 (0)