-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add tests for multiple in-process diagnosers with varying run modes #2857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
431b88d
Initial plan
Copilot 33f392c
Add tests for multiple in-process diagnosers with varying run modes
Copilot 6b21e82
Consolidate tests as theories and use base mock diagnoser
Copilot 2a9c805
Fix handler contract and use loops for all run mode combinations
Copilot c5be18c
Remove unused class, consolidate diagnosers, and add SeparateLogic tests
Copilot 74a9854
Fix MockInProcessDiagnoser result and SeparateLogic handling
Copilot b848941
Remove redundant InProcess diagnoser tests
Copilot b82e47c
Rename MultipleInProcessDiagnosersTests to InProcessDiagnoserTests
timcassell 093d57c
Remove unused index parameter and count=2 test cases
Copilot 709242a
Add verification that handlers are called at correct times
Copilot 41b812a
Fix handler timing verification to use serialized results
Copilot bb2ee34
Revert "Fix handler timing verification to use serialized results"
timcassell 91564d7
Revert "Add verification that handlers are called at correct times"
timcassell a22e9aa
Test diagnoser timing.
timcassell 7ffc08f
Expect SeparateLogic to work.
timcassell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
tests/BenchmarkDotNet.IntegrationTests/InProcessDiagnoserTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Columns; | ||
| using BenchmarkDotNet.Configs; | ||
| using BenchmarkDotNet.IntegrationTests.Diagnosers; | ||
| using BenchmarkDotNet.Jobs; | ||
| using BenchmarkDotNet.Tests.Loggers; | ||
| using BenchmarkDotNet.Toolchains; | ||
| using BenchmarkDotNet.Toolchains.InProcess.Emit; | ||
| using BenchmarkDotNet.Toolchains.InProcess.NoEmit; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
| using RunMode = BenchmarkDotNet.Diagnosers.RunMode; | ||
|
|
||
| namespace BenchmarkDotNet.IntegrationTests; | ||
|
|
||
| public class InProcessDiagnoserTests : BenchmarkTestExecutor | ||
| { | ||
| public InProcessDiagnoserTests(ITestOutputHelper output) : base(output) { } | ||
|
|
||
| private static readonly RunMode[] AllRunModes = { RunMode.NoOverhead, RunMode.ExtraRun, RunMode.None, RunMode.SeparateLogic }; | ||
|
|
||
| private static IEnumerable<BaseMockInProcessDiagnoser[]> GetDiagnoserCombinations(int count) | ||
| { | ||
| if (count == 1) | ||
| { | ||
| foreach (var runMode in AllRunModes) | ||
| { | ||
| yield return [CreateDiagnoser(runMode, 0)]; | ||
| } | ||
| } | ||
| else if (count == 2) | ||
| { | ||
| foreach (var runMode1 in AllRunModes) | ||
| { | ||
| foreach (var runMode2 in AllRunModes) | ||
| { | ||
| yield return [CreateDiagnoser(runMode1, 0), CreateDiagnoser(runMode2, 1)]; | ||
| } | ||
| } | ||
| } | ||
| else if (count == 3) | ||
| { | ||
| foreach (var runMode1 in AllRunModes) | ||
| { | ||
| foreach (var runMode2 in AllRunModes) | ||
| { | ||
| foreach (var runMode3 in AllRunModes) | ||
| { | ||
| yield return [CreateDiagnoser(runMode1, 0), CreateDiagnoser(runMode2, 1), CreateDiagnoser(runMode3, 2)]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static BaseMockInProcessDiagnoser CreateDiagnoser(RunMode runMode, int index) | ||
timcassell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return runMode switch | ||
| { | ||
| RunMode.NoOverhead => new MockInProcessDiagnoser(), | ||
| RunMode.ExtraRun => new MockInProcessDiagnoserExtraRun(), | ||
| RunMode.None => new MockInProcessDiagnoserNone(), | ||
| RunMode.SeparateLogic => new MockInProcessDiagnoserSeparateLogic(), | ||
| _ => throw new ArgumentException($"Unsupported run mode: {runMode}") | ||
| }; | ||
| } | ||
|
|
||
| public static IEnumerable<object[]> GetTestCombinations() | ||
| { | ||
| var toolchains = new IToolchain[] | ||
| { | ||
| InProcessEmitToolchain.DontLogOutput, | ||
| new InProcessNoEmitToolchain(TimeSpan.Zero, true), | ||
| null // Default toolchain | ||
| }; | ||
|
|
||
| var counts = new[] { 1, 2, 3 }; | ||
|
|
||
| foreach (var toolchain in toolchains) | ||
| { | ||
| foreach (var count in counts) | ||
| { | ||
| foreach (var diagnosers in GetDiagnoserCombinations(count)) | ||
| { | ||
| yield return new object[] { diagnosers, toolchain }; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(GetTestCombinations))] | ||
| public void MultipleInProcessDiagnosersWork(BaseMockInProcessDiagnoser[] diagnosers, IToolchain toolchain) | ||
| { | ||
| var logger = new OutputLogger(Output); | ||
| var config = CreateConfig(logger, toolchain); | ||
|
|
||
| foreach (var diagnoser in diagnosers) | ||
| { | ||
| config = config.AddDiagnoser(diagnoser); | ||
| } | ||
|
|
||
| var summary = CanExecute<SimpleBenchmark>(config); | ||
|
|
||
| foreach (var diagnoser in diagnosers) | ||
| { | ||
| // NoOverhead, ExtraRun, and SeparateLogic should collect results | ||
| // None should not collect results | ||
| bool shouldHaveResults = diagnoser.DiagnoserRunMode != RunMode.None; | ||
|
|
||
| if (shouldHaveResults) | ||
| { | ||
| if (diagnoser.DiagnoserRunMode == RunMode.SeparateLogic) | ||
| { | ||
| // SeparateLogic is not yet implemented for in-process diagnosers, so we expect it to fail | ||
| // This is marked as a known limitation to be fixed in the future | ||
| Assert.Empty(diagnoser.Results); // Expected to fail until SeparateLogic is implemented | ||
| } | ||
| else | ||
| { | ||
| Assert.NotEmpty(diagnoser.Results); | ||
| Assert.Equal(summary.BenchmarksCases.Length, diagnoser.Results.Count); | ||
| Assert.All(diagnoser.Results.Values, result => Assert.Equal(diagnoser.ExpectedResult, result)); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| Assert.Empty(diagnoser.Results); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private IConfig CreateConfig(OutputLogger logger, IToolchain toolchain) | ||
| { | ||
| var job = Job.Dry; | ||
| if (toolchain != null) | ||
| { | ||
| job = job.WithToolchain(toolchain); | ||
| } | ||
|
|
||
| return new ManualConfig() | ||
| .AddJob(job) | ||
| .AddLogger(logger) | ||
| .AddColumnProvider(DefaultColumnProviders.Instance); | ||
| } | ||
|
|
||
| public class SimpleBenchmark | ||
| { | ||
| private int counter; | ||
|
|
||
| [Benchmark] | ||
| public void BenchmarkMethod() | ||
| { | ||
| Interlocked.Increment(ref counter); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.