[bcl] Enable tests for the monodroid profile.
[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
24 TEST_LIB_MCS_FLAGS = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(TEST_LIB_REFS))
25
26 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)%)
27 test_nunit_ref = $(test_nunit_dep:%=-r:%)
28 tests_CLEAN_FILES += TestResult*.xml
29
30 test_sourcefile = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
31
32 ifeq ($(wildcard $(test_sourcefile)),)
33 test_sourcefile = $(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll.sources)
34 endif
35
36 test_lib = $(PROFILE)_$(ASSEMBLY:$(ASSEMBLY_EXT)=_test.dll)
37 test_sourcefile_excludes = $(test_lib).exclude.sources
38
39 test_pdb = $(test_lib:.dll=.pdb)
40 test_response = $(depsdir)/$(test_lib).response
41 test_makefrag = $(depsdir)/$(test_lib).makefrag
42 test_flags = -r:$(the_assembly) $(test_nunit_ref) $(TEST_MCS_FLAGS) $(TEST_LIB_MCS_FLAGS)
43 tests_CLEAN_FILES += $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.dll) $(ASSEMBLY:$(ASSEMBLY_EXT)=_test*.pdb) $(test_response) $(test_makefrag)
44
45 ifndef HAVE_CS_TESTS
46 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
47 endif
48
49 HAVE_SOURCE_EXCLUDES := $(wildcard $(test_sourcefile_excludes))
50
51 endif # !NO_TEST
52
53 ifndef NO_TEST
54 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
55         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
56
57 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
58 ifndef PARENT_PROFILE
59         cd ${topdir}/tools/nunit-lite && $(MAKE)
60 endif
61         echo "stamp" >$@
62
63 tests_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
64 endif
65
66 test_assemblies :=
67
68 ifdef HAVE_CS_TESTS
69 test_assemblies += $(test_lib)
70 endif
71
72 ifdef test_assemblies
73 check: run-test
74 test-local: $(test_assemblies)
75 run-test-local: run-test-lib
76 run-test-ondotnet-local: run-test-ondotnet-lib
77
78 TEST_HARNESS_EXCLUDES = -exclude=$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotWorking,ValueAdd,CAS,InetAccess
79 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:$(PLATFORM_TEST_HARNESS_EXCLUDES)$(PROFILE_TEST_HARNESS_EXCLUDES)NotDotNet,CAS
80
81 NOSHADOW_FLAG =
82
83 ifdef FIXTURE
84 FIXTURE_ARG = -test=MonoTests.$(FIXTURE)
85 endif
86
87 ifdef TESTNAME
88 TESTNAME_ARG = -test=MonoTests.$(TESTNAME)
89 endif
90
91 ifdef TEST_HARNESS_VERBOSE
92 LABELS_ARG = -labels
93 endif
94
95 ifdef ALWAYS_AOT
96 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
97         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)
98
99 else
100 test-local-aot-compile: $(topdir)/build/deps/nunit-$(PROFILE).stamp
101
102 endif # ALWAYS_AOT
103
104 NUNITLITE_CONFIG_FILE=$(topdir)/class/lib/$(PROFILE)/$(PARENT_PROFILE)nunit-lite-console.exe.config
105
106 patch-nunitlite-appconfig:
107         cp -f $(topdir)/tools/nunit-lite/nunit-lite-console/nunit-lite-console.exe.config.tmpl $(NUNITLITE_CONFIG_FILE)
108 ifdef TEST_NUNITLITE_APP_CONFIG_GLOBAL
109         sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_GLOBAL__/r $(TEST_NUNITLITE_APP_CONFIG_GLOBAL)" $(NUNITLITE_CONFIG_FILE)
110 endif
111 ifdef TEST_NUNITLITE_APP_CONFIG_RUNTIME
112         sed -i -e "/__INSERT_CUSTOM_APP_CONFIG_RUNTIME__/r $(TEST_NUNITLITE_APP_CONFIG_RUNTIME)" $(NUNITLITE_CONFIG_FILE)
113 endif
114
115 ## FIXME: i18n problem in the 'sed' command below
116 run-test-lib: test-local test-local-aot-compile patch-nunitlite-appconfig
117         ok=:; \
118         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; \
119         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; \
120         $$ok
121
122 ## Instructs compiler to compile to target .net execution, it can be usefull in rare cases when runtime detection is not possible
123 run-test-ondotnet-lib: LOCAL_TEST_COMPILER_ONDOTNET_FLAGS:=-d:RUN_ONDOTNET
124 run-test-ondotnet-lib: test-local
125         ok=:; \
126         $(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; \
127         $$ok
128
129
130 endif # test_assemblies
131
132 TEST_FILES =
133
134 ifdef HAVE_CS_TESTS
135 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(test_sourcefile)`
136 endif
137
138 ifdef HAVE_CS_TESTS
139
140 $(test_lib): $(the_assembly) $(test_response) $(test_nunit_dep)
141         $(TEST_COMPILE) $(LIBRARY_FLAGS) -target:library -out:$@ $(test_flags) $(LOCAL_TEST_COMPILER_ONDOTNET_FLAGS) @$(test_response)
142
143 test_response_preprocessed = $(test_response)_preprocessed
144
145 # This handles .excludes/.sources pairs, as well as resolving the
146 # includes that occur in .sources files
147 $(test_response_preprocessed): $(test_sourcefile)
148         $(SHELL) $(topdir)/build/gensources.sh $@ '$(test_sourcefile)' '$(test_sourcefile_excludes)'
149
150 $(test_response): $(test_response_preprocessed)
151 #       @echo Creating $@ ...
152         @sed -e '/^$$/d' -e 's,^,Test/,' $(test_response_preprocessed) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
153
154 $(test_makefrag): $(test_response)
155 #       @echo Creating $@ ...
156         @sed 's,^,$(test_lib): ,' $< >$@
157
158 -include $(test_makefrag)
159
160 build-test-lib: $(test_lib)
161         @echo Building testing lib
162
163 endif
164
165 .PHONY: patch-nunitlite-appconfig