From 761ee18e57a2d90a7f2be826d6817bb8e2f95aec Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 14 Sep 2017 10:31:04 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tests] Ignore AOT tests if compiler is not available. This commit makes a number of changes to the unit tests to allow us to handle different behaviour between x-a 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 x-a we never do. For exmaple in x-a having DebugSymbols = 'None', EmbedAssemblies=False and Optimize = False will result in the DebugAttribute not being added. This is correct behaviour for x-a because we ALWAYS embed assemblies regardless of the user setting. In monodroid hower that is incorrect. So we need seperate test cases. This commit also moves some of the logic to do with EmbedAssemblies into the Xamarin.Android.Common.targets. This is protected bu the `$(_XASupportsFastDev)` property. Again it means the logic is all in one place rather than being split up across .targets. This should make it easier to maintain. --- .../BuildTest.OSS.cs | 30 +++++++++++++++++++ .../Xamarin.Android.Build.Tests/BuildTest.cs | 6 +++- .../ManifestTest.OSS.cs | 29 ++++++++++++++++++ .../ManifestTest.cs | 16 +--------- .../Xamarin.Android.Build.Tests.csproj | 1 + .../Common/ProjectBuilder.cs | 2 +- .../Xamarin.Android.Common.targets | 3 +- 7 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.OSS.cs diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs index 07bbb755b13..4e0567b9acf 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs @@ -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, @@ -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, @@ -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 [] { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index 77b3499a74e..cab2ebc331e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -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"); @@ -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) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.OSS.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.OSS.cs new file mode 100644 index 00000000000..6e889582ef3 --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.OSS.cs @@ -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, }, + }; + } +} diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs index 30fcc1ca399..ceebaee3164 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/ManifestTest.cs @@ -10,7 +10,7 @@ namespace Xamarin.Android.Build.Tests { - public class ManifestTest : BaseTest + public partial class ManifestTest : BaseTest { readonly string TargetSdkManifest = @" @@ -436,20 +436,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) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj index 71ac3703bf7..dd125f52e0b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj @@ -58,5 +58,6 @@ + diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectBuilder.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectBuilder.cs index 20cd257f7d5..9566758d051 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectBuilder.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/ProjectBuilder.cs @@ -121,7 +121,7 @@ public RuntimeInfo [] GetSupportedRuntimes () var runtimeInfo = new List (); 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) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index f0bdd856c47..0aa206f5571 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -177,7 +177,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. MonoAndroid v$(_XAMajorVersionNumber).0 True - True + False + True False False False