xref: /openbmc/qemu/tests/tcg/Makefile.target (revision 8905770b)
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 := ,
43
44quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
45
46# $1 = test name, $2 = cmd, $3 = desc
47ifeq ($(filter %-softmmu, $(TARGET)),)
48run-test = $(call quiet-command, timeout --foreground $(TIMEOUT) $2 > $1.out, \
49	"TEST",$3)
50else
51run-test = $(call quiet-command, timeout --foreground $(TIMEOUT) $2,"TEST",$3)
52endif
53
54# $1 = test name, $2 = reference
55# to work around the pipe squashing the status we only pipe the result if
56# we know it failed and then force failure at the end.
57diff-out = $(call quiet-command, diff -q $1.out $2 || \
58                                 (diff -u $1.out $2 | head -n 10 && false), \
59                                 "DIFF","$1.out with $2")
60
61# $1 = test name, $2 = reason
62skip-test = @printf "  SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
63
64# $1 = test name, $2 = reference
65# As above but only diff if reference file exists, otherwise the test
66# passes if it managed to complete with a status of zero
67conditional-diff-out = 							\
68	$(if $(wildcard $2), 						\
69		$(call diff-out,$1,$2), 				\
70		$(call skip-test,"$1 check","no reference"))
71
72
73# Tests we are building
74TESTS=
75# additional tests which may re-use existing binaries
76EXTRA_TESTS=
77
78# Start with a blank slate, the build targets get to add stuff first
79CFLAGS=
80LDFLAGS=
81
82QEMU_OPTS=
83
84
85# If TCG debugging, or TCI is enabled things are a lot slower
86# ??? Makefile no longer has any indication that TCI is enabled,
87# but for the record:
88#   15s    original default
89#   60s    with --enable-debug
90#   90s    with --enable-tcg-interpreter
91TIMEOUT=90
92
93ifeq ($(filter %-softmmu, $(TARGET)),)
94# The order we include is important. We include multiarch first and
95# then the target. If there are common tests shared between
96# sub-targets (e.g. ARM & AArch64) then it is up to
97# $(TARGET_NAME)/Makefile.target to include the common parent
98# architecture in its VPATH.
99-include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
100-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
101
102# Add the common build options
103CFLAGS+=-Wall -Werror -O0 -g -fno-strict-aliasing
104ifeq ($(BUILD_STATIC),y)
105LDFLAGS+=-static
106endif
107
108%: %.c
109	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
110else
111# For softmmu targets we include a different Makefile fragement as the
112# build options for bare programs are usually pretty different. They
113# are expected to provide their own build recipes.
114-include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
115-include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
116-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
117
118endif
119
120all: $(TESTS) $(EXTRA_TESTS)
121
122#
123# Test Runners
124#
125# By default we just run the test with the appropriate QEMU for the
126# target. More advanced tests may want to override the runner in their
127# specific make rules. Additional runners for the same binary should
128# be added to EXTRA_RUNS.
129#
130
131RUN_TESTS=$(patsubst %,run-%, $(TESTS))
132
133# If plugins exist also include those in the tests
134ifeq ($(CONFIG_PLUGIN),y)
135PLUGIN_SRC=$(SRC_PATH)/tests/plugin
136PLUGIN_LIB=../../plugin
137VPATH+=$(PLUGIN_LIB)
138PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
139
140# We need to ensure expand the run-plugin-TEST-with-PLUGIN
141# pre-requistes manually here as we can't use stems to handle it. We
142# also add some special helpers the run-plugin- rules can use bellow.
143
144$(foreach p,$(PLUGINS), \
145	$(foreach t,$(TESTS),\
146		$(eval run-plugin-$(t)-with-$(p): $t $p) \
147		$(eval RUN_TESTS+=run-plugin-$(t)-with-$(p))))
148endif
149
150strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1))
151extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1))
152
153RUN_TESTS+=$(EXTRA_RUNS)
154
155ifeq ($(filter %-softmmu, $(TARGET)),)
156run-%: %
157	$(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<, "$< on $(TARGET_NAME)")
158
159run-plugin-%:
160	$(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
161		-plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
162		-d plugin -D $*.pout \
163		 $(call strip-plugin,$<), \
164	"$* on $(TARGET_NAME)")
165else
166run-%: %
167	$(call run-test, $<, \
168	  $(QEMU) -monitor none -display none \
169		  -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
170	   	  $(QEMU_OPTS) $<, \
171	  "$< on $(TARGET_NAME)")
172
173run-plugin-%:
174	$(call run-test, $@, \
175	  $(QEMU) -monitor none -display none \
176		  -chardev file$(COMMA)path=$@.out$(COMMA)id=output \
177	   	  -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
178	    	  -d plugin -D $*.pout \
179	   	  $(QEMU_OPTS) $(call strip-plugin,$<), \
180	  "$* on $(TARGET_NAME)")
181endif
182
183gdb-%: %
184	gdb --args $(QEMU) $(QEMU_OPTS) $<
185
186.PHONY: run
187run: $(RUN_TESTS)
188
189clean:
190	rm -f $(TESTS) *.o
191