Skip to content
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 @@ -9,8 +9,10 @@ namespace Microsoft.Diagnostics.Monitoring.TestCommon
{
public partial class DotNetHost
{
// The version is in the Major.Minor.Patch-label format; remove the label
// and only parse the Major.Minor.Patch part.
private static Lazy<Version> s_runtimeVersionLazy =
new(() => Version.Parse(CurrentNetCoreVersionString));
new(() => Version.Parse(CurrentNetCoreVersionString.Split("-")[0]));

public static Version RuntimeVersion =>
s_runtimeVersionLazy.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FileFormats;
using Microsoft.FileFormats.ELF;
using Microsoft.FileFormats.MachO;
using System;
using System.IO;
using System.Net.Http;
using System.Runtime.InteropServices;
Expand All @@ -24,6 +26,8 @@ namespace Microsoft.Diagnostics.Monitoring.UnitTests
[Collection(DefaultCollectionFixture.Name)]
public class DumpTests
{
private const string EnableElfDumpOnMacOS = "COMPlus_DbgEnableElfDumpOnMacOS";

private readonly IHttpClientFactory _httpClientFactory;
private readonly ITestOutputHelper _outputHelper;

Expand Down Expand Up @@ -65,10 +69,10 @@ public async Task DumpTest(DiagnosticPortConnectionMode mode, DumpType type)
appRunner.DiagnosticPortPath = diagnosticPortPath;
appRunner.ScenarioName = TestAppScenarios.AsyncWait.Name;

// MachO not supported, only ELF: https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/xplat-minidump-generation.md#os-x
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
// MachO not supported on .NET 5, only ELF: https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/xplat-minidump-generation.md#os-x
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && DotNetHost.RuntimeVersion.Major == 5)
{
appRunner.Environment.Add("COMPlus_DbgEnableElfDumpOnMacOS", "1");
appRunner.Environment.Add(EnableElfDumpOnMacOS, "1");
}

await appRunner.ExecuteAsync(async () =>
Expand All @@ -84,7 +88,7 @@ await appRunner.ExecuteAsync(async () =>
// Read enough to deserialize the header.
int read;
int total = 0;
using CancellationTokenSource cancellation = new(TestTimeouts.HttpApi);
using CancellationTokenSource cancellation = new(TestTimeouts.DumpTimeout);
while (total < headerBuffer.Length && 0 != (read = await holder.Stream.ReadAsync(headerBuffer, total, headerBuffer.Length - total, cancellation.Token)))
{
total += read;
Expand All @@ -103,14 +107,49 @@ await appRunner.ExecuteAsync(async () =>
// Validate Signature
Assert.True(header.IsSignatureValid.Check());
}
else
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
ELFHeader header = dumpReader.Read<ELFHeader>(0);
ELFHeaderIdent ident = dumpReader.Read<ELFHeaderIdent>(0);
Assert.True(ident.IsIdentMagicValid.Check());
Assert.True(ident.IsClassValid.Check());
Assert.True(ident.IsDataValid.Check());

LayoutManager layoutManager = new();
layoutManager.AddELFTypes(
isBigEndian: ident.Data == ELFData.BigEndian,
is64Bit: ident.Class == ELFClass.Class64);
Reader headerReader = new(dumpAddressSpace, layoutManager);

ELFHeader header = headerReader.Read<ELFHeader>(0);
// Validate Signature
Assert.True(header.IsIdentMagicValid.Check());
// Validate ELF file is a core dump
Assert.Equal(ELFHeaderType.Core, header.Type);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
if (appRunner.Environment.ContainsKey(EnableElfDumpOnMacOS))
{
ELFHeader header = dumpReader.Read<ELFHeader>(0);
// Validate Signature
Assert.True(header.IsIdentMagicValid.Check());
// Validate ELF file is a core dump
Assert.Equal(ELFHeaderType.Core, header.Type);
}
else
{
MachHeader header = dumpReader.Read<MachHeader>(0);
// Validate Signature
Assert.True(header.IsMagicValid.Check());
// Validate MachO file is a core dump
Assert.True(header.IsFileTypeValid.Check());
Assert.Equal(MachHeaderFileType.Core, header.FileType);
}
}
else
{
throw new NotImplementedException("Dump header check not implemented for this OS platform.");
}

await appRunner.SendCommandAsync(TestAppScenarios.AsyncWait.Commands.Continue);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static async Task<Dictionary<string, string>> GetProcessEnvironmentAsync(
/// </summary>
public static Task<ResponseStreamHolder> CaptureDumpAsync(this ApiClient client, int pid, DumpType dumpType)
{
return client.CaptureDumpAsync(pid, dumpType, TestTimeouts.HttpApi);
return client.CaptureDumpAsync(pid, dumpType, TestTimeouts.DumpTimeout);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public static bool IsDumpSupported
{
get
{
// Linux dumps currently broken by https://github.com/dotnet/diagnostics/issues/2098
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return false;

// MacOS supported dumps starting in .NET 5
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && DotNetHost.RuntimeVersion.Major < 5)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ internal static class TestTimeouts
/// Default logs collection duration.
/// </summary>
public static readonly TimeSpan LogsDuration = TimeSpan.FromSeconds(10);

/// <summary>
/// Default timeout for dump collection.
/// </summary>
public static readonly TimeSpan DumpTimeout = TimeSpan.FromMinutes(1);
}
}