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