xref: /openbmc/qemu/tests/tcg/Makefile.target (revision 6e510855)
1# -*- Mode: makefile -*-
2#
3# TCG tests
4#
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.
9#
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.
13#
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:
16#
17#   CC - the C compiler command
18#   EXTRA_CFLAGS - any extra CFLAGS
19#   BUILD_STATIC - are we building static binaries
20#
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.
26#
27# We also accept SPEED=slow to enable slower running tests
28#
29# We also expect to be in the tests build dir for the FOO-(linux-user|softmmu).
30#
31
32all:
33-include ../config-host.mak
34-include config-target.mak
35
36# Get semihosting definitions for user-mode emulation
37ifeq ($(filter %-softmmu, $(TARGET)),)
38-include $(SRC_PATH)/configs/targets/$(TARGET).mak
39endif
40
41# for including , in command strings
42COMMA := ,
43NULL :=
44SPACE := $(NULL) #
45TARGET_PREFIX=tests/tcg/$(TARGET):$(SPACE)
46
47quiet-@ = $(if $(V),,@$(if $1,printf "  %-7s %s\n" "$(strip $1)" "$(strip $2)" && ))
48quiet-command = $(call quiet-@,$2,$3)$1
49
50cc-test = $(CC) -Werror $1 -c -o /dev/null -xc /dev/null >/dev/null 2>&1
51cc-option = if $(call cc-test, $1); then \
52    echo "$(TARGET_PREFIX)$1 detected" && echo "$(strip $2)=y" >&3; else \
53    echo "$(TARGET_PREFIX)$1 not detected"; fi
54
55# $1 = test name, $2 = cmd, $3 = desc
56ifeq ($(filter %-softmmu, $(TARGET)),)
57run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2 > $1.out, \
58	TEST,$(or $3, $*, $<) on $(TARGET_NAME))
59else
60run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2, \
61        TEST,$(or $3, $*, $<) on $(TARGET_NAME))
62endif
63
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.
67diff-out = $(call quiet-command, diff -q $1.out $2 || \
68                                 (diff -u $1.out $2 | head -n 10 && false), \
69                                 DIFF,$1.out with $2)
70
71# $1 = test name, $2 = reason
72skip-test = @printf "  SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
73
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
77conditional-diff-out = 							\
78	$(if $(wildcard $2), 						\
79		$(call diff-out,$1,$2), 				\
80		$(call skip-test,"$1 check","no reference"))
81
82
83# Tests we are building
84TESTS=
85# additional tests which may re-use existing binaries
86EXTRA_TESTS=
87
88# Start with a blank slate, the build targets get to add stuff first
89CFLAGS=
90LDFLAGS=
91
92QEMU_OPTS=
93
94
95# If TCG debugging, or TCI is enabled things are a lot slower
96# ??? Makefile no longer has any indication that TCI is enabled,
97# but for the record:
98#   15s    original default
99#   60s    with --enable-debug
100#   90s    with --enable-tcg-interpreter
101TIMEOUT=90
102
103ifeq ($(filter %-softmmu, $(TARGET)),)
104# The order we include is important. We include multiarch first and
105# then the target. If there are common tests shared between
106# sub-targets (e.g. ARM & AArch64) then it is up to
107# $(TARGET_NAME)/Makefile.target to include the common parent
108# architecture in its VPATH.
109-include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
110-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
111
112# Add the common build options
113CFLAGS+=-Wall -Werror -O0 -g -fno-strict-aliasing
114ifeq ($(BUILD_STATIC),y)
115LDFLAGS+=-static
116endif
117
118%: %.c
119	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
120%: %.S
121	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
122else
123# For softmmu targets we include a different Makefile fragment as the
124# build options for bare programs are usually pretty different. They
125# are expected to provide their own build recipes.
126EXTRA_CFLAGS += -ffreestanding
127-include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
128-include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
129-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
130
131endif
132
133all: $(TESTS) $(EXTRA_TESTS)
134
135#
136# Test Runners
137#
138# By default we just run the test with the appropriate QEMU for the
139# target. More advanced tests may want to override the runner in their
140# specific make rules. Additional runners for the same binary should
141# be added to EXTRA_RUNS.
142#
143
144RUN_TESTS=$(patsubst %,run-%, $(TESTS))
145
146# If plugins exist also include those in the tests
147ifeq ($(CONFIG_PLUGIN),y)
148PLUGIN_SRC=$(SRC_PATH)/tests/plugin
149PLUGIN_LIB=../../plugin
150VPATH+=$(PLUGIN_LIB)
151PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
152
153# We need to ensure expand the run-plugin-TEST-with-PLUGIN
154# pre-requistes manually here as we can't use stems to handle it. We
155# only expand MULTIARCH_TESTS which are common on most of our targets
156# to avoid an exponential explosion as new tests are added. We also
157# add some special helpers the run-plugin- rules can use below.
158
159ifneq ($(MULTIARCH_TESTS),)
160$(foreach p,$(PLUGINS), \
161	$(foreach t,$(MULTIARCH_TESTS),\
162		$(eval run-plugin-$(t)-with-$(p): $t $p) \
163		$(eval RUN_TESTS+=run-plugin-$(t)-with-$(p))))
164endif # MULTIARCH_TESTS
165endif # CONFIG_PLUGIN
166
167strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1))
168extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1))
169
170RUN_TESTS+=$(EXTRA_RUNS)
171
172# Some plugins need additional arguments above the default to fully
173# exercise things. We can define them on a per-test basis here.
174run-plugin-%-with-libmem.so: PLUGIN_ARGS=$(COMMA)inline=true$(COMMA)callback=true
175
176ifeq ($(filter %-softmmu, $(TARGET)),)
177run-%: %
178	$(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<)
179
180run-plugin-%:
181	$(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
182		-plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \
183		-d plugin -D $*.pout \
184		 $(call strip-plugin,$<))
185else
186run-%: %
187	$(call run-test, $<, \
188	  $(QEMU) -monitor none -display none \
189		  -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
190		  $(QEMU_OPTS) $<)
191
192run-plugin-%:
193	$(call run-test, $@, \
194	  $(QEMU) -monitor none -display none \
195		  -chardev file$(COMMA)path=$@.out$(COMMA)id=output \
196	   	  -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \
197	    	  -d plugin -D $*.pout \
198		  $(QEMU_OPTS) $(call strip-plugin,$<))
199endif
200
201gdb-%: %
202	gdb --args $(QEMU) $(QEMU_OPTS) $<
203
204.PHONY: run
205run: $(RUN_TESTS)
206
207clean:
208	rm -f $(TESTS) *.o $(CLEANFILES)
209
210distclean:
211	rm -f config-cc.mak config-target.mak ../config-$(TARGET).mak
212
213.PHONY: help
214help:
215	@echo "TCG tests help $(TARGET_NAME)"
216	@echo "Built with $(CC)"
217	@echo "Available tests:"
218	@$(foreach t,$(RUN_TESTS),echo "  $t";)
219