Skip to content

Commit

Permalink
Fix hangdump space in dump path (#3994)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Nov 4, 2024
1 parent a3a5c5c commit 9d5248f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Globalization;
#if NETCOREAPP
using System.Runtime.InteropServices;
#endif

using Microsoft.Testing.Extensions.Diagnostics.Resources;
using Microsoft.Testing.Extensions.HangDump.Serializers;
Expand Down Expand Up @@ -362,6 +365,13 @@ private async Task TakeDumpAsync()
_ => throw ApplicationStateGuard.Unreachable(),
};

// Wrap the dump path into "" when it has space in it, this is a workaround for this runtime issue: https://github.com/dotnet/diagnostics/issues/5020
// It only affects windows. Otherwise the dump creation fails with: [createdump] The pid argument is no longer supported
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && finalDumpFileName.Contains(' '))
{
finalDumpFileName = $"\"{finalDumpFileName}\"";
}

diagnosticsClient.WriteDump(dumpType, finalDumpFileName, true);
#else
MiniDumpWriteDump.MiniDumpTypeOption miniDumpTypeOption = _dumpType.ToLowerInvariant().Trim() switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ public async Task HangDump_CustomFileName_CreateDump()
Assert.IsTrue(dumpFile is not null, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'");
}

public async Task HangDump_PathWithSpaces_CreateDump()
{
string resultDir = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent.Arguments);
string resultDirectory = Path.Combine(resultDir, "directory with spaces");
Directory.CreateDirectory(resultDirectory);
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent.Arguments);
TestHostResult testHostResult = await testHost.ExecuteAsync(
$"""--hangdump --hangdump-timeout 8s --hangdump-filename myhungdumpfile_%p.dmp --results-directory "{resultDirectory}" """,
new Dictionary<string, string>
{
{ "SLEEPTIMEMS1", "4000" },
{ "SLEEPTIMEMS2", "20000" },
});
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string? dumpFile = Directory.GetFiles(resultDirectory, "myhungdumpfile_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
Assert.IsTrue(dumpFile is not null, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'");
}

[Arguments("Mini")]
[Arguments("Heap")]
[Arguments("Triage")]
Expand Down

0 comments on commit 9d5248f

Please sign in to comment.