Skip to content

Commit a098bc1

Browse files
authored
tests can't assume x64 hardware (#2235)
1 parent 9684485 commit a098bc1

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

tests/BenchmarkDotNet.IntegrationTests/JitRuntimeValidationTest.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System.Linq;
2-
using BenchmarkDotNet.Attributes;
1+
using BenchmarkDotNet.Attributes;
32
using BenchmarkDotNet.Columns;
43
using BenchmarkDotNet.Configs;
54
using BenchmarkDotNet.Environments;
65
using BenchmarkDotNet.Jobs;
6+
using BenchmarkDotNet.Portability;
77
using BenchmarkDotNet.Tests.Loggers;
88
using BenchmarkDotNet.Tests.XUnit;
9+
using System.Collections.Generic;
910
using Xunit;
1011
using Xunit.Abstractions;
1112

@@ -39,10 +40,15 @@ public void CheckClrOnWindows(Jit jit, Platform platform, string errorMessage)
3940
// Verify(Runtime.Mono, jit, platform, errorMessage);
4041
// }
4142

43+
public static IEnumerable<object[]> CheckCore_Arguments()
44+
{
45+
yield return new object[] { Jit.LegacyJit, Platform.X86, ToolchainSupportsOnlyRyuJit };
46+
yield return new object[] { Jit.LegacyJit, Platform.X64, ToolchainSupportsOnlyRyuJit };
47+
yield return new object[] { Jit.RyuJit, RuntimeInformation.GetCurrentPlatform(), null };
48+
}
49+
4250
[Theory]
43-
[InlineData(Jit.LegacyJit, Platform.X86, ToolchainSupportsOnlyRyuJit)]
44-
[InlineData(Jit.LegacyJit, Platform.X64, ToolchainSupportsOnlyRyuJit)]
45-
[InlineData(Jit.RyuJit, Platform.X64, null)]
51+
[MemberData(nameof(CheckCore_Arguments))]
4652
public void CheckCore(Jit jit, Platform platform, string errorMessage)
4753
{
4854
Verify(CoreRuntime.Core70, jit, platform, errorMessage);

tests/BenchmarkDotNet.IntegrationTests/ProcessorArchitectureTest.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
2+
using System.Collections.Generic;
23
using BenchmarkDotNet.Attributes;
34
using BenchmarkDotNet.Configs;
45
using BenchmarkDotNet.Environments;
56
using BenchmarkDotNet.Jobs;
7+
using BenchmarkDotNet.Portability;
68
using BenchmarkDotNet.Tests.Loggers;
79
using Xunit;
810
using Xunit.Abstractions;
@@ -15,17 +17,27 @@ public ProcessorArchitectureTest(ITestOutputHelper outputHelper) : base(outputHe
1517
{
1618
}
1719

18-
[Fact]
19-
public void SpecifiedProcessorArchitectureMustBeRespected()
20+
public static IEnumerable<object[]> Arguments()
2021
{
21-
#if NETFRAMEWORK // dotnet cli does not support x86 compilation so far, so I disable this test
22-
Verify(Platform.X86, typeof(X86Benchmark));
23-
#endif
24-
Verify(Platform.X64, typeof(X64Benchmark));
25-
Verify(Platform.AnyCpu, typeof(AnyCpuBenchmark));
22+
Platform current = RuntimeInformation.GetCurrentPlatform();
23+
24+
if (RuntimeInformation.IsFullFramework && current is Platform.X64 or Platform.X86)
25+
{
26+
// RoslynToolchain (used for Full Framework) supports building and running for different architecture than the host process
27+
yield return new object[]
28+
{
29+
current is Platform.X64 ? Platform.X86 : Platform.X64,
30+
current is Platform.X64 ? typeof(Benchmark_32bit) : typeof(Benchmark_64bit)
31+
};
32+
}
33+
34+
yield return new object[] { current, IntPtr.Size == 8 ? typeof(Benchmark_64bit) : typeof(Benchmark_32bit) };
35+
yield return new object[] { Platform.AnyCpu, typeof(AnyCpuBenchmark) };
2636
}
2737

28-
private void Verify(Platform platform, Type benchmark)
38+
[Theory]
39+
[MemberData(nameof(Arguments))]
40+
public void SpecifiedProcessorArchitectureMustBeRespected(Platform platform, Type benchmark)
2941
{
3042
var config = ManualConfig.CreateEmpty()
3143
.AddJob(Job.Dry.WithPlatform(platform))
@@ -35,10 +47,10 @@ private void Verify(Platform platform, Type benchmark)
3547
CanExecute(benchmark, config, fullValidation: true);
3648
}
3749

38-
public class X86Benchmark
50+
public class Benchmark_32bit
3951
{
4052
[Benchmark]
41-
public void _32Bit()
53+
public void Verify()
4254
{
4355
if (IntPtr.Size != 4)
4456
{
@@ -47,10 +59,10 @@ public void _32Bit()
4759
}
4860
}
4961

50-
public class X64Benchmark
62+
public class Benchmark_64bit
5163
{
5264
[Benchmark]
53-
public void _64Bit()
65+
public void Verify()
5466
{
5567
if (IntPtr.Size != 8)
5668
{

0 commit comments

Comments
 (0)