tests.mk 36.7 KB
Newer Older
N
Nick Cameron 已提交
1
# Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

11

G
Graydon Hoare 已提交
12
######################################################################
13
# Test variables
G
Graydon Hoare 已提交
14 15
######################################################################

16
# The names of crates that must be tested
17

18
# libcore/librustc_unicode tests are in a separate crate
19 20 21
DEPS_coretest :=
$(eval $(call RUST_CRATE,coretest))

22 23 24
DEPS_collectionstest :=
$(eval $(call RUST_CRATE,collectionstest))

A
Alex Crichton 已提交
25
TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system libc \
26
		     		  alloc_jemalloc,$(TARGET_CRATES)) \
27
			collectionstest coretest
K
Kevin Butler 已提交
28
TEST_DOC_CRATES = $(DOC_CRATES) arena
29 30
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \
		   		rustc_trans rustc_lint,\
31
                     $(HOST_CRATES))
32
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
G
Graydon Hoare 已提交
33

34 35 36
######################################################################
# Environment configuration
######################################################################
37

B
Brian Anderson 已提交
38 39 40 41 42
# The arguments to all test runners
ifdef TESTNAME
  TESTARGS += $(TESTNAME)
endif

43
ifdef CHECK_IGNORED
B
Brian Anderson 已提交
44 45 46 47 48 49 50
  TESTARGS += --ignored
endif

# Arguments to the cfail/rfail/rpass/bench tests
ifdef CFG_VALGRIND
  CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
endif
51

52 53 54 55 56
# Arguments to the perf tests
ifdef CFG_PERF_TOOL
  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
endif

B
Brian Anderson 已提交
57
CTEST_TESTARGS := $(TESTARGS)
G
Graydon Hoare 已提交
58

59 60 61 62 63
# --bench is only relevant for crate tests, not for the compile tests
ifdef PLEASE_BENCH
  TESTARGS += --bench
endif

B
Brian Anderson 已提交
64 65 66
ifdef VERBOSE
  CTEST_TESTARGS += --verbose
endif
67

68 69 70 71
# Setting locale ensures that gdb's output remains consistent.
# This prevents tests from failing with some locales (fixes #17423).
export LC_ALL=C

72 73 74
# If we're running perf then set this environment variable
# to put the benchmarks into 'hard mode'
ifeq ($(MAKECMDGOALS),perf)
75
  export RUST_BENCH=1
76 77
endif

78 79
TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
80

81 82 83
define DEF_TARGET_COMMANDS

ifdef CFG_UNIXY_$(1)
A
Alex Crichton 已提交
84 85
  CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
	  $$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
86 87 88
endif

ifdef CFG_WINDOWSY_$(1)
C
Chris Morgan 已提交
89
  CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
90
   $$(if $$(findstring stage0,$$(1)), \
91
       stage0/$$(CFG_LIBDIR_RELATIVE), \
92
      $$(if $$(findstring stage1,$$(1)), \
93
           stage1/$$(CFG_LIBDIR_RELATIVE), \
94
          $$(if $$(findstring stage2,$$(1)), \
95
               stage2/$$(CFG_LIBDIR_RELATIVE), \
96
               $$(if $$(findstring stage3,$$(1)), \
97
                    stage3/$$(CFG_LIBDIR_RELATIVE), \
98
               )))))/rustlib/$$(CFG_BUILD)/lib
99 100
  CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
	  $$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(4)),$$(1))
101 102 103 104
endif

# Run the compiletest runner itself under valgrind
ifdef CTEST_VALGRIND
105
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
A
Alex Crichton 已提交
106
      $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(3),$$(4))
107
else
108 109
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
      $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
110 111 112 113
endif

endef

H
Heather 已提交
114
$(foreach target,$(CFG_TARGET), \
115 116
  $(eval $(call DEF_TARGET_COMMANDS,$(target))))

117
# Target platform specific variables for android
118 119
define DEF_ADB_DEVICE_STATUS
CFG_ADB_DEVICE_STATUS=$(1)
120 121
endef

H
Heather 已提交
122
$(foreach target,$(CFG_TARGET), \
123
  $(if $(findstring android, $(target)), \
124
    $(if $(findstring adb,$(CFG_ADB)), \
125
      $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
126 127 128 129
        $(info check: android device attached) \
        $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
        $(info check: android device not attached) \
        $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
130
      ), \
131 132
      $(info check: adb not found) \
      $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
133
    ), \
134 135 136
  ) \
)

137 138
ifeq ($(CFG_ADB_DEVICE_STATUS),true)
CFG_ADB_TEST_DIR=/data/tmp
139

140
$(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
141 142 143 144
 $(shell $(CFG_ADB) remount 1>/dev/null) \
 $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
 $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
 $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
145
 $(foreach target,$(CFG_TARGET), \
146
  $(if $(findstring android, $(target)), \
147 148 149 150 151
   $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/$(target)) \
   $(foreach crate,$(TARGET_CRATES), \
    $(shell $(CFG_ADB) push $(TLIB2_T_$(target)_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_$(target),$(crate)) \
                    $(CFG_ADB_TEST_DIR)/$(target))), \
 )))
152 153
else
CFG_ADB_TEST_DIR=
154
endif
155

S
Steve Klabnik 已提交
156 157 158 159 160 161 162 163 164
# $(1) - name of doc test
# $(2) - file of the test
define DOCTEST
DOC_NAMES := $$(DOC_NAMES) $(1)
DOCFILE_$(1) := $(2)
endef

$(foreach doc,$(DOCS), \
  $(eval $(call DOCTEST,md-$(doc),$(S)src/doc/$(doc).md)))
165 166
$(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \
  $(eval $(call DOCTEST,$(file:$(S)src/doc/trpl/%.md=trpl-%),$(file))))
167 168
$(foreach file,$(wildcard $(S)src/doc/nomicon/*.md), \
  $(eval $(call DOCTEST,$(file:$(S)src/doc/nomicon/%.md=nomicon-%),$(file))))
B
Brian Anderson 已提交
169 170 171 172
######################################################################
# Main test targets
######################################################################

173
# The main testing target. Tests lots of stuff.
174
check: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2 tidy
175
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
H
Huon Wilson 已提交
176

177
# As above but don't bother running tidy.
178
check-notidy: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2
179 180
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

181
# A slightly smaller set of tests for smoke testing.
182
check-lite: check-sanitycheck cleantestlibs cleantmptestlogs \
183
	$(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
N
Nick Cameron 已提交
184
	check-stage2-rpass check-stage2-rpass-valgrind \
185
	check-stage2-rfail check-stage2-cfail check-stage2-pfail check-stage2-rmake
186 187
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

188
# Only check the 'reference' tests: rpass/cfail/rfail/rmake.
189 190 191
check-ref: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-rpass \
	check-stage2-rpass-valgrind check-stage2-rfail check-stage2-cfail check-stage2-pfail \
	check-stage2-rmake
192 193
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

194
# Only check the docs.
195
check-docs: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-docs
B
Brian Anderson 已提交
196 197
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

198 199
# Some less critical tests that are not prone to breakage.
# Not run as part of the normal test suite, but tested by bors on checkin.
200
check-secondary: check-build-compiletest check-build-lexer-verifier check-lexer check-pretty
201

202 203 204 205 206
.PHONY: check-sanitycheck

check-sanitycheck:
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-sanitycheck.py

207
# check + check-secondary.
208 209 210 211 212
#
# Issue #17883: build check-secondary first so hidden dependencies in
# e.g. building compiletest are exercised (resolve those by adding
# deps to rules that need them; not by putting `check` first here).
check-all: check-secondary check
213 214

# Pretty-printing tests.
215 216
check-pretty: check-stage2-T-$(CFG_BUILD)-H-$(CFG_BUILD)-pretty-exec

217 218 219 220 221 222 223 224 225 226 227
define DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE
check-stage$(1)-build-compiletest: 	$$(HBIN$(1)_H_$(CFG_BUILD))/compiletest$$(X_$(CFG_BUILD))
endef

$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE,$(stage))))

check-build-compiletest: \
	check-stage1-build-compiletest \
	check-stage2-build-compiletest

228 229
.PHONY: cleantmptestlogs cleantestlibs

230 231
cleantmptestlogs:
	$(Q)rm -f tmp/*.log
232

233
cleantestlibs:
H
Heather 已提交
234
	$(Q)find $(CFG_BUILD)/test \
235
         -name '*.[odasS]' -o \
236 237 238 239 240 241 242 243 244
         -name '*.so' -o \
         -name '*.dylib' -o \
         -name '*.dll' -o \
         -name '*.def' -o \
         -name '*.bc' -o \
         -name '*.dSYM' -o \
         -name '*.libaux' -o \
         -name '*.out' -o \
         -name '*.err' -o \
B
Brian Leibig 已提交
245
	 -name '*.debugger.script' \
246
         | xargs rm -rf
247

248

249 250 251
######################################################################
# Tidy
######################################################################
B
Brian Anderson 已提交
252

253
ifdef CFG_NOTIDY
254
.PHONY: tidy
B
Brian Anderson 已提交
255
tidy:
256
else
257

258
# Run the tidy script in multiple parts to avoid huge 'echo' commands
259 260 261 262 263 264 265
.PHONY: tidy
tidy: tidy-basic tidy-binaries tidy-errors tidy-features

endif

.PHONY: tidy-basic
tidy-basic:
266
		@$(call E, check: formatting)
267
		$(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
268 269 270 271

.PHONY: tidy-binaries
tidy-binaries:
		@$(call E, check: binaries)
272 273
		$(Q)find $(S)src -type f \
		    \( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
274
		    -not -name '*.rs' -and -not -name '*.py' \
275
		    -and -not -name '*.sh' -and -not -name '*.pp' \
D
Daniel Micay 已提交
276
		| grep '^$(S)src/jemalloc' -v \
277
		| grep '^$(S)src/libuv' -v \
D
Daniel Micay 已提交
278
		| grep '^$(S)src/llvm' -v \
279
		| grep '^$(S)src/rt/hoedown' -v \
280 281
		| grep '^$(S)src/gyp' -v \
		| grep '^$(S)src/etc' -v \
282
		| grep '^$(S)src/doc' -v \
283
		| grep '^$(S)src/compiler-rt' -v \
284
		| grep '^$(S)src/libbacktrace' -v \
B
Brian Anderson 已提交
285
		| grep '^$(S)src/rust-installer' -v \
A
Alex Crichton 已提交
286
		| grep '^$(S)src/liblibc' -v \
287
		| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
288

289 290 291 292
.PHONY: tidy-errors
tidy-errors:
		@$(call E, check: extended errors)
		$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
S
Steve Klabnik 已提交
293

294 295 296 297
.PHONY: tidy-features
tidy-features:
		@$(call E, check: feature sanity)
		$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
298

299

B
Brian Anderson 已提交
300
######################################################################
301
# Sets of tests
B
Brian Anderson 已提交
302 303
######################################################################

304 305
define DEF_TEST_SETS

306 307 308 309
check-stage$(1)-T-$(2)-H-$(3)-exec: \
	check-stage$(1)-T-$(2)-H-$(3)-rpass-exec \
	check-stage$(1)-T-$(2)-H-$(3)-rfail-exec \
	check-stage$(1)-T-$(2)-H-$(3)-cfail-exec \
310
	check-stage$(1)-T-$(2)-H-$(3)-pfail-exec \
311 312
    check-stage$(1)-T-$(2)-H-$(3)-rpass-valgrind-exec \
    check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
313
    check-stage$(1)-T-$(2)-H-$(3)-rfail-full-exec \
314 315
	check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
	check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
316
	check-stage$(1)-T-$(2)-H-$(3)-rustdocck-exec \
317 318 319
        check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
        check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
	check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
320 321
	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
322
	check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
323 324 325
	check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-exec

326 327
# Only test the compiler-dependent crates when the target is
# able to build a compiler (when the target triple is in the set of host triples)
H
Heather 已提交
328
ifneq ($$(findstring $(2),$$(CFG_HOST)),)
329

330 331 332 333
check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
	$$(foreach crate,$$(TEST_CRATES), \
           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)

334 335 336 337 338 339 340 341
else

check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
	$$(foreach crate,$$(TEST_TARGET_CRATES), \
           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)

endif

342 343
check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
        $$(foreach crate,$$(TEST_DOC_CRATES), \
344
           check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec)
345

346
check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
S
Steve Klabnik 已提交
347 348
        $$(foreach docname,$$(DOC_NAMES), \
           check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec) \
349 350

check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
351
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
352
    check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-valgrind-exec \
353 354
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
355
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-full-exec \
356
	check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
357
	check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
358

B
Brian Anderson 已提交
359 360
endef

H
Heather 已提交
361 362
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
363 364 365
  $(foreach stage,$(STAGES), \
    $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))

B
Brian Anderson 已提交
366

367
######################################################################
368
# Crate testing
369 370
######################################################################

371
define TEST_RUNNER
372

373 374 375
# If NO_REBUILD is set then break the dependencies on everything but
# the source files so we can test crates without rebuilding any of the
# parent crates.
376
ifeq ($(NO_REBUILD),)
377
TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
378
			    $$(foreach crate,$$(TARGET_CRATES), \
379 380
				$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
				$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))
381

382
else
383
TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
384 385
endif

386
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
387
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \
388 389
		$$(CRATEFILE_$(4)) \
		$$(TESTDEP_$(1)_$(2)_$(3)_$(4))
390
	@$$(call E, rustc: $$@)
391
	$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
R
Richard Diamond 已提交
392
	    $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \
393
		-L "$$(RT_OUTPUT_DIR_$(2))" \
394
		$$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
A
Alex Crichton 已提交
395
		$$(RUSTFLAGS_$(4))
396

397 398
endef

H
Heather 已提交
399 400
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
401
  $(eval $(foreach stage,$(STAGES), \
402 403
   $(eval $(foreach crate,$(TEST_CRATES), \
    $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
404 405

define DEF_TEST_CRATE_RULES
406 407 408
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
A
Alex Crichton 已提交
409
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
410
	@$$(call E, run: $$<)
411
	$$(Q)touch $$@.start_time
A
Alex Crichton 已提交
412
	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
413 414
	    --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
	    $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
415
	    && touch -r $$@.start_time $$@ && rm $$@.start_time
416
endef
417

418
define DEF_TEST_CRATE_RULES_android
419 420 421
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
A
Alex Crichton 已提交
422
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
423
	@$$(call E, run: $$< via adb)
424
	$$(Q)touch $$@.start_time
425
	$$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
426
	$$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=./$(2) \
427
		./$$(notdir $$<) \
428
		--logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
429
		$$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
430
		> tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
431 432 433 434
	$$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
	$$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
	$$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
	$$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
435 436 437
	@if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
	then \
		rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
438
		touch -r $$@.start_time $$@ && rm $$@.start_time; \
439 440 441 442 443 444 445 446 447 448
	else \
		rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
		exit 101; \
	fi
endef

define DEF_TEST_CRATE_RULES_null
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
A
Alex Crichton 已提交
449
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
450 451
	@$$(call E, failing: no device for $$< )
	false
452 453
endef

H
Heather 已提交
454 455
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
456 457
  $(foreach stage,$(STAGES), \
   $(foreach crate, $(TEST_CRATES), \
H
Heather 已提交
458
    $(if $(findstring $(target),$(CFG_BUILD)), \
459
     $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
460
     $(if $(findstring android, $(target)), \
461
      $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
462
       $(eval $(call DEF_TEST_CRATE_RULES_android,$(stage),$(target),$(host),$(crate))), \
463 464
       $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
      ), \
465
      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
D
Daniel Micay 已提交
466
     ))))))
467

468 469 470 471 472
######################################################################
# Rules for the compiletest tests (rpass, rfail, etc.)
######################################################################

RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
N
Nick Cameron 已提交
473
RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
474
RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
475
RFAIL_FULL_RS := $(wildcard $(S)src/test/run-fail-fulldeps/*.rs)
476
CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
477 478
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
479
PFAIL_RS := $(wildcard $(S)src/test/parse-fail/*.rs)
480
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
481
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
482 483
DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
484 485
CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
486
RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdoc/*.rs)
487

488 489
# perf tests are the same as bench tests only they run under
# a performance monitor.
490
PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
491

492 493 494
RPASS_TESTS := $(RPASS_RS)
RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
RPASS_FULL_TESTS := $(RPASS_FULL_RS)
495
RFAIL_FULL_TESTS := $(RFAIL_FULL_RS)
496 497
CFAIL_FULL_TESTS := $(CFAIL_FULL_RS)
RFAIL_TESTS := $(RFAIL_RS)
498 499
CFAIL_TESTS := $(CFAIL_RS)
PFAIL_TESTS := $(PFAIL_RS)
500 501 502
BENCH_TESTS := $(BENCH_RS)
PERF_TESTS := $(PERF_RS)
PRETTY_TESTS := $(PRETTY_RS)
503 504
DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
505
CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
506
RUSTDOCCK_TESTS := $(RUSTDOCCK_RS)
B
Brian Anderson 已提交
507

508 509 510 511
CTEST_SRC_BASE_rpass = run-pass
CTEST_BUILD_BASE_rpass = run-pass
CTEST_MODE_rpass = run-pass
CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
B
Brian Anderson 已提交
512

N
Nick Cameron 已提交
513 514 515 516 517
CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind
CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind
CTEST_MODE_rpass-valgrind = run-pass-valgrind
CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL)

518 519
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
520 521 522
CTEST_MODE_rpass-full = run-pass
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)

523 524 525 526 527
CTEST_SRC_BASE_rfail-full = run-fail-fulldeps
CTEST_BUILD_BASE_rfail-full = run-fail-fulldeps
CTEST_MODE_rfail-full = run-fail
CTEST_RUNTOOL_rfail-full = $(CTEST_RUNTOOL)

528 529 530 531 532
CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
CTEST_MODE_cfail-full = compile-fail
CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)

533 534 535 536 537 538 539 540 541 542
CTEST_SRC_BASE_rfail = run-fail
CTEST_BUILD_BASE_rfail = run-fail
CTEST_MODE_rfail = run-fail
CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)

CTEST_SRC_BASE_cfail = compile-fail
CTEST_BUILD_BASE_cfail = compile-fail
CTEST_MODE_cfail = compile-fail
CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)

543 544 545 546 547
CTEST_SRC_BASE_pfail = parse-fail
CTEST_BUILD_BASE_pfail = parse-fail
CTEST_MODE_pfail = parse-fail
CTEST_RUNTOOL_pfail = $(CTEST_RUNTOOL)

548
CTEST_SRC_BASE_bench = bench
549 550 551 552 553 554 555 556 557
CTEST_BUILD_BASE_bench = bench
CTEST_MODE_bench = run-pass
CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)

CTEST_SRC_BASE_perf = bench
CTEST_BUILD_BASE_perf = perf
CTEST_MODE_perf = run-pass
CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)

558 559 560 561 562 563 564 565 566
CTEST_SRC_BASE_debuginfo-gdb = debuginfo
CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
CTEST_MODE_debuginfo-gdb = debuginfo-gdb
CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)

CTEST_SRC_BASE_debuginfo-lldb = debuginfo
CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
CTEST_MODE_debuginfo-lldb = debuginfo-lldb
CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
B
Brian Leibig 已提交
567

568 569 570 571 572
CTEST_SRC_BASE_codegen = codegen
CTEST_BUILD_BASE_codegen = codegen
CTEST_MODE_codegen = codegen
CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)

573 574 575 576 577
CTEST_SRC_BASE_rustdocck = rustdoc
CTEST_BUILD_BASE_rustdocck = rustdoc
CTEST_MODE_rustdocck = rustdoc
CTEST_RUNTOOL_rustdocck = $(CTEST_RUNTOOL)

578 579 580 581
# CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
# disabled and the associated message to be printed as a warning
# during attempts to run those tests.

582
ifeq ($(CFG_GDB),)
583 584 585 586 587
CTEST_DISABLE_debuginfo-gdb = "no gdb found"
endif

ifeq ($(CFG_LLDB),)
CTEST_DISABLE_debuginfo-lldb = "no lldb found"
588 589
endif

590 591 592 593
ifneq ($(CFG_OSTYPE),apple-darwin)
CTEST_DISABLE_debuginfo-lldb = "lldb tests are only run on darwin"
endif

594
ifeq ($(CFG_OSTYPE),apple-darwin)
C
Corey Farwell 已提交
595
CTEST_DISABLE_debuginfo-gdb = "gdb on darwin needs root"
596 597
endif

598 599 600 601 602
ifeq ($(findstring android, $(CFG_TARGET)), android)
CTEST_DISABLE_debuginfo-gdb =
CTEST_DISABLE_debuginfo-lldb = "lldb tests are disabled on android"
endif

603 604 605 606
ifeq ($(findstring msvc,$(CFG_TARGET)),msvc)
CTEST_DISABLE_debuginfo-gdb = "gdb tests are disabled on MSVC"
endif

607 608 609 610 611 612
# CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
# test group to be disabled *unless* the target is able to build a
# compiler (i.e. when the target triple is in the set of of host
# triples).  The associated message will be printed as a warning
# during attempts to run those tests.

613 614 615 616 617 618 619 620 621 622 623
define DEF_CTEST_VARS

# All the per-stage build rules you might want to call from the
# command line.
#
# $(1) is the stage number
# $(2) is the target triple to test
# $(3) is the host triple to test

# Prerequisites for compiletest tests
TEST_SREQ$(1)_T_$(2)_H_$(3) = \
624
	$$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
625
	$$(SREQ$(1)_T_$(2)_H_$(3))
B
Brian Anderson 已提交
626

B
Brian Anderson 已提交
627
# Rules for the cfail/rfail/rpass/bench/perf test runner
628

629 630
# The tests select when to use debug configuration on their own;
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
631
CTEST_RUSTC_FLAGS := $$(subst -C debug-assertions,,$$(subst -C debug-assertions=on,,$$(CFG_RUSTC_FLAGS)))
632

N
Nick Cameron 已提交
633
# The tests cannot be optimized while the rest of the compiler is optimized, so
634 635 636 637 638 639
# filter out the optimization (if any) from rustc and then figure out if we need
# to be optimized
CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
ifndef CFG_DISABLE_OPTIMIZE_TESTS
CTEST_RUSTC_FLAGS += -O
endif
640

641 642 643 644 645 646 647
# Analogously to the above, whether to pass `-g` when compiling tests
# is a separate choice from whether to pass `-g` when building the
# compiler and standard library themselves.
CTEST_RUSTC_FLAGS := $$(subst -g,,$$(CTEST_RUSTC_FLAGS))
ifdef CFG_ENABLE_DEBUGINFO_TESTS
CTEST_RUSTC_FLAGS += -g
endif
N
Nick Cameron 已提交
648

649 650 651 652
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
		--compile-lib-path $$(HLIB$(1)_H_$(3)) \
        --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
        --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
653
        --rustdoc-path $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
H
Heather 已提交
654
        --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
655 656 657 658
        --aux-base $$(S)src/test/auxiliary/ \
        --stage-id stage$(1)-$(2) \
        --target $(2) \
        --host $(3) \
659
	--python $$(CFG_PYTHON) \
660
        --gdb-version="$(CFG_GDB_VERSION)" \
661
        --lldb-version="$(CFG_LLDB_VERSION)" \
662 663 664
        --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
        --adb-path=$(CFG_ADB) \
        --adb-test-dir=$(CFG_ADB_TEST_DIR) \
665
        --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
666
        --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
L
Luqman Aden 已提交
667
        --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
N
Niko Matsakis 已提交
668 669
        $$(CTEST_TESTARGS)

670 671 672 673 674 675 676 677 678 679 680 681
ifdef CFG_VALGRIND_RPASS
ifdef GOOD_VALGRIND_$(2)
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
endif
endif

ifndef CFG_DISABLE_VALGRIND_RPASS
ifdef GOOD_VALGRIND_$(2)
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --force-valgrind
endif
endif

682
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
N
Nick Cameron 已提交
683
CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
684
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
685
CTEST_DEPS_rfail-full_$(1)-T-$(2)-H-$(3) = $$(RFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
686
CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
687 688
CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
689
CTEST_DEPS_pfail_$(1)-T-$(2)-H-$(3) = $$(PFAIL_TESTS)
690 691
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
692
CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
693 694 695
CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
                                               $(S)src/etc/lldb_batchmode.py \
                                               $(S)src/etc/lldb_rust_formatters.py
696
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
697 698 699
CTEST_DEPS_rustdocck_$(1)-T-$(2)-H-$(3) = $$(RUSTDOCCK_TESTS) \
        $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
	$(S)src/etc/htmldocck.py
N
Niko Matsakis 已提交
700

701
endef
N
Niko Matsakis 已提交
702

H
Heather 已提交
703 704
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
705 706
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
N
Niko Matsakis 已提交
707

708
define DEF_RUN_COMPILETEST
709

710
CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
711
        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
712
        --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
713 714 715
        --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
        --mode $$(CTEST_MODE_$(4)) \
	$$(CTEST_RUNTOOL_$(4))
N
Niko Matsakis 已提交
716

717 718
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

719 720 721 722 723
# CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
# Goal: leave this variable as empty string if we should run the test.
# Otherwise, set it to the reason we are not running the test.
# (Encoded as a separate variable because GNU make does not have a
# good way to express OR on ifeq commands)
724

725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
ifneq ($$(CTEST_DISABLE_$(4)),)
# Test suite is disabled for all configured targets.
CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
else
# else, check if non-self-hosted target (i.e. target not-in hosts) ...
ifeq ($$(findstring $(2),$$(CFG_HOST)),)
# ... if so, then check if this test suite is disabled for non-selfhosts.
ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
# Test suite is disabled for this target.
CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
endif
endif
# Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
endif

ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
741
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
742 743
		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
744
	@$$(call E, run $(4) [$(2)]: $$<)
745
	$$(Q)touch $$@.start_time
746
	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
747
		$$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
748
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
749
                && touch -r $$@.start_time $$@ && rm $$@.start_time
N
Niko Matsakis 已提交
750

751 752
else

753
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
754
	@$$(call E, run $(4) [$(2)]: $$<)
755
	@$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
756 757 758 759
	touch $$@

endif

760
endef
N
Niko Matsakis 已提交
761

762
CTEST_NAMES = rpass rpass-valgrind rpass-full rfail-full cfail-full rfail cfail pfail \
763
	bench perf debuginfo-gdb debuginfo-lldb codegen rustdocck
764

H
Heather 已提交
765 766
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
767 768 769 770
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(foreach name,$(CTEST_NAMES), \
   $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))

771 772
PRETTY_NAMES = pretty-rpass pretty-rpass-valgrind pretty-rpass-full pretty-rfail-full pretty-rfail \
    pretty-bench pretty-pretty
773
PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
774
PRETTY_DEPS_pretty-rpass-valgrind = $(RPASS_VALGRIND_TESTS)
775
PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
776
PRETTY_DEPS_pretty-rfail-full = $(RFAIL_FULL_TESTS)
777 778 779 780
PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
PRETTY_DIRNAME_pretty-rpass = run-pass
781
PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
782
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
783
PRETTY_DIRNAME_pretty-rfail-full = run-fail-fulldeps
784 785 786 787
PRETTY_DIRNAME_pretty-rfail = run-fail
PRETTY_DIRNAME_pretty-bench = bench
PRETTY_DIRNAME_pretty-pretty = pretty

788 789
define DEF_PRETTY_FULLDEPS
PRETTY_DEPS$(1)_T_$(2)_H_$(3)_pretty-rpass-full = $$(CSREQ$(1)_T_$(3)_H_$(3))
790
PRETTY_DEPS$(1)_T_$(2)_H_$(3)_pretty-rfail-full = $$(CSREQ$(1)_T_$(3)_H_$(3))
791 792 793 794 795 796 797
endef

$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
  $(foreach stage,$(STAGES), \
   $(eval $(call DEF_PRETTY_FULLDEPS,$(stage),$(target),$(host))))))

798 799
define DEF_RUN_PRETTY_TEST

800 801
PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
		$$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
802 803
        --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
        --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
N
Niko Matsakis 已提交
804 805
        --mode pretty

806 807 808
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
809
	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
810
	        $$(PRETTY_DEPS_$(4)) \
811
	        $$(PRETTY_DEPS$(1)_T_$(2)_H_$(3)_$(4))
812
	@$$(call E, run pretty-rpass [$(2)]: $$<)
813
	$$(Q)touch $$@.start_time
814
	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
815
		$$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
816
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
817
                && touch -r $$@.start_time $$@ && rm $$@.start_time
N
Niko Matsakis 已提交
818

819
endef
N
Niko Matsakis 已提交
820

H
Heather 已提交
821 822
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
823 824 825
  $(foreach stage,$(STAGES), \
   $(foreach pretty-name,$(PRETTY_NAMES), \
    $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
B
Brian Anderson 已提交
826

827

828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
######################################################################
# Crate & freestanding documentation tests
######################################################################

define DEF_RUSTDOC
RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
endef

$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
  $(foreach stage,$(STAGES), \
   $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))

# Freestanding

define DEF_DOC_TEST
845

846
check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
847

848 849 850 851 852
# If NO_REBUILD is set then break the dependencies on everything but
# the source files so we can test documentation without rebuilding
# rustdoc etc.
ifeq ($(NO_REBUILD),)
DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
S
Steve Klabnik 已提交
853
	$$(DOCFILE_$(4)) \
854
	$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
855 856
	$$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
else
S
Steve Klabnik 已提交
857
DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(DOCFILE_$(4))
858
endif
859

860 861 862
ifeq ($(2),$$(CFG_BUILD))
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
	@$$(call E, run doc-$(4) [$(2)])
863
	$$(Q)touch $$@.start_time
S
Steve Klabnik 已提交
864
	$$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< \
865 866
		--test-args "$$(TESTARGS)" && \
		touch -r $$@.start_time $$@ && rm $$@.start_time
867 868 869 870
else
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
	touch $$@
endif
871
endef
872

H
Heather 已提交
873 874
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
875
  $(foreach stage,$(STAGES), \
S
Steve Klabnik 已提交
876
   $(foreach docname,$(DOC_NAMES), \
877 878 879
    $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))

# Crates
880

881 882
define DEF_CRATE_DOC_TEST

883 884 885 886
# If NO_REBUILD is set then break the dependencies on everything but
# the source files so we can test crate documentation without
# rebuilding any of the parent crates.
ifeq ($(NO_REBUILD),)
887
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
888 889
	$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
	$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
890
	$$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
891
else
892
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
893 894
endif

895 896
check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
	$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
897

898
ifeq ($(2),$$(CFG_BUILD))
899 900
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
	@$$(call E, run doc-crate-$(4) [$(2)])
901
	$$(Q)touch $$@.start_time
902
	$$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
R
Richard Diamond 已提交
903
	    $$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
904 905
	        $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && \
	        touch -r $$@.start_time $$@ && rm $$@.start_time
906
else
907
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
908 909
	touch $$@
endif
910 911 912 913

endef

$(foreach host,$(CFG_HOST), \
914 915 916 917
 $(foreach target,$(CFG_TARGET), \
  $(foreach stage,$(STAGES), \
   $(foreach crate,$(TEST_DOC_CRATES), \
    $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
918

919 920 921
######################################################################
# Shortcut rules
######################################################################
922

923 924 925
TEST_GROUPS = \
	crates \
	$(foreach crate,$(TEST_CRATES),$(crate)) \
926
	$(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
927
	rpass \
N
Nick Cameron 已提交
928
    rpass-valgrind \
929
	rpass-full \
930
	rfail-full \
931
	cfail-full \
932 933
	rfail \
	cfail \
934
	pfail \
935 936
	bench \
	perf \
A
Alex Crichton 已提交
937
	rmake \
938
	rustdocck \
939 940
	debuginfo-gdb \
	debuginfo-lldb \
941
	codegen \
942
	doc \
S
Steve Klabnik 已提交
943
	$(foreach docname,$(DOC_NAMES),doc-$(docname)) \
944 945
	pretty \
	pretty-rpass \
946
    pretty-rpass-valgrind \
947
	pretty-rpass-full \
948
	pretty-rfail-full \
949 950 951 952 953 954 955 956
	pretty-rfail \
	pretty-bench \
	pretty-pretty \
	$(NULL)

define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
endef
957

958
$(foreach stage,$(STAGES), \
H
Heather 已提交
959 960
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
961
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
962

963 964 965
define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
endef
B
Brian Anderson 已提交
966

967
$(foreach stage,$(STAGES), \
H
Heather 已提交
968 969
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
970 971
   $(foreach group,$(TEST_GROUPS), \
    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
972

973
define DEF_CHECK_FOR_STAGE
H
Heather 已提交
974 975
check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
976 977
                           check-stage$(1)-H-$$(target))
endef
978

979 980
$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
981

982
define DEF_CHECK_FOR_STAGE_AND_GROUP
H
Heather 已提交
983 984
check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
985 986
                               check-stage$(1)-H-$$(target)-$(2))
endef
987

988 989 990
$(foreach stage,$(STAGES), \
 $(foreach group,$(TEST_GROUPS), \
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
991

992 993

define DEF_CHECK_FOR_STAGE_AND_HOSTS
H
Heather 已提交
994
check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
995
                           check-stage$(1)-T-$$(target)-H-$(2))
B
Brian Anderson 已提交
996
endef
997

998
$(foreach stage,$(STAGES), \
H
Heather 已提交
999
 $(foreach host,$(CFG_HOST), \
1000 1001 1002
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))

define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
H
Heather 已提交
1003
check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
1004 1005 1006 1007
                                check-stage$(1)-T-$$(target)-H-$(2)-$(3))
endef

$(foreach stage,$(STAGES), \
H
Heather 已提交
1008
 $(foreach host,$(CFG_HOST), \
1009 1010
  $(foreach group,$(TEST_GROUPS), \
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
1011

B
Brian Anderson 已提交
1012
define DEF_CHECK_DOC_FOR_STAGE
S
Steve Klabnik 已提交
1013
check-stage$(1)-docs: $$(foreach docname,$$(DOC_NAMES), \
B
Brian Anderson 已提交
1014
                       check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
1015
                     $$(foreach crate,$$(TEST_DOC_CRATES), \
1016
                       check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
B
Brian Anderson 已提交
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
endef

$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))

define DEF_CHECK_CRATE
check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
endef

$(foreach crate,$(TEST_CRATES), \
 $(eval $(call DEF_CHECK_CRATE,$(crate))))

N
Niko Matsakis 已提交
1029
######################################################################
1030
# RMAKE rules
N
Niko Matsakis 已提交
1031
######################################################################
1032

A
Alex Crichton 已提交
1033 1034 1035 1036 1037 1038 1039 1040
RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)

define DEF_RMAKE_FOR_T_H
# $(1) the stage
# $(2) target triple
# $(3) host triple

1041 1042

ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
A
Alex Crichton 已提交
1043 1044 1045 1046 1047 1048 1049
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
		$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)

$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
		$$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
	@touch $$@

1050 1051 1052 1053
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
	export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(3)))
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
	export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(3)))
A
Alex Crichton 已提交
1054 1055
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
		$(S)src/test/run-make/%/Makefile \
C
Corey Richardson 已提交
1056
		$$(CSREQ$(1)_T_$(2)_H_$(3))
A
Alex Crichton 已提交
1057 1058
	@rm -rf $(3)/test/run-make/$$*
	@mkdir -p $(3)/test/run-make/$$*
1059
	$$(Q)touch $$@.start_time
1060
	$$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
1061
        $$(MAKE) \
A
Alex Crichton 已提交
1062
	    $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
A
Alex Crichton 已提交
1063
	    $(3)/test/run-make/$$* \
1064
	    '$$(CC_$(3))' \
1065
	    "$$(CFG_GCCISH_CFLAGS_$(3))" \
1066
	    $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
1067
	    "$$(TESTNAME)" \
1068 1069 1070
	    $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
	    "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
	    "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
1071
	    $(1) \
1072 1073
	    $$(S) \
	    $(3)
1074
	@touch -r $$@.start_time $$@ && rm $$@.start_time
1075 1076 1077 1078 1079 1080 1081
else
# FIXME #11094 - The above rule doesn't work right for multiple targets
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
	@true

endif

A
Alex Crichton 已提交
1082 1083 1084 1085 1086 1087 1088

endef

$(foreach stage,$(STAGES), \
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
   $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))