-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[cDAC] Add infrastructure to run cDAC tests using CLRMD and dumps #124564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,681
−2
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
9e06fe4
add cdac dump-test infrastructure
max-charlamb 20a18ae
centralize debuggee props
max-charlamb 03d470d
add CI pipeline
max-charlamb d06c90f
address comments
max-charlamb 7bf223f
move pipeline inside of runtime-diagnostics
max-charlamb 8295470
comments
max-charlamb eb8ad7d
update yaml for cross-platform dump testing
max-charlamb f19b808
add more tests
max-charlamb 5c06718
refactor skip logic
max-charlamb 0727d57
refactor more
max-charlamb da8011b
update
max-charlamb 7686c17
refactor
max-charlamb b4ad6ee
run stages in parallel
max-charlamb d02012e
Fix cross-platform cDAC dump test artifact download
steveisok b5ba445
Standardize cDAC dump artifacts on tar.gz format
steveisok 3dc06d1
publish test results seperately
max-charlamb c8519a4
Merge branch 'cdac-dumptests' of https://github.com/max-charlamb/runt…
max-charlamb ab80618
add support for running from CI dumps
max-charlamb 3f16942
fix windows paths on unix machines
max-charlamb 06cc2bd
add more platforms
max-charlamb ef9ff5f
address comments
max-charlamb dd69e3c
only build on avaialble ADO queues
max-charlamb 6056ed8
fix cDAC Thread object from requiring the UEWatsonBucketTrackerBucket…
max-charlamb 056af5a
remove more skips
max-charlamb 265d112
add serverGC test
max-charlamb d1f203c
try to fix arm64 build
max-charlamb 642be8b
try using heap dumps
max-charlamb 2bb3bd1
don't use osx_arm64
max-charlamb eb5fb49
change back to full dumps
max-charlamb 1408dc5
fix windows dump generation
max-charlamb c0274ea
update dump collection to allow heap or full
max-charlamb bc60842
temporarily disable osx run for time
max-charlamb 9929328
update dump collection
max-charlamb 6879035
update to allow net10.0 testing
max-charlamb 4151ab4
fix comments
max-charlamb 23b59ee
add docs
max-charlamb 774a1eb
fix stackwalk on .net10.0
max-charlamb 8cbce1a
fail if any job fails
max-charlamb 587bdfe
improve string handling
max-charlamb 46a93dd
handle DisableAuxProviderSignatureCheck more safely
max-charlamb 612897c
remove useless test
max-charlamb 10a0749
update GC tests
max-charlamb 1cfc60b
another round of test cleanup
max-charlamb c2cfa22
update docs
max-charlamb d9837c3
update script to make it more accurate
max-charlamb 35ddc37
WIP convert to Theories
max-charlamb a195e29
simplify
max-charlamb 7401e80
update
max-charlamb de143fd
remove extra file
max-charlamb 8cafdb9
fix
max-charlamb d64f9e2
comments
max-charlamb 060bc13
update readme
max-charlamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/native/managed/cdac/tests/DumpTests/ClrMdDumpHost.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using Microsoft.Diagnostics.Runtime; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.DumpTests; | ||
|
|
||
| /// <summary> | ||
| /// Wraps a ClrMD DataTarget to provide the memory read callback and symbol lookup | ||
| /// needed to create a <see cref="ContractDescriptorTarget"/> from a crash dump. | ||
| /// </summary> | ||
| internal sealed class ClrMdDumpHost : IDisposable | ||
| { | ||
| private static readonly string[] s_runtimeModuleNames = | ||
| { | ||
| "coreclr.dll", | ||
| "libcoreclr.so", | ||
| "libcoreclr.dylib", | ||
| }; | ||
|
|
||
| private readonly DataTarget _dataTarget; | ||
|
|
||
| public string DumpPath { get; } | ||
|
|
||
| private ClrMdDumpHost(string dumpPath, DataTarget dataTarget) | ||
| { | ||
| DumpPath = dumpPath; | ||
| _dataTarget = dataTarget; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Open a crash dump and prepare it for cDAC analysis. | ||
| /// </summary> | ||
| public static ClrMdDumpHost Open(string dumpPath) | ||
| { | ||
| DataTarget dataTarget = DataTarget.LoadDump(dumpPath); | ||
| return new ClrMdDumpHost(dumpPath, dataTarget); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Read memory from the dump at the specified address. | ||
| /// Returns 0 on success, non-zero on failure. | ||
| /// </summary> | ||
| public int ReadFromTarget(ulong address, Span<byte> buffer) | ||
| { | ||
| int bytesRead = _dataTarget.DataReader.Read(address, buffer); | ||
| return bytesRead == buffer.Length ? 0 : -1; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get a thread's register context from the dump. | ||
| /// Returns 0 on success, non-zero on failure. | ||
| /// </summary> | ||
| public int GetThreadContext(uint threadId, uint contextFlags, Span<byte> buffer) | ||
| { | ||
| return _dataTarget.DataReader.GetThreadContext(threadId, contextFlags, buffer) ? 0 : -1; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Locate the DotNetRuntimeContractDescriptor symbol address in the dump. | ||
| /// Uses ClrMD's built-in export resolution which handles PE, ELF, and Mach-O formats. | ||
| /// </summary> | ||
| public ulong FindContractDescriptorAddress() | ||
| { | ||
| foreach (ModuleInfo module in _dataTarget.DataReader.EnumerateModules()) | ||
| { | ||
| string? fileName = module.FileName; | ||
| if (fileName is null) | ||
| continue; | ||
|
|
||
| // Path.GetFileName doesn't handle Windows paths on a Linux/macOS host, | ||
| // so split on both separators to extract the file name correctly when | ||
| // analyzing cross-platform dumps. | ||
| int lastSep = Math.Max(fileName.LastIndexOf('/'), fileName.LastIndexOf('\\')); | ||
| string name = lastSep >= 0 ? fileName[(lastSep + 1)..] : fileName; | ||
| if (!IsRuntimeModule(name)) | ||
| continue; | ||
|
|
||
| ulong address = module.GetExportSymbolAddress("DotNetRuntimeContractDescriptor"); | ||
| if (address != 0) | ||
| return address; | ||
| } | ||
|
|
||
| throw new InvalidOperationException("Could not find DotNetRuntimeContractDescriptor export in any runtime module in the dump."); | ||
| } | ||
|
|
||
| private static bool IsRuntimeModule(string fileName) | ||
| { | ||
| foreach (string name in s_runtimeModuleNames) | ||
| { | ||
| if (fileName.Equals(name, StringComparison.OrdinalIgnoreCase)) | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _dataTarget.Dispose(); | ||
| } | ||
max-charlamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
2 changes: 2 additions & 0 deletions
2
src/native/managed/cdac/tests/DumpTests/Debuggees/BasicThreads/BasicThreads.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| </Project> |
56 changes: 56 additions & 0 deletions
56
src/native/managed/cdac/tests/DumpTests/Debuggees/BasicThreads/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
|
|
||
| /// <summary> | ||
| /// Debuggee app for cDAC dump tests. | ||
| /// Spawns threads with known names, ensures they are all alive, then crashes | ||
| /// so a dump is produced for analysis. | ||
| /// </summary> | ||
| internal static class Program | ||
| { | ||
| // These constants are referenced by ThreadDumpTests to assert expected values. | ||
| public const int SpawnedThreadCount = 5; | ||
| public static readonly string[] ThreadNames = new[] | ||
| { | ||
| "cdac-test-thread-0", | ||
| "cdac-test-thread-1", | ||
| "cdac-test-thread-2", | ||
| "cdac-test-thread-3", | ||
| "cdac-test-thread-4", | ||
| }; | ||
|
|
||
| private static void Main() | ||
| { | ||
| // Barrier ensures all threads are alive and named before we crash. | ||
| // participantCount = SpawnedThreadCount + 1 (main thread) | ||
| using Barrier barrier = new(SpawnedThreadCount + 1); | ||
|
|
||
| Thread[] threads = new Thread[SpawnedThreadCount]; | ||
| for (int i = 0; i < SpawnedThreadCount; i++) | ||
| { | ||
| int index = i; | ||
| threads[i] = new Thread(() => | ||
| { | ||
| // Signal that this thread is alive and wait for all others. | ||
| barrier.SignalAndWait(); | ||
|
|
||
| // Keep the thread alive until the process crashes. | ||
| Thread.Sleep(Timeout.Infinite); | ||
| }) | ||
| { | ||
| Name = ThreadNames[index], | ||
| IsBackground = true, | ||
| }; | ||
| threads[i].Start(); | ||
| } | ||
|
|
||
| // Wait until all spawned threads have reached the barrier. | ||
| barrier.SignalAndWait(); | ||
|
|
||
| // All threads are alive and named. Crash to produce a dump. | ||
| Environment.FailFast("cDAC dump test: BasicThreads debuggee intentional crash"); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/native/managed/cdac/tests/DumpTests/Debuggees/Directory.Build.props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project> | ||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFrameworks>$(NetCoreAppToolCurrent);net10.0</TargetFrameworks> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
| <Nullable>enable</Nullable> | ||
| <OutputPath>$(ArtifactsBinDir)DumpTests\$(MSBuildProjectName)\$(Configuration)\</OutputPath> | ||
| <AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath> | ||
| <!-- Debuggees intentionally use unsealed types for type hierarchy testing --> | ||
| <NoWarn>$(NoWarn);CA1852</NoWarn> | ||
| <!-- Default dump type for dump generation. Override per-debuggee csproj as needed. | ||
| Supported values: "Heap", "Full", or "Heap;Full" for both. --> | ||
| <DumpTypes Condition="'$(DumpTypes)' == ''">Heap</DumpTypes> | ||
| </PropertyGroup> | ||
| </Project> |
11 changes: 11 additions & 0 deletions
11
src/native/managed/cdac/tests/DumpTests/Debuggees/Directory.Build.targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <Project> | ||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)..\'))" /> | ||
|
|
||
| <!-- Target invoked by GenerateAllDumps (from DumpTests.targets) on each debuggee csproj | ||
| to extract the DumpTypes property. Returns the project name with DumpTypes metadata. --> | ||
| <Target Name="GetDumpTypes" Returns="@(_DumpTypeOutput)"> | ||
| <ItemGroup> | ||
| <_DumpTypeOutput Include="$(MSBuildProjectName)" DumpTypes="$(DumpTypes)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
| </Project> |
2 changes: 2 additions & 0 deletions
2
src/native/managed/cdac/tests/DumpTests/Debuggees/GCRoots/GCRoots.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| </Project> |
48 changes: 48 additions & 0 deletions
48
src/native/managed/cdac/tests/DumpTests/Debuggees/GCRoots/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| /// <summary> | ||
| /// Debuggee for cDAC dump tests — exercises the Object and GC contracts. | ||
| /// Pins objects, creates GC handles, then crashes. | ||
| /// </summary> | ||
| internal static class Program | ||
| { | ||
| public const int PinnedObjectCount = 5; | ||
| public const string TestStringValue = "cDAC-GCRoots-test-string"; | ||
|
|
||
| private static void Main() | ||
| { | ||
| // Allocate objects of various types | ||
| string testString = TestStringValue; | ||
| byte[] byteArray = new byte[1024]; | ||
| object boxedInt = 42; | ||
|
|
||
| // Create pinned handles | ||
| GCHandle[] pinnedHandles = new GCHandle[PinnedObjectCount]; | ||
| byte[][] pinnedArrays = new byte[PinnedObjectCount][]; | ||
|
|
||
| for (int i = 0; i < PinnedObjectCount; i++) | ||
| { | ||
| pinnedArrays[i] = new byte[64]; | ||
| pinnedHandles[i] = GCHandle.Alloc(pinnedArrays[i], GCHandleType.Pinned); | ||
| } | ||
|
|
||
| // Create weak and strong handles | ||
| var weakRef = new WeakReference(new object()); | ||
| var strongHandle = GCHandle.Alloc(testString, GCHandleType.Normal); | ||
|
|
||
| // Keep references alive | ||
| GC.KeepAlive(testString); | ||
| GC.KeepAlive(byteArray); | ||
| GC.KeepAlive(boxedInt); | ||
| GC.KeepAlive(pinnedHandles); | ||
| GC.KeepAlive(pinnedArrays); | ||
| GC.KeepAlive(weakRef); | ||
| GC.KeepAlive(strongHandle); | ||
|
|
||
| Environment.FailFast("cDAC dump test: GCRoots debuggee intentional crash"); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.