PageRenderTime 52ms CodeModel.GetById 2ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 1ms

/mk/tests.mk

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