[corlib] corefx tests from System.Threading.* and System.Text.RegularExpressions...
[mono-project.git] / mcs / build / tests.make
blob21074591e9b95c42ec93c57e83324ec73339e09d
1 # -*- makefile -*-
3 # Rules for building unit tests.
4 #
5 # Includers of this file must define the following values:
7 # ASSEMBLY
8 # ASSEMBLY_EXT
9 # the_assembly
11 tests_CLEAN_FILES :=
13 ifndef TEST_COMPILE
14 TEST_COMPILE = $(subst $(test_remove),,$(CSCOMPILE))
15 endif
17 TEST_RUNTIME_WRAPPERS_PATH = $(shell dirname $(RUNTIME))/_tmpinst/bin
19 ## Unit test support
20 ifndef NO_TEST
22 test_nunit_lib = nunitlite.dll
23 xunit_core := xunit.core xunit.abstractions xunit.assert Xunit.NetCore.Extensions
24 xunit_deps := System.Runtime
25 xunit_src := $(patsubst %,$(topdir)/../external/xunit-binaries/%,BenchmarkAttribute.cs BenchmarkDiscover.cs) $(topdir)/../mcs/class/test-helpers/PlatformDetection.cs
26 xunit_class_deps :=
28 xunit_libs_ref = $(patsubst %,-r:$(topdir)/../external/xunit-binaries/%.dll,$(xunit_core))
29 xunit_libs_ref += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/Facades/%.dll,$(xunit_deps))
31 xunit_libs_dep = $(xunit_class_deps:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%.dll)
32 xunit_libs_ref += $(xunit_libs_dep:%=-r:%)
34 TEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(TEST_LIB_REFS))
35 XTEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(XTEST_LIB_REFS))
37 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%)
38 test_nunit_ref = $(test_nunit_dep:%=-r:%)
39 tests_CLEAN_FILES += TestResult*.xml
41 test_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
43 ifeq ($(wildcard $(test_sourcefile)),)
44 test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
45 endif
47 test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll)
49 test_sourcefile_excludes = $(test_lib).exclude.sources
51 test_pdb = $(test_lib:.dll=.pdb)
52 test_response = $(depsdir)/$(test_lib).response
53 test_makefrag = $(depsdir)/$(test_lib).makefrag
54 test_flags = -r:$(the_assembly) $(test_nunit_ref) $(TEST_MCS_FLAGS) $(TEST_LIB_MCS_FLAGS)
55 tests_CLEAN_FILES += $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.dll) $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.pdb) $(test_response) $(test_makefrag)
57 xtest_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_xtest.dll.sources)
58 xtest_sourcefile_excludes = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_xtest.dll.exclude.sources)
60 xunit_test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_xunit-test.dll)
62 xtest_response = $(depsdir)/$(xunit_test_lib).response
63 xtest_makefrag = $(depsdir)/$(xunit_test_lib).makefrag
64 xtest_flags = -r:$(the_assembly) $(xunit_libs_ref) $(XTEST_MCS_FLAGS) $(XTEST_LIB_MCS_FLAGS)
66 ifeq ($(wildcard $(xtest_sourcefile)),)
67 xtest_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_xtest.dll.sources)
68 tests_CLEAN_FILES += $(xunit_test_lib) $(xtest_response) $(xtest_makefrag)
69 endif
71 ifndef HAVE_CS_TESTS
72 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
73 endif
75 HAVE_CS_XTESTS := $(wildcard $(xtest_sourcefile))
77 endif # !NO_TEST
79 ifndef NO_TEST
80 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
81 @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
83 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
84 ifndef PARENT_PROFILE
85 cd ${topdir}/tools/nunit-lite && $(MAKE)
86 endif
87 echo "stamp" >$@
89 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
91 endif
93 ifdef HAVE_CS_TESTS
94 test_assemblies = $(test_lib)
96 check: run-test
97 test-local: $(test_assemblies)
98 run-test-local: run-test-lib
99 run-test-ondotnet-local: run-test-ondotnet-lib
101 ifdef TEST_WITH_INTERPRETER
102 TEST_HARNESS_EXCLUDES = -exclude=$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotWorking,InterpreterNotWorking,CAS
103 else
104 TEST_HARNESS_EXCLUDES = -exclude=$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotWorking,CAS
105 endif
107 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotDotNet,CAS
109 NOSHADOW_FLAG =
111 ifdef FIXTURE
112 FIXTURE_ARG = -test=MonoTests.$(FIXTURE)
113 endif
115 ifdef TESTNAME
116 TESTNAME_ARG = -test=MonoTests.$(TESTNAME)
117 endif
119 ifdef TEST_HARNESS_VERBOSE
120 LABELS_ARG = -labels
121 endif
123 ifdef ALWAYS_AOT
124 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
125 PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" MONO_REGISTRY_PATH="$(HOME)/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $(TEST_RUNTIME) $(TEST_RUNTIME_FLAGS) $(AOT_BUILD_FLAGS) $(test_assemblies)
127 else
128 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
130 endif # ALWAYS_AOT
132 ifdef COVERAGE
133 TEST_COVERAGE_FLAGS = -O=-aot --profile=coverage:output=$(topdir)/class/lib/$(PROFILE_DIRECTORY)/coverage_nunit_$(ASSEMBLY).xml
134 endif
136 NUNITLITE_CONFIG_FILE=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)nunit-lite-console.exe.config
138 patch-nunitlite-appconfig:
139 cp -f $(topdir)/tools/nunit-lite/nunit-lite-console/nunit-lite-console.exe.config.tmpl $(NUNITLITE_CONFIG_FILE)
140 ifdef TEST_NUNITLITE_APP_CONFIG_GLOBAL
141 sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_GLOBAL__/r $(TEST_NUNITLITE_APP_CONFIG_GLOBAL)" $(NUNITLITE_CONFIG_FILE)
142 endif
143 ifdef TEST_NUNITLITE_APP_CONFIG_RUNTIME
144 sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_RUNTIME__/r $(TEST_NUNITLITE_APP_CONFIG_RUNTIME)" $(NUNITLITE_CONFIG_FILE)
145 endif
147 ## FIXME: i18n problem in the 'sed' command below
148 run-test-lib: test-local test-local-aot-compile patch-nunitlite-appconfig
149 ok=:; \
150 PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" MONO_REGISTRY_PATH="$(HOME)/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $(TEST_RUNTIME) $(TEST_RUNTIME_FLAGS) $(TEST_COVERAGE_FLAGS) $(AOT_RUN_FLAGS) $(TEST_HARNESS) $(test_assemblies) $(NOSHADOW_FLAG) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_FLAGS) $(TEST_HARNESS_EXCLUDES) $(LABELS_ARG) -format:nunit2 -result:TestResult-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG)|| ok=false; \
151 if [ ! -f "TestResult-$(PROFILE).xml" ]; then echo "<?xml version='1.0' encoding='utf-8'?><test-results failures='1' total='1' not-run='0' name='bcl-tests' date='$$(date +%F)' time='$$(date +%T)'><test-suite name='$(strip $(test_assemblies))' success='False' time='0'><results><test-case name='crash' executed='True' success='False' time='0'><failure><message>The test runner didn't produce a test result XML, probably due to a crash of the runtime. Check the log for more details.</message><stack-trace></stack-trace></failure></test-case></results></test-suite></test-results>" > TestResult-$(PROFILE).xml; fi; \
152 $$ok
154 ## Instructs compiler to compile to target .net execution, it can be usefull in rare cases when runtime detection is not possible
155 run-test-ondotnet-lib: LOCAL_TEST_COMPILER_ONDOTNET_FLAGS:=-d:RUN_ONDOTNET
156 run-test-ondotnet-lib: test-local
157 ok=:; \
158 $(TEST_HARNESS) $(test_assemblies) $(NOSHADOW_FLAG) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_ONDOTNET_FLAGS) $(TEST_HARNESS_EXCLUDES_ONDOTNET) $(LABELS_ARG) -format:nunit2 -result:TestResult-ondotnet-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG) || ok=false; \
159 $$ok
162 endif
164 TEST_FILES =
166 ifdef HAVE_CS_TESTS
167 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -e '/^\#.*$$/d' -et -e 's,^,Test/,' $(test_sourcefile)`
168 endif
170 ifdef HAVE_CS_TESTS
172 $(test_lib): $(the_assembly) $(test_response) $(test_nunit_dep)
173 $(TEST_COMPILE) $(LIBRARY_FLAGS) -target:library -out:$@ $(test_flags) $(LOCAL_TEST_COMPILER_ONDOTNET_FLAGS) @$(test_response)
175 test_response_preprocessed = $(test_response)_preprocessed
177 # This handles .excludes/.sources pairs, as well as resolving the
178 # includes that occur in .sources files
179 $(test_response_preprocessed): $(test_sourcefile) $(wildcard $(test_sourcefile_excludes))
180 $(SHELL) $(topdir)/build/gensources.sh $@ '$(test_sourcefile)' '$(test_sourcefile_excludes)'
182 $(test_response): $(test_response_preprocessed)
183 # @echo Creating $@ ...
184 @sed -e '/^$$/d' -e 's,^,Test/,' $(test_response_preprocessed) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
186 $(test_makefrag): $(test_response)
187 # @echo Creating $@ ...
188 @sed 's,^,$(test_lib): ,' $< >$@
190 -include $(test_makefrag)
192 build-test-lib: $(test_lib)
193 @echo Building testing lib
195 endif
198 ifdef HAVE_CS_XTESTS
200 XTEST_HARNESS_PATH = $(topdir)/../external/xunit-binaries
201 XTEST_HARNESS = $(XTEST_HARNESS_PATH)/xunit.console.exe
202 XTEST_HARNESS_FLAGS := -noappdomain -noshadow -parallel none -nunit TestResult-$(PROFILE)-xunit.xml
203 XTEST_TRAIT := -notrait category=failing -notrait category=nonnetcoreapptests -notrait Benchmark=true -notrait category=outerloop
205 ifdef FIXTURE
206 XTEST_HARNESS_FLAGS += -class $(FIXTURE)
207 endif
209 ifdef TESTNAME
210 XTEST_HARNESS_FLAGS += -method $(TESTNAME)
211 endif
213 ifdef COVERAGE
214 XTEST_COVERAGE_FLAGS = -O=-aot --profile=coverage:output=$(topdir)/class/lib/$(PROFILE_DIRECTORY)/coverage_xunit_$(ASSEMBLY).xml
215 endif
217 check: run-xunit-test-local
218 run-xunit-test: run-xunit-test-local
219 xunit-test-local: $(xunit_test_lib)
220 run-xunit-test-local: run-xunit-test-lib
222 # cp -rf is a HACK for xunit runner to require xunit.execution.desktop.dll file in local folder on .net only
223 run-xunit-test-lib: xunit-test-local
224 @cp -rf $(XTEST_HARNESS_PATH)/xunit.execution.desktop.dll xunit.execution.desktop.dll
225 ok=:; \
226 PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" $(TEST_RUNTIME) $(TEST_RUNTIME_FLAGS) $(XTEST_COVERAGE_FLAGS) $(AOT_RUN_FLAGS) $(XTEST_HARNESS) $(xunit_test_lib) $(XTEST_HARNESS_FLAGS) $(XTEST_TRAIT) || ok=false; \
227 $$ok
228 @rm -f xunit.execution.desktop.dll
230 $(xunit_test_lib): $(the_assembly) $(xtest_response) $(xunit_libs_dep) $(xunit_src)
231 $(TEST_COMPILE) $(LIBRARY_FLAGS) $(XTEST_LIB_FLAGS) -target:library -out:$@ $(xtest_flags) @$(xtest_response) $(xunit_src)
233 xtest_response_preprocessed = $(xtest_response)_preprocessed
235 # This handles .excludes/.sources pairs, as well as resolving the
236 # includes that occur in .sources files
237 $(xtest_response): $(xtest_sourcefile) $(wildcard $(xtest_sourcefile_excludes))
238 $(SHELL) $(topdir)/build/gensources.sh $@ '$(xtest_sourcefile)' '$(xtest_sourcefile_excludes)'
240 $(xtest_makefrag): $(xtest_response)
241 @echo Creating $@ ...
242 @sed 's,^,$(xunit_test_lib): ,' $< >$@
244 -include $(xtest_makefrag)
246 endif
249 .PHONY: patch-nunitlite-appconfig