]>
Commit | Line | Data |
---|---|---|
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 | 32 | all: |
544f4a25 | 33 | -include ../config-host.mak |
a3e28f81 | 34 | -include config-target.mak |
36e38426 PB |
35 | |
36 | # Get semihosting definitions for user-mode emulation | |
8e61ecca | 37 | ifeq ($(filter %-softmmu, $(TARGET)),) |
36e38426 | 38 | -include $(SRC_PATH)/configs/targets/$(TARGET).mak |
3539d84d | 39 | endif |
076d2471 | 40 | |
fdfda70e AB |
41 | # for including , in command strings |
42 | COMMA := , | |
15b273f8 PB |
43 | NULL := |
44 | SPACE := $(NULL) # | |
45 | TARGET_PREFIX=tests/tcg/$(TARGET):$(SPACE) | |
fdfda70e | 46 | |
c6cf8a20 PB |
47 | quiet-@ = $(if $(V),,@$(if $1,printf " %-7s %s\n" "$(strip $1)" "$(strip $2)" && )) |
48 | quiet-command = $(call quiet-@,$2,$3)$1 | |
7d13299d | 49 | |
15b273f8 PB |
50 | cc-test = $(CC) -Werror $1 -c -o /dev/null -xc /dev/null >/dev/null 2>&1 |
51 | cc-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 | 56 | ifeq ($(filter %-softmmu, $(TARGET)),) |
9ab10ba3 | 57 | run-test = $(call quiet-command, timeout --foreground $(TIMEOUT) $2 > $1.out, \ |
c6cf8a20 | 58 | TEST,$(or $3, $*, $<) on $(TARGET_NAME)) |
fdfda70e | 59 | else |
c6cf8a20 PB |
60 | run-test = $(call quiet-command, timeout --foreground $(TIMEOUT) $2, \ |
61 | TEST,$(or $3, $*, $<) on $(TARGET_NAME)) | |
fdfda70e | 62 | endif |
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. | |
67 | diff-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 | |
72 | skip-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 | |
77 | conditional-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 |
84 | TESTS= | |
1852f3e4 AB |
85 | # additional tests which may re-use existing binaries |
86 | EXTRA_TESTS= | |
2b2e59e6 | 87 | |
7e97017e AB |
88 | # Start with a blank slate, the build targets get to add stuff first |
89 | CFLAGS= | |
4d1135e4 FB |
90 | LDFLAGS= |
91 | ||
fdfda70e | 92 | QEMU_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 | 101 | TIMEOUT=90 |
2b2e59e6 | 102 | |
8e61ecca | 103 | ifeq ($(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 | 113 | CFLAGS+=-Wall -Werror -O0 -g -fno-strict-aliasing |
7e97017e AB |
114 | ifeq ($(BUILD_STATIC),y) |
115 | LDFLAGS+=-static | |
116 | endif | |
394411ac | 117 | |
7e97017e AB |
118 | %: %.c |
119 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) | |
bd15e6e0 AB |
120 | else |
121 | # For softmmu targets we include a different Makefile fragement as the | |
122 | # build options for bare programs are usually pretty different. They | |
123 | # are expected to provide their own build recipes. | |
bb52a8a2 | 124 | EXTRA_CFLAGS += -ffreestanding |
a113ec98 | 125 | -include $(SRC_PATH)/tests/tcg/minilib/Makefile.target |
8041650a | 126 | -include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target |
bd15e6e0 | 127 | -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target |
bd15e6e0 AB |
128 | |
129 | endif | |
394411ac | 130 | |
1852f3e4 | 131 | all: $(TESTS) $(EXTRA_TESTS) |
18c9b560 | 132 | |
7e97017e AB |
133 | # |
134 | # Test Runners | |
135 | # | |
136 | # By default we just run the test with the appropriate QEMU for the | |
137 | # target. More advanced tests may want to override the runner in their | |
138 | # specific make rules. Additional runners for the same binary should | |
139 | # be added to EXTRA_RUNS. | |
140 | # | |
e4630047 | 141 | |
7e97017e | 142 | RUN_TESTS=$(patsubst %,run-%, $(TESTS)) |
3089e74e AB |
143 | |
144 | # If plugins exist also include those in the tests | |
145 | ifeq ($(CONFIG_PLUGIN),y) | |
fefa0271 AB |
146 | PLUGIN_SRC=$(SRC_PATH)/tests/plugin |
147 | PLUGIN_LIB=../../plugin | |
148 | VPATH+=$(PLUGIN_LIB) | |
c17a386b | 149 | PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c))) |
3089e74e AB |
150 | |
151 | # We need to ensure expand the run-plugin-TEST-with-PLUGIN | |
152 | # pre-requistes manually here as we can't use stems to handle it. We | |
153 | # also add some special helpers the run-plugin- rules can use bellow. | |
154 | ||
155 | $(foreach p,$(PLUGINS), \ | |
156 | $(foreach t,$(TESTS),\ | |
157 | $(eval run-plugin-$(t)-with-$(p): $t $p) \ | |
3089e74e AB |
158 | $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p)))) |
159 | endif | |
160 | ||
161 | strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1)) | |
162 | extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1)) | |
163 | ||
7e97017e | 164 | RUN_TESTS+=$(EXTRA_RUNS) |
e4630047 | 165 | |
8e61ecca | 166 | ifeq ($(filter %-softmmu, $(TARGET)),) |
7e97017e | 167 | run-%: % |
c6cf8a20 | 168 | $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<) |
3089e74e AB |
169 | |
170 | run-plugin-%: | |
171 | $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \ | |
fefa0271 | 172 | -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \ |
3089e74e | 173 | -d plugin -D $*.pout \ |
c6cf8a20 | 174 | $(call strip-plugin,$<)) |
fdfda70e AB |
175 | else |
176 | run-%: % | |
177 | $(call run-test, $<, \ | |
178 | $(QEMU) -monitor none -display none \ | |
179 | -chardev file$(COMMA)path=$<.out$(COMMA)id=output \ | |
c6cf8a20 | 180 | $(QEMU_OPTS) $<) |
3089e74e AB |
181 | |
182 | run-plugin-%: | |
183 | $(call run-test, $@, \ | |
184 | $(QEMU) -monitor none -display none \ | |
185 | -chardev file$(COMMA)path=$@.out$(COMMA)id=output \ | |
fefa0271 | 186 | -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \ |
3089e74e | 187 | -d plugin -D $*.pout \ |
c6cf8a20 | 188 | $(QEMU_OPTS) $(call strip-plugin,$<)) |
fdfda70e | 189 | endif |
e7daa605 | 190 | |
d0ce6257 AB |
191 | gdb-%: % |
192 | gdb --args $(QEMU) $(QEMU_OPTS) $< | |
193 | ||
7e97017e AB |
194 | .PHONY: run |
195 | run: $(RUN_TESTS) | |
d65f0831 | 196 | |
eebf199c | 197 | clean: |
91117bc5 | 198 | rm -f $(TESTS) *.o $(CLEANFILES) |
6ffe8137 PB |
199 | |
200 | distclean: | |
15b273f8 | 201 | rm -f config-cc.mak config-target.mak ../config-$(TARGET).mak |