]> git.proxmox.com Git - mirror_qemu.git/blame - tests/tcg/Makefile.target
Merge tag 'misc-fixes-pull-request' of https://gitlab.com/berrange/qemu into staging
[mirror_qemu.git] / tests / tcg / Makefile.target
CommitLineData
7e97017e
AB
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#
bd15e6e0 29# We also expect to be in the tests build dir for the FOO-(linux-user|softmmu).
7e97017e
AB
30#
31
fc76c56d 32all:
544f4a25 33-include ../config-host.mak
a3e28f81 34-include config-target.mak
36e38426
PB
35
36# Get semihosting definitions for user-mode emulation
8e61ecca 37ifeq ($(filter %-softmmu, $(TARGET)),)
36e38426 38-include $(SRC_PATH)/configs/targets/$(TARGET).mak
3539d84d 39endif
076d2471 40
fdfda70e
AB
41# for including , in command strings
42COMMA := ,
15b273f8
PB
43NULL :=
44SPACE := $(NULL) #
45TARGET_PREFIX=tests/tcg/$(TARGET):$(SPACE)
fdfda70e 46
c6cf8a20
PB
47quiet-@ = $(if $(V),,@$(if $1,printf " %-7s %s\n" "$(strip $1)" "$(strip $2)" && ))
48quiet-command = $(call quiet-@,$2,$3)$1
7d13299d 49
15b273f8
PB
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
607bf9b5 55# $1 = test name, $2 = cmd, $3 = desc
8e61ecca 56ifeq ($(filter %-softmmu, $(TARGET)),)
57dbce5a 57run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2 > $1.out, \
c6cf8a20 58 TEST,$(or $3, $*, $<) on $(TARGET_NAME))
fdfda70e 59else
57dbce5a 60run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2, \
c6cf8a20 61 TEST,$(or $3, $*, $<) on $(TARGET_NAME))
fdfda70e 62endif
607bf9b5
AB
63
64# $1 = test name, $2 = reference
ef860047
AB
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), \
c6cf8a20 69 DIFF,$1.out with $2)
607bf9b5
AB
70
71# $1 = test name, $2 = reason
72skip-test = @printf " SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
a4f3ed62
AB
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
607bf9b5 82
7e97017e
AB
83# Tests we are building
84TESTS=
1852f3e4
AB
85# additional tests which may re-use existing binaries
86EXTRA_TESTS=
2b2e59e6 87
7e97017e
AB
88# Start with a blank slate, the build targets get to add stuff first
89CFLAGS=
4d1135e4
FB
90LDFLAGS=
91
fdfda70e 92QEMU_OPTS=
2b2e59e6 93
3d55c026 94
e5b46549 95# If TCG debugging, or TCI is enabled things are a lot slower
909c476d
RH
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
e5b46549 101TIMEOUT=90
2b2e59e6 102
8e61ecca 103ifeq ($(filter %-softmmu, $(TARGET)),)
9a297fac
AB
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.
7e97017e 109-include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
7e97017e 110-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
367e86e8 111
7e97017e 112# Add the common build options
2af43a6a 113CFLAGS+=-Wall -Werror -O0 -g -fno-strict-aliasing
7e97017e
AB
114ifeq ($(BUILD_STATIC),y)
115LDFLAGS+=-static
116endif
394411ac 117
7e97017e
AB
118%: %.c
119 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
ec2918b4
RH
120%: %.S
121 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
bd15e6e0 122else
7893e42d 123# For system targets we include a different Makefile fragment as the
bd15e6e0
AB
124# build options for bare programs are usually pretty different. They
125# are expected to provide their own build recipes.
580731dc 126EXTRA_CFLAGS += -ffreestanding -fno-stack-protector
a113ec98 127-include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
8041650a 128-include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
bd15e6e0 129-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
bd15e6e0
AB
130
131endif
394411ac 132
1852f3e4 133all: $(TESTS) $(EXTRA_TESTS)
18c9b560 134
7e97017e
AB
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#
e4630047 143
7e97017e 144RUN_TESTS=$(patsubst %,run-%, $(TESTS))
3089e74e
AB
145
146# If plugins exist also include those in the tests
147ifeq ($(CONFIG_PLUGIN),y)
fefa0271
AB
148PLUGIN_SRC=$(SRC_PATH)/tests/plugin
149PLUGIN_LIB=../../plugin
150VPATH+=$(PLUGIN_LIB)
c17a386b 151PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
3089e74e
AB
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
d044b7c3
AB
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
8b81968c 157# add some special helpers the run-plugin- rules can use below.
3089e74e 158
d044b7c3 159ifneq ($(MULTIARCH_TESTS),)
3089e74e 160$(foreach p,$(PLUGINS), \
d044b7c3 161 $(foreach t,$(MULTIARCH_TESTS),\
3089e74e 162 $(eval run-plugin-$(t)-with-$(p): $t $p) \
3089e74e 163 $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p))))
d044b7c3
AB
164endif # MULTIARCH_TESTS
165endif # CONFIG_PLUGIN
3089e74e
AB
166
167strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1))
168extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1))
169
7e97017e 170RUN_TESTS+=$(EXTRA_RUNS)
e4630047 171
af323aab
AB
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
8e61ecca 176ifeq ($(filter %-softmmu, $(TARGET)),)
7e97017e 177run-%: %
c6cf8a20 178 $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<)
3089e74e
AB
179
180run-plugin-%:
181 $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
af323aab 182 -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \
3089e74e 183 -d plugin -D $*.pout \
c6cf8a20 184 $(call strip-plugin,$<))
fdfda70e
AB
185else
186run-%: %
187 $(call run-test, $<, \
188 $(QEMU) -monitor none -display none \
189 -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
c6cf8a20 190 $(QEMU_OPTS) $<)
3089e74e
AB
191
192run-plugin-%:
193 $(call run-test, $@, \
194 $(QEMU) -monitor none -display none \
195 -chardev file$(COMMA)path=$@.out$(COMMA)id=output \
af323aab 196 -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@)$(PLUGIN_ARGS) \
3089e74e 197 -d plugin -D $*.pout \
c6cf8a20 198 $(QEMU_OPTS) $(call strip-plugin,$<))
fdfda70e 199endif
e7daa605 200
d0ce6257
AB
201gdb-%: %
202 gdb --args $(QEMU) $(QEMU_OPTS) $<
203
7e97017e
AB
204.PHONY: run
205run: $(RUN_TESTS)
d65f0831 206
eebf199c 207clean:
91117bc5 208 rm -f $(TESTS) *.o $(CLEANFILES)
6ffe8137
PB
209
210distclean:
15b273f8 211 rm -f config-cc.mak config-target.mak ../config-$(TARGET).mak
6f6ca067
AB
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";)