Skip to content

Commit 9d5248f

Browse files
authored
Fix hangdump space in dump path (#3994)
1 parent a3a5c5c commit 9d5248f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpProcessLifetimeHandler.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Globalization;
5+
#if NETCOREAPP
6+
using System.Runtime.InteropServices;
7+
#endif
58

69
using Microsoft.Testing.Extensions.Diagnostics.Resources;
710
using Microsoft.Testing.Extensions.HangDump.Serializers;
@@ -362,6 +365,13 @@ private async Task TakeDumpAsync()
362365
_ => throw ApplicationStateGuard.Unreachable(),
363366
};
364367

368+
// 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
369+
// It only affects windows. Otherwise the dump creation fails with: [createdump] The pid argument is no longer supported
370+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && finalDumpFileName.Contains(' '))
371+
{
372+
finalDumpFileName = $"\"{finalDumpFileName}\"";
373+
}
374+
365375
diagnosticsClient.WriteDump(dumpType, finalDumpFileName, true);
366376
#else
367377
MiniDumpWriteDump.MiniDumpTypeOption miniDumpTypeOption = _dumpType.ToLowerInvariant().Trim() switch

test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ public async Task HangDump_CustomFileName_CreateDump()
4747
Assert.IsTrue(dumpFile is not null, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'");
4848
}
4949

50+
public async Task HangDump_PathWithSpaces_CreateDump()
51+
{
52+
string resultDir = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent.Arguments);
53+
string resultDirectory = Path.Combine(resultDir, "directory with spaces");
54+
Directory.CreateDirectory(resultDirectory);
55+
var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent.Arguments);
56+
TestHostResult testHostResult = await testHost.ExecuteAsync(
57+
$"""--hangdump --hangdump-timeout 8s --hangdump-filename myhungdumpfile_%p.dmp --results-directory "{resultDirectory}" """,
58+
new Dictionary<string, string>
59+
{
60+
{ "SLEEPTIMEMS1", "4000" },
61+
{ "SLEEPTIMEMS2", "20000" },
62+
});
63+
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
64+
string? dumpFile = Directory.GetFiles(resultDirectory, "myhungdumpfile_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
65+
Assert.IsTrue(dumpFile is not null, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'");
66+
}
67+
5068
[Arguments("Mini")]
5169
[Arguments("Heap")]
5270
[Arguments("Triage")]

0 commit comments

Comments
 (0)