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