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