Skip to content

Commit 7982b8c

Browse files
authored
Fix Full Framework tests (#2208)
* run tests as 4.6.2, not 4.6.1 * fix tests that were broken recently and went undetected: * default TFM when using CoreRun is now net8.0 * don't load Capstone.NET types when using diassembler to avoid strong signature error * pass mandatory tfm to ClrMdV1 disassembler * disable flaky tests
1 parent 47b8b72 commit 7982b8c

File tree

12 files changed

+39
-22
lines changed

12 files changed

+39
-22
lines changed

build/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,17 @@ public override bool ShouldRun(BuildContext context)
338338
public override void Run(BuildContext context)
339339
{
340340
var targetFrameworks = context.IsRunningOnWindows()
341-
? new[] { "net461", "net6.0" }
341+
? new[] { "net462", "net6.0" }
342342
: new[] { "net6.0" };
343343

344344
foreach (var targetFramework in targetFrameworks)
345345
context.RunTests(context.UnitTestsProjectFile, "UnitTests", targetFramework);
346346
}
347347
}
348348

349-
[TaskName("SlowTestsNet461")]
349+
[TaskName("SlowFullFrameworkTests")]
350350
[IsDependentOn(typeof(BuildTask))]
351-
public class SlowTestsNet461Task : FrostingTask<BuildContext>
351+
public class SlowFullFrameworkTestsTask : FrostingTask<BuildContext>
352352
{
353353
public override bool ShouldRun(BuildContext context)
354354
{
@@ -357,7 +357,7 @@ public override bool ShouldRun(BuildContext context)
357357

358358
public override void Run(BuildContext context)
359359
{
360-
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net461");
360+
context.RunTests(context.IntegrationTestsProjectFile, "IntegrationTests", "net462");
361361
}
362362
}
363363

@@ -378,7 +378,7 @@ public override void Run(BuildContext context)
378378

379379
[TaskName("AllTests")]
380380
[IsDependentOn(typeof(FastTestsTask))]
381-
[IsDependentOn(typeof(SlowTestsNet461Task))]
381+
[IsDependentOn(typeof(SlowFullFrameworkTestsTask))]
382382
[IsDependentOn(typeof(SlowTestsNet5Task))]
383383
public class AllTestsTask : FrostingTask<BuildContext>
384384
{

src/BenchmarkDotNet.Disassembler.x64/ClrMdV1Disassembler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ private static IEnumerable<Asm> Decode(ulong startAddress, uint size, State stat
171171

172172
TryTranslateAddressToName(instruction, state, depth, currentMethod, out ulong referencedAddress);
173173

174-
yield return new Asm
174+
yield return new IntelAsm
175175
{
176176
InstructionPointer = instruction.IP,
177177
InstructionLength = instruction.Length,
178-
IntelInstruction = instruction,
178+
Instruction = instruction,
179179
ReferencedAddress = (referencedAddress > ushort.MaxValue) ? referencedAddress : null,
180180
};
181181
}

src/BenchmarkDotNet.Disassembler.x64/DataContracts.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ public class Sharp : SourceCode
2222
public int LineNumber { get; set; }
2323
}
2424

25-
public class Asm : SourceCode
25+
public abstract class Asm : SourceCode
2626
{
2727
public int InstructionLength { get; set; }
2828
public ulong? ReferencedAddress { get; set; }
2929
public bool IsReferencedAddressIndirect { get; set; }
30+
}
31+
32+
public class IntelAsm : Asm
33+
{
34+
public Instruction Instruction { get; set; }
35+
}
3036

31-
public Instruction? IntelInstruction { get; set; }
37+
public class Arm64Asm : Asm
38+
{
3239
#if !CLRMDV1
33-
public Gee.External.Capstone.Arm64.Arm64Instruction Arm64Instruction { get; set; }
40+
public Gee.External.Capstone.Arm64.Arm64Instruction Instruction { get; set; }
3441
#endif
3542
}
3643

@@ -44,7 +51,10 @@ public class Map
4451
[XmlArray("Instructions")]
4552
[XmlArrayItem(nameof(SourceCode), typeof(SourceCode))]
4653
[XmlArrayItem(nameof(Sharp), typeof(Sharp))]
47-
[XmlArrayItem(nameof(Asm), typeof(Asm))]
54+
[XmlArrayItem(nameof(IntelAsm), typeof(IntelAsm))]
55+
#if NET6_0_OR_GREATER // we can replace it with !CLRMDV1 when https://github.com/9ee1/Capstone.NET/issues/36 is solved
56+
[XmlArrayItem(nameof(Arm64Asm), typeof(Arm64Asm))]
57+
#endif
4858
public SourceCode[] SourceCodes { get; set; }
4959
}
5060

src/BenchmarkDotNet/Disassemblers/Arm64Disassembler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, Stat
232232

233233
accumulator.Feed(instruction);
234234

235-
yield return new Asm()
235+
yield return new Arm64Asm()
236236
{
237237
InstructionPointer = (ulong)instruction.Address,
238238
InstructionLength = instruction.Bytes.Length,
239-
Arm64Instruction = instruction,
239+
Instruction = instruction,
240240
ReferencedAddress = (address > ushort.MaxValue) ? address : null,
241241
IsReferencedAddressIndirect = isIndirect
242242
};

src/BenchmarkDotNet/Disassemblers/Arm64InstructionFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ internal static class Arm64InstructionFormatter
99
{
1010
// FormatterOptions is an Intel-specific concept that comes from the Iced library, but since our users can pass custom
1111
// Iced Formatter to DisassemblyDiagnoserConfig and it provides all the settings we need, we just reuse it here.
12-
internal static string Format(Asm asm, FormatterOptions formatterOptions,
12+
internal static string Format(Arm64Asm asm, FormatterOptions formatterOptions,
1313
bool printInstructionAddresses, uint pointerSize, IReadOnlyDictionary<ulong, string> symbols)
1414
{
1515
StringBuilder output = new ();
16-
Arm64Instruction instruction = asm.Arm64Instruction;
16+
Arm64Instruction instruction = asm.Instruction;
1717

1818
if (printInstructionAddresses)
1919
{

src/BenchmarkDotNet/Disassemblers/InstructionFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ internal static class CodeFormatter
99
internal static string Format(SourceCode sourceCode, Formatter formatter, bool printInstructionAddresses, uint pointerSize, IReadOnlyDictionary<ulong, string> symbols)
1010
=> sourceCode switch
1111
{
12-
Asm asm when asm.IntelInstruction.HasValue => IntelInstructionFormatter.Format(asm.IntelInstruction.Value, formatter, printInstructionAddresses, pointerSize),
13-
Asm asm when asm.Arm64Instruction is not null => Arm64InstructionFormatter.Format(asm, formatter.Options, printInstructionAddresses, pointerSize, symbols),
12+
IntelAsm intel => IntelInstructionFormatter.Format(intel.Instruction, formatter, printInstructionAddresses, pointerSize),
13+
Arm64Asm arm64 => Arm64InstructionFormatter.Format(arm64, formatter.Options, printInstructionAddresses, pointerSize, symbols),
1414
Sharp sharp => sharp.Text,
1515
MonoCode mono => mono.Text,
1616
_ => throw new NotSupportedException(),

src/BenchmarkDotNet/Disassemblers/IntelDisassembler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ protected override IEnumerable<Asm> Decode(byte[] code, ulong startAddress, Stat
8686
}
8787
}
8888

89-
yield return new Asm
89+
yield return new IntelAsm
9090
{
9191
InstructionPointer = instruction.IP,
9292
InstructionLength = instruction.Length,
93-
IntelInstruction = instruction,
93+
Instruction = instruction,
9494
ReferencedAddress = (address > ushort.MaxValue) ? address : null,
9595
IsReferencedAddressIndirect = isIndirect,
9696
};

src/BenchmarkDotNet/Disassemblers/WindowsDisassembler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ private string BuildArguments(DiagnoserActionParameters parameters, string resul
146146
.Append(' ')
147147
.Append(config.Syntax.ToString())
148148
.Append(' ')
149+
.Append(parameters.BenchmarkCase.Job.Environment.GetRuntime().MsBuildMoniker)
150+
.Append(' ')
149151
.Append(string.Join(" ", config.Filters.Select(Escape)))
150152
.ToString();
151153

tests/BenchmarkDotNet.IntegrationTests/BenchmarkSwitcherTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public void WhenUserCreatesStaticBenchmarkMethodWeDisplayAnError_FromAssembly()
332332
Assert.Contains("static", logger.GetLog());
333333
}
334334

335-
[Fact]
335+
[FactDotNetCoreOnly("For some reason this test is flaky on Full Framework")]
336336
public void WhenUserAddTheResumeAttributeAndRunTheBenchmarks()
337337
{
338338
var logger = new OutputLogger(Output);

tests/BenchmarkDotNet.IntegrationTests/DisassemblyDiagnoserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void CanDisassembleInlinableBenchmarks(Jit jit, Platform platform, Runtim
143143

144144
var disassemblyResult = disassemblyDiagnoser.Results.Values.Single(result => result.Methods.Count(method => method.Name.Contains(nameof(WithInlineable.JustReturn))) == 1);
145145

146-
Assert.Contains(disassemblyResult.Methods, method => method.Maps.Any(map => map.SourceCodes.OfType<Asm>().All(asm => asm.IntelInstruction.ToString().Contains("ret"))));
146+
Assert.Contains(disassemblyResult.Methods, method => method.Maps.Any(map => map.SourceCodes.OfType<IntelAsm>().All(asm => asm.Instruction.ToString().Contains("ret"))));
147147
}
148148

149149
private IConfig CreateConfig(Jit jit, Platform platform, Runtime runtime, IDiagnoser disassemblyDiagnoser, RunStrategy runStrategy)

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ [Benchmark] public void EmptyMethod() { }
123123
[Trait(Constants.Category, Constants.BackwardCompatibilityCategory)]
124124
public void EngineShouldNotInterfereAllocationResults(IToolchain toolchain)
125125
{
126+
if (RuntimeInformation.IsFullFramework && toolchain.IsInProcess)
127+
{
128+
return; // this test is flaky on Full Framework
129+
}
130+
126131
AssertAllocations(toolchain, typeof(NoAllocationsAtAll), new Dictionary<string, long>
127132
{
128133
{ nameof(NoAllocationsAtAll.EmptyMethod), 0 }

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void SpecifyingCoreRunWithFullFrameworkTargetsMostRecentTfm()
160160

161161
CoreRunToolchain coreRunToolchain = (CoreRunToolchain)coreRunJob.GetToolchain();
162162
DotNetCliGenerator generator = (DotNetCliGenerator)coreRunToolchain.Generator;
163-
Assert.Equal("net7.0", generator.TargetFrameworkMoniker);
163+
Assert.Equal("net8.0", generator.TargetFrameworkMoniker);
164164
}
165165

166166
[FactDotNetCoreOnly("It's impossible to determine TFM for CoreRunToolchain if host process is not .NET (Core) process")]

0 commit comments

Comments
 (0)