Skip to content

Commit 36a2301

Browse files
Youssef1313Copilot
andauthored
Unskip CrashDumpTests on macOS (#6874)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent 7343527 commit 36a2301

File tree

3 files changed

+63
-40
lines changed

3 files changed

+63
-40
lines changed

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@ public sealed class CrashDumpTests : AcceptanceTestBase<CrashDumpTests.TestAsset
1010
[TestMethod]
1111
public async Task CrashDump_DefaultSetting_CreateDump(string tfm)
1212
{
13-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
14-
{
15-
// TODO: Investigate failures on macos
16-
return;
17-
}
13+
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();
1814

1915
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
20-
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", tfm);
21-
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
22-
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
16+
DotnetMuxerResult result = await DotnetCli.RunAsync(
17+
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {tfm} {globalProperties} --crashdump --results-directory {resultDirectory}",
18+
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
19+
failIfReturnValueIsNotZero: false,
20+
cancellationToken: TestContext.CancellationToken);
21+
22+
result.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
2323
string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
24-
Assert.IsNotNull(dumpFile, $"Dump file not found '{tfm}'\n{testHostResult}'");
24+
Assert.IsNotNull(dumpFile, $"Dump file not found '{tfm}'\n{result}'");
2525
}
2626

2727
[TestMethod]
2828
public async Task CrashDump_CustomDumpName_CreateDump()
2929
{
30-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
31-
{
32-
// TODO: Investigate failures on macos
33-
return;
34-
}
30+
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();
3531

3632
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
37-
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
38-
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-filename customdumpname.dmp --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
39-
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
33+
DotnetMuxerResult result = await DotnetCli.RunAsync(
34+
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {TargetFrameworks.NetCurrent} {globalProperties} --crashdump --crashdump-filename customdumpname.dmp --results-directory {resultDirectory}",
35+
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
36+
failIfReturnValueIsNotZero: false,
37+
cancellationToken: TestContext.CancellationToken);
38+
39+
result.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
4040
Assert.IsNotNull(Directory.GetFiles(resultDirectory, "customdumpname.dmp", SearchOption.AllDirectories).SingleOrDefault(), "Dump file not found");
4141
}
4242

@@ -47,29 +47,35 @@ public async Task CrashDump_CustomDumpName_CreateDump()
4747
[TestMethod]
4848
public async Task CrashDump_Formats_CreateDump(string format)
4949
{
50-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
51-
{
52-
// TODO: Investigate failures on macos
53-
return;
54-
}
50+
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();
5551

5652
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
57-
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
58-
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type {format} --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
59-
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
53+
DotnetMuxerResult result = await DotnetCli.RunAsync(
54+
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {TargetFrameworks.NetCurrent} {globalProperties} --crashdump --crashdump-type {format} --results-directory {resultDirectory}",
55+
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
56+
failIfReturnValueIsNotZero: false,
57+
cancellationToken: TestContext.CancellationToken);
58+
59+
result.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
6060
string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
61-
Assert.IsNotNull(dumpFile, $"Dump file not found '{format}'\n{testHostResult}'");
61+
Assert.IsNotNull(dumpFile, $"Dump file not found '{format}'\n{result}'");
6262
File.Delete(dumpFile);
6363
}
6464

6565
[TestMethod]
6666
public async Task CrashDump_InvalidFormat_ShouldFail()
6767
{
68+
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();
69+
6870
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
69-
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
70-
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type invalid --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
71-
testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine);
72-
testHostResult.AssertOutputContains("Option '--crashdump-type' has invalid arguments: 'invalid' is not a valid dump type. Valid options are 'Mini', 'Heap', 'Triage' and 'Full'");
71+
DotnetMuxerResult result = await DotnetCli.RunAsync(
72+
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {TargetFrameworks.NetCurrent} {globalProperties} --crashdump --crashdump-type invalid --results-directory {resultDirectory}",
73+
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
74+
failIfReturnValueIsNotZero: false,
75+
cancellationToken: TestContext.CancellationToken);
76+
77+
result.AssertExitCodeIs(ExitCodes.InvalidCommandLine);
78+
result.AssertOutputContains("Option '--crashdump-type' has invalid arguments: 'invalid' is not a valid dump type. Valid options are 'Mini', 'Heap', 'Triage' and 'Full'");
7379
}
7480

7581
public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,11 @@ public sealed class HangDumpProcessTreeTests : AcceptanceTestBase<HangDumpProces
1010
[TestMethod]
1111
public async Task HangDump_DumpAllChildProcesses_CreateDump(string tfm)
1212
{
13-
string globalProperties = string.Empty;
14-
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
15-
{
16-
// Workaround: createdump doesn't work correctly on the apphost on macOS.
17-
// But it works correctly on the dotnet process.
18-
// So, disable apphost on macOS for now.
19-
// Related: https://github.com/dotnet/runtime/issues/119945
20-
globalProperties = "-p:UseAppHost=false";
21-
}
13+
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();
2214

2315
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), tfm);
2416
DotnetMuxerResult result = await DotnetCli.RunAsync(
25-
$"run --project {AssetFixture.TargetAssetPath} -f {tfm} {globalProperties} --hangdump --hangdump-timeout 8s --hangdump-type mini --results-directory {resultDirectory}",
17+
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {tfm} {globalProperties} --hangdump --hangdump-timeout 8s --hangdump-type mini --results-directory {resultDirectory}",
2618
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
2719
environmentVariables: new Dictionary<string, string?>
2820
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Runtime.InteropServices;
5+
6+
namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers;
7+
8+
internal static class DumpWorkaround
9+
{
10+
/// <summary>
11+
/// Gets MSBuild global properties to work around crash/hang dump issues on macOS.
12+
/// </summary>
13+
/// <returns>
14+
/// On macOS, returns "-p:UseAppHost=false" to work around createdump not working correctly on apphost.
15+
/// On other platforms, returns an empty string.
16+
/// </returns>
17+
/// <remarks>
18+
/// Workaround: createdump doesn't work correctly on the apphost on macOS.
19+
/// But it works correctly on the dotnet process.
20+
/// So, disable apphost on macOS for now.
21+
/// Related: https://github.com/dotnet/runtime/issues/119945
22+
/// </remarks>
23+
public static string GetGlobalPropertiesWorkaround()
24+
=> RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "-p:UseAppHost=false" : string.Empty;
25+
}

0 commit comments

Comments
 (0)