PageRenderTime 36ms CodeModel.GetById 2ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/mk/tests.mk

https://github.com/osaut/rust
Makefile | 712 lines | 496 code | 151 blank | 65 comment | 4 complexity | fcfec07ae92f43f4546b5d1c82965f17 MD5 | raw file
  1# Copyright 2012 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
 17TEST_TARGET_CRATES = core std
 18TEST_HOST_CRATES = syntax rustc rustdoc rusti rust rustpkg
 19TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
 20
 21# Markdown files under doc/ that should have their code extracted and run
 22DOC_TEST_NAMES = tutorial tutorial-ffi tutorial-macros tutorial-borrowed-ptr tutorial-tasks rust
 23
 24######################################################################
 25# Environment configuration
 26######################################################################
 27
 28# The arguments to all test runners
 29ifdef TESTNAME
 30  TESTARGS += $(TESTNAME)
 31endif
 32
 33ifdef CHECK_XFAILS
 34  TESTARGS += --ignored
 35endif
 36
 37# Arguments to the cfail/rfail/rpass/bench tests
 38ifdef CFG_VALGRIND
 39  CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
 40endif
 41
 42# Arguments to the perf tests
 43ifdef CFG_PERF_TOOL
 44  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
 45endif
 46
 47CTEST_TESTARGS := $(TESTARGS)
 48
 49ifdef VERBOSE
 50  CTEST_TESTARGS += --verbose
 51endif
 52
 53# If we're running perf then set this environment variable
 54# to put the benchmarks into 'hard mode'
 55ifeq ($(MAKECMDGOALS),perf)
 56  RUST_BENCH=1
 57  export RUST_BENCH
 58endif
 59
 60TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
 61TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
 62
 63define DEF_TARGET_COMMANDS
 64
 65ifdef CFG_UNIXY_$(1)
 66  CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
 67endif
 68
 69ifdef CFG_WINDOWSY_$(1)
 70  CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)/$$(2)/$$(strip \
 71   $$(if $$(findstring stage0,$$(1)), \
 72       stage0/$$(CFG_LIBDIR), \
 73      $$(if $$(findstring stage1,$$(1)), \
 74           stage1/$$(CFG_LIBDIR), \
 75          $$(if $$(findstring stage2,$$(1)), \
 76               stage2/$$(CFG_LIBDIR), \
 77               $$(if $$(findstring stage3,$$(1)), \
 78                    stage3/$$(CFG_LIBDIR), \
 79               )))))/rustc/$$(CFG_BUILD_TRIPLE)/$$(CFG_LIBDIR)
 80  CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(3)),$$(1))
 81endif
 82
 83# Run the compiletest runner itself under valgrind
 84ifdef CTEST_VALGRIND
 85CFG_RUN_CTEST_$(1)=$$(call CFG_RUN_TEST_$$(CFG_BUILD_TRIPLE),$$(2),$$(3))
 86else
 87CFG_RUN_CTEST_$(1)=$$(call CFG_RUN_$$(CFG_BUILD_TRIPLE),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
 88endif
 89
 90endef
 91
 92$(foreach target,$(CFG_TARGET_TRIPLES), \
 93  $(eval $(call DEF_TARGET_COMMANDS,$(target))))
 94
 95
 96######################################################################
 97# Main test targets
 98######################################################################
 99
100check: cleantestlibs cleantmptestlogs tidy all check-stage2
101	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
102
103check-notidy: cleantestlibs cleantmptestlogs all check-stage2
104	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
105
106check-full: cleantestlibs cleantmptestlogs tidy \
107            all check-stage1 check-stage2 check-stage3
108	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
109
110check-test: cleantestlibs cleantmptestlogs all check-stage2-rfail
111	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
112
113check-lite: cleantestlibs cleantmptestlogs \
114	check-stage2-core check-stage2-std check-stage2-rpass \
115	check-stage2-rfail check-stage2-cfail
116	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
117
118.PHONY: cleantmptestlogs cleantestlibs
119
120cleantmptestlogs:
121	$(Q)rm -f tmp/*.log
122
123cleantestlibs:
124	$(Q)find $(CFG_BUILD_TRIPLE)/test \
125         -name '*.[odasS]' -o \
126         -name '*.so' -o      \
127         -name '*.dylib' -o   \
128         -name '*.dll' -o     \
129         -name '*.def' -o     \
130         -name '*.bc' -o      \
131         -name '*.dSYM' -o    \
132         -name '*.libaux' -o      \
133         -name '*.out' -o     \
134         -name '*.err' -o     \
135	 -name '*.debugger.script' \
136         | xargs rm -rf
137
138
139######################################################################
140# Tidy
141######################################################################
142
143ifdef CFG_NOTIDY
144tidy:
145else
146
147ALL_CS := $(wildcard $(S)src/rt/*.cpp \
148                     $(S)src/rt/*/*.cpp \
149                     $(S)src/rt/*/*/*.cpp \
150                     $(S)srcrustllvm/*.cpp)
151ALL_CS := $(filter-out $(S)src/rt/bigint/bigint_ext.cpp \
152                       $(S)src/rt/bigint/bigint_int.cpp \
153                       $(S)src/rt/miniz.cpp \
154                       $(S)src/rt/linenoise/linenoise.c \
155                       $(S)src/rt/linenoise/utf8.c \
156	,$(ALL_CS))
157ALL_HS := $(wildcard $(S)src/rt/*.h \
158                     $(S)src/rt/*/*.h \
159                     $(S)src/rt/*/*/*.h \
160                     $(S)srcrustllvm/*.h)
161ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
162                       $(S)src/rt/vg/memcheck.h \
163                       $(S)src/rt/uthash/uthash.h \
164                       $(S)src/rt/uthash/utlist.h \
165                       $(S)src/rt/msvc/typeof.h \
166                       $(S)src/rt/msvc/stdint.h \
167                       $(S)src/rt/msvc/inttypes.h \
168                       $(S)src/rt/bigint/bigint.h \
169                       $(S)src/rt/linenoise/linenoise.h \
170                       $(S)src/rt/linenoise/utf8.h \
171	,$(ALL_HS))
172
173# Run the tidy script in multiple parts to avoid huge 'echo' commands
174tidy:
175		@$(call E, check: formatting)
176		$(Q)find $(S)src -name '*.r[sc]' \
177		| grep '^$(S)src/test' -v \
178		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
179		$(Q)find $(S)src/etc -name '*.py' \
180		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
181		$(Q)echo $(ALL_CS) \
182	  	| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
183		$(Q)echo $(ALL_HS) \
184	  	| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
185
186endif
187
188
189######################################################################
190# Sets of tests
191######################################################################
192
193define DEF_TEST_SETS
194
195check-stage$(1)-T-$(2)-H-$(3)-exec:     				\
196	check-stage$(1)-T-$(2)-H-$(3)-rpass-exec			\
197	check-stage$(1)-T-$(2)-H-$(3)-rfail-exec			\
198	check-stage$(1)-T-$(2)-H-$(3)-cfail-exec			\
199	check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec			\
200        check-stage$(1)-T-$(2)-H-$(3)-crates-exec                      \
201	check-stage$(1)-T-$(2)-H-$(3)-bench-exec			\
202	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-exec \
203	check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
204	check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
205
206# Only test the compiler-dependent crates when the target is
207# able to build a compiler (when the target triple is in the set of host triples)
208ifneq ($$(findstring $(2),$$(CFG_HOST_TRIPLES)),)
209
210check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
211	$$(foreach crate,$$(TEST_CRATES), \
212           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
213
214else
215
216check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
217	$$(foreach crate,$$(TEST_TARGET_CRATES), \
218           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
219
220endif
221
222check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
223        $$(foreach docname,$$(DOC_TEST_NAMES), \
224           check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec)
225
226check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
227	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec	\
228	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec	\
229	check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec	\
230	check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec	\
231	check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
232
233endef
234
235$(foreach host,$(CFG_HOST_TRIPLES), \
236 $(foreach target,$(CFG_TARGET_TRIPLES), \
237  $(foreach stage,$(STAGES), \
238    $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))
239
240
241######################################################################
242# Crate testing
243######################################################################
244
245define TEST_RUNNER
246
247# If NO_REBUILD is set then break the dependencies on std so we can
248# test crates without rebuilding core and std first
249ifeq ($(NO_REBUILD),)
250STDTESTDEP_$(1)_$(2)_$(3) = $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB_$(2))
251else
252STDTESTDEP_$(1)_$(2)_$(3) =
253endif
254
255$(3)/test/coretest.stage$(1)-$(2)$$(X_$(2)):			\
256		$$(CORELIB_CRATE) $$(CORELIB_INPUTS)	\
257		$$(STDTESTDEP_$(1)_$(2)_$(3))
258	@$$(call E, compile_and_link: $$@)
259	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
260
261$(3)/test/stdtest.stage$(1)-$(2)$$(X_$(2)):			\
262		$$(STDLIB_CRATE) $$(STDLIB_INPUTS)	\
263		$$(STDTESTDEP_$(1)_$(2)_$(3))
264	@$$(call E, compile_and_link: $$@)
265	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
266
267$(3)/test/syntaxtest.stage$(1)-$(2)$$(X_$(2)):			\
268		$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS)	\
269		$$(STDTESTDEP_$(1)_$(2)_$(3))
270	@$$(call E, compile_and_link: $$@)
271	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
272
273$(3)/test/rustctest.stage$(1)-$(2)$$(X_$(2)):					\
274		$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
275		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM_$(2)) \
276                $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2))
277	@$$(call E, compile_and_link: $$@)
278	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
279
280$(3)/test/rustpkgtest.stage$(1)-$(2)$$(X_$(2)):					\
281		$$(RUSTPKG_LIB) $$(RUSTPKG_INPUTS)		\
282		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
283	@$$(call E, compile_and_link: $$@)
284	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
285
286$(3)/test/rustitest.stage$(1)-$(2)$$(X_$(2)):					\
287		$$(RUSTI_LIB) $$(RUSTI_INPUTS)		\
288		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
289	@$$(call E, compile_and_link: $$@)
290	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
291
292$(3)/test/rusttest.stage$(1)-$(2)$$(X_$(2)):					\
293		$$(RUST_LIB) $$(RUST_INPUTS)		\
294		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
295	@$$(call E, compile_and_link: $$@)
296	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
297
298$(3)/test/rustdoctest.stage$(1)-$(2)$$(X_$(2)):					\
299		$$(RUSTDOC_LIB) $$(RUSTDOC_INPUTS)		\
300		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
301	@$$(call E, compile_and_link: $$@)
302	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
303
304endef
305
306$(foreach host,$(CFG_HOST_TRIPLES), \
307 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
308  $(eval $(foreach stage,$(STAGES), \
309   $(eval $(call TEST_RUNNER,$(stage),$(target),$(host))))))))
310
311define DEF_TEST_CRATE_RULES
312check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
313
314$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
315		$(3)/test/$(4)test.stage$(1)-$(2)$$(X_$(2))
316	@$$(call E, run: $$<)
317	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) $$(TESTARGS)	\
318	--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
319	&& touch $$@
320endef
321
322$(foreach host,$(CFG_HOST_TRIPLES), \
323 $(foreach target,$(CFG_TARGET_TRIPLES), \
324  $(foreach stage,$(STAGES), \
325   $(foreach crate, $(TEST_CRATES), \
326    $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate)))))))
327
328
329######################################################################
330# Rules for the compiletest tests (rpass, rfail, etc.)
331######################################################################
332
333RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
334RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
335RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
336RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
337RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
338RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
339CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
340CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
341BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
342PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
343DEBUGINFO_RS := $(wildcard $(S)src/test/debug-info/*.rs)
344
345# perf tests are the same as bench tests only they run under
346# a performance monitor.
347PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
348
349RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
350RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
351RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
352CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
353BENCH_TESTS := $(BENCH_RS)
354PERF_TESTS := $(PERF_RS)
355PRETTY_TESTS := $(PRETTY_RS)
356DEBUGINFO_TESTS := $(DEBUGINFO_RS)
357
358CTEST_SRC_BASE_rpass = run-pass
359CTEST_BUILD_BASE_rpass = run-pass
360CTEST_MODE_rpass = run-pass
361CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
362
363CTEST_SRC_BASE_rpass-full = run-pass-full
364CTEST_BUILD_BASE_rpass-full = run-pass-full
365CTEST_MODE_rpass-full = run-pass
366CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
367
368CTEST_SRC_BASE_rfail = run-fail
369CTEST_BUILD_BASE_rfail = run-fail
370CTEST_MODE_rfail = run-fail
371CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
372
373CTEST_SRC_BASE_cfail = compile-fail
374CTEST_BUILD_BASE_cfail = compile-fail
375CTEST_MODE_cfail = compile-fail
376CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
377
378CTEST_SRC_BASE_bench = bench
379CTEST_BUILD_BASE_bench = bench
380CTEST_MODE_bench = run-pass
381CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
382
383CTEST_SRC_BASE_perf = bench
384CTEST_BUILD_BASE_perf = perf
385CTEST_MODE_perf = run-pass
386CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
387
388CTEST_SRC_BASE_debuginfo = debug-info
389CTEST_BUILD_BASE_debuginfo = debug-info
390CTEST_MODE_debuginfo = debug-info
391CTEST_RUNTOOL_debuginfo = $(CTEST_RUNTOOL)
392
393ifeq ($(CFG_GDB),)
394CTEST_DISABLE_debuginfo = "no gdb found"
395endif
396
397ifeq ($(CFG_OSTYPE),apple-darwin)
398CTEST_DISABLE_debuginfo = "gdb on darwing needs root"
399endif
400
401define DEF_CTEST_VARS
402
403# All the per-stage build rules you might want to call from the
404# command line.
405#
406# $(1) is the stage number
407# $(2) is the target triple to test
408# $(3) is the host triple to test
409
410# Prerequisites for compiletest tests
411TEST_SREQ$(1)_T_$(2)_H_$(3) = \
412	$$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
413	$$(SREQ$(1)_T_$(2)_H_$(3))
414
415# Rules for the cfail/rfail/rpass/bench/perf test runner
416
417CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) :=						\
418		--compile-lib-path $$(HLIB$(1)_H_$(3))				\
419        --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3))			\
420        --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))			\
421        --aux-base $$(S)src/test/auxiliary/                 \
422        --stage-id stage$(1)-$(2)							\
423        --rustcflags "$(RUSTC_FLAGS_$(2)) $$(CFG_RUSTC_FLAGS) --target=$(2)" \
424        $$(CTEST_TESTARGS)
425
426CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
427CTEST_DEPS_rpass_full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
428CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
429CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
430CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
431CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
432CTEST_DEPS_debuginfo_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_TESTS)
433
434endef
435
436$(foreach host,$(CFG_HOST_TRIPLES), \
437 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
438  $(eval $(foreach stage,$(STAGES), \
439   $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
440
441define DEF_RUN_COMPILETEST
442
443CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
444        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
445        --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
446        --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
447        --mode $$(CTEST_MODE_$(4)) \
448	$$(CTEST_RUNTOOL_$(4))
449
450check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
451
452ifeq ($$(CTEST_DISABLE_$(4)),)
453
454$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
455		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
456                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
457	@$$(call E, run $(4): $$<)
458	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
459		$$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
460		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
461                && touch $$@
462
463else
464
465$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
466		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
467                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
468	@$$(call E, run $(4): $$<)
469	@$$(call E, warning: tests disabled: $$(CTEST_DISABLE_$(4)))
470	touch $$@
471
472endif
473
474endef
475
476CTEST_NAMES = rpass rpass-full rfail cfail bench perf debuginfo
477
478$(foreach host,$(CFG_HOST_TRIPLES), \
479 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
480  $(eval $(foreach stage,$(STAGES), \
481   $(eval $(foreach name,$(CTEST_NAMES), \
482   $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
483
484PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
485PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
486PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
487PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
488PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
489PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
490PRETTY_DIRNAME_pretty-rpass = run-pass
491PRETTY_DIRNAME_pretty-rpass-full = run-pass-full
492PRETTY_DIRNAME_pretty-rfail = run-fail
493PRETTY_DIRNAME_pretty-bench = bench
494PRETTY_DIRNAME_pretty-pretty = pretty
495
496define DEF_RUN_PRETTY_TEST
497
498PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) :=			\
499		$$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
500        --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
501        --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
502        --mode pretty
503
504check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
505
506$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
507	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))		\
508	        $$(PRETTY_DEPS_$(4))
509	@$$(call E, run pretty-rpass: $$<)
510	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
511		$$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
512		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
513                && touch $$@
514
515endef
516
517$(foreach host,$(CFG_HOST_TRIPLES), \
518 $(foreach target,$(CFG_TARGET_TRIPLES), \
519  $(foreach stage,$(STAGES), \
520   $(foreach pretty-name,$(PRETTY_NAMES), \
521    $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
522
523define DEF_RUN_DOC_TEST
524
525DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-doc-$(4) := \
526        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
527        --src-base $(3)/test/doc-$(4)/	\
528        --build-base $(3)/test/doc-$(4)/	\
529        --mode run-pass
530
531check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
532
533$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): \
534	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))		\
535                doc-$(4)-extract$(3)
536	@$$(call E, run doc-$(4): $$<)
537	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
538                $$(DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-doc-$(4)) \
539		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),doc-$(4)) \
540                && touch $$@
541
542endef
543
544$(foreach host,$(CFG_HOST_TRIPLES), \
545 $(foreach target,$(CFG_TARGET_TRIPLES), \
546  $(foreach stage,$(STAGES), \
547   $(foreach docname,$(DOC_TEST_NAMES), \
548    $(eval $(call DEF_RUN_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
549
550
551######################################################################
552# Extracting tests for docs
553######################################################################
554
555EXTRACT_TESTS := "$(CFG_PYTHON)" $(S)src/etc/extract-tests.py
556
557define DEF_DOC_TEST_HOST
558
559doc-$(2)-extract$(1):
560	@$$(call E, extract: $(2) tests)
561	$$(Q)rm -f $(1)/test/doc-$(2)/*.rs
562	$$(Q)$$(EXTRACT_TESTS) $$(S)doc/$(2).md $(1)/test/doc-$(2)
563
564endef
565
566$(foreach host,$(CFG_HOST_TRIPLES), \
567 $(foreach docname,$(DOC_TEST_NAMES), \
568  $(eval $(call DEF_DOC_TEST_HOST,$(host),$(docname)))))
569
570
571######################################################################
572# Shortcut rules
573######################################################################
574
575TEST_GROUPS = \
576	crates \
577	$(foreach crate,$(TEST_CRATES),$(crate)) \
578	rpass \
579	rpass-full \
580	rfail \
581	cfail \
582	bench \
583	perf \
584	debuginfo \
585	doc \
586	$(foreach docname,$(DOC_TEST_NAMES),$(docname)) \
587	pretty \
588	pretty-rpass \
589	pretty-rpass-full \
590	pretty-rfail \
591	pretty-bench \
592	pretty-pretty \
593	$(NULL)
594
595define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
596check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
597endef
598
599$(foreach stage,$(STAGES), \
600 $(foreach target,$(CFG_TARGET_TRIPLES), \
601  $(foreach host,$(CFG_HOST_TRIPLES), \
602   $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
603
604define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
605check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
606endef
607
608$(foreach stage,$(STAGES), \
609 $(foreach target,$(CFG_TARGET_TRIPLES), \
610  $(foreach host,$(CFG_HOST_TRIPLES), \
611   $(foreach group,$(TEST_GROUPS), \
612    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
613
614define DEF_CHECK_FOR_STAGE
615check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD_TRIPLE)
616check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET_TRIPLES), \
617                           check-stage$(1)-H-$$(target))
618endef
619
620$(foreach stage,$(STAGES), \
621 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
622
623define DEF_CHECK_FOR_STAGE_AND_GROUP
624check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD_TRIPLE)-$(2)
625check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET_TRIPLES), \
626                               check-stage$(1)-H-$$(target)-$(2))
627endef
628
629$(foreach stage,$(STAGES), \
630 $(foreach group,$(TEST_GROUPS), \
631  $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
632
633
634define DEF_CHECK_FOR_STAGE_AND_HOSTS
635check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET_TRIPLES), \
636                           check-stage$(1)-T-$$(target)-H-$(2))
637endef
638
639$(foreach stage,$(STAGES), \
640 $(foreach host,$(CFG_HOST_TRIPLES), \
641  $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
642
643define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
644check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET_TRIPLES), \
645                                check-stage$(1)-T-$$(target)-H-$(2)-$(3))
646endef
647
648$(foreach stage,$(STAGES), \
649 $(foreach host,$(CFG_HOST_TRIPLES), \
650  $(foreach group,$(TEST_GROUPS), \
651   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
652
653######################################################################
654# check-fast rules
655######################################################################
656
657FT := run_pass_stage2
658FT_LIB := $(call CFG_LIB_NAME_$(CFG_BUILD_TRIPLE),$(FT))
659FT_DRIVER := $(FT)_driver
660
661GENERATED += tmp/$(FT).rc tmp/$(FT_DRIVER).rs
662
663tmp/$(FT).rc tmp/$(FT_DRIVER).rs: \
664		$(RPASS_TESTS) \
665		$(S)src/etc/combine-tests.py
666	@$(call E, check: building combined stage2 test runner)
667	$(Q)$(CFG_PYTHON) $(S)src/etc/combine-tests.py
668
669define DEF_CHECK_FAST_FOR_T_H
670# $(1) unused
671# $(2) target triple
672# $(3) host triple
673
674$$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB): \
675		tmp/$$(FT).rc \
676		$$(SREQ2_T_$(2)_H_$(3))
677	@$$(call E, compile_and_link: $$@)
678	$$(STAGE2_T_$(2)_H_$(3)) --lib -o $$@ $$<
679
680$(3)/test/$$(FT_DRIVER)-$(2)$$(X_$(2)): \
681		tmp/$$(FT_DRIVER).rs \
682		$$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB) \
683		$$(SREQ2_T_$(2)_H_$(3))
684	@$$(call E, compile_and_link: $$@ $$<)
685	$$(STAGE2_T_$(2)_H_$(3)) -o $$@ $$<
686
687$(3)/test/$$(FT_DRIVER)-$(2).out: \
688		$(3)/test/$$(FT_DRIVER)-$(2)$$(X_$(2)) \
689		$$(SREQ2_T_$(2)_H_$(3))
690	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) \
691	--logfile tmp/$$(FT_DRIVER)-$(2).log
692
693check-fast-T-$(2)-H-$(3):     			\
694	$(3)/test/$$(FT_DRIVER)-$(2).out
695
696endef
697
698$(foreach host,$(CFG_HOST_TRIPLES), \
699 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
700   $(eval $(call DEF_CHECK_FAST_FOR_T_H,,$(target),$(host))))))
701
702check-fast: tidy check-fast-H-$(CFG_BUILD_TRIPLE)
703
704define DEF_CHECK_FAST_FOR_H
705
706check-fast-H-$(1): 		check-fast-T-$(1)-H-$(1)
707
708endef
709
710$(foreach host,$(CFG_HOST_TRIPLES),			\
711 $(eval $(call DEF_CHECK_FAST_FOR_H,$(host))))
712