Skip to content

Commit 61b3c56

Browse files
authored
Update SDK to .NET 7, re-enable NativeAOT tests, fix some other tests (#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
1 parent 7982b8c commit 61b3c56

File tree

26 files changed

+70
-68
lines changed

26 files changed

+70
-68
lines changed

build/Build.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
66
</PropertyGroup>
77
<ItemGroup>

build/Program.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public class BuildContext : FrostingContext
6363
public DotNetCoreMSBuildSettings MsBuildSettings { get; }
6464

6565
private IAppVeyorProvider AppVeyor => this.BuildSystem().AppVeyor;
66-
public bool IsOnAppVeyorAndNotPr => AppVeyor.IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest;
66+
public bool IsRunningOnAppVeyor => AppVeyor.IsRunningOnAppVeyor;
67+
public bool IsOnAppVeyorAndNotPr => IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest;
6768
public bool IsOnAppVeyorAndBdnNightlyCiCd => IsOnAppVeyorAndNotPr && AppVeyor.Environment.Repository.Branch == "master" && this.IsRunningOnWindows();
6869
public bool IsLocalBuild => this.BuildSystem().IsLocalBuild;
6970
public bool IsCiBuild => !this.BuildSystem().IsLocalBuild;
@@ -338,8 +339,8 @@ public override bool ShouldRun(BuildContext context)
338339
public override void Run(BuildContext context)
339340
{
340341
var targetFrameworks = context.IsRunningOnWindows()
341-
? new[] { "net462", "net6.0" }
342-
: new[] { "net6.0" };
342+
? new[] { "net462", "net7.0" }
343+
: new[] { "net7.0" };
343344

344345
foreach (var targetFramework in targetFrameworks)
345346
context.RunTests(context.UnitTestsProjectFile, "UnitTests", targetFramework);
@@ -352,7 +353,7 @@ public class SlowFullFrameworkTestsTask : FrostingTask<BuildContext>
352353
{
353354
public override bool ShouldRun(BuildContext context)
354355
{
355-
return !context.SkipTests && !context.SkipSlowTests && context.IsRunningOnWindows();
356+
return !context.SkipTests && !context.SkipSlowTests && context.IsRunningOnWindows() && !context.IsRunningOnAppVeyor;
356357
}
357358

358359
public override void Run(BuildContext context)
@@ -361,9 +362,9 @@ public override void Run(BuildContext context)
361362
}
362363
}
363364

364-
[TaskName("SlowTestsNet5")]
365+
[TaskName("SlowTestsNetCore")]
365366
[IsDependentOn(typeof(BuildTask))]
366-
public class SlowTestsNet5Task : FrostingTask<BuildContext>
367+
public class SlowTestsNetCoreTask : FrostingTask<BuildContext>
367368
{
368369
public override bool ShouldRun(BuildContext context)
369370
{
@@ -372,14 +373,14 @@ public override bool ShouldRun(BuildContext context)
372373

373374
public override void Run(BuildContext context)
374375
{
375-
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net6.0");
376+
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net7.0");
376377
}
377378
}
378379

379380
[TaskName("AllTests")]
380381
[IsDependentOn(typeof(FastTestsTask))]
381382
[IsDependentOn(typeof(SlowFullFrameworkTestsTask))]
382-
[IsDependentOn(typeof(SlowTestsNet5Task))]
383+
[IsDependentOn(typeof(SlowTestsNetCoreTask))]
383384
public class AllTestsTask : FrostingTask<BuildContext>
384385
{
385386
}

build/global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.201",
3+
"version": "7.0.100",
44
"rollForward": "disable"
55
}
66
}

docs/_redirects/RedirectGenerator/RedirectGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net7.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

samples/BenchmarkDotNet.Samples.FSharp/BenchmarkDotNet.Samples.FSharp.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66
<PropertyGroup>
77
<OutputType>Exe</OutputType>
8-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
8+
<TargetFrameworks>net462;net7.0</TargetFrameworks>
99
</PropertyGroup>
1010
<ItemGroup>
1111
<Compile Include="Program.fs" />

samples/BenchmarkDotNet.Samples/BenchmarkDotNet.Samples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\build\common.props" />
33
<PropertyGroup>
44
<AssemblyTitle>BenchmarkDotNet.Samples</AssemblyTitle>
5-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
5+
<TargetFrameworks>net462;net7.0</TargetFrameworks>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<AssemblyName>BenchmarkDotNet.Samples</AssemblyName>
88
<OutputType>Exe</OutputType>

src/BenchmarkDotNet/Engines/GcStats.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public struct GcStats : IEquatable<GcStats>
1313

1414
public static readonly long AllocationQuantum = CalculateAllocationQuantumSize();
1515

16+
#if !NET6_0_OR_GREATER
1617
private static readonly Func<long> GetAllocatedBytesForCurrentThreadDelegate = CreateGetAllocatedBytesForCurrentThreadDelegate();
1718
private static readonly Func<bool, long> GetTotalAllocatedBytesDelegate = CreateGetTotalAllocatedBytesDelegate();
18-
19+
#endif
1920
public static readonly GcStats Empty = new GcStats(0, 0, 0, 0, 0);
2021

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

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

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

152157
private static Func<long> CreateGetAllocatedBytesForCurrentThreadDelegate()

src/BenchmarkDotNet/Toolchains/Executor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
34
using System.IO;
45
using System.IO.Pipes;
@@ -67,7 +68,17 @@ private static ExecuteResult Execute(Process process, BenchmarkCase benchmarkCas
6768
{
6869
logger.WriteLineInfo($"// Execute: {process.StartInfo.FileName} {process.StartInfo.Arguments} in {process.StartInfo.WorkingDirectory}");
6970

70-
process.Start();
71+
try
72+
{
73+
process.Start();
74+
}
75+
catch (Win32Exception ex)
76+
{
77+
logger.WriteLineError($"// Failed to start the benchmark process: {ex}");
78+
79+
return new ExecuteResult(true, null, null, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), launchIndex);
80+
}
81+
7182
processOutputReader.BeginRead();
7283

7384
process.EnsureHighPriority(logger);

tests/BenchmarkDotNet.IntegrationTests.ConfigPerAssembly/BenchmarkDotNet.IntegrationTests.ConfigPerAssembly.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\build\common.props" />
33
<PropertyGroup>
44
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.ConfigPerAssembly</AssemblyTitle>
5-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
5+
<TargetFrameworks>net462;net7.0</TargetFrameworks>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<AssemblyName>BenchmarkDotNet.IntegrationTests.ConfigPerAssembly</AssemblyName>
88
<PackageId>BenchmarkDotNet.IntegrationTests.ConfigPerAssembly</PackageId>

tests/BenchmarkDotNet.IntegrationTests.DisabledOptimizations/BenchmarkDotNet.IntegrationTests.DisabledOptimizations.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\build\common.props" />
33
<PropertyGroup>
44
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.DisabledOptimizations</AssemblyTitle>
5-
<TargetFrameworks>net462;net6.0</TargetFrameworks>
5+
<TargetFrameworks>net462;net7.0</TargetFrameworks>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<AssemblyName>BenchmarkDotNet.IntegrationTests.DisabledOptimizations</AssemblyName>
88
<PackageId>BenchmarkDotNet.IntegrationTests.DisabledOptimizations</PackageId>

0 commit comments

Comments
 (0)