On Wed, 30 Jul 2025 at 06:04, Theodore Ts'o <
ty...@mit.edu> wrote:
>
> 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.
>
> Link:
https://groups.google.com/g/kunit-dev/c/aHnAlT13ayU
> Signed-off-by: Theodore Ts'o <
ty...@mit.edu>
> ---
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
> Makefile | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index 478f2004602d..1d5257240a5d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
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:
---
diff --git a/Makefile b/Makefile
index fab4c47988c1..6e31a9486a06 100644
--- a/Makefile
+++ b/Makefile
@@ -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
---
> +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.
> + @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
kunit-dev+...@googlegroups.com.
> To view this discussion visit
https://groups.google.com/d/msgid/kunit-dev/20250729220439.421735-1-tytso%40mit.edu.