Skip to content

Commit 4d86cd1

Browse files
committed
Changed remaining RuntimeInformation properties to readonly fields.
Disabled allocating tests.
1 parent 9476e9b commit 4d86cd1

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/BenchmarkDotNet/Engines/Engine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private ClockSpan Measure(Action<long> action, long invokeCount)
235235
Thread.Sleep(TimeSpan.FromMilliseconds(500));
236236
}
237237

238-
// GC collect before measuring allocations, as we do not collect during the measurement.
238+
// GC collect before measuring allocations.
239239
ForceGcCollect();
240240
var gcStats = MeasureWithGc(data.InvokeCount / data.UnrollFactor);
241241

src/BenchmarkDotNet/Engines/GcStats.cs

-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ public static GcStats FromForced(int forcedFullGarbageCollections)
145145
if (RuntimeInformation.IsWasm)
146146
return null;
147147

148-
// Calling GC.Collect() before calling GC.GetTotalAllocatedBytes appears to interfere with the results for some reason,
149-
// so we just call the API without forcing a collection.
150148
#if NET6_0_OR_GREATER
151149
return GC.GetTotalAllocatedBytes(precise: true);
152150
#else

src/BenchmarkDotNet/Portability/RuntimeInformation.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ private static bool IsAotMethod()
9797
&& Environment.GetEnvironmentVariable("DOTNET_TieredCompilation") != "0"
9898
&& (!AppContext.TryGetSwitch("System.Runtime.TieredCompilation", out isEnabled) || isEnabled));
9999

100-
public static bool IsRunningInContainer => string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), "true");
100+
public static readonly bool IsRunningInContainer = string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), "true");
101101

102-
internal static string ExecutableExtension => IsWindows() ? ".exe" : string.Empty;
102+
internal static readonly string ExecutableExtension = IsWindows() ? ".exe" : string.Empty;
103103

104-
internal static string ScriptFileExtension => IsWindows() ? ".bat" : ".sh";
104+
internal static readonly string ScriptFileExtension = IsWindows() ? ".bat" : ".sh";
105105

106106
internal static string GetArchitecture() => GetCurrentPlatform().ToString();
107107

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

+11-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
namespace BenchmarkDotNet.IntegrationTests
2828
{
29+
// TODO: re-enable allocating tests after https://github.com/dotnet/runtime/issues/101536 is fixed.
2930
public class MemoryDiagnoserTests
3031
{
3132
private readonly ITestOutputHelper output;
@@ -50,7 +51,7 @@ public class AccurateAllocations
5051
[Benchmark] public Task<int> AllocateTask() => Task.FromResult<int>(-12345);
5152
}
5253

53-
[Theory, MemberData(nameof(GetToolchains))]
54+
[Theory(Skip = "System.Runtime.InteropServices.RuntimeInformation allocates unexpectedly"), MemberData(nameof(GetToolchains))]
5455
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
5556
public void MemoryDiagnoserIsAccurate(IToolchain toolchain)
5657
{
@@ -70,7 +71,8 @@ public void MemoryDiagnoserIsAccurate(IToolchain toolchain)
7071
});
7172
}
7273

73-
[FactEnvSpecific("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 7.0)", EnvRequirement.DotNetCoreOnly)]
74+
[Fact(Skip = "System.Runtime.InteropServices.RuntimeInformation allocates unexpectedly")]
75+
//[FactEnvSpecific("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 8.0)", EnvRequirement.DotNetCoreOnly)]
7476
public void MemoryDiagnoserSupportsNativeAOT()
7577
{
7678
if (RuntimeInformation.IsMacOS())
@@ -79,7 +81,8 @@ public void MemoryDiagnoserSupportsNativeAOT()
7981
MemoryDiagnoserIsAccurate(NativeAotToolchain.Net80);
8082
}
8183

82-
[FactEnvSpecific("We don't want to test MonoVM twice (for .NET Framework 4.6.2 and .NET 8.0)", EnvRequirement.DotNetCoreOnly)]
84+
[Fact(Skip = "System.Runtime.InteropServices.RuntimeInformation allocates unexpectedly")]
85+
//[FactEnvSpecific("We don't want to test MonoVM twice (for .NET Framework 4.6.2 and .NET 8.0)", EnvRequirement.DotNetCoreOnly)]
8386
public void MemoryDiagnoserSupportsModernMono()
8487
{
8588
MemoryDiagnoserIsAccurate(MonoToolchain.Mono80);
@@ -207,7 +210,7 @@ public void WithOperationsPerInvoke()
207210
private void DoNotInline(object left, object right) { }
208211
}
209212

210-
[Theory, MemberData(nameof(GetToolchains))]
213+
[Theory(Skip = "System.Runtime.InteropServices.RuntimeInformation allocates unexpectedly"), MemberData(nameof(GetToolchains))]
211214
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
212215
public void AllocatedMemoryShouldBeScaledForOperationsPerInvoke(IToolchain toolchain)
213216
{
@@ -233,7 +236,8 @@ public byte[] SixtyFourBytesArray()
233236
}
234237
}
235238

236-
[TheoryEnvSpecific("Full Framework cannot measure precisely enough for low invocation counts.", EnvRequirement.DotNetCoreOnly), MemberData(nameof(GetToolchains))]
239+
[Theory(Skip = "System.Runtime.InteropServices.RuntimeInformation allocates unexpectedly"), MemberData(nameof(GetToolchains))]
240+
//[TheoryEnvSpecific("Full Framework cannot measure precisely enough for low invocation counts.", EnvRequirement.DotNetCoreOnly), MemberData(nameof(GetToolchains))]
237241
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
238242
public void AllocationQuantumIsNotAnIssueForNetCore21Plus(IToolchain toolchain)
239243
{
@@ -298,7 +302,8 @@ public void Allocate()
298302
}
299303
}
300304

301-
[TheoryEnvSpecific("Full Framework cannot measure precisely enough", EnvRequirement.DotNetCoreOnly)]
305+
[Theory(Skip = "System.Runtime.InteropServices.RuntimeInformation allocates unexpectedly"), MemberData(nameof(GetToolchains))]
306+
//[TheoryEnvSpecific("Full Framework cannot measure precisely enough", EnvRequirement.DotNetCoreOnly)]
302307
[MemberData(nameof(GetToolchains))]
303308
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
304309
public void MemoryDiagnoserIsAccurateForMultiThreadedBenchmarks(IToolchain toolchain)

0 commit comments

Comments
 (0)