Skip to content

Split mock CDAC types into test helper assembly#125827

Open
hoyosjs wants to merge 3 commits intodotnet:mainfrom
hoyosjs:juhoyosa/split-mock-types
Open

Split mock CDAC types into test helper assembly#125827
hoyosjs wants to merge 3 commits intodotnet:mainfrom
hoyosjs:juhoyosa/split-mock-types

Conversation

@hoyosjs
Copy link
Member

@hoyosjs hoyosjs commented Mar 20, 2026

This pull request introduces a new test utility package, refactors the test project structure, and updates references throughout the codebase to support using the test infrastructure in other diagnostic testing. It introduces Microsoft.Diagnostics.Internal.RuntimeMemoryMocks helper assembly and package it as a transport package assembly

Copilot AI review requested due to automatic review settings March 20, 2026 11:06
@hoyosjs hoyosjs requested a review from a team March 20, 2026 11:06
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copy link
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

This PR factors the cDAC test-only mock target/memory/descriptor infrastructure into a new reusable helper assembly (Microsoft.Diagnostics.Internal.RuntimeMemoryMocks), updates the existing DataContractReader test project to consume it, and adds/expands unit tests for several contract/helper components.

Changes:

  • Introduces a new packable helper project (Microsoft.Diagnostics.Internal.RuntimeMemoryMocks) and moves mock target/memory/descriptor types into its own namespace.
  • Updates Microsoft.Diagnostics.DataContractReader.Tests project structure and references to use the new helper assembly.
  • Adds new/expanded tests covering contract descriptor parsing, platform context register access, Hot/Cold lookup, and printf stress message formatting.

Reviewed changes

Copilot reviewed 52 out of 57 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/TestPlaceholderTarget.cs Moves mock Target implementation into new helper namespace and makes it reusable.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/TargetTestHelpers.cs Exposes target layout/write helpers from the helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockTarget.cs Moves mock architecture helpers into the new helper namespace.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockMemorySpace.cs Moves mock memory space builder/context into helper assembly and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockMemorySpace.BumpAllocator.cs Moves bump allocator into helper assembly and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.cs Makes mock descriptor root type public in the helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.Thread.cs Moves thread mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.SyncBlock.cs Moves sync block mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.RuntimeTypeSystem.cs Moves RTS mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.RuntimeFunctions.cs Moves runtime function mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.ReJIT.cs Moves ReJIT mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.Object.cs Moves object mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.MethodDescriptors.cs Moves method descriptor mocks into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.Loader.cs Moves loader mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.HashMap.cs Moves hash map mock descriptors into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.GC.cs Moves GC heap builder/mocks into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.ExecutionManager.cs Moves ExecutionManager mocks into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.CodeVersions.cs Moves code version mocks into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/ExecutionManager/NibbleMapTestBuilder.cs Moves nibble map test builders into helper namespace and updates visibility.
src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks.csproj Adds new packable helper project for distributing test mocks.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/Microsoft.Diagnostics.DataContractReader.Tests.csproj Updates test project layout/import paths and references the new helper project.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/TypeDescTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ThreadTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/SyncBlockTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/SOSDacInterface8Tests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/RuntimeInfoTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ReJITTests.cs Updates aliases/imports to reference mocks from the helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/PrecodeStubsTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ObjectTests.cs Updates aliases/imports to reference mocks from the helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/MethodTableTests.cs Updates aliases/imports to reference mocks from the helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/MethodDescTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/LoaderTests.cs Updates aliases/imports to reference mocks from the helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/GetRegisterNameTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/GCTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/DacStreamsTests.cs Updates test imports to use the new helper assembly and normalizes header.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ExecutionManager/ExecutionManagerTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ExecutionManager/HashMapTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ExecutionManager/NibbleMapTests.cs Updates test imports to use the new helper assembly and moved builders.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ExecutionManager/RangeSectionMapTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ExecutionManager/RuntimeFunctionTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ExecutionManager/HotColdLookupTests.cs Adds unit tests for HotColdLookup.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ContractDescriptor/ContractDescriptorHelpers.cs Updates helper imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ContractDescriptor/ContractDescriptorBuilder.cs Updates helper imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ContractDescriptor/ContractDescriptorHelpers.cs Updates helper imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ContractDescriptor/TargetTests.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ContractDescriptor/TargetTests.SubDescriptors.cs Updates test imports to use the new helper assembly.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/ContractDescriptor/ParserTests.cs Adds unit tests for compact contract descriptor JSON parsing.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/PrintfStressMessageFormatterTests.cs Adds unit tests for PrintfStressMessageFormatter.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/PlatformContextTests.cs Adds unit tests for platform context register access by number.
src/native/managed/cdac/tests/Microsoft.Diagnostics.DataContractReader.Tests/TestHelpers.cs Adds test helper methods for HResult formatting/assertions.
src/native/managed/cdac/cdac.slnx Adds the new helper project to the cDAC solution.
src/native/managed/cdac/README.md Updates command examples to reflect the new test project path.
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Microsoft.Diagnostics.DataContractReader.Contracts.csproj Adds IVT access for the new helper assembly.
eng/Subsets.props Ensures the helper assembly is built/packed and updates test project paths in subsets.
Comments suppressed due to low confidence (1)

src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/TestPlaceholderTarget.cs:21

  • Making this type public exposes its API surface (including the constructor) to external consumers. The constructor currently uses optional parameters defaulting to null but the parameter types are non-nullable reference types; please update those constructor parameter types to nullable (e.g., Dictionary<...>? types = null, etc.) so the public API has correct nullability annotations.

@hoyosjs hoyosjs force-pushed the juhoyosa/split-mock-types branch from 4bbf880 to 0a06f9b Compare March 20, 2026 22:17
Copilot AI review requested due to automatic review settings March 20, 2026 22:17
Copy link
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

Copilot reviewed 56 out of 61 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (3)

src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.ExecutionManager.cs:24

  • This comment refers to an ExecutionManagerTestTarget “below”, but that type doesn’t exist in this file (or anywhere in the test tree). Please update the comment to reference the correct type/usage (or remove the reference) so the constraint on RealCodeHeaderSize remains understandable.
    src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/ExecutionManager/NibbleMapTestBuilder.cs:51
  • There are a couple of spacing/style issues in these helper methods (e.g., extra space in the cast and a space before the parameter list in Pos2ShiftCount (ulong addr)). Please normalize spacing to match typical C# formatting so it stays consistent with the rest of the file.
    src/native/managed/cdac/tests/Microsoft.Diagnostics.Internal.RuntimeMemoryMocks/MockDescriptors/MockDescriptors.RuntimeFunctions.cs:104
  • The max-value check uses 1 << 18 - 1, which due to operator precedence is evaluated as 1 << (18 - 1) (2^17), not (1 << 18) - 1 (2^18-1). This will throw for valid 18-bit values; add parentheses (and consider using an unsigned literal) to express the intended limit. Also consider trimming the trailing space in the exception message.

$(SharedNativeRoot)managed\cdac\Microsoft.Diagnostics.DataContractReader.Contracts\Microsoft.Diagnostics.DataContractReader.Contracts.csproj" Category="tools" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />

<!-- Transport package for added testing -->
<ProjectToBuild Include="$(SharedNativeRoot)managed\cdac\tests\Microsoft.Diagnostics.Internal.RuntimeMemoryMocks\Microsoft.Diagnostics.Internal.RuntimeMemoryMocks.csproj" Category="tools" />
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

This ProjectToBuild entry is part of the “Direct references … for packing” block, but unlike the other entries here it isn’t conditioned on $(DotNetBuildSourceOnly) != 'true'. If source-build skips packing these projects, this unconditional build can reintroduce source-build failures; consider applying the same condition for consistency.

Suggested change
<ProjectToBuild Include="$(SharedNativeRoot)managed\cdac\tests\Microsoft.Diagnostics.Internal.RuntimeMemoryMocks\Microsoft.Diagnostics.Internal.RuntimeMemoryMocks.csproj" Category="tools" />
<ProjectToBuild Include="$(SharedNativeRoot)managed\cdac\tests\Microsoft.Diagnostics.Internal.RuntimeMemoryMocks\Microsoft.Diagnostics.Internal.RuntimeMemoryMocks.csproj" Category="tools" Condition="'$(DotNetBuildSourceOnly)' != 'true'" />

Copilot uses AI. Check for mistakes.
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