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