Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tests] Ignore AOT tests if no cross-* (#855)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dellis1972 authored and jonpryor committed Sep 19, 2017
1 parent 3416fb5 commit 410cba8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public partial class BuildTest : BaseTest
{
#pragma warning disable 414
static object [] AotChecks = new object [] {
new object[] {
/* supportedAbis */ "armeabi",
/* enableLLVM */ false,
/* expectedResult */ true,
},
new object[] {
/* supportedAbis */ "armeabi",
/* enableLLVM */ true,
/* expectedResult */ true,
},
new object[] {
/* supportedAbis */ "armeabi-v7a",
/* enableLLVM */ false,
Expand All @@ -23,6 +33,16 @@ public partial class BuildTest : BaseTest
/* enableLLVM */ true,
/* expectedResult */ true,
},
new object[] {
/* supportedAbis */ "arm64-v8a",
/* enableLLVM */ false,
/* expectedResult */ true,
},
new object[] {
/* supportedAbis */ "arm64-v8a",
/* enableLLVM */ true,
/* expectedResult */ true,
},
new object[] {
/* supportedAbis */ "x86",
/* enableLLVM */ false,
Expand All @@ -33,6 +53,16 @@ public partial class BuildTest : BaseTest
/* enableLLVM */ true,
/* expectedResult */ true,
},
new object[] {
/* supportedAbis */ "x86_64",
/* enableLLVM */ false,
/* expectedResult */ true,
},
new object[] {
/* supportedAbis */ "x86_64",
/* enableLLVM */ true,
/* expectedResult */ true,
},
};

static object [] ProguardChecks = new object [] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ public void BuildAotApplication (string supportedAbis, bool enableLLVM, bool exp
}
using (var b = CreateApkBuilder (path)) {
if (!b.CrossCompilerAvailable (supportedAbis))
Assert.Ignore ("Cross compiler was not available");
Assert.Ignore ($"Cross compiler for {supportedAbis} was not available");
if (!b.GetSupportedRuntimes ().Any (x => supportedAbis == x.Abi))
Assert.Ignore ($"Runtime for {supportedAbis} was not available.");
b.ThrowOnBuildFailure = false;
b.Verbosity = LoggerVerbosity.Diagnostic;
Assert.AreEqual (expectedResult, b.Build (proj), "Build should have {0}.", expectedResult ? "succeeded" : "failed");
Expand Down Expand Up @@ -281,6 +283,8 @@ public void BuildAotApplicationAndBundle (string supportedAbis, bool enableLLVM,
using (var b = CreateApkBuilder (path)) {
if (!b.CrossCompilerAvailable (supportedAbis))
Assert.Ignore ("Cross compiler was not available");
if (!b.GetSupportedRuntimes ().Any (x => supportedAbis == x.Abi))
Assert.Ignore ($"Runtime for {supportedAbis} was not available.");
b.ThrowOnBuildFailure = false;
Assert.AreEqual (expectedResult, b.Build (proj), "Build should have {0}.", expectedResult ? "succeeded" : "failed");
if (!expectedResult)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Linq;
using NUnit.Framework;
using Xamarin.ProjectTools;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using Xamarin.Tools.Zip;

namespace Xamarin.Android.Build.Tests
{
public partial class ManifestTest : BaseTest
{
static object [] DebuggerAttributeCases = new object [] {
// DebugType, isRelease, extpected
new object[] { "", true, false, },
new object[] { "", false, true, },
new object[] { "None", true, false, },
new object[] { "None", false, false, },
new object[] { "PdbOnly", true, false, },
new object[] { "PdbOnly", false, true, },
new object[] { "Full", true, false, },
new object[] { "Full", false, true, },
new object[] { "Portable", true, false, },
new object[] { "Portable", false, true, },
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

static object[] DebuggerAttributeCases = new object[] {
// DebugType, isRelease, extpected
new object[] { "", true, false, },
new object[] { "", false, true, },
new object[] { "None", true, false, },
new object[] { "None", false, false, },
new object[] { "PdbOnly", true, false, },
new object[] { "PdbOnly", false, true, },
new object[] { "Full", true, false, },
new object[] { "Full", false, true, },
new object[] { "Portable", true, false, },
new object[] { "Portable", false, true, },
};

[Test]
[TestCaseSource ("DebuggerAttributeCases")]
public void DebuggerAttribute (string debugType, bool isRelease, bool expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BuildTest.OSS.cs" />
<Compile Include="ManifestTest.OSS.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public RuntimeInfo [] GetSupportedRuntimes ()
var runtimeInfo = new List<RuntimeInfo> ();
var outdir = FrameworkLibDirectory;
var path = Path.Combine (outdir, IsUnix ? Path.Combine ("xbuild", "Xamarin", "Android", "lib") : "");
foreach (var file in Directory.EnumerateFiles (path, "libmono-android.*.*.so", SearchOption.AllDirectories)) {
foreach (var file in Directory.EnumerateFiles (path, "libmono-android.*.so", SearchOption.AllDirectories)) {
string fullFilePath = Path.GetFullPath (file);
DirectoryInfo parentDir = Directory.GetParent (fullFilePath);
if (parentDir == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">MonoAndroid</TargetFrameworkIdentifier>
<MonoAndroidVersion>v$(_XAMajorVersionNumber).0</MonoAndroidVersion>
<AndroidUpdateResourceReferences Condition="'$(AndroidUpdateResourceReferences)' == ''">True</AndroidUpdateResourceReferences>
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' Or '$(_XASupportsFastDev)' == 'False' ">True</EmbedAssembliesIntoApk>
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' And '$(Optimize)' != 'True' And '$(_XASupportsFastDev)' == 'True' ">False</EmbedAssembliesIntoApk>
<EmbedAssembliesIntoApk Condition=" '$(_XASupportsFastDev)' == 'False' ">True</EmbedAssembliesIntoApk>
<AndroidPreferNativeLibrariesWithDebugSymbols Condition=" '$(AndroidPreferNativeLibrariesWithDebugSymbols)' == '' ">False</AndroidPreferNativeLibrariesWithDebugSymbols>
<AndroidSkipJavacVersionCheck Condition="'$(AndroidSkipJavacVersionCheck)' == ''">False</AndroidSkipJavacVersionCheck>
<AndroidBuildApplicationPackage Condition=" '$(AndroidBuildApplicationPackage)' == ''">False</AndroidBuildApplicationPackage>
Expand Down

0 comments on commit 410cba8

Please sign in to comment.