Merge branch 'master' into config-checks-ipv6
[mono.git] / mcs / build / tests.make
1 # -*- makefile -*-
2 #
3 # Rules for building unit tests.
4
5 # Includers of this file must define the following values:
6 #
7 #   ASSEMBLY
8 #   ASSEMBLY_EXT
9 #   the_assembly
10
11 tests_CLEAN_FILES := 
12
13 ifndef TEST_COMPILE
14 TEST_COMPILE = $(subst $(test_remove),,$(CSCOMPILE))
15 endif
16
17 TEST_RUNTIME_WRAPPERS_PATH = $(shell dirname $(RUNTIME))/_tmpinst/bin
18
19 ## Unit test support
20 ifndef NO_TEST
21
22 test_nunit_lib = nunitlite.dll
23 xunit_core := xunit.core xunit.abstractions xunit.assert
24 xunit_deps := System.Runtime
25 xunit_class_deps := Xunit.NetCore.Extensions
26
27 xunit_libs_ref = $(patsubst %,-r:$(topdir)/../external/xunit-binaries/%.dll,$(xunit_core))
28 xunit_libs_ref += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/Facades/%.dll,$(xunit_deps))
29
30 xunit_libs_dep = $(xunit_class_deps:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%.dll)
31 xunit_libs_ref += $(xunit_libs_dep:%=-r:%)
32
33 TEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(TEST_LIB_REFS))
34 XTEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(XTEST_LIB_REFS))
35
36 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%)
37 test_nunit_ref = $(test_nunit_dep:%=-r:%)
38 tests_CLEAN_FILES += TestResult*.xml
39
40 test_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
41
42 ifeq ($(wildcard $(test_sourcefile)),)
43 test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
44 endif
45
46 test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll)
47
48 test_sourcefile_excludes = $(test_lib).exclude.sources
49
50 test_pdb = $(test_lib:.dll=.pdb)
51 test_response = $(depsdir)/$(test_lib).response
52 test_makefrag = $(depsdir)/$(test_lib).makefrag
53 test_flags = -r:$(the_assembly) $(test_nunit_ref) $(TEST_MCS_FLAGS) $(TEST_LIB_MCS_FLAGS)
54 tests_CLEAN_FILES += $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.dll) $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.pdb) $(test_response) $(test_makefrag)
55
56 xtest_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_xtest.dll.sources)
57
58
59 xunit_test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_xunit-test.dll)
60
61 xtest_response = $(depsdir)/$(xunit_test_lib).response
62 xtest_makefrag = $(depsdir)/$(xunit_test_lib).makefrag
63 xtest_flags = -r:$(the_assembly) $(xunit_libs_ref) $(XTEST_MCS_FLAGS) $(XTEST_LIB_MCS_FLAGS)
64
65 ifeq ($(wildcard $(xtest_sourcefile)),)
66 xtest_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_xtest.dll.sources)
67 tests_CLEAN_FILES += $(xunit_test_lib) $(xtest_response) $(xtest_makefrag)
68 endif
69
70 ifndef HAVE_CS_TESTS
71 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
72 endif
73
74 HAVE_SOURCE_EXCLUDES := $(wildcard $(test_sourcefile_excludes))
75
76 HAVE_CS_XTESTS := $(wildcard $(xtest_sourcefile))
77
78 endif # !NO_TEST
79
80 ifndef NO_TEST
81 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
82         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
83
84 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
85 ifndef PARENT_PROFILE
86         cd ${topdir}/tools/nunit-lite && $(MAKE)
87 endif
88         echo "stamp" >$@
89
90 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
91
92 $(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)Xunit.NetCore.Extensions.dll:
93         $(MAKE) -C $(topdir)/class/Xunit.NetCore.Extensions
94
95 endif
96
97 test_assemblies :=
98
99 ifdef HAVE_CS_TESTS
100 test_assemblies += $(test_lib)
101 endif
102
103 ifdef test_assemblies
104 check: run-test
105 test-local: $(test_assemblies)
106 run-test-local: run-test-lib
107 run-test-ondotnet-local: run-test-ondotnet-lib
108
109 TEST_HARNESS_EXCLUDES = -exclude=$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotWorking,ValueAdd,CAS,InetAccess
110 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotDotNet,CAS
111
112 NOSHADOW_FLAG =
113
114 ifdef FIXTURE
115 FIXTURE_ARG = -test=MonoTests.$(FIXTURE)
116 endif
117
118 ifdef TESTNAME
119 TESTNAME_ARG = -test=MonoTests.$(TESTNAME)
120 endif
121
122 ifdef TEST_HARNESS_VERBOSE
123 LABELS_ARG = -labels
124 endif
125
126 ifdef ALWAYS_AOT
127 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
128         PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" MONO_REGISTRY_PATH="$(HOME)/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(AOT_BUILD_FLAGS) $(test_assemblies)
129
130 else
131 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
132
133 endif # ALWAYS_AOT
134
135 NUNITLITE_CONFIG_FILE=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)nunit-lite-console.exe.config
136
137 patch-nunitlite-appconfig:
138         cp -f $(topdir)/tools/nunit-lite/nunit-lite-console/nunit-lite-console.exe.config.tmpl $(NUNITLITE_CONFIG_FILE)
139 ifdef TEST_NUNITLITE_APP_CONFIG_GLOBAL
140         sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_GLOBAL__/r $(TEST_NUNITLITE_APP_CONFIG_GLOBAL)" $(NUNITLITE_CONFIG_FILE)
141 endif
142 ifdef TEST_NUNITLITE_APP_CONFIG_RUNTIME
143         sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_RUNTIME__/r $(TEST_NUNITLITE_APP_CONFIG_RUNTIME)" $(NUNITLITE_CONFIG_FILE)
144 endif
145
146 ## FIXME: i18n problem in the 'sed' command below
147 run-test-lib: test-local test-local-aot-compile patch-nunitlite-appconfig
148         ok=:; \
149         PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" MONO_REGISTRY_PATH="$(HOME)/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $(TEST_RUNTIME) $(RUNTIME_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; \
150         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; \
151         $$ok
152
153 ## Instructs compiler to compile to target .net execution, it can be usefull in rare cases when runtime detection is not possible
154 run-test-ondotnet-lib: LOCAL_TEST_COMPILER_ONDOTNET_FLAGS:=-d:RUN_ONDOTNET
155 run-test-ondotnet-lib: test-local
156         ok=:; \
157         $(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; \
158         $$ok
159
160
161 endif # test_assemblies
162
163 TEST_FILES =
164
165 ifdef HAVE_CS_TESTS
166 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(test_sourcefile)`
167 endif
168
169 ifdef HAVE_CS_TESTS
170
171 $(test_lib): $(the_assembly) $(test_response) $(test_nunit_dep)
172         $(TEST_COMPILE) $(LIBRARY_FLAGS) -target:library -out:$@ $(test_flags) $(LOCAL_TEST_COMPILER_ONDOTNET_FLAGS) @$(test_response)
173
174 test_response_preprocessed = $(test_response)_preprocessed
175
176 # This handles .excludes/.sources pairs, as well as resolving the
177 # includes that occur in .sources files
178 $(test_response_preprocessed): $(test_sourcefile)
179         $(SHELL) $(topdir)/build/gensources.sh $@ '$(test_sourcefile)' '$(test_sourcefile_excludes)'
180
181 $(test_response): $(test_response_preprocessed)
182 #       @echo Creating $@ ...
183         @sed -e '/^$$/d' -e 's,^,Test/,' $(test_response_preprocessed) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
184
185 $(test_makefrag): $(test_response)
186 #       @echo Creating $@ ...
187         @sed 's,^,$(test_lib): ,' $< >$@
188
189 -include $(test_makefrag)
190
191 build-test-lib: $(test_lib)
192         @echo Building testing lib
193
194 endif
195
196
197 ifdef HAVE_CS_XTESTS
198
199 XTEST_HARNESS_PATH = $(topdir)/../external/xunit-binaries
200 XTEST_HARNESS = $(XTEST_HARNESS_PATH)/xunit.console.exe
201 XTEST_HARNESS_FLAGS := -noappdomain -noshadow -parallel none -nunit TestResult-$(PROFILE)-xunit.xml
202 XTEST_TRAIT := -notrait category=failing -notrait category=nonnetcoreapptests -notrait Benchmark=true -notrait category=outerloop
203
204 ifdef FIXTURE
205 XTEST_HARNESS_FLAGS += -class $(FIXTURE)
206 endif
207
208 ifdef TESTNAME
209 XTEST_HARNESS_FLAGS += -method $(TESTNAME)
210 endif
211
212 check: run-xunit-test-local
213 run-xunit-test: run-xunit-test-local
214 xunit-test-local: $(xunit_test_lib)
215 run-xunit-test-local: run-xunit-test-lib
216
217 # ln -s is a HACK for xunit runner to require xunit.execution.desktop.dll file in local folder on .net only
218 run-xunit-test-lib: xunit-test-local
219         @ln -fs $(XTEST_HARNESS_PATH)/xunit.execution.desktop.dll xunit.execution.desktop.dll
220         ok=:; \
221         PATH="$(TEST_RUNTIME_WRAPPERS_PATH):$(PATH)" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(AOT_RUN_FLAGS) $(XTEST_HARNESS) $(xunit_test_lib) $(XTEST_HARNESS_FLAGS) $(XTEST_TRAIT) || ok=false; \
222         $$ok
223         @rm -f xunit.execution.desktop.dll
224
225 $(xunit_test_lib): $(the_assembly) $(xtest_response) $(xunit_libs_dep)
226         $(TEST_COMPILE) $(LIBRARY_FLAGS) $(XTEST_LIB_FLAGS) -target:library -out:$@ $(xtest_flags) @$(xtest_response)
227
228 xtest_response_preprocessed = $(xtest_response)_preprocessed
229
230 # This handles .excludes/.sources pairs, as well as resolving the
231 # includes that occur in .sources files
232 $(xtest_response): $(xtest_sourcefile)
233         $(SHELL) $(topdir)/build/gensources.sh $@ '$(xtest_sourcefile)' '$(xtest_sourcefile_excludes)'
234
235 $(xtest_makefrag): $(xtest_response)
236         @echo Creating $@ ...
237         @sed 's,^,$(xunit_test_lib): ,' $< >$@
238
239 -include $(xtest_makefrag)
240
241 endif
242
243
244 .PHONY: patch-nunitlite-appconfig