Skip to content

Commit f8106b0

Browse files
Add trimmable typemap test plumbing and CI lane
- MonoAndroidTypeMapFlavor=legacy|trimmable MSBuild switch - CoreCLRTrimmable CI lane in stage-package-tests.yaml - ExcludeCategories: NativeTypeMap, TrimmableIgnore, SSL - ExcludedTestNames for Java.Interop-Tests JavaObject-based fixtures - TrimmableIgnore on NewOpenGenericTypeThrows, ActivatedDirectThrowable, JavaCast_BaseToGenericWrapper Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d5aefaa commit f8106b0

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

build-tools/automation/yaml-templates/stage-package-tests.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,20 @@ stages:
199199
testName: Mono.Android.NET_Tests-CoreCLR
200200
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
201201
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)CoreCLR.xml
202-
extraBuildArgs: -p:TestsFlavor=CoreCLR -p:UseMonoRuntime=false
202+
extraBuildArgs: -p:MonoAndroidTypeMapFlavor=legacy
203203
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
204204
artifactFolder: $(DotNetTargetFramework)-CoreCLR
205205

206+
- template: /build-tools/automation/yaml-templates/apk-instrumentation.yaml
207+
parameters:
208+
configuration: $(XA.Build.Configuration)
209+
testName: Mono.Android.NET_Tests-CoreCLRTrimmable
210+
project: tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj
211+
testResultsFiles: TestResult-Mono.Android.NET_Tests-$(XA.Build.Configuration)CoreCLRTrimmable.xml
212+
extraBuildArgs: -p:MonoAndroidTypeMapFlavor=trimmable
213+
artifactSource: bin/Test$(XA.Build.Configuration)/$(DotNetTargetFramework)-android/Mono.Android.NET_Tests-Signed.aab
214+
artifactFolder: $(DotNetTargetFramework)-CoreCLRTrimmable
215+
206216
- template: /build-tools/automation/yaml-templates/apk-instrumentation.yaml
207217
parameters:
208218
configuration: $(XA.Build.Configuration)

tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JavaObjectExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Java.InteropTests {
1515
[TestFixture]
1616
public class JavaObjectExtensionsTests {
1717

18-
[Test]
18+
[Test, Category ("TrimmableIgnore")]
1919
public void JavaCast_BaseToGenericWrapper ()
2020
{
2121
using (var list = new JavaList (new[]{ 1, 2, 3 }))

tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void InvokingNullInstanceDoesNotCrashDalvik ()
121121
}
122122
}
123123

124-
[Test]
124+
[Test, Category ("TrimmableIgnore")]
125125
public void NewOpenGenericTypeThrows ()
126126
{
127127
try {
@@ -301,7 +301,7 @@ public void ActivatedDirectObjectSubclassesShouldBeRegistered ()
301301
}
302302
}
303303

304-
[Test]
304+
[Test, Category ("TrimmableIgnore")]
305305
public void ActivatedDirectThrowableSubclassesShouldBeRegistered ()
306306
{
307307
if (Build.VERSION.SdkInt <= BuildVersionCodes.GingerbreadMr1)

tests/Mono.Android-Tests/Mono.Android-Tests/Java.Lang/ObjectTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ public void JnienvCreateInstance_RegistersMultipleInstances ()
7272

7373
var intermediate = CreateInstance_OverrideAbsListView_Adapter.Intermediate;
7474
var registered = Java.Lang.Object.GetObject<CreateInstance_OverrideAbsListView_Adapter>(adapter.Handle, JniHandleOwnership.DoNotTransfer);
75+
var asBase = Java.Lang.Object.GetObject<AbsListView>(adapter.Handle, JniHandleOwnership.DoNotTransfer);
7576

7677
Assert.AreNotSame (adapter, intermediate);
7778
Assert.AreSame (adapter, registered);
79+
Assert.AreSame (adapter, asBase);
7880
}
7981
}
8082

tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
<ExcludeCategories Condition=" '$(EnableLLVM)' == 'true' ">$(ExcludeCategories):InetAccess:NetworkInterfaces</ExcludeCategories>
3838
</PropertyGroup>
3939

40+
<PropertyGroup>
41+
<MonoAndroidTypeMapFlavor Condition=" '$(MonoAndroidTypeMapFlavor)' == '' "></MonoAndroidTypeMapFlavor>
42+
<UseMonoRuntime Condition=" '$(MonoAndroidTypeMapFlavor)' != '' and '$(UseMonoRuntime)' == '' and '$(PublishAot)' != 'true' ">false</UseMonoRuntime>
43+
<_AndroidTypeMapImplementation Condition=" '$(MonoAndroidTypeMapFlavor)' == 'legacy' and '$(_AndroidTypeMapImplementation)' == '' ">llvm-ir</_AndroidTypeMapImplementation>
44+
<_AndroidTypeMapImplementation Condition=" '$(MonoAndroidTypeMapFlavor)' == 'trimmable' and '$(_AndroidTypeMapImplementation)' == '' ">trimmable</_AndroidTypeMapImplementation>
45+
<TestsFlavor Condition=" '$(TestsFlavor)' == '' and '$(MonoAndroidTypeMapFlavor)' == 'legacy' ">CoreCLR</TestsFlavor>
46+
<TestsFlavor Condition=" '$(TestsFlavor)' == '' and '$(MonoAndroidTypeMapFlavor)' == 'trimmable' ">CoreCLRTrimmable</TestsFlavor>
47+
<ExcludeCategories Condition=" '$(MonoAndroidTypeMapFlavor)' == 'trimmable' ">$(ExcludeCategories):NativeTypeMap:TrimmableIgnore:SSL</ExcludeCategories>
48+
</PropertyGroup>
49+
4050
<ItemGroup>
4151
<PackageReference Include="Mono.Linq.Expressions" Version="2.0.0" />
4252
</ItemGroup>
@@ -260,6 +270,18 @@
260270
</TestAab>
261271
</ItemGroup>
262272

273+
<Target Name="_ValidateMonoAndroidTypeMapFlavor"
274+
BeforeTargets="Build">
275+
<Error Condition=" '$(MonoAndroidTypeMapFlavor)' != '' and '$(MonoAndroidTypeMapFlavor)' != 'legacy' and '$(MonoAndroidTypeMapFlavor)' != 'trimmable' "
276+
Text="Invalid value for MonoAndroidTypeMapFlavor: '$(MonoAndroidTypeMapFlavor)'. Valid values are: legacy, trimmable." />
277+
<Error Condition=" '$(MonoAndroidTypeMapFlavor)' != '' and '$(PublishAot)' == 'true' "
278+
Text="MonoAndroidTypeMapFlavor only supports the Mono.Android.NET-Tests CoreCLR configurations." />
279+
<Error Condition=" '$(MonoAndroidTypeMapFlavor)' != '' and '$(UseMonoRuntime)' == 'true' "
280+
Text="MonoAndroidTypeMapFlavor requires CoreCLR. Remove UseMonoRuntime=true." />
281+
<Error Condition=" '$(MonoAndroidTypeMapFlavor)' == 'trimmable' and '$(_AndroidTypeMapImplementation)' != 'trimmable' "
282+
Text="MonoAndroidTypeMapFlavor=trimmable requires _AndroidTypeMapImplementation=trimmable." />
283+
</Target>
284+
263285
<Import Project="$(XamarinAndroidSourcePath)build-tools\scripts\TestApks.targets" />
264286

265287
</Project>

tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.RuntimeTests/NUnitInstrumentation.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ protected override string LogTag
2525
protected NUnitInstrumentation(IntPtr handle, JniHandleOwnership transfer)
2626
: base(handle, transfer)
2727
{
28+
if (Microsoft.Android.Runtime.RuntimeFeature.TrimmableTypeMap) {
29+
// Java.Interop-Tests fixtures that use JavaObject types (not Java.Lang.Object)
30+
// don't have JCW Java classes in the trimmable APK, and method remapping
31+
// tests require Java-side support not present in the trimmable path.
32+
// Exclude these entire fixtures to prevent ClassNotFoundException crashes.
33+
ExcludedTestNames = new [] {
34+
"Java.InteropTests.JavaObjectTest",
35+
"Java.InteropTests.InvokeVirtualFromConstructorTests",
36+
"Java.InteropTests.JniPeerMembersTests",
37+
"Java.InteropTests.JniTypeManagerTests",
38+
"Java.InteropTests.JniValueMarshaler_object_ContractTests",
39+
"Java.InteropTests.JavaExceptionTests.InnerExceptionIsNotAProxy",
40+
};
41+
}
2842
}
2943

3044
protected override IList<TestAssemblyInfo> GetTestAssemblies()

0 commit comments

Comments
 (0)