Skip to content

Commit

Permalink
tests can't assume x64 hardware (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Dec 23, 2022
1 parent 9684485 commit a098bc1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
16 changes: 11 additions & 5 deletions tests/BenchmarkDotNet.IntegrationTests/JitRuntimeValidationTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Tests.Loggers;
using BenchmarkDotNet.Tests.XUnit;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;

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

public static IEnumerable<object[]> CheckCore_Arguments()
{
yield return new object[] { Jit.LegacyJit, Platform.X86, ToolchainSupportsOnlyRyuJit };
yield return new object[] { Jit.LegacyJit, Platform.X64, ToolchainSupportsOnlyRyuJit };
yield return new object[] { Jit.RyuJit, RuntimeInformation.GetCurrentPlatform(), null };
}

[Theory]
[InlineData(Jit.LegacyJit, Platform.X86, ToolchainSupportsOnlyRyuJit)]
[InlineData(Jit.LegacyJit, Platform.X64, ToolchainSupportsOnlyRyuJit)]
[InlineData(Jit.RyuJit, Platform.X64, null)]
[MemberData(nameof(CheckCore_Arguments))]
public void CheckCore(Jit jit, Platform platform, string errorMessage)
{
Verify(CoreRuntime.Core70, jit, platform, errorMessage);
Expand Down
36 changes: 24 additions & 12 deletions tests/BenchmarkDotNet.IntegrationTests/ProcessorArchitectureTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Portability;
using BenchmarkDotNet.Tests.Loggers;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -15,17 +17,27 @@ public ProcessorArchitectureTest(ITestOutputHelper outputHelper) : base(outputHe
{
}

[Fact]
public void SpecifiedProcessorArchitectureMustBeRespected()
public static IEnumerable<object[]> Arguments()
{
#if NETFRAMEWORK // dotnet cli does not support x86 compilation so far, so I disable this test
Verify(Platform.X86, typeof(X86Benchmark));
#endif
Verify(Platform.X64, typeof(X64Benchmark));
Verify(Platform.AnyCpu, typeof(AnyCpuBenchmark));
Platform current = RuntimeInformation.GetCurrentPlatform();

if (RuntimeInformation.IsFullFramework && current is Platform.X64 or Platform.X86)
{
// RoslynToolchain (used for Full Framework) supports building and running for different architecture than the host process
yield return new object[]
{
current is Platform.X64 ? Platform.X86 : Platform.X64,
current is Platform.X64 ? typeof(Benchmark_32bit) : typeof(Benchmark_64bit)
};
}

yield return new object[] { current, IntPtr.Size == 8 ? typeof(Benchmark_64bit) : typeof(Benchmark_32bit) };
yield return new object[] { Platform.AnyCpu, typeof(AnyCpuBenchmark) };
}

private void Verify(Platform platform, Type benchmark)
[Theory]
[MemberData(nameof(Arguments))]
public void SpecifiedProcessorArchitectureMustBeRespected(Platform platform, Type benchmark)
{
var config = ManualConfig.CreateEmpty()
.AddJob(Job.Dry.WithPlatform(platform))
Expand All @@ -35,10 +47,10 @@ private void Verify(Platform platform, Type benchmark)
CanExecute(benchmark, config, fullValidation: true);
}

public class X86Benchmark
public class Benchmark_32bit
{
[Benchmark]
public void _32Bit()
public void Verify()
{
if (IntPtr.Size != 4)
{
Expand All @@ -47,10 +59,10 @@ public void _32Bit()
}
}

public class X64Benchmark
public class Benchmark_64bit
{
[Benchmark]
public void _64Bit()
public void Verify()
{
if (IntPtr.Size != 8)
{
Expand Down

0 comments on commit a098bc1

Please sign in to comment.