]> git.lizzy.rs Git - rust.git/blob - mk/tests.mk
Merge pull request #20510 from tshepang/patch-6
[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 else
377 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
378 endif
379
380 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
381 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \
382                 $$(CRATEFILE_$(4)) \
383                 $$(TESTDEP_$(1)_$(2)_$(3)_$(4))
384         @$$(call E, rustc: $$@)
385         $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(3)) \
386             $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \
387                 -L "$$(RT_OUTPUT_DIR_$(2))" \
388                 -L "$$(LLVM_LIBDIR_$(2))" \
389                 $$(RUSTFLAGS_$(4))
390
391 endef
392
393 $(foreach host,$(CFG_HOST), \
394  $(eval $(foreach target,$(CFG_TARGET), \
395   $(eval $(foreach stage,$(STAGES), \
396    $(eval $(foreach crate,$(TEST_CRATES), \
397     $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
398
399 define DEF_TEST_CRATE_RULES
400 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
401
402 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
403                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
404         @$$(call E, run: $$<)
405         $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
406             --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
407             $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
408             && touch $$@
409 endef
410
411 define DEF_TEST_CRATE_RULES_arm-linux-androideabi
412 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
413
414 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
415                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
416         @$$(call E, run: $$< via adb)
417         $$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
418         $$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
419                 ./$$(notdir $$<) \
420                 --logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
421                 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
422                 > tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
423         $$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
424         $$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
425         $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
426         $$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
427         @if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
428         then \
429                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
430                 touch $$@; \
431         else \
432                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
433                 exit 101; \
434         fi
435 endef
436
437 define DEF_TEST_CRATE_RULES_null
438 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
439
440 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
441                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
442         @$$(call E, failing: no device for $$< )
443         false
444 endef
445
446 $(foreach host,$(CFG_HOST), \
447  $(foreach target,$(CFG_TARGET), \
448   $(foreach stage,$(STAGES), \
449    $(foreach crate, $(TEST_CRATES), \
450     $(if $(findstring $(target),$(CFG_BUILD)), \
451      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
452      $(if $(findstring $(target),"arm-linux-androideabi"), \
453       $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
454        $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
455        $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
456       ), \
457       $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
458      ))))))
459
460 ######################################################################
461 # Rules for the compiletest tests (rpass, rfail, etc.)
462 ######################################################################
463
464 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
465 RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
466 RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
467 CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
468 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
469 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
470 BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
471 PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
472 DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
473 DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
474 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
475 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
476
477 # perf tests are the same as bench tests only they run under
478 # a performance monitor.
479 PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
480
481 RPASS_TESTS := $(RPASS_RS)
482 RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
483 RPASS_FULL_TESTS := $(RPASS_FULL_RS)
484 CFAIL_FULL_TESTS := $(CFAIL_FULL_RS)
485 RFAIL_TESTS := $(RFAIL_RS)
486 CFAIL_TESTS := $(CFAIL_RS)
487 BENCH_TESTS := $(BENCH_RS)
488 PERF_TESTS := $(PERF_RS)
489 PRETTY_TESTS := $(PRETTY_RS)
490 DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
491 DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
492 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
493
494 CTEST_SRC_BASE_rpass = run-pass
495 CTEST_BUILD_BASE_rpass = run-pass
496 CTEST_MODE_rpass = run-pass
497 CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
498
499 CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind
500 CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind
501 CTEST_MODE_rpass-valgrind = run-pass-valgrind
502 CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL)
503
504 CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
505 CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
506 CTEST_MODE_rpass-full = run-pass
507 CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
508
509 CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
510 CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
511 CTEST_MODE_cfail-full = compile-fail
512 CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)
513
514 CTEST_SRC_BASE_rfail = run-fail
515 CTEST_BUILD_BASE_rfail = run-fail
516 CTEST_MODE_rfail = run-fail
517 CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
518
519 CTEST_SRC_BASE_cfail = compile-fail
520 CTEST_BUILD_BASE_cfail = compile-fail
521 CTEST_MODE_cfail = compile-fail
522 CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
523
524 CTEST_SRC_BASE_bench = bench
525 CTEST_BUILD_BASE_bench = bench
526 CTEST_MODE_bench = run-pass
527 CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
528
529 CTEST_SRC_BASE_perf = bench
530 CTEST_BUILD_BASE_perf = perf
531 CTEST_MODE_perf = run-pass
532 CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
533
534 CTEST_SRC_BASE_debuginfo-gdb = debuginfo
535 CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
536 CTEST_MODE_debuginfo-gdb = debuginfo-gdb
537 CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)
538
539 CTEST_SRC_BASE_debuginfo-lldb = debuginfo
540 CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
541 CTEST_MODE_debuginfo-lldb = debuginfo-lldb
542 CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
543
544 CTEST_SRC_BASE_codegen = codegen
545 CTEST_BUILD_BASE_codegen = codegen
546 CTEST_MODE_codegen = codegen
547 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
548
549 # CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
550 # disabled and the associated message to be printed as a warning
551 # during attempts to run those tests.
552
553 ifeq ($(CFG_GDB),)
554 CTEST_DISABLE_debuginfo-gdb = "no gdb found"
555 endif
556
557 ifeq ($(CFG_LLDB),)
558 CTEST_DISABLE_debuginfo-lldb = "no lldb found"
559 endif
560
561 ifeq ($(CFG_CLANG),)
562 CTEST_DISABLE_codegen = "no clang found"
563 endif
564
565 ifneq ($(CFG_OSTYPE),apple-darwin)
566 CTEST_DISABLE_debuginfo-lldb = "lldb tests are only run on darwin"
567 endif
568
569 ifeq ($(CFG_OSTYPE),apple-darwin)
570 CTEST_DISABLE_debuginfo-gdb = "gdb on darwin needs root"
571 endif
572
573 # CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
574 # test group to be disabled *unless* the target is able to build a
575 # compiler (i.e. when the target triple is in the set of of host
576 # triples).  The associated message will be printed as a warning
577 # during attempts to run those tests.
578
579 define DEF_CTEST_VARS
580
581 # All the per-stage build rules you might want to call from the
582 # command line.
583 #
584 # $(1) is the stage number
585 # $(2) is the target triple to test
586 # $(3) is the host triple to test
587
588 # Prerequisites for compiletest tests
589 TEST_SREQ$(1)_T_$(2)_H_$(3) = \
590         $$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
591         $$(SREQ$(1)_T_$(2)_H_$(3))
592
593 # Rules for the cfail/rfail/rpass/bench/perf test runner
594
595 # The tests select when to use debug configuration on their own;
596 # remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
597 CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
598
599 # The tests cannot be optimized while the rest of the compiler is optimized, so
600 # filter out the optimization (if any) from rustc and then figure out if we need
601 # to be optimized
602 CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
603 ifndef CFG_DISABLE_OPTIMIZE_TESTS
604 CTEST_RUSTC_FLAGS += -O
605 endif
606
607
608 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
609                 --compile-lib-path $$(HLIB$(1)_H_$(3)) \
610         --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
611         --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
612         --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
613         --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
614         --aux-base $$(S)src/test/auxiliary/ \
615         --stage-id stage$(1)-$(2) \
616         --target $(2) \
617         --host $(3) \
618         --gdb-version="$(CFG_GDB_VERSION)" \
619         --lldb-version="$(CFG_LLDB_VERSION)" \
620         --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
621         --adb-path=$(CFG_ADB) \
622         --adb-test-dir=$(CFG_ADB_TEST_DIR) \
623         --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
624         --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
625         --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
626         $$(CTEST_TESTARGS)
627
628 ifdef CFG_VALGRIND_RPASS
629 ifdef GOOD_VALGRIND_$(2)
630 $(info cfg: valgrind-path set to $(CFG_VALGRIND_RPASS))
631 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
632 endif
633 endif
634
635 ifndef CFG_DISABLE_VALGRIND_RPASS
636 ifdef GOOD_VALGRIND_$(2)
637 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --force-valgrind
638 endif
639 endif
640
641 CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
642 CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
643 CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
644 CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
645 CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
646 CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
647 CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
648 CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
649 CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
650 CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
651                                                $(S)src/etc/lldb_batchmode.py \
652                                                $(S)src/etc/lldb_rust_formatters.py
653 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
654
655 endef
656
657 $(foreach host,$(CFG_HOST), \
658  $(eval $(foreach target,$(CFG_TARGET), \
659   $(eval $(foreach stage,$(STAGES), \
660    $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
661
662 define DEF_RUN_COMPILETEST
663
664 CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
665         $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
666         --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
667         --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
668         --mode $$(CTEST_MODE_$(4)) \
669         $$(CTEST_RUNTOOL_$(4))
670
671 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
672
673 # CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
674 # Goal: leave this variable as empty string if we should run the test.
675 # Otherwise, set it to the reason we are not running the test.
676 # (Encoded as a separate variable because GNU make does not have a
677 # good way to express OR on ifeq commands)
678
679 ifneq ($$(CTEST_DISABLE_$(4)),)
680 # Test suite is disabled for all configured targets.
681 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
682 else
683 # else, check if non-self-hosted target (i.e. target not-in hosts) ...
684 ifeq ($$(findstring $(2),$$(CFG_HOST)),)
685 # ... if so, then check if this test suite is disabled for non-selfhosts.
686 ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
687 # Test suite is disabled for this target.
688 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
689 endif
690 endif
691 # Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
692 endif
693
694 ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
695 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
696                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
697                 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
698         @$$(call E, run $(4) [$(2)]: $$<)
699         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
700                 $$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
701                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
702                 && touch $$@
703
704 else
705
706 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
707         @$$(call E, run $(4) [$(2)]: $$<)
708         @$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
709         touch $$@
710
711 endif
712
713 endef
714
715 CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
716
717 $(foreach host,$(CFG_HOST), \
718  $(eval $(foreach target,$(CFG_TARGET), \
719   $(eval $(foreach stage,$(STAGES), \
720    $(eval $(foreach name,$(CTEST_NAMES), \
721    $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
722
723 PRETTY_NAMES = pretty-rpass pretty-rpass-valgrind pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
724 PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
725 PRETTY_DEPS_pretty-rpass-valgrind = $(RPASS_VALGRIND_TESTS)
726 PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
727 PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
728 PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
729 PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
730 # The stage- and host-specific dependencies are for e.g. macro_crate_test which pulls in
731 # external crates.
732 PRETTY_DEPS$(1)_H_$(3)_pretty-rpass =
733 PRETTY_DEPS$(1)_H_$(3)_pretty-rpass-full = $$(HLIB$(1)_H_$(3))/stamp.syntax $$(HLIB$(1)_H_$(3))/stamp.rustc
734 PRETTY_DEPS$(1)_H_$(3)_pretty-rfail =
735 PRETTY_DEPS$(1)_H_$(3)_pretty-bench =
736 PRETTY_DEPS$(1)_H_$(3)_pretty-pretty =
737 PRETTY_DIRNAME_pretty-rpass = run-pass
738 PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
739 PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
740 PRETTY_DIRNAME_pretty-rfail = run-fail
741 PRETTY_DIRNAME_pretty-bench = bench
742 PRETTY_DIRNAME_pretty-pretty = pretty
743
744 define DEF_RUN_PRETTY_TEST
745
746 PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
747                 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
748         --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
749         --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
750         --mode pretty
751
752 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
753
754 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
755                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
756                 $$(PRETTY_DEPS_$(4)) \
757                 $$(PRETTY_DEPS$(1)_H_$(3)_$(4))
758         @$$(call E, run pretty-rpass [$(2)]: $$<)
759         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
760                 $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
761                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
762                 && touch $$@
763
764 endef
765
766 $(foreach host,$(CFG_HOST), \
767  $(foreach target,$(CFG_TARGET), \
768   $(foreach stage,$(STAGES), \
769    $(foreach pretty-name,$(PRETTY_NAMES), \
770     $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
771
772
773 ######################################################################
774 # Crate & freestanding documentation tests
775 ######################################################################
776
777 define DEF_RUSTDOC
778 RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
779 RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
780 endef
781
782 $(foreach host,$(CFG_HOST), \
783  $(foreach target,$(CFG_TARGET), \
784   $(foreach stage,$(STAGES), \
785    $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))
786
787 # Freestanding
788
789 define DEF_DOC_TEST
790
791 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
792
793 # If NO_REBUILD is set then break the dependencies on everything but
794 # the source files so we can test documentation without rebuilding
795 # rustdoc etc.
796 ifeq ($(NO_REBUILD),)
797 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
798         $$(D)/$(4).md \
799         $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
800         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
801 else
802 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(D)/$(4).md
803 endif
804
805 ifeq ($(2),$$(CFG_BUILD))
806 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
807         @$$(call E, run doc-$(4) [$(2)])
808         $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< --test-args "$$(TESTARGS)" && touch $$@
809 else
810 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
811         touch $$@
812 endif
813 endef
814
815 $(foreach host,$(CFG_HOST), \
816  $(foreach target,$(CFG_TARGET), \
817   $(foreach stage,$(STAGES), \
818    $(foreach docname,$(DOCS), \
819     $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
820
821 # Crates
822
823 define DEF_CRATE_DOC_TEST
824
825 # If NO_REBUILD is set then break the dependencies on everything but
826 # the source files so we can test crate documentation without
827 # rebuilding any of the parent crates.
828 ifeq ($(NO_REBUILD),)
829 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
830         $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
831         $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
832         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
833 else
834 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
835 endif
836
837 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
838         $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
839
840 ifeq ($(2),$$(CFG_BUILD))
841 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
842         @$$(call E, run doc-crate-$(4) [$(2)])
843         $$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(3)) \
844             $$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
845                 $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
846 else
847 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
848         touch $$@
849 endif
850
851 endef
852
853 $(foreach host,$(CFG_HOST), \
854  $(foreach target,$(CFG_TARGET), \
855   $(foreach stage,$(STAGES), \
856    $(foreach crate,$(TEST_DOC_CRATES), \
857     $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
858
859 ######################################################################
860 # Shortcut rules
861 ######################################################################
862
863 TEST_GROUPS = \
864         crates \
865         $(foreach crate,$(TEST_CRATES),$(crate)) \
866         $(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
867         rpass \
868     rpass-valgrind \
869         rpass-full \
870         cfail-full \
871         rfail \
872         cfail \
873         bench \
874         perf \
875         rmake \
876         debuginfo-gdb \
877         debuginfo-lldb \
878         codegen \
879         doc \
880         $(foreach docname,$(DOCS),doc-$(docname)) \
881         pretty \
882         pretty-rpass \
883     pretty-rpass-valgrind \
884         pretty-rpass-full \
885         pretty-rfail \
886         pretty-bench \
887         pretty-pretty \
888         $(NULL)
889
890 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
891 check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
892 endef
893
894 $(foreach stage,$(STAGES), \
895  $(foreach target,$(CFG_TARGET), \
896   $(foreach host,$(CFG_HOST), \
897    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
898
899 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
900 check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
901 endef
902
903 $(foreach stage,$(STAGES), \
904  $(foreach target,$(CFG_TARGET), \
905   $(foreach host,$(CFG_HOST), \
906    $(foreach group,$(TEST_GROUPS), \
907     $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
908
909 define DEF_CHECK_FOR_STAGE
910 check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
911 check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
912                            check-stage$(1)-H-$$(target))
913 endef
914
915 $(foreach stage,$(STAGES), \
916  $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
917
918 define DEF_CHECK_FOR_STAGE_AND_GROUP
919 check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
920 check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
921                                check-stage$(1)-H-$$(target)-$(2))
922 endef
923
924 $(foreach stage,$(STAGES), \
925  $(foreach group,$(TEST_GROUPS), \
926   $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
927
928
929 define DEF_CHECK_FOR_STAGE_AND_HOSTS
930 check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
931                            check-stage$(1)-T-$$(target)-H-$(2))
932 endef
933
934 $(foreach stage,$(STAGES), \
935  $(foreach host,$(CFG_HOST), \
936   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
937
938 define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
939 check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
940                                 check-stage$(1)-T-$$(target)-H-$(2)-$(3))
941 endef
942
943 $(foreach stage,$(STAGES), \
944  $(foreach host,$(CFG_HOST), \
945   $(foreach group,$(TEST_GROUPS), \
946    $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
947
948 define DEF_CHECK_DOC_FOR_STAGE
949 check-stage$(1)-docs: $$(foreach docname,$$(DOCS), \
950                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
951                      $$(foreach crate,$$(TEST_DOC_CRATES), \
952                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
953 endef
954
955 $(foreach stage,$(STAGES), \
956  $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))
957
958 define DEF_CHECK_CRATE
959 check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
960 endef
961
962 $(foreach crate,$(TEST_CRATES), \
963  $(eval $(call DEF_CHECK_CRATE,$(crate))))
964
965 ######################################################################
966 # RMAKE rules
967 ######################################################################
968
969 RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
970 RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
971
972 define DEF_RMAKE_FOR_T_H
973 # $(1) the stage
974 # $(2) target triple
975 # $(3) host triple
976
977
978 ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
979 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
980                 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
981
982 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
983                 $$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
984         @touch $$@
985
986 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
987                 $(S)src/test/run-make/%/Makefile \
988                 $$(CSREQ$(1)_T_$(2)_H_$(3))
989         @rm -rf $(3)/test/run-make/$$*
990         @mkdir -p $(3)/test/run-make/$$*
991         $$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
992         $$(MAKE) \
993             $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
994             $(3)/test/run-make/$$* \
995             "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
996             $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
997             "$$(TESTNAME)" \
998             $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
999             "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
1000             "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
1001             $(1)
1002         @touch $$@
1003 else
1004 # FIXME #11094 - The above rule doesn't work right for multiple targets
1005 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
1006         @true
1007
1008 endif
1009
1010
1011 endef
1012
1013 $(foreach stage,$(STAGES), \
1014  $(foreach target,$(CFG_TARGET), \
1015   $(foreach host,$(CFG_HOST), \
1016    $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))