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