tests.mk 10.8 KB
Newer Older
G
Graydon Hoare 已提交
1 2 3 4 5 6 7 8
######################################################################
# Testing variables
######################################################################

ALL_TEST_INPUTS = $(wildcard $(S)src/test/*/*.rs   \
                              $(S)src/test/*/*/*.rs \
                              $(S)src/test/*/*.rc)

9
RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
B
Brian Anderson 已提交
10
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
11 12 13 14
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)
15 16
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
G
Graydon Hoare 已提交
17

18 19 20 21
# perf tests are the same as bench tests only they run under
# a performance monitor.
PERF_RS := $(wildcard $(S)src/test/bench/*.rs)

B
Brian Anderson 已提交
22 23 24
RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
25
BENCH_TESTS := $(BENCH_RS)
26
PERF_TESTS := $(PERF_RS)
27
PRETTY_TESTS := $(PRETTY_RS)
G
Graydon Hoare 已提交
28

29 30 31 32 33
FT := run_pass_stage2
FT_LIB := $(call CFG_LIB_NAME,$(FT))
FT_DRIVER := $(FT)_driver
GENERATED += test/$(FT).rc test/$(FT_DRIVER).rs

B
Brian Anderson 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46
# 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
47

48 49 50 51 52
# Arguments to the perf tests
ifdef CFG_PERF_TOOL
  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
endif

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

B
Brian Anderson 已提交
55 56 57
ifdef VERBOSE
  CTEST_TESTARGS += --verbose
endif
58

B
Brian Anderson 已提交
59 60 61
# The test runner that runs the cfail/rfail/rpass and bench tests
COMPILETEST_CRATE := $(S)src/test/compiletest/compiletest.rc
COMPILETEST_INPUTS := $(wildcard $(S)src/test/compiletest/*rs)
62

B
Brian Anderson 已提交
63 64 65
# The standard library test crate
STDTEST_CRATE := $(S)src/test/stdtest/stdtest.rc
STDTEST_INPUTS := $(wildcard $(S)src/test/stdtest/*rs)
66

67 68 69 70 71 72
# Run the compiletest runner itself under valgrind
ifdef CTEST_VALGRIND
  CFG_RUN_CTEST=$(call CFG_RUN_TEST,$(2))
else
  CFG_RUN_CTEST=$(call CFG_RUN,stage$(1)/lib,$(2))
endif
73

B
Brian Anderson 已提交
74 75 76 77 78
######################################################################
# Main test targets
######################################################################

check: tidy check-stage2 \
79

B
Brian Anderson 已提交
80
check-full: tidy check-stage1 check-stage2 check-stage3 \
81

82
check-fast: tidy \
B
Brian Anderson 已提交
83 84
	check-stage2-rustc check-stage2-std \
	test/$(FT_DRIVER).out \
85

B
Brian Anderson 已提交
86 87 88 89 90 91 92 93
tidy:
	@$(call E, check: formatting)
	$(Q)echo \
	  $(filter-out $(GENERATED) $(addprefix $(S)src/, $(GENERATED)) \
	    $(addprefix $(S)src/, $(RUSTLLVM_LIB_CS) $(RUSTLLVM_OBJS_CS) \
	      $(RUSTLLVM_HDR) $(PKG_3RDPARTY)) \
	    $(S)src/etc/%, $(PKG_FILES)) \
	  | xargs -n 10 python $(S)src/etc/tidy.py
G
Graydon Hoare 已提交
94

B
Brian Anderson 已提交
95 96
# Cancel the implicit .out rule in GNU make
%.out: %
G
Graydon Hoare 已提交
97

B
Brian Anderson 已提交
98 99
%.out: %.out.tmp
	$(Q)mv $< $@
G
Graydon Hoare 已提交
100

101 102

######################################################################
B
Brian Anderson 已提交
103
# Rules for the test runners
104 105
######################################################################

B
Brian Anderson 已提交
106 107
# StageN template: to stay consistent with stageN.mk, arge 2 is the
# stage being tested, arg 1 is stage N-1
108

B
Brian Anderson 已提交
109
define TEST_STAGEN
110

111 112 113 114 115 116 117 118
# FIXME: These rules are complicated by a scheme to produce .out files
# for each test, with the idea that if the targets produce actual
# output, subsequent "make check's" will just exit successfully
# without re-running the tests. Unfortunately this scheme is currently
# broken and the tests rerun with every invocation of "make check"
# anyway. Nobody seems to have noticed, so it would be simpler to just
# remove all the code here involved with producing .out files.

B
Brian Anderson 已提交
119 120 121 122 123 124 125
check-stage$(2): tidy \
	check-stage$(2)-rustc \
	check-stage$(2)-std \
	check-stage$(2)-rpass \
	check-stage$(2)-rfail \
	check-stage$(2)-cfail \
	check-stage$(2)-bench \
126
	check-stage$(2)-pretty \
127 128


B
Brian Anderson 已提交
129
# Rules for the standard library test runner
130

B
Brian Anderson 已提交
131
check-stage$(2)-std: test/stdtest.stage$(2).out \
G
Graydon Hoare 已提交
132

B
Brian Anderson 已提交
133 134 135
test/stdtest.stage$(2)$$(X): $$(STDTEST_CRATE) $$(STDTEST_INPUTS) \
                             $$(SREQ$(2))
	@$$(call E, compile_and_link: $$@)
136
	$$(STAGE$(2)) -o $$@ $$< --test
137

B
Brian Anderson 已提交
138 139 140 141
test/stdtest.stage$(2).out.tmp: test/stdtest.stage$(2)$$(X)
	@$$(call E, run: $$<)
	$$(Q)$$(call CFG_RUN_TEST,$$<) $$(TESTARGS)
	$$(Q)touch $$@
142 143


B
Brian Anderson 已提交
144
# Rules for the rustc test runner
145

B
Brian Anderson 已提交
146
check-stage$(2)-rustc: test/rustctest.stage$(2).out \
G
Graydon Hoare 已提交
147

B
Brian Anderson 已提交
148 149 150 151 152 153 154
test/rustctest.stage$(2)$$(X): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
                           stage$(2)/$$(CFG_RUNTIME) \
                           $$(call CFG_STDLIB_DEFAULT,stage$(1),stage$(2)) \
                           stage$(2)/$$(CFG_RUSTLLVM) \
                           $$(SREQ$(1))
	@$$(call E, compile_and_link: $$@)
	$$(STAGE$(1)) -o $$@ $$< --test
G
Graydon Hoare 已提交
155

B
Brian Anderson 已提交
156 157 158 159 160
test/rustctest.stage$(2).out.tmp: test/rustctest.stage$(2)$$(X)
	@$$(call E, run: $$<)
	$$(Q)$$(call CFG_RUN,stage$(2),$$(CFG_VALGRIND) $$<) \
	  $$(TESTARGS)
	$$(Q)touch $$@
G
Graydon Hoare 已提交
161 162


163
# Rules for the cfail/rfail/rpass/bench/perf test runner
G
Graydon Hoare 已提交
164

B
Brian Anderson 已提交
165
check-stage$(2)-cfail: test/compile-fail.stage$(2).out \
166

B
Brian Anderson 已提交
167
check-stage$(2)-rfail: test/run-fail.stage$(2).out \
168

B
Brian Anderson 已提交
169
check-stage$(2)-rpass: test/run-pass.stage$(2).out \
170

B
Brian Anderson 已提交
171
check-stage$(2)-bench: test/bench.stage$(2).out \
172

173 174
check-stage$(2)-perf: test/perf.stage$(2).out \

175 176 177 178
check-stage$(2)-pretty-rpass: test/pretty-rpass.stage$(2).out \

check-stage$(2)-pretty-rfail: test/pretty-rfail.stage$(2).out \

179 180
check-stage$(2)-pretty-bench: test/pretty-bench.stage$(2).out \

181 182 183 184
check-stage$(2)-pretty-pretty: test/pretty-pretty.stage$(2).out \

check-stage$(2)-pretty: check-stage$(2)-pretty-rpass \
                        check-stage$(2)-pretty-rfail \
185
                        check-stage$(2)-pretty-bench \
186 187
                        check-stage$(2)-pretty-pretty \

B
Brian Anderson 已提交
188 189 190 191 192 193
CTEST_COMMON_ARGS$(2) := --compile-lib-path stage$(2) \
                         --run-lib-path stage$(2)/lib \
                         --rustc-path stage$(2)/rustc$$(X) \
                         --stage-id stage$(2) \
                         --rustcflags "$$(CFG_RUSTC_FLAGS)" \
                         $$(CTEST_TESTARGS) \
194

B
Brian Anderson 已提交
195 196 197 198
CFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                  --src-base $$(S)src/test/compile-fail/ \
                  --build-base test/compile-fail/ \
                  --mode compile-fail \
199

B
Brian Anderson 已提交
200 201 202 203
RFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                  --src-base $$(S)src/test/run-fail/ \
                  --build-base test/run-fail/ \
                  --mode run-fail \
204
                  $$(CTEST_RUNTOOL) \
205

B
Brian Anderson 已提交
206 207 208 209 210
RPASS_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                  --src-base $(S)src/test/run-pass/ \
                  --build-base test/run-pass/ \
                  --mode run-pass \
                  $$(CTEST_RUNTOOL) \
211

B
Brian Anderson 已提交
212 213 214 215 216
BENCH_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                  --src-base $(S)src/test/bench/ \
                  --build-base test/bench/ \
                  --mode run-pass \
                  $$(CTEST_RUNTOOL) \
217

218 219 220 221 222 223
PERF_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                  --src-base $(S)src/test/bench/ \
                  --build-base test/perf/ \
                  --mode run-pass \
                  $$(CTEST_PERF_RUNTOOL) \

224 225 226 227 228 229 230 231 232
PRETTY_RPASS_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                         --src-base $$(S)src/test/run-pass/ \
                         --build-base test/run-pass/ \
                         --mode pretty \

PRETTY_RFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                         --src-base $$(S)src/test/run-fail/ \
                         --build-base test/run-fail/ \
                         --mode pretty \
233

234 235 236 237 238
PRETTY_BENCH_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                         --src-base $$(S)src/test/bench/ \
                         --build-base test/bench/ \
                         --mode pretty \

239 240 241 242 243
PRETTY_PRETTY_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
                          --src-base $$(S)src/test/pretty/ \
                          --build-base test/pretty/ \
                          --mode pretty \

B
Brian Anderson 已提交
244 245 246 247 248
test/compiletest.stage$(2)$$(X): $$(COMPILETEST_CRATE) \
                                 $$(COMPILETEST_INPUTS) \
                                 $$(SREQ$(2))
	@$$(call E, compile_and_link: $$@)
	$$(STAGE$(2)) -o $$@ $$<
249

B
Brian Anderson 已提交
250 251 252
test/compile-fail.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                                   $$(CFAIL_TESTS)
	@$$(call E, run: $$<)
253
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(CFAIL_ARGS$(2))
B
Brian Anderson 已提交
254
	$$(Q)touch $$@
255

B
Brian Anderson 已提交
256 257 258
test/run-fail.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                               $$(RFAIL_TESTS)
	@$$(call E, run: $$<)
259
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(RFAIL_ARGS$(2))
B
Brian Anderson 已提交
260 261 262 263 264
	$$(Q)touch $$@

test/run-pass.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                               $$(RPASS_TESTS)
	@$$(call E, run: $$<)
265
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(RPASS_ARGS$(2))
B
Brian Anderson 已提交
266 267 268 269 270
	$$(Q)touch $$@

test/bench.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                            $$(BENCH_TESTS)
	@$$(call E, run: $$<)
271
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(BENCH_ARGS$(2))
B
Brian Anderson 已提交
272
	$$(Q)touch $$@
273

274 275 276 277 278 279
test/perf.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                            $$(BENCH_TESTS)
	@$$(call E, perf: $$<)
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PERF_ARGS$(2))
	$$(Q)touch $$@

280 281 282 283 284 285 286 287
test/pretty-rpass.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                                     $$(RPASS_TESTS)
	@$$(call E, run: $$<)
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_RPASS_ARGS$(2))
	$$(Q)touch $$@

test/pretty-rfail.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                                     $$(RFAIL_TESTS)
288
	@$$(call E, run: $$<)
289 290 291
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_RFAIL_ARGS$(2))
	$$(Q)touch $$@

292 293 294 295 296 297
test/pretty-bench.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                                     $$(BENCH_TESTS)
	@$$(call E, run: $$<)
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_BENCH_ARGS$(2))
	$$(Q)touch $$@

298 299 300 301
test/pretty-pretty.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
                                     $$(PRETTY_TESTS)
	@$$(call E, run: $$<)
	$$(Q)$$(call CFG_RUN_CTEST,$(2),$$<) $$(PRETTY_PRETTY_ARGS$(2))
302 303
	$$(Q)touch $$@

B
Brian Anderson 已提交
304
endef
305

306
# Instantiate the template for stage 0, 1, 2, 3
307

308
$(eval $(call TEST_STAGEN,0,0))
B
Brian Anderson 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
$(eval $(call TEST_STAGEN,0,1))
$(eval $(call TEST_STAGEN,1,2))
$(eval $(call TEST_STAGEN,2,3))


######################################################################
# Fast-test rules
######################################################################

test/$(FT).rc test/$(FT_DRIVER).rs: $(TEST_RPASS_SOURCES_STAGE2) \
    $(S)src/etc/combine-tests.py
	@$(call E, check: building combined stage2 test runner)
	$(Q)$(S)src/etc/combine-tests.py

stage2/lib/$(FT_LIB): test/$(FT).rc $(SREQ2)
	@$(call E, compile_and_link: $@)
	$(STAGE2) --lib -o $@ $<

test/$(FT_DRIVER)$(X): test/$(FT_DRIVER).rs stage2/lib/$(FT_LIB) $(SREQ2)
	@$(call E, compile_and_link: $@)
	$(STAGE2) -o $@ $<

test/$(FT_DRIVER).out: test/$(FT_DRIVER)$(X) $(SREQ2)
332
	$(Q)$(call CFG_RUN_TEST, $<)