Skip to content

Commit c6d5030

Browse files
authored
Fixing the reminder of crash dumps (#2520)
* Add env vars * Create sequence file even if not crashed * Fix net5.0 version comparisons * Print message when sequence is not generated
1 parent 9394924 commit c6d5030

File tree

10 files changed

+70
-12
lines changed

10 files changed

+70
-12
lines changed

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/BlameCollector.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,19 @@ public override void Initialize(
139139
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgEnableElfDumpOnMacOS", "1"));
140140
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgEnableMiniDump", "1"));
141141

142+
if (!this.processFullDumpEnabled)
143+
{
144+
// https://github.com./dotnet/coreclr/blob/master/Documentation/botr/xplat-minidump-generation.md
145+
// MiniDumpWithPrivateReadWriteMemory = 2
146+
// MiniDumpNormal = 1
147+
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgMiniDumpType", this.processFullDumpEnabled ? "2" : "1"));
148+
}
149+
142150
var guid = Guid.NewGuid().ToString();
143151

144152
var dumpDirectory = Path.Combine(Path.GetTempPath(), guid);
145153
Directory.CreateDirectory(dumpDirectory);
146-
var dumpPath = Path.Combine(dumpDirectory, $"dotnet_%d_crashdump.dmp");
154+
var dumpPath = Path.Combine(dumpDirectory, $"%e_%p_%t_crashdump.dmp");
147155
this.environmentVariables.Add(new KeyValuePair<string, string>("COMPlus_DbgMiniDumpName", dumpPath));
148156
}
149157

@@ -416,8 +424,12 @@ private void SessionEndedHandler(object sender, SessionEndEventArgs args)
416424
var filepath = Path.Combine(this.GetTempDirectory(), Constants.AttachmentFileName + "_" + this.attachmentGuid);
417425

418426
filepath = this.blameReaderWriter.WriteTestSequence(this.testSequence, this.testObjectDictionary, filepath);
419-
var fileTranferInformation = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
420-
this.dataCollectionSink.SendFileAsync(fileTranferInformation);
427+
var fti = new FileTransferInformation(this.context.SessionDataCollectionContext, filepath, true);
428+
this.dataCollectionSink.SendFileAsync(fti);
429+
}
430+
else
431+
{
432+
this.logger.LogWarning(this.context.SessionDataCollectionContext, Resources.Resources.NotGeneratingSequenceFile);
421433
}
422434

423435
if (this.collectProcessDumpOnTrigger)

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/CrashDumperFactory.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,29 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector
66
using System;
77
using System.Runtime.InteropServices;
88
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
9+
using NuGet.Frameworks;
910

1011
internal class CrashDumperFactory : ICrashDumperFactory
1112
{
1213
public ICrashDumper Create(string targetFramework)
1314
{
15+
if (targetFramework is null)
16+
{
17+
throw new ArgumentNullException(nameof(targetFramework));
18+
}
19+
1420
EqtTrace.Info($"CrashDumperFactory: Creating dumper for {RuntimeInformation.OSDescription} with target framework {targetFramework}.");
21+
22+
var tfm = NuGetFramework.Parse(targetFramework);
23+
24+
if (tfm == null || tfm.IsUnsupported)
25+
{
26+
EqtTrace.Error($"CrashDumperFactory: Could not parse target framework {targetFramework}, to a supported framework version.");
27+
throw new NotSupportedException($"Could not parse target framework {targetFramework}, to a supported framework version.");
28+
}
29+
30+
var isNet50OrNewer = tfm.Framework == ".NETCoreApp" && tfm.Version >= Version.Parse("5.0.0.0");
31+
1532
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1633
{
1734
EqtTrace.Info($"CrashDumperFactory: This is Windows, returning ProcDumpCrashDumper that uses ProcDump utility.");
@@ -28,7 +45,7 @@ public ICrashDumper Create(string targetFramework)
2845
// return new NetClientCrashDumper();
2946
}
3047

31-
if (!string.IsNullOrWhiteSpace(targetFramework) && targetFramework.Contains("v5.0"))
48+
if (isNet50OrNewer)
3249
{
3350
EqtTrace.Info($"CrashDumperFactory: This is {RuntimeInformation.OSDescription} on {targetFramework} .NETClient dumper which uses env variables to collect crashdumps of testhost and any child process.");
3451
return new NetClientCrashDumper();

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/HangDumperFactory.cs

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,27 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector
66
using System;
77
using System.Runtime.InteropServices;
88
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
9+
using NuGet.Frameworks;
910

1011
internal class HangDumperFactory : IHangDumperFactory
1112
{
1213
public IHangDumper Create(string targetFramework)
1314
{
15+
if (targetFramework is null)
16+
{
17+
throw new ArgumentNullException(nameof(targetFramework));
18+
}
19+
1420
EqtTrace.Info($"HangDumperFactory: Creating dumper for {RuntimeInformation.OSDescription} with target framework {targetFramework}.");
21+
22+
var tfm = NuGetFramework.Parse(targetFramework);
23+
24+
if (tfm == null || tfm.IsUnsupported)
25+
{
26+
EqtTrace.Error($"HangDumperFactory: Could not parse target framework {targetFramework}, to a supported framework version.");
27+
throw new NotSupportedException($"Could not parse target framework {targetFramework}, to a supported framework version.");
28+
}
29+
1530
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1631
{
1732
EqtTrace.Info($"HangDumperFactory: This is Windows, returning the default WindowsHangDumper that P/Invokes MiniDumpWriteDump.");
@@ -20,7 +35,8 @@ public IHangDumper Create(string targetFramework)
2035

2136
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
2237
{
23-
if (!string.IsNullOrWhiteSpace(targetFramework) && targetFramework.Contains("v2.1"))
38+
var isLessThan31 = tfm.Framework == ".NETCoreApp" && tfm.Version < Version.Parse("3.1.0.0");
39+
if (isLessThan31)
2440
{
2541
EqtTrace.Info($"HangDumperFactory: This is Linux on netcoreapp2.1, returning SigtrapDumper.");
2642

@@ -33,7 +49,8 @@ public IHangDumper Create(string targetFramework)
3349

3450
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
3551
{
36-
if (!string.IsNullOrWhiteSpace(targetFramework) && !targetFramework.Contains("v5.0"))
52+
var isLessThan50 = tfm.Framework == ".NETCoreApp" && tfm.Version < Version.Parse("5.0.0.0");
53+
if (isLessThan50)
3754
{
3855
EqtTrace.Info($"HangDumperFactory: This is OSX on {targetFramework}, This combination of OS and framework is not supported.");
3956

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ProjectReference Include="..\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
2424
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj" />
2525
</ItemGroup>
26-
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
26+
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' AND '$(OS)' != 'Windows_NT' ">
2727
<Reference Include="System" />
2828
<Reference Include="System.Runtime" />
2929
<Reference Include="System.Xml" />
@@ -34,7 +34,6 @@
3434
<PackageReference Include="Microsoft.Diagnostics.NETCore.Client">
3535
<Version>0.2.0-preview.20378.10</Version>
3636
</PackageReference>
37-
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
3837
</ItemGroup>
3938
<ItemGroup>
4039
<Compile Update="Resources\Resources.Designer.cs">

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.resx

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@
132132
<data name="InactivityTimeout" xml:space="preserve">
133133
<value>The specified inactivity time of {0} minute/s has elapsed. Collecting a dump and killing the test host process.</value>
134134
</data>
135+
<data name="NotGeneratingSequenceFile" xml:space="preserve">
136+
<value>All tests finished running, Sequence file will not be generated.</value>
137+
<comment>"Sequence" is the name of the file.</comment>
138+
</data>
135139
<data name="ProcDumpCouldNotStart" xml:space="preserve">
136140
<value>Could not start process dump: {0}</value>
137141
</data>

src/testhost.x86/testhost.x86.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<FromP2P>true</FromP2P>
3131
</ProjectReference>
3232
</ItemGroup>
33-
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
33+
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
3434
<Reference Include="netstandard" />
3535
<Reference Include="System" />
3636
<Reference Include="System.Runtime" />

src/testhost/testhost.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<FromP2P>true</FromP2P>
3333
</ProjectReference>
3434
</ItemGroup>
35-
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
35+
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
3636
<Reference Include="netstandard" />
3737
<Reference Include="System" />
3838
<Reference Include="System.Runtime" />

test/Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests/Microsoft.TestPlatform.Extensions.BlameDataCollector.UnitTests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.Extensions.BlameDataCollector\Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj" />
2020
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
2121
</ItemGroup>
22-
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' AND '$(OS)' != 'Windows_NT' ">
2323
<Reference Include="System.Runtime" />
2424
<Reference Include="System" />
2525
<Reference Include="Microsoft.CSharp" />

test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Microsoft.TestPlatform.TestHostProvider.UnitTests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.TestHostProvider\Microsoft.TestPlatform.TestHostProvider.csproj" />
1616
</ItemGroup>
17-
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
17+
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' AND '$(OS)' != 'Windows_NT' ">
1818
<Reference Include="System.Runtime" />
1919
<Reference Include="System" />
2020
<Reference Include="Microsoft.CSharp" />

0 commit comments

Comments
 (0)