Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -10,34 +10,22 @@ public sealed class CrashDumpTests : AcceptanceTestBase<CrashDumpTests.TestAsset
[TestMethod]
public async Task CrashDump_DefaultSetting_CreateDump(string tfm)
{
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();

string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
DotnetMuxerResult result = await DotnetCli.RunAsync(
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {tfm} {globalProperties} --crashdump --results-directory {resultDirectory}",
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
failIfReturnValueIsNotZero: false,
cancellationToken: TestContext.CancellationToken);

result.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
Assert.IsNotNull(dumpFile, $"Dump file not found '{tfm}'\n{result}'");
Assert.IsNotNull(dumpFile, $"Dump file not found '{tfm}'\n{testHostResult}'");
}

[TestMethod]
public async Task CrashDump_CustomDumpName_CreateDump()
{
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();

string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
DotnetMuxerResult result = await DotnetCli.RunAsync(
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {TargetFrameworks.NetCurrent} {globalProperties} --crashdump --crashdump-filename customdumpname.dmp --results-directory {resultDirectory}",
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
failIfReturnValueIsNotZero: false,
cancellationToken: TestContext.CancellationToken);

result.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
Assert.IsNotNull(Directory.GetFiles(resultDirectory, "customdumpname.dmp", SearchOption.AllDirectories).SingleOrDefault(), "Dump file not found");
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-filename customdumpname.dmp --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
Assert.ContainsSingle(Directory.GetFiles(resultDirectory, "customdumpname.dmp", SearchOption.AllDirectories), $"Dump file not found\n{testHostResult}");
}

[DataRow("Mini")]
Expand All @@ -47,35 +35,23 @@ public async Task CrashDump_CustomDumpName_CreateDump()
[TestMethod]
public async Task CrashDump_Formats_CreateDump(string format)
{
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();

string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
DotnetMuxerResult result = await DotnetCli.RunAsync(
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {TargetFrameworks.NetCurrent} {globalProperties} --crashdump --crashdump-type {format} --results-directory {resultDirectory}",
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
failIfReturnValueIsNotZero: false,
cancellationToken: TestContext.CancellationToken);
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type {format} --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);

result.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump_*.dmp", SearchOption.AllDirectories).SingleOrDefault();
Assert.IsNotNull(dumpFile, $"Dump file not found '{format}'\n{result}'");
string dumpFile = Assert.ContainsSingle(Directory.GetFiles(resultDirectory, "CrashDump_*.dmp", SearchOption.AllDirectories), $"Dump file not found '{format}'\n{testHostResult}");
File.Delete(dumpFile);
}

[TestMethod]
public async Task CrashDump_InvalidFormat_ShouldFail()
{
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();

string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"));
DotnetMuxerResult result = await DotnetCli.RunAsync(
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {TargetFrameworks.NetCurrent} {globalProperties} --crashdump --crashdump-type invalid --results-directory {resultDirectory}",
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
failIfReturnValueIsNotZero: false,
cancellationToken: TestContext.CancellationToken);

result.AssertExitCodeIs(ExitCodes.InvalidCommandLine);
result.AssertOutputContains("Option '--crashdump-type' has invalid arguments: 'invalid' is not a valid dump type. Valid options are 'Mini', 'Heap', 'Triage' and 'Full'");
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent);
TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type invalid --results-directory {resultDirectory}", cancellationToken: TestContext.CancellationToken);
testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine);
testHostResult.AssertOutputContains("Option '--crashdump-type' has invalid arguments: 'invalid' is not a valid dump type. Valid options are 'Mini', 'Heap', 'Triage' and 'Full'");
}

public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
Expand All @@ -98,7 +74,6 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.
<PropertyGroup>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseAppHost>true</UseAppHost>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public sealed class HangDumpOutputTests : AcceptanceTestBase<HangDumpOutputTests
{
[DataRow("Mini")]
[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX, IgnoreMessage = "Investigate failures on macos")]
public async Task HangDump_Outputs_HangingTests_EvenWhenHangingTestsHaveTheSameDisplayName(string format)
{
// This test makes sure that when tests have the same display name (e.g. like Test1 from both Class1 and Class2)
Expand Down Expand Up @@ -51,7 +50,6 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.
<PropertyGroup>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseAppHost>true</UseAppHost>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,19 @@ public sealed class HangDumpProcessTreeTests : AcceptanceTestBase<HangDumpProces
[TestMethod]
public async Task HangDump_DumpAllChildProcesses_CreateDump(string tfm)
{
string globalProperties = DumpWorkaround.GetGlobalPropertiesWorkaround();

string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), tfm);
DotnetMuxerResult result = await DotnetCli.RunAsync(
$"run -c Release --no-build --project {AssetFixture.TargetAssetPath} -f {tfm} {globalProperties} --hangdump --hangdump-timeout 8s --hangdump-type mini --results-directory {resultDirectory}",
AcceptanceFixture.NuGetGlobalPackagesFolder.Path,
environmentVariables: new Dictionary<string, string?>
var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "HangDumpWithChild", tfm);
TestHostResult testHostResult = await testHost.ExecuteAsync(
$"--hangdump --hangdump-timeout 8s --hangdump-type mini --results-directory {resultDirectory}",
new Dictionary<string, string?>
{
{ "SLEEPTIMEMS1", "4000" },
{ "SLEEPTIMEMS2", "600000" },
{ "SLEEPTIMEMS1", "4000" },
{ "SLEEPTIMEMS2", "600000" },
},
failIfReturnValueIsNotZero: false,
cancellationToken: TestContext.CancellationToken);

result.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string[] dumpFiles = Directory.GetFiles(resultDirectory, "*.dmp", SearchOption.AllDirectories);
Assert.HasCount(4, dumpFiles, $"There should be 4 dumps, one for each process in the tree. {result}");
testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully);
string[] dumpFiles = Directory.GetFiles(resultDirectory, "HangDump*.dmp", SearchOption.AllDirectories);
Assert.HasCount(4, dumpFiles, $"There should be 4 dumps, one for each process in the tree. {testHostResult}");
}

public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public sealed class HangDumpTests : AcceptanceTestBase<HangDumpTests.TestAssetFi
{
[DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX, IgnoreMessage = "Investigate failures on macos")]
public async Task HangDump_DefaultSetting_CreateDump(string tfm)
{
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), tfm);
Expand All @@ -27,7 +26,6 @@ public async Task HangDump_DefaultSetting_CreateDump(string tfm)
}

[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX, IgnoreMessage = "Investigate failures on macos")]
public async Task HangDump_WithDotnetTest_CreateDump()
{
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);
Expand All @@ -51,7 +49,6 @@ public async Task HangDump_WithDotnetTest_CreateDump()
}

[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX, IgnoreMessage = "Investigate failures on macos")]
public async Task HangDump_CustomFileName_CreateDump()
{
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);
Expand All @@ -69,7 +66,6 @@ public async Task HangDump_CustomFileName_CreateDump()
}

[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX, IgnoreMessage = "Investigate failures on macos")]
public async Task HangDump_PathWithSpaces_CreateDump()
{
string resultDir = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent);
Expand All @@ -94,7 +90,6 @@ public async Task HangDump_PathWithSpaces_CreateDump()
[DataRow("Triage")]
[DataRow("Full")]
[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX, IgnoreMessage = "Investigate failures on macos")]
public async Task HangDump_Formats_CreateDump(string format)
{
string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), format);
Expand Down Expand Up @@ -153,7 +148,6 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.
<PropertyGroup>
<TargetFrameworks>$TargetFrameworks$</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseAppHost>true</UseAppHost>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ public async Task RetryFailedTests_MaxTestsCount_Succeeds(string tfm, bool fail)
[TestMethod]
// We use crash dump, not supported in NetFramework at the moment
[DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX)]
public async Task RetryFailedTests_MoveFiles_Succeeds(string tfm)
// TODO: Crash dump is not working properly on macos, so we skip the test for now
=> await RetryHelper.RetryAsync(
async () =>
{
Expand Down Expand Up @@ -229,7 +227,7 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<UseAppHost>true</UseAppHost>
<UseAppHost Condition="$([MSBuild]::IsOSPlatform('OSX'))">false</UseAppHost>
<LangVersion>preview</LangVersion>
<GenerateTestingPlatformEntryPoint>false</GenerateTestingPlatformEntryPoint>
<TestingPlatformCaptureOutput>false</TestingPlatformCaptureOutput>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public async Task Trx_WhenReportTrxIsSpecified_TrxReportIsGeneratedInDefaultLoca

[DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))]
[TestMethod]
[OSCondition(ConditionMode.Exclude, OperatingSystems.OSX, IgnoreMessage = "Investigate failures on macos")]
public async Task Trx_WhenTestHostCrash_ErrorIsDisplayedInsideTheTrx(string tfm)
{
string fileName = Guid.NewGuid().ToString("N");
Expand Down Expand Up @@ -220,7 +219,6 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<UseAppHost>true</UseAppHost>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,30 @@ we end up with a -dev or -ci version which will lose resolution over -preview de
-->
<PackageReference Include="Microsoft.Testing.Platform" Version="{AppVersion.DefaultSemVer}" Condition="'$(UsingMSTestSdk)' != 'true' AND '$(EnableMicrosoftTestingPlatform)' == 'true'" />
</ItemGroup>

<Target Name="WorkaroundMacOSDumpIssue" AfterTargets="Build" Condition="$([MSBuild]::IsOSPlatform('OSX')) AND '$(UseAppHost)' != 'false' AND '$(OutputType)' == 'Exe' AND '$(TargetFramework)' != '' AND '$(RunCommand)' != ''">
<Exec Command="codesign --sign - --force --entitlements '$(MSBuildThisFileDirectory)mtp-test-entitlements.plist' '$(RunCommand)'" />
</Target>
</Project>
""");

File.WriteAllText(System.IO.Path.Combine(directoryPath, "mtp-test-entitlements.plist"), """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.debugger</key>
<true/>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>
""");

string directoryPackagesProps = System.IO.Path.Combine(directoryPath, "Directory.Packages.props");
Expand Down