-
-
Notifications
You must be signed in to change notification settings - Fork 987
/
Copy pathProcessorArchitectureTest.cs
82 lines (73 loc) · 2.62 KB
/
ProcessorArchitectureTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
namespace BenchmarkDotNet.IntegrationTests
{
public class ProcessorArchitectureTest : BenchmarkTestExecutor
{
public ProcessorArchitectureTest(ITestOutputHelper outputHelper) : base(outputHelper)
{
}
public static IEnumerable<object[]> Arguments()
{
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) };
}
[Theory]
[MemberData(nameof(Arguments))]
public void SpecifiedProcessorArchitectureMustBeRespected(Platform platform, Type benchmark)
{
var config = ManualConfig.CreateEmpty()
.AddJob(Job.Dry.WithPlatform(platform))
.AddLogger(new OutputLogger(Output)); // make sure we get an output in the TestRunner log
// CanExecute ensures that at least one benchmark has executed successfully
CanExecute(benchmark, config, fullValidation: true);
}
public class Benchmark_32bit
{
[Benchmark]
public void Verify()
{
if (IntPtr.Size != 4)
{
throw new InvalidOperationException("32 bit failed!");
}
}
}
public class Benchmark_64bit
{
[Benchmark]
public void Verify()
{
if (IntPtr.Size != 8)
{
throw new InvalidOperationException("64 bit failed!");
}
}
}
public class AnyCpuBenchmark
{
[Benchmark]
public void AnyCpu()
{
}
}
}
}