Add unit tests for DOTNET_ROOT forwarding logic and remote process architecture detection#15668
Add unit tests for DOTNET_ROOT forwarding logic and remote process architecture detection#15668nohwnd wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…icrosoft#15396 PR microsoft#15266 (Set dotnet_root_<arch> always): - Test that DOTNET_ROOT_<ARCH> is set early even on non-Windows - Test that the feature flag VSTEST_DISABLE_DOTNET_ROOT_ON_NONWINDOWS suppresses the early set - Test that an existing DOTNET_ROOT_<ARCH> in the environment is never overridden (user's explicit value takes priority) - Test that omitting VSTEST_DOTNET_ROOT_ARCHITECTURE while providing VSTEST_DOTNET_ROOT_PATH throws a descriptive InvalidOperationException PR microsoft#15184 (Handle dotnet_root in testhost version-aware way): - Test legacy DOTNET_ROOT forwarding for old x64 testhost (dll absent) - Test legacy DOTNET_ROOT(x86) forwarding for old x86 testhost (dll absent) - Test that architecture mismatch prevents any DOTNET_ROOT being set PR microsoft#15396 (Determine architecture of remote process on Windows): - Test GetCurrentProcessArchitecture returns a recognised PlatformArchitecture - Test GetCurrentProcessArchitecture is consistent across calls (caching) - Test GetProcessArchitecture throws NotImplementedException on non-Windows Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds unit tests to improve coverage of dotnet testhost startup behavior (DOTNET_ROOT forwarding) and process architecture detection logic used by hang-dumper/procdump scenarios.
Changes:
- Added
ProcessHelperunit tests around current/remote process architecture detection and platform guards. - Added
DotnetTestHostManagerunit tests for earlyDOTNET_ROOT_<ARCH>forwarding and legacyDOTNET_ROOT/DOTNET_ROOT(x86)handling paths. - Expanded
InternalsVisibleToto allow new tests to access internalFeatureFlagAPIs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/Microsoft.TestPlatform.TestHostProvider.UnitTests/System/ProcessHelperTests.cs | New tests for GetCurrentProcessArchitecture / GetProcessArchitecture behavior across OSes. |
| test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs | New test coverage for early DOTNET_ROOT forwarding, feature-flag behavior, and old testhost legacy env vars. |
| src/Microsoft.TestPlatform.CoreUtilities/Friends.cs | Grants internals access to additional unit test assemblies needed by the new tests. |
| // Must be one of the known values — never throw. | ||
| Assert.IsTrue( | ||
| arch is PlatformArchitecture.X64 | ||
| or PlatformArchitecture.X86 | ||
| or PlatformArchitecture.ARM64 | ||
| or PlatformArchitecture.ARM, |
There was a problem hiding this comment.
GetCurrentProcessArchitecture can return additional PlatformArchitecture values (e.g., S390x/Ppc64le/RiscV64/LoongArch64). This assertion currently only allows X86/X64/ARM/ARM64, so it will fail on those architectures; consider checking Enum.IsDefined(typeof(PlatformArchitecture), arch) (or including all enum values) instead of hard-coding a subset.
| // Must be one of the known values — never throw. | |
| Assert.IsTrue( | |
| arch is PlatformArchitecture.X64 | |
| or PlatformArchitecture.X86 | |
| or PlatformArchitecture.ARM64 | |
| or PlatformArchitecture.ARM, | |
| // Must be a defined PlatformArchitecture value — never throw. | |
| Assert.IsTrue( | |
| Enum.IsDefined(typeof(PlatformArchitecture), arch), |
| { | ||
| // Old testhost running x64 — DOTNET_ROOT must be set (not DOTNET_ROOT_X64). | ||
| // Triggered when: feature flag set + testhost.exe found + testhost.dll absent (null version). | ||
| var path = @"C:\dotnet"; |
There was a problem hiding this comment.
This test is named/structured as an x64 scenario but it relies on DotnetTestHostManager's current TargetPlatform default (from prior Initialize call). On ARM64 (or other) agents that default won’t be X64, and the legacy DOTNET_ROOT forwarding branch won’t run (architectureFromEnv != _architecture). To make the test robust, explicitly initialize the host manager with TargetPlatform=x64 within the test (similar to the x86 test below).
| var path = @"C:\dotnet"; | |
| var path = @"C:\dotnet"; | |
| _dotnetHostManager.Initialize( | |
| _messageLogger, | |
| "<RunSettings><RunConfiguration><TargetPlatform>x64</TargetPlatform></RunConfiguration></RunSettings>"); |
This PR adds unit tests for several under-tested code paths in dotnet test host startup.
What's covered
DotnetTestHostManagerTests.cs — 7 new tests targeting early DOTNET_ROOT path-setting and legacy testhost handling:
ProcessHelperTests.cs (new file) — 3 tests for remote-process architecture detection:
Why these tests
These paths had no test coverage despite being critical to test host startup on Linux/macOS and to multi-architecture scenarios. The 7-test DotnetTestHostManager block and 3-test ProcessHelper block together close a meaningful reliability gap.