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