PageRenderTime 55ms CodeModel.GetById 3ms app.highlight 43ms RepoModel.GetById 1ms app.codeStats 1ms

/mk/tests.mk

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