tests.mk 11.6 KB
Newer Older
G
Graydon Hoare 已提交
1 2 3 4 5 6 7 8
######################################################################
# Testing variables
######################################################################

ALL_TEST_INPUTS = $(wildcard $(S)src/test/*/*.rs   \
                              $(S)src/test/*/*/*.rs \
                              $(S)src/test/*/*.rc)

9
RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
B
Brian Anderson 已提交
10
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
11 12 13 14
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
15 16
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
G
Graydon Hoare 已提交
17

18 19 20 21
# perf tests are the same as bench tests only they run under
# a performance monitor.
PERF_RS := $(wildcard $(S)src/test/bench/*.rs)

B
Brian Anderson 已提交
22 23 24
RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
25
BENCH_TESTS := $(BENCH_RS)
26
PERF_TESTS := $(PERF_RS)
27
PRETTY_TESTS := $(PRETTY_RS)
G
Graydon Hoare 已提交
28

29 30 31 32 33
FT := run_pass_stage2
FT_LIB := $(call CFG_LIB_NAME,$(FT))
FT_DRIVER := $(FT)_driver
GENERATED += test/$(FT).rc test/$(FT_DRIVER).rs

B
Brian Anderson 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46
# The arguments to all test runners
ifdef TESTNAME
  TESTARGS += $(TESTNAME)
endif

ifdef CHECK_XFAILS
  TESTARGS += --ignored
endif

# Arguments to the cfail/rfail/rpass/bench tests
ifdef CFG_VALGRIND
  CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
endif
47

48 49 50 51 52
# Arguments to the perf tests
ifdef CFG_PERF_TOOL
  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
endif

B
Brian Anderson 已提交
53
CTEST_TESTARGS := $(TESTARGS)
G
Graydon Hoare 已提交
54

B
Brian Anderson 已提交
55 56 57
ifdef VERBOSE
  CTEST_TESTARGS += --verbose
endif
58

B
Brian Anderson 已提交
59 60 61
# The standard library test crate
STDTEST_CRATE := $(S)src/test/stdtest/stdtest.rc
STDTEST_INPUTS := $(wildcard $(S)src/test/stdtest/*rs)
62

63 64 65 66
# Run the compiletest runner itself under valgrind
ifdef CTEST_VALGRIND
  CFG_RUN_CTEST=$(call CFG_RUN_TEST,$(2))
else
67
  CFG_RUN_CTEST=$(call CFG_RUN,$(TARGET_HOST_LIB$(1)),$(2))
68
endif
69

B
Brian Anderson 已提交
70 71 72 73 74
######################################################################
# Main test targets
######################################################################

check: tidy check-stage2 \
75

B
Brian Anderson 已提交
76
check-full: tidy check-stage1 check-stage2 check-stage3 \
77

78
check-fast: tidy \
B
Brian Anderson 已提交
79
	check-stage2-rustc check-stage2-std \
N
Niko Matsakis 已提交
80
	test/$(FT_DRIVER).out
81

82
# Run the tidy script in multiple parts to avoid huge 'echo' commands
B
Brian Anderson 已提交
83 84 85 86
tidy:
	@$(call E, check: formatting)
	$(Q)echo \
	    $(addprefix $(S)src/, $(RUSTLLVM_LIB_CS) $(RUSTLLVM_OBJS_CS) \
87
	      $(RUSTLLVM_HDR) \
B
Brian Anderson 已提交
88
              $(RUNTIME_CS) $(RUNTIME_HDR) $(RUNTIME_S)) \
89
            $(wildcard $(S)src/etc/*.py)  \
B
Brian Anderson 已提交
90 91 92 93 94 95
            $(COMPILER_CRATE) \
            $(COMPILER_INPUTS) \
            $(STDLIB_CRATE) \
            $(STDLIB_INPUTS) \
            $(COMPILETEST_CRATE) \
            $(COMPILETEST_INPUTS) \
96 97
	  | xargs -n 10 python $(S)src/etc/tidy.py
	$(Q)echo \
98
            $(ALL_TEST_INPUTS) \
B
Brian Anderson 已提交
99
	  | xargs -n 10 python $(S)src/etc/tidy.py
G
Graydon Hoare 已提交
100

101 102

######################################################################
B
Brian Anderson 已提交
103
# Rules for the test runners
104 105
######################################################################

B
Brian Anderson 已提交
106
define TEST_STAGEN
107

B
Brian Anderson 已提交
108
# All the per-stage build rules you might want to call from the
109 110 111 112
# command line.
#
# $(1) is the stage number
# $(2) is the target triple
113

114 115 116 117 118 119 120 121
check-stage$(1)-$(2): tidy \
	check-stage$(1)-$(2)-rustc \
	check-stage$(1)-$(2)-std \
	check-stage$(1)-$(2)-rpass \
	check-stage$(1)-$(2)-rfail \
	check-stage$(1)-$(2)-cfail \
	check-stage$(1)-$(2)-bench \
	check-stage$(1)-$(2)-pretty
122

123
check-stage$(1)-$(2)-std: check-stage$(1)-$(2)-std-dummy
124

125
check-stage$(1)-$(2)-rustc: check-stage$(1)-$(2)-rustc-dummy
126

127
check-stage$(1)-$(2)-cfail: check-stage$(1)-$(2)-cfail-dummy
G
Graydon Hoare 已提交
128

129
check-stage$(1)-$(2)-rfail: check-stage$(1)-$(2)-rfail-dummy
130

131
check-stage$(1)-$(2)-rpass: check-stage$(1)-$(2)-rpass-dummy
132

133
check-stage$(1)-$(2)-bench: check-stage$(1)-$(2)-bench-dummy
134

135
check-stage$(1)-$(2)-perf: check-stage$(1)-$(2)-perf-dummy
136

137 138 139 140
check-stage$(1)-$(2)-pretty: check-stage$(1)-$(2)-pretty-rpass \
                        check-stage$(1)-$(2)-pretty-rfail \
                        check-stage$(1)-$(2)-pretty-bench \
                        check-stage$(1)-$(2)-pretty-pretty
G
Graydon Hoare 已提交
141

142
check-stage$(1)-$(2)-pretty-rpass: check-stage$(1)-$(2)-pretty-rpass-dummy
G
Graydon Hoare 已提交
143

144
check-stage$(1)-$(2)-pretty-rfail: check-stage$(1)-$(2)-pretty-rfail-dummy
G
Graydon Hoare 已提交
145

146
check-stage$(1)-$(2)-pretty-bench: check-stage$(1)-$(2)-pretty-bench-dummy
G
Graydon Hoare 已提交
147

148
check-stage$(1)-$(2)-pretty-pretty: check-stage$(1)-$(2)-pretty-pretty-dummy
G
Graydon Hoare 已提交
149

150

B
Brian Anderson 已提交
151
# Rules for the standard library test runner
152

153
test/stdtest.stage$(1)-$(2)$$(X): $$(STDTEST_CRATE) $$(STDTEST_INPUTS) \
B
Brian Anderson 已提交
154 155
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE))
	@$$(call E, compile_and_link: $$@)
156
	$$(STAGE$(1)_$(2)) -o $$@ $$< --test
157

158
check-stage$(1)-$(2)-std-dummy: test/stdtest.stage$(1)-$(2)$$(X)
B
Brian Anderson 已提交
159 160
	@$$(call E, run: $$<)
	$$(Q)$$(call CFG_RUN_TEST,$$<) $$(TESTARGS)
161

162

B
Brian Anderson 已提交
163
# Rules for the rustc test runner
164

165
test/rustctest.stage$(1)-$(2)$$(X): \
B
Brian Anderson 已提交
166
	$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
167
	$$(TARGET_SREQ$(1)$$(CFG_HOST_TRIPLE)) \
168 169 170
    $$(HOST_LIB$(1))/$$(CFG_RUSTLLVM) \
	$$(TARGET_LIB$(1)$(2))/$$(CFG_RUSTLLVM) \
	$$(TARGET_LIB$(1)$(2))/$$(CFG_STDLIB)
B
Brian Anderson 已提交
171
	@$$(call E, compile_and_link: $$@)
172
	$$(STAGE$(1)_$(2)) -o $$@ $$< --test
173

174
check-stage$(1)-$(2)-rustc-dummy: test/rustctest.stage$(1)-$(2)$$(X)
B
Brian Anderson 已提交
175
	@$$(call E, run: $$<)
176
	$$(Q)$$(call CFG_RUN_TEST,$$<) \
B
Brian Anderson 已提交
177
	  $$(TESTARGS)
178

179

B
Brian Anderson 已提交
180
# Rules for the cfail/rfail/rpass/bench/perf test runner
181

182
CTEST_COMMON_ARGS$(1)-$(2) := --compile-lib-path $$(HOST_LIB$(1)) \
B
Brian Anderson 已提交
183 184
                         --run-lib-path $$(TARGET_LIB$(1)$$(CFG_HOST_TRIPLE)) \
                         --rustc-path $$(HOST_BIN$(1))/rustc$$(X) \
185 186
                         --stage-id stage$(1)-$(2) \
                         --rustcflags "$$(CFG_RUSTC_FLAGS) --target=$(2)" \
187
                         $$(CTEST_TESTARGS)
188

189
CFAIL_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
B
Brian Anderson 已提交
190 191
                  --src-base $$(S)src/test/compile-fail/ \
                  --build-base test/compile-fail/ \
192
                  --mode compile-fail
193

194
RFAIL_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
B
Brian Anderson 已提交
195 196 197
                  --src-base $$(S)src/test/run-fail/ \
                  --build-base test/run-fail/ \
                  --mode run-fail \
198
                  $$(CTEST_RUNTOOL)
199

200
RPASS_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
201
                  --src-base $$(S)src/test/run-pass/ \
B
Brian Anderson 已提交
202 203
                  --build-base test/run-pass/ \
                  --mode run-pass \
204
                  $$(CTEST_RUNTOOL)
205

206
BENCH_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
207
                  --src-base $$(S)src/test/bench/ \
B
Brian Anderson 已提交
208 209
                  --build-base test/bench/ \
                  --mode run-pass \
210
                  $$(CTEST_RUNTOOL)
211

212
PERF_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
213
                  --src-base $$(S)src/test/bench/ \
214 215
                  --build-base test/perf/ \
                  --mode run-pass \
216
                  $$(CTEST_PERF_RUNTOOL)
217

218
PRETTY_RPASS_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
219 220
                         --src-base $$(S)src/test/run-pass/ \
                         --build-base test/run-pass/ \
221
                         --mode pretty
222

223
PRETTY_RFAIL_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
224 225
                         --src-base $$(S)src/test/run-fail/ \
                         --build-base test/run-fail/ \
226
                         --mode pretty
227

228
PRETTY_BENCH_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
229 230
                         --src-base $$(S)src/test/bench/ \
                         --build-base test/bench/ \
231
                         --mode pretty
232

233
PRETTY_PRETTY_ARGS$(1)-$(2) := $$(CTEST_COMMON_ARGS$(1)-$(2)) \
234 235
                          --src-base $$(S)src/test/pretty/ \
                          --build-base test/pretty/ \
236
                          --mode pretty
237

238
check-stage$(1)-$(2)-cfail-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
239
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
B
Brian Anderson 已提交
240 241
                                   $$(CFAIL_TESTS)
	@$$(call E, run: $$<)
242
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(CFAIL_ARGS$(1)-$(2))
243

244
check-stage$(1)-$(2)-rfail-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
245
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
B
Brian Anderson 已提交
246 247
                               $$(RFAIL_TESTS)
	@$$(call E, run: $$<)
248
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(RFAIL_ARGS$(1)-$(2))
B
Brian Anderson 已提交
249

250
check-stage$(1)-$(2)-rpass-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
251
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
B
Brian Anderson 已提交
252 253
                               $$(RPASS_TESTS)
	@$$(call E, run: $$<)
254
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(RPASS_ARGS$(1)-$(2))
B
Brian Anderson 已提交
255

256
check-stage$(1)-$(2)-bench-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
257
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
B
Brian Anderson 已提交
258 259
                            $$(BENCH_TESTS)
	@$$(call E, run: $$<)
260
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(BENCH_ARGS$(1)-$(2))
261

262
check-stage$(1)-$(2)-perf-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
263
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
264 265
                            $$(BENCH_TESTS)
	@$$(call E, perf: $$<)
266
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(PERF_ARGS$(1)-$(2))
267

268
check-stage$(1)-$(2)-pretty-rpass-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
269
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
270 271
                                     $$(RPASS_TESTS)
	@$$(call E, run: $$<)
272
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(PRETTY_RPASS_ARGS$(1)-$(2))
273

274
check-stage$(1)-$(2)-pretty-rfail-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
275
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
276
                                     $$(RFAIL_TESTS)
277
	@$$(call E, run: $$<)
278
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(PRETTY_RFAIL_ARGS$(1)-$(2))
279

280
check-stage$(1)-$(2)-pretty-bench-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
281
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
282 283
                                     $$(BENCH_TESTS)
	@$$(call E, run: $$<)
284
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(PRETTY_BENCH_ARGS$(1)-$(2))
285

286
check-stage$(1)-$(2)-pretty-pretty-dummy: $$(HOST_BIN$(1))/compiletest$$(X) \
B
Brian Anderson 已提交
287
                             $$(SREQ$(1)$$(CFG_HOST_TRIPLE)) \
288 289
                                     $$(PRETTY_TESTS)
	@$$(call E, run: $$<)
290
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<) $$(PRETTY_PRETTY_ARGS$(1)-$(2))
291

B
Brian Anderson 已提交
292
endef
293

294
# Instantiate the template for stage 0, 1, 2, 3
295

296 297 298 299 300
$(foreach target,$(CFG_TARGET_TRIPLES), \
 $(eval $(call TEST_STAGEN,0,$(target))) \
 $(eval $(call TEST_STAGEN,1,$(target))) \
 $(eval $(call TEST_STAGEN,2,$(target))) \
 $(eval $(call TEST_STAGEN,3,$(target))))
B
Brian Anderson 已提交
301

302 303 304 305 306 307 308 309 310
# Make convenient Shorthand Targets for use on command
# line or by other rules:
check-stage0:        check-stage0-$(CFG_HOST_TRIPLE)
check-stage1:        check-stage1-$(CFG_HOST_TRIPLE)
check-stage2:        check-stage2-$(CFG_HOST_TRIPLE)
check-stage2-perf:   check-stage2-$(CFG_HOST_TRIPLE)-perf
check-stage2-rustc:  check-stage2-$(CFG_HOST_TRIPLE)-rustc
check-stage2-std:    check-stage2-$(CFG_HOST_TRIPLE)-std
check-stage3:        check-stage3-$(CFG_HOST_TRIPLE)
B
Brian Anderson 已提交
311 312 313 314 315 316 317 318 319 320

######################################################################
# Fast-test rules
######################################################################

test/$(FT).rc test/$(FT_DRIVER).rs: $(TEST_RPASS_SOURCES_STAGE2) \
    $(S)src/etc/combine-tests.py
	@$(call E, check: building combined stage2 test runner)
	$(Q)$(S)src/etc/combine-tests.py

321
$(TARGET_HOST_LIB2)/$(FT_LIB): test/$(FT).rc $(SREQ2$(CFG_HOST_TRIPLE))
B
Brian Anderson 已提交
322
	@$(call E, compile_and_link: $@)
N
Niko Matsakis 已提交
323
	$(STAGE2_$(CFG_HOST_TRIPLE)) --lib -o $@ $<
B
Brian Anderson 已提交
324

325 326
test/$(FT_DRIVER)$(X): test/$(FT_DRIVER).rs $(TARGET_HOST_LIB2)/$(FT_LIB) \
	$(SREQ2$(CFG_HOST_TRIPLE))
B
Brian Anderson 已提交
327
	@$(call E, compile_and_link: $@)
N
Niko Matsakis 已提交
328
	$(STAGE2_$(CFG_HOST_TRIPLE)) -L $(HOST_LIB2) -o $@ $<
B
Brian Anderson 已提交
329

330
test/$(FT_DRIVER).out: test/$(FT_DRIVER)$(X) $(SREQ2$(CFG_HOST_TRIPLE))
331
	$(Q)$(call CFG_RUN_TEST, $<)