Skip to content

Add new SOS test harness - #5979

Merged
steveisok merged 11 commits into
dotnet:mainfrom
max-charlamb:max-charlamb/sos-testing
Sep 2, 2026
Merged

steveisok merged 11 commits into
dotnet:mainfrom
max-charlamb:max-charlamb/sos-testing

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add a consolidated, cross-host SOS test harness covering CDB, dotnet-dump, and LLDB
  • exercise dump and live targets across runtime versions, deployment flavors, and DAC modes
  • isolate dbgeng and dump capture in helper processes with replay artifacts for failures
  • disable W^X for live EngineHost debuggees so bpmd can patch JIT code safely
  • restore Unix executable permissions after pipeline artifact transfer for the MTP runner and debuggee apphosts

This branch is based on Lee Culver's leculver/sos-testing work and is opened as a draft to inspect and review the complete diff.

Validation

  • dotnet build src\tests\SOS.Tests\SOS.Tests.csproj --no-restore --configuration Debug
  • SOS.Tests.exe --filter-method SOS.Tests.GcWhereTests.GcWhere_Moves --parallel none: 24 passed

Follow-up

  • prebuild SingleFile debuggees for CI instead of publishing them during test execution

@max-charlamb max-charlamb changed the title Add cross-host SOS test harness Add new SOS test harness Aug 25, 2026
leculver and others added 7 commits August 25, 2026 16:54
Add a marker-driven scenario process that exposes managed stacks, heap shapes, exceptions, delegates, synchronization state, and crash points for SOS command validation across runtime versions and deployment modes.

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

Copilot-Session: 2bba76c7-c3b4-4774-84d5-6d21347e8ef8
Add reusable target acquisition, dump capture, debugger-host abstractions, matrix configuration, SOS output parsing, replay diagnostics, and source generation for marker constants used by command tests.

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

Copilot-Session: 2bba76c7-c3b4-4774-84d5-6d21347e8ef8
Run dbgeng command execution and dump capture in helper processes so debugger failures remain isolated from the xUnit test host and architecture-specific binaries are resolved correctly.

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

Copilot-Session: 2bba76c7-c3b4-4774-84d5-6d21347e8ef8
Add xUnit v3 command coverage for stacks, threads, heaps, objects, modules, runtime state, and diagnostic commands across supported hosts, deployment flavors, dump kinds, GC modes, runtimes, and DAC implementations. Include failure replay output and a local execution runbook.

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

Copilot-Session: 2bba76c7-c3b4-4774-84d5-6d21347e8ef8
Include the harness library, source generator, debugger helper hosts, and SOS.Tests project in build.sln for IDE discovery and repository builds.

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

Copilot-Session: 2bba76c7-c3b4-4774-84d5-6d21347e8ef8
Disable W^X for live debuggees so bpmd can patch JIT code without triggering access violations.

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

Copilot-Session: 2d5c60f7-9c89-42e6-b9fc-04ef78c8f8d8
Pipeline artifact transfer drops executable bits. Restore them before running the MTP test apphost or launching debuggee apphosts.

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

Copilot-Session: 2d5c60f7-9c89-42e6-b9fc-04ef78c8f8d8
@max-charlamb
max-charlamb force-pushed the max-charlamb/sos-testing branch from 9041f9b to 620c347 Compare August 25, 2026 20:59
Max Charlamb and others added 2 commits August 25, 2026 17:13
Use Arcade's TestToRun command path directly because UseAppHost metadata is not populated for the MTP executable.

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

Copilot-Session: 2d5c60f7-9c89-42e6-b9fc-04ef78c8f8d8
Publish version-matched single-file debuggees during the build and make the test harness consume the transferred immutable outputs instead of invoking dotnet publish during tests.

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

Copilot-Session: 886d87aa-631a-49cd-a973-aacd17a1df81

@noahfalk noahfalk left a comment

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.

The shape of this seems reasonable to me and if we want to make some adjustments that seems easier to do after we've gotten a little experience and we can make targetted diffs rather than trying tweak this giant PR. I think the main thing we should do before committing this is:

  1. Make a little audit confirming the new testing appears to cover the same (or more) coverage than before
  2. Add a small design/usage document that describes how the harness works, how it is run, what a canonical test case looks like and what canonical test output/test artifacts get generated.
  3. Test the tests by having a new copilot session select at random 5 places where a buggy change in SOS is deliberately inserted. Then confirm that the new tests are at least as good at catching those issues as the previous ones.

Add the legacy-to-new coverage map, mutation experiment results, harness architecture and usage guidance, and focused dumpgen argument/filter coverage.

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

Copy link
Copy Markdown
Member

The shape of this seems reasonable to me and if we want to make some adjustments that seems easier to do after we've gotten a little experience and we can make targetted diffs rather than trying tweak this giant PR. I think the main thing we should do before committing this is:

  1. Make a little audit confirming the new testing appears to cover the same (or more) coverage than before
  2. Add a small design/usage document that describes how the harness works, how it is run, what a canonical test case looks like and what canonical test output/test artifacts get generated.
  3. Test the tests by having a new copilot session select at random 5 places where a buggy change in SOS is deliberately inserted. Then confirm that the new tests are at least as good at catching those issues as the previous ones.

Pushed a commit with what you asked for. Once we get this in I'll start integrating pieces of what I have in my helix PR.

@steveisok
steveisok marked this pull request as ready for review September 2, 2026 00:11
@steveisok
steveisok requested a review from a team as a code owner September 2, 2026 00:11
Copilot AI lite review requested due to automatic review settings September 2, 2026 00:11

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.

🟡 Changes recommended

There is at least one confirmed correctness risk in the new debuggee snapshot helper (possible deadlock when redirecting process output) that should be addressed before merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR introduces a new consolidated SOS test harness and a large set of SOS command tests that run across multiple debugger hosts (cdb/dbgeng, dotnet-dump, lldb) and target flavors (framework-dependent, single-file, and desktop .NET Framework), including both dump-backed and live-debugging scenarios.

Changes:

  • Add a new SOS.TestHarness library plus helper executables (EngineHost/Capturer) to drive hosts, capture/record replay context, and manage host lifetime constraints.
  • Add a new SOS.Tests xUnit v3 test suite with broad SOS command coverage and matrix helpers for host/flavor/runtime/dump-kind/DAC combinations.
  • Update debuggee build/publish infrastructure to support single-file publish outputs and runtime version stamping for DAC resolution.
File summaries
File Description
src/tests/SOS.UnitTests/Debuggees/SosHarnessScenarios/TestHarness.cs Adds a marker debuggee helper that no-ops in live mode and self-snapshots via dotnet-dump in capture mode.
src/tests/SOS.UnitTests/Debuggees/SosHarnessScenarios/SosHarnessScenarios.csproj New scenarios debuggee project used by the SOS harness test matrix.
src/tests/SOS.UnitTests/Debuggees/Directory.Build.props Writes a runtime.version file into publish outputs to carry pinned runtime patch info.
src/tests/SOS.Tests/WindowsTheoryAttribute.cs Adds a Windows-only theory attribute to avoid “empty data” failures on non-Windows for cdb-only matrices.
src/tests/SOS.Tests/TestObjectHelpers.cs Adds shared helper(s) for locating exact heap objects used by multiple tests.
src/tests/SOS.Tests/TestMatrices.cs Adds reusable matrix builders/filters for known dump/runtime/DAC limitations.
src/tests/SOS.Tests/StackInspectionTests.cs Adds tests for stack-inspection commands across hosts (including Windows-only dbgeng stackwalk cases).
src/tests/SOS.Tests/SpecializedInspectionTests.cs Adds tests for SOS commands that require specific staged runtime state in the debuggee.
src/tests/SOS.Tests/SosTheoryAttribute.cs Adds a cross-platform theory attribute intended to keep empty-matrix cases as failures.
src/tests/SOS.Tests/SOS.Tests.csproj Introduces the new SOS test project and its source-generator wiring and Unix exec-bit fixup for MTP runner.
src/tests/SOS.Tests/RuntimeInfoTests.cs Adds tests for runtime/module/process listing commands (eeversion, modules, runtimes, etc.).
src/tests/SOS.Tests/PrintExceptionTests.cs Adds cross-host/flavor tests for printexception on a nested-exception crash dump.
src/tests/SOS.Tests/ObjectGcHelperTests.cs Adds tests for per-object GC helper commands (dumpobjgcrefs, pathto, dumpalc, etc.).
src/tests/SOS.Tests/ObjectFieldsTests.cs Adds tests validating dumpobj/dumpvc field decoding against debuggee-oracle values.
src/tests/SOS.Tests/NativeAddressSpaceTests.cs Adds coverage for notreachableinrange under dotnet-dump.
src/tests/SOS.Tests/ModuleResolveTests.cs Adds round-trip tests for name/token resolution (name2ee, token2ee).
src/tests/SOS.Tests/MiscCommandTests.cs Adds smoke coverage for session/diagnostic commands (dbgout, sosflush, enummem gating).
src/tests/SOS.Tests/MemoryAndDecodeTests.cs Adds tests for REPL memory dumpers and state decoders (threadstate/taskstate/dumpexceptions).
src/tests/SOS.Tests/LiveBpmdTests.cs Adds a live-debugging test that validates raw bpmd breakpoint mechanics.
src/tests/SOS.Tests/HeapAnalysisTests.cs Adds tests for heap-wide analysis commands (sizestats, traverseheap, ephrefs).
src/tests/SOS.Tests/GcWhereTests.cs Adds tests for gcwhere including a live generation-promotion scenario.
src/tests/SOS.Tests/EeHeapTests.cs Adds structural tests for eeheap -gc parsing including server-GC multi-heap coverage.
src/tests/SOS.Tests/DumpSigTests.cs Adds combined smoke tests for signature decoding commands (dumpsig, dumpsigelem).
src/tests/SOS.Tests/DumpModuleTests.cs Adds tests for dumpmodule structure and -mt type table correctness.
src/tests/SOS.Tests/DumpIlTests.cs Adds IL decoding tests for dumpil including pointer-based decode variant.
src/tests/SOS.Tests/DumpHeapThinLockTests.cs Adds tests for dumpheap -thinlock using a staged thin-lock debuggee object.
src/tests/SOS.Tests/DumpHeapStringsTests.cs Adds content-based tests for dumpheap -strings and -strings -stat.
src/tests/SOS.Tests/DumpHeapObjectsTests.cs Adds tests for dumpheap listing/statistics and selection flags (-stat/-type/-mt/-min/-max).
src/tests/SOS.Tests/DumpHeapLiveDeadTests.cs Adds tests for dumpheap -live/-dead partitioning correctness.
src/tests/SOS.Tests/DumpHeapGenerationsTests.cs Adds tests for dumpheap generation/segment/heap selection validated against eeheap ranges.
src/tests/SOS.Tests/DumpDomainTests.cs Adds tests for dumpdomain/dumpassembly including runtime-shape differences.
src/tests/SOS.Tests/DumpDelegateTests.cs Adds tests for delegate decoding (dumpdelegate) on known staged delegates.
src/tests/SOS.Tests/DumpArrayTests.cs Adds tests for dumparray parameters and documented edge cases.
src/tests/SOS.Tests/DiagnosticCommandTests.cs Adds tests for diagnostic/status commands including clrma host constraints.
src/tests/SOS.Tests/CollectionQueueTests.cs Adds tests for concurrent-collection dumpers (dcq, threadpoolqueue).
src/tests/SOS.Tests/CodeInfoTests.cs Adds tests for ehinfo/gcinfo including dump-kind selection where required.
src/tests/SOS.Tests/ClrUTests.cs Adds Windows-only cdb tests for !clru shape and interleaving options.
src/tests/SOS.Tests/ClrThreadsTests.cs Adds cross-matrix tests for clrthreads including parser validation.
src/tests/SOS.Tests/ClrThreadsParsing.cs Adds a dedicated parser for the clrthreads table’s atypical header/layout.
src/tests/SOS.Tests/ClrStackLinesTests.cs Adds tests asserting source line behavior in clrstack and suppression with -n.
src/tests/SOS.Tests/ClrStackICorDebugTests.cs Adds tests for experimental clrstack -i and variable decoding (-i -a).
src/tests/SOS.Tests/ClrStackFullTests.cs Adds tests for clrstack -f with cross-variant self-consistency checks.
src/tests/SOS.Tests/ClrStackFrameCountTests.cs Adds tests for clrstack -c frame limiting semantics.
src/tests/SOS.Tests/ClrStackArgsLocalsTests.cs Adds tests for clrstack -p/-l/-a with value and oracle cross-checks.
src/tests/SOS.Tests/ClrStackAllThreadsTests.cs Adds tests for clrstack -all with deterministic worker-thread staging.
src/tests/SOS.TestHarness/Targets.cs Adds memoized dump-session resolution and global teardown for shared hosts/sessions.
src/tests/SOS.TestHarness/Target.cs Adds the unified Target abstraction plus replay recording hooks for navigation/commands.
src/tests/SOS.TestHarness/SosToken.cs Adds tokenized matching/parsing for nondeterministic SOS output values.
src/tests/SOS.TestHarness/SosTable.cs Adds a fixed-width SOS table parser plus rich assertion helpers.
src/tests/SOS.TestHarness/SosRow.cs Adds row model supporting extra scalar columns and structured attached data.
src/tests/SOS.TestHarness/SosDataRowExtensions.cs Adds assertion helpers for structured “internal data” record sets.
src/tests/SOS.TestHarness/SosDataRow.cs Adds structured sub-record model used by table data extractors.
src/tests/SOS.TestHarness/SosDataExtractor.cs Adds delegate contract for consuming “internal data” lines during parsing.
src/tests/SOS.TestHarness/SosConvert.cs Adds shared numeric/boolean converters tied to tokens and rich failure context.
src/tests/SOS.TestHarness/SosColumn.cs Adds column-spec model including alignment and optional per-column validation token.
src/tests/SOS.TestHarness/SosCell.cs Adds typed parsing helpers and consistent failure messages for cell values.
src/tests/SOS.TestHarness/SosAssertException.cs Adds a rich assertion exception that includes command/host/output context.
src/tests/SOS.TestHarness/SOS.TestHarness.csproj Introduces the harness library project and its dependencies (DbgEng utilities, xUnit v3 core).
src/tests/SOS.TestHarness/ReplayContext.cs Adds per-test replay capture (commands/navigations/host diagnostics) for failure artifacts.
src/tests/SOS.TestHarness/lldbhelper.py Adds an LLDB scripting helper to provide reliable per-command framing and success status.
src/tests/SOS.TestHarness/LldbCliHost.cs Adds the dump-backed LLDB host implementation and DAC selection wiring.
src/tests/SOS.TestHarness/Liveness.cs Adds the dump vs live axis used by the test matrix.
src/tests/SOS.TestHarness/ILiveDebuggerHost.cs Adds the interface contract for live, advancing debugger hosts.
src/tests/SOS.TestHarness/IDiagnosticHost.cs Adds optional diagnostics-capture capability surface for child-process hosts.
src/tests/SOS.TestHarness/IDebuggerHost.cs Adds the base host abstraction for SOS + raw debugger command execution.
src/tests/SOS.TestHarness/HostSlot.cs Adds single-slot pooling/eviction mechanics for resource-constrained host backends.
src/tests/SOS.TestHarness/Hosts.cs Adds the host axis enum (cdb/lldb/dotnet-dump) for matrix expansion.
src/tests/SOS.TestHarness/HostFactory.cs Adds backend selection for dump and live hosts, including DAC-dir overrides.
src/tests/SOS.TestHarness/HarnessSkip.cs Adds a harness-level dynamic skip mechanism for intrinsic host/flavor limitations.
src/tests/SOS.TestHarness/HarnessCancellation.cs Bridges runner cancellation into blocking host waits for responsive Ctrl+C behavior.
src/tests/SOS.TestHarness/GcType.cs Adds the workstation vs server GC axis for capture/launch and layout coverage.
src/tests/SOS.TestHarness/Flavor.cs Adds the Core/SingleFile/Framework flavor axis used across targets and hosts.
src/tests/SOS.TestHarness/EngineProtocol.cs Adds the command framing protocol for the dbgeng EngineHost child process.
src/tests/SOS.TestHarness/DumpKind.cs Adds dump-kind axis (Heap/Mini/Full) for reduced-dump behavior coverage.
src/tests/SOS.TestHarness/DumpGenerationRequirements.cs Adds Windows reduced-dump prerequisite handling and fallback/skip behavior.
src/tests/SOS.TestHarness/DeadTarget.cs Adds a dump-backed cursor target that resolves memoized DumpSessions on navigation.
src/tests/SOS.TestHarness/DbgEngDumpHost.cs Adds an in-process dbgeng dump host implementation.
src/tests/SOS.TestHarness/DbgEngCapturer.cs Adds dbgeng-based dump capture for flavors that can’t self-collect.
src/tests/SOS.TestHarness/DacPolicy.cs Adds the DAC selection policy including an environment-variable clamp.
src/tests/SOS.TestHarness/Dac.cs Adds the legacy vs cDAC axis and its validity constraints (net11+).
src/tests/SOS.TestHarness/CoreVersion.cs Adds the core runtime version axis used to fan out builds/installs and disable versions.
src/tests/SOS.TestHarness/CaptureCli.cs Adds the Capturer CLI entrypoint for out-of-process dump capture.
src/tests/SOS.TestHarness.SourceGen/SOS.TestHarness.SourceGen.csproj Introduces the source generator project for mirroring debuggee constants into tests.
src/tests/SOS.TestHarness.SourceGen/MirrorGenerator.cs Implements the incremental source generator for compile-time “oracle” constants.
src/tests/SOS.TestHarness.EngineHost/SOS.TestHarness.EngineHost.csproj Introduces the dbgeng EngineHost child process project.
src/tests/SOS.TestHarness.EngineHost/Program.cs Implements the EngineHost stdin/stdout REPL for dump/live dbgeng operations.
src/tests/SOS.TestHarness.Capturer/SOS.TestHarness.Capturer.csproj Introduces the Capturer helper executable project.
src/tests/SOS.TestHarness.Capturer/Program.cs Wires the Capturer exe entrypoint to the capture CLI.
src/tests/Debuggees.proj Adds a post-build publish step to produce single-file SOS debuggees for the harness to consume.
Review details
  • Files reviewed: 120/120 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/tests/SOS.Tests/TestObjectHelpers.cs Outdated

@hoyosjs hoyosjs left a comment

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.

the stdin/out feedback is fair. The document is a little verbose, but a fair documentation of the env vars and the example summarizes most of the needed info anyway

@noahfalk noahfalk left a comment •

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.

👍

The copilot review comment about deadlocks redirecting output should probably be addressed.

Drain dotnet-dump output concurrently and preserve the first-object helper semantics while improving empty-result diagnostics.

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

Copilot-Session: a51fef8d-7fe5-4093-910c-a21184eb8123
@steveisok

Copy link
Copy Markdown
Member

/ba-g known issues #5996 and #5997

@steveisok
steveisok merged commit bf833ee into dotnet:main Sep 2, 2026
17 of 26 checks passed
steveisok added a commit that referenced this pull request Sep 4, 2026
steveisok added a commit that referenced this pull request Sep 4, 2026
## Summary

- Restores the complete reviewed SOS test harness from
[#5979](#5979) after its exact
revert in [#6006](#6006).
- Re-establishes this change as the new bottom layer beneath
[#5999](#5999),
[#6000](#6000),
[#6001](#6001), and
[#6002](#6002).
- Temporarily excludes only `SOS.Tests` from local CI via `SkipTests`
when `ContinuousIntegrationBuild` is true. Normal local builds and
discovery remain enabled until the upper Helix layer moves execution out
of local CI.

## Reconstruction proof

- The baseline restoration commit
`2c7616acc2be6b20cf377574fa52e40196f16ca7` has tree
`5d2ab7a6990a8cdc2ff8a3d2ec7a29e373b99d54`, exactly matching the
pre-revert commit `ec5af2a1a56c4d9348e7e92438bb2faf8684f15f`.
- The only subsequent delta is five added lines in
`src/tests/SOS.Tests/SOS.Tests.csproj` for the temporary CI-only skip.

## Validation

- `./dotnet.sh build src/tests/SOS.Tests/SOS.Tests.csproj --no-restore
--verbosity minimal` — succeeds with 0 warnings and 0 errors.
- Focused Microsoft.Testing.Platform discovery for
`SOS.Tests.PrintExceptionTests.PrintException_Data` with
DotnetDump/Core/net10 constraints — 2 expected rows discovered without
`ContinuousIntegrationBuild`.
- MSBuild property evaluation: default `SkipTests` is empty;
`-p:ContinuousIntegrationBuild=true` evaluates `SkipTests=true`.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c34cd9f4-d3b5-4b46-b7fc-e34b34bc88c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants