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