]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/Makerules.UNITTEST
update
[l4.git] / kernel / fiasco / src / Makerules.UNITTEST
1 # -*- makefile -*-
2
3 # Unit tests for the KERN subsystem
4
5 UNITTEST = unittest
6
7 ALL_TESTS = $(INTERFACES_UNITTEST)
8 RUN_TESTS = $(addsuffix .ok, $(ALL_TESTS))
9
10 .PHONY: unittest
11 unittest: $(RUN_TESTS)
12
13 #
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
22 #
23
24 # Trim trailing "_t"
25 module_of_test = $(patsubst %_t,%,$(1))
26
27 # return sublist of $(2) which contains all elements before $(1)
28 earlier_modules = $(shell echo $(2) | sed 's, $(strip $(1)) *.*$$,,')
29
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))
34
35 # remove elements trailing list $(1) that do not appear in list $(2)
36 comma = ,
37 define trimlist 
38   $(shell perl -e '@l = split " ", "$(strip $(1))"; 
39                    %inc = ( $(addsuffix =>" "$(comma),$(2)) );
40                    sub trim { return () if ! scalar @_;
41                               my $$last = $$_[-1]; 
42                               return @_ if defined $$inc{$$last};
43                               pop @_;
44                               return trim(@_); }
45                    print join(" ", trim(@l));')
46 endef
47
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))))
51
52 ifdef BUILD_SOURCES
53
54 do-all: .Unittest.deps
55
56 .Unittest.deps: $(MODULES_FILE)
57         @echo "Generating $@"
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))))';)        \
67         )  > $@.new
68         mv $@.new $@
69 endif
70
71 ifdef BUILD_OBJECTS
72 include .Unittest.deps
73 endif
74
75 # List of subsystems on which KERNEL depends 
76 $(ALL_TESTS): $(ABI) $(JABI) $(DRIVERS) $(LIBK) $(LIBAMM) $(CXXLIB)
77 $(ALL_TESTS): kernel.ux.lds
78
79 # XXX Hacks
80 $(ALL_TESTS): sighandler.o
81
82 #
83 # Compilation Rules
84 #
85
86 $(ALL_TESTS): %: %.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
91
92 %.ok: %
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
100         @set -e;                                                   \
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."; \
105               exit 1;                                              \
106             fi;                                                    \
107           else                                                     \
108             testbase=$$testbase.$(CONFIG_ABI);                     \
109           fi;                                                      \
110           diff -u $(DIFF_FLAGS) $$testbase $*.out
111 else  # ! ux
112 # Add commands for executing tests built for other architectures.
113 endif # ! ux
114         @touch $@
115
116 clean-UNITTEST:
117         rm -f *_t *_t.ok *_t.out .Unittest.deps