1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using BenchmarkDotNet . Attributes ;
3
4
using BenchmarkDotNet . Configs ;
4
5
using BenchmarkDotNet . Environments ;
5
6
using BenchmarkDotNet . Jobs ;
7
+ using BenchmarkDotNet . Portability ;
6
8
using BenchmarkDotNet . Tests . Loggers ;
7
9
using Xunit ;
8
10
using Xunit . Abstractions ;
@@ -15,17 +17,27 @@ public ProcessorArchitectureTest(ITestOutputHelper outputHelper) : base(outputHe
15
17
{
16
18
}
17
19
18
- [ Fact ]
19
- public void SpecifiedProcessorArchitectureMustBeRespected ( )
20
+ public static IEnumerable < object [ ] > Arguments ( )
20
21
{
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 ) } ;
26
36
}
27
37
28
- private void Verify ( Platform platform , Type benchmark )
38
+ [ Theory ]
39
+ [ MemberData ( nameof ( Arguments ) ) ]
40
+ public void SpecifiedProcessorArchitectureMustBeRespected ( Platform platform , Type benchmark )
29
41
{
30
42
var config = ManualConfig . CreateEmpty ( )
31
43
. AddJob ( Job . Dry . WithPlatform ( platform ) )
@@ -35,10 +47,10 @@ private void Verify(Platform platform, Type benchmark)
35
47
CanExecute ( benchmark , config , fullValidation : true ) ;
36
48
}
37
49
38
- public class X86Benchmark
50
+ public class Benchmark_32bit
39
51
{
40
52
[ Benchmark ]
41
- public void _32Bit ( )
53
+ public void Verify ( )
42
54
{
43
55
if ( IntPtr . Size != 4 )
44
56
{
@@ -47,10 +59,10 @@ public void _32Bit()
47
59
}
48
60
}
49
61
50
- public class X64Benchmark
62
+ public class Benchmark_64bit
51
63
{
52
64
[ Benchmark ]
53
- public void _64Bit ( )
65
+ public void Verify ( )
54
66
{
55
67
if ( IntPtr . Size != 8 )
56
68
{
0 commit comments