From 743af6525b0f8a96ef197c6909eb089e75564df4 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 25 Feb 2025 16:10:42 -0600 Subject: [PATCH] [nativeaot] run Mono.Android-Tests Context: https://github.com/dotnet/android/issues/10079 This runs Mono.Android-Tests with `-p:PublishAot=true`. I temporarily disabled the following tests: * The `Java.Interop-Tests.dll` test assembly * `GCBridge` category, related to a missing "GC Bridge" * `SSL` and `NTLM` categories related to some http tests * Some individual tests These categories will probably *never need to* work on NativeAOT: * `Export`: use of `Mono.Android.Export.dll` * `AndroidClientHandler`: legacy `HttpClientHandler` implementation * `NativeTypeMap`: as the managed typemap is trimmer safe * `AppContextTests.TestPrivateSwitches` may not be relevant for NativeAOT I left a `TODO` comment for each ignored test, to investigate in the future. --- .../automation/yaml-templates/stage-package-tests.yaml | 10 ++++++++++ samples/NativeAOT/NativeAOT.csproj | 8 -------- .../AndroidValueManagerContractTests.cs | 4 +++- .../Mono.Android-Tests/Java.Interop/JnienvTest.cs | 8 ++++---- .../Mono.Android-Tests/Java.Lang/ObjectTest.cs | 1 + .../Mono.Android-Tests/Mono.Android.NET-Tests.csproj | 2 ++ .../Mono.Android-Tests/System/AppContextTests.cs | 1 + .../Mono.Android-Tests/System/ExceptionTest.cs | 1 + .../Xamarin.Android.Net/AndroidClientHandlerTests.cs | 2 ++ .../Xamarin.Android.Net/HttpClientIntegrationTests.cs | 1 + 10 files changed, 25 insertions(+), 13 deletions(-) diff --git a/build-tools/automation/yaml-templates/stage-package-tests.yaml b/build-tools/automation/yaml-templates/stage-package-tests.yaml index b858b9a2a94..5c6fcfeb141 100644 --- a/build-tools/automation/yaml-templates/stage-package-tests.yaml +++ b/build-tools/automation/yaml-templates/stage-package-tests.yaml @@ -208,6 +208,16 @@ stages: artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab artifactFolder: $(DotNetTargetFramework)-CoreCLR + - template: /build-tools/automation/yaml-templates/apk-instrumentation.yaml + parameters: + configuration: $(XA.Build.Configuration) + testName: Mono.Android.NET_Tests-NativeAOT + project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj + testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)NativeAOT.xml + extraBuildArgs: -p:TestsFlavor=NativeAOT -p:PublishAot=true + artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab + artifactFolder: $(DotNetTargetFramework)-NativeAOT + - template: /build-tools/automation/yaml-templates/apk-instrumentation.yaml parameters: configuration: $(XA.Build.Configuration) diff --git a/samples/NativeAOT/NativeAOT.csproj b/samples/NativeAOT/NativeAOT.csproj index 8b9148c5a88..d16ef4b8056 100644 --- a/samples/NativeAOT/NativeAOT.csproj +++ b/samples/NativeAOT/NativeAOT.csproj @@ -12,12 +12,4 @@ true - - - - <_NuGetFolderOnCI>..\..\bin\Build$(Configuration)\nuget-unsigned - $(_NuGetFolderOnCI) - <_FastDeploymentDiagnosticLogging>true - - \ No newline at end of file diff --git a/tests/Mono.Android-Tests/Java.Interop-Tests/Java.InteropTests/AndroidValueManagerContractTests.cs b/tests/Mono.Android-Tests/Java.Interop-Tests/Java.InteropTests/AndroidValueManagerContractTests.cs index 74033ebcb7c..6a3bba40934 100644 --- a/tests/Mono.Android-Tests/Java.Interop-Tests/Java.InteropTests/AndroidValueManagerContractTests.cs +++ b/tests/Mono.Android-Tests/Java.Interop-Tests/Java.InteropTests/AndroidValueManagerContractTests.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Threading; @@ -11,9 +12,10 @@ using NUnit.Framework; namespace Java.InteropTests { - [TestFixture] + [TestFixture, Category ("NativeTypeMap")] public class AndroidValueManagerContractTests : JniRuntimeJniValueManagerContract { + [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] protected override Type ValueManagerType => typeof (Android.Runtime.AndroidValueManager); } } diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs index e28317387d4..c97a8d6e1d3 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs @@ -238,7 +238,7 @@ public void SetField_PermitNullValues () } } - [Test] + [Test, Category ("Export")] [Category ("CoreCLRIgnore")] //TODO: https://github.com/dotnet/android/issues/10069 public void CreateTypeWithExportedMethods () { @@ -251,7 +251,7 @@ public void CreateTypeWithExportedMethods () } } - [Test] + [Test, Category ("Export")] [Category ("CoreCLRIgnore")] //TODO: https://github.com/dotnet/android/issues/10069 public void ActivatedDirectObjectSubclassesShouldBeRegistered () { @@ -407,7 +407,7 @@ public void MoarThreadingTests () Assert.IsNull (ignore_t2, string.Format ("No exception should be thrown [t2]! Got: {0}", ignore_t2)); } - [Test] + [Test, Category ("NativeTypeMap")] public void JavaToManagedTypeMapping () { Type m = Java.Interop.TypeManager.GetJavaToManagedType ("android/content/res/Resources"); @@ -416,7 +416,7 @@ public void JavaToManagedTypeMapping () Assert.AreEqual (null, m); } - [Test] + [Test, Category ("NativeTypeMap")] public void ManagedToJavaTypeMapping () { Type type = typeof(Activity); diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Lang/ObjectTest.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Lang/ObjectTest.cs index 1d656e434a9..875641156d2 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Lang/ObjectTest.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Lang/ObjectTest.cs @@ -67,6 +67,7 @@ static MethodInfo MakeGenericMethod (MethodInfo method, Type type) => [Test] [Category ("CoreCLRIgnore")] //TODO: https://github.com/dotnet/android/issues/10069 + [Category ("NativeAOTIgnore")] //TODO: https://github.com/dotnet/android/issues/10079 public void JnienvCreateInstance_RegistersMultipleInstances () { using (var adapter = new CreateInstance_OverrideAbsListView_Adapter (Application.Context)) { diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj b/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj index b56fdfa8857..7856cb38d1b 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj @@ -33,6 +33,8 @@ DotNetIgnore $(ExcludeCategories):CoreCLRIgnore:SSL:NTLM:GCBridge:RuntimeConfig + + $(ExcludeCategories):NativeAOTIgnore:SSL:NTLM:GCBridge:AndroidClientHandler:Export:NativeTypeMap $(ExcludeCategories):LLVMIgnore $(ExcludeCategories):InetAccess:NetworkInterfaces diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/System/AppContextTests.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/System/AppContextTests.cs index 4cfd9856eed..8bb16a1e567 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/System/AppContextTests.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/System/AppContextTests.cs @@ -49,6 +49,7 @@ public void GetData (string name, string expected) }; [Test] + [Category ("NativeAOTIgnore")] // These switches only exist in Mono & CoreCLR BCL assemblies [TestCaseSource (nameof (TestPrivateSwitchesSource))] public void TestPrivateSwitches ( [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/System/ExceptionTest.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/System/ExceptionTest.cs index 96cf8a921fd..52e98dac4e3 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/System/ExceptionTest.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/System/ExceptionTest.cs @@ -30,6 +30,7 @@ static Java.Lang.Throwable CreateJavaProxyThrowable (Exception e) [Test] [Category ("CoreCLRIgnore")] //TODO: https://github.com/dotnet/android/issues/10069 + [Category ("NativeAOTIgnore")] // NativeAOT has very limited stack traces [RequiresUnreferencedCode ("Tests trimming unsafe features")] public void InnerExceptionIsSet () { diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs index a41040b9223..661e22e1b02 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs @@ -147,6 +147,7 @@ bool IgnoreIfConnectionFailed (WebException wex, out bool connectionFailed) } } + [Category ("AndroidClientHandler")] public abstract class AndroidHandlerTestBase : HttpClientHandlerTestBase { static IEnumerable Exceptions (Exception e) @@ -316,6 +317,7 @@ public bool ShouldIgnoreSuccessStatusCode (HttpStatusCode code) } [TestFixture] + [Category ("AndroidClientHandler")] public class AndroidClientHandlerTests : AndroidHandlerTestBase { protected override HttpMessageHandler CreateHandler () diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/HttpClientIntegrationTests.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/HttpClientIntegrationTests.cs index f3fedc19edd..253be09b574 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/HttpClientIntegrationTests.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.Net/HttpClientIntegrationTests.cs @@ -1062,6 +1062,7 @@ public static implicit operator HttpMessageHandler (AndroidHandlerSettingsAdapte } [TestFixture] + [Category ("AndroidClientHandler")] public class AndroidClientHandlerIntegrationTests : HttpClientIntegrationTestBase { protected override AndroidHandlerSettingsAdapter CreateHandler ()