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