kbuild: run kunit selftests via the top-level kunit target
PATCH 1/1 kbuild: run kunit selftests via the top-level kunit target
If we can make kunit tests easier to run (currently, the way to run them is via "./tools/testing/kunit/kunit.py run") then it's much more likely that people will run the Kernel unit tests as part of their normal development workflow.
See the discusion linked below for more details about the rationale behind this change.
--- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Makefile +10 -1
@@ -295,7 +295,7 @@ no-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ - outputmakefile rustavailable rustfmt rustfmtcheck + outputmakefile rustavailable rustfmt rustfmtcheck kunit no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ image_name single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/
@@ -2139,6 +2139,15 @@ existing-targets := $(wildcard $(sort $(targets))) -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) +PHONY += kunit +kunit: +ifeq ($(SRCARCH),x86) + $(Q)$(PYTHON3) $(srctree)/tools/testing/kunit/kunit.py run +else + @echo >&2 "Kunit not supported on this architecture: $(ARCH)" + @false +endif + endif # config-build endif # mixed-build endif # need-sub-make
Signature · 1 line
2.47.2
Quoted 11 lines · Theodore Ts'o
If we can make kunit tests easier to run (currently, the way to run them is via "
./tools/testing/kunit/kunit.pyrun") then it's much more likely that people will run the Kernel unit tests as part of their normal development workflow.See the discusion linked below for more details about the rationale behind this change.
There is no reason to grow the top-level Makefile for this because tools/testing/kunit/kunit.py is an independent script that does not rely on any Make variables from the top-level Makefile.
If you prefer a shorter command, you can add a simple wrapper.
$ cat tools/kunit #!/bin/sh $(dirname $0)/testing/kunit/kunit.py run
Quoted 37 lines
--- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)Makefile +10
-2@@ -295,7 +295,7 @@ no-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ - outputmakefile rustavailable rustfmt rustfmtcheck + outputmakefile rustavailable rustfmt rustfmtcheck kunit no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ image_name single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/@@ -2139,6 +2139,15 @@ existing-targets := $(wildcard $(sort $(targets))) -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) +PHONY += kunit +kunit: +ifeq ($(SRCARCH),x86) + $(Q)$(PYTHON3) $(srctree)/tools/testing/kunit/kunit.py run +else + @echo >&2 "Kunit not supported on this architecture: $(ARCH)" + @false +endif + endif # config-build endif # mixed-build endif # need-sub-make --2.47.2
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 6 lines · Theodore Ts'o
If we can make kunit tests easier to run (currently, the way to run them is via "
./tools/testing/kunit/kunit.pyrun") then it's much more likely that people will run the Kernel unit tests as part of their normal development workflow.
Quoted 6 lines
See the discusion linked below for more details about the rationale behind this change.
Signed-off-by Theodore Ts'o <[email protected]>---
Thanks very much.
Unfortunately this isn't working on a clean tree (and possibly having some issues even on one with an existing .kunit/ build), due to all of the environment variables (and the working directory) having been changed by the Makefile, which breaks kunit.py.
I've put a quick hack using env to clear the environment below. The other option would be to modify kunit.py to clean the environment before shelling out to make, which might be worth doing anyway (though I'm hesitant to always clear out environment variables).
Cheers,
-- David
Quoted 17 lines
Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)Makefile +1
-1@@ -295,7 +295,7 @@ no-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ - outputmakefile rustavailable rustfmt rustfmtcheck + outputmakefile rustavailable rustfmt rustfmtcheck kunit no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ image_name single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/
Makefile existing-targets := $(wildcard $(sort $(targets))) · line 2145
Quoted 7 lines
Makefile +4
-0@@ -2139,6 +2139,15 @@ existing-targets := $(wildcard $(sort $(targets))) -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) +PHONY += kunit +kunit: +ifeq ($(SRCARCH),x86) + $(Q)$(PYTHON3) $(srctree)/tools/testing/kunit/kunit.py run
This doesn't actually work, as the Makefile has already set a bunch of environment variables which conflict with the build triggered by kunit.py
A quick fix seems to be:
---
Makefile +0 -0
@@ -2145,7 +2145,7 @@ existing-targets := $(wildcard $(sort $(targets)))
PHONY += kunit
kunit:
ifeq ($(SRCARCH),x86)
- $(Q)$(PYTHON3) $(srctree)/tools/testing/kunit/kunit.py run
+ $(Q)env -C$(srctree) -i PATH=$(PATH) TERM=$(TERM) HOME=$(HOME)
$(PYTHON3) $(srctree)/tools/testing/kunit/kunit.py run else
@echo >&2 "Kunit not supported on this architecture: $(ARCH)"
@false---
Makefile existing-targets := $(wildcard $(sort $(targets))) · line 2147
Quoted 2 lines
Makefile +2
-0+else + @echo >&2 "Kunit not supported on this architecture: $(ARCH)"
Nit: we tend to use "KUnit" or "kunit" for capitalisation here.
It also might be possible to automatically fall back to the qemu codepath here, but that's something I'll look at as a kunit.py change, not a makefile change.
Quoted 13 lines
Makefile +3
-1+ @false +endif + endif # config-build endif # mixed-build endif # need-sub-make --2.47.2
--
You received this message because you are subscribed to the Google Groups "KUnit Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/kunit-dev/20250729220439.421735-1-tytso%40mit.edu.