diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AssetPackTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AssetPackTests.cs index 9d815c33d1b..5b1a3831c71 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AssetPackTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AssetPackTests.cs @@ -4,6 +4,7 @@ using System.Text; using Xamarin.Android.Tasks; using Xamarin.ProjectTools; +using System.Collections.Generic; namespace Xamarin.Android.Build.Tests { @@ -13,8 +14,11 @@ public class AssetPackTests : BaseTest { [Test] [Category ("SmokeTests")] - public void BuildLibraryWithAssetPack ([Values (true, false)] bool isRelease) + public void BuildLibraryWithAssetPack ([Values] bool isRelease, [Values] AndroidRuntime runtime) { + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var path = Path.Combine ("temp", TestName); var lib = new XamarinAndroidLibraryProject { IsRelease = isRelease, @@ -26,6 +30,7 @@ public void BuildLibraryWithAssetPack ([Values (true, false)] bool isRelease) }, } }; + lib.SetRuntime (runtime); using (var builder = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) { builder.ThrowOnBuildFailure = false; Assert.IsFalse (builder.Build (lib), $"{lib.ProjectName} should fail."); @@ -36,13 +41,11 @@ public void BuildLibraryWithAssetPack ([Values (true, false)] bool isRelease) [Test] [Category ("SmokeTests")] - [TestCase (false, AndroidRuntime.MonoVM)] - [TestCase (true, AndroidRuntime.MonoVM)] - [TestCase (false, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.NativeAOT)] - public void BuildApplicationWithAssetPackThatHasInvalidName (bool isRelease, AndroidRuntime runtime) + public void BuildApplicationWithAssetPackThatHasInvalidName ([Values] bool isRelease, [Values] AndroidRuntime runtime) { + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var path = Path.Combine ("temp", TestName); var app = new XamarinAndroidApplicationProject { IsRelease = isRelease, @@ -66,13 +69,11 @@ public void BuildApplicationWithAssetPackThatHasInvalidName (bool isRelease, And [Test] [Category ("SmokeTests")] - [TestCase (false, AndroidRuntime.MonoVM)] - [TestCase (true, AndroidRuntime.MonoVM)] - [TestCase (false, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.NativeAOT)] - public void BuildApplicationWithAssetPackOutsideProjectDirectory (bool isRelease, AndroidRuntime runtime) + public void BuildApplicationWithAssetPackOutsideProjectDirectory ([Values] bool isRelease, [Values] AndroidRuntime runtime) { + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var path = Path.Combine ("temp", TestName); var app = new XamarinAndroidApplicationProject { ProjectName = "MyApp", @@ -117,13 +118,11 @@ public void BuildApplicationWithAssetPackOutsideProjectDirectory (bool isRelease [Test] [Category ("SmokeTests")] - [TestCase (false, AndroidRuntime.MonoVM)] - [TestCase (true, AndroidRuntime.MonoVM)] - [TestCase (false, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.NativeAOT)] - public void BuildApplicationWithAssetPackOverrides (bool isRelease, AndroidRuntime runtime) + public void BuildApplicationWithAssetPackOverrides ([Values] bool isRelease, [Values] AndroidRuntime runtime) { + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var path = Path.Combine ("temp", TestName); var app = new XamarinAndroidApplicationProject { ProjectName = "MyApp", @@ -161,13 +160,11 @@ public void BuildApplicationWithAssetPackOverrides (bool isRelease, AndroidRunti [Test] [Category ("SmokeTests")] - [TestCase (false, AndroidRuntime.MonoVM)] - [TestCase (true, AndroidRuntime.MonoVM)] - [TestCase (false, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.CoreCLR)] - [TestCase (true, AndroidRuntime.NativeAOT)] - public void BuildApplicationWithAssetPack (bool isRelease, AndroidRuntime runtime) + public void BuildApplicationWithAssetPack ([Values] bool isRelease, [Values] AndroidRuntime runtime) { + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var path = Path.Combine ("temp", TestName); var asset3 = new AndroidItem.AndroidAsset ("Assets\\asset3.txt") { TextContent = () => "Asset3", diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs index da088199ffd..2b55531d7e7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/CodeBehindTests.cs @@ -9,6 +9,8 @@ using NUnit.Framework; using Xamarin.ProjectTools; +using Xamarin.Android.Tasks; +using System.Text; namespace Xamarin.Android.Build.Tests { @@ -111,25 +113,29 @@ sealed class TestProjectInfo { public string RootDirectory { get; } public string OutputDirectory { get; } + public string TestRootDirectory { get; } public string ObjPath { get; } public string BinPath { get; } public string GeneratedPath { get; } public string ProjectPath { get; } public string ProjectName { get; } public string TestName { get; } + public AndroidRuntime Runtime { get; } - public TestProjectInfo (string projectName, string testName, string rootDirectory, string outputRootDir) + public TestProjectInfo (string projectName, string testName, string rootDirectory, string outputRootDir, AndroidRuntime runtime) { TestName = testName; RootDirectory = rootDirectory; ProjectName = projectName; + Runtime = runtime; ObjPath = Path.Combine (rootDirectory, "obj"); GeneratedPath = Path.Combine (ObjPath, XABuildPaths.Configuration, "codebehind"); BinPath = Path.Combine (rootDirectory, "bin", XABuildPaths.Configuration); ProjectPath = Path.Combine (rootDirectory, $"{projectName}.csproj"); - OutputDirectory = Path.Combine (outputRootDir, testName, XABuildPaths.Configuration); + TestRootDirectory = Path.Combine (outputRootDir, testName); + OutputDirectory = Path.Combine (TestRootDirectory, XABuildPaths.Configuration); } } @@ -267,42 +273,43 @@ static CodeBehindTests () }, }; + // TODO: for some reason the tests no longer produce both aab and apk packages, at least locally? Fine? Bug? produced_binaries = new List { $"{ProjectName}.dll", "CommonSampleLibrary.dll", - $"{PackageName}-Signed.apk", +// $"{PackageName}-Signed.apk", $"{PackageName}.aab", $"{PackageName}-Signed.aab", }; } [Test] - public void SuccessfulBuildFew () + public void SuccessfulBuildFew ([Values] AndroidRuntime runtime) { - RunTest ("SuccessfulBuildFew", many: false, dtb: false, runner: SuccessfulBuild_RunTest); + RunTest (TestName, many: false, dtb: false, runner: SuccessfulBuild_RunTest, runtime: runtime); } [Test] - public void SuccessfulBuildMany () + public void SuccessfulBuildMany ([Values] AndroidRuntime runtime) { - RunTest ("SuccessfulBuildMany", many: true, dtb: false, runner: SuccessfulBuild_RunTest); + RunTest (TestName, many: true, dtb: false, runner: SuccessfulBuild_RunTest, runtime: runtime); } [Test] - public void SuccessfulBuildFew_DTB () + public void SuccessfulBuildFew_DTB ([Values] AndroidRuntime runtime) { - RunTest ("SuccessfulBuildFew_DTB", many: false, dtb: true, runner: SuccessfulBuild_RunTest); + RunTest (TestName, many: false, dtb: true, runner: SuccessfulBuild_RunTest, runtime: runtime); } [Test] - public void SuccessfulBuildMany_DTB () + public void SuccessfulBuildMany_DTB ([Values] AndroidRuntime runtime) { - RunTest ("SuccessfulBuildMany_DTB", many: true, dtb: true, runner: SuccessfulBuild_RunTest); + RunTest (TestName, many: true, dtb: true, runner: SuccessfulBuild_RunTest, runtime: runtime); } - void SuccessfulBuild_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder) + void SuccessfulBuild_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder, AndroidRuntime runtime) { - string[] parameters = GetBuildProperties (builder, many, dtb, referenceAndroidX:false); + string[] parameters = GetBuildProperties (builder, runtime, many, dtb, referenceAndroidX:false); bool success = builder.Build (testInfo.ProjectPath, GetBuildTarget (dtb), parameters); CopyLogs (testInfo, true); @@ -328,19 +335,21 @@ void SuccessfulBuild_RunTest (TestProjectInfo testInfo, bool many, bool dtb, Loc } [Test] - public void SuccessfulAndroidXApp () + public void SuccessfulAndroidXApp ([Values] AndroidRuntime runtime) { - RunTest ("SuccessfulAndroidXApp", many: true, dtb: false, runner: SuccessfulBuild_AndroidX); + RunTest (TestName, many: true, dtb: false, runner: SuccessfulBuild_AndroidX, runtime: runtime); } - void SuccessfulBuild_AndroidX (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder) + void SuccessfulBuild_AndroidX (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder, AndroidRuntime runtime) { - string[] parameters = GetBuildProperties (builder, many, dtb, referenceAndroidX:true, "__HAVE_ANDROIDX__"); + string[] parameters = GetBuildProperties (builder, runtime, many, dtb, referenceAndroidX:true, "__HAVE_ANDROIDX__"); bool success = builder.Build (testInfo.ProjectPath, GetBuildTarget (dtb), parameters); CopyLogs (testInfo, true); Assert.That (success, Is.True, "Build should have succeeded"); - Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, " 0 Warning(s)"), $"{builder.BuildLogFile} should have no MSBuild warnings."); + if (testInfo.Runtime != AndroidRuntime.NativeAOT) { // NativeAOT currently (Nov 2025) produces 9 ILC warnings + Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, " 0 Warning(s)"), $"{builder.BuildLogFile} should have no MSBuild warnings."); + } CopyGeneratedFiles (testInfo); @@ -363,20 +372,20 @@ void SuccessfulBuild_AndroidX (TestProjectInfo testInfo, bool many, bool dtb, Lo } [Test] - public void FailedBuildFew_ConflictingFragment () + public void FailedBuildFew_ConflictingFragment ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildFew_ConflictingFragment", many: false, dtb: false, runner: FailedBuild_ConflictingFragment_RunTest); + RunTest (TestName, many: false, dtb: false, runner: FailedBuild_ConflictingFragment_RunTest, runtime: runtime); } [Test] - public void FailedBuildMany_ConflictingFragment () + public void FailedBuildMany_ConflictingFragment ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildMany_ConflictingFragment", many: true, dtb: false, runner: FailedBuild_ConflictingFragment_RunTest); + RunTest (TestName, many: true, dtb: false, runner: FailedBuild_ConflictingFragment_RunTest, runtime: runtime); } - void FailedBuild_ConflictingFragment_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder) + void FailedBuild_ConflictingFragment_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder, AndroidRuntime runtime) { - string[] parameters = GetBuildProperties (builder, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_FRAGMENT"); + string[] parameters = GetBuildProperties (builder, runtime, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_FRAGMENT"); bool success = builder.Build (testInfo.ProjectPath, GetBuildTarget (dtb), parameters); CopyLogs (testInfo, true); @@ -391,20 +400,20 @@ void FailedBuild_ConflictingFragment_RunTest (TestProjectInfo testInfo, bool man } [Test] - public void FailedBuildFew_ConflictingTextView () + public void FailedBuildFew_ConflictingTextView ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildFew_ConflictingTextView", many: false, dtb: false, runner: FailedBuild_ConflictingTextView_RunTest); + RunTest (TestName, many: false, dtb: false, runner: FailedBuild_ConflictingTextView_RunTest, runtime: runtime); } [Test] - public void FailedBuildMany_ConflictingTextView () + public void FailedBuildMany_ConflictingTextView ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildMany_ConflictingTextView", many: true, dtb: false, runner: FailedBuild_ConflictingTextView_RunTest); + RunTest (TestName, many: true, dtb: false, runner: FailedBuild_ConflictingTextView_RunTest, runtime: runtime); } - void FailedBuild_ConflictingTextView_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder) + void FailedBuild_ConflictingTextView_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder, AndroidRuntime runtime) { - string[] parameters = GetBuildProperties (builder, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_TEXTVIEW"); + string[] parameters = GetBuildProperties (builder, runtime, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_TEXTVIEW"); bool success = builder.Build (testInfo.ProjectPath, GetBuildTarget (dtb), parameters); CopyLogs (testInfo, true); @@ -419,20 +428,20 @@ void FailedBuild_ConflictingTextView_RunTest (TestProjectInfo testInfo, bool man } [Test] - public void FailedBuildFew_ConflictingButton () + public void FailedBuildFew_ConflictingButton ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildFew_ConflictingButton", many: false, dtb: false, runner: FailedBuild_ConflictingButton_RunTest); + RunTest (TestName, many: false, dtb: false, runner: FailedBuild_ConflictingButton_RunTest, runtime: runtime); } [Test] - public void FailedBuildMany_ConflictingButton () + public void FailedBuildMany_ConflictingButton ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildMany_ConflictingButton", many: true, dtb: false, runner: FailedBuild_ConflictingButton_RunTest); + RunTest (TestName, many: true, dtb: false, runner: FailedBuild_ConflictingButton_RunTest, runtime: runtime); } - void FailedBuild_ConflictingButton_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder) + void FailedBuild_ConflictingButton_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder, AndroidRuntime runtime) { - string[] parameters = GetBuildProperties (builder, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_BUTTON"); + string[] parameters = GetBuildProperties (builder, runtime, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_BUTTON"); bool success = builder.Build (testInfo.ProjectPath, GetBuildTarget (dtb), parameters); CopyLogs (testInfo, true); @@ -447,20 +456,20 @@ void FailedBuild_ConflictingButton_RunTest (TestProjectInfo testInfo, bool many, } [Test] - public void FailedBuildFew_ConflictingLinearLayout () + public void FailedBuildFew_ConflictingLinearLayout ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildFew_ConflictingLinearLayout", many: false, dtb: false, runner: FailedBuild_ConflictingLinearLayout_RunTest); + RunTest (TestName, many: false, dtb: false, runner: FailedBuild_ConflictingLinearLayout_RunTest, runtime: runtime); } [Test] - public void FailedBuildMany_ConflictingLinearLayout () + public void FailedBuildMany_ConflictingLinearLayout ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildMany_ConflictingLinearLayout", many: true, dtb: false, runner: FailedBuild_ConflictingLinearLayout_RunTest); + RunTest (TestName, many: true, dtb: false, runner: FailedBuild_ConflictingLinearLayout_RunTest, runtime: runtime); } - void FailedBuild_ConflictingLinearLayout_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder) + void FailedBuild_ConflictingLinearLayout_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder, AndroidRuntime runtime) { - string[] parameters = GetBuildProperties (builder, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_LINEARLAYOUT"); + string[] parameters = GetBuildProperties (builder, runtime, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_LINEARLAYOUT"); bool success = builder.Build (testInfo.ProjectPath, GetBuildTarget (dtb), parameters); CopyLogs (testInfo, true); @@ -475,20 +484,20 @@ void FailedBuild_ConflictingLinearLayout_RunTest (TestProjectInfo testInfo, bool } [Test] - public void FailedBuildFew_ConflictingRelativeLayout () + public void FailedBuildFew_ConflictingRelativeLayout ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildFew_ConflictingRelativeLayout", many: false, dtb: false, runner: FailedBuild_ConflictingRelativeLayout_RunTest); + RunTest (TestName, many: false, dtb: false, runner: FailedBuild_ConflictingRelativeLayout_RunTest, runtime: runtime); } [Test] - public void FailedBuildMany_ConflictingRelativeLayout () + public void FailedBuildMany_ConflictingRelativeLayout ([Values] AndroidRuntime runtime) { - RunTest ("FailedBuildMany_ConflictingRelativeLayout", many: true, dtb: false, runner: FailedBuild_ConflictingRelativeLayout_RunTest); + RunTest (TestName, many: true, dtb: false, runner: FailedBuild_ConflictingRelativeLayout_RunTest, runtime: runtime); } - void FailedBuild_ConflictingRelativeLayout_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder) + void FailedBuild_ConflictingRelativeLayout_RunTest (TestProjectInfo testInfo, bool many, bool dtb, LocalBuilder builder, AndroidRuntime runtime) { - string[] parameters = GetBuildProperties (builder, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_RELATIVELAYOUT"); + string[] parameters = GetBuildProperties (builder, runtime, many, dtb, referenceAndroidX:false, "NOT_CONFLICTING_RELATIVELAYOUT"); bool success = builder.Build (testInfo.ProjectPath, GetBuildTarget (dtb), parameters); CopyLogs (testInfo, true); @@ -507,11 +516,38 @@ string GetBuildTarget (bool isDTB) return isDTB ? "Compile" : "SignAndroidPackage"; } - string[] GetBuildProperties (LocalBuilder builder, bool manyBuild, bool dtbBuild, bool referenceAndroidX, params string[] extraConstants) + string[] GetBuildProperties (LocalBuilder builder, AndroidRuntime runtime, bool manyBuild, bool dtbBuild, bool referenceAndroidX, params string[] extraConstants) { + var noWarn = new List { + "CA1416", + "CS0414", + "CS1591", + "XA1005", + "XA4225", + }; + + if (runtime == AndroidRuntime.NativeAOT) { + // We disable these only on CI, since they would cause the tests to fail there. + // It appears that despite us exporting `RunningOnCI` in our pipeline YAML, we actually get + // an all-uppercase version of the variable: + // + // temp/CodeBehind/SuccessfulBuildFewNativeAOT/Release/Directory.Build.props(78,28): message : Property 'RUNNINGONCI' with value 'true' expanded from the environment. + // + string? runningOnCI = + Environment.GetEnvironmentVariable ("RunningOnCI") ?? + Environment.GetEnvironmentVariable ("RUNNINGONCI"); + if (runningOnCI == "true") { + Console.WriteLine ("CodeBehindTests: using NativeAOT and running on CI, disabling warnings."); + noWarn.Add ("IL2091"); + noWarn.Add ("IL2104"); + noWarn.Add ("IL3053"); + noWarn.Add ("XA1040"); + } + } + var ret = new List { "AndroidGenerateLayoutBindings=true", - "\"NoWarn=CS0414;CA1416;CS1591;XA1005;XA4225\"" + $"\"NoWarn={String.Join (';', noWarn)}\"" }; if (manyBuild) ret.Add ("ForceParallelBuild=true"); @@ -577,15 +613,20 @@ void AssertHaveCompilerError (bool haveError, string fileName, int line) /// Generate code in parallel if true, serially otherwise /// Test design-time build if true, regular build otherwise /// Action consituting the main body of the test. Passed parameters are described above in the remarks section. - void RunTest (string testName, bool many, bool dtb, Action runner) + void RunTest (string testName, bool many, bool dtb, Action runner, AndroidRuntime runtime) { - string temporaryProjectDir = PrepareProject (testName); + bool isRelease = runtime == AndroidRuntime.NativeAOT; + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } + + string temporaryProjectDir = PrepareProject (testName, isRelease, runtime); LocalBuilder builder = GetBuilder ($"{ProjectName}.{testName}"); builder.BuildingInsideVisualStudio = dtb; - var testInfo = new TestProjectInfo (ProjectName, testName, temporaryProjectDir, TestOutputDir); + var testInfo = new TestProjectInfo (ProjectName, testName, temporaryProjectDir, TestOutputDir, runtime); try { - runner (testInfo, many, dtb, builder); + runner (testInfo, many, dtb, builder, runtime); if (many) { Assert.That (WasParsedInParallel (testInfo), Is.True, "Should have been parsed in parallel"); @@ -604,7 +645,7 @@ void RunTest (string testName, bool many, bool dtb, Action ignoreDirs) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DeferredBuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DeferredBuildTest.cs index 696cffe87b2..07bd0676864 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DeferredBuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/DeferredBuildTest.cs @@ -2,6 +2,7 @@ using System.IO; using Xamarin.ProjectTools; using Microsoft.Build.Framework; +using Xamarin.Android.Tasks; namespace Xamarin.Android.Build.Tests { @@ -9,13 +10,19 @@ namespace Xamarin.Android.Build.Tests public class DeferredBuildTest : BaseTest { [Test] - public void SelectivelyRunUpdateAndroidResources () + public void SelectivelyRunUpdateAndroidResources ([Values] AndroidRuntime runtime) { + bool isRelease = runtime == AndroidRuntime.NativeAOT; + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var path = Path.Combine ("temp", TestName); var app = new XamarinAndroidApplicationProject { + IsRelease = isRelease, ProjectName = "MyApp", }; + app.SetRuntime (runtime); app.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "True"); app.SetProperty ("AndroidUseIntermediateDesignerFile", "True"); @@ -54,13 +61,20 @@ public void SelectivelyRunUpdateAndroidResources () } [Test] - public void RunUpdateAndroidResourcesIfBackgroundBuildNotSupported () + public void RunUpdateAndroidResourcesIfBackgroundBuildNotSupported ([Values] AndroidRuntime runtime) { + bool isRelease = runtime == AndroidRuntime.NativeAOT; + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } + var path = Path.Combine ("temp", TestName); var app = new XamarinAndroidApplicationProject { + IsRelease = isRelease, ProjectName = "MyApp", }; + app.SetRuntime (runtime); app.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "True"); app.SetProperty ("AndroidUseIntermediateDesignerFile", "True"); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/EnvironmentContentTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/EnvironmentContentTests.cs index 1427e30cf0b..b0eb166863a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/EnvironmentContentTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/EnvironmentContentTests.cs @@ -16,18 +16,29 @@ public class EnvironmentContentTests : BaseTest { [Test] [NonParallelizable] - public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode, - [Values (AndroidRuntime.MonoVM, AndroidRuntime.CoreCLR)] AndroidRuntime runtime) + public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline")] string sequencePointsMode, [Values] AndroidRuntime runtime) { + const bool isRelease = true; + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } + + // TODO: NativeAOT fails all the tests, `MONO_DEBUG` is not found in the environment. Question is - should we fix it for backward compatibility, + // even though NativeAOT won't use it (and CoreCLR passes the tests), or should we just ignore this test for NativeAOT? + if (runtime == AndroidRuntime.NativeAOT) { + Assert.Ignore ("NativeAOT doesn't currently export the MONO_DEBUG environment variable"); + } + string supportedAbis = runtime switch { AndroidRuntime.MonoVM => "armeabi-v7a;x86", AndroidRuntime.CoreCLR => "arm64-v8a;x86_64", + AndroidRuntime.NativeAOT => "arm64-v8a;x86_64", _ => throw new NotSupportedException ($"Unsupported runtime '{runtime}'") }; var lib = new XamarinAndroidLibraryProject { ProjectName = "Library1", - IsRelease = true, + IsRelease = isRelease, OtherBuildItems = { new AndroidItem.AndroidEnvironment ("Mono.env") { TextContent = () => "MONO_DEBUG=soft-breakpoints" }, @@ -35,7 +46,7 @@ public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline }; lib.SetRuntime (runtime); var app = new XamarinFormsAndroidApplicationProject () { - IsRelease = true, + IsRelease = isRelease, AndroidLinkModeRelease = AndroidLinkMode.Full, References = { new BuildItem ("ProjectReference","..\\Library1\\Library1.csproj"), @@ -53,7 +64,7 @@ public void BuildApplicationWithMonoEnvironment ([Values ("", "Normal", "Offline Assert.IsTrue (appb.Build (app), "App should have succeeded."); string intermediateOutputDir = Path.Combine (Root, appb.ProjectDirectory, app.IntermediateOutputPath); - List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true); + List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime); Dictionary envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, runtime); Assert.IsTrue (envvars.Count > 0, $"No environment variables defined"); @@ -99,7 +110,7 @@ public void CheckMonoDebugIsAddedToEnvironment ([Values ("", "Normal", "Offline" Assert.IsTrue (b.Build (proj), "Build should have succeeded."); string intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath); - List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true); + List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, AndroidRuntime.MonoVM); Dictionary envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, AndroidRuntime.MonoVM); Assert.IsTrue (envvars.Count > 0, $"No environment variables defined"); @@ -122,6 +133,7 @@ public void CheckConcurrentGC () var proj = new XamarinAndroidApplicationProject () { IsRelease = true, }; + var gcVarName = "MONO_GC_PARAMS"; var expectedDefaultValue = "major=marksweep"; var expectedUpdatedValue = "major=marksweep-conc"; @@ -135,14 +147,14 @@ public void CheckConcurrentGC () Assert.IsTrue (b.Build (proj), "Build should have succeeded."); var intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath); // AndroidEnableSGenConcurrent=False by default - List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true); + List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, AndroidRuntime.MonoVM); Dictionary envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, AndroidRuntime.MonoVM); Assert.IsTrue (envvars.ContainsKey (gcVarName), $"Environment should contain '{gcVarName}'."); Assert.AreEqual (expectedDefaultValue, envvars[gcVarName], $"'{gcVarName}' should have been '{expectedDefaultValue}' when concurrent GC is disabled."); proj.SetProperty ("AndroidEnableSGenConcurrent", "True"); Assert.IsTrue (b.Build (proj), "Second build should have succeeded."); - envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true); + envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, AndroidRuntime.MonoVM); envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, AndroidRuntime.MonoVM); Assert.IsTrue (envvars.ContainsKey (gcVarName), $"Environment should contain '{gcVarName}'."); Assert.AreEqual (expectedUpdatedValue, envvars[gcVarName], $"'{gcVarName}' should have been '{expectedUpdatedValue}' when concurrent GC is enabled."); @@ -150,11 +162,16 @@ public void CheckConcurrentGC () } [Test] - public void CheckForInvalidHttpClientHandlerType () + public void CheckForInvalidHttpClientHandlerType ([Values] AndroidRuntime runtime) { + const bool isRelease = true; + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var proj = new XamarinAndroidApplicationProject () { - IsRelease = true, + IsRelease = isRelease, }; + proj.SetRuntime (runtime); using (var b = CreateApkBuilder ()) { b.ThrowOnBuildFailure = false; proj.SetProperty ("AndroidHttpClientHandlerType", "Android.App.Application"); @@ -164,10 +181,14 @@ public void CheckForInvalidHttpClientHandlerType () } [Test] - public void CheckHttpClientHandlerType ([Values (AndroidRuntime.MonoVM, AndroidRuntime.CoreCLR)] AndroidRuntime runtime) + public void CheckHttpClientHandlerType ([Values] AndroidRuntime runtime) { + bool isRelease = runtime == AndroidRuntime.NativeAOT; + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } var proj = new XamarinAndroidApplicationProject () { - IsRelease = true, + IsRelease = isRelease, }; var httpClientHandlerVarName = "XA_HTTP_CLIENT_HANDLER_TYPE"; var expectedDefaultValue = "System.Net.Http.SocketsHttpHandler, System.Net.Http"; @@ -176,6 +197,7 @@ public void CheckHttpClientHandlerType ([Values (AndroidRuntime.MonoVM, AndroidR string supportedAbis = runtime switch { AndroidRuntime.MonoVM => "armeabi-v7a;arm64-v8a", AndroidRuntime.CoreCLR => "arm64-v8a;x86_64", + AndroidRuntime.NativeAOT => "arm64-v8a;x86_64", _ => throw new NotSupportedException ($"Unsupported runtime '{runtime}'") }; proj.SetRuntime (runtime); @@ -187,14 +209,14 @@ public void CheckHttpClientHandlerType ([Values (AndroidRuntime.MonoVM, AndroidR proj.SetProperty ("AndroidHttpClientHandlerType", expectedDefaultValue); Assert.IsTrue (b.Build (proj), "Build should have succeeded."); var intermediateOutputDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath); - List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true); + List envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime); Dictionary envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, runtime); Assert.IsTrue (envvars.ContainsKey (httpClientHandlerVarName), $"Environment should contain '{httpClientHandlerVarName}'."); Assert.AreEqual (expectedDefaultValue, envvars[httpClientHandlerVarName]); proj.SetProperty ("AndroidHttpClientHandlerType", expectedUpdatedValue); Assert.IsTrue (b.Build (proj), "Second build should have succeeded."); - envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true); + envFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediateOutputDir, supportedAbis, true, runtime); envvars = EnvironmentHelper.ReadEnvironmentVariables (envFiles, runtime); Assert.IsTrue (envvars.ContainsKey (httpClientHandlerVarName), $"Environment should contain '{httpClientHandlerVarName}'."); Assert.AreEqual (expectedUpdatedValue, envvars[httpClientHandlerVarName]); diff --git a/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj b/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj index 2175ae82a5d..25439f6fff7 100644 --- a/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj +++ b/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj @@ -11,7 +11,17 @@ false false false + aab + @UseMonoRuntime@ + @PublishAot@ + @Configuration@ + + + + XA1040;IL3053 + + $(DefineConstants);$(ExtraConstants) diff --git a/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.NET.csproj b/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.NET.csproj index 3765f0d1a57..c053db4655b 100644 --- a/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.NET.csproj +++ b/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.NET.csproj @@ -4,6 +4,9 @@ CommonSampleLibrary CommonSampleLibrary false + @UseMonoRuntime@ + @PublishAot@ + @Configuration@ $(DefineConstants);$(ExtraConstants)