Skip to content

Commit

Permalink
Fix SOS unit tests dump generation fixture (#4636)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikem8361 committed Apr 24, 2024
1 parent 790499a commit 592039f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
6 changes: 0 additions & 6 deletions eng/Versions.props
Expand Up @@ -119,16 +119,10 @@
</PropertyGroup>
<ItemGroup Condition="!$(InternalReleaseTesting)">
<RuntimeTestVersions Include="Latest">
<!--
<RuntimeDownload>$(VSRedistCommonNetCoreSharedFrameworkx6490Version)</RuntimeDownload>
<Runtime>$(MicrosoftNETCoreAppRuntimewinx64Version)</Runtime>
<AspNetDownload>$(MicrosoftAspNetCoreAppRefInternalVersion)</AspNetDownload>
<AspNet>$(MicrosoftAspNetCoreAppRefVersion)</AspNet>
-->
<RuntimeDownload>9.0.0-preview.4.24218.7</RuntimeDownload>
<Runtime>9.0.0-preview.4.24218.7</Runtime>
<AspNetDownload>9.0.0-preview.4.24218.1</AspNetDownload>
<AspNet>9.0.0-preview.4.24218.1</AspNet>
<TargetFramework>net9.0</TargetFramework>
</RuntimeTestVersions>
<RuntimeTestVersions Include="Servicing1">
Expand Down
Expand Up @@ -21,6 +21,7 @@
<LogDir>$(RootBinDir)\TestResults\$(TargetConfiguration)\sos.unittests_$(Timestamp)</LogDir>
<DumpDir>$(RootBinDir)\tmp\$(TargetConfiguration)\dumps</DumpDir>
<CDBHelperExtension>$(InstallDir)\runcommand.dll</CDBHelperExtension>
<MicrosoftNETCoreAppPath>$(DotNetRoot)\shared\Microsoft.NETCore.App\</MicrosoftNETCoreAppPath>

<SetHostExe>true</SetHostExe>
<SetFxVersion>true</SetFxVersion>
Expand Down
55 changes: 36 additions & 19 deletions src/SOS/SOS.UnitTests/DumpGenerationFixture.cs
Expand Up @@ -34,39 +34,56 @@ public DumpGenerationFixture()
{
}

// Create a unique list of all the runtime paths used by the tests
// Create a unique list of all the installed test runtime paths
HashSet<string> paths = new();
foreach (TestConfiguration config in TestRunConfiguration.Instance.Configurations)
{
if (config.IsNETCore && config.RuntimeFrameworkVersionMajor >= 8)
// Enumerate configs until we see this property
if (config.AllSettings.TryGetValue("MicrosoftNETCoreAppPath", out string path))
{
string path = config.RuntimeSymbolsPath;
if (!string.IsNullOrEmpty(path))
{
paths.Add(path);
path = TestConfiguration.MakeCanonicalPath(path);
try
{
foreach (string directory in Directory.GetDirectories(path))
{
if (Path.GetFileName(directory).StartsWith("9"))
{
paths.Add(directory);
}
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
}
break;
}
}
}

// Now try to create the keys for the older Windows versions
try
if (paths.Count > 0)
{
using RegistryKey auxiliaryKey = Registry.LocalMachine.CreateSubKey(_auxiliaryNode, writable: true);
using RegistryKey knownKey = Registry.LocalMachine.CreateSubKey(_knownNode, writable: true);
// Now try to create the keys for the older Windows versions
try
{
using RegistryKey auxiliaryKey = Registry.LocalMachine.CreateSubKey(_auxiliaryNode, writable: true);
using RegistryKey knownKey = Registry.LocalMachine.CreateSubKey(_knownNode, writable: true);

foreach (string path in paths)
foreach (string path in paths)
{
string dacPath = Path.Combine(path, "mscordaccore.dll");
string runtimePath = Path.Combine(path, "coreclr.dll");
knownKey.SetValue(dacPath, 0, RegistryValueKind.DWord);
auxiliaryKey.SetValue(runtimePath, dacPath, RegistryValueKind.String);
}

// Save the paths after writing them successfully to registry
_paths = paths;
}
catch (Exception ex) when (ex is UnauthorizedAccessException)
{
string dacPath = Path.Combine(path, "mscordaccore.dll");
string runtimePath = Path.Combine(path, "coreclr.dll");
knownKey.SetValue(dacPath, 0, RegistryValueKind.DWord);
auxiliaryKey.SetValue(runtimePath, dacPath, RegistryValueKind.String);
}

// Save the paths after writing them successfully to registry
_paths = paths;
}
catch (Exception ex) when (ex is UnauthorizedAccessException)
{
}
}
}
Expand Down

0 comments on commit 592039f

Please sign in to comment.