3 # Unit tests for the KERN subsystem
7 ALL_TESTS = $(INTERFACES_UNITTEST)
8 RUN_TESTS = $(addsuffix .ok, $(ALL_TESTS))
11 unittest: $(RUN_TESTS)
14 # Dependency calculation. WARNING: Black Art [tm].
15 # Algorithm: For each module M:
16 # - Include everything mentioned in the INTERFACES_KERNEL before M
17 # - Optimization: Sibling weed-out: Remove all modules mentioned
18 # directly before M that M does not #include
19 # - Find object files comprising these modules
20 # - Finally, add objects comprising module M_t, and all libraries
21 # subsystem KERNEL depends on
25 module_of_test = $(patsubst %_t,%,$(1))
27 # return sublist of $(2) which contains all elements before $(1)
28 earlier_modules = $(shell echo $(2) | sed 's, $(strip $(1)) *.*$$,,')
30 # return list of modules included by module $(1); candidates are in $(2)
31 inc_sedstr = 's/^ *\# *include *"\(.*\)\.h"/\1/p'
32 includes = $(filter $(2), \
33 $(shell sed -n $(inc_sedstr) auto/$(strip $(1)).h auto/$(strip $(1))_i.h))
35 # remove elements trailing list $(1) that do not appear in list $(2)
38 $(shell perl -e '@l = split " ", "$(strip $(1))";
39 %inc = ( $(addsuffix =>" "$(comma),$(2)) );
40 sub trim { return () if ! scalar @_;
42 return @_ if defined $$inc{$$last};
45 print join(" ", trim(@l));')
48 # return list of objects belonging to a list of module
49 objects = $(addsuffix .o, $(foreach mod, $(1), \
50 $(if $($(mod)_IMPL), $($(mod)_IMPL), $(mod))))
54 do-all: .Unittest.deps
56 .Unittest.deps: $(MODULES_FILE)
58 $(VERBOSE)( $(foreach test, $(ALL_TESTS), \
59 test_base=$(call module_of_test, $(test)); \
60 echo '$(test): $(call objects, $(test)) \
61 $$(call objects, '"$$test_base"' $$(call trimlist, \
62 $(call earlier_modules, \
63 $(call module_of_test, $(test)), \
64 $(INTERFACES_KERNEL)), \
65 $$(call includes, '"$$test_base"', \
66 $$(INTERFACES_KERNEL))))';) \
72 include .Unittest.deps
75 # List of subsystems on which KERNEL depends
76 $(ALL_TESTS): $(ABI) $(JABI) $(DRIVERS) $(LIBK) $(LIBAMM) $(CXXLIB)
77 $(ALL_TESTS): kernel.ux.lds
80 $(ALL_TESTS): sighandler.o
87 @echo "Linking test $@"
88 $(VERBOSE)$(CXX) -m32 -Wl,-Tkernel.ux.lds,--gc-sections \
89 -static $(CXXFLAGS) $(LDFLAGS) $(PROF_FLAGS) $(OPT_CXXFLAGS) \
90 $(filter-out kernel.ux.lds,$^) -o $@ $(TEST_LIB) -lutil
93 ifeq ($(SYSTEM_TARGET)$(CONFIG_XARCH),ux) # Test execution for non-cross UX builds
94 @echo -n "Running test $* ... "
95 @./$< --test --quiet > $*.out.full
96 @grep "^\[UTEST\]" $*.out.full > $*.out
97 ifeq ($(RECREATE_OUTPUT),1)
98 @cp $*.out $(srcdir)/test/unit/$*.out.verify.$(CONFIG_ABI)
99 endif # RECREATE_OUTPUT
101 testbase=$(srcdir)/test/unit/$*.out.verify; \
102 if [ -f $$testbase ]; then \
103 if [ -f $$testbase.$(CONFIG_ABI) ]; then \
104 echo "Error: $$testbase.$(CONFIG_ABI) and $$testbase both exist."; \
108 testbase=$$testbase.$(CONFIG_ABI); \
110 diff -u $(DIFF_FLAGS) $$testbase $*.out
112 # Add commands for executing tests built for other architectures.
117 rm -f *_t *_t.ok *_t.out .Unittest.deps