1 # -*- Mode: makefile -*-
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
10 # The tests themselves should be as minimal as possible as
11 # cross-compilers don't always have a large amount of libraries
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
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).
33 -include ../config-host.mak
34 -include config-target.mak
36 # Get semihosting definitions for user-mode emulation
37 ifeq ($(filter %-softmmu, $(TARGET)),)
38 -include $(SRC_PATH)/configs/targets/$(TARGET).mak
41 # for including , in command strings
45 TARGET_PREFIX=tests/tcg/$(TARGET):$(SPACE)
47 quiet-@ = $(if $(V),,@$(if $1,printf " %-7s %s\n" "$(strip $1)" "$(strip $2)" && ))
48 quiet-command = $(call quiet-@,$2,$3)$1
50 cc-test = $(CC) -Werror $1 -c -o /dev/null -xc /dev/null >/dev/null 2>&1
51 cc-option = if $(call cc-test, $1); then \
52 echo "$(TARGET_PREFIX)$1 detected" && echo "$(strip $2)=$(strip $1)" >&3; else \
53 echo "$(TARGET_PREFIX)$1 not detected"; fi
55 # $1 = test name, $2 = cmd, $3 = desc
56 ifeq ($(filter %-softmmu, $(TARGET)),)
57 run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2 > $1.out, \
58 TEST,$(or $3, $*, $<) on $(TARGET_NAME))
60 run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2, \
61 TEST,$(or $3, $*, $<) on $(TARGET_NAME))
64 # $1 = test name, $2 = reference
65 # to work around the pipe squashing the status we only pipe the result if
66 # we know it failed and then force failure at the end.
67 diff-out = $(call quiet-command, diff -q $1.out $2 || \
68 (diff -u $1.out $2 | head -n 10 && false), \
71 # $1 = test name, $2 = reason
72 skip-test = @printf " SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
74 # $1 = test name, $2 = reference
75 # As above but only diff if reference file exists, otherwise the test
76 # passes if it managed to complete with a status of zero
77 conditional-diff-out = \
78 $(if $(wildcard $2), \
79 $(call diff-out,$1,$2), \
80 $(call skip-test,"$1 check","no reference"))
83 # Tests we are building
85 # additional tests which may re-use existing binaries
88 # Start with a blank slate, the build targets get to add stuff first
93 CHECK_PLUGIN_OUTPUT_COMMAND=
96 # If TCG debugging, or TCI is enabled things are a lot slower
97 # so we have to set our timeout for that. The current worst case
98 # offender is the system memory test running under TCI.
101 ifeq ($(filter %-softmmu, $(TARGET)),)
102 # The order we include is important. We include multiarch first and
103 # then the target. If there are common tests shared between
104 # sub-targets (e.g. ARM & AArch64) then it is up to
105 # $(TARGET_NAME)/Makefile.target to include the common parent
106 # architecture in its VPATH.
107 -include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
108 -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
110 # Add the common build options
111 CFLAGS+=-Wall -Werror -O0 -g -fno-strict-aliasing
112 ifeq ($(BUILD_STATIC),y)
117 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
119 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -Wa,--noexecstack $< -o $@ $(LDFLAGS)
121 # For system targets we include a different Makefile fragment as the
122 # build options for bare programs are usually pretty different. They
123 # are expected to provide their own build recipes.
124 EXTRA_CFLAGS += -ffreestanding -fno-stack-protector
125 -include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
126 -include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
127 -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
131 all: $(TESTS) $(EXTRA_TESTS)
136 # By default we just run the test with the appropriate QEMU for the
137 # target. More advanced tests may want to override the runner in their
138 # specific make rules. Additional runners for the same binary should
139 # be added to EXTRA_RUNS.
142 RUN_TESTS=$(patsubst %,run-%, $(TESTS))
144 # If plugins exist also include those in the tests
145 ifeq ($(CONFIG_PLUGIN),y)
146 PLUGIN_SRC=$(SRC_PATH)/tests/tcg/plugins
147 PLUGIN_LIB=../plugins
149 PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
151 # We need to ensure expand the run-plugin-TEST-with-PLUGIN
152 # pre-requistes manually here as we can't use stems to handle it. We
153 # only expand MULTIARCH_TESTS which are common on most of our targets
154 # to avoid an exponential explosion as new tests are added. We also
155 # add some special helpers the run-plugin- rules can use below.
156 # In more, extra tests can be added using ADDITIONAL_PLUGINS_TESTS variable.
158 ifneq ($(MULTIARCH_TESTS),)
159 $(foreach p,$(PLUGINS), \
160 $(foreach t,$(MULTIARCH_TESTS) $(ADDITIONAL_PLUGINS_TESTS),\
161 $(eval run-plugin-$(t)-with-$(p): $t $p) \
162 $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p))))
163 endif # MULTIARCH_TESTS
164 endif # CONFIG_PLUGIN
166 strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1))
167 extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1))
169 RUN_TESTS+=$(EXTRA_RUNS)
171 # Some plugins need additional arguments above the default to fully
172 # exercise things. We can define them on a per-test basis here.
173 run-plugin-%-with-libmem.so: PLUGIN_ARGS=$(COMMA)inline=true
175 ifeq ($(filter %-softmmu, $(TARGET)),)
177 $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<)
180 $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
181 -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \
182 -d plugin -D $*.pout \
183 $(call strip-plugin,$<))
184 $(if $(CHECK_PLUGIN_OUTPUT_COMMAND), \
185 $(call quiet-command, $(CHECK_PLUGIN_OUTPUT_COMMAND) $*.pout, \
186 TEST, check plugin $(call extract-plugin,$@) output \
187 with $(call strip-plugin,$<)))
190 $(call run-test, $<, \
191 $(QEMU) -monitor none -display none \
192 -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
196 $(call run-test, $@, \
197 $(QEMU) -monitor none -display none \
198 -chardev file$(COMMA)path=$@.out$(COMMA)id=output \
199 -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \
200 -d plugin -D $*.pout \
201 $(QEMU_OPTS) $(call strip-plugin,$<))
202 $(if $(CHECK_PLUGIN_OUTPUT_COMMAND), \
203 $(call quiet-command, $(CHECK_PLUGIN_OUTPUT_COMMAND) $*.pout, \
204 TEST, check plugin $(call extract-plugin,$@) output \
205 with $(call strip-plugin,$<)))
209 gdb --args $(QEMU) $(QEMU_OPTS) $<
215 rm -f $(TESTS) *.o $(CLEANFILES)
218 rm -f config-cc.mak config-target.mak ../config-$(TARGET).mak
222 @echo "TCG tests help $(TARGET_NAME)"
223 @echo "Built with $(CC)"
224 @echo "Available tests:"
225 @$(foreach t,$(RUN_TESTS),echo " $t";)