tests.mk 20.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
# Copyright 2012 The Rust Project Developers. See the COPYRIGHT
# 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 17
# The names of crates that must be tested
TEST_CRATES = core std syntax rustc rustdoc rusti cargo
G
Graydon Hoare 已提交
18

19 20
# Markdown files under doc/ that should have their code extracted and run
DOC_TEST_NAMES = tutorial tutorial-ffi tutorial-macros tutorial-borrowed-ptr tutorial-tasks rust
21

22 23 24
######################################################################
# Environment configuration
######################################################################
25

B
Brian Anderson 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38
# The arguments to all test runners
ifdef TESTNAME
  TESTARGS += $(TESTNAME)
endif

ifdef CHECK_XFAILS
  TESTARGS += --ignored
endif

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

40 41 42 43 44
# Arguments to the perf tests
ifdef CFG_PERF_TOOL
  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
endif

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

B
Brian Anderson 已提交
47 48 49
ifdef VERBOSE
  CTEST_TESTARGS += --verbose
endif
50

51 52
# Run the compiletest runner itself under valgrind
ifdef CTEST_VALGRIND
53
  CFG_RUN_CTEST=$(call CFG_RUN_TEST,$(2),$(3))
54
else
N
Niko Matsakis 已提交
55
  CFG_RUN_CTEST=$(call CFG_RUN,$(TLIB$(1)_T_$(3)_H_$(3)),$(2))
56
endif
57

58 59 60 61 62 63 64
# If we're running perf then set this environment variable
# to put the benchmarks into 'hard mode'
ifeq ($(MAKECMDGOALS),perf)
  RUST_BENCH=1
  export RUST_BENCH
endif

65 66
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
67

B
Brian Anderson 已提交
68 69 70 71
######################################################################
# Main test targets
######################################################################

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
check: cleantestlibs cleantmptestlogs tidy all check-stage2
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

check-notidy: cleantestlibs cleantmptestlogs all check-stage2
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

check-full: cleantestlibs cleantmptestlogs tidy \
            all check-stage1 check-stage2 check-stage3
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

check-test: cleantestlibs cleantmptestlogs all check-stage2-rfail
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

check-lite: cleantestlibs cleantmptestlogs \
	check-stage2-core check-stage2-std check-stage2-rpass \
	check-stage2-rfail check-stage2-cfail
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

90 91
.PHONY: cleantmptestlogs cleantestlibs

92 93
cleantmptestlogs:
	$(Q)rm -f tmp/*.log
94

95 96 97 98 99 100 101 102 103
cleantestlibs:
	$(Q)find $(CFG_HOST_TRIPLE)/test \
         -name '*.[odasS]' -o \
         -name '*.so' -o      \
         -name '*.dylib' -o   \
         -name '*.dll' -o     \
         -name '*.def' -o     \
         -name '*.bc' -o      \
         -name '*.dSYM' -o    \
104
         -name '*.libaux' -o      \
105
         -name '*.out' -o     \
B
Brian Leibig 已提交
106 107
         -name '*.err' -o     \
	 -name '*.debugger.script' \
108
         | xargs rm -rf
109

110

111 112 113
######################################################################
# Tidy
######################################################################
B
Brian Anderson 已提交
114

115
ifdef CFG_NOTIDY
B
Brian Anderson 已提交
116
tidy:
117
else
118 119 120 121 122 123 124

ALL_CS := $(wildcard $(S)src/rt/*.cpp \
                     $(S)src/rt/*/*.cpp \
                     $(S)src/rt/*/*/*.cpp \
                     $(S)srcrustllvm/*.cpp)
ALL_CS := $(filter-out $(S)src/rt/bigint/bigint_ext.cpp \
                       $(S)src/rt/bigint/bigint_int.cpp \
125
                       $(S)src/rt/miniz.cpp \
126
                       $(S)src/rt/linenoise/linenoise.c \
B
Brian Anderson 已提交
127
                       $(S)src/rt/linenoise/utf8.c \
128 129 130 131 132 133 134 135 136 137 138 139 140
	,$(ALL_CS))
ALL_HS := $(wildcard $(S)src/rt/*.h \
                     $(S)src/rt/*/*.h \
                     $(S)src/rt/*/*/*.h \
                     $(S)srcrustllvm/*.h)
ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
                       $(S)src/rt/vg/memcheck.h \
                       $(S)src/rt/uthash/uthash.h \
                       $(S)src/rt/uthash/utlist.h \
                       $(S)src/rt/msvc/typeof.h \
                       $(S)src/rt/msvc/stdint.h \
                       $(S)src/rt/msvc/inttypes.h \
                       $(S)src/rt/bigint/bigint.h \
141
                       $(S)src/rt/linenoise/linenoise.h \
B
Brian Anderson 已提交
142
                       $(S)src/rt/linenoise/utf8.h \
143 144
	,$(ALL_HS))

145
# Run the tidy script in multiple parts to avoid huge 'echo' commands
146 147
tidy:
		@$(call E, check: formatting)
148
		$(Q)find $(S)src -name '*.r[sc]' \
149
		| grep '^$(S)src/test' -v \
150
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
151
		$(Q)find $(S)src/etc -name '*.py' \
152
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
153
		$(Q)echo $(ALL_CS) \
154
	  	| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
155
		$(Q)echo $(ALL_HS) \
156
	  	| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
157

158
endif
159

160

B
Brian Anderson 已提交
161
######################################################################
162
# Sets of tests
B
Brian Anderson 已提交
163 164
######################################################################

165 166 167 168 169 170 171 172 173
define DEF_TEST_SETS

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			\
	check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec			\
        check-stage$(1)-T-$(2)-H-$(3)-crates-exec                      \
	check-stage$(1)-T-$(2)-H-$(3)-bench-exec			\
174
	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-exec \
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
	check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-exec

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

check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
        $$(foreach docname,$$(DOC_TEST_NAMES), \
           check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec)

check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec	\
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec	\
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec	\
	check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec	\
	check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
192

B
Brian Anderson 已提交
193 194 195
endef

$(foreach host,$(CFG_TARGET_TRIPLES), \
196 197 198 199
 $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(foreach stage,$(STAGES), \
    $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))

B
Brian Anderson 已提交
200

201
######################################################################
202
# Crate testing
203 204
######################################################################

205
define TEST_RUNNER
206 207 208

$(3)/test/coretest.stage$(1)-$(2)$$(X):			\
		$$(CORELIB_CRATE) $$(CORELIB_INPUTS)	\
209
		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB)
210
	@$$(call E, compile_and_link: $$@)
211
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
212

N
Niko Matsakis 已提交
213
$(3)/test/stdtest.stage$(1)-$(2)$$(X):			\
214
		$$(STDLIB_CRATE) $$(STDLIB_INPUTS)	\
215
		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB)
B
Brian Anderson 已提交
216
	@$$(call E, compile_and_link: $$@)
N
Niko Matsakis 已提交
217
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
218

219 220
$(3)/test/syntaxtest.stage$(1)-$(2)$$(X):			\
		$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS)	\
221
		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB)
222 223 224
	@$$(call E, compile_and_link: $$@)
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test

N
Niko Matsakis 已提交
225
$(3)/test/rustctest.stage$(1)-$(2)$$(X):					\
226
		$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
227 228
		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM) \
                $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX)
B
Brian Anderson 已提交
229
	@$$(call E, compile_and_link: $$@)
N
Niko Matsakis 已提交
230
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
231

232 233 234 235 236
$(3)/test/cargotest.stage$(1)-$(2)$$(X):					\
		$$(CARGO_LIB) $$(CARGO_INPUTS)		\
		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
	@$$(call E, compile_and_link: $$@)
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
237

238 239 240 241 242
$(3)/test/rustitest.stage$(1)-$(2)$$(X):					\
		$$(RUSTI_LIB) $$(RUSTI_INPUTS)		\
		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
	@$$(call E, compile_and_link: $$@)
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
243 244

$(3)/test/rustdoctest.stage$(1)-$(2)$$(X):					\
245
		$$(RUSTDOC_LIB) $$(RUSTDOC_INPUTS)		\
246 247 248 249
		$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
	@$$(call E, compile_and_link: $$@)
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test

250 251 252 253 254 255 256 257
endef

$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(call TEST_RUNNER,$(stage),$(target),$(host))))))))

define DEF_TEST_CRATE_RULES
258 259 260
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)): \
261
		$(3)/test/$(4)test.stage$(1)-$(2)$$(X)
262
	@$$(call E, run: $$<)
263
	$$(Q)$$(call CFG_RUN_TEST,$$<,$(2),$(3)) $$(TESTARGS)	\
264 265
	--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
	&& touch $$@
266
endef
267

268 269 270 271 272
$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(foreach stage,$(STAGES), \
   $(foreach crate, $(TEST_CRATES), \
    $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate)))))))
273 274


275 276 277 278 279 280 281 282 283 284 285 286 287 288
######################################################################
# Rules for the compiletest tests (rpass, rfail, etc.)
######################################################################

RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
B
Brian Anderson 已提交
289
DEBUGINFO_RS := $(wildcard $(S)src/test/debug-info/*.rs)
290

291 292 293
# perf tests are the same as bench tests only they run under
# a performance monitor.
PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
294

295 296 297 298 299 300 301
RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
BENCH_TESTS := $(BENCH_RS)
PERF_TESTS := $(PERF_RS)
PRETTY_TESTS := $(PRETTY_RS)
B
Brian Leibig 已提交
302
DEBUGINFO_TESTS := $(DEBUGINFO_RS)
B
Brian Anderson 已提交
303

304 305 306 307
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 已提交
308

309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
CTEST_SRC_BASE_rpass-full = run-pass-full
CTEST_BUILD_BASE_rpass-full = run-pass-full
CTEST_MODE_rpass-full = run-pass
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)

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)

CTEST_SRC_BASE_bench = bench
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)

B
Brian Leibig 已提交
334 335 336 337 338
CTEST_SRC_BASE_debuginfo = debug-info
CTEST_BUILD_BASE_debuginfo = debug-info
CTEST_MODE_debuginfo = debug-info
CTEST_RUNTOOL_debuginfo = $(CTEST_RUNTOOL)

339 340 341 342
ifeq ($(CFG_GDB),)
CTEST_DISABLE_debuginfo = "no gdb found"
endif

343 344 345 346 347 348 349 350 351 352 353 354 355
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) = \
	$$(HBIN$(1)_H_$(3))/compiletest$$(X) \
	$$(SREQ$(1)_T_$(2)_H_$(3))
B
Brian Anderson 已提交
356

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

N
Niko Matsakis 已提交
359
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) :=						\
N
Niko Matsakis 已提交
360 361 362
		--compile-lib-path $$(HLIB$(1)_H_$(3))				\
        --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3))			\
        --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X)			\
363
        --aux-base $$(S)src/test/auxiliary/                 \
N
Niko Matsakis 已提交
364
        --stage-id stage$(1)-$(2)							\
365
       --rustcflags "$$(CFG_RUSTC_FLAGS) --target=$(2)"	\
N
Niko Matsakis 已提交
366 367
        $$(CTEST_TESTARGS)

368 369 370 371 372 373
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
CTEST_DEPS_rpass_full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
B
Brian Leibig 已提交
374
CTEST_DEPS_debuginfo_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_TESTS)
N
Niko Matsakis 已提交
375

376
endef
N
Niko Matsakis 已提交
377

378 379 380 381
$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
N
Niko Matsakis 已提交
382

383
define DEF_RUN_COMPILETEST
384

385 386 387 388 389 390
CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
        --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
        --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
        --mode $$(CTEST_MODE_$(4)) \
	$$(CTEST_RUNTOOL_$(4))
N
Niko Matsakis 已提交
391

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

394 395
ifeq ($$(CTEST_DISABLE_$(4)),)

396
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
397 398 399 400 401
		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
	@$$(call E, run $(4): $$<)
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<,$(3)) \
		$$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
402 403
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
                && touch $$@
N
Niko Matsakis 已提交
404

405 406 407 408 409 410 411 412 413 414 415
else

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
	@$$(call E, run $(4): $$<)
	@$$(call E, warning: tests disabled: $$(CTEST_DISABLE_$(4)))
	touch $$@

endif

416
endef
N
Niko Matsakis 已提交
417

B
Brian Leibig 已提交
418
CTEST_NAMES = rpass rpass-full rfail cfail bench perf debuginfo
419

420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(foreach name,$(CTEST_NAMES), \
   $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))

PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
PRETTY_DIRNAME_pretty-rpass = run-pass
PRETTY_DIRNAME_pretty-rpass-full = run-pass-full
PRETTY_DIRNAME_pretty-rfail = run-fail
PRETTY_DIRNAME_pretty-bench = bench
PRETTY_DIRNAME_pretty-pretty = pretty

define DEF_RUN_PRETTY_TEST

PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) :=			\
N
Niko Matsakis 已提交
441
		$$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
442 443
        --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
        --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
N
Niko Matsakis 已提交
444 445
        --mode pretty

446 447 448
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)): \
449 450 451 452 453
	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))		\
	        $$(PRETTY_DEPS_$(4))
	@$$(call E, run pretty-rpass: $$<)
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<,$(3)) \
		$$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
454 455
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
                && touch $$@
N
Niko Matsakis 已提交
456

457
endef
N
Niko Matsakis 已提交
458

459 460 461 462 463
$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(foreach stage,$(STAGES), \
   $(foreach pretty-name,$(PRETTY_NAMES), \
    $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
B
Brian Anderson 已提交
464

465
define DEF_RUN_DOC_TEST
466

467 468 469 470
DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
        --src-base $(3)/test/doc-$(4)/	\
        --build-base $(3)/test/doc-$(4)/	\
471 472
        --mode run-pass

473 474 475
check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
476 477 478 479 480
	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))		\
                doc-$(4)-extract$(3)
	@$$(call E, run doc-$(4): $$<)
	$$(Q)$$(call CFG_RUN_CTEST,$(1),$$<,$(3)) \
                $$(DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
481 482
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),doc-$(4)) \
                && touch $$@
483

484
endef
485

486 487 488 489 490
$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(foreach stage,$(STAGES), \
   $(foreach docname,$(DOC_TEST_NAMES), \
    $(eval $(call DEF_RUN_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
491

492

493 494 495
######################################################################
# Extracting tests for docs
######################################################################
B
Brian Anderson 已提交
496

497
EXTRACT_TESTS := "$(CFG_PYTHON)" $(S)src/etc/extract-tests.py
B
Brian Anderson 已提交
498

499
define DEF_DOC_TEST_HOST
500

501 502 503 504
doc-$(2)-extract$(1):
	@$$(call E, extract: $(2) tests)
	$$(Q)rm -f $(1)/test/doc-$(2)/*.rs
	$$(Q)$$(EXTRACT_TESTS) $$(S)doc/$(2).md $(1)/test/doc-$(2)
505

506
endef
507

508 509 510
$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(foreach docname,$(DOC_TEST_NAMES), \
  $(eval $(call DEF_DOC_TEST_HOST,$(host),$(docname)))))
511

512

513 514 515
######################################################################
# Shortcut rules
######################################################################
516

517 518 519 520 521 522 523 524 525
TEST_GROUPS = \
	crates \
	$(foreach crate,$(TEST_CRATES),$(crate)) \
	rpass \
	rpass-full \
	rfail \
	cfail \
	bench \
	perf \
B
Brian Leibig 已提交
526
	debuginfo \
527 528 529 530 531 532 533 534 535 536 537 538 539
	doc \
	$(foreach docname,$(DOC_TEST_NAMES),$(docname)) \
	pretty \
	pretty-rpass \
	pretty-rpass-full \
	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
540

541 542 543 544
$(foreach stage,$(STAGES), \
 $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(foreach host,$(CFG_TARGET_TRIPLES), \
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
545

546 547 548
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 已提交
549

550 551 552 553 554
$(foreach stage,$(STAGES), \
 $(foreach target,$(CFG_TARGET_TRIPLES), \
  $(foreach host,$(CFG_TARGET_TRIPLES), \
   $(foreach group,$(TEST_GROUPS), \
    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
555

556 557 558 559 560
define DEF_CHECK_FOR_STAGE
check-stage$(1): check-stage$(1)-H-$$(CFG_HOST_TRIPLE)
check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET_TRIPLES), \
                           check-stage$(1)-H-$$(target))
endef
561

562 563
$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
564

565 566 567 568 569
define DEF_CHECK_FOR_STAGE_AND_GROUP
check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_HOST_TRIPLE)-$(2)
check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET_TRIPLES), \
                               check-stage$(1)-H-$$(target)-$(2))
endef
570

571 572 573
$(foreach stage,$(STAGES), \
 $(foreach group,$(TEST_GROUPS), \
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
574

575 576 577 578

define DEF_CHECK_FOR_STAGE_AND_HOSTS
check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET_TRIPLES), \
                           check-stage$(1)-T-$$(target)-H-$(2))
B
Brian Anderson 已提交
579
endef
580

581 582 583 584 585 586 587 588 589 590 591 592 593
$(foreach stage,$(STAGES), \
 $(foreach host,$(CFG_TARGET_TRIPLES), \
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))

define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET_TRIPLES), \
                                check-stage$(1)-T-$$(target)-H-$(2)-$(3))
endef

$(foreach stage,$(STAGES), \
 $(foreach host,$(CFG_TARGET_TRIPLES), \
  $(foreach group,$(TEST_GROUPS), \
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
594

B
Brian Anderson 已提交
595

N
Niko Matsakis 已提交
596
######################################################################
597
# check-fast rules
N
Niko Matsakis 已提交
598
######################################################################
599

600 601 602 603
FT := run_pass_stage2
FT_LIB := $(call CFG_LIB_NAME,$(FT))
FT_DRIVER := $(FT)_driver

604
GENERATED += tmp/$(FT).rc tmp/$(FT_DRIVER).rs
N
Niko Matsakis 已提交
605

N
Niko Matsakis 已提交
606
tmp/$(FT).rc tmp/$(FT_DRIVER).rs: \
607
		$(RPASS_TESTS) \
N
Niko Matsakis 已提交
608 609
		$(S)src/etc/combine-tests.py
	@$(call E, check: building combined stage2 test runner)
610
	$(Q)$(CFG_PYTHON) $(S)src/etc/combine-tests.py
N
Niko Matsakis 已提交
611 612 613 614 615 616 617 618 619 620

define DEF_CHECK_FAST_FOR_T_H
# $(1) unused
# $(2) target triple
# $(3) host triple

$$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB): \
		tmp/$$(FT).rc \
		$$(SREQ2_T_$(2)_H_$(3))
	@$$(call E, compile_and_link: $$@)
N
Niko Matsakis 已提交
621
	$$(STAGE2_T_$(2)_H_$(3)) --lib -o $$@ $$<
N
Niko Matsakis 已提交
622

N
Niko Matsakis 已提交
623 624 625 626 627
$(3)/test/$$(FT_DRIVER)-$(2)$$(X): \
		tmp/$$(FT_DRIVER).rs \
		$$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB) \
		$$(SREQ2_T_$(2)_H_$(3))
	@$$(call E, compile_and_link: $$@ $$<)
628
	$$(STAGE2_T_$(2)_H_$(3)) -o $$@ $$<
N
Niko Matsakis 已提交
629

N
Niko Matsakis 已提交
630 631 632
$(3)/test/$$(FT_DRIVER)-$(2).out: \
		$(3)/test/$$(FT_DRIVER)-$(2)$$(X) \
		$$(SREQ2_T_$(2)_H_$(3))
633 634
	$$(Q)$$(call CFG_RUN_TEST,$$<,$(2),$(3)) \
	--logfile tmp/$$(FT_DRIVER)-$(2).log
N
Niko Matsakis 已提交
635

636
check-fast-T-$(2)-H-$(3):     			\
N
Niko Matsakis 已提交
637
	$(3)/test/$$(FT_DRIVER)-$(2).out
N
Niko Matsakis 已提交
638 639 640 641 642 643 644

endef

$(foreach host,$(CFG_TARGET_TRIPLES), \
 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
   $(eval $(call DEF_CHECK_FAST_FOR_T_H,,$(target),$(host))))))

645
check-fast: tidy check-fast-H-$(CFG_HOST_TRIPLE)
N
Niko Matsakis 已提交
646 647 648 649 650 651

define DEF_CHECK_FAST_FOR_H

check-fast-H-$(1): 		check-fast-T-$(1)-H-$(1)

endef
N
Niko Matsakis 已提交
652

N
Niko Matsakis 已提交
653 654 655
$(foreach target,$(CFG_TARGET_TRIPLES),			\
 $(eval $(call DEF_CHECK_FAST_FOR_H,$(target))))