Skip to content

[TrimmableTypeMap] Add CoreCLRTrimmable Mono.Android.NET-Tests lane#11091

Open
simonrozsival wants to merge 40 commits intomainfrom
dev/simonrozsival/trimmable-test-plumbing
Open

[TrimmableTypeMap] Add CoreCLRTrimmable Mono.Android.NET-Tests lane#11091
simonrozsival wants to merge 40 commits intomainfrom
dev/simonrozsival/trimmable-test-plumbing

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented Apr 8, 2026

Summary

Add the CoreCLRTrimmable Mono.Android.NET-Tests lane and fix the Release regressions exposed by the trimmable typemap path.

This PR includes

  • add the new Mono.Android.NET_Tests-CoreCLRTrimmable lane while keeping the existing CoreCLR lane on the LLVM IR typemap
  • fix trimmable typemap generation and deferred-registration issues required for Release + CoreCLR + trimmable
  • keep native app config / assembly-store counts aligned for the extra generated typemap assemblies
  • add regression coverage at the generator, MSBuild task, and build-test levels, including build assertions for the Release CoreCLRTrimmable scenario
  • root the test assemblies for this trimmed test app and preserve only the specific runtime pieces needed via TrimmerRoots.xml
  • keep the remaining trimmable test exclusions targeted and documented, including the AndroidMessageHandlerTests certificate-callback methods that currently reproduce a native SIGSEGV

Split out of this PR

The generic Android NUnit runner work was moved to #11162:

  • dry-run discovery support
  • noexclusions=true audit mode
  • visible ignored-test reporting with reasons
  • final summary-count fix
  • stale-logcat overwrite cleanup

Validation

Local Release + CoreCLR + trimmable runs now complete and produce a real NUnit XML instead of a synthetic crash result.

Latest local device result after the current cleanup:

  • 826 passed
  • 1 error (System.NetTests.SslTest.SslWithinTasksShouldWork, connection reset by peer)
  • 6 ignored
  • 833 total

Skipped tests in the trimmable lane

The CoreCLRTrimmable lane runs 833 of 913 tests (91%). 80 tests are excluded — broken down as follows:

Category Count Reason
Java.InteropTests 68 Rely on DynamicRegistration or JNI features not yet supported by the trimmable typemap
AndroidMessageHandlerTests 5 ServerCertificateCustomValidationCallback_* — native SIGSEGV due to IX509TrustManager lookup failure in trimmed typemap
AndroidMessageHandlerNegotiateAuthenticationTests 3 Negotiate auth tests excluded by category
JnienvArrayMarshaling 1 GetObjectArray — dynamic registration
Other (category-based) 3 InetAccess:NetworkInterfaces, DotNet, DynamicRegistration category exclusions

Of the 833 tests that do run, 6 are marked [Ignore] by NUnit (pre-existing, not trimmable-specific) and 1 flaky error (SslWithinTasksShouldWork, connection reset by peer).

@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-test-plumbing branch from f8106b0 to a437455 Compare April 9, 2026 09:19
@simonrozsival simonrozsival added trimmable-type-map copilot `copilot-cli` or other AIs were used to author this labels Apr 9, 2026
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-runtime-fixes branch from d5aefaa to 3a8d509 Compare April 10, 2026 09:49
Base automatically changed from dev/simonrozsival/trimmable-runtime-fixes to main April 10, 2026 22:50
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-test-plumbing branch 2 times, most recently from 1814a6d to d0e30f6 Compare April 11, 2026 09:42
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Test plumbing and CI lane for Mono.Android.NET-Tests [TrimmableTypeMap] Stabilize CoreCLR Mono.Android.NET-Tests lane Apr 11, 2026
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-test-plumbing branch from 17b123b to e2c70fd Compare April 11, 2026 23:28
@simonrozsival simonrozsival changed the base branch from main to dev/simonrozsival/root-manifest-referenced-types April 11, 2026 23:28
simonrozsival added a commit that referenced this pull request Apr 11, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-test-plumbing branch from e2c70fd to 87c531f Compare April 11, 2026 23:50
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Stabilize CoreCLR Mono.Android.NET-Tests lane [TrimmableTypeMap] Add CoreCLR Mono.Android.NET-Tests lane plumbing Apr 11, 2026
@simonrozsival simonrozsival marked this pull request as ready for review April 12, 2026 08:01
Copilot AI review requested due to automatic review settings April 12, 2026 08:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds CI/test-lane plumbing to run Mono.Android.NET-Tests on CoreCLR with the trimmable typemap implementation, keeping currently-unsupported test buckets explicitly excluded to maintain green coverage while follow-up runtime/generator work lands separately.

Changes:

  • Adds a new CoreCLRTrimmable APK instrumentation lane and pins the existing CoreCLR lane to llvm-ir.
  • Updates Mono.Android.NET-Tests.csproj to default to CoreCLR + exclude trimmable-specific buckets when _AndroidTypeMapImplementation=trimmable.
  • Centralizes additional trimmable-mode runtime test exclusions in NUnitInstrumentation, and adjusts a few Java.Interop tests/projects to avoid unsupported coverage.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Mono.Android-Tests/Mono.Android-Tests/Xamarin.Android.RuntimeTests/NUnitInstrumentation.cs Adds runtime-switch-driven exclusions for categories and specific Java.Interop test names under trimmable typemap.
tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj Sets defaults/exclusions for trimmable typemap runs (incl. CoreCLRTrimmable flavor).
tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs Marks specific tests as TrimmableIgnore.
tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JavaObjectExtensionsTests.cs Marks a specific test as TrimmableIgnore (and normalizes file header).
tests/Mono.Android-Tests/Java.Interop-Tests/Java.Interop-Tests.NET.csproj Removes JniTypeUtf8Test.cs from compilation due to unsupported APIs in the product assembly.
build-tools/automation/yaml-templates/stage-package-tests.yaml Updates CoreCLR lane args and adds the new CoreCLRTrimmable lane.

Copy link
Copy Markdown
Member Author

@simonrozsival simonrozsival left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review Summary

Verdict: ✅ LGTM

Found 1 suggestion:

  • 💡 Code organization — the trimmable category filtering is now split between Mono.Android.NET-Tests.csproj and NUnitInstrumentation.cs (NUnitInstrumentation.cs:29). Keeping one source of truth would make the temporary exclusions easier to retire.

The lane wiring itself looks good, and I like that the unsupported cases stay explicit instead of being hidden behind runtime fallback behavior.


Review generated by android-reviewer from review guidelines.

Base automatically changed from dev/simonrozsival/root-manifest-referenced-types to main April 13, 2026 11:47
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-test-plumbing branch 2 times, most recently from 02780bb to c3a7ebc Compare April 13, 2026 12:15
Comment thread build-tools/automation/yaml-templates/stage-package-tests.yaml Outdated
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-test-plumbing branch from 619991d to 6a0644f Compare April 13, 2026 16:39
@simonrozsival simonrozsival changed the base branch from main to dev/simonrozsival/fix-deferred-registration-propagation April 13, 2026 16:39
Base automatically changed from dev/simonrozsival/fix-deferred-registration-propagation to main April 14, 2026 14:19
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/trimmable-test-plumbing branch from 19ec2fa to e084238 Compare April 14, 2026 14:32
@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Add CoreCLR Mono.Android.NET-Tests lane plumbing [TrimmableTypeMap] Add CoreCLRTrimmable Mono.Android.NET-Tests lane plumbing Apr 14, 2026
During the CoreCLRTrimmable investigation, several speculative changes were
added that turned out not to be needed once the real root cause (missing
self-application attribute on generated JavaPeerProxy types) was fixed:

- src/native/: revert the 'registerNativesFn' callback, deferred-class queue,
  and JNI export symbol. Verified via unconditional logging during a full
  device test run that Java_mono_android_Runtime_registerNatives is never
  called when the managed TrimmableTypeMap.OnRegisterNatives handler is
  wired via JniEnvironment.Types.RegisterNatives.
- src/Mono.Android/Android.Runtime/JNIEnvInit.cs: drop the now-unused
  registerNativesFn assignment.
- src/Mono.Android/Microsoft.Android.Runtime/TrimmableTypeMap.cs: restore
  the 'u8' optimized JNI type name literal 'mono/android/Runtime'u8.

All 794 CoreCLRTrimmable device tests still pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival
Copy link
Copy Markdown
Member Author

simonrozsival commented Apr 17, 2026

Splitting this PR into focused, reviewable pieces so each fix gets the attention it deserves. This PR will stay open and become a thin, clean addition to CI configuration once all the children land on main.

Child PRs

# Scope Status
#11142 Package CoreCLR preserve list in SDK pack (+<None> with Link + test asserting the file is actually packaged) merged
#11144 Fix IL1034 by excluding the app assembly from trimmer roots (Option A — preserves the whole point of the trimmable typemap by not rooting everything) merged
#11143 Manifest generator fixes: default instrumentation targetPackage, stale-manifest sentinel on mode switch, outer IntermediateOutputPath, CRC name rewriting in manifest template merged
#11145 Runtime and typemap generator fixes: init ordering, generic type proxy loading, ClassLoader mismatch in RegisterNatives, abstract Instrumentation/Application subtypes, proxy self-application as [JavaPeerProxy] + regression test merged

Once the children merge, this PR will be rebased to include only:

  • The new CoreCLRTrimmable CI lane + TestEnvironment plumbing.
  • Test-side adjustments and CoreCLRTrimmable-specific skips for failing JavaCast/JavaAs/JavaObjectArray tests.

Follow-ups (issues)

  • Unify the native-method registration approach: always defer via __md_registerNatives () for all types, remove the CannotRegisterInStaticConstructor flag and its propagation helpers, and revisit static { registerNatives } as a later optimization for provably safe types. ([TrimmableTypeMap] Runtime and typemap generator fixes #11145 notes the known gap this creates for concrete descendants of abstract Application/Instrumentation.)

@simonrozsival simonrozsival marked this pull request as draft April 17, 2026 10:35
simonrozsival added a commit that referenced this pull request Apr 18, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simonrozsival and others added 9 commits April 18, 2026 22:30
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Filter stale ApplicationRegistration entries, count generated typemap assemblies in native config, and avoid stale logcat false positives in test harness.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add discovery-only dry runs and explicit exclusion auditing for the CoreCLR trimmable test lane, replace obsolete [Preserve] usage with trimmer roots, and narrow the SSL crash handling to targeted named exclusions so the suite completes and reports real XML results.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simonrozsival and others added 3 commits April 20, 2026 11:57
Keep the trimmable typemap PR focused on the CoreCLRTrimmable lane and its targeted test-side plumbing. Move the generic NUnit runner and logcat auditing work to PR #11162, and drop the leftover Preserve-related noise.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the trimmable-specific explanations in NUnitInstrumentation.cs, including the AndroidMessageHandlerTests certificate-callback SIGSEGV note, while keeping SSL narrowed to the individual crashing tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the existing LinqExpressionTest preserve attribute, remove the temporary TrimmableIgnore category usage in favor of explicit ExcludedTestNames, and move the NativeTypeMap exclusion into the test project configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival marked this pull request as ready for review April 20, 2026 10:46
Copy link
Copy Markdown
Member Author

@simonrozsival simonrozsival left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Needs Changes

Nice split between the trimmable typemap/product work here and the generic harness changes in #11162 — that makes this PR much easier to reason about. I left one inline suggestion on the new regression tests.

CI note: the public checks look good, but the internal Xamarin.Android-PR pipeline is still pending, so this is not merge-ready quite yet.

simonrozsival and others added 2 commits April 20, 2026 13:01
Strengthen the trimmable typemap build tests so they exercise the Release CoreCLRTrimmable scenario and assert successful builds instead of tolerating unrelated downstream failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix _GenerateJavaStubs incrementality in the trimmable path by using
  the TypeMap DLL as a focused sentinel input instead of the full
  @(_GenerateJavaStubsInputs) which caused false cache invalidation.
- Move _AdditionalNativeConfigResolvedAssemblies population to a
  separate _PrepareTrimmableNativeConfigAssemblies target so it runs
  even when _GenerateJavaStubs is skipped on incremental builds.
- Skip ServerCertificateCustomValidationCallback_RejectRequest in
  trimmable typemap tests (IX509TrustManager lookup bug, to revisit).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants