Currently, kselftests does not have a generalised mechanism to skip compilation
and run tests when required kernel configuration flags are missing.

This patch introduces a check to validate the presence of required config flags
specified in the selftest config files. In case scripts/config or the current
kernel config is not found, this check is skipped.

In order to skip checking for config options required to compile the test,
set the environment variable SKIP_CHECKS=1.

example usage:
```
make SKIP_CHECKS=1 -C livepatch/
```

Suggested-by: Petr Mladek <pmla...@suse.com>
Suggested-by: Miroslav Benes <mbe...@suse.cz>
Signed-off-by: Siddharth Menon <simed...@gmail.com>
---
 v1->v2:
 - Moved the logic to check for required configurations
   to an external script
 v2 -> v3:
 - Add SKIP_CHECKS flag to skip checking the dependencies
   if required
 - Updated the test skip statement to be more meaningful
 tools/testing/selftests/lib.mk | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 tools/testing/selftests/lib.mk

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
old mode 100644
new mode 100755
index d6edcfcb5be8..0e11d1d3bab8
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -97,7 +97,18 @@ TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
 
-all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) \
+TEST_DIR := $(shell pwd)
+
+check_kselftest_deps:
+ifneq ($(SKIP_CHECKS),1)
+       @$(selfdir)/check_kselftest_deps.pl $(TEST_DIR) $(CC) || { \
+               echo "Skipping test: $(notdir $(TEST_DIR)) (missing required 
kernel features)"; \
+               exit 1; \
+       }
+endif
+
+
+all: check_kselftest_deps $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) 
$(TEST_GEN_FILES) \
        $(if $(TEST_GEN_MODS_DIR),gen_mods_dir)
 
 define RUN_TESTS
@@ -228,4 +239,4 @@ $(OUTPUT)/%:%.S
        $(LINK.S) $^ $(LDLIBS) -o $@
 endif
 
-.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir
+.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir 
check_kselftest_deps
-- 
2.39.5


Reply via email to