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