Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hangdump space in dump path #3994

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading