Skip to content

Add deterministic NativeAOT regression smoke test for GC restricted reverse P/Invoke assert path#130459

Draft
MichalStrehovsky with Copilot wants to merge 2 commits into
mainfrom
copilot/create-focused-regression-test-issue-110683
Draft

Add deterministic NativeAOT regression smoke test for GC restricted reverse P/Invoke assert path#130459
MichalStrehovsky with Copilot wants to merge 2 commits into
mainfrom
copilot/create-focused-regression-test-issue-110683

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This adds a focused NativeAOT regression test for the GC restricted callout path where background GC can invoke managed [UnmanagedCallersOnly] callbacks and hit Thread::InlineTryFastReversePInvoke assertion behavior prior to the runtime fix. The change is test-only and is intended to reliably drive the failing pre-fix path, not modify product behavior.

  • Test added

    • src/tests/nativeaot/SmokeTests/GcRestrictedCalloutReversePInvoke/
    • New smoke test project plus program harness.
  • Repro wiring

    • Registers tracker support via ComWrappers.RegisterForTrackerSupport(...).
    • Creates a tracker object through MockReferenceTrackerRuntime so GC restricted tracker callbacks are active (GCStopCollection path).
  • Deterministic triggering

    • Forces repeated concurrent Gen2 collections (GC.Collect(..., blocking:false)).
    • Runs bounded allocation pressure on a background thread.
    • Uses timeout + synchronization (SpinWait + elapsed bound) instead of unbounded probabilistic loops.
  • Scope/guards

    • Configured as process-isolated NativeAOT smoke test.
    • Excludes Apple mobile and Android targets where the required native dependency is not available in this leg.
    • Keeps coverage broad otherwise (not win-x86-only).
  • Expectation documented

    • Source comment references dotnet/runtime#110683 and states expected behavior:
      • release: test should complete,
      • assertion-enabled runtime (before product fix): can fail on the target assertion path.
  • Environment limitation observed while validating command

    • In this environment, Release NativeAOT targeted test build failed due to missing Microsoft.DotNet.ILCompiler.SingleEntry.targets; Checked configuration was used for targeted execution.
GC.Collect(2, GCCollectionMode.Forced, blocking: false, compacting: false);

if (GC.GetGCMemoryInfo().Generation == 2 &&
    GC.GetGCMemoryInfo().Concurrent)
{
    // Concurrent Gen2 observed while tracker GC callbacks are registered.
    // This is the targeted repro envelope for dotnet/runtime#110683.
}

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 10, 2026 03:33
Copilot AI changed the title [WIP] Add regression test for NativeAOT runtime assertion failure Add deterministic NativeAOT regression smoke test for GC restricted reverse P/Invoke assert path Jul 10, 2026
Copilot AI requested a review from MichalStrehovsky July 10, 2026 03:38
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants