PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 59ms RepoModel.GetById 2ms app.codeStats 0ms

/mk/tests.mk

https://github.com/veddan/rust
Makefile | 920 lines | 662 code | 176 blank | 82 comment | 7 complexity | dcbf8eb115cca982349e79b061bf6f07 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 = $(TARGET_CRATES)
 18TEST_DOC_CRATES = $(DOC_CRATES)
 19TEST_HOST_CRATES = $(HOST_CRATES)
 20TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
 21
 22# Markdown files under doc/ that should have their code extracted and run
 23DOC_TEST_NAMES = tutorial guide-ffi guide-macros guide-lifetimes \
 24                 guide-tasks guide-container guide-pointers \
 25                 complement-cheatsheet guide-runtime \
 26                 rust
 27
 28######################################################################
 29# Environment configuration
 30######################################################################
 31
 32# The arguments to all test runners
 33ifdef TESTNAME
 34  TESTARGS += $(TESTNAME)
 35endif
 36
 37ifdef CHECK_XFAILS
 38  TESTARGS += --ignored
 39endif
 40
 41TEST_BENCH = --bench
 42
 43# Arguments to the cfail/rfail/rpass/bench tests
 44ifdef CFG_VALGRIND
 45  CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
 46  TEST_BENCH =
 47endif
 48
 49ifdef NO_BENCH
 50  TEST_BENCH =
 51endif
 52
 53# Arguments to the perf tests
 54ifdef CFG_PERF_TOOL
 55  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
 56endif
 57
 58CTEST_TESTARGS := $(TESTARGS)
 59
 60ifdef VERBOSE
 61  CTEST_TESTARGS += --verbose
 62endif
 63
 64# If we're running perf then set this environment variable
 65# to put the benchmarks into 'hard mode'
 66ifeq ($(MAKECMDGOALS),perf)
 67  RUST_BENCH=1
 68  export RUST_BENCH
 69endif
 70
 71TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
 72TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
 73
 74TEST_RATCHET_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4)-metrics.json
 75TEST_RATCHET_NOISE_PERCENT=10.0
 76
 77# Whether to ratchet or merely save benchmarks
 78ifdef CFG_RATCHET_BENCH
 79CRATE_TEST_EXTRA_ARGS=\
 80  --test $(TEST_BENCH) \
 81  --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
 82  --ratchet-noise-percent $(TEST_RATCHET_NOISE_PERCENT)
 83else
 84CRATE_TEST_EXTRA_ARGS=\
 85  --test $(TEST_BENCH) \
 86  --save-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4))
 87endif
 88
 89# If we're sharding the testsuite between parallel testers,
 90# pass this argument along to the compiletest and crate test
 91# invocations.
 92ifdef TEST_SHARD
 93  CTEST_TESTARGS += --test-shard=$(TEST_SHARD)
 94  CRATE_TEST_EXTRA_ARGS += --test-shard=$(TEST_SHARD)
 95endif
 96
 97define DEF_TARGET_COMMANDS
 98
 99ifdef CFG_UNIXY_$(1)
100  CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
101endif
102
103ifdef CFG_WINDOWSY_$(1)
104  CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
105   $$(if $$(findstring stage0,$$(1)), \
106       stage0/$$(CFG_LIBDIR_RELATIVE), \
107      $$(if $$(findstring stage1,$$(1)), \
108           stage1/$$(CFG_LIBDIR_RELATIVE), \
109          $$(if $$(findstring stage2,$$(1)), \
110               stage2/$$(CFG_LIBDIR_RELATIVE), \
111               $$(if $$(findstring stage3,$$(1)), \
112                    stage3/$$(CFG_LIBDIR_RELATIVE), \
113               )))))/$$(CFG_RUSTLIBDIR)/$$(CFG_BUILD)/lib
114  CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(3)),$$(1))
115endif
116
117# Run the compiletest runner itself under valgrind
118ifdef CTEST_VALGRIND
119CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
120      $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(2),$$(3))
121else
122CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
123      $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
124endif
125
126endef
127
128$(foreach target,$(CFG_TARGET), \
129  $(eval $(call DEF_TARGET_COMMANDS,$(target))))
130
131# Target platform specific variables
132# for arm-linux-androidabi
133define DEF_ADB_DEVICE_STATUS
134CFG_ADB_DEVICE_STATUS=$(1)
135endef
136
137$(foreach target,$(CFG_TARGET), \
138  $(if $(findstring $(target),"arm-linux-androideabi"), \
139    $(if $(findstring adb,$(CFG_ADB)), \
140      $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
141        $(info check: android device attached) \
142        $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
143        $(info check: android device not attached) \
144        $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
145      ), \
146      $(info check: adb not found) \
147      $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
148    ), \
149  ) \
150)
151
152ifeq ($(CFG_ADB_DEVICE_STATUS),true)
153CFG_ADB_TEST_DIR=/data/tmp
154
155$(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
156 $(shell $(CFG_ADB) remount 1>/dev/null) \
157 $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
158 $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
159 $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/tmp) \
160 $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
161 $(foreach crate,$(TARGET_CRATES),\
162    $(shell $(CFG_ADB) push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_arm-linux-androideabi,$(crate)) \
163                    $(CFG_ADB_TEST_DIR)))\
164 )
165else
166CFG_ADB_TEST_DIR=
167endif
168
169
170######################################################################
171# Main test targets
172######################################################################
173
174check: cleantestlibs cleantmptestlogs tidy all check-stage2
175	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
176
177check-notidy: cleantestlibs cleantmptestlogs all check-stage2
178	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
179
180check-full: cleantestlibs cleantmptestlogs tidy \
181            all check-stage1 check-stage2 check-stage3
182	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
183
184check-test: cleantestlibs cleantmptestlogs all check-stage2-rfail
185	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
186
187check-lite: cleantestlibs cleantmptestlogs \
188	$(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
189	check-stage2-rpass \
190	check-stage2-rfail check-stage2-cfail check-stage2-rmake
191	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
192
193.PHONY: cleantmptestlogs cleantestlibs
194
195cleantmptestlogs:
196	$(Q)rm -f tmp/*.log
197
198cleantestlibs:
199	$(Q)find $(CFG_BUILD)/test \
200         -name '*.[odasS]' -o \
201         -name '*.so' -o      \
202         -name '*.dylib' -o   \
203         -name '*.dll' -o     \
204         -name '*.def' -o     \
205         -name '*.bc' -o      \
206         -name '*.dSYM' -o    \
207         -name '*.libaux' -o      \
208         -name '*.out' -o     \
209         -name '*.err' -o     \
210	 -name '*.debugger.script' \
211         | xargs rm -rf
212
213
214######################################################################
215# Tidy
216######################################################################
217
218ifdef CFG_NOTIDY
219tidy:
220else
221
222ALL_CS := $(wildcard $(S)src/rt/*.cpp \
223                     $(S)src/rt/*/*.cpp \
224                     $(S)src/rt/*/*/*.cpp \
225                     $(S)src/rustllvm/*.cpp)
226ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
227		       $(wildcard $(S)src/rt/sundown/src/*.c) \
228		       $(wildcard $(S)src/rt/sundown/html/*.c) \
229	,$(ALL_CS))
230ALL_HS := $(wildcard $(S)src/rt/*.h \
231                     $(S)src/rt/*/*.h \
232                     $(S)src/rt/*/*/*.h \
233                     $(S)src/rustllvm/*.h)
234ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
235                       $(S)src/rt/vg/memcheck.h \
236                       $(S)src/rt/msvc/typeof.h \
237                       $(S)src/rt/msvc/stdint.h \
238                       $(S)src/rt/msvc/inttypes.h \
239		       $(wildcard $(S)src/rt/sundown/src/*.h) \
240		       $(wildcard $(S)src/rt/sundown/html/*.h) \
241	,$(ALL_HS))
242
243# Run the tidy script in multiple parts to avoid huge 'echo' commands
244tidy:
245		@$(call E, check: formatting)
246		$(Q)find $(S)src -name '*.r[sc]' \
247		| grep '^$(S)src/libuv' -v \
248		| grep '^$(S)src/llvm' -v \
249		| grep '^$(S)src/gyp' -v \
250		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
251		$(Q)find $(S)src/etc -name '*.py' \
252		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
253		$(Q)echo $(ALL_CS) \
254		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
255		$(Q)echo $(ALL_HS) \
256		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
257		$(Q)find $(S)src -type f -perm +111 \
258		    -not -name '*.rs' -and -not -name '*.py' \
259		    -and -not -name '*.sh' \
260		| grep '^$(S)src/llvm' -v \
261		| grep '^$(S)src/libuv' -v \
262		| grep '^$(S)src/gyp' -v \
263		| grep '^$(S)src/etc' -v \
264		| grep '^$(S)src/doc' -v \
265		| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
266
267endif
268
269
270######################################################################
271# Sets of tests
272######################################################################
273
274define DEF_TEST_SETS
275
276check-stage$(1)-T-$(2)-H-$(3)-exec:     				\
277	check-stage$(1)-T-$(2)-H-$(3)-rpass-exec			\
278	check-stage$(1)-T-$(2)-H-$(3)-rfail-exec			\
279	check-stage$(1)-T-$(2)-H-$(3)-cfail-exec			\
280	check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec			\
281	check-stage$(1)-T-$(2)-H-$(3)-rmake-exec			\
282        check-stage$(1)-T-$(2)-H-$(3)-crates-exec                       \
283        check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec                   \
284	check-stage$(1)-T-$(2)-H-$(3)-bench-exec			\
285	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-exec \
286	check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
287	check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
288	check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
289
290# Only test the compiler-dependent crates when the target is
291# able to build a compiler (when the target triple is in the set of host triples)
292ifneq ($$(findstring $(2),$$(CFG_HOST)),)
293
294check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
295	$$(foreach crate,$$(TEST_CRATES), \
296           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
297
298else
299
300check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
301	$$(foreach crate,$$(TEST_TARGET_CRATES), \
302           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
303
304endif
305
306check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
307        $$(foreach crate,$$(TEST_DOC_CRATES), \
308           check-stage$(1)-T-$(2)-H-$(3)-doc-$$(crate)-exec)
309
310check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
311        $$(foreach docname,$$(DOC_TEST_NAMES), \
312           check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec)
313
314check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
315	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec	\
316	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec	\
317	check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec	\
318	check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec	\
319	check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
320
321endef
322
323$(foreach host,$(CFG_HOST), \
324 $(foreach target,$(CFG_TARGET), \
325  $(foreach stage,$(STAGES), \
326    $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))
327
328
329######################################################################
330# Crate testing
331######################################################################
332
333define TEST_RUNNER
334
335# If NO_REBUILD is set then break the dependencies on extra so we can
336# test crates without rebuilding std and extra first
337ifeq ($(NO_REBUILD),)
338STDTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
339			    $$(foreach crate,$$(TARGET_CRATES),\
340				$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate))
341else
342STDTESTDEP_$(1)_$(2)_$(3)_$(4) =
343endif
344
345$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER = $(2)
346$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)):				\
347		$$(CRATEFILE_$(4))					\
348		$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))		\
349		$$(STDTESTDEP_$(1)_$(2)_$(3)_$(4))
350	@$$(call E, oxidize: $$@)
351	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test	\
352		-L "$$(RT_OUTPUT_DIR_$(2))"		\
353		-L "$$(LLVM_LIBDIR_$(2))"
354
355endef
356
357$(foreach host,$(CFG_HOST), \
358 $(eval $(foreach target,$(CFG_TARGET), \
359  $(eval $(foreach stage,$(STAGES), \
360   $(eval $(foreach crate,$(TEST_CRATES), \
361    $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
362
363define DEF_TEST_CRATE_RULES
364check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
365
366check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
367
368$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
369		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
370	@$$(call E, run: $$<)
371	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) $$(TESTARGS) \
372	    --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
373	    $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
374	    && touch $$@
375endef
376
377define DEF_TEST_CRATE_RULES_arm-linux-androideabi
378check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
379
380$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
381		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
382	@$$(call E, run: $$< via adb)
383	$$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
384	$$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
385		./$$(notdir $$<) \
386		--logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
387		$$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
388		> tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
389	$$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
390	$$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
391	$$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
392	$$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
393	$$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/$$(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) tmp/
394	@if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
395	then \
396		rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
397		touch $$@; \
398	else \
399		rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
400		exit 101; \
401	fi
402endef
403
404define DEF_TEST_CRATE_RULES_null
405check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
406
407$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
408		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
409	@$$(call E, failing: no device for $$< )
410	false
411endef
412
413$(foreach host,$(CFG_HOST), \
414 $(foreach target,$(CFG_TARGET), \
415  $(foreach stage,$(STAGES), \
416   $(foreach crate, $(TEST_CRATES), \
417    $(if $(findstring $(target),$(CFG_BUILD)), \
418     $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
419     $(if $(findstring $(target),"arm-linux-androideabi"), \
420      $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
421       $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
422       $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
423      ), \
424      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
425     ))))))
426
427######################################################################
428# Rules for the compiletest tests (rpass, rfail, etc.)
429######################################################################
430
431RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
432RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
433RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
434RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
435RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
436RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
437CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
438CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
439BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
440PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
441DEBUGINFO_RS := $(wildcard $(S)src/test/debug-info/*.rs)
442CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
443CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
444
445# perf tests are the same as bench tests only they run under
446# a performance monitor.
447PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
448
449RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
450RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
451RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
452CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
453BENCH_TESTS := $(BENCH_RS)
454PERF_TESTS := $(PERF_RS)
455PRETTY_TESTS := $(PRETTY_RS)
456DEBUGINFO_TESTS := $(DEBUGINFO_RS)
457CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
458
459CTEST_SRC_BASE_rpass = run-pass
460CTEST_BUILD_BASE_rpass = run-pass
461CTEST_MODE_rpass = run-pass
462CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
463
464CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
465CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
466CTEST_MODE_rpass-full = run-pass
467CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
468
469CTEST_SRC_BASE_rfail = run-fail
470CTEST_BUILD_BASE_rfail = run-fail
471CTEST_MODE_rfail = run-fail
472CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
473
474CTEST_SRC_BASE_cfail = compile-fail
475CTEST_BUILD_BASE_cfail = compile-fail
476CTEST_MODE_cfail = compile-fail
477CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
478
479CTEST_SRC_BASE_bench = bench
480CTEST_BUILD_BASE_bench = bench
481CTEST_MODE_bench = run-pass
482CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
483
484CTEST_SRC_BASE_perf = bench
485CTEST_BUILD_BASE_perf = perf
486CTEST_MODE_perf = run-pass
487CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
488
489CTEST_SRC_BASE_debuginfo = debug-info
490CTEST_BUILD_BASE_debuginfo = debug-info
491CTEST_MODE_debuginfo = debug-info
492CTEST_RUNTOOL_debuginfo = $(CTEST_RUNTOOL)
493
494CTEST_SRC_BASE_codegen = codegen
495CTEST_BUILD_BASE_codegen = codegen
496CTEST_MODE_codegen = codegen
497CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
498
499ifeq ($(CFG_GDB),)
500CTEST_DISABLE_debuginfo = "no gdb found"
501endif
502
503ifeq ($(CFG_CLANG),)
504CTEST_DISABLE_codegen = "no clang found"
505endif
506
507ifeq ($(CFG_OSTYPE),apple-darwin)
508CTEST_DISABLE_debuginfo = "gdb on darwing needs root"
509endif
510
511define DEF_CTEST_VARS
512
513# All the per-stage build rules you might want to call from the
514# command line.
515#
516# $(1) is the stage number
517# $(2) is the target triple to test
518# $(3) is the host triple to test
519
520# Prerequisites for compiletest tests
521TEST_SREQ$(1)_T_$(2)_H_$(3) = \
522	$$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
523	$$(SREQ$(1)_T_$(2)_H_$(3))
524
525# Rules for the cfail/rfail/rpass/bench/perf test runner
526
527# The tests select when to use debug configuration on their own;
528# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
529CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
530
531# There's no need our entire test suite to take up gigabytes of space on disk
532# including copies of libstd/libextra all over the place
533CTEST_RUSTC_FLAGS := $$(CTEST_RUSTC_FLAGS) -C prefer-dynamic
534
535# The tests can not be optimized while the rest of the compiler is optimized, so
536# filter out the optimization (if any) from rustc and then figure out if we need
537# to be optimized
538CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
539ifndef CFG_DISABLE_OPTIMIZE_TESTS
540CTEST_RUSTC_FLAGS += -O
541endif
542
543CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) :=						\
544		--compile-lib-path $$(HLIB$(1)_H_$(3))				\
545        --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3))			\
546        --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))			\
547        --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
548        --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
549        --aux-base $$(S)src/test/auxiliary/                 \
550        --stage-id stage$(1)-$(2)							\
551        --target $(2)                                       \
552        --host $(3)                                       \
553        --adb-path=$(CFG_ADB)                          \
554        --adb-test-dir=$(CFG_ADB_TEST_DIR)                  \
555        --rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
556        $$(CTEST_TESTARGS)
557
558CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
559CTEST_DEPS_rpass_full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
560CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
561CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
562CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
563CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
564CTEST_DEPS_debuginfo_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_TESTS)
565CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
566
567endef
568
569$(foreach host,$(CFG_HOST), \
570 $(eval $(foreach target,$(CFG_TARGET), \
571  $(eval $(foreach stage,$(STAGES), \
572   $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
573
574define DEF_RUN_COMPILETEST
575
576CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
577        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
578        --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
579        --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
580        --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
581        --mode $$(CTEST_MODE_$(4)) \
582	$$(CTEST_RUNTOOL_$(4))
583
584check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
585
586ifeq ($$(CTEST_DISABLE_$(4)),)
587
588$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
589		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
590                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
591	@$$(call E, run $(4) [$(2)]: $$<)
592	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
593		$$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
594		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
595                && touch $$@
596
597else
598
599$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
600		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
601                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
602	@$$(call E, run $(4) [$(2)]: $$<)
603	@$$(call E, warning: tests disabled: $$(CTEST_DISABLE_$(4)))
604	touch $$@
605
606endif
607
608endef
609
610CTEST_NAMES = rpass rpass-full rfail cfail bench perf debuginfo codegen
611
612$(foreach host,$(CFG_HOST), \
613 $(eval $(foreach target,$(CFG_TARGET), \
614  $(eval $(foreach stage,$(STAGES), \
615   $(eval $(foreach name,$(CTEST_NAMES), \
616   $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
617
618PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
619PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
620PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
621PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
622PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
623PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
624PRETTY_DIRNAME_pretty-rpass = run-pass
625PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
626PRETTY_DIRNAME_pretty-rfail = run-fail
627PRETTY_DIRNAME_pretty-bench = bench
628PRETTY_DIRNAME_pretty-pretty = pretty
629
630define DEF_RUN_PRETTY_TEST
631
632PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) :=			\
633		$$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
634        --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
635        --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
636        --mode pretty
637
638check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
639
640$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
641	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))		\
642	        $$(PRETTY_DEPS_$(4))
643	@$$(call E, run pretty-rpass [$(2)]: $$<)
644	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
645		$$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
646		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
647                && touch $$@
648
649endef
650
651$(foreach host,$(CFG_HOST), \
652 $(foreach target,$(CFG_TARGET), \
653  $(foreach stage,$(STAGES), \
654   $(foreach pretty-name,$(PRETTY_NAMES), \
655    $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
656
657define DEF_RUN_DOC_TEST
658
659DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-doc-$(4) := \
660        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
661        --src-base $(3)/test/doc-$(4)/	\
662        --build-base $(3)/test/doc-$(4)/	\
663        --mode run-pass
664
665check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
666
667$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): \
668	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))		\
669                doc-$(4)-extract$(3)
670	@$$(call E, run doc-$(4) [$(2)]: $$<)
671	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
672                $$(DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-doc-$(4)) \
673		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),doc-$(4)) \
674                && touch $$@
675
676endef
677
678$(foreach host,$(CFG_HOST), \
679 $(foreach target,$(CFG_TARGET), \
680  $(foreach stage,$(STAGES), \
681   $(foreach docname,$(DOC_TEST_NAMES), \
682    $(eval $(call DEF_RUN_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
683
684define DEF_CRATE_DOC_TEST
685
686check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
687
688ifeq ($(2),$$(CFG_BUILD))
689$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):				\
690	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))				\
691		$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))		\
692		$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
693	@$$(call E, run doc-$(4) [$(2)])
694	$$(Q)$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) --test \
695	    $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
696else
697$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
698	touch $$@
699endif
700
701endef
702
703$(foreach host,$(CFG_HOST), \
704 $(foreach target,$(CFG_TARGET), \
705  $(foreach stage,$(STAGES), \
706   $(foreach crate,$(TEST_DOC_CRATES), \
707    $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
708
709######################################################################
710# Extracting tests for docs
711######################################################################
712
713EXTRACT_TESTS := "$(CFG_PYTHON)" $(S)src/etc/extract-tests.py
714
715define DEF_DOC_TEST_HOST
716
717doc-$(2)-extract$(1):
718	@$$(call E, extract: $(2) tests)
719	$$(Q)rm -f $(1)/test/doc-$(2)/*.rs
720	$$(Q)$$(EXTRACT_TESTS) $$(D)/$(2).md $(1)/test/doc-$(2)
721
722endef
723
724$(foreach host,$(CFG_HOST), \
725 $(foreach docname,$(DOC_TEST_NAMES), \
726  $(eval $(call DEF_DOC_TEST_HOST,$(host),$(docname)))))
727
728
729######################################################################
730# Shortcut rules
731######################################################################
732
733TEST_GROUPS = \
734	crates \
735	$(foreach crate,$(TEST_CRATES),$(crate)) \
736	$(foreach crate,$(TEST_DOC_CRATES),doc-$(crate)) \
737	rpass \
738	rpass-full \
739	rfail \
740	cfail \
741	bench \
742	perf \
743	rmake \
744	debuginfo \
745	codegen \
746	doc \
747	$(foreach docname,$(DOC_TEST_NAMES),doc-$(docname)) \
748	pretty \
749	pretty-rpass \
750	pretty-rpass-full \
751	pretty-rfail \
752	pretty-bench \
753	pretty-pretty \
754	$(NULL)
755
756define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
757check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
758endef
759
760$(foreach stage,$(STAGES), \
761 $(foreach target,$(CFG_TARGET), \
762  $(foreach host,$(CFG_HOST), \
763   $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
764
765define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
766check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
767endef
768
769$(foreach stage,$(STAGES), \
770 $(foreach target,$(CFG_TARGET), \
771  $(foreach host,$(CFG_HOST), \
772   $(foreach group,$(TEST_GROUPS), \
773    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
774
775define DEF_CHECK_FOR_STAGE
776check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
777check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
778                           check-stage$(1)-H-$$(target))
779endef
780
781$(foreach stage,$(STAGES), \
782 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
783
784define DEF_CHECK_FOR_STAGE_AND_GROUP
785check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
786check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
787                               check-stage$(1)-H-$$(target)-$(2))
788endef
789
790$(foreach stage,$(STAGES), \
791 $(foreach group,$(TEST_GROUPS), \
792  $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
793
794
795define DEF_CHECK_FOR_STAGE_AND_HOSTS
796check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
797                           check-stage$(1)-T-$$(target)-H-$(2))
798endef
799
800$(foreach stage,$(STAGES), \
801 $(foreach host,$(CFG_HOST), \
802  $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
803
804define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
805check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
806                                check-stage$(1)-T-$$(target)-H-$(2)-$(3))
807endef
808
809$(foreach stage,$(STAGES), \
810 $(foreach host,$(CFG_HOST), \
811  $(foreach group,$(TEST_GROUPS), \
812   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
813
814######################################################################
815# check-fast rules
816######################################################################
817
818FT := run_pass_stage2
819FT_LIB := $(call CFG_LIB_NAME_$(CFG_BUILD),$(FT))
820FT_DRIVER := $(FT)_driver
821
822GENERATED += tmp/$(FT).rc tmp/$(FT_DRIVER).rs
823
824tmp/$(FT).rc tmp/$(FT_DRIVER).rs: \
825		$(RPASS_TESTS) \
826		$(S)src/etc/combine-tests.py
827	@$(call E, check: building combined stage2 test runner)
828	$(Q)$(CFG_PYTHON) $(S)src/etc/combine-tests.py
829
830define DEF_CHECK_FAST_FOR_T_H
831# $(1) unused
832# $(2) target triple
833# $(3) host triple
834
835$$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB): \
836		tmp/$$(FT).rc \
837		$$(SREQ2_T_$(2)_H_$(3))
838	@$$(call E, oxidize: $$@)
839	$$(STAGE2_T_$(2)_H_$(3)) --crate-type=dylib --out-dir $$(@D) $$< \
840	  -L "$$(RT_OUTPUT_DIR_$(2))"
841
842$(3)/test/$$(FT_DRIVER)-$(2)$$(X_$(2)): \
843		tmp/$$(FT_DRIVER).rs \
844		$$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB) \
845		$$(SREQ2_T_$(2)_H_$(3))
846	@$$(call E, oxidize: $$@ $$<)
847	$$(STAGE2_T_$(2)_H_$(3)) -o $$@ $$< \
848	  -L "$$(RT_OUTPUT_DIR_$(2))"
849
850$(3)/test/$$(FT_DRIVER)-$(2).out: \
851		$(3)/test/$$(FT_DRIVER)-$(2)$$(X_$(2)) \
852		$$(SREQ2_T_$(2)_H_$(3))
853	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) \
854	--logfile tmp/$$(FT_DRIVER)-$(2).log
855
856check-fast-T-$(2)-H-$(3):     			\
857	$(3)/test/$$(FT_DRIVER)-$(2).out
858
859endef
860
861$(foreach host,$(CFG_HOST), \
862 $(eval $(foreach target,$(CFG_TARGET), \
863   $(eval $(call DEF_CHECK_FAST_FOR_T_H,,$(target),$(host))))))
864
865check-fast: tidy check-fast-H-$(CFG_BUILD) \
866	    $(foreach crate,$(TARGET_CRATES),check-stage2-$(crate))
867	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
868
869define DEF_CHECK_FAST_FOR_H
870
871check-fast-H-$(1): 		check-fast-T-$(1)-H-$(1)
872
873endef
874
875$(foreach host,$(CFG_HOST),			\
876 $(eval $(call DEF_CHECK_FAST_FOR_H,$(host))))
877
878RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
879RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
880
881define DEF_RMAKE_FOR_T_H
882# $(1) the stage
883# $(2) target triple
884# $(3) host triple
885
886
887ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
888check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
889		$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
890
891$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
892		$$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
893	@touch $$@
894
895$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
896		$(S)src/test/run-make/%/Makefile \
897		$$(CSREQ$(1)_T_$(2)_H_$(3))
898	@rm -rf $(3)/test/run-make/$$*
899	@mkdir -p $(3)/test/run-make/$$*
900	$$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
901	    $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
902	    $(3)/test/run-make/$$* \
903	    "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
904	    $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
905	    "$$(TESTNAME)"
906	@touch $$@
907else
908# FIXME #11094 - The above rule doesn't work right for multiple targets
909check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
910	@true
911
912endif
913
914
915endef
916
917$(foreach stage,$(STAGES), \
918 $(foreach target,$(CFG_TARGET), \
919  $(foreach host,$(CFG_HOST), \
920   $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))