diff mbox series

[v3,2/2] selftests/lib.mk: Introduce check to validate required dependencies

Message ID 20250227053322.114215-3-simeddon@gmail.com (mailing list archive)
State New
Headers show
Series update kselftest framework to check for required configs | expand

Commit Message

Siddharth Menon Feb. 27, 2025, 5:29 a.m. UTC
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 <pmladek@suse.com>
Suggested-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Siddharth Menon <simeddon@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(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index d6edcfcb5be8..0e11d1d3bab8 100644
--- 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