]> git.lizzy.rs Git - rust.git/blob - mk/tests.mk
auto merge of #12099 : alexcrichton/rust/rpath-tests, r=thestinger
[rust.git] / mk / tests.mk
1 # Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
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 TEST_TARGET_CRATES = $(TARGET_CRATES)
18 TEST_DOC_CRATES = $(DOC_CRATES)
19 TEST_HOST_CRATES = $(HOST_CRATES)
20 TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
21
22 # Markdown files under doc/ that should have their code extracted and run
23 DOC_TEST_NAMES = tutorial guide-ffi guide-macros guide-lifetimes \
24                  guide-tasks guide-container guide-pointers \
25                  complement-cheatsheet guide-runtime \
26                  rust
27
28 ######################################################################
29 # Environment configuration
30 ######################################################################
31
32 # The arguments to all test runners
33 ifdef TESTNAME
34   TESTARGS += $(TESTNAME)
35 endif
36
37 ifdef CHECK_XFAILS
38   TESTARGS += --ignored
39 endif
40
41 TEST_BENCH = --bench
42
43 # Arguments to the cfail/rfail/rpass/bench tests
44 ifdef CFG_VALGRIND
45   CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
46   TEST_BENCH =
47 endif
48
49 ifdef NO_BENCH
50   TEST_BENCH =
51 endif
52
53 # Arguments to the perf tests
54 ifdef CFG_PERF_TOOL
55   CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
56 endif
57
58 CTEST_TESTARGS := $(TESTARGS)
59
60 ifdef VERBOSE
61   CTEST_TESTARGS += --verbose
62 endif
63
64 # If we're running perf then set this environment variable
65 # to put the benchmarks into 'hard mode'
66 ifeq ($(MAKECMDGOALS),perf)
67   RUST_BENCH=1
68   export RUST_BENCH
69 endif
70
71 TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
72 TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
73
74 TEST_RATCHET_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4)-metrics.json
75 TEST_RATCHET_NOISE_PERCENT=10.0
76
77 # Whether to ratchet or merely save benchmarks
78 ifdef CFG_RATCHET_BENCH
79 CRATE_TEST_EXTRA_ARGS=\
80   --test $(TEST_BENCH) \
81   --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
82   --ratchet-noise-percent $(TEST_RATCHET_NOISE_PERCENT)
83 else
84 CRATE_TEST_EXTRA_ARGS=\
85   --test $(TEST_BENCH) \
86   --save-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4))
87 endif
88
89 # If we're sharding the testsuite between parallel testers,
90 # pass this argument along to the compiletest and crate test
91 # invocations.
92 ifdef TEST_SHARD
93   CTEST_TESTARGS += --test-shard=$(TEST_SHARD)
94   CRATE_TEST_EXTRA_ARGS += --test-shard=$(TEST_SHARD)
95 endif
96
97 define DEF_TARGET_COMMANDS
98
99 ifdef CFG_UNIXY_$(1)
100   CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
101 endif
102
103 ifdef CFG_WINDOWSY_$(1)
104   CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
105    $$(if $$(findstring stage0,$$(1)), \
106        stage0/$$(CFG_LIBDIR_RELATIVE), \
107       $$(if $$(findstring stage1,$$(1)), \
108            stage1/$$(CFG_LIBDIR_RELATIVE), \
109           $$(if $$(findstring stage2,$$(1)), \
110                stage2/$$(CFG_LIBDIR_RELATIVE), \
111                $$(if $$(findstring stage3,$$(1)), \
112                     stage3/$$(CFG_LIBDIR_RELATIVE), \
113                )))))/$$(CFG_RUSTLIBDIR)/$$(CFG_BUILD)/lib
114   CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(3)),$$(1))
115 endif
116
117 # Run the compiletest runner itself under valgrind
118 ifdef CTEST_VALGRIND
119 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
120       $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(2),$$(3))
121 else
122 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
123       $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
124 endif
125
126 endef
127
128 $(foreach target,$(CFG_TARGET), \
129   $(eval $(call DEF_TARGET_COMMANDS,$(target))))
130
131 # Target platform specific variables
132 # for arm-linux-androidabi
133 define DEF_ADB_DEVICE_STATUS
134 CFG_ADB_DEVICE_STATUS=$(1)
135 endef
136
137 $(foreach target,$(CFG_TARGET), \
138   $(if $(findstring $(target),"arm-linux-androideabi"), \
139     $(if $(findstring adb,$(CFG_ADB)), \
140       $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
141         $(info check: android device attached) \
142         $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
143         $(info check: android device not attached) \
144         $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
145       ), \
146       $(info check: adb not found) \
147       $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
148     ), \
149   ) \
150 )
151
152 ifeq ($(CFG_ADB_DEVICE_STATUS),true)
153 CFG_ADB_TEST_DIR=/data/tmp
154
155 $(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
156  $(shell $(CFG_ADB) remount 1>/dev/null) \
157  $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
158  $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
159  $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/tmp) \
160  $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
161  $(foreach crate,$(TARGET_CRATES),\
162     $(shell $(CFG_ADB) push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_arm-linux-androideabi,$(crate)) \
163                     $(CFG_ADB_TEST_DIR)))\
164  )
165 else
166 CFG_ADB_TEST_DIR=
167 endif
168
169
170 ######################################################################
171 # Main test targets
172 ######################################################################
173
174 check: cleantestlibs cleantmptestlogs tidy all check-stage2
175         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
176
177 check-notidy: cleantestlibs cleantmptestlogs all check-stage2
178         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
179
180 check-full: cleantestlibs cleantmptestlogs tidy \
181             all check-stage1 check-stage2 check-stage3
182         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
183
184 check-test: cleantestlibs cleantmptestlogs all check-stage2-rfail
185         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
186
187 check-lite: cleantestlibs cleantmptestlogs \
188         $(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
189         check-stage2-rpass \
190         check-stage2-rfail check-stage2-cfail check-stage2-rmake
191         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
192
193 .PHONY: cleantmptestlogs cleantestlibs
194
195 cleantmptestlogs:
196         $(Q)rm -f tmp/*.log
197
198 cleantestlibs:
199         $(Q)find $(CFG_BUILD)/test \
200          -name '*.[odasS]' -o \
201          -name '*.so' -o      \
202          -name '*.dylib' -o   \
203          -name '*.dll' -o     \
204          -name '*.def' -o     \
205          -name '*.bc' -o      \
206          -name '*.dSYM' -o    \
207          -name '*.libaux' -o      \
208          -name '*.out' -o     \
209          -name '*.err' -o     \
210          -name '*.debugger.script' \
211          | xargs rm -rf
212
213
214 ######################################################################
215 # Tidy
216 ######################################################################
217
218 ifdef CFG_NOTIDY
219 tidy:
220 else
221
222 ALL_CS := $(wildcard $(S)src/rt/*.cpp \
223                      $(S)src/rt/*/*.cpp \
224                      $(S)src/rt/*/*/*.cpp \
225                      $(S)src/rustllvm/*.cpp)
226 ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
227                        $(wildcard $(S)src/rt/sundown/src/*.c) \
228                        $(wildcard $(S)src/rt/sundown/html/*.c) \
229         ,$(ALL_CS))
230 ALL_HS := $(wildcard $(S)src/rt/*.h \
231                      $(S)src/rt/*/*.h \
232                      $(S)src/rt/*/*/*.h \
233                      $(S)src/rustllvm/*.h)
234 ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
235                        $(S)src/rt/vg/memcheck.h \
236                        $(S)src/rt/msvc/typeof.h \
237                        $(S)src/rt/msvc/stdint.h \
238                        $(S)src/rt/msvc/inttypes.h \
239                        $(wildcard $(S)src/rt/sundown/src/*.h) \
240                        $(wildcard $(S)src/rt/sundown/html/*.h) \
241         ,$(ALL_HS))
242
243 # Run the tidy script in multiple parts to avoid huge 'echo' commands
244 tidy:
245                 @$(call E, check: formatting)
246                 $(Q)find $(S)src -name '*.r[sc]' \
247                 | grep '^$(S)src/libuv' -v \
248                 | grep '^$(S)src/llvm' -v \
249                 | grep '^$(S)src/gyp' -v \
250                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
251                 $(Q)find $(S)src/etc -name '*.py' \
252                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
253                 $(Q)echo $(ALL_CS) \
254                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
255                 $(Q)echo $(ALL_HS) \
256                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
257                 $(Q)find $(S)src -type f -perm +111 \
258                     -not -name '*.rs' -and -not -name '*.py' \
259                     -and -not -name '*.sh' \
260                 | grep '^$(S)src/llvm' -v \
261                 | grep '^$(S)src/libuv' -v \
262                 | grep '^$(S)src/gyp' -v \
263                 | grep '^$(S)src/etc' -v \
264                 | grep '^$(S)src/doc' -v \
265                 | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
266
267 endif
268
269
270 ######################################################################
271 # Sets of tests
272 ######################################################################
273
274 define DEF_TEST_SETS
275
276 check-stage$(1)-T-$(2)-H-$(3)-exec:                                     \
277         check-stage$(1)-T-$(2)-H-$(3)-rpass-exec                        \
278         check-stage$(1)-T-$(2)-H-$(3)-rfail-exec                        \
279         check-stage$(1)-T-$(2)-H-$(3)-cfail-exec                        \
280         check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec                   \
281         check-stage$(1)-T-$(2)-H-$(3)-rmake-exec                        \
282         check-stage$(1)-T-$(2)-H-$(3)-crates-exec                       \
283         check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec                   \
284         check-stage$(1)-T-$(2)-H-$(3)-bench-exec                        \
285         check-stage$(1)-T-$(2)-H-$(3)-debuginfo-exec \
286         check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
287         check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
288         check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
289
290 # Only test the compiler-dependent crates when the target is
291 # able to build a compiler (when the target triple is in the set of host triples)
292 ifneq ($$(findstring $(2),$$(CFG_HOST)),)
293
294 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
295         $$(foreach crate,$$(TEST_CRATES), \
296            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
297
298 else
299
300 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
301         $$(foreach crate,$$(TEST_TARGET_CRATES), \
302            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
303
304 endif
305
306 check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
307         $$(foreach crate,$$(TEST_DOC_CRATES), \
308            check-stage$(1)-T-$(2)-H-$(3)-doc-$$(crate)-exec)
309
310 check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
311         $$(foreach docname,$$(DOC_TEST_NAMES), \
312            check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec)
313
314 check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
315         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
316         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec    \
317         check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
318         check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
319         check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
320
321 endef
322
323 $(foreach host,$(CFG_HOST), \
324  $(foreach target,$(CFG_TARGET), \
325   $(foreach stage,$(STAGES), \
326     $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))
327
328
329 ######################################################################
330 # Crate testing
331 ######################################################################
332
333 define TEST_RUNNER
334
335 # If NO_REBUILD is set then break the dependencies on extra so we can
336 # test crates without rebuilding std and extra first
337 ifeq ($(NO_REBUILD),)
338 STDTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
339                             $$(foreach crate,$$(TARGET_CRATES),\
340                                 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate))
341 else
342 STDTESTDEP_$(1)_$(2)_$(3)_$(4) =
343 endif
344
345 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER = $(2)
346 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)):                            \
347                 $$(CRATEFILE_$(4))                                      \
348                 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))              \
349                 $$(STDTESTDEP_$(1)_$(2)_$(3)_$(4))
350         @$$(call E, compile_and_link: $$@)
351         $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test   \
352                 -L "$$(RT_OUTPUT_DIR_$(2))"             \
353                 -L "$$(LLVM_LIBDIR_$(2))"
354
355 endef
356
357 $(foreach host,$(CFG_HOST), \
358  $(eval $(foreach target,$(CFG_TARGET), \
359   $(eval $(foreach stage,$(STAGES), \
360    $(eval $(foreach crate,$(TEST_CRATES), \
361     $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
362
363 define DEF_TEST_CRATE_RULES
364 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
365
366 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
367
368 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
369                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
370         @$$(call E, run: $$<)
371         $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) $$(TESTARGS) \
372             --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
373             $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
374             && touch $$@
375 endef
376
377 define DEF_TEST_CRATE_RULES_arm-linux-androideabi
378 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
379
380 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
381                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
382         @$$(call E, run: $$< via adb)
383         $$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
384         $$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
385                 ./$$(notdir $$<) \
386                 --logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
387                 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
388                 > tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
389         $$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
390         $$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
391         $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
392         $$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
393         $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/$$(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) tmp/
394         @if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
395         then \
396                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
397                 touch $$@; \
398         else \
399                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
400                 exit 101; \
401         fi
402 endef
403
404 define DEF_TEST_CRATE_RULES_null
405 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
406
407 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
408                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
409         @$$(call E, failing: no device for $$< )
410         false
411 endef
412
413 $(foreach host,$(CFG_HOST), \
414  $(foreach target,$(CFG_TARGET), \
415   $(foreach stage,$(STAGES), \
416    $(foreach crate, $(TEST_CRATES), \
417     $(if $(findstring $(target),$(CFG_BUILD)), \
418      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
419      $(if $(findstring $(target),"arm-linux-androideabi"), \
420       $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
421        $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
422        $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
423       ), \
424       $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
425      ))))))
426
427 ######################################################################
428 # Rules for the compiletest tests (rpass, rfail, etc.)
429 ######################################################################
430
431 RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
432 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
433 RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
434 RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
435 RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
436 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
437 CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
438 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
439 BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
440 PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
441 DEBUGINFO_RS := $(wildcard $(S)src/test/debug-info/*.rs)
442 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
443 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
444
445 # perf tests are the same as bench tests only they run under
446 # a performance monitor.
447 PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
448
449 RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
450 RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
451 RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
452 CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
453 BENCH_TESTS := $(BENCH_RS)
454 PERF_TESTS := $(PERF_RS)
455 PRETTY_TESTS := $(PRETTY_RS)
456 DEBUGINFO_TESTS := $(DEBUGINFO_RS)
457 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
458
459 CTEST_SRC_BASE_rpass = run-pass
460 CTEST_BUILD_BASE_rpass = run-pass
461 CTEST_MODE_rpass = run-pass
462 CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
463
464 CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
465 CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
466 CTEST_MODE_rpass-full = run-pass
467 CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
468
469 CTEST_SRC_BASE_rfail = run-fail
470 CTEST_BUILD_BASE_rfail = run-fail
471 CTEST_MODE_rfail = run-fail
472 CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
473
474 CTEST_SRC_BASE_cfail = compile-fail
475 CTEST_BUILD_BASE_cfail = compile-fail
476 CTEST_MODE_cfail = compile-fail
477 CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
478
479 CTEST_SRC_BASE_bench = bench
480 CTEST_BUILD_BASE_bench = bench
481 CTEST_MODE_bench = run-pass
482 CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
483
484 CTEST_SRC_BASE_perf = bench
485 CTEST_BUILD_BASE_perf = perf
486 CTEST_MODE_perf = run-pass
487 CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
488
489 CTEST_SRC_BASE_debuginfo = debug-info
490 CTEST_BUILD_BASE_debuginfo = debug-info
491 CTEST_MODE_debuginfo = debug-info
492 CTEST_RUNTOOL_debuginfo = $(CTEST_RUNTOOL)
493
494 CTEST_SRC_BASE_codegen = codegen
495 CTEST_BUILD_BASE_codegen = codegen
496 CTEST_MODE_codegen = codegen
497 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
498
499 ifeq ($(CFG_GDB),)
500 CTEST_DISABLE_debuginfo = "no gdb found"
501 endif
502
503 ifeq ($(CFG_CLANG),)
504 CTEST_DISABLE_codegen = "no clang found"
505 endif
506
507 ifeq ($(CFG_OSTYPE),apple-darwin)
508 CTEST_DISABLE_debuginfo = "gdb on darwing needs root"
509 endif
510
511 define DEF_CTEST_VARS
512
513 # All the per-stage build rules you might want to call from the
514 # command line.
515 #
516 # $(1) is the stage number
517 # $(2) is the target triple to test
518 # $(3) is the host triple to test
519
520 # Prerequisites for compiletest tests
521 TEST_SREQ$(1)_T_$(2)_H_$(3) = \
522         $$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
523         $$(SREQ$(1)_T_$(2)_H_$(3))
524
525 # Rules for the cfail/rfail/rpass/bench/perf test runner
526
527 # The tests select when to use debug configuration on their own;
528 # remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
529 CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
530
531 # There's no need our entire test suite to take up gigabytes of space on disk
532 # including copies of libstd/libextra all over the place
533 CTEST_RUSTC_FLAGS := $$(CTEST_RUSTC_FLAGS) -Z prefer-dynamic
534
535 # The tests can not be optimized while the rest of the compiler is optimized, so
536 # filter out the optimization (if any) from rustc and then figure out if we need
537 # to be optimized
538 CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
539 ifndef CFG_DISABLE_OPTIMIZE_TESTS
540 CTEST_RUSTC_FLAGS += -O
541 endif
542
543 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) :=                                          \
544                 --compile-lib-path $$(HLIB$(1)_H_$(3))                          \
545         --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3))                       \
546         --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                        \
547         --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
548         --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
549         --aux-base $$(S)src/test/auxiliary/                 \
550         --stage-id stage$(1)-$(2)                                                       \
551         --target $(2)                                       \
552         --host $(3)                                       \
553         --adb-path=$(CFG_ADB)                          \
554         --adb-test-dir=$(CFG_ADB_TEST_DIR)                  \
555         --rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
556         $$(CTEST_TESTARGS)
557
558 CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
559 CTEST_DEPS_rpass_full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
560 CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
561 CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
562 CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
563 CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
564 CTEST_DEPS_debuginfo_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_TESTS)
565 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
566
567 endef
568
569 $(foreach host,$(CFG_HOST), \
570  $(eval $(foreach target,$(CFG_TARGET), \
571   $(eval $(foreach stage,$(STAGES), \
572    $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
573
574 define DEF_RUN_COMPILETEST
575
576 CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
577         $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
578         --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
579         --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
580         --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
581         --mode $$(CTEST_MODE_$(4)) \
582         $$(CTEST_RUNTOOL_$(4))
583
584 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
585
586 ifeq ($$(CTEST_DISABLE_$(4)),)
587
588 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
589                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
590                 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
591         @$$(call E, run $(4) [$(2)]: $$<)
592         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
593                 $$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
594                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
595                 && touch $$@
596
597 else
598
599 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
600                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
601                 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
602         @$$(call E, run $(4) [$(2)]: $$<)
603         @$$(call E, warning: tests disabled: $$(CTEST_DISABLE_$(4)))
604         touch $$@
605
606 endif
607
608 endef
609
610 CTEST_NAMES = rpass rpass-full rfail cfail bench perf debuginfo codegen
611
612 $(foreach host,$(CFG_HOST), \
613  $(eval $(foreach target,$(CFG_TARGET), \
614   $(eval $(foreach stage,$(STAGES), \
615    $(eval $(foreach name,$(CTEST_NAMES), \
616    $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
617
618 PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
619 PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
620 PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
621 PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
622 PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
623 PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
624 PRETTY_DIRNAME_pretty-rpass = run-pass
625 PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
626 PRETTY_DIRNAME_pretty-rfail = run-fail
627 PRETTY_DIRNAME_pretty-bench = bench
628 PRETTY_DIRNAME_pretty-pretty = pretty
629
630 define DEF_RUN_PRETTY_TEST
631
632 PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) :=                   \
633                 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
634         --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
635         --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
636         --mode pretty
637
638 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
639
640 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
641                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3))         \
642                 $$(PRETTY_DEPS_$(4))
643         @$$(call E, run pretty-rpass [$(2)]: $$<)
644         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
645                 $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
646                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
647                 && touch $$@
648
649 endef
650
651 $(foreach host,$(CFG_HOST), \
652  $(foreach target,$(CFG_TARGET), \
653   $(foreach stage,$(STAGES), \
654    $(foreach pretty-name,$(PRETTY_NAMES), \
655     $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
656
657 define DEF_RUN_DOC_TEST
658
659 DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-doc-$(4) := \
660         $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
661         --src-base $(3)/test/doc-$(4)/  \
662         --build-base $(3)/test/doc-$(4)/        \
663         --mode run-pass
664
665 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
666
667 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): \
668                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3))         \
669                 doc-$(4)-extract$(3)
670         @$$(call E, run doc-$(4) [$(2)]: $$<)
671         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
672                 $$(DOC_TEST_ARGS$(1)-T-$(2)-H-$(3)-doc-$(4)) \
673                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),doc-$(4)) \
674                 && touch $$@
675
676 endef
677
678 $(foreach host,$(CFG_HOST), \
679  $(foreach target,$(CFG_TARGET), \
680   $(foreach stage,$(STAGES), \
681    $(foreach docname,$(DOC_TEST_NAMES), \
682     $(eval $(call DEF_RUN_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
683
684 define DEF_CRATE_DOC_TEST
685
686 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
687
688 ifeq ($(2),$$(CFG_BUILD))
689 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):                          \
690                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3))                         \
691                 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))              \
692                 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
693         @$$(call E, run doc-$(4) [$(2)])
694         $$(Q)$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) --test \
695             $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
696 else
697 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
698         touch $$@
699 endif
700
701 endef
702
703 $(foreach host,$(CFG_HOST), \
704  $(foreach target,$(CFG_TARGET), \
705   $(foreach stage,$(STAGES), \
706    $(foreach crate,$(TEST_DOC_CRATES), \
707     $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
708
709 ######################################################################
710 # Extracting tests for docs
711 ######################################################################
712
713 EXTRACT_TESTS := "$(CFG_PYTHON)" $(S)src/etc/extract-tests.py
714
715 define DEF_DOC_TEST_HOST
716
717 doc-$(2)-extract$(1):
718         @$$(call E, extract: $(2) tests)
719         $$(Q)rm -f $(1)/test/doc-$(2)/*.rs
720         $$(Q)$$(EXTRACT_TESTS) $$(D)/$(2).md $(1)/test/doc-$(2)
721
722 endef
723
724 $(foreach host,$(CFG_HOST), \
725  $(foreach docname,$(DOC_TEST_NAMES), \
726   $(eval $(call DEF_DOC_TEST_HOST,$(host),$(docname)))))
727
728
729 ######################################################################
730 # Shortcut rules
731 ######################################################################
732
733 TEST_GROUPS = \
734         crates \
735         $(foreach crate,$(TEST_CRATES),$(crate)) \
736         $(foreach crate,$(TEST_DOC_CRATES),doc-$(crate)) \
737         rpass \
738         rpass-full \
739         rfail \
740         cfail \
741         bench \
742         perf \
743         rmake \
744         debuginfo \
745         codegen \
746         doc \
747         $(foreach docname,$(DOC_TEST_NAMES),doc-$(docname)) \
748         pretty \
749         pretty-rpass \
750         pretty-rpass-full \
751         pretty-rfail \
752         pretty-bench \
753         pretty-pretty \
754         $(NULL)
755
756 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
757 check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
758 endef
759
760 $(foreach stage,$(STAGES), \
761  $(foreach target,$(CFG_TARGET), \
762   $(foreach host,$(CFG_HOST), \
763    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
764
765 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
766 check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
767 endef
768
769 $(foreach stage,$(STAGES), \
770  $(foreach target,$(CFG_TARGET), \
771   $(foreach host,$(CFG_HOST), \
772    $(foreach group,$(TEST_GROUPS), \
773     $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
774
775 define DEF_CHECK_FOR_STAGE
776 check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
777 check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
778                            check-stage$(1)-H-$$(target))
779 endef
780
781 $(foreach stage,$(STAGES), \
782  $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
783
784 define DEF_CHECK_FOR_STAGE_AND_GROUP
785 check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
786 check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
787                                check-stage$(1)-H-$$(target)-$(2))
788 endef
789
790 $(foreach stage,$(STAGES), \
791  $(foreach group,$(TEST_GROUPS), \
792   $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
793
794
795 define DEF_CHECK_FOR_STAGE_AND_HOSTS
796 check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
797                            check-stage$(1)-T-$$(target)-H-$(2))
798 endef
799
800 $(foreach stage,$(STAGES), \
801  $(foreach host,$(CFG_HOST), \
802   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
803
804 define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
805 check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
806                                 check-stage$(1)-T-$$(target)-H-$(2)-$(3))
807 endef
808
809 $(foreach stage,$(STAGES), \
810  $(foreach host,$(CFG_HOST), \
811   $(foreach group,$(TEST_GROUPS), \
812    $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
813
814 ######################################################################
815 # check-fast rules
816 ######################################################################
817
818 FT := run_pass_stage2
819 FT_LIB := $(call CFG_LIB_NAME_$(CFG_BUILD),$(FT))
820 FT_DRIVER := $(FT)_driver
821
822 GENERATED += tmp/$(FT).rc tmp/$(FT_DRIVER).rs
823
824 tmp/$(FT).rc tmp/$(FT_DRIVER).rs: \
825                 $(RPASS_TESTS) \
826                 $(S)src/etc/combine-tests.py
827         @$(call E, check: building combined stage2 test runner)
828         $(Q)$(CFG_PYTHON) $(S)src/etc/combine-tests.py
829
830 define DEF_CHECK_FAST_FOR_T_H
831 # $(1) unused
832 # $(2) target triple
833 # $(3) host triple
834
835 $$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB): \
836                 tmp/$$(FT).rc \
837                 $$(SREQ2_T_$(2)_H_$(3))
838         @$$(call E, compile_and_link: $$@)
839         $$(STAGE2_T_$(2)_H_$(3)) --crate-type=dylib --out-dir $$(@D) $$< \
840           -L "$$(RT_OUTPUT_DIR_$(2))"
841
842 $(3)/test/$$(FT_DRIVER)-$(2)$$(X_$(2)): \
843                 tmp/$$(FT_DRIVER).rs \
844                 $$(TLIB2_T_$(2)_H_$(3))/$$(FT_LIB) \
845                 $$(SREQ2_T_$(2)_H_$(3))
846         @$$(call E, compile_and_link: $$@ $$<)
847         $$(STAGE2_T_$(2)_H_$(3)) -o $$@ $$< \
848           -L "$$(RT_OUTPUT_DIR_$(2))"
849
850 $(3)/test/$$(FT_DRIVER)-$(2).out: \
851                 $(3)/test/$$(FT_DRIVER)-$(2)$$(X_$(2)) \
852                 $$(SREQ2_T_$(2)_H_$(3))
853         $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) \
854         --logfile tmp/$$(FT_DRIVER)-$(2).log
855
856 check-fast-T-$(2)-H-$(3):                       \
857         $(3)/test/$$(FT_DRIVER)-$(2).out
858
859 endef
860
861 $(foreach host,$(CFG_HOST), \
862  $(eval $(foreach target,$(CFG_TARGET), \
863    $(eval $(call DEF_CHECK_FAST_FOR_T_H,,$(target),$(host))))))
864
865 check-fast: tidy check-fast-H-$(CFG_BUILD) \
866             $(foreach crate,$(TARGET_CRATES),check-stage2-$(crate))
867         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
868
869 define DEF_CHECK_FAST_FOR_H
870
871 check-fast-H-$(1):              check-fast-T-$(1)-H-$(1)
872
873 endef
874
875 $(foreach host,$(CFG_HOST),                     \
876  $(eval $(call DEF_CHECK_FAST_FOR_H,$(host))))
877
878 RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
879 RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
880
881 define DEF_RMAKE_FOR_T_H
882 # $(1) the stage
883 # $(2) target triple
884 # $(3) host triple
885
886
887 ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
888 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
889                 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
890
891 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
892                 $$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
893         @touch $$@
894
895 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
896                 $(S)src/test/run-make/%/Makefile \
897                 $$(CSREQ$(1)_T_$(2)_H_$(3))
898         @rm -rf $(3)/test/run-make/$$*
899         @mkdir -p $(3)/test/run-make/$$*
900         $$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
901             $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
902             $(3)/test/run-make/$$* \
903             "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
904             $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
905             "$$(TESTNAME)"
906         @touch $$@
907 else
908 # FIXME #11094 - The above rule doesn't work right for multiple targets
909 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
910         @true
911
912 endif
913
914
915 endef
916
917 $(foreach stage,$(STAGES), \
918  $(foreach target,$(CFG_TARGET), \
919   $(foreach host,$(CFG_HOST), \
920    $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))