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.
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.
12 ######################################################################
14 ######################################################################
16 # The names of crates that must be tested
17 TEST_TARGET_CRATES = $(TARGET_CRATES)
18 TEST_DOC_CRATES = $(DOC_CRATES)
19 TEST_HOST_CRATES = $(HOST_CRATES)
20 TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
22 ######################################################################
23 # Environment configuration
24 ######################################################################
26 # The arguments to all test runners
28 TESTARGS += $(TESTNAME)
37 # Arguments to the cfail/rfail/rpass/bench tests
39 CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
47 # Arguments to the perf tests
49 CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
52 CTEST_TESTARGS := $(TESTARGS)
55 CTEST_TESTARGS += --verbose
58 # If we're running perf then set this environment variable
59 # to put the benchmarks into 'hard mode'
60 ifeq ($(MAKECMDGOALS),perf)
65 TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
66 TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
68 TEST_RATCHET_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4)-metrics.json
69 TEST_RATCHET_NOISE_PERCENT=10.0
71 # Whether to ratchet or merely save benchmarks
72 ifdef CFG_RATCHET_BENCH
73 CRATE_TEST_EXTRA_ARGS=\
74 --test $(TEST_BENCH) \
75 --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
76 --ratchet-noise-percent $(TEST_RATCHET_NOISE_PERCENT)
78 CRATE_TEST_EXTRA_ARGS=\
79 --test $(TEST_BENCH) \
80 --save-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4))
83 # If we're sharding the testsuite between parallel testers,
84 # pass this argument along to the compiletest and crate test
87 CTEST_TESTARGS += --test-shard=$(TEST_SHARD)
88 CRATE_TEST_EXTRA_ARGS += --test-shard=$(TEST_SHARD)
91 define DEF_TARGET_COMMANDS
94 CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
95 $$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
98 ifdef CFG_WINDOWSY_$(1)
99 CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
100 $$(if $$(findstring stage0,$$(1)), \
101 stage0/$$(CFG_LIBDIR_RELATIVE), \
102 $$(if $$(findstring stage1,$$(1)), \
103 stage1/$$(CFG_LIBDIR_RELATIVE), \
104 $$(if $$(findstring stage2,$$(1)), \
105 stage2/$$(CFG_LIBDIR_RELATIVE), \
106 $$(if $$(findstring stage3,$$(1)), \
107 stage3/$$(CFG_LIBDIR_RELATIVE), \
108 )))))/rustlib/$$(CFG_BUILD)/lib
109 CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(4)),$$(1))
112 # Run the compiletest runner itself under valgrind
114 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
115 $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(3),$$(4))
117 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
118 $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
123 $(foreach target,$(CFG_TARGET), \
124 $(eval $(call DEF_TARGET_COMMANDS,$(target))))
126 # Target platform specific variables
127 # for arm-linux-androidabi
128 define DEF_ADB_DEVICE_STATUS
129 CFG_ADB_DEVICE_STATUS=$(1)
132 $(foreach target,$(CFG_TARGET), \
133 $(if $(findstring $(target),"arm-linux-androideabi"), \
134 $(if $(findstring adb,$(CFG_ADB)), \
135 $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
136 $(info check: android device attached) \
137 $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
138 $(info check: android device not attached) \
139 $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
141 $(info check: adb not found) \
142 $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
147 ifeq ($(CFG_ADB_DEVICE_STATUS),true)
148 CFG_ADB_TEST_DIR=/data/tmp
150 $(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
151 $(shell $(CFG_ADB) remount 1>/dev/null) \
152 $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
153 $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
154 $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/tmp) \
155 $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
156 $(foreach crate,$(TARGET_CRATES),\
157 $(shell $(CFG_ADB) push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_arm-linux-androideabi,$(crate)) \
158 $(CFG_ADB_TEST_DIR)))\
165 ######################################################################
167 ######################################################################
169 check: cleantmptestlogs cleantestlibs tidy check-notidy
171 check-notidy: cleantmptestlogs cleantestlibs all check-stage2
172 $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
174 check-lite: cleantestlibs cleantmptestlogs \
175 $(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
177 check-stage2-rfail check-stage2-cfail check-stage2-rmake
178 $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
180 check-ref: cleantestlibs cleantmptestlogs check-stage2-rpass \
181 check-stage2-rfail check-stage2-cfail check-stage2-rmake
182 $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
184 check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
185 $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
187 # NOTE: Remove after reprogramming windows bots
188 check-fast: check-lite
190 .PHONY: cleantmptestlogs cleantestlibs
196 $(Q)find $(CFG_BUILD)/test \
197 -name '*.[odasS]' -o \
204 -name '*.libaux' -o \
207 -name '*.debugger.script' \
211 ######################################################################
213 ######################################################################
219 ALL_CS := $(wildcard $(S)src/rt/*.cpp \
221 $(S)src/rt/*/*/*.cpp \
222 $(S)src/rustllvm/*.cpp)
223 ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
224 $(wildcard $(S)src/rt/hoedown/src/*.c) \
225 $(wildcard $(S)src/rt/hoedown/bin/*.c) \
227 ALL_HS := $(wildcard $(S)src/rt/*.h \
230 $(S)src/rustllvm/*.h)
231 ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
232 $(S)src/rt/valgrind/memcheck.h \
233 $(S)src/rt/msvc/typeof.h \
234 $(S)src/rt/msvc/stdint.h \
235 $(S)src/rt/msvc/inttypes.h \
236 $(wildcard $(S)src/rt/hoedown/src/*.h) \
237 $(wildcard $(S)src/rt/hoedown/bin/*.h) \
240 # Run the tidy script in multiple parts to avoid huge 'echo' commands
242 @$(call E, check: formatting)
243 $(Q)find $(S)src -name '*.r[sc]' \
244 | grep '^$(S)src/jemalloc' -v \
245 | grep '^$(S)src/libuv' -v \
246 | grep '^$(S)src/llvm' -v \
247 | grep '^$(S)src/gyp' -v \
248 | grep '^$(S)src/libbacktrace' -v \
249 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
250 $(Q)find $(S)src/etc -name '*.py' \
251 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
252 $(Q)find $(S)src/doc -name '*.js' \
253 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
254 $(Q)find $(S)src/etc -name '*.sh' \
255 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
256 $(Q)find $(S)src/etc -name '*.pl' \
257 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
258 $(Q)find $(S)src/etc -name '*.c' \
259 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
260 $(Q)find $(S)src/etc -name '*.h' \
261 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
263 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
265 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
266 $(Q)find $(S)src -type f -perm +111 \
267 -not -name '*.rs' -and -not -name '*.py' \
268 -and -not -name '*.sh' \
269 | grep '^$(S)src/jemalloc' -v \
270 | grep '^$(S)src/libuv' -v \
271 | grep '^$(S)src/llvm' -v \
272 | grep '^$(S)src/rt/hoedown' -v \
273 | grep '^$(S)src/gyp' -v \
274 | grep '^$(S)src/etc' -v \
275 | grep '^$(S)src/doc' -v \
276 | grep '^$(S)src/compiler-rt' -v \
277 | grep '^$(S)src/libbacktrace' -v \
278 | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
283 ######################################################################
285 ######################################################################
289 check-stage$(1)-T-$(2)-H-$(3)-exec: \
290 check-stage$(1)-T-$(2)-H-$(3)-rpass-exec \
291 check-stage$(1)-T-$(2)-H-$(3)-rfail-exec \
292 check-stage$(1)-T-$(2)-H-$(3)-cfail-exec \
293 check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
294 check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
295 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
296 check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
297 check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
298 check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
299 check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
300 check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
301 check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
302 check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
303 check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
305 # Only test the compiler-dependent crates when the target is
306 # able to build a compiler (when the target triple is in the set of host triples)
307 ifneq ($$(findstring $(2),$$(CFG_HOST)),)
309 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
310 $$(foreach crate,$$(TEST_CRATES), \
311 check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
315 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
316 $$(foreach crate,$$(TEST_TARGET_CRATES), \
317 check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
321 check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
322 $$(foreach crate,$$(TEST_DOC_CRATES), \
323 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec)
325 check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
326 $$(foreach docname,$$(DOCS), \
327 check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec)
329 check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
330 check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
331 check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec \
332 check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
333 check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
334 check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
338 $(foreach host,$(CFG_HOST), \
339 $(foreach target,$(CFG_TARGET), \
340 $(foreach stage,$(STAGES), \
341 $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))
344 ######################################################################
346 ######################################################################
350 # If NO_REBUILD is set then break the dependencies on everything but
351 # the source files so we can test crates without rebuilding any of the
353 ifeq ($(NO_REBUILD),)
354 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
355 $$(foreach crate,$$(TARGET_CRATES),\
356 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
357 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))
359 # The regex crate depends on the regex_macros crate during testing, but it
360 # notably depend on the *host* regex_macros crate, not the target version.
361 # Additionally, this is not a dependency in stage1, only in stage2.
364 TESTDEP_$(1)_$(2)_$(3)_$(4) += $$(TLIB$(1)_T_$(3)_H_$(3))/stamp.regex_macros
369 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
372 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
373 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \
375 $$(TESTDEP_$(1)_$(2)_$(3)_$(4))
376 @$$(call E, rustc: $$@)
377 $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test \
378 -L "$$(RT_OUTPUT_DIR_$(2))" \
379 -L "$$(LLVM_LIBDIR_$(2))"
383 $(foreach host,$(CFG_HOST), \
384 $(eval $(foreach target,$(CFG_TARGET), \
385 $(eval $(foreach stage,$(STAGES), \
386 $(eval $(foreach crate,$(TEST_CRATES), \
387 $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
389 define DEF_TEST_CRATE_RULES
390 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
392 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
393 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
394 @$$(call E, run: $$<)
395 $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
396 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
397 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
401 define DEF_TEST_CRATE_RULES_arm-linux-androideabi
402 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
404 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
405 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
406 @$$(call E, run: $$< via adb)
407 $$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
408 $$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
410 --logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
411 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
412 > tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
413 $$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
414 $$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
415 $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
416 $$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
417 $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/$$(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) tmp/
418 @if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
420 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
423 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
428 define DEF_TEST_CRATE_RULES_null
429 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
431 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
432 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
433 @$$(call E, failing: no device for $$< )
437 $(foreach host,$(CFG_HOST), \
438 $(foreach target,$(CFG_TARGET), \
439 $(foreach stage,$(STAGES), \
440 $(foreach crate, $(TEST_CRATES), \
441 $(if $(findstring $(target),$(CFG_BUILD)), \
442 $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
443 $(if $(findstring $(target),"arm-linux-androideabi"), \
444 $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
445 $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
446 $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
448 $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
451 ######################################################################
452 # Rules for the compiletest tests (rpass, rfail, etc.)
453 ######################################################################
455 RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
456 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
457 RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
458 RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
459 CFAIL_FULL_RC := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rc)
460 CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
461 RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
462 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
463 CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
464 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
465 BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
466 PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
467 DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
468 DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
469 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
470 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
472 # perf tests are the same as bench tests only they run under
473 # a performance monitor.
474 PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
476 RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
477 RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
478 CFAIL_FULL_TESTS := $(CFAIL_FULL_RC) $(CFAIL_FULL_RS)
479 RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
480 CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
481 BENCH_TESTS := $(BENCH_RS)
482 PERF_TESTS := $(PERF_RS)
483 PRETTY_TESTS := $(PRETTY_RS)
484 DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
485 DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
486 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
488 CTEST_SRC_BASE_rpass = run-pass
489 CTEST_BUILD_BASE_rpass = run-pass
490 CTEST_MODE_rpass = run-pass
491 CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
493 CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
494 CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
495 CTEST_MODE_rpass-full = run-pass
496 CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
498 CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
499 CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
500 CTEST_MODE_cfail-full = compile-fail
501 CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)
503 CTEST_SRC_BASE_rfail = run-fail
504 CTEST_BUILD_BASE_rfail = run-fail
505 CTEST_MODE_rfail = run-fail
506 CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
508 CTEST_SRC_BASE_cfail = compile-fail
509 CTEST_BUILD_BASE_cfail = compile-fail
510 CTEST_MODE_cfail = compile-fail
511 CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
513 CTEST_SRC_BASE_bench = bench
514 CTEST_BUILD_BASE_bench = bench
515 CTEST_MODE_bench = run-pass
516 CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
518 CTEST_SRC_BASE_perf = bench
519 CTEST_BUILD_BASE_perf = perf
520 CTEST_MODE_perf = run-pass
521 CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
523 CTEST_SRC_BASE_debuginfo-gdb = debuginfo
524 CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
525 CTEST_MODE_debuginfo-gdb = debuginfo-gdb
526 CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)
528 CTEST_SRC_BASE_debuginfo-lldb = debuginfo
529 CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
530 CTEST_MODE_debuginfo-lldb = debuginfo-lldb
531 CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
533 CTEST_SRC_BASE_codegen = codegen
534 CTEST_BUILD_BASE_codegen = codegen
535 CTEST_MODE_codegen = codegen
536 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
538 # CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
539 # disabled and the associated message to be printed as a warning
540 # during attempts to run those tests.
543 CTEST_DISABLE_debuginfo-gdb = "no gdb found"
547 CTEST_DISABLE_debuginfo-lldb = "no lldb found"
550 # Completely disable LLDB tests for now
551 CTEST_DISABLE_debuginfo-lldb = "LLDB tests are not enabled yet"
554 CTEST_DISABLE_codegen = "no clang found"
557 ifeq ($(CFG_OSTYPE),apple-darwin)
558 CTEST_DISABLE_debuginfo-gdb = "gdb on darwing needs root"
561 # CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
562 # test group to be disabled *unless* the target is able to build a
563 # compiler (i.e. when the target triple is in the set of of host
564 # triples). The associated message will be printed as a warning
565 # during attempts to run those tests.
567 define DEF_CTEST_VARS
569 # All the per-stage build rules you might want to call from the
572 # $(1) is the stage number
573 # $(2) is the target triple to test
574 # $(3) is the host triple to test
576 # Prerequisites for compiletest tests
577 TEST_SREQ$(1)_T_$(2)_H_$(3) = \
578 $$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
579 $$(SREQ$(1)_T_$(2)_H_$(3))
581 # Rules for the cfail/rfail/rpass/bench/perf test runner
583 # The tests select when to use debug configuration on their own;
584 # remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
585 CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
587 # The tests can not be optimized while the rest of the compiler is optimized, so
588 # filter out the optimization (if any) from rustc and then figure out if we need
590 CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
591 ifndef CFG_DISABLE_OPTIMIZE_TESTS
592 CTEST_RUSTC_FLAGS += -O
595 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
596 --compile-lib-path $$(HLIB$(1)_H_$(3)) \
597 --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
598 --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
599 --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
600 --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
601 --aux-base $$(S)src/test/auxiliary/ \
602 --stage-id stage$(1)-$(2) \
605 --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
606 --adb-path=$(CFG_ADB) \
607 --adb-test-dir=$(CFG_ADB_TEST_DIR) \
608 --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
609 --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
610 --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
613 CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
614 CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
615 CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
616 CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
617 CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
618 CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
619 CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
620 CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
621 CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS)
622 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
626 $(foreach host,$(CFG_HOST), \
627 $(eval $(foreach target,$(CFG_TARGET), \
628 $(eval $(foreach stage,$(STAGES), \
629 $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
631 define DEF_RUN_COMPILETEST
633 CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
634 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
635 --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
636 --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
637 --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
638 --mode $$(CTEST_MODE_$(4)) \
639 $$(CTEST_RUNTOOL_$(4))
641 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
643 # CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
644 # Goal: leave this variable as empty string if we should run the test.
645 # Otherwise, set it to the reason we are not running the test.
646 # (Encoded as a separate variable because GNU make does not have a
647 # good way to express OR on ifeq commands)
649 ifneq ($$(CTEST_DISABLE_$(4)),)
650 # Test suite is disabled for all configured targets.
651 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
653 # else, check if non-self-hosted target (i.e. target not-in hosts) ...
654 ifeq ($$(findstring $(2),$$(CFG_HOST)),)
655 # ... if so, then check if this test suite is disabled for non-selfhosts.
656 ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
657 # Test suite is disabled for this target.
658 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
661 # Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
664 ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
665 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
666 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
667 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
668 @$$(call E, run $(4) [$(2)]: $$<)
669 $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
670 $$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
671 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
676 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
677 @$$(call E, run $(4) [$(2)]: $$<)
678 @$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
685 CTEST_NAMES = rpass rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
687 $(foreach host,$(CFG_HOST), \
688 $(eval $(foreach target,$(CFG_TARGET), \
689 $(eval $(foreach stage,$(STAGES), \
690 $(eval $(foreach name,$(CTEST_NAMES), \
691 $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
693 PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
694 PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
695 PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
696 PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
697 PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
698 PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
699 PRETTY_DIRNAME_pretty-rpass = run-pass
700 PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
701 PRETTY_DIRNAME_pretty-rfail = run-fail
702 PRETTY_DIRNAME_pretty-bench = bench
703 PRETTY_DIRNAME_pretty-pretty = pretty
705 define DEF_RUN_PRETTY_TEST
707 PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
708 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
709 --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
710 --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
713 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
715 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
716 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
718 @$$(call E, run pretty-rpass [$(2)]: $$<)
719 $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
720 $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
721 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
726 $(foreach host,$(CFG_HOST), \
727 $(foreach target,$(CFG_TARGET), \
728 $(foreach stage,$(STAGES), \
729 $(foreach pretty-name,$(PRETTY_NAMES), \
730 $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
733 ######################################################################
734 # Crate & freestanding documentation tests
735 ######################################################################
738 RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
739 RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
742 $(foreach host,$(CFG_HOST), \
743 $(foreach target,$(CFG_TARGET), \
744 $(foreach stage,$(STAGES), \
745 $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))
751 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
753 # If NO_REBUILD is set then break the dependencies on everything but
754 # the source files so we can test documentation without rebuilding
756 ifeq ($(NO_REBUILD),)
757 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
759 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
760 $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
762 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(D)/$(4).md
765 ifeq ($(2),$$(CFG_BUILD))
766 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
767 @$$(call E, run doc-$(4) [$(2)])
768 $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< --test-args "$$(TESTARGS)" && touch $$@
770 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
775 $(foreach host,$(CFG_HOST), \
776 $(foreach target,$(CFG_TARGET), \
777 $(foreach stage,$(STAGES), \
778 $(foreach docname,$(DOCS), \
779 $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
783 define DEF_CRATE_DOC_TEST
785 # If NO_REBUILD is set then break the dependencies on everything but
786 # the source files so we can test crate documentation without
787 # rebuilding any of the parent crates.
788 ifeq ($(NO_REBUILD),)
789 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
790 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
791 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
792 $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
794 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
797 # (Issues #13732, #13983, #14000) The doc for the regex crate includes
798 # uses of the `regex!` macro from the regex_macros crate. There is
799 # normally a dependence injected that makes the target's regex depend
800 # upon the host's regex_macros (see #13845), but that dependency
801 # injection is currently skipped for stage1 as a special case.
803 # Therefore, as a further special case, this conditional skips
804 # attempting to run the doc tests for the regex crate atop stage1,
805 # (since there is no regex_macros crate for the stage1 rustc to load).
807 # (Another approach for solving this would be to inject the desired
808 # dependence for stage1 as well, by setting things up to generate a
809 # regex_macros crate that was compatible with the stage1 rustc and
810 # thus re-enable our ability to run this test.)
811 ifeq (stage$(1)-crate-$(4),stage1-crate-regex)
812 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec:
813 @$$(call E, skipping doc-crate-$(4) as it uses macros and cannot run at stage$(1))
815 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
816 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
819 ifeq ($(2),$$(CFG_BUILD))
820 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
821 @$$(call E, run doc-crate-$(4) [$(2)])
822 $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
823 $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
825 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
831 $(foreach host,$(CFG_HOST), \
832 $(foreach target,$(CFG_TARGET), \
833 $(foreach stage,$(STAGES), \
834 $(foreach crate,$(TEST_DOC_CRATES), \
835 $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
837 ######################################################################
839 ######################################################################
843 $(foreach crate,$(TEST_CRATES),$(crate)) \
844 $(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
857 $(foreach docname,$(DOCS),doc-$(docname)) \
866 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
867 check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
870 $(foreach stage,$(STAGES), \
871 $(foreach target,$(CFG_TARGET), \
872 $(foreach host,$(CFG_HOST), \
873 $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
875 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
876 check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
879 $(foreach stage,$(STAGES), \
880 $(foreach target,$(CFG_TARGET), \
881 $(foreach host,$(CFG_HOST), \
882 $(foreach group,$(TEST_GROUPS), \
883 $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
885 define DEF_CHECK_FOR_STAGE
886 check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
887 check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
888 check-stage$(1)-H-$$(target))
891 $(foreach stage,$(STAGES), \
892 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
894 define DEF_CHECK_FOR_STAGE_AND_GROUP
895 check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
896 check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
897 check-stage$(1)-H-$$(target)-$(2))
900 $(foreach stage,$(STAGES), \
901 $(foreach group,$(TEST_GROUPS), \
902 $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
905 define DEF_CHECK_FOR_STAGE_AND_HOSTS
906 check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
907 check-stage$(1)-T-$$(target)-H-$(2))
910 $(foreach stage,$(STAGES), \
911 $(foreach host,$(CFG_HOST), \
912 $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
914 define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
915 check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
916 check-stage$(1)-T-$$(target)-H-$(2)-$(3))
919 $(foreach stage,$(STAGES), \
920 $(foreach host,$(CFG_HOST), \
921 $(foreach group,$(TEST_GROUPS), \
922 $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
924 define DEF_CHECK_DOC_FOR_STAGE
925 check-stage$(1)-docs: $$(foreach docname,$$(DOCS),\
926 check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
927 $$(foreach crate,$$(TEST_DOC_CRATES),\
928 check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
931 $(foreach stage,$(STAGES), \
932 $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))
934 define DEF_CHECK_CRATE
935 check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
938 $(foreach crate,$(TEST_CRATES), \
939 $(eval $(call DEF_CHECK_CRATE,$(crate))))
941 ######################################################################
943 ######################################################################
945 RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
946 RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
948 define DEF_RMAKE_FOR_T_H
954 ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
955 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
956 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
958 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
959 $$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
962 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
963 $(S)src/test/run-make/%/Makefile \
964 $$(CSREQ$(1)_T_$(2)_H_$(3))
965 @rm -rf $(3)/test/run-make/$$*
966 @mkdir -p $(3)/test/run-make/$$*
967 $$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
969 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
970 $(3)/test/run-make/$$* \
971 "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
972 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
974 $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
975 "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
976 "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
980 # FIXME #11094 - The above rule doesn't work right for multiple targets
981 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
989 $(foreach stage,$(STAGES), \
990 $(foreach target,$(CFG_TARGET), \
991 $(foreach host,$(CFG_HOST), \
992 $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))