Skip to content

[cdac] Make contracts tests use mock/placeholder target instead of actual target#110027

Merged
elinor-fung merged 5 commits into
dotnet:mainfrom
elinor-fung:cdac-test-use-placeholder-target
Nov 21, 2024
Merged

[cdac] Make contracts tests use mock/placeholder target instead of actual target#110027
elinor-fung merged 5 commits into
dotnet:mainfrom
elinor-fung:cdac-test-use-placeholder-target

Conversation

@elinor-fung

Copy link
Copy Markdown
Member
  • Separate helpers for testing an actual contract descriptor from helpers for mock memory
    • Tests/helpers for the contract descriptor are now under the ContractDescriptor folder
  • Make all contracts tests use the mock target instead of creating a contract descriptor and using the ContractDescriptorTarget
  • Update root namespaces from Microsoft.Diagnostics.DataContractReader.UnitTests -> Microsoft.Diagnostics.DataContractReader.Tests to match assembly name

.ToDictionary();

// Tests are currently always set to use funclets
bool useFunclets = true;

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.

This was for #109873 (comment)


namespace Microsoft.Diagnostics.DataContractReader.Tests;

internal partial class MockDescriptors

@elinor-fung elinor-fung Nov 20, 2024

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.

This file was just renamed from ExecutionManagerTestBuilder.cs and put as an inner class of MockDescriptors. The only actual change was #110027 (comment)


namespace Microsoft.Diagnostics.DataContractReader.Tests.ContractDescriptor;

internal class ContractDescriptorBuilder : MockMemorySpace.Builder

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.

This was all copied out of MockMemorySpace.cs


namespace Microsoft.Diagnostics.DataContractReader.Tests.ContractDescriptor;

internal unsafe class ContractDescriptorHelpers

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.

This was all copied out of TargetTestHelpers.cs

@@ -19,21 +21,19 @@ public void GetPath(MockTarget.Architecture arch)
TargetTestHelpers helpers = new(arch);
MockMemorySpace.Builder builder = new(helpers);
MockLoader loader = new(builder);

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.

By switching from creating a "real" ContractDescriptorTarget to a TestPlaceholderTarget, we are bypassing the ContractDescriptorParser. It looks like we already test the contractdescriptor reading in other places, is the benefit that it is easier to mock out contracts?

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.

Yeah, the intent is that it is easier to mock out contracts (or other things needed by tests). It narrows down the portion of the 'real' product we are testing and we don't need to build out the JSON needed for the contract descriptor (which we were never using for a bunch of the tests already using the placeholder target).


internal Dictionary<DataType, Target.TypeInfo> Types { get; }
internal (string Name, ulong Value, string? Type)[] Globals { get; }
internal (string Name, ulong Value)[] Globals { get; }

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.

Why is the string? Type no longer needed for globals when testing? Looking at how they are used in the contracts, it seems the contracts are assumed to already know the type and reference them by name.

It looks like the ContractDescriptor JSON encodes the global type information and it is returned when reading a global. I don't see any contracts that use this, but it is part of the available information, is this needed? If so, do we need to replicate it during testing?

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.

We put the global type information (optionally) in the contract descriptor with the idea that contracts could validate what type they expect. But as you noted, we didn't actually end up doing this in the contracts we added.

We have testing for ContractDescriptorTarget that covers getting the global type information (when it exists). For all the mock descriptors that are now used with the placeholder target, I removed the optional type to make the test infrastructure a little simpler.

@elinor-fung elinor-fung merged commit 09b30a4 into dotnet:main Nov 21, 2024
@elinor-fung elinor-fung deleted the cdac-test-use-placeholder-target branch November 21, 2024 21:11
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this pull request Dec 10, 2024
…tual target (dotnet#110027)

- Separate helpers for testing an actual contract descriptor from helpers for mock memory
  - Tests/helpers for the contract descriptor are now under the `ContractDescriptor` folder
- Make all contracts tests use the mock target instead of creating a contract descriptor and using the `ContractDescriptorTarget`
- Update root namespaces from `Microsoft.Diagnostics.DataContractReader.UnitTests` -> `Microsoft.Diagnostics.DataContractReader.Tests` to match assembly name
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Diagnostics-coreclr test-enhancement Improvements of test source code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants