Skip to content

Commit cde39fa

Browse files
committed
[Xamarin.Android.Bcl-Tests] Add BCL test project.
What do we want? (with apologies to 48e3fc2) **MOAR** Unit tests! Specifically, we want to run the BCL unit tests which mono generates: $ cd external/mono/mcs/class/corlib $ make PROFILE=monodroid test # creates `monodroid_corlib_test.dll` Creation of `monodroid_*_test.dll` assemblies and the `make PROFILE=monodroid test` target is a relatively recent development, for which I need to buy the #runtime team some beers. In terms of `mono-runtimes.targets`, we can build *all* of the BCL unit test assemblies with: $ cd external/mono/mcs/class $ make -i do-test PROFILE=monodroid Now that we can create them, how do we *use* them? That's the trickier bit: they need to be built within mono, as part of the existing BCL build process. This in turn means that the BCL unit test assemblies need to be distributed as part of the mono bundle, as we don't want to rebuild the mono repo "from scratch" just for the unit tests. Update `build-tools/mono-runtimes/ProfileAssemblies.projitems` to include a new `@(MonoTestAssembly)` item group which contains all of the BCL unit test assemblies and related files which should be included into `bundle-*.zip`. Additionally, add `ProfileAssemblies.projitems` to `@(VersionFile)` witihin `bundle-path.targets`, so that if anything within `ProfileAssemblies.projitems` changes, we rebuild the bundle. Once we *have* the BCL unit test assemblies, we need to *run* them. The new `Xamarin.Android.Bcl-Tests.csproj` project is a Xamarin.Android application project which will execute the unit tests. There's just one small problem: Xamarin.Android apps want to use `Xamarin.Android.NUnitLite.dll`. The BCL unit test assemblies instead build against their own `nunitlite.dll`, which has no Xamarin.Android integration or support. How do we use the new test assemblies? *Force* a fix by using `remap-assembly-ref` to "rename" the `nunitlite` assembly reference to `Xamarin.Android.NUnitLite.dll`. This *cannot* be done as part of the `mono-runtimes.mdproj` build, as `Xamarin.Android.NUnitLite.dll` won't yet exist. Instead, remap the assemblies within `Xamarin.Android.Bcl-Tests.targets`, and distribute the remapped assemblies with the application.
1 parent 91b3430 commit cde39fa

24 files changed

+449
-6
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ run-ji-tests:
156156
TEST_APK_PROJECTS = \
157157
src/Mono.Android/Test/Mono.Android-Tests.csproj \
158158
tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj \
159-
tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj
159+
tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj \
160+
tests/Xamarin.Android.Bcl-Tests/Xamarin.Android.Bcl-Tests.csproj
160161

161162
TEST_APK_PROJECTS_RELEASE = \
162163
src/Mono.Android/Test/Mono.Android-Tests.csproj \

Xamarin.Android-Tests.sln

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Xamarin.Forms.Performance.I
4949
EndProject
5050
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Forms.Performance.Integration.Droid", "tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj", "{576312CC-83FF-48B1-A473-488CDC7121AD}"
5151
EndProject
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Bcl-Tests", "tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.csproj", "{E865C28E-32AF-4210-A41D-5791C39A9D85}"
53+
EndProject
5254
Global
5355
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5456
Debug|Any CPU = Debug|Any CPU
@@ -119,10 +121,14 @@ Global
119121
{B297008B-C313-455E-B230-E119589D2D79}.Debug|Any CPU.Build.0 = Debug|Any CPU
120122
{B297008B-C313-455E-B230-E119589D2D79}.Release|Any CPU.ActiveCfg = Release|Any CPU
121123
{B297008B-C313-455E-B230-E119589D2D79}.Release|Any CPU.Build.0 = Release|Any CPU
122-
{576312CC-83FF-48B1-A473-488CDC7121AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123-
{576312CC-83FF-48B1-A473-488CDC7121AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
124-
{576312CC-83FF-48B1-A473-488CDC7121AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
125-
{576312CC-83FF-48B1-A473-488CDC7121AD}.Release|Any CPU.Build.0 = Release|Any CPU
124+
{576312CC-83FF-48B1-A473-488CDC7121AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
125+
{576312CC-83FF-48B1-A473-488CDC7121AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
126+
{576312CC-83FF-48B1-A473-488CDC7121AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
127+
{576312CC-83FF-48B1-A473-488CDC7121AD}.Release|Any CPU.Build.0 = Release|Any CPU
128+
{E865C28E-32AF-4210-A41D-5791C39A9D85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
129+
{E865C28E-32AF-4210-A41D-5791C39A9D85}.Debug|Any CPU.Build.0 = Debug|Any CPU
130+
{E865C28E-32AF-4210-A41D-5791C39A9D85}.Release|Any CPU.ActiveCfg = Release|Any CPU
131+
{E865C28E-32AF-4210-A41D-5791C39A9D85}.Release|Any CPU.Build.0 = Release|Any CPU
126132
EndGlobalSection
127133
GlobalSection(NestedProjects) = preSolution
128134
{2305B00D-DE81-4744-B0DA-357835CAFE5A} = {43A4FB09-279A-4138-8027-EC1E1CED2E8A}

build-tools/bundle/bundle-path.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<!-- Files which contribute to the bundle "version" -->
2525
<ItemGroup>
2626
<VersionFile Include="..\mono-runtimes\mono-runtimes.*" />
27+
<VersionFile Include="..\mono-runtimes\ProfileAssemblies.projitems" />
2728
<VersionFile Include="..\scripts\BuildEverything.mk" />
2829
</ItemGroup>
2930
<HashFileContents

build-tools/mono-runtimes/ProfileAssemblies.projitems

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,63 @@
188188
<MonoProfileAssembly Include="System.Xml.Linq.dll" />
189189
<MonoProfileAssembly Include="System.Xml.Serialization.dll" />
190190
</ItemGroup>
191+
<ItemGroup>
192+
<MonoTestAssembly Include="monodroid_corlib_test.dll">
193+
<SourcePath>corlib</SourcePath>
194+
</MonoTestAssembly>
195+
<MonoTestAssembly Include="monodroid_Mono.CSharp_test.dll">
196+
<SourcePath>Mono.CSharp</SourcePath>
197+
</MonoTestAssembly>
198+
<MonoTestAssembly Include="monodroid_Mono.Data.Sqlite_test.dll">
199+
<SourcePath>Mono.Data.Sqlite</SourcePath>
200+
</MonoTestAssembly>
201+
<MonoTestAssembly Include="monodroid_Mono.Data.Tds_test.dll">
202+
<SourcePath>Mono.Data.Tds</SourcePath>
203+
</MonoTestAssembly>
204+
<MonoTestAssembly Include="monodroid_Mono.Security_test.dll">
205+
<SourcePath>Mono.Security</SourcePath>
206+
</MonoTestAssembly>
207+
<MonoTestAssembly Include="monodroid_System_test.dll">
208+
<SourcePath>System</SourcePath>
209+
</MonoTestAssembly>
210+
<MonoTestAssembly Include="monodroid_System.Core_test.dll">
211+
<SourcePath>System.Core</SourcePath>
212+
</MonoTestAssembly>
213+
<MonoTestAssembly Include="monodroid_System.Data_test.dll">
214+
<SourcePath>System.Data</SourcePath>
215+
</MonoTestAssembly>
216+
<MonoTestAssembly Include="monodroid_System.IO.Compression.FileSystem_test.dll">
217+
<SourcePath>System.IO.Compression.FileSystem</SourcePath>
218+
</MonoTestAssembly>
219+
<MonoTestAssembly Include="monodroid_System.IO.Compression_test.dll">
220+
<SourcePath>System.IO.Compression</SourcePath>
221+
</MonoTestAssembly>
222+
<MonoTestAssembly Include="monodroid_System.Json_test.dll">
223+
<SourcePath>System.Json</SourcePath>
224+
</MonoTestAssembly>
225+
<MonoTestAssembly Include="monodroid_System.Net.Http_test.dll">
226+
<SourcePath>System.Net.Http</SourcePath>
227+
</MonoTestAssembly>
228+
<MonoTestAssembly Include="monodroid_System.Numerics_test.dll">
229+
<SourcePath>System.Numerics</SourcePath>
230+
</MonoTestAssembly>
231+
<MonoTestAssembly Include="monodroid_System.Runtime.Serialization_test.dll">
232+
<SourcePath>System.Runtime.Serialization</SourcePath>
233+
</MonoTestAssembly>
234+
<MonoTestAssembly Include="monodroid_System.ServiceModel.Web_test.dll">
235+
<SourcePath>System.ServiceModel.Web</SourcePath>
236+
</MonoTestAssembly>
237+
<MonoTestAssembly Include="monodroid_System.Transactions_test.dll">
238+
<SourcePath>System.Transactions</SourcePath>
239+
</MonoTestAssembly>
240+
<MonoTestAssembly Include="monodroid_System.Xml_test.dll">
241+
<SourcePath>System.XML</SourcePath>
242+
</MonoTestAssembly>
243+
<MonoTestAssembly Include="monodroid_System.Xml.Linq_test.dll">
244+
<SourcePath>System.Xml.Linq</SourcePath>
245+
</MonoTestAssembly>
246+
<MonoTestAssembly Include="nunitlite.dll">
247+
<SourcePath>lib/monodroid</SourcePath>
248+
</MonoTestAssembly>
249+
</ItemGroup>
191250
</Project>

build-tools/mono-runtimes/mono-runtimes.targets

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
<_BclAssembly Include="@(MonoProfileAssembly)" />
5858
<_BclExcludeDebugSymbols Include="System.Windows.dll" />
5959
<_BclExcludeDebugSymbols Include="System.Xml.Serialization.dll" />
60+
<_BclTestAssemblySource Include="@(MonoTestAssembly->'$(MonoSourceFullPath)\mcs\class\%(SourcePath)\%(Identity)')" />
61+
<_BclTestAssemblyDestination Include="@(MonoTestAssembly->'$(XAInstallPrefix)\..\..\tests\%(Identity)')" />
6062
</ItemGroup>
6163
<ItemGroup>
6264
<_BclProfileItems Include="@(_BclAssembly->'$(_MonoProfileDir)\%(Identity)')" />
@@ -286,7 +288,7 @@
286288
<Target Name="_BuildRuntimes"
287289
DependsOnTargets="_GetRuntimesOutputItems;_ConfigureRuntimes"
288290
Inputs="@(_RuntimeBuildStamp)"
289-
Outputs="@(_RuntimeSource);@(_ProfilerSource);@(_MonoPosixHelperSource);@(_BclProfileItems);@(_MonoBtlsSource)">
291+
Outputs="@(_RuntimeSource);@(_ProfilerSource);@(_MonoPosixHelperSource);@(_BclProfileItems);@(_MonoBtlsSource);@(_BclTestAssemblyDestination)">
290292
<Exec
291293
Condition=" '%(_MonoRuntime.DoBuild)' == 'true' "
292294
Command="make $(MakeConcurrency) # %(_MonoRuntime.Identity)"
@@ -296,6 +298,18 @@
296298
<Touch
297299
Files="@(_RuntimeSource);@(_ProfilerSource);@(_MonoPosixHelperSource);@(_BclProfileItems);@(_MonoBtlsSource)"
298300
/>
301+
<Exec
302+
Command="make $(MakeConcurrency) -i do-test PROFILE=monodroid"
303+
IgnoreStandardErrorWarningFormat="True"
304+
WorkingDirectory="$(MonoSourceFullPath)\mcs\class"
305+
/>
306+
<Copy
307+
SourceFiles="@(_BclTestAssemblySource)"
308+
DestinationFiles="@(_BclTestAssemblyDestination)"
309+
/>
310+
<Touch
311+
Files="@(_BclTestAssemblyDestination)"
312+
/>
299313
</Target>
300314
<Target Name="_InstallRuntimes"
301315
DependsOnTargets="_GetRuntimesOutputItems"
@@ -577,6 +591,7 @@
577591
<BundleItem Include="$(_MSBuildDir)\%(_MonoCrossRuntime.InstallPath)%(_MonoCrossRuntime.CrossMonoName)%(_MonoCrossRuntime.ExeSuffix)"
578592
Condition=" '@(_MonoCrossRuntime)' != '' "
579593
/>
594+
<BundleItem Include="@(_BclTestAssemblyDestination)" />
580595
</ItemGroup>
581596
</Target>
582597
<Target Name="ForceBuild"

tests/RunApkTests.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
in the toplevel Makefile so that the `.apk` is built.
1515
-->
1616
<Import Project="..\src\Mono.Android\Test\Mono.Android-Tests.projitems" />
17+
<Import Project="..\tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.csproj" />
1718
<Import Project="..\tests\CodeGen-Binding\Xamarin.Android.JcwGen-Tests\Xamarin.Android.JcwGen-Tests.projitems" Condition=" '$(Configuration)' == 'Debug' " />
1819
<Import Project="..\tests\locales\Xamarin.Android.Locale-Tests\Xamarin.Android.Locale-Tests.projitems" Condition=" '$(Configuration)' == 'Debug' " />
1920
<Import Project="..\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.projitems" Condition=" '$(Configuration)' == 'Release' And '$(AotAssemblies)' != 'true' " />
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
6+
namespace Xamarin.Android.BclTests
7+
{
8+
static partial class App
9+
{
10+
internal static string[] ExcludeAssemblyNames = {
11+
// Not needed; distributed only for "sanity"/consistency
12+
"nunitlite",
13+
};
14+
15+
internal static IEnumerable<Assembly> GetTestAssemblies ()
16+
{
17+
yield return typeof (App).Assembly;
18+
19+
var names = TestAssemblyNames.Except (ExcludeAssemblyNames);
20+
foreach (var name in names) {
21+
var a = Assembly.Load (name);
22+
if (a == null) {
23+
Console.WriteLine ($"# WARNING: Unable to load assembly: {name}");
24+
continue;
25+
}
26+
yield return a;
27+
}
28+
}
29+
30+
internal static IEnumerable<string> GetExcludedCategories ()
31+
{
32+
var excluded = new List<string> {
33+
"AndroidNotWorking",
34+
"CAS",
35+
"InetAccess",
36+
"MobileNotWorking",
37+
"NotWorking",
38+
};
39+
40+
if (!System.Environment.Is64BitOperatingSystem) {
41+
excluded.Add ("LargeFileSupport");
42+
}
43+
44+
return excluded;
45+
}
46+
}
47+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Xamarin.Android.BclTests {
2+
partial class App {
3+
public static string[] TestAssemblyNames = {
4+
@ASSEMBLIES@
5+
};
6+
}
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using Android.App;
5+
using Android.Widget;
6+
using Android.OS;
7+
8+
using Xamarin.Android.NUnitLite;
9+
10+
namespace Xamarin.Android.BclTests
11+
{
12+
[Activity (
13+
Label = "Xamarin.Android BCL Tests",
14+
MainLauncher = true,
15+
Name = "xamarin.android.bcltests.MainActivity")]
16+
public class MainActivity : TestSuiteActivity
17+
{
18+
protected override void OnCreate (Bundle bundle)
19+
{
20+
foreach (var tests in App.GetTestAssemblies ()) {
21+
AddTest (tests);
22+
}
23+
24+
// Once you called base.OnCreate(), you cannot add more assemblies.
25+
base.OnCreate (bundle);
26+
}
27+
28+
protected override IEnumerable<string> GetExcludedCategories ()
29+
{
30+
return App.GetExcludedCategories ();
31+
}
32+
}
33+
}
34+

0 commit comments

Comments
 (0)