]> git.lizzy.rs Git - rust.git/blob - mk/tests.mk
Warn if the test suite is run on Windows in console with non-UTF-8 code page
[rust.git] / mk / tests.mk
1 # Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11
12 ######################################################################
13 # Test variables
14 ######################################################################
15
16 # The names of crates that must be tested
17
18 # libcore/librustc_unicode tests are in a separate crate
19 DEPS_coretest :=
20 $(eval $(call RUST_CRATE,coretest))
21
22 DEPS_collectionstest :=
23 $(eval $(call RUST_CRATE,collectionstest))
24
25 TEST_TARGET_CRATES = $(filter-out core rustc_unicode,$(TARGET_CRATES)) \
26                         collectionstest coretest
27 TEST_DOC_CRATES = $(DOC_CRATES)
28 TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \
29                                 rustc_trans rustc_lint,\
30                      $(HOST_CRATES))
31 TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
32
33 ######################################################################
34 # Environment configuration
35 ######################################################################
36
37 # The arguments to all test runners
38 ifdef TESTNAME
39   TESTARGS += $(TESTNAME)
40 endif
41
42 ifdef CHECK_IGNORED
43   TESTARGS += --ignored
44 endif
45
46 # Arguments to the cfail/rfail/rpass/bench tests
47 ifdef CFG_VALGRIND
48   CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
49 endif
50
51 # Arguments to the perf tests
52 ifdef CFG_PERF_TOOL
53   CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
54 endif
55
56 CTEST_TESTARGS := $(TESTARGS)
57
58 # --bench is only relevant for crate tests, not for the compile tests
59 ifdef PLEASE_BENCH
60   TESTARGS += --bench
61 endif
62
63 ifdef VERBOSE
64   CTEST_TESTARGS += --verbose
65 endif
66
67 # Setting locale ensures that gdb's output remains consistent.
68 # This prevents tests from failing with some locales (fixes #17423).
69 export LC_ALL=C
70
71 # If we're running perf then set this environment variable
72 # to put the benchmarks into 'hard mode'
73 ifeq ($(MAKECMDGOALS),perf)
74   export RUST_BENCH=1
75 endif
76
77 TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
78 TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
79
80 define DEF_TARGET_COMMANDS
81
82 ifdef CFG_UNIXY_$(1)
83   CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
84           $$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
85 endif
86
87 ifdef CFG_WINDOWSY_$(1)
88   CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
89    $$(if $$(findstring stage0,$$(1)), \
90        stage0/$$(CFG_LIBDIR_RELATIVE), \
91       $$(if $$(findstring stage1,$$(1)), \
92            stage1/$$(CFG_LIBDIR_RELATIVE), \
93           $$(if $$(findstring stage2,$$(1)), \
94                stage2/$$(CFG_LIBDIR_RELATIVE), \
95                $$(if $$(findstring stage3,$$(1)), \
96                     stage3/$$(CFG_LIBDIR_RELATIVE), \
97                )))))/rustlib/$$(CFG_BUILD)/lib
98   CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(4)),$$(1))
99 endif
100
101 # Run the compiletest runner itself under valgrind
102 ifdef CTEST_VALGRIND
103 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
104       $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(3),$$(4))
105 else
106 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
107       $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
108 endif
109
110 endef
111
112 $(foreach target,$(CFG_TARGET), \
113   $(eval $(call DEF_TARGET_COMMANDS,$(target))))
114
115 # Target platform specific variables for android
116 define DEF_ADB_DEVICE_STATUS
117 CFG_ADB_DEVICE_STATUS=$(1)
118 endef
119
120 $(foreach target,$(CFG_TARGET), \
121   $(if $(findstring android, $(target)), \
122     $(if $(findstring adb,$(CFG_ADB)), \
123       $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
124         $(info check: android device attached) \
125         $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
126         $(info check: android device not attached) \
127         $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
128       ), \
129       $(info check: adb not found) \
130       $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
131     ), \
132   ) \
133 )
134
135 ifeq ($(CFG_ADB_DEVICE_STATUS),true)
136 CFG_ADB_TEST_DIR=/data/tmp
137
138 $(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
139  $(shell $(CFG_ADB) remount 1>/dev/null) \
140  $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
141  $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
142  $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
143  $(foreach target,$(CFG_TARGET), \
144   $(if $(findstring android, $(target)), \
145    $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/$(target)) \
146    $(foreach crate,$(TARGET_CRATES), \
147     $(shell $(CFG_ADB) push $(TLIB2_T_$(target)_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_$(target),$(crate)) \
148                     $(CFG_ADB_TEST_DIR)/$(target))), \
149  )))
150 else
151 CFG_ADB_TEST_DIR=
152 endif
153
154 # $(1) - name of doc test
155 # $(2) - file of the test
156 define DOCTEST
157 DOC_NAMES := $$(DOC_NAMES) $(1)
158 DOCFILE_$(1) := $(2)
159 endef
160
161 $(foreach doc,$(DOCS), \
162   $(eval $(call DOCTEST,md-$(doc),$(S)src/doc/$(doc).md)))
163 $(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \
164   $(eval $(call DOCTEST,$(file:$(S)src/doc/trpl/%.md=trpl-%),$(file))))
165
166 ######################################################################
167 # Main test targets
168 ######################################################################
169
170 # The main testing target. Tests lots of stuff.
171 check: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2 tidy
172         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
173
174 # As above but don't bother running tidy.
175 check-notidy: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2
176         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
177
178 # A slightly smaller set of tests for smoke testing.
179 check-lite: check-sanitycheck cleantestlibs cleantmptestlogs \
180         $(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
181         check-stage2-rpass check-stage2-rpass-valgrind \
182         check-stage2-rfail check-stage2-cfail check-stage2-pfail check-stage2-rmake
183         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
184
185 # Only check the 'reference' tests: rpass/cfail/rfail/rmake.
186 check-ref: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-rpass \
187         check-stage2-rpass-valgrind check-stage2-rfail check-stage2-cfail check-stage2-pfail \
188         check-stage2-rmake
189         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
190
191 # Only check the docs.
192 check-docs: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-docs
193         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
194
195 # Some less critical tests that are not prone to breakage.
196 # Not run as part of the normal test suite, but tested by bors on checkin.
197 check-secondary: check-build-compiletest check-build-lexer-verifier check-lexer check-pretty
198
199 .PHONY: check-sanitycheck
200
201 check-sanitycheck:
202         $(Q)$(CFG_PYTHON) $(S)src/etc/check-sanitycheck.py
203
204 # check + check-secondary.
205 #
206 # Issue #17883: build check-secondary first so hidden dependencies in
207 # e.g. building compiletest are exercised (resolve those by adding
208 # deps to rules that need them; not by putting `check` first here).
209 check-all: check-secondary check
210
211 # Pretty-printing tests.
212 check-pretty: check-stage2-T-$(CFG_BUILD)-H-$(CFG_BUILD)-pretty-exec
213
214 define DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE
215 check-stage$(1)-build-compiletest:      $$(HBIN$(1)_H_$(CFG_BUILD))/compiletest$$(X_$(CFG_BUILD))
216 endef
217
218 $(foreach stage,$(STAGES), \
219  $(eval $(call DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE,$(stage))))
220
221 check-build-compiletest: \
222         check-stage1-build-compiletest \
223         check-stage2-build-compiletest
224
225 .PHONY: cleantmptestlogs cleantestlibs
226
227 cleantmptestlogs:
228         $(Q)rm -f tmp/*.log
229
230 cleantestlibs:
231         $(Q)find $(CFG_BUILD)/test \
232          -name '*.[odasS]' -o \
233          -name '*.so' -o \
234          -name '*.dylib' -o \
235          -name '*.dll' -o \
236          -name '*.def' -o \
237          -name '*.bc' -o \
238          -name '*.dSYM' -o \
239          -name '*.libaux' -o \
240          -name '*.out' -o \
241          -name '*.err' -o \
242          -name '*.debugger.script' \
243          | xargs rm -rf
244
245
246 ######################################################################
247 # Tidy
248 ######################################################################
249
250 ifdef CFG_NOTIDY
251 .PHONY: tidy
252 tidy:
253 else
254
255 # Run the tidy script in multiple parts to avoid huge 'echo' commands
256 .PHONY: tidy
257 tidy: tidy-basic tidy-binaries tidy-errors tidy-features
258
259 endif
260
261 .PHONY: tidy-basic
262 tidy-basic:
263                 @$(call E, check: formatting)
264                 $(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
265
266 .PHONY: tidy-binaries
267 tidy-binaries:
268                 @$(call E, check: binaries)
269                 $(Q)find $(S)src -type f -perm +a+x \
270                     -not -name '*.rs' -and -not -name '*.py' \
271                     -and -not -name '*.sh' \
272                 | grep '^$(S)src/jemalloc' -v \
273                 | grep '^$(S)src/libuv' -v \
274                 | grep '^$(S)src/llvm' -v \
275                 | grep '^$(S)src/rt/hoedown' -v \
276                 | grep '^$(S)src/gyp' -v \
277                 | grep '^$(S)src/etc' -v \
278                 | grep '^$(S)src/doc' -v \
279                 | grep '^$(S)src/compiler-rt' -v \
280                 | grep '^$(S)src/libbacktrace' -v \
281                 | grep '^$(S)src/rust-installer' -v \
282                 | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
283
284 .PHONY: tidy-errors
285 tidy-errors:
286                 @$(call E, check: extended errors)
287                 $(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
288
289 .PHONY: tidy-features
290 tidy-features:
291                 @$(call E, check: feature sanity)
292                 $(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
293
294
295 ######################################################################
296 # Sets of tests
297 ######################################################################
298
299 define DEF_TEST_SETS
300
301 check-stage$(1)-T-$(2)-H-$(3)-exec: \
302         check-stage$(1)-T-$(2)-H-$(3)-rpass-exec \
303         check-stage$(1)-T-$(2)-H-$(3)-rfail-exec \
304         check-stage$(1)-T-$(2)-H-$(3)-cfail-exec \
305         check-stage$(1)-T-$(2)-H-$(3)-pfail-exec \
306     check-stage$(1)-T-$(2)-H-$(3)-rpass-valgrind-exec \
307     check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
308     check-stage$(1)-T-$(2)-H-$(3)-rfail-full-exec \
309         check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
310         check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
311         check-stage$(1)-T-$(2)-H-$(3)-rustdocck-exec \
312         check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
313         check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
314         check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
315         check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
316         check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
317         check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
318         check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
319         check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
320
321 # Only test the compiler-dependent crates when the target is
322 # able to build a compiler (when the target triple is in the set of host triples)
323 ifneq ($$(findstring $(2),$$(CFG_HOST)),)
324
325 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
326         $$(foreach crate,$$(TEST_CRATES), \
327            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
328
329 else
330
331 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
332         $$(foreach crate,$$(TEST_TARGET_CRATES), \
333            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
334
335 endif
336
337 check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
338         $$(foreach crate,$$(TEST_DOC_CRATES), \
339            check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec)
340
341 check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
342         $$(foreach docname,$$(DOC_NAMES), \
343            check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec) \
344
345 check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
346         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
347     check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-valgrind-exec \
348         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec \
349         check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
350         check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-full-exec \
351         check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
352         check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
353
354 endef
355
356 $(foreach host,$(CFG_HOST), \
357  $(foreach target,$(CFG_TARGET), \
358   $(foreach stage,$(STAGES), \
359     $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))
360
361
362 ######################################################################
363 # Crate testing
364 ######################################################################
365
366 define TEST_RUNNER
367
368 # If NO_REBUILD is set then break the dependencies on everything but
369 # the source files so we can test crates without rebuilding any of the
370 # parent crates.
371 ifeq ($(NO_REBUILD),)
372 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
373                             $$(foreach crate,$$(TARGET_CRATES), \
374                                 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
375                                 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))
376
377 else
378 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
379 endif
380
381 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
382 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \
383                 $$(CRATEFILE_$(4)) \
384                 $$(TESTDEP_$(1)_$(2)_$(3)_$(4))
385         @$$(call E, rustc: $$@)
386         $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
387             $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \
388                 -L "$$(RT_OUTPUT_DIR_$(2))" \
389                 $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
390                 $$(RUSTFLAGS_$(4))
391
392 endef
393
394 $(foreach host,$(CFG_HOST), \
395  $(eval $(foreach target,$(CFG_TARGET), \
396   $(eval $(foreach stage,$(STAGES), \
397    $(eval $(foreach crate,$(TEST_CRATES), \
398     $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
399
400 define DEF_TEST_CRATE_RULES
401 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
402
403 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
404                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
405         @$$(call E, run: $$<)
406         $$(Q)touch $$@.start_time
407         $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
408             --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
409             $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
410             && touch -r $$@.start_time $$@ && rm $$@.start_time
411 endef
412
413 define DEF_TEST_CRATE_RULES_android
414 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
415
416 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
417                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
418         @$$(call E, run: $$< via adb)
419         $$(Q)touch $$@.start_time
420         $$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
421         $$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=./$(2) \
422                 ./$$(notdir $$<) \
423                 --logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
424                 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
425                 > tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
426         $$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
427         $$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
428         $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
429         $$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
430         @if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
431         then \
432                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
433                 touch -r $$@.start_time $$@ && rm $$@.start_time; \
434         else \
435                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
436                 exit 101; \
437         fi
438 endef
439
440 define DEF_TEST_CRATE_RULES_null
441 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
442
443 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
444                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
445         @$$(call E, failing: no device for $$< )
446         false
447 endef
448
449 $(foreach host,$(CFG_HOST), \
450  $(foreach target,$(CFG_TARGET), \
451   $(foreach stage,$(STAGES), \
452    $(foreach crate, $(TEST_CRATES), \
453     $(if $(findstring $(target),$(CFG_BUILD)), \
454      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
455      $(if $(findstring android, $(target)), \
456       $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
457        $(eval $(call DEF_TEST_CRATE_RULES_android,$(stage),$(target),$(host),$(crate))), \
458        $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
459       ), \
460       $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
461      ))))))
462
463 ######################################################################
464 # Rules for the compiletest tests (rpass, rfail, etc.)
465 ######################################################################
466
467 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
468 RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
469 RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
470 RFAIL_FULL_RS := $(wildcard $(S)src/test/run-fail-fulldeps/*.rs)
471 CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
472 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
473 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
474 PFAIL_RS := $(wildcard $(S)src/test/parse-fail/*.rs)
475 BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
476 PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
477 DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
478 DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
479 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
480 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
481 RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdoc/*.rs)
482
483 # perf tests are the same as bench tests only they run under
484 # a performance monitor.
485 PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
486
487 RPASS_TESTS := $(RPASS_RS)
488 RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
489 RPASS_FULL_TESTS := $(RPASS_FULL_RS)
490 RFAIL_FULL_TESTS := $(RFAIL_FULL_RS)
491 CFAIL_FULL_TESTS := $(CFAIL_FULL_RS)
492 RFAIL_TESTS := $(RFAIL_RS)
493 CFAIL_TESTS := $(CFAIL_RS)
494 PFAIL_TESTS := $(PFAIL_RS)
495 BENCH_TESTS := $(BENCH_RS)
496 PERF_TESTS := $(PERF_RS)
497 PRETTY_TESTS := $(PRETTY_RS)
498 DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
499 DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
500 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
501 RUSTDOCCK_TESTS := $(RUSTDOCCK_RS)
502
503 CTEST_SRC_BASE_rpass = run-pass
504 CTEST_BUILD_BASE_rpass = run-pass
505 CTEST_MODE_rpass = run-pass
506 CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
507
508 CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind
509 CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind
510 CTEST_MODE_rpass-valgrind = run-pass-valgrind
511 CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL)
512
513 CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
514 CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
515 CTEST_MODE_rpass-full = run-pass
516 CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
517
518 CTEST_SRC_BASE_rfail-full = run-fail-fulldeps
519 CTEST_BUILD_BASE_rfail-full = run-fail-fulldeps
520 CTEST_MODE_rfail-full = run-fail
521 CTEST_RUNTOOL_rfail-full = $(CTEST_RUNTOOL)
522
523 CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
524 CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
525 CTEST_MODE_cfail-full = compile-fail
526 CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)
527
528 CTEST_SRC_BASE_rfail = run-fail
529 CTEST_BUILD_BASE_rfail = run-fail
530 CTEST_MODE_rfail = run-fail
531 CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
532
533 CTEST_SRC_BASE_cfail = compile-fail
534 CTEST_BUILD_BASE_cfail = compile-fail
535 CTEST_MODE_cfail = compile-fail
536 CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
537
538 CTEST_SRC_BASE_pfail = parse-fail
539 CTEST_BUILD_BASE_pfail = parse-fail
540 CTEST_MODE_pfail = parse-fail
541 CTEST_RUNTOOL_pfail = $(CTEST_RUNTOOL)
542
543 CTEST_SRC_BASE_bench = bench
544 CTEST_BUILD_BASE_bench = bench
545 CTEST_MODE_bench = run-pass
546 CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
547
548 CTEST_SRC_BASE_perf = bench
549 CTEST_BUILD_BASE_perf = perf
550 CTEST_MODE_perf = run-pass
551 CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
552
553 CTEST_SRC_BASE_debuginfo-gdb = debuginfo
554 CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
555 CTEST_MODE_debuginfo-gdb = debuginfo-gdb
556 CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)
557
558 CTEST_SRC_BASE_debuginfo-lldb = debuginfo
559 CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
560 CTEST_MODE_debuginfo-lldb = debuginfo-lldb
561 CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
562
563 CTEST_SRC_BASE_codegen = codegen
564 CTEST_BUILD_BASE_codegen = codegen
565 CTEST_MODE_codegen = codegen
566 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
567
568 CTEST_SRC_BASE_rustdocck = rustdoc
569 CTEST_BUILD_BASE_rustdocck = rustdoc
570 CTEST_MODE_rustdocck = rustdoc
571 CTEST_RUNTOOL_rustdocck = $(CTEST_RUNTOOL)
572
573 # CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
574 # disabled and the associated message to be printed as a warning
575 # during attempts to run those tests.
576
577 ifeq ($(CFG_GDB),)
578 CTEST_DISABLE_debuginfo-gdb = "no gdb found"
579 endif
580
581 ifeq ($(CFG_LLDB),)
582 CTEST_DISABLE_debuginfo-lldb = "no lldb found"
583 endif
584
585 ifeq ($(CFG_CLANG),)
586 CTEST_DISABLE_codegen = "no clang found"
587 endif
588
589 ifneq ($(CFG_OSTYPE),apple-darwin)
590 CTEST_DISABLE_debuginfo-lldb = "lldb tests are only run on darwin"
591 endif
592
593 ifeq ($(CFG_OSTYPE),apple-darwin)
594 CTEST_DISABLE_debuginfo-gdb = "gdb on darwin needs root"
595 endif
596
597 ifeq ($(findstring android, $(CFG_TARGET)), android)
598 CTEST_DISABLE_debuginfo-gdb =
599 CTEST_DISABLE_debuginfo-lldb = "lldb tests are disabled on android"
600 endif
601
602 # CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
603 # test group to be disabled *unless* the target is able to build a
604 # compiler (i.e. when the target triple is in the set of of host
605 # triples).  The associated message will be printed as a warning
606 # during attempts to run those tests.
607
608 define DEF_CTEST_VARS
609
610 # All the per-stage build rules you might want to call from the
611 # command line.
612 #
613 # $(1) is the stage number
614 # $(2) is the target triple to test
615 # $(3) is the host triple to test
616
617 # Prerequisites for compiletest tests
618 TEST_SREQ$(1)_T_$(2)_H_$(3) = \
619         $$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
620         $$(SREQ$(1)_T_$(2)_H_$(3))
621
622 # Rules for the cfail/rfail/rpass/bench/perf test runner
623
624 # The tests select when to use debug configuration on their own;
625 # remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
626 CTEST_RUSTC_FLAGS := $$(subst -C debug-assertions,,$$(subst -C debug-assertions=on,,$$(CFG_RUSTC_FLAGS)))
627
628 # The tests cannot be optimized while the rest of the compiler is optimized, so
629 # filter out the optimization (if any) from rustc and then figure out if we need
630 # to be optimized
631 CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
632 ifndef CFG_DISABLE_OPTIMIZE_TESTS
633 CTEST_RUSTC_FLAGS += -O
634 endif
635
636 # Analogously to the above, whether to pass `-g` when compiling tests
637 # is a separate choice from whether to pass `-g` when building the
638 # compiler and standard library themselves.
639 CTEST_RUSTC_FLAGS := $$(subst -g,,$$(CTEST_RUSTC_FLAGS))
640 ifdef CFG_ENABLE_DEBUGINFO_TESTS
641 CTEST_RUSTC_FLAGS += -g
642 endif
643
644 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
645                 --compile-lib-path $$(HLIB$(1)_H_$(3)) \
646         --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
647         --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
648         --rustdoc-path $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
649         --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
650         --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
651         --aux-base $$(S)src/test/auxiliary/ \
652         --stage-id stage$(1)-$(2) \
653         --target $(2) \
654         --host $(3) \
655         --python $$(CFG_PYTHON) \
656         --gdb-version="$(CFG_GDB_VERSION)" \
657         --lldb-version="$(CFG_LLDB_VERSION)" \
658         --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
659         --adb-path=$(CFG_ADB) \
660         --adb-test-dir=$(CFG_ADB_TEST_DIR) \
661         --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
662         --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
663         --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
664         $$(CTEST_TESTARGS)
665
666 ifdef CFG_VALGRIND_RPASS
667 ifdef GOOD_VALGRIND_$(2)
668 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
669 endif
670 endif
671
672 ifndef CFG_DISABLE_VALGRIND_RPASS
673 ifdef GOOD_VALGRIND_$(2)
674 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --force-valgrind
675 endif
676 endif
677
678 CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
679 CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
680 CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
681 CTEST_DEPS_rfail-full_$(1)-T-$(2)-H-$(3) = $$(RFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
682 CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
683 CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
684 CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
685 CTEST_DEPS_pfail_$(1)-T-$(2)-H-$(3) = $$(PFAIL_TESTS)
686 CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
687 CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
688 CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
689 CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
690                                                $(S)src/etc/lldb_batchmode.py \
691                                                $(S)src/etc/lldb_rust_formatters.py
692 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
693 CTEST_DEPS_rustdocck_$(1)-T-$(2)-H-$(3) = $$(RUSTDOCCK_TESTS) \
694         $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
695         $(S)src/etc/htmldocck.py
696
697 endef
698
699 $(foreach host,$(CFG_HOST), \
700  $(eval $(foreach target,$(CFG_TARGET), \
701   $(eval $(foreach stage,$(STAGES), \
702    $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
703
704 define DEF_RUN_COMPILETEST
705
706 CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
707         $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
708         --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
709         --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
710         --mode $$(CTEST_MODE_$(4)) \
711         $$(CTEST_RUNTOOL_$(4))
712
713 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
714
715 # CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
716 # Goal: leave this variable as empty string if we should run the test.
717 # Otherwise, set it to the reason we are not running the test.
718 # (Encoded as a separate variable because GNU make does not have a
719 # good way to express OR on ifeq commands)
720
721 ifneq ($$(CTEST_DISABLE_$(4)),)
722 # Test suite is disabled for all configured targets.
723 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
724 else
725 # else, check if non-self-hosted target (i.e. target not-in hosts) ...
726 ifeq ($$(findstring $(2),$$(CFG_HOST)),)
727 # ... if so, then check if this test suite is disabled for non-selfhosts.
728 ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
729 # Test suite is disabled for this target.
730 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
731 endif
732 endif
733 # Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
734 endif
735
736 ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
737 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
738                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
739                 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
740         @$$(call E, run $(4) [$(2)]: $$<)
741         $$(Q)touch $$@.start_time
742         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
743                 $$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
744                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
745                 && touch -r $$@.start_time $$@ && rm $$@.start_time
746
747 else
748
749 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
750         @$$(call E, run $(4) [$(2)]: $$<)
751         @$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
752         touch $$@
753
754 endif
755
756 endef
757
758 CTEST_NAMES = rpass rpass-valgrind rpass-full rfail-full cfail-full rfail cfail pfail \
759         bench perf debuginfo-gdb debuginfo-lldb codegen rustdocck
760
761 $(foreach host,$(CFG_HOST), \
762  $(eval $(foreach target,$(CFG_TARGET), \
763   $(eval $(foreach stage,$(STAGES), \
764    $(eval $(foreach name,$(CTEST_NAMES), \
765    $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
766
767 PRETTY_NAMES = pretty-rpass pretty-rpass-valgrind pretty-rpass-full pretty-rfail-full pretty-rfail \
768     pretty-bench pretty-pretty
769 PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
770 PRETTY_DEPS_pretty-rpass-valgrind = $(RPASS_VALGRIND_TESTS)
771 PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
772 PRETTY_DEPS_pretty-rfail-full = $(RFAIL_FULL_TESTS)
773 PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
774 PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
775 PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
776 PRETTY_DIRNAME_pretty-rpass = run-pass
777 PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
778 PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
779 PRETTY_DIRNAME_pretty-rfail-full = run-fail-fulldeps
780 PRETTY_DIRNAME_pretty-rfail = run-fail
781 PRETTY_DIRNAME_pretty-bench = bench
782 PRETTY_DIRNAME_pretty-pretty = pretty
783
784 define DEF_PRETTY_FULLDEPS
785 PRETTY_DEPS$(1)_T_$(2)_H_$(3)_pretty-rpass-full = $$(CSREQ$(1)_T_$(3)_H_$(3))
786 PRETTY_DEPS$(1)_T_$(2)_H_$(3)_pretty-rfail-full = $$(CSREQ$(1)_T_$(3)_H_$(3))
787 endef
788
789 $(foreach host,$(CFG_HOST), \
790  $(foreach target,$(CFG_TARGET), \
791   $(foreach stage,$(STAGES), \
792    $(eval $(call DEF_PRETTY_FULLDEPS,$(stage),$(target),$(host))))))
793
794 define DEF_RUN_PRETTY_TEST
795
796 PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
797                 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
798         --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
799         --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
800         --mode pretty
801
802 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
803
804 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
805                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
806                 $$(PRETTY_DEPS_$(4)) \
807                 $$(PRETTY_DEPS$(1)_T_$(2)_H_$(3)_$(4))
808         @$$(call E, run pretty-rpass [$(2)]: $$<)
809         $$(Q)touch $$@.start_time
810         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
811                 $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
812                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
813                 && touch -r $$@.start_time $$@ && rm $$@.start_time
814
815 endef
816
817 $(foreach host,$(CFG_HOST), \
818  $(foreach target,$(CFG_TARGET), \
819   $(foreach stage,$(STAGES), \
820    $(foreach pretty-name,$(PRETTY_NAMES), \
821     $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
822
823
824 ######################################################################
825 # Crate & freestanding documentation tests
826 ######################################################################
827
828 define DEF_RUSTDOC
829 RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
830 RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
831 endef
832
833 $(foreach host,$(CFG_HOST), \
834  $(foreach target,$(CFG_TARGET), \
835   $(foreach stage,$(STAGES), \
836    $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))
837
838 # Freestanding
839
840 define DEF_DOC_TEST
841
842 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
843
844 # If NO_REBUILD is set then break the dependencies on everything but
845 # the source files so we can test documentation without rebuilding
846 # rustdoc etc.
847 ifeq ($(NO_REBUILD),)
848 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
849         $$(DOCFILE_$(4)) \
850         $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
851         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
852 else
853 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(DOCFILE_$(4))
854 endif
855
856 ifeq ($(2),$$(CFG_BUILD))
857 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
858         @$$(call E, run doc-$(4) [$(2)])
859         $$(Q)touch $$@.start_time
860         $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< \
861                 --test-args "$$(TESTARGS)" && \
862                 touch -r $$@.start_time $$@ && rm $$@.start_time
863 else
864 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
865         touch $$@
866 endif
867 endef
868
869 $(foreach host,$(CFG_HOST), \
870  $(foreach target,$(CFG_TARGET), \
871   $(foreach stage,$(STAGES), \
872    $(foreach docname,$(DOC_NAMES), \
873     $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
874
875 # Crates
876
877 define DEF_CRATE_DOC_TEST
878
879 # If NO_REBUILD is set then break the dependencies on everything but
880 # the source files so we can test crate documentation without
881 # rebuilding any of the parent crates.
882 ifeq ($(NO_REBUILD),)
883 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
884         $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
885         $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
886         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
887 else
888 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
889 endif
890
891 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
892         $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
893
894 ifeq ($(2),$$(CFG_BUILD))
895 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
896         @$$(call E, run doc-crate-$(4) [$(2)])
897         $$(Q)touch $$@.start_time
898         $$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
899             $$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
900                 $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && \
901                 touch -r $$@.start_time $$@ && rm $$@.start_time
902 else
903 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
904         touch $$@
905 endif
906
907 endef
908
909 $(foreach host,$(CFG_HOST), \
910  $(foreach target,$(CFG_TARGET), \
911   $(foreach stage,$(STAGES), \
912    $(foreach crate,$(TEST_DOC_CRATES), \
913     $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
914
915 ######################################################################
916 # Shortcut rules
917 ######################################################################
918
919 TEST_GROUPS = \
920         crates \
921         $(foreach crate,$(TEST_CRATES),$(crate)) \
922         $(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
923         rpass \
924     rpass-valgrind \
925         rpass-full \
926         rfail-full \
927         cfail-full \
928         rfail \
929         cfail \
930         pfail \
931         bench \
932         perf \
933         rmake \
934         rustdocck \
935         debuginfo-gdb \
936         debuginfo-lldb \
937         codegen \
938         doc \
939         $(foreach docname,$(DOC_NAMES),doc-$(docname)) \
940         pretty \
941         pretty-rpass \
942     pretty-rpass-valgrind \
943         pretty-rpass-full \
944         pretty-rfail-full \
945         pretty-rfail \
946         pretty-bench \
947         pretty-pretty \
948         $(NULL)
949
950 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
951 check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
952 endef
953
954 $(foreach stage,$(STAGES), \
955  $(foreach target,$(CFG_TARGET), \
956   $(foreach host,$(CFG_HOST), \
957    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
958
959 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
960 check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
961 endef
962
963 $(foreach stage,$(STAGES), \
964  $(foreach target,$(CFG_TARGET), \
965   $(foreach host,$(CFG_HOST), \
966    $(foreach group,$(TEST_GROUPS), \
967     $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
968
969 define DEF_CHECK_FOR_STAGE
970 check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
971 check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
972                            check-stage$(1)-H-$$(target))
973 endef
974
975 $(foreach stage,$(STAGES), \
976  $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
977
978 define DEF_CHECK_FOR_STAGE_AND_GROUP
979 check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
980 check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
981                                check-stage$(1)-H-$$(target)-$(2))
982 endef
983
984 $(foreach stage,$(STAGES), \
985  $(foreach group,$(TEST_GROUPS), \
986   $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
987
988
989 define DEF_CHECK_FOR_STAGE_AND_HOSTS
990 check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
991                            check-stage$(1)-T-$$(target)-H-$(2))
992 endef
993
994 $(foreach stage,$(STAGES), \
995  $(foreach host,$(CFG_HOST), \
996   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
997
998 define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
999 check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
1000                                 check-stage$(1)-T-$$(target)-H-$(2)-$(3))
1001 endef
1002
1003 $(foreach stage,$(STAGES), \
1004  $(foreach host,$(CFG_HOST), \
1005   $(foreach group,$(TEST_GROUPS), \
1006    $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
1007
1008 define DEF_CHECK_DOC_FOR_STAGE
1009 check-stage$(1)-docs: $$(foreach docname,$$(DOC_NAMES), \
1010                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
1011                      $$(foreach crate,$$(TEST_DOC_CRATES), \
1012                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
1013 endef
1014
1015 $(foreach stage,$(STAGES), \
1016  $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))
1017
1018 define DEF_CHECK_CRATE
1019 check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
1020 endef
1021
1022 $(foreach crate,$(TEST_CRATES), \
1023  $(eval $(call DEF_CHECK_CRATE,$(crate))))
1024
1025 ######################################################################
1026 # RMAKE rules
1027 ######################################################################
1028
1029 RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
1030 RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
1031
1032 define DEF_RMAKE_FOR_T_H
1033 # $(1) the stage
1034 # $(2) target triple
1035 # $(3) host triple
1036
1037
1038 ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
1039 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
1040                 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
1041
1042 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
1043                 $$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
1044         @touch $$@
1045
1046 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
1047                 $(S)src/test/run-make/%/Makefile \
1048                 $$(CSREQ$(1)_T_$(2)_H_$(3))
1049         @rm -rf $(3)/test/run-make/$$*
1050         @mkdir -p $(3)/test/run-make/$$*
1051         $$(Q)touch $$@.start_time
1052         $$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
1053         $$(MAKE) \
1054             $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
1055             $(3)/test/run-make/$$* \
1056             "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
1057             $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
1058             "$$(TESTNAME)" \
1059             $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
1060             "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
1061             "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
1062             $(1) \
1063             $$(S)
1064         @touch -r $$@.start_time $$@ && rm $$@.start_time
1065 else
1066 # FIXME #11094 - The above rule doesn't work right for multiple targets
1067 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
1068         @true
1069
1070 endif
1071
1072
1073 endef
1074
1075 $(foreach stage,$(STAGES), \
1076  $(foreach target,$(CFG_TARGET), \
1077   $(foreach host,$(CFG_HOST), \
1078    $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))