From f1e1e44a2b99945424e3837d6f42297ee1867ac2 Mon Sep 17 00:00:00 2001 From: Cameron Aavik Date: Thu, 15 Feb 2024 12:16:48 +1000 Subject: [PATCH 1/3] Add VSTest Adapter --- eng/Versions.props | 2 +- src/benchmarks/micro/MicroBenchmarks.csproj | 9 +++++--- .../micro/Properties/AssemblyInfo.cs | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/benchmarks/micro/Properties/AssemblyInfo.cs diff --git a/eng/Versions.props b/eng/Versions.props index 5fb125a8b6a..806575514f5 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -9,7 +9,7 @@ 9.0.0-preview.2.24109.4 9.0.0-preview.2.24109.4 - 0.13.11-nightly.20231126.107 + 0.13.13-nightly.20240213.132 9.0.0-preview.2.24109.4 9.0.0-preview.2.24109.4 diff --git a/src/benchmarks/micro/MicroBenchmarks.csproj b/src/benchmarks/micro/MicroBenchmarks.csproj index 3d9e9fd4286..1cd004a0df8 100644 --- a/src/benchmarks/micro/MicroBenchmarks.csproj +++ b/src/benchmarks/micro/MicroBenchmarks.csproj @@ -19,6 +19,7 @@ LatestMajor + false @@ -60,6 +61,7 @@ + @@ -73,6 +75,7 @@ + @@ -212,9 +215,9 @@ - - - + + + diff --git a/src/benchmarks/micro/Properties/AssemblyInfo.cs b/src/benchmarks/micro/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..b173785a201 --- /dev/null +++ b/src/benchmarks/micro/Properties/AssemblyInfo.cs @@ -0,0 +1,23 @@ +using System.IO; +using System; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Extensions; +using System.Collections.Immutable; + +[assembly: MicroBenchmarks.RecommendedConfigSource] + +namespace MicroBenchmarks +{ + [AttributeUsage(AttributeTargets.Assembly)] + class RecommendedConfigSourceAttribute : Attribute, IConfigSource + { + public RecommendedConfigSourceAttribute() + { + Config = RecommendedConfig.Create( + artifactsPath: new DirectoryInfo(Path.Combine(AppContext.BaseDirectory, "BenchmarkDotNet.Artifacts")), + mandatoryCategories: ImmutableHashSet.Create(Categories.Libraries, Categories.Runtime, Categories.ThirdParty)); + } + + public IConfig Config { get; } + } +} \ No newline at end of file From 7cfd55df78ae732e0291f5b450e45d477b258817 Mon Sep 17 00:00:00 2001 From: Cameron Aavik Date: Tue, 20 Feb 2024 07:24:34 +1000 Subject: [PATCH 2/3] Only use assembly config if in VSTest --- src/benchmarks/micro/Properties/AssemblyInfo.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/benchmarks/micro/Properties/AssemblyInfo.cs b/src/benchmarks/micro/Properties/AssemblyInfo.cs index b173785a201..205cc24cc74 100644 --- a/src/benchmarks/micro/Properties/AssemblyInfo.cs +++ b/src/benchmarks/micro/Properties/AssemblyInfo.cs @@ -3,19 +3,24 @@ using BenchmarkDotNet.Configs; using BenchmarkDotNet.Extensions; using System.Collections.Immutable; +using System.Reflection; -[assembly: MicroBenchmarks.RecommendedConfigSource] +[assembly: MicroBenchmarks.VSTestConfigSource] namespace MicroBenchmarks { [AttributeUsage(AttributeTargets.Assembly)] - class RecommendedConfigSourceAttribute : Attribute, IConfigSource + class VSTestConfigSourceAttribute : Attribute, IConfigSource { - public RecommendedConfigSourceAttribute() + public VSTestConfigSourceAttribute() { - Config = RecommendedConfig.Create( - artifactsPath: new DirectoryInfo(Path.Combine(AppContext.BaseDirectory, "BenchmarkDotNet.Artifacts")), - mandatoryCategories: ImmutableHashSet.Create(Categories.Libraries, Categories.Runtime, Categories.ThirdParty)); + // We only want to set an assembly-level config when it isn't being set by the entry point + // We check for this by seeing if the calling assembly is the same as the executing assembly + Config = Assembly.GetCallingAssembly() == Assembly.GetExecutingAssembly() + ? ManualConfig.CreateEmpty() + : RecommendedConfig.Create( + artifactsPath: new DirectoryInfo(Path.Combine(AppContext.BaseDirectory, "BenchmarkDotNet.Artifacts")), + mandatoryCategories: ImmutableHashSet.Create(Categories.Libraries, Categories.Runtime, Categories.ThirdParty)); } public IConfig Config { get; } From 7a24fcba8e78bd0c43f42112eb17ecd5ea9ddc31 Mon Sep 17 00:00:00 2001 From: Cameron Aavik Date: Tue, 20 Feb 2024 12:35:57 +1000 Subject: [PATCH 3/3] Use Entry Assembly, not Calling Assembly --- src/benchmarks/micro/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/benchmarks/micro/Properties/AssemblyInfo.cs b/src/benchmarks/micro/Properties/AssemblyInfo.cs index 205cc24cc74..08d47f66651 100644 --- a/src/benchmarks/micro/Properties/AssemblyInfo.cs +++ b/src/benchmarks/micro/Properties/AssemblyInfo.cs @@ -16,7 +16,7 @@ public VSTestConfigSourceAttribute() { // We only want to set an assembly-level config when it isn't being set by the entry point // We check for this by seeing if the calling assembly is the same as the executing assembly - Config = Assembly.GetCallingAssembly() == Assembly.GetExecutingAssembly() + Config = Assembly.GetEntryAssembly() == Assembly.GetExecutingAssembly() ? ManualConfig.CreateEmpty() : RecommendedConfig.Create( artifactsPath: new DirectoryInfo(Path.Combine(AppContext.BaseDirectory, "BenchmarkDotNet.Artifacts")),