gitlab: Extract default build/test jobs templates
[qemu/ar7.git] / tests / tcg / Makefile.target
blobb29fae463020b51079d213774067c9bb4315bd83
1 # -*- Mode: makefile -*-
3 # TCG tests
5 # These are complicated by the fact we want to build them for guest
6 # systems. This requires knowing what guests we are building and which
7 # ones we have cross-compilers for or docker images with
8 # cross-compilers.
10 # The tests themselves should be as minimal as possible as
11 # cross-compilers don't always have a large amount of libraries
12 # available.
14 # We only include the host build system for SRC_PATH and we don't
15 # bother with the common rules.mk. We expect the following:
17 #   CC - the C compiler command
18 #   EXTRA_CFLAGS - any extra CFLAGS
19 #   BUILD_STATIC - are we building static binaries
21 # By default all tests are statically compiled but some host systems
22 # may not package static libraries by default. If an external
23 # cross-compiler can only build dynamic libraries the user might need
24 # to make extra efforts to ensure ld.so can link at runtime when the
25 # tests are run.
27 # We also accept SPEED=slow to enable slower running tests
29 # We also expect to be in the tests build dir for the FOO-(linux-user|softmmu).
32 all:
33 -include ../../../config-host.mak
34 -include ../config-$(TARGET).mak
35 ifeq ($(CONFIG_USER_ONLY),y)
36 -include $(SRC_PATH)/default-configs/targets/$(TARGET).mak
37 endif
39 # for including , in command strings
40 COMMA := ,
42 quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
44 # $1 = test name, $2 = cmd, $3 = desc
45 ifdef CONFIG_USER_ONLY
46 run-test = $(call quiet-command, timeout --foreground $(TIMEOUT) $2 > $1.out, \
47         "TEST",$3)
48 else
49 run-test = $(call quiet-command, timeout --foreground $(TIMEOUT) $2,"TEST",$3)
50 endif
52 # $1 = test name, $2 = reference
53 # to work around the pipe squashing the status we only pipe the result if
54 # we know it failed and then force failure at the end.
55 diff-out = $(call quiet-command, diff -q $1.out $2 || \
56                                  (diff -u $1.out $2 | head -n 10 && false), \
57                                  "DIFF","$1.out with $2")
59 # $1 = test name, $2 = reason
60 skip-test = @printf "  SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
62 # $1 = test name, $2 = reference
63 # As above but only diff if reference file exists, otherwise the test
64 # passes if it managed to complete with a status of zero
65 conditional-diff-out =                                                  \
66         $(if $(wildcard $2),                                            \
67                 $(call diff-out,$1,$2),                                 \
68                 $(call skip-test,"$1 check","no reference"))
71 # Tests we are building
72 TESTS=
73 # additional tests which may re-use existing binaries
74 EXTRA_TESTS=
76 # Start with a blank slate, the build targets get to add stuff first
77 CFLAGS=
78 QEMU_CFLAGS=
79 LDFLAGS=
81 QEMU_OPTS=
84 # If TCG debugging is enabled things are a lot slower
85 ifeq ($(CONFIG_DEBUG_TCG),y)
86 TIMEOUT=60
87 else
88 TIMEOUT=15
89 endif
91 ifdef CONFIG_USER_ONLY
92 # The order we include is important. We include multiarch first and
93 # then the target. If there are common tests shared between
94 # sub-targets (e.g. ARM & AArch64) then it is up to
95 # $(TARGET_NAME)/Makefile.target to include the common parent
96 # architecture in its VPATH.
97 -include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
98 -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
100 # Add the common build options
101 CFLAGS+=-Wall -Werror -O0 -g -fno-strict-aliasing
102 ifeq ($(BUILD_STATIC),y)
103 LDFLAGS+=-static
104 endif
106 %: %.c
107         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
108 else
109 # For softmmu targets we include a different Makefile fragement as the
110 # build options for bare programs are usually pretty different. They
111 # are expected to provide their own build recipes.
112 -include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
113 -include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
114 -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
116 endif
118 all: $(TESTS) $(EXTRA_TESTS)
121 # Test Runners
123 # By default we just run the test with the appropriate QEMU for the
124 # target. More advanced tests may want to override the runner in their
125 # specific make rules. Additional runners for the same binary should
126 # be added to EXTRA_RUNS.
129 RUN_TESTS=$(patsubst %,run-%, $(TESTS))
131 # If plugins exist also include those in the tests
132 ifeq ($(CONFIG_PLUGIN),y)
133 PLUGIN_SRC=$(SRC_PATH)/tests/plugin
134 PLUGIN_LIB=../../plugin
135 VPATH+=$(PLUGIN_LIB)
136 PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
138 # We need to ensure expand the run-plugin-TEST-with-PLUGIN
139 # pre-requistes manually here as we can't use stems to handle it. We
140 # also add some special helpers the run-plugin- rules can use bellow.
142 $(foreach p,$(PLUGINS), \
143         $(foreach t,$(TESTS),\
144                 $(eval run-plugin-$(t)-with-$(p): $t $p) \
145                 $(eval run-plugin-$(t)-with-$(p): TIMEOUT=60) \
146                 $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p))))
147 endif
149 strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1))
150 extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1))
152 RUN_TESTS+=$(EXTRA_RUNS)
154 ifdef CONFIG_USER_ONLY
155 run-%: %
156         $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<, "$< on $(TARGET_NAME)")
158 run-plugin-%:
159         $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
160                 -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
161                 -d plugin -D $*.pout \
162                  $(call strip-plugin,$<), \
163         "$* on $(TARGET_NAME)")
164 else
165 run-%: %
166         $(call run-test, $<, \
167           $(QEMU) -monitor none -display none \
168                   -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
169                   $(QEMU_OPTS) $<, \
170           "$< on $(TARGET_NAME)")
172 run-plugin-%:
173         $(call run-test, $@, \
174           $(QEMU) -monitor none -display none \
175                   -chardev file$(COMMA)path=$@.out$(COMMA)id=output \
176                   -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
177                   -d plugin -D $*.pout \
178                   $(QEMU_OPTS) $(call strip-plugin,$<), \
179           "$* on $(TARGET_NAME)")
180 endif
182 gdb-%: %
183         gdb --args $(QEMU) $(QEMU_OPTS) $<
185 .PHONY: run
186 run: $(RUN_TESTS)
188 # There is no clean target, the calling make just rm's the tests build dir