Skip to content

Test trimmable typemap behavior at runtime - #12512

Merged
simonrozsival merged 7 commits into
mainfrom
simonrozsival/trimmable-typemap-runtime-tests
Aug 26, 2026
Merged

Test trimmable typemap behavior at runtime#12512
simonrozsival merged 7 commits into
mainfrom
simonrozsival/trimmable-typemap-runtime-tests

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

  • replace trimmable typemap IL and metadata inspection tests with end-to-end Java/JNI runtime coverage where behavior is observable
  • reuse the existing constructor and export runtime matrix instead of duplicating it
  • add runtime coverage for modern boolean callbacks, static exports, primitive and object ExportField values, alias groups, and Java.Interop-style activation
  • retain focused build-time tests for scanner/model behavior, metadata contracts, diagnostics, constructed generic callback references, and instance ExportField Java generation

Migration

Constructors

The existing ConstructorActivationTests and JnienvTest device tests already cover parameterless, primitive, string, object, array, nested-array, and mixed Java-to-managed constructor activation under both CoreCLRTrimmable and NativeAOT. The corresponding emitted-IL assertions were removed.

Callbacks

  • invoke View.IOnLongClickListener.OnLongClick from Java to cover the modern JNI boolean ABI
  • extend the existing AbsListView runtime test to invoke AdapterView.setSelection
  • keep generator contracts for legacy callback ABIs, unresolved fallbacks, and constructed generic-base MemberRef encoding

Exports

  • use the existing runtime matrix for instance exports, arrays, Java peers, copy-back, and exception routing
  • invoke a static [Export] through GetStaticMethodID and CallStaticIntMethod
  • read primitive and object-valued static [ExportField] values through JNI
  • retain build-time coverage for stream/XML export marshalling and instance ExportField Java generation

Proxy resolution

  • verify the generated java/util/ArrayList alias group contains both JavaList and JavaList<>
  • wrap separate Java-created ArrayList handles using generic and non-generic target hints
  • create a Java-owned peer and activate it through the Java.Interop-style (ref JniObjectReference, JniObjectReferenceOptions) constructor
  • retain structural alias serialization and open-generic rejection contracts

Result

  • 817 net lines removed across seven files
  • 409 focused Fact/Theory methods remain in the standalone project for build-time behavior that runtime tests cannot establish
  • six reviewable commits preserve the migration boundaries

Test plan

  • dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimal
    • 771 passed
  • CoreCLRTrimmable and NativeAOT Mono.Android.NET-Tests device lanes should exercise the new runtime tests in CI

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85e194d3-06ac-4880-be33-40e8b6c266b3
The on-device constructor activation suite covers parameterless, primitive, object, array, and mixed Java-to-managed constructor dispatch under both trimmable runtimes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85e194d3-06ac-4880-be33-40e8b6c266b3
Exercise modern boolean callback returns and constructed generic base callbacks through Java and JNI instead of inspecting emitted member references.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85e194d3-06ac-4880-be33-40e8b6c266b3
Cover static exports and primitive and object ExportField initialization at runtime, and rely on existing device tests for instance export dispatch and exception routing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85e194d3-06ac-4880-be33-40e8b6c266b3
Exercise generated alias groups with Java-created ArrayList handles and verify Java.Interop-style activation through a Java-owned peer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85e194d3-06ac-4880-be33-40e8b6c266b3
Keep focused coverage for constructed generic callback references and instance ExportField Java generation, which runtime tests cannot establish.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 85e194d3-06ac-4880-be33-40e8b6c266b3
@simonrozsival
simonrozsival force-pushed the simonrozsival/trimmable-typemap-runtime-tests branch from c6a55be to 7be5748 Compare August 25, 2026 11:01
@simonrozsival
simonrozsival changed the base branch from simonrozsival/trimmable-typemap-conditional-acws to main August 25, 2026 11:01
@simonrozsival
simonrozsival marked this pull request as ready for review August 25, 2026 13:13
Copilot AI lite review requested due to automatic review settings August 25, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the trimmable typemap test strategy by shifting from build-time IL/metadata inspection toward end-to-end device/runtime coverage where JNI/Java↔managed behavior is directly observable, while retaining focused generator/scanner/model contract tests.

Changes:

  • Adds new device/runtime tests for boolean callback ABI (OnLongClick), static [Export] dispatch, static [ExportField] visibility, alias-group target-hint selection, and Java.Interop-style activation.
  • Extends an existing AbsListView JNI invocation test to cover AdapterView.setSelection overriding behavior.
  • Simplifies and refocuses generator tests by removing proxy/activation/export IL-shape assertions and keeping targeted signature/contract checks.
Show a summary per file
File Description
tests/Mono.Android-Tests/Mono.Android-Tests/java/net/dot/android/test/TrimmableRuntimeJavaInteropPeer.java Adds a Java-side peer used for Java-created handle activation coverage.
tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/TrimmableTypeMapRuntimeCoverageTests.cs Adds runtime coverage for long-click boolean ABI, alias groups, and Java.Interop-style activation.
tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ExportTests.cs Adds runtime tests for static [Export] invocation and static [ExportField] visibility via JNI.
tests/Mono.Android-Tests/Mono.Android-Tests/Android.Widget/AdapterTests.cs Extends JNI-based adapter test to exercise setSelection virtual dispatch into managed override.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapAssemblyGeneratorTests.cs Removes broad proxy/activation/export IL inspections; keeps narrower generic callback signature assertions.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/RootTypeMapAssemblyGeneratorTests.cs Removes a now-redundant PE validity test.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/ExportFieldTests.cs Narrows generator coverage to scanner/model + instance field generation contract assertions.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12512

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ LGTM

No blocking issues found. The runtime tests cover the observable behavior formerly checked through emitted IL/metadata, while focused generator contracts remain in place.

Findings: 0 errors · 0 warnings · 1 suggestion

CI is green: all 44 checks passed, including Azure DevOps dotnet-android build #1567349.

Generated by Android PR Reviewer for #12512 · gpt56 · 196.5 AIC · ⌖ 19.4 AIC · ⊞ 25.7K
Comment /review to run again

var method = JNIEnv.GetMethodID (listener.Class.Handle, "onLongClick", "(Landroid/view/View;)Z");
var handled = JNIEnv.CallBooleanMethod (listener.Handle, method, new JValue (view.Handle));

Assert.IsTrue (handled);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 💡 Testing — Please exercise both true and false return values here. This runtime test replaces the removed generator-level boolean ABI assertion, but the hard-coded true path would not catch a callback that incorrectly marshals every result as JNI true. Parameterizing the listener's return value would verify both directions of the managed bool → JNI jboolean conversion.

@simonrozsival
simonrozsival merged commit c59f822 into main Aug 26, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival/trimmable-typemap-runtime-tests branch August 26, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants