Skip to content

Commit

Permalink
fix MemoryDiagnoserTests issues, fixes #813
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Jul 4, 2018
1 parent 0f9c48d commit 33e5686
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/BenchmarkDotNet/Engines/GcStats.cs
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Toolchains.DotNetCli;

namespace BenchmarkDotNet.Engines
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public long BytesAllocatedPerOperation
{
get
{
bool excludeAllocationQuantumSideEffects = !RuntimeInformation.IsNetCore; // the issue got fixed for .NET Core 2.0 https://github.com/dotnet/coreclr/issues/10207
bool excludeAllocationQuantumSideEffects = !RuntimeInformation.IsNetCore || NetCoreAppSettings.Current.Value == NetCoreAppSettings.NetCoreApp20; // the issue got fixed for .NET Core 2.0+ https://github.com/dotnet/coreclr/issues/10207

return GetTotalAllocatedBytes(excludeAllocationQuantumSideEffects) == 0
? 0
Expand Down
@@ -1,3 +1,4 @@
using System;
using System.Reflection;
using BenchmarkDotNet.Portability;
using JetBrains.Annotations;
Expand All @@ -13,6 +14,8 @@ public class NetCoreAppSettings
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp20 = new NetCoreAppSettings("netcoreapp2.0", null, ".NET Core 2.0");
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp21 = new NetCoreAppSettings("netcoreapp2.1", null, ".NET Core 2.1");
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp22 = new NetCoreAppSettings("netcoreapp2.2", null, ".NET Core 2.2");

public static readonly Lazy<NetCoreAppSettings> Current = new Lazy<NetCoreAppSettings>(GetCurrentVersion);

private static NetCoreAppSettings Default =>
#if NETCOREAPP2_1
Expand Down
27 changes: 15 additions & 12 deletions tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs
Expand Up @@ -12,6 +12,7 @@
using BenchmarkDotNet.Extensions;
using BenchmarkDotNet.IntegrationTests.Xunit;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Tests.Loggers;
using BenchmarkDotNet.Tests.XUnit;
Expand All @@ -30,16 +31,18 @@ public class MemoryDiagnoserTests
public MemoryDiagnoserTests(ITestOutputHelper outputHelper) => output = outputHelper;

public static IEnumerable<object[]> GetToolchains()
=> new[]
{
new object[] { Job.Default.GetToolchain() },
new object[] { InProcessToolchain.Instance },
#if NETCOREAPP2_1
// we don't want to test CoreRT twice (for .NET 4.6 and Core 2.1) when running the integration tests (these tests take a lot of time)
// we test against specific version to keep this test stable
new object[] { CoreRtToolchain.CreateBuilder().UseCoreRtNuGet(microsoftDotNetILCompilerVersion: "1.0.0-alpha-26414-01").ToToolchain() }
#endif
};
=> RuntimeInformation.IsMono // https://github.com/mono/mono/issues/8397
? Array.Empty<object[]>()
: new[]
{
new object[] { Job.Default.GetToolchain() },
new object[] { InProcessToolchain.Instance },
#if NETCOREAPP2_1
// we don't want to test CoreRT twice (for .NET 4.6 and Core 2.1) when running the integration tests (these tests take a lot of time)
// we test against specific version to keep this test stable
new object[] { CoreRtToolchain.CreateBuilder().UseCoreRtNuGet(microsoftDotNetILCompilerVersion: "1.0.0-alpha-26414-01").ToToolchain() }
#endif
};

public class AccurateAllocations
{
Expand Down Expand Up @@ -192,9 +195,9 @@ public byte[] SixtyFourBytesArray()
}
}

[TheoryNetCoreOnly("Only .NET Core 2.0+ API is bug free for this case"), MemberData(nameof(GetToolchains))]
[TheoryNetCore21PlusOnly("Only .NET Core 2.0+ API is bug free for this case"), MemberData(nameof(GetToolchains))]
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
public void AllocationQuantumIsNotAnIssueForNetCore(IToolchain toolchain)
public void AllocationQuantumIsNotAnIssueForNetCore21Plus(IToolchain toolchain)
{
if (toolchain is CoreRtToolchain) // the fix has not yet been backported to CoreRT
return;
Expand Down
@@ -0,0 +1,16 @@
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Toolchains.DotNetCli;
using Xunit;

namespace BenchmarkDotNet.Tests.XUnit
{
public class TheoryNetCore21PlusOnlyAttribute : TheoryAttribute
{
// ReSharper disable once VirtualMemberCallInConstructor
public TheoryNetCore21PlusOnlyAttribute(string skipReason)
{
if (!RuntimeInformation.IsNetCore || NetCoreAppSettings.GetCurrentVersion() == NetCoreAppSettings.NetCoreApp20)
Skip = skipReason;
}
}
}

0 comments on commit 33e5686

Please sign in to comment.