Skip to content

[Tests] Add NativeCrashProducesManagedStackTrace device test#11338

Merged
jonathanpeppers merged 3 commits into
mainfrom
jonathanpeppers/crash-reporting-device-test
May 15, 2026
Merged

[Tests] Add NativeCrashProducesManagedStackTrace device test#11338
jonathanpeppers merged 3 commits into
mainfrom
jonathanpeppers/crash-reporting-device-test

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

Context: #11291

Adds an MSBuildDeviceIntegration test that verifies the System.Runtime.CrashReportBeforeSignalChaining config option works end-to-end on CoreCLR.

The test:

  1. Builds a Release CoreCLR app that P/Invokes libc memset(NULL, 0, 1) to trigger a native SIGSEGV
  2. Monitors logcat for the DOTNET tag containing the managed method name (ForceNativeSegfault) in the crash reporting stack trace

This validates that the .NET runtime logs managed stack frames before Android's signal handler aborts the process, as enabled by dotnet/runtime#123735.

Adds an MSBuildDeviceIntegration test that verifies the
System.Runtime.CrashReportBeforeSignalChaining config option works
end-to-end on CoreCLR. The test builds a Release app that triggers
a native SIGSEGV via P/Invoke to libc memset(NULL), then checks
logcat for the managed stack trace logged by the DOTNET tag before
Android's signal handler takes over.

See: #11291
See: dotnet/runtime#123735

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment on lines +824 to +834
// CoreCLR logs the managed stack trace via the DOTNET logcat tag when crash reporting
// runs before signal chaining. The stack trace JSON includes method names like
// "ForceNativeSegfault" from the managed frames leading up to the crash.
string logcatFile = Path.Combine (Root, builder.ProjectDirectory, "crash-logcat.log");
Assert.IsTrue (
MonitorAdbLogcat (
(line) => line.Contains ("DOTNET") && line.Contains ("ForceNativeSegfault"),
logcatFilePath: logcatFile,
timeout: 30),
"Crash reporting should have logged a managed stack trace containing 'ForceNativeSegfault' via the DOTNET logcat tag. " +
"Verify the System.Runtime.CrashReportBeforeSignalChaining config option is set and the runtime supports it.");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

New test passed:

Image

@mdh1418 is there anything else here we should be asserting?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure, I suppose if there's anything else that is critical for diagnosing how the crash occurred? I suppose you could check for native crashes what the signal was. See the Sigsegv example in dotnet/runtime#123824.

That said, CrashReportBeforeSignalChaining was merged (2/13) before managed callstacks logging was merged (2/18), so as long as this test doesn't run on a version of the runtime that is between those two it should work.

For what it's worth, this config option also guards the inproc crash reporter's json file added by dotnet/runtime#126916, which is in progress to be added to logcat in dotnet/runtime#128105

@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 13, 2026 19:16
@jonathanpeppers jonathanpeppers added ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). labels May 13, 2026
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 a new MSBuildDeviceIntegration device test to validate CoreCLR’s end-to-end native-crash reporting behavior on Android, specifically that managed frames are logged to logcat before Android’s signal handler aborts the process (via System.Runtime.CrashReportBeforeSignalChaining).

Changes:

  • Add NativeCrashProducesManagedStackTrace device test that builds/installs a Release CoreCLR app and triggers a native SIGSEGV via P/Invoke.
  • Monitor adb logcat for DOTNET output containing a known managed frame name (ForceNativeSegfault) to prove managed stack frames are emitted before signal chaining.

Comment thread tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Comment thread tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Comment thread tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
jonathanpeppers and others added 2 commits May 14, 2026 08:44
- Assert that logcat contains both SIGSEGV signal and ForceNativeSegfault
  managed frame from the DOTNET tag
- Add reference to dotnet/runtime#123824 which implements the managed
  callstack logging

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers merged commit 0d99c4e into main May 15, 2026
3 checks passed
@jonathanpeppers jonathanpeppers deleted the jonathanpeppers/crash-reporting-device-test branch May 15, 2026 13:56
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).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants