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))" \
384 $(foreach host,$(CFG_HOST), \
385 $(eval $(foreach target,$(CFG_TARGET), \
386 $(eval $(foreach stage,$(STAGES), \
387 $(eval $(foreach crate,$(TEST_CRATES), \
388 $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
390 define DEF_TEST_CRATE_RULES
391 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
393 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
394 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
395 @$$(call E, run: $$<)
396 $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
397 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
398 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
402 define DEF_TEST_CRATE_RULES_arm-linux-androideabi
403 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
405 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
406 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
407 @$$(call E, run: $$< via adb)
408 $$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
409 $$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
411 --logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
412 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
413 > tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
414 $$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
415 $$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
416 $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
417 $$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
418 $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/$$(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) tmp/
419 @if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
421 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
424 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
429 define DEF_TEST_CRATE_RULES_null
430 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
432 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
433 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
434 @$$(call E, failing: no device for $$< )
438 $(foreach host,$(CFG_HOST), \
439 $(foreach target,$(CFG_TARGET), \
440 $(foreach stage,$(STAGES), \
441 $(foreach crate, $(TEST_CRATES), \
442 $(if $(findstring $(target),$(CFG_BUILD)), \
443 $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
444 $(if $(findstring $(target),"arm-linux-androideabi"), \
445 $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
446 $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
447 $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
449 $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
452 ######################################################################
453 # Rules for the compiletest tests (rpass, rfail, etc.)
454 ######################################################################
456 RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
457 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
458 RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
459 RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
460 CFAIL_FULL_RC := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rc)
461 CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
462 RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
463 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
464 CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
465 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
466 BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
467 PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
468 DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
469 DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
470 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
471 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
473 # perf tests are the same as bench tests only they run under
474 # a performance monitor.
475 PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
477 RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
478 RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
479 CFAIL_FULL_TESTS := $(CFAIL_FULL_RC) $(CFAIL_FULL_RS)
480 RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
481 CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
482 BENCH_TESTS := $(BENCH_RS)
483 PERF_TESTS := $(PERF_RS)
484 PRETTY_TESTS := $(PRETTY_RS)
485 DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
486 DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
487 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
489 CTEST_SRC_BASE_rpass = run-pass
490 CTEST_BUILD_BASE_rpass = run-pass
491 CTEST_MODE_rpass = run-pass
492 CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
494 CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
495 CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
496 CTEST_MODE_rpass-full = run-pass
497 CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
499 CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
500 CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
501 CTEST_MODE_cfail-full = compile-fail
502 CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)
504 CTEST_SRC_BASE_rfail = run-fail
505 CTEST_BUILD_BASE_rfail = run-fail
506 CTEST_MODE_rfail = run-fail
507 CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
509 CTEST_SRC_BASE_cfail = compile-fail
510 CTEST_BUILD_BASE_cfail = compile-fail
511 CTEST_MODE_cfail = compile-fail
512 CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
514 CTEST_SRC_BASE_bench = bench
515 CTEST_BUILD_BASE_bench = bench
516 CTEST_MODE_bench = run-pass
517 CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
519 CTEST_SRC_BASE_perf = bench
520 CTEST_BUILD_BASE_perf = perf
521 CTEST_MODE_perf = run-pass
522 CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
524 CTEST_SRC_BASE_debuginfo-gdb = debuginfo
525 CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
526 CTEST_MODE_debuginfo-gdb = debuginfo-gdb
527 CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)
529 CTEST_SRC_BASE_debuginfo-lldb = debuginfo
530 CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
531 CTEST_MODE_debuginfo-lldb = debuginfo-lldb
532 CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
534 CTEST_SRC_BASE_codegen = codegen
535 CTEST_BUILD_BASE_codegen = codegen
536 CTEST_MODE_codegen = codegen
537 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
539 # CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
540 # disabled and the associated message to be printed as a warning
541 # during attempts to run those tests.
544 CTEST_DISABLE_debuginfo-gdb = "no gdb found"
548 CTEST_DISABLE_debuginfo-lldb = "no lldb found"
551 # Completely disable LLDB tests for now
552 CTEST_DISABLE_debuginfo-lldb = "LLDB tests are not enabled yet"
555 CTEST_DISABLE_codegen = "no clang found"
558 ifeq ($(CFG_OSTYPE),apple-darwin)
559 CTEST_DISABLE_debuginfo-gdb = "gdb on darwing needs root"
562 # CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
563 # test group to be disabled *unless* the target is able to build a
564 # compiler (i.e. when the target triple is in the set of of host
565 # triples). The associated message will be printed as a warning
566 # during attempts to run those tests.
568 define DEF_CTEST_VARS
570 # All the per-stage build rules you might want to call from the
573 # $(1) is the stage number
574 # $(2) is the target triple to test
575 # $(3) is the host triple to test
577 # Prerequisites for compiletest tests
578 TEST_SREQ$(1)_T_$(2)_H_$(3) = \
579 $$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
580 $$(SREQ$(1)_T_$(2)_H_$(3))
582 # Rules for the cfail/rfail/rpass/bench/perf test runner
584 # The tests select when to use debug configuration on their own;
585 # remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
586 CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
588 # The tests can not be optimized while the rest of the compiler is optimized, so
589 # filter out the optimization (if any) from rustc and then figure out if we need
591 CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
592 ifndef CFG_DISABLE_OPTIMIZE_TESTS
593 CTEST_RUSTC_FLAGS += -O
596 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
597 --compile-lib-path $$(HLIB$(1)_H_$(3)) \
598 --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
599 --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
600 --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
601 --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
602 --aux-base $$(S)src/test/auxiliary/ \
603 --stage-id stage$(1)-$(2) \
606 --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
607 --adb-path=$(CFG_ADB) \
608 --adb-test-dir=$(CFG_ADB_TEST_DIR) \
609 --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
610 --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
611 --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
614 CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
615 CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
616 CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
617 CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
618 CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
619 CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
620 CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
621 CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
622 CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS)
623 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
627 $(foreach host,$(CFG_HOST), \
628 $(eval $(foreach target,$(CFG_TARGET), \
629 $(eval $(foreach stage,$(STAGES), \
630 $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
632 define DEF_RUN_COMPILETEST
634 CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
635 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
636 --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
637 --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
638 --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
639 --mode $$(CTEST_MODE_$(4)) \
640 $$(CTEST_RUNTOOL_$(4))
642 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
644 # CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
645 # Goal: leave this variable as empty string if we should run the test.
646 # Otherwise, set it to the reason we are not running the test.
647 # (Encoded as a separate variable because GNU make does not have a
648 # good way to express OR on ifeq commands)
650 ifneq ($$(CTEST_DISABLE_$(4)),)
651 # Test suite is disabled for all configured targets.
652 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
654 # else, check if non-self-hosted target (i.e. target not-in hosts) ...
655 ifeq ($$(findstring $(2),$$(CFG_HOST)),)
656 # ... if so, then check if this test suite is disabled for non-selfhosts.
657 ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
658 # Test suite is disabled for this target.
659 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
662 # Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
665 ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
666 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
667 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
668 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
669 @$$(call E, run $(4) [$(2)]: $$<)
670 $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
671 $$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
672 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
677 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
678 @$$(call E, run $(4) [$(2)]: $$<)
679 @$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
686 CTEST_NAMES = rpass rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
688 $(foreach host,$(CFG_HOST), \
689 $(eval $(foreach target,$(CFG_TARGET), \
690 $(eval $(foreach stage,$(STAGES), \
691 $(eval $(foreach name,$(CTEST_NAMES), \
692 $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
694 PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
695 PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
696 PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
697 PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
698 PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
699 PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
700 PRETTY_DIRNAME_pretty-rpass = run-pass
701 PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
702 PRETTY_DIRNAME_pretty-rfail = run-fail
703 PRETTY_DIRNAME_pretty-bench = bench
704 PRETTY_DIRNAME_pretty-pretty = pretty
706 define DEF_RUN_PRETTY_TEST
708 PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
709 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
710 --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
711 --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
714 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
716 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
717 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
719 @$$(call E, run pretty-rpass [$(2)]: $$<)
720 $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
721 $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
722 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
727 $(foreach host,$(CFG_HOST), \
728 $(foreach target,$(CFG_TARGET), \
729 $(foreach stage,$(STAGES), \
730 $(foreach pretty-name,$(PRETTY_NAMES), \
731 $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
734 ######################################################################
735 # Crate & freestanding documentation tests
736 ######################################################################
739 RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
740 RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
743 $(foreach host,$(CFG_HOST), \
744 $(foreach target,$(CFG_TARGET), \
745 $(foreach stage,$(STAGES), \
746 $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))
752 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
754 # If NO_REBUILD is set then break the dependencies on everything but
755 # the source files so we can test documentation without rebuilding
757 ifeq ($(NO_REBUILD),)
758 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
760 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
761 $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
763 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(D)/$(4).md
766 ifeq ($(2),$$(CFG_BUILD))
767 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
768 @$$(call E, run doc-$(4) [$(2)])
769 $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< --test-args "$$(TESTARGS)" && touch $$@
771 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
776 $(foreach host,$(CFG_HOST), \
777 $(foreach target,$(CFG_TARGET), \
778 $(foreach stage,$(STAGES), \
779 $(foreach docname,$(DOCS), \
780 $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
784 define DEF_CRATE_DOC_TEST
786 # If NO_REBUILD is set then break the dependencies on everything but
787 # the source files so we can test crate documentation without
788 # rebuilding any of the parent crates.
789 ifeq ($(NO_REBUILD),)
790 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
791 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
792 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
793 $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
795 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
798 # (Issues #13732, #13983, #14000) The doc for the regex crate includes
799 # uses of the `regex!` macro from the regex_macros crate. There is
800 # normally a dependence injected that makes the target's regex depend
801 # upon the host's regex_macros (see #13845), but that dependency
802 # injection is currently skipped for stage1 as a special case.
804 # Therefore, as a further special case, this conditional skips
805 # attempting to run the doc tests for the regex crate atop stage1,
806 # (since there is no regex_macros crate for the stage1 rustc to load).
808 # (Another approach for solving this would be to inject the desired
809 # dependence for stage1 as well, by setting things up to generate a
810 # regex_macros crate that was compatible with the stage1 rustc and
811 # thus re-enable our ability to run this test.)
812 ifeq (stage$(1)-crate-$(4),stage1-crate-regex)
813 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec:
814 @$$(call E, skipping doc-crate-$(4) as it uses macros and cannot run at stage$(1))
816 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
817 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
820 ifeq ($(2),$$(CFG_BUILD))
821 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
822 @$$(call E, run doc-crate-$(4) [$(2)])
823 $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
824 $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
826 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
832 $(foreach host,$(CFG_HOST), \
833 $(foreach target,$(CFG_TARGET), \
834 $(foreach stage,$(STAGES), \
835 $(foreach crate,$(TEST_DOC_CRATES), \
836 $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
838 ######################################################################
840 ######################################################################
844 $(foreach crate,$(TEST_CRATES),$(crate)) \
845 $(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
858 $(foreach docname,$(DOCS),doc-$(docname)) \
867 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
868 check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
871 $(foreach stage,$(STAGES), \
872 $(foreach target,$(CFG_TARGET), \
873 $(foreach host,$(CFG_HOST), \
874 $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
876 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
877 check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
880 $(foreach stage,$(STAGES), \
881 $(foreach target,$(CFG_TARGET), \
882 $(foreach host,$(CFG_HOST), \
883 $(foreach group,$(TEST_GROUPS), \
884 $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
886 define DEF_CHECK_FOR_STAGE
887 check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
888 check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
889 check-stage$(1)-H-$$(target))
892 $(foreach stage,$(STAGES), \
893 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
895 define DEF_CHECK_FOR_STAGE_AND_GROUP
896 check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
897 check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
898 check-stage$(1)-H-$$(target)-$(2))
901 $(foreach stage,$(STAGES), \
902 $(foreach group,$(TEST_GROUPS), \
903 $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
906 define DEF_CHECK_FOR_STAGE_AND_HOSTS
907 check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
908 check-stage$(1)-T-$$(target)-H-$(2))
911 $(foreach stage,$(STAGES), \
912 $(foreach host,$(CFG_HOST), \
913 $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
915 define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
916 check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
917 check-stage$(1)-T-$$(target)-H-$(2)-$(3))
920 $(foreach stage,$(STAGES), \
921 $(foreach host,$(CFG_HOST), \
922 $(foreach group,$(TEST_GROUPS), \
923 $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
925 define DEF_CHECK_DOC_FOR_STAGE
926 check-stage$(1)-docs: $$(foreach docname,$$(DOCS),\
927 check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
928 $$(foreach crate,$$(TEST_DOC_CRATES),\
929 check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
932 $(foreach stage,$(STAGES), \
933 $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))
935 define DEF_CHECK_CRATE
936 check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
939 $(foreach crate,$(TEST_CRATES), \
940 $(eval $(call DEF_CHECK_CRATE,$(crate))))
942 ######################################################################
944 ######################################################################
946 RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
947 RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
949 define DEF_RMAKE_FOR_T_H
955 ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
956 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
957 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
959 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
960 $$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
963 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
964 $(S)src/test/run-make/%/Makefile \
965 $$(CSREQ$(1)_T_$(2)_H_$(3))
966 @rm -rf $(3)/test/run-make/$$*
967 @mkdir -p $(3)/test/run-make/$$*
968 $$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
970 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
971 $(3)/test/run-make/$$* \
972 "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
973 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
975 $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
976 "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
977 "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
981 # FIXME #11094 - The above rule doesn't work right for multiple targets
982 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
990 $(foreach stage,$(STAGES), \
991 $(foreach target,$(CFG_TARGET), \
992 $(foreach host,$(CFG_HOST), \
993 $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))