Skip to content

Commit

Permalink
Update SDK to .NET 7, re-enable NativeAOT tests, fix some other tests (
Browse files Browse the repository at this point in the history
…dotnet#2209)

* update SDK to 7.0

* update samples and test projects to .NET 7

* bump NativeAOT tests to .NET 7, re-enable some of them

* handle edge case to get the tests passing again

* don't run Full Framework tests on AppVeyor to avoid build timeouts

* avoid reflection when possible

* NativeAOT is not supported on macOS with .NET 7

* run fewer tests on AppVeyor to avoid getting timeouts
  • Loading branch information
adamsitnik authored Dec 1, 2022
1 parent 7982b8c commit 61b3c56
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 68 deletions.
2 changes: 1 addition & 1 deletion build/Build.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
Expand Down
17 changes: 9 additions & 8 deletions build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class BuildContext : FrostingContext
public DotNetCoreMSBuildSettings MsBuildSettings { get; }

private IAppVeyorProvider AppVeyor => this.BuildSystem().AppVeyor;
public bool IsOnAppVeyorAndNotPr => AppVeyor.IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest;
public bool IsRunningOnAppVeyor => AppVeyor.IsRunningOnAppVeyor;
public bool IsOnAppVeyorAndNotPr => IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest;
public bool IsOnAppVeyorAndBdnNightlyCiCd => IsOnAppVeyorAndNotPr && AppVeyor.Environment.Repository.Branch == "master" && this.IsRunningOnWindows();
public bool IsLocalBuild => this.BuildSystem().IsLocalBuild;
public bool IsCiBuild => !this.BuildSystem().IsLocalBuild;
Expand Down Expand Up @@ -338,8 +339,8 @@ public override bool ShouldRun(BuildContext context)
public override void Run(BuildContext context)
{
var targetFrameworks = context.IsRunningOnWindows()
? new[] { "net462", "net6.0" }
: new[] { "net6.0" };
? new[] { "net462", "net7.0" }
: new[] { "net7.0" };

foreach (var targetFramework in targetFrameworks)
context.RunTests(context.UnitTestsProjectFile, "UnitTests", targetFramework);
Expand All @@ -352,7 +353,7 @@ public class SlowFullFrameworkTestsTask : FrostingTask<BuildContext>
{
public override bool ShouldRun(BuildContext context)
{
return !context.SkipTests && !context.SkipSlowTests && context.IsRunningOnWindows();
return !context.SkipTests && !context.SkipSlowTests && context.IsRunningOnWindows() && !context.IsRunningOnAppVeyor;
}

public override void Run(BuildContext context)
Expand All @@ -361,9 +362,9 @@ public override void Run(BuildContext context)
}
}

[TaskName("SlowTestsNet5")]
[TaskName("SlowTestsNetCore")]
[IsDependentOn(typeof(BuildTask))]
public class SlowTestsNet5Task : FrostingTask<BuildContext>
public class SlowTestsNetCoreTask : FrostingTask<BuildContext>
{
public override bool ShouldRun(BuildContext context)
{
Expand All @@ -372,14 +373,14 @@ public override bool ShouldRun(BuildContext context)

public override void Run(BuildContext context)
{
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net6.0");
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net7.0");
}
}

[TaskName("AllTests")]
[IsDependentOn(typeof(FastTestsTask))]
[IsDependentOn(typeof(SlowFullFrameworkTestsTask))]
[IsDependentOn(typeof(SlowTestsNet5Task))]
[IsDependentOn(typeof(SlowTestsNetCoreTask))]
public class AllTestsTask : FrostingTask<BuildContext>
{
}
Expand Down
2 changes: 1 addition & 1 deletion build/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.201",
"version": "7.0.100",
"rollForward": "disable"
}
}
2 changes: 1 addition & 1 deletion docs/_redirects/RedirectGenerator/RedirectGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet.Samples</AssemblyTitle>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>BenchmarkDotNet.Samples</AssemblyName>
<OutputType>Exe</OutputType>
Expand Down
7 changes: 6 additions & 1 deletion src/BenchmarkDotNet/Engines/GcStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public struct GcStats : IEquatable<GcStats>

public static readonly long AllocationQuantum = CalculateAllocationQuantumSize();

#if !NET6_0_OR_GREATER
private static readonly Func<long> GetAllocatedBytesForCurrentThreadDelegate = CreateGetAllocatedBytesForCurrentThreadDelegate();
private static readonly Func<bool, long> GetTotalAllocatedBytesDelegate = CreateGetTotalAllocatedBytesDelegate();

#endif
public static readonly GcStats Empty = new GcStats(0, 0, 0, 0, 0);

private GcStats(int gen0Collections, int gen1Collections, int gen2Collections, long allocatedBytes, long totalOperations)
Expand Down Expand Up @@ -142,11 +143,15 @@ private static long GetAllocatedBytes()
if (RuntimeInformation.IsFullFramework) // it can be a .NET app consuming our .NET Standard package
return AppDomain.CurrentDomain.MonitoringTotalAllocatedMemorySize;

#if NET6_0_OR_GREATER
return GC.GetTotalAllocatedBytes(precise: true);
#else
if (GetTotalAllocatedBytesDelegate != null) // it's .NET Core 3.0 with the new API available
return GetTotalAllocatedBytesDelegate.Invoke(true); // true for the "precise" argument

// https://apisof.net/catalog/System.GC.GetAllocatedBytesForCurrentThread() is not part of the .NET Standard, so we use reflection to call it..
return GetAllocatedBytesForCurrentThreadDelegate.Invoke();
#endif
}

private static Func<long> CreateGetAllocatedBytesForCurrentThreadDelegate()
Expand Down
13 changes: 12 additions & 1 deletion src/BenchmarkDotNet/Toolchains/Executor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
Expand Down Expand Up @@ -67,7 +68,17 @@ private static ExecuteResult Execute(Process process, BenchmarkCase benchmarkCas
{
logger.WriteLineInfo($"// Execute: {process.StartInfo.FileName} {process.StartInfo.Arguments} in {process.StartInfo.WorkingDirectory}");

process.Start();
try
{
process.Start();
}
catch (Win32Exception ex)
{
logger.WriteLineError($"// Failed to start the benchmark process: {ex}");

return new ExecuteResult(true, null, null, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), launchIndex);
}

processOutputReader.BeginRead();

process.EnsureHighPriority(logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.ConfigPerAssembly</AssemblyTitle>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>BenchmarkDotNet.IntegrationTests.ConfigPerAssembly</AssemblyName>
<PackageId>BenchmarkDotNet.IntegrationTests.ConfigPerAssembly</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.DisabledOptimizations</AssemblyTitle>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>BenchmarkDotNet.IntegrationTests.DisabledOptimizations</AssemblyName>
<PackageId>BenchmarkDotNet.IntegrationTests.DisabledOptimizations</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.EnabledOptimizations</AssemblyTitle>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>BenchmarkDotNet.IntegrationTests.EnabledOptimizations</AssemblyName>
<PackageId>BenchmarkDotNet.IntegrationTests.EnabledOptimizations</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<PublicSign>false</PublicSign>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.ManualRunning</AssemblyTitle>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>BenchmarkDotNet.IntegrationTests.ManualRunning</AssemblyName>
<PackageId>BenchmarkDotNet.IntegrationTests.ManualRunning</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.Static</AssemblyTitle>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>BenchmarkDotNet.IntegrationTests.Static</AssemblyName>
<PackageId>BenchmarkDotNet.IntegrationTests.Static</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\BenchmarkDotNet\BenchmarkDotNet.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<AssemblyTitle>BenchmarkDotNet.IntegrationTests</AssemblyTitle>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net462;net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>BenchmarkDotNet.IntegrationTests</AssemblyName>
<PackageId>BenchmarkDotNet.IntegrationTests</PackageId>
Expand Down
10 changes: 5 additions & 5 deletions tests/BenchmarkDotNet.IntegrationTests/BuildTimeoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public void WhenBuildTakesMoreTimeThanTheTimeoutTheBuildIsCancelled()
{
if (!RuntimeInformation.Is64BitPlatform()) // NativeAOT does not support 32bit yet
return;
if (RuntimeInformation.IsMacOSX())
return; // currently not supported

// we use NativeAOT on purpose because it takes a LOT of time to build it
// so we can be sure that timeout = 1s should fail!
Expand All @@ -27,12 +29,10 @@ public void WhenBuildTakesMoreTimeThanTheTimeoutTheBuildIsCancelled()
var config = ManualConfig.CreateEmpty()
.WithBuildTimeout(timeout)
.AddJob(Job.Dry
.WithRuntime(NativeAotRuntime.Net60)
.WithRuntime(NativeAotRuntime.Net70)
.WithToolchain(NativeAotToolchain.CreateBuilder()
.UseNuGet(
"6.0.0-rc.1.21420.1", // we test against specific version to keep this test stable
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json") // using old feed that supports net6.0
.TargetFrameworkMoniker("net6.0")
.UseNuGet("7.0.0", "https://api.nuget.org/v3/index.json")
.TargetFrameworkMoniker("net7.0")
.ToToolchain()));

var summary = CanExecute<NativeAotBenchmark>(config, fullValidation: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IEnumerable<object[]> GetAllJits()

new object[] { Jit.RyuJit, Platform.X64, ClrRuntime.Net462 }, // RyuJit for desktop .NET
#endif
new object[] { Jit.RyuJit, Platform.X64, CoreRuntime.Core60 }, // .NET Core
new object[] { Jit.RyuJit, Platform.X64, CoreRuntime.Core70 }, // .NET Core

// we could add new object[] { Jit.Llvm, Platform.X64, new MonoRuntime() } here but our CI would need to have Mono installed..
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void CheckClrOnWindows(Jit jit, Platform platform, string errorMessage)
[InlineData(Jit.RyuJit, Platform.X64, null)]
public void CheckCore(Jit jit, Platform platform, string errorMessage)
{
Verify(CoreRuntime.Core60, jit, platform, errorMessage);
Verify(CoreRuntime.Core70, jit, platform, errorMessage);
}

private void Verify(Runtime runtime, Jit jit, Platform platform, string errorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void BenchmarkCanAllocateMoreThan2Gb()
var summary = BenchmarkRunner
.Run<NeedsMoreThan2GB>(
ManualConfig.CreateEmpty()
.AddJob(Job.Dry.WithRuntime(CoreRuntime.Core60).WithPlatform(Platform.X64).WithId("Core"))
.AddJob(Job.Dry.WithRuntime(ClrRuntime.Net462).WithPlatform(Platform.X86).WithLargeAddressAware().WithId("Framework"))
.AddJob(Job.Dry.WithRuntime(CoreRuntime.Core70).WithPlatform(Platform.X64).WithId("Core"))
.AddJob(Job.Dry.WithRuntime(ClrRuntime.Net462).WithPlatform(Platform.X86).WithGcServer(false).WithLargeAddressAware().WithId("Framework"))
.AddColumnProvider(DefaultColumnProviders.Instance)
.AddLogger(new OutputLogger(output)));

Expand All @@ -47,7 +47,7 @@ public void BenchmarkCanAllocateMoreThan2Gb()
.Any());

Assert.Contains(".NET Framework", summary.AllRuntimes);
Assert.Contains(".NET 6.0", summary.AllRuntimes);
Assert.Contains(".NET 7.0", summary.AllRuntimes);
}
}

Expand Down
28 changes: 8 additions & 20 deletions tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,21 @@ public void MemoryDiagnoserIsAccurate(IToolchain toolchain)
{
{ nameof(AccurateAllocations.EightBytesArray), 8 + objectAllocationOverhead + arraySizeOverhead },
{ nameof(AccurateAllocations.SixtyFourBytesArray), 64 + objectAllocationOverhead + arraySizeOverhead },

{ nameof(AccurateAllocations.AllocateTask), CalculateRequiredSpace<Task<int>>() },
});
}

[FactDotNetCoreOnly("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 6.0)")]
[FactDotNetCoreOnly("We don't want to test NativeAOT twice (for .NET Framework 4.6.2 and .NET 7.0)")]
public void MemoryDiagnoserSupportsNativeAOT()
{
if (ContinuousIntegration.IsAppVeyorOnWindows()) // too time consuming for AppVeyor (1h limit)
return;
if (RuntimeInformation.GetCurrentPlatform() == Platform.Arm64 && RuntimeInformation.IsMacOSX())
return; // Native compilation does not support targeting osx-arm64 yet. https://github.com/dotnet/corert/issues/4589
if (RuntimeInformation.IsMacOSX())
return; // currently not supported
if (ContinuousIntegration.IsAppVeyorOnWindows())
return; // timeouts

MemoryDiagnoserIsAccurate(
NativeAotToolchain.CreateBuilder()
.UseNuGet(
"6.0.0-rc.1.21420.1", // we test against specific version to keep this test stable
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json")
.UseNuGet("7.0.0", "https://api.nuget.org/v3/index.json")
.ToToolchain());
}

Expand Down Expand Up @@ -221,9 +218,6 @@ public byte[] SixtyFourBytesArray()
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
public void AllocationQuantumIsNotAnIssueForNetCore21Plus(IToolchain toolchain)
{
if (toolchain is NativeAotToolchain) // the fix has not yet been backported to NativeAOT
return;

long objectAllocationOverhead = IntPtr.Size * 2; // pointer to method table + object header word
long arraySizeOverhead = IntPtr.Size; // array length

Expand Down Expand Up @@ -263,9 +257,6 @@ public void Allocate()
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
public void MemoryDiagnoserIsAccurateForMultiThreadedBenchmarks(IToolchain toolchain)
{
if (toolchain is NativeAotToolchain) // the API has not been yet ported to NativeAOT
return;

long objectAllocationOverhead = IntPtr.Size * 2; // pointer to method table + object header word
long arraySizeOverhead = IntPtr.Size; // array length
long memoryAllocatedPerArray = (MultiThreadedAllocation.Size + objectAllocationOverhead + arraySizeOverhead);
Expand All @@ -287,11 +278,6 @@ private void AssertAllocations(IToolchain toolchain, Type benchmarkType, Diction

foreach (var benchmarkAllocationsValidator in benchmarksAllocationsValidators)
{
// NativeAOT is missing some of the CoreCLR threading/task related perf improvements, so sizeof(Task<int>) calculated for CoreCLR < sizeof(Task<int>) on CoreRT
// see https://github.com/dotnet/corert/issues/5705 for more
if (benchmarkAllocationsValidator.Key == nameof(AccurateAllocations.AllocateTask) && toolchain is NativeAotToolchain)
continue;

var allocatingBenchmarks = benchmarks.BenchmarksCases.Where(benchmark => benchmark.DisplayInfo.Contains(benchmarkAllocationsValidator.Key));

foreach (var benchmark in allocatingBenchmarks)
Expand All @@ -315,6 +301,8 @@ private IConfig CreateConfig(IToolchain toolchain)
.WithWarmupCount(0) // don't run warmup to save some time for our CI runs
.WithIterationCount(1) // single iteration is enough for us
.WithGcForce(false)
.WithGcServer(false)
.WithGcConcurrent(false)
.WithEnvironmentVariable("COMPlus_TieredCompilation", "0") // Tiered JIT can allocate some memory on a background thread, let's disable it to make our tests less flaky (#1542)
.WithToolchain(toolchain))
.AddColumnProvider(DefaultColumnProviders.Instance)
Expand Down
4 changes: 2 additions & 2 deletions tests/BenchmarkDotNet.IntegrationTests/MonoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace BenchmarkDotNet.IntegrationTests
public class MonoTests : BenchmarkTestExecutor
{
[FactDotNetCoreOnly("UseMonoRuntime option is available in .NET Core only starting from .NET 6")]
public void Mono60IsSupported()
public void Mono70IsSupported()
{
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(MonoRuntime.Mono60));
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(MonoRuntime.Mono70));
CanExecute<MonoBenchmark>(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void SingleBenchmarkCanBeExecutedForMultipleRuntimes()
var summary = BenchmarkRunner
.Run<C>(
ManualConfig.CreateEmpty()
.AddJob(Job.Dry.WithRuntime(CoreRuntime.Core60).WithPlatform(Platform.X64).WithId("Core"))
.AddJob(Job.Dry.WithRuntime(CoreRuntime.Core70).WithPlatform(Platform.X64).WithId("Core"))
.AddJob(Job.Dry.WithRuntime(ClrRuntime.Net462).WithId("Framework"))
.AddColumnProvider(DefaultColumnProviders.Instance)
.AddLogger(new OutputLogger(output)));
Expand All @@ -51,7 +51,7 @@ public void SingleBenchmarkCanBeExecutedForMultipleRuntimes()
.Any());

Assert.Contains(".NET Framework", summary.AllRuntimes);
Assert.Contains(".NET 6.0", summary.AllRuntimes);
Assert.Contains(".NET 7.0", summary.AllRuntimes);
}
}

Expand Down
Loading

0 comments on commit 61b3c56

Please sign in to comment.