blob: a3b0aaf8af1ff4f0d3a9ec99999267e404e65124 [file] [log] [blame]
Alex Bennée7e970172018-04-06 13:32:18 +01001# -*- 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#
Alex Bennéebd15e6e2018-11-29 22:19:21 +000029# We also expect to be in the tests build dir for the FOO-(linux-user|softmmu).
Alex Bennée7e970172018-04-06 13:32:18 +010030#
31
Paolo Bonzinifc76c562019-08-07 16:35:22 +020032all:
Paolo Bonzini544f4a22022-04-19 10:10:13 +010033-include ../config-host.mak
Paolo Bonzinia3e28f82022-09-29 12:41:59 +010034-include config-target.mak
Paolo Bonzini36e38422022-03-29 12:44:39 +020035
36# Get semihosting definitions for user-mode emulation
Paolo Bonzini8e61ecc2022-04-19 10:10:09 +010037ifeq ($(filter %-softmmu, $(TARGET)),)
Paolo Bonzini36e38422022-03-29 12:44:39 +020038-include $(SRC_PATH)/configs/targets/$(TARGET).mak
Alex Bennée3539d842021-03-23 16:52:51 +000039endif
Paolo Bonzini076d2472009-12-21 10:06:55 +010040
Alex Bennéefdfda702019-03-12 14:13:16 +000041# for including , in command strings
42COMMA := ,
Paolo Bonzini15b273f2022-09-29 12:42:04 +010043NULL :=
44SPACE := $(NULL) #
45TARGET_PREFIX=tests/tcg/$(TARGET):$(SPACE)
Alex Bennéefdfda702019-03-12 14:13:16 +000046
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +010047quiet-@ = $(if $(V),,@$(if $1,printf " %-7s %s\n" "$(strip $1)" "$(strip $2)" && ))
48quiet-command = $(call quiet-@,$2,$3)$1
bellard7d132992003-03-06 23:23:54 +000049
Paolo Bonzini15b273f2022-09-29 12:42:04 +010050cc-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
Alex Bennée607bf9b2018-05-21 10:38:37 +010055# $1 = test name, $2 = cmd, $3 = desc
Paolo Bonzini8e61ecc2022-04-19 10:10:09 +010056ifeq ($(filter %-softmmu, $(TARGET)),)
Richard Henderson57dbce52023-01-24 18:01:08 +000057run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2 > $1.out, \
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +010058 TEST,$(or $3, $*, $<) on $(TARGET_NAME))
Alex Bennéefdfda702019-03-12 14:13:16 +000059else
Richard Henderson57dbce52023-01-24 18:01:08 +000060run-test = $(call quiet-command, timeout -s KILL --foreground $(TIMEOUT) $2, \
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +010061 TEST,$(or $3, $*, $<) on $(TARGET_NAME))
Alex Bennéefdfda702019-03-12 14:13:16 +000062endif
Alex Bennée607bf9b2018-05-21 10:38:37 +010063
64# $1 = test name, $2 = reference
Alex Bennéeef860042019-07-05 12:56:35 +010065# 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), \
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +010069 DIFF,$1.out with $2)
Alex Bennée607bf9b2018-05-21 10:38:37 +010070
71# $1 = test name, $2 = reason
72skip-test = @printf " SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
73
Alex Bennéea4f3ed62019-09-13 12:12:17 +010074# $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
Alex Bennée7e970172018-04-06 13:32:18 +010083# Tests we are building
84TESTS=
Alex Bennée1852f3e2019-10-10 17:56:11 +010085# additional tests which may re-use existing binaries
86EXTRA_TESTS=
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +020087
Alex Bennée7e970172018-04-06 13:32:18 +010088# Start with a blank slate, the build targets get to add stuff first
89CFLAGS=
bellard4d1135e2003-02-24 20:14:06 +000090LDFLAGS=
91
Alex Bennéefdfda702019-03-12 14:13:16 +000092QEMU_OPTS=
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +020093
Alex Bennée3d55c022018-12-06 11:09:17 +000094
Richard Hendersone5b46542021-02-07 18:15:04 -080095# If TCG debugging, or TCI is enabled things are a lot slower
Richard Henderson909c4762021-12-30 13:54:01 -080096# ??? 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
Richard Hendersone5b46542021-02-07 18:15:04 -0800101TIMEOUT=90
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +0200102
Paolo Bonzini8e61ecc2022-04-19 10:10:09 +0100103ifeq ($(filter %-softmmu, $(TARGET)),)
Alex Bennée9a297fa2019-09-11 17:49:55 +0100104# 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.
Alex Bennée7e970172018-04-06 13:32:18 +0100109-include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
Alex Bennée7e970172018-04-06 13:32:18 +0100110-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
bellard367e86e2003-03-01 17:13:26 +0000111
Alex Bennée7e970172018-04-06 13:32:18 +0100112# Add the common build options
Alex Bennée2af43a62020-12-10 19:04:17 +0000113CFLAGS+=-Wall -Werror -O0 -g -fno-strict-aliasing
Alex Bennée7e970172018-04-06 13:32:18 +0100114ifeq ($(BUILD_STATIC),y)
115LDFLAGS+=-static
116endif
bellard4d1135e2003-02-24 20:14:06 +0000117
Alex Bennée7e970172018-04-06 13:32:18 +0100118%: %.c
119 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
Richard Hendersonec2918b2022-12-03 11:57:44 -0600120%: %.S
121 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
Alex Bennéebd15e6e2018-11-29 22:19:21 +0000122else
123# For softmmu targets we include a different Makefile fragement as the
124# build options for bare programs are usually pretty different. They
125# are expected to provide their own build recipes.
Paolo Bonzinibb52a8a2022-06-22 11:06:27 +0200126EXTRA_CFLAGS += -ffreestanding
Alex Bennéea113ec92019-03-05 11:40:31 +0000127-include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
Alex Bennée80416502019-04-29 15:38:44 +0100128-include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
Alex Bennéebd15e6e2018-11-29 22:19:21 +0000129-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
Alex Bennéebd15e6e2018-11-29 22:19:21 +0000130
131endif
bellard4d1135e2003-02-24 20:14:06 +0000132
Alex Bennée1852f3e2019-10-10 17:56:11 +0100133all: $(TESTS) $(EXTRA_TESTS)
Alex Bennée7e970172018-04-06 13:32:18 +0100134
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))
Alex Bennée3089e742019-05-17 17:09:48 +0100145
146# If plugins exist also include those in the tests
147ifeq ($(CONFIG_PLUGIN),y)
Alex Bennéefefa0272020-06-15 15:19:21 +0100148PLUGIN_SRC=$(SRC_PATH)/tests/plugin
149PLUGIN_LIB=../../plugin
150VPATH+=$(PLUGIN_LIB)
Alex Bennéec17a3862020-09-09 12:27:41 +0100151PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
Alex Bennée3089e742019-05-17 17:09:48 +0100152
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# also add some special helpers the run-plugin- rules can use bellow.
156
157$(foreach p,$(PLUGINS), \
158 $(foreach t,$(TESTS),\
159 $(eval run-plugin-$(t)-with-$(p): $t $p) \
Alex Bennée3089e742019-05-17 17:09:48 +0100160 $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p))))
161endif
162
163strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1))
164extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1))
165
Alex Bennée7e970172018-04-06 13:32:18 +0100166RUN_TESTS+=$(EXTRA_RUNS)
bellard4d1135e2003-02-24 20:14:06 +0000167
Paolo Bonzini8e61ecc2022-04-19 10:10:09 +0100168ifeq ($(filter %-softmmu, $(TARGET)),)
Paolo Bonzini2b2e59e2010-10-21 10:18:40 +0200169run-%: %
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +0100170 $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<)
Alex Bennée3089e742019-05-17 17:09:48 +0100171
172run-plugin-%:
173 $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
Alex Bennéefefa0272020-06-15 15:19:21 +0100174 -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
Alex Bennée3089e742019-05-17 17:09:48 +0100175 -d plugin -D $*.pout \
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +0100176 $(call strip-plugin,$<))
Alex Bennéefdfda702019-03-12 14:13:16 +0000177else
178run-%: %
179 $(call run-test, $<, \
180 $(QEMU) -monitor none -display none \
181 -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +0100182 $(QEMU_OPTS) $<)
Alex Bennée3089e742019-05-17 17:09:48 +0100183
184run-plugin-%:
185 $(call run-test, $@, \
186 $(QEMU) -monitor none -display none \
187 -chardev file$(COMMA)path=$@.out$(COMMA)id=output \
Alex Bennéefefa0272020-06-15 15:19:21 +0100188 -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
Alex Bennée3089e742019-05-17 17:09:48 +0100189 -d plugin -D $*.pout \
Paolo Bonzinic6cf8a22022-09-29 12:42:03 +0100190 $(QEMU_OPTS) $(call strip-plugin,$<))
Alex Bennéefdfda702019-03-12 14:13:16 +0000191endif
bellard1b6b0292003-03-22 17:31:38 +0000192
Alex Bennéed0ce6252019-02-27 15:42:18 +0000193gdb-%: %
194 gdb --args $(QEMU) $(QEMU_OPTS) $<
195
Alex Bennée7e970172018-04-06 13:32:18 +0100196.PHONY: run
197run: $(RUN_TESTS)
bellard7fb9a242003-04-11 00:13:04 +0000198
Paolo Bonzinieebf1992022-04-19 10:10:12 +0100199clean:
Paul Brook91117bc2022-04-24 23:02:03 +0100200 rm -f $(TESTS) *.o $(CLEANFILES)
Paolo Bonzini6ffe8132022-09-29 12:42:01 +0100201
202distclean:
Paolo Bonzini15b273f2022-09-29 12:42:04 +0100203 rm -f config-cc.mak config-target.mak ../config-$(TARGET).mak