Skip to content

Commit 410cba8

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tests] Ignore AOT tests if no cross-* (#855)
This commit makes a number of changes to the unit tests to allow us to handle different behaviour between xamarin-android and monodroid. Firstly we can now ignore AOT based tests if the compilers or runtime is not available. This means we can share the test inputs between repos. We also split out the Debugger Attribute test inputs into a `ManifestTest.OSS.cs` file to we can provide different inputs in monodroid. This is because there is a difference in behaviour between the two systems. In certain cases in monodroid we *do* want a debug runtime/attribute where in xamarin-android we never do. For example in xamarin-android having: * `$(DebugSymbols)`=None * `$(EmbedAssembliesIntoApk)`=False * `$(Optimize)`=False will result in `//application/@android:debuggable` *not* being added. This is correct behavior in xamarin-android because we *always* embed assemblies regardless of the value of `$(EmbedAssembliesIntoApk)`. In monodroid however that is incorrect, so we need separate test cases. This commit also moves some of the logic to do with `$(EmbedAssembliesIntoApk)` into `Xamarin.Android.Common.targets`. This is protected by the `$(_XASupportsFastDev)` property. This means the logic is all in one place rather than being split up across `.targets`. This should make it easier to maintain.
1 parent 3416fb5 commit 410cba8

File tree

7 files changed

+69
-18
lines changed

7 files changed

+69
-18
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ public partial class BuildTest : BaseTest
1313
{
1414
#pragma warning disable 414
1515
static object [] AotChecks = new object [] {
16+
new object[] {
17+
/* supportedAbis */ "armeabi",
18+
/* enableLLVM */ false,
19+
/* expectedResult */ true,
20+
},
21+
new object[] {
22+
/* supportedAbis */ "armeabi",
23+
/* enableLLVM */ true,
24+
/* expectedResult */ true,
25+
},
1626
new object[] {
1727
/* supportedAbis */ "armeabi-v7a",
1828
/* enableLLVM */ false,
@@ -23,6 +33,16 @@ public partial class BuildTest : BaseTest
2333
/* enableLLVM */ true,
2434
/* expectedResult */ true,
2535
},
36+
new object[] {
37+
/* supportedAbis */ "arm64-v8a",
38+
/* enableLLVM */ false,
39+
/* expectedResult */ true,
40+
},
41+
new object[] {
42+
/* supportedAbis */ "arm64-v8a",
43+
/* enableLLVM */ true,
44+
/* expectedResult */ true,
45+
},
2646
new object[] {
2747
/* supportedAbis */ "x86",
2848
/* enableLLVM */ false,
@@ -33,6 +53,16 @@ public partial class BuildTest : BaseTest
3353
/* enableLLVM */ true,
3454
/* expectedResult */ true,
3555
},
56+
new object[] {
57+
/* supportedAbis */ "x86_64",
58+
/* enableLLVM */ false,
59+
/* expectedResult */ true,
60+
},
61+
new object[] {
62+
/* supportedAbis */ "x86_64",
63+
/* enableLLVM */ true,
64+
/* expectedResult */ true,
65+
},
3666
};
3767

3868
static object [] ProguardChecks = new object [] {

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ public void BuildAotApplication (string supportedAbis, bool enableLLVM, bool exp
222222
}
223223
using (var b = CreateApkBuilder (path)) {
224224
if (!b.CrossCompilerAvailable (supportedAbis))
225-
Assert.Ignore ("Cross compiler was not available");
225+
Assert.Ignore ($"Cross compiler for {supportedAbis} was not available");
226+
if (!b.GetSupportedRuntimes ().Any (x => supportedAbis == x.Abi))
227+
Assert.Ignore ($"Runtime for {supportedAbis} was not available.");
226228
b.ThrowOnBuildFailure = false;
227229
b.Verbosity = LoggerVerbosity.Diagnostic;
228230
Assert.AreEqual (expectedResult, b.Build (proj), "Build should have {0}.", expectedResult ? "succeeded" : "failed");
@@ -281,6 +283,8 @@ public void BuildAotApplicationAndBundle (string supportedAbis, bool enableLLVM,
281283
using (var b = CreateApkBuilder (path)) {
282284
if (!b.CrossCompilerAvailable (supportedAbis))
283285
Assert.Ignore ("Cross compiler was not available");
286+
if (!b.GetSupportedRuntimes ().Any (x => supportedAbis == x.Abi))
287+
Assert.Ignore ($"Runtime for {supportedAbis} was not available.");
284288
b.ThrowOnBuildFailure = false;
285289
Assert.AreEqual (expectedResult, b.Build (proj), "Build should have {0}.", expectedResult ? "succeeded" : "failed");
286290
if (!expectedResult)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Linq;
3+
using NUnit.Framework;
4+
using Xamarin.ProjectTools;
5+
using System.IO;
6+
using System.Xml;
7+
using System.Xml.Linq;
8+
using System.Xml.XPath;
9+
using Xamarin.Tools.Zip;
10+
11+
namespace Xamarin.Android.Build.Tests
12+
{
13+
public partial class ManifestTest : BaseTest
14+
{
15+
static object [] DebuggerAttributeCases = new object [] {
16+
// DebugType, isRelease, extpected
17+
new object[] { "", true, false, },
18+
new object[] { "", false, true, },
19+
new object[] { "None", true, false, },
20+
new object[] { "None", false, false, },
21+
new object[] { "PdbOnly", true, false, },
22+
new object[] { "PdbOnly", false, true, },
23+
new object[] { "Full", true, false, },
24+
new object[] { "Full", false, true, },
25+
new object[] { "Portable", true, false, },
26+
new object[] { "Portable", false, true, },
27+
};
28+
}
29+
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Xamarin.Android.Build.Tests
1212
{
13-
public class ManifestTest : BaseTest
13+
public partial class ManifestTest : BaseTest
1414
{
1515
readonly string TargetSdkManifest = @"<?xml version=""1.0"" encoding=""utf-8""?>
1616
<manifest xmlns:android=""http://schemas.android.com/apk/res/android"" android:versionCode=""1"" android:versionName=""1.0"" package=""Bug12935.Bug12935"">
@@ -468,20 +468,6 @@ public void ManifestPlaceHolders2 ()
468468
}
469469
}
470470

471-
static object[] DebuggerAttributeCases = new object[] {
472-
// DebugType, isRelease, extpected
473-
new object[] { "", true, false, },
474-
new object[] { "", false, true, },
475-
new object[] { "None", true, false, },
476-
new object[] { "None", false, false, },
477-
new object[] { "PdbOnly", true, false, },
478-
new object[] { "PdbOnly", false, true, },
479-
new object[] { "Full", true, false, },
480-
new object[] { "Full", false, true, },
481-
new object[] { "Portable", true, false, },
482-
new object[] { "Portable", false, true, },
483-
};
484-
485471
[Test]
486472
[TestCaseSource ("DebuggerAttributeCases")]
487473
public void DebuggerAttribute (string debugType, bool isRelease, bool expected)

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@
5858
</ItemGroup>
5959
<ItemGroup>
6060
<Compile Include="BuildTest.OSS.cs" />
61+
<Compile Include="ManifestTest.OSS.cs" />
6162
</ItemGroup>
6263
</Project>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public RuntimeInfo [] GetSupportedRuntimes ()
121121
var runtimeInfo = new List<RuntimeInfo> ();
122122
var outdir = FrameworkLibDirectory;
123123
var path = Path.Combine (outdir, IsUnix ? Path.Combine ("xbuild", "Xamarin", "Android", "lib") : "");
124-
foreach (var file in Directory.EnumerateFiles (path, "libmono-android.*.*.so", SearchOption.AllDirectories)) {
124+
foreach (var file in Directory.EnumerateFiles (path, "libmono-android.*.so", SearchOption.AllDirectories)) {
125125
string fullFilePath = Path.GetFullPath (file);
126126
DirectoryInfo parentDir = Directory.GetParent (fullFilePath);
127127
if (parentDir == null)

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
177177
<TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">MonoAndroid</TargetFrameworkIdentifier>
178178
<MonoAndroidVersion>v$(_XAMajorVersionNumber).0</MonoAndroidVersion>
179179
<AndroidUpdateResourceReferences Condition="'$(AndroidUpdateResourceReferences)' == ''">True</AndroidUpdateResourceReferences>
180-
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' Or '$(_XASupportsFastDev)' == 'False' ">True</EmbedAssembliesIntoApk>
180+
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' And '$(Optimize)' != 'True' And '$(_XASupportsFastDev)' == 'True' ">False</EmbedAssembliesIntoApk>
181+
<EmbedAssembliesIntoApk Condition=" '$(_XASupportsFastDev)' == 'False' ">True</EmbedAssembliesIntoApk>
181182
<AndroidPreferNativeLibrariesWithDebugSymbols Condition=" '$(AndroidPreferNativeLibrariesWithDebugSymbols)' == '' ">False</AndroidPreferNativeLibrariesWithDebugSymbols>
182183
<AndroidSkipJavacVersionCheck Condition="'$(AndroidSkipJavacVersionCheck)' == ''">False</AndroidSkipJavacVersionCheck>
183184
<AndroidBuildApplicationPackage Condition=" '$(AndroidBuildApplicationPackage)' == ''">False</AndroidBuildApplicationPackage>

0 commit comments

Comments
 (0)