diff --git a/src/BenchmarkDotNet.Disassembler.x64/DataContracts.cs b/src/BenchmarkDotNet.Disassembler.x64/DataContracts.cs index 6eb048d21b..f088430970 100644 --- a/src/BenchmarkDotNet.Disassembler.x64/DataContracts.cs +++ b/src/BenchmarkDotNet.Disassembler.x64/DataContracts.cs @@ -32,12 +32,16 @@ public abstract class Asm : SourceCode public class IntelAsm : Asm { public Instruction Instruction { get; set; } + + public override string ToString() => Instruction.ToString(); } public class Arm64Asm : Asm { #if !CLRMDV1 // don't include it in ClrMD V1 disassembler that supports only x86 and x64 public Gee.External.Capstone.Arm64.Arm64Instruction Instruction { get; set; } + + public override string ToString() => Instruction.ToString(); #endif } diff --git a/tests/BenchmarkDotNet.IntegrationTests/DisassemblyDiagnoserTests.cs b/tests/BenchmarkDotNet.IntegrationTests/DisassemblyDiagnoserTests.cs index dbb9ae3c8b..aaed87f626 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/DisassemblyDiagnoserTests.cs +++ b/tests/BenchmarkDotNet.IntegrationTests/DisassemblyDiagnoserTests.cs @@ -11,8 +11,8 @@ using BenchmarkDotNet.Environments; using BenchmarkDotNet.IntegrationTests.Xunit; using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Portability; using BenchmarkDotNet.Tests.Loggers; -using BenchmarkDotNet.Tests.XUnit; using Xunit; using Xunit.Abstractions; @@ -20,23 +20,29 @@ namespace BenchmarkDotNet.IntegrationTests { public class DisassemblyDiagnoserTests : BenchmarkTestExecutor { - private const string WindowsOnly = "Disassembler supports only Windows"; - public DisassemblyDiagnoserTests(ITestOutputHelper output) : base(output) { } public static IEnumerable GetAllJits() - => new[] + { + if (RuntimeInformation.IsFullFramework) { -#if NETFRAMEWORK - new object[] { Jit.LegacyJit, Platform.X86, ClrRuntime.Net462 }, // 32bit LegacyJit for desktop .NET - new object[] { Jit.LegacyJit, Platform.X64, ClrRuntime.Net462 }, // 64bit LegacyJit for desktop .NET - - new object[] { Jit.RyuJit, Platform.X64, ClrRuntime.Net462 }, // RyuJit for desktop .NET -#endif - new object[] { Jit.RyuJit, Platform.X64, CoreRuntime.Core70 }, // .NET Core - - // we could add new object[] { Jit.Llvm, Platform.X64, new MonoRuntime() } here but our CI would need to have Mono installed.. - }; + yield return new object[] { Jit.LegacyJit, Platform.X86, ClrRuntime.Net462 }; // 32bit LegacyJit for desktop .NET + yield return new object[] { Jit.LegacyJit, Platform.X64, ClrRuntime.Net462 }; // 64bit LegacyJit for desktop .NET + yield return new object[] { Jit.RyuJit, Platform.X64, ClrRuntime.Net462 }; // RyuJit for desktop .NET + } + else if (RuntimeInformation.IsNetCore) + { + if (RuntimeInformation.GetCurrentPlatform() is Platform.X86 or Platform.X64) + { + yield return new object[] { Jit.RyuJit, Platform.X64, CoreRuntime.Core70 }; // .NET Core x64 + } + else if (RuntimeInformation.GetCurrentPlatform() is Platform.Arm64 && RuntimeInformation.IsLinux()) + { + yield return new object[] { Jit.RyuJit, Platform.Arm64, CoreRuntime.Core70 }; // .NET Core arm64 + } + } + // we could add new object[] { Jit.Llvm, Platform.X64, new MonoRuntime() } here but our CI would need to have Mono installed.. + } public class WithCalls { @@ -71,11 +77,14 @@ public void Recursive() [MethodImpl(MethodImplOptions.NoInlining)] public void Benchmark(bool justAnOverload) { } // we need to test overloads (#562) } - [TheoryWindowsOnly(WindowsOnly)] + [Theory] [MemberData(nameof(GetAllJits))] [Trait(Constants.Category, Constants.BackwardCompatibilityCategory)] public void CanDisassembleAllMethodCalls(Jit jit, Platform platform, Runtime runtime) { + if (RuntimeInformation.IsMacOS()) return; // currently not supported + if (RuntimeInformation.IsLinux()) return; // https://github.com/dotnet/BenchmarkDotNet/issues/2223 + var disassemblyDiagnoser = new DisassemblyDiagnoser( new DisassemblyDiagnoserConfig(printSource: true, maxDepth: 3)); @@ -88,11 +97,13 @@ public void CanDisassembleAllMethodCalls(Jit jit, Platform platform, Runtime run AssertDisassembled(disassemblyDiagnoser, $"{nameof(WithCalls.Recursive)}()"); } - [TheoryWindowsOnly(WindowsOnly)] + [Theory] [MemberData(nameof(GetAllJits))] [Trait(Constants.Category, Constants.BackwardCompatibilityCategory)] public void CanDisassembleAllMethodCallsUsingFilters(Jit jit, Platform platform, Runtime runtime) { + if (RuntimeInformation.IsMacOS()) return; // currently not supported + var disassemblyDiagnoser = new DisassemblyDiagnoser( new DisassemblyDiagnoserConfig(printSource: true, maxDepth: 1, filters: new[] { "*WithCalls*" })); @@ -111,11 +122,13 @@ public void CanDisassembleAllMethodCallsUsingFilters(Jit jit, Platform platform, public T Create() => new T(); } - [TheoryWindowsOnly(WindowsOnly)] + [Theory] [MemberData(nameof(GetAllJits))] [Trait(Constants.Category, Constants.BackwardCompatibilityCategory)] public void CanDisassembleGenericTypes(Jit jit, Platform platform, Runtime runtime) { + if (RuntimeInformation.IsMacOS()) return; // currently not supported + var disassemblyDiagnoser = new DisassemblyDiagnoser( new DisassemblyDiagnoserConfig(printSource: true, maxDepth: 3)); @@ -131,11 +144,14 @@ public class WithInlineable [Benchmark] public void JustReturn() { } } - [TheoryWindowsOnly(WindowsOnly)] + [Theory] [MemberData(nameof(GetAllJits))] [Trait(Constants.Category, Constants.BackwardCompatibilityCategory)] public void CanDisassembleInlinableBenchmarks(Jit jit, Platform platform, Runtime runtime) { + if (RuntimeInformation.IsMacOS()) return; // currently not supported + if (RuntimeInformation.IsLinux()) return; // https://github.com/dotnet/BenchmarkDotNet/issues/2223 + var disassemblyDiagnoser = new DisassemblyDiagnoser( new DisassemblyDiagnoserConfig(printSource: true, maxDepth: 3)); @@ -143,7 +159,7 @@ public void CanDisassembleInlinableBenchmarks(Jit jit, Platform platform, Runtim var disassemblyResult = disassemblyDiagnoser.Results.Values.Single(result => result.Methods.Count(method => method.Name.Contains(nameof(WithInlineable.JustReturn))) == 1); - Assert.Contains(disassemblyResult.Methods, method => method.Maps.Any(map => map.SourceCodes.OfType().All(asm => asm.Instruction.ToString().Contains("ret")))); + Assert.Contains(disassemblyResult.Methods, method => method.Maps.Any(map => map.SourceCodes.OfType().All(asm => asm.ToString().Contains("ret")))); } private IConfig CreateConfig(Jit jit, Platform platform, Runtime runtime, IDiagnoser disassemblyDiagnoser, RunStrategy runStrategy) @@ -159,9 +175,10 @@ private IConfig CreateConfig(Jit jit, Platform platform, Runtime runtime, IDiagn private void AssertDisassembled(DisassemblyDiagnoser diagnoser, string methodSignature) { - Assert.True(diagnoser.Results.Single().Value - .Methods.Any(method => method.Name.EndsWith(methodSignature) && method.Maps.Any(map => map.SourceCodes.Any())), - $"{methodSignature} is missing"); + DisassemblyResult result = diagnoser.Results.Single().Value; + + Assert.Contains(methodSignature, result.Methods.Select(m => m.Name.Split('.').Last()).ToArray()); + Assert.Contains(result.Methods.Single(m => m.Name.EndsWith(methodSignature)).Maps, map => map.SourceCodes.Any()); } } } \ No newline at end of file