Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Marcos Paulo de Souza and committed by
Shuah Khan
54ee3526 8ab37b0d

+19
+13
tools/testing/selftests/livepatch/functions.sh
··· 34 34 fi 35 35 } 36 36 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 + 37 49 # die(msg) - game over, man 38 50 # msg - dying words 39 51 function die() { ··· 120 108 # the ftrace_enabled sysctl. 121 109 function setup_config() { 122 110 is_root 111 + has_kdir 123 112 push_config 124 113 set_dynamic_debug 125 114 set_ftrace_enabled 1
+6
tools/testing/selftests/livepatch/test_modules/Makefile
··· 13 13 test_klp_shadow_vars.o \ 14 14 test_klp_syscall.o 15 15 16 + # Ensure that KDIR exists, otherwise skip the compilation 16 17 modules: 18 + ifneq ("$(wildcard $(KDIR))", "") 17 19 $(Q)$(MAKE) -C $(KDIR) modules KBUILD_EXTMOD=$(TESTMODS_DIR) 20 + endif 18 21 22 + # Ensure that KDIR exists, otherwise skip the clean target 19 23 clean: 24 + ifneq ("$(wildcard $(KDIR))", "") 20 25 $(Q)$(MAKE) -C $(KDIR) clean KBUILD_EXTMOD=$(TESTMODS_DIR) 26 + endif