Skip to content

[tests] Use blittable RegisterNatives in JNI callback tests#12019

Merged
simonrozsival merged 2 commits into
mainfrom
dev/simonrozsival/jni-native-method-registration-trimmable-skip
Jul 9, 2026
Merged

[tests] Use blittable RegisterNatives in JNI callback tests#12019
simonrozsival merged 2 commits into
mainfrom
dev/simonrozsival/jni-native-method-registration-trimmable-skip

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Tiny test-only split from #11822.

Instead of disabling the RegisterNativeMethods_JniNativeMethodRegistration* coverage on trimmable NativeAOT, this updates those tests to use the NativeAOT-compatible path:

  • ManagedAdd is now [UnmanagedCallersOnly].
  • The tests register native methods through the blittable RegisterNatives(JniObjectReference, ReadOnlySpan<JniNativeMethod>) overload with raw function pointers.
  • The single-method and >32-method registration cases remain covered without the dynamic-code requirement from JniNativeMethodRegistration[] delegate marshaling.

Testing

  • dotnet test external/Java.Interop/tests/Java.Interop-Tests/Java.Interop-Tests.csproj --filter 'FullyQualifiedName~JniTypeTest.RegisterNativeMethods_JniNativeMethod' could not run in the temporary worktree because Java tool resolution failed before compiling tests (Java.Interop.targets: empty javac command, exit 127).

Notes

Extracted from #11822 to keep the NativeAOT default flip focused.

RegisterNativeMethods_JniNativeMethodRegistration and
RegisterNativeMethods_JniNativeMethodRegistration_ManyMethods exercise the
JniNativeMethodRegistration[] RegisterNatives path, which marshals managed
delegates and requires dynamic code (IL3050) - unsupported under the trimmable
typemap and NativeAOT, where native registration goes through the runtime
registerNatives path instead.

Add [Category ("NativeAOTIgnore")] and [Category ("TrimmableTypeMapUnsupported")]
so TestInstrumentation excludes them on NativeAOT (PublishAot) and trimmable
typemap runs, matching the other unsupported Java.Interop tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 09:14

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 Java.Interop test metadata so two JniNativeMethodRegistration[] RegisterNatives tests can be excluded in NativeAOT/trimmable scenarios where delegate marshaling requires dynamic code and is not supported.

Changes:

  • Add NativeAOTIgnore category to two JniNativeMethodRegistration[] registration tests.
  • Add TrimmableTypeMapUnsupported category to the same tests.
Show a summary per file
File Description
external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniTypeTest.cs Adds NUnit categories to skip the JniNativeMethodRegistration[] registration-path tests under specific runtimes/configurations.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniTypeTest.cs Outdated
Comment thread external/Java.Interop/tests/Java.Interop-Tests/Java.Interop/JniTypeTest.cs Outdated
Keep the RegisterNatives coverage enabled under NativeAOT by switching the affected tests from JniNativeMethodRegistration[] delegate marshaling to the blittable JniNativeMethod span overload with UnmanagedCallersOnly function pointers. This avoids the dynamic-code requirement while preserving the single-method and many-method registration coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival changed the title [tests] Skip JniNativeMethodRegistration tests on trimmable NativeAOT [tests] Use blittable RegisterNatives in JNI callback tests Jul 8, 2026
@simonrozsival simonrozsival added trimmable-type-map ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). labels Jul 8, 2026
@simonrozsival simonrozsival merged commit 71d847c into main Jul 9, 2026
42 checks passed
@simonrozsival simonrozsival deleted the dev/simonrozsival/jni-native-method-registration-trimmable-skip branch July 9, 2026 21:12
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