[Tests] Add NativeCrashProducesManagedStackTrace device test#11338
Conversation
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>
| // 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."); |
There was a problem hiding this comment.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
NativeCrashProducesManagedStackTracedevice test that builds/installs a Release CoreCLR app and triggers a native SIGSEGV via P/Invoke. - Monitor
adb logcatforDOTNEToutput containing a known managed frame name (ForceNativeSegfault) to prove managed stack frames are emitted before signal chaining.
…-reporting-device-test
- 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>

Context: #11291
Adds an MSBuildDeviceIntegration test that verifies the
System.Runtime.CrashReportBeforeSignalChainingconfig option works end-to-end on CoreCLR.The test:
libc memset(NULL, 0, 1)to trigger a native SIGSEGVDOTNETtag containing the managed method name (ForceNativeSegfault) in the crash reporting stack traceThis validates that the .NET runtime logs managed stack frames before Android's signal handler aborts the process, as enabled by dotnet/runtime#123735.