diff --git a/CHANGELOG.md b/CHANGELOG.md index 9210c0e..863f448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to BenchmarkGate are documented here. ## [Unreleased] +### Added +- Core `BenchmarkRun` and `BenchmarkEnvironment` domain model types (ADR-0006 Decisions 1–2): report-level environment metadata, kept separate from `BenchmarkIdentity`/`BenchmarkObservation`. `BenchmarkRun.Environment` is `null` when no environment document was supplied at all, distinct from a present-but-partial `BenchmarkEnvironment` where some dimensions were unavailable. +- New Core-owned enums `BenchmarkArchitecture` and `BenchmarkHardwareTimerKind`, normalized from BenchmarkDotNet's own vocabulary (`BenchmarkDotNet.Environments.Platform`, `Perfolizer.Horology.HardwareTimerKind`) so persisted history is never coupled to a BenchmarkDotNet dependency. Both include an `Unknown` member for forward compatibility with future BenchmarkDotNet values. +- New Core enums `EnvironmentCompatibilityRole` (`Filter`/`Advisory`/`None`) and `EnvironmentDimension` (one member per `BenchmarkEnvironment` field), laying groundwork for environment coherence and compatibility comparison in later v0.5.0 issues. + ### Fixed - `BdnParameterStringParser` no longer silently discards malformed BenchmarkDotNet parameter fragments (e.g. `N1000000` missing its `=`, or `=1000000` with an empty diff --git a/src/BenchmarkGate.Core/Model/BenchmarkArchitecture.cs b/src/BenchmarkGate.Core/Model/BenchmarkArchitecture.cs new file mode 100644 index 0000000..e18f7ae --- /dev/null +++ b/src/BenchmarkGate.Core/Model/BenchmarkArchitecture.cs @@ -0,0 +1,51 @@ +namespace Bijecta.BenchmarkGate.Core.Model; + +/// +/// Processor architecture reported for a benchmark's execution environment, normalized from +/// BenchmarkDotNet's own architecture vocabulary (BenchmarkDotNet.Environments.Platform) into a +/// Core-owned type so persisted history is never coupled to a BenchmarkDotNet dependency. +/// Mapping into this enum is the BenchmarkDotNet adapter's responsibility, not Core's. +/// +public enum BenchmarkArchitecture +{ + /// Platform-agnostic build target ("AnyCPU"). Retained for source-vocabulary fidelity; not expected on a running process's reported architecture. + AnyCpu, + + /// 32-bit x86. + X86, + + /// 64-bit x86 (x64/AMD64). + X64, + + /// 32-bit ARM. + Arm, + + /// 64-bit ARM. + Arm64, + + /// WebAssembly. + Wasm, + + /// IBM Z (s390x). + S390x, + + /// LoongArch, 64-bit. + LoongArch64, + + /// 32-bit ARMv6. + Armv6, + + /// PowerPC 64-bit, little-endian. + Ppc64le, + + /// RISC-V, 64-bit. + RiscV64, + + /// + /// A recognized-but-unmapped architecture value. Reserved for forward compatibility: + /// persisted history can outlive the BenchmarkGate version that wrote it, so a future + /// BenchmarkDotNet architecture this version's adapter doesn't recognize maps here instead + /// of failing deserialization or being coerced into an unrelated known value. + /// + Unknown +} \ No newline at end of file diff --git a/src/BenchmarkGate.Core/Model/BenchmarkEnvironment.cs b/src/BenchmarkGate.Core/Model/BenchmarkEnvironment.cs new file mode 100644 index 0000000..e552a96 --- /dev/null +++ b/src/BenchmarkGate.Core/Model/BenchmarkEnvironment.cs @@ -0,0 +1,42 @@ +namespace Bijecta.BenchmarkGate.Core.Model; + +/// +/// Benchmark execution-environment metadata captured for a single BenchmarkDotNet report +/// (ADR-0006 Decision 2). Every property is independently nullable: a property is +/// when the source document did not provide that specific field, distinct +/// from the whole environment being absent (see , which is +/// when no environment document was supplied at all). This type owns no +/// parsing, validation, or comparison behavior — those are added by later issues in the v0.5.0 +/// chain. +/// +/// The BenchmarkDotNet product caption reported in the source document (e.g. "BenchmarkDotNet"). +/// The BenchmarkDotNet version string that produced the report. +/// The operating system version string reported for the run. +/// The processor name reported for the run. +/// The number of physical processors reported for the run. +/// The number of physical cores reported for the run. +/// The number of logical cores reported for the run. +/// The .NET runtime version string reported for the run. +/// The processor architecture reported for the run, normalized into a Core-owned value by the BenchmarkDotNet adapter. +/// Whether a debugger was attached to the process during the run, if reported. +/// Whether the RyuJIT compiler was in use during the run, if reported. +/// The build configuration reported for the run (e.g. "RELEASE"). +/// The .NET CLI (SDK) version string reported for the run. +/// The chronometer frequency, in hertz, reported for the run. +/// The hardware timer substrate reported for the run, normalized into a Core-owned value by the BenchmarkDotNet adapter. +public sealed record BenchmarkEnvironment( + string? BenchmarkDotNetCaption, + string? BenchmarkDotNetVersion, + string? OsVersion, + string? ProcessorName, + int? PhysicalProcessorCount, + int? PhysicalCoreCount, + int? LogicalCoreCount, + string? RuntimeVersion, + BenchmarkArchitecture? Architecture, + bool? HasAttachedDebugger, + bool? HasRyuJit, + string? Configuration, + string? DotNetCliVersion, + long? ChronometerFrequencyHertz, + BenchmarkHardwareTimerKind? HardwareTimerKind); \ No newline at end of file diff --git a/src/BenchmarkGate.Core/Model/BenchmarkHardwareTimerKind.cs b/src/BenchmarkGate.Core/Model/BenchmarkHardwareTimerKind.cs new file mode 100644 index 0000000..d8ea209 --- /dev/null +++ b/src/BenchmarkGate.Core/Model/BenchmarkHardwareTimerKind.cs @@ -0,0 +1,32 @@ +namespace Bijecta.BenchmarkGate.Core.Model; + +/// +/// Hardware timer substrate used by BenchmarkDotNet's chronometer, normalized from +/// BenchmarkDotNet's own vocabulary (Perfolizer.Horology.HardwareTimerKind) into a Core-owned +/// type. is a real BenchmarkDotNet-emitted sentinel (confirmed from a live +/// 0.15.8 fixture, not a placeholder) representing "recognized but semantically unavailable +/// evidence" — an ordinary known value for environment coherence checks, but never a +/// compatibility Match. What means for compatibility comparison is out of +/// scope here; that's added by the comparison logic in a later v0.5.0 issue. +/// +public enum BenchmarkHardwareTimerKind +{ + /// Operating system timer. + System, + + /// Time Stamp Counter. + Tsc, + + /// ACPI power management timer. + Acpi, + + /// High Precision Event Timer. + Hpet, + + /// + /// BenchmarkDotNet's own producer-defined sentinel for a chronometer frequency it could not + /// attribute to a specific known timer substrate. Recognized and preserved as a known value, + /// not a parse failure. + /// + Unknown +} \ No newline at end of file diff --git a/src/BenchmarkGate.Core/Model/BenchmarkRun.cs b/src/BenchmarkGate.Core/Model/BenchmarkRun.cs new file mode 100644 index 0000000..9714425 --- /dev/null +++ b/src/BenchmarkGate.Core/Model/BenchmarkRun.cs @@ -0,0 +1,15 @@ +namespace Bijecta.BenchmarkGate.Core.Model; + +/// +/// A single parsed BenchmarkDotNet report: its execution-environment metadata, if any, and its +/// observations (ADR-0006 Decision 1). is when +/// no environment document was supplied at all (e.g. a non-full BDN JSON export, or a +/// pre-v0.5.0 baseline) — distinct from a present-but-partial +/// where a document existed but some dimensions were unavailable. These two states are never +/// merged. +/// +/// The execution-environment metadata captured for this report, or if no environment document was supplied at all. +/// The benchmark observations parsed from this report. +public sealed record BenchmarkRun( + BenchmarkEnvironment? Environment, + IReadOnlyList Observations); \ No newline at end of file diff --git a/src/BenchmarkGate.Core/Model/EnvironmentCompatibilityRole.cs b/src/BenchmarkGate.Core/Model/EnvironmentCompatibilityRole.cs new file mode 100644 index 0000000..cc67a86 --- /dev/null +++ b/src/BenchmarkGate.Core/Model/EnvironmentCompatibilityRole.cs @@ -0,0 +1,19 @@ +namespace Bijecta.BenchmarkGate.Core.Model; + +/// +/// The role a single plays in environment compatibility +/// comparison (ADR-0006 Decision 2). This issue defines the role as data only; what a role value +/// does during comparison (e.g. a Filter mismatch forcing an Incompatible verdict) is comparison +/// logic added in a later issue. +/// +public enum EnvironmentCompatibilityRole +{ + /// A mismatch on this dimension can drive an environment compatibility verdict to Incompatible. + Filter, + + /// A mismatch on this dimension is surfaced for visibility but never by itself drives an Incompatible verdict. + Advisory, + + /// This dimension does not participate in compatibility comparison at all. + None +} \ No newline at end of file diff --git a/src/BenchmarkGate.Core/Model/EnvironmentDimension.cs b/src/BenchmarkGate.Core/Model/EnvironmentDimension.cs new file mode 100644 index 0000000..b2e92a2 --- /dev/null +++ b/src/BenchmarkGate.Core/Model/EnvironmentDimension.cs @@ -0,0 +1,54 @@ +namespace Bijecta.BenchmarkGate.Core.Model; + +/// +/// One member per captured field of (ADR-0006 Decision 2), +/// used to identify a specific dimension of environment metadata independent of its runtime +/// value — e.g. when reporting which dimension caused a coherence or compatibility outcome. +/// +public enum EnvironmentDimension +{ + /// Corresponds to . + BenchmarkDotNetCaption, + + /// Corresponds to . + BenchmarkDotNetVersion, + + /// Corresponds to . + OsVersion, + + /// Corresponds to . + ProcessorName, + + /// Corresponds to . + PhysicalProcessorCount, + + /// Corresponds to . + PhysicalCoreCount, + + /// Corresponds to . + LogicalCoreCount, + + /// Corresponds to . + RuntimeVersion, + + /// Corresponds to . + Architecture, + + /// Corresponds to . + HasAttachedDebugger, + + /// Corresponds to . + HasRyuJit, + + /// Corresponds to . + Configuration, + + /// Corresponds to . + DotNetCliVersion, + + /// Corresponds to . + ChronometerFrequencyHertz, + + /// Corresponds to . + HardwareTimerKind +} \ No newline at end of file diff --git a/tests/BenchmarkGate.Core.Tests/Model/BenchmarkEnvironmentTests.cs b/tests/BenchmarkGate.Core.Tests/Model/BenchmarkEnvironmentTests.cs new file mode 100644 index 0000000..5aa937c --- /dev/null +++ b/tests/BenchmarkGate.Core.Tests/Model/BenchmarkEnvironmentTests.cs @@ -0,0 +1,81 @@ +using Bijecta.BenchmarkGate.Core.Model; +using FluentAssertions; +using Xunit; + +namespace Bijecta.BenchmarkGate.Core.Tests.Model; + +public sealed class BenchmarkEnvironmentTests +{ + [Fact] + public void RecordEquality_AllFieldsEqual_AreEqual() + { + var left = CreateFullEnvironment(); + var right = CreateFullEnvironment(); + + left.Should().Be(right); + } + + [Fact] + public void RecordEquality_OneFieldDiffers_AreNotEqual() + { + var left = CreateFullEnvironment(); + var right = CreateFullEnvironment() with { ProcessorName = "Different Processor" }; + + left.Should().NotBe(right); + } + + [Fact] + public void AllProperties_CanBeNull() + { + var environment = new BenchmarkEnvironment( + BenchmarkDotNetCaption: null, + BenchmarkDotNetVersion: null, + OsVersion: null, + ProcessorName: null, + PhysicalProcessorCount: null, + PhysicalCoreCount: null, + LogicalCoreCount: null, + RuntimeVersion: null, + Architecture: null, + HasAttachedDebugger: null, + HasRyuJit: null, + Configuration: null, + DotNetCliVersion: null, + ChronometerFrequencyHertz: null, + HardwareTimerKind: null); + + environment.BenchmarkDotNetCaption.Should().BeNull(); + environment.Architecture.Should().BeNull(); + environment.HardwareTimerKind.Should().BeNull(); + environment.ChronometerFrequencyHertz.Should().BeNull(); + } + + [Fact] + public void With_ProducesNewInstance_LeavesOriginalUnchanged() + { + var original = CreateFullEnvironment(); + + var modified = original with { HardwareTimerKind = BenchmarkHardwareTimerKind.Tsc }; + + original.HardwareTimerKind.Should().Be(BenchmarkHardwareTimerKind.Unknown); + modified.HardwareTimerKind.Should().Be(BenchmarkHardwareTimerKind.Tsc); + } + + private static BenchmarkEnvironment CreateFullEnvironment() => + new( + BenchmarkDotNetCaption: "BenchmarkDotNet", + BenchmarkDotNetVersion: "0.15.8", + OsVersion: "Windows 11 (10.0.26100.8875/24H2/2024Update/HudsonValley)", + ProcessorName: "Intel Core Ultra 7 155H", + PhysicalProcessorCount: 1, + PhysicalCoreCount: 16, + LogicalCoreCount: 22, + RuntimeVersion: ".NET 10.0.10 (10.0.10, 10.0.1026.32716)", + Architecture: BenchmarkArchitecture.X64, + HasAttachedDebugger: false, + HasRyuJit: true, + Configuration: "RELEASE", + DotNetCliVersion: "10.0.302", + ChronometerFrequencyHertz: 10_000_000, + HardwareTimerKind: BenchmarkHardwareTimerKind.Unknown); +} \ No newline at end of file diff --git a/tests/BenchmarkGate.Core.Tests/Model/BenchmarkRunTests.cs b/tests/BenchmarkGate.Core.Tests/Model/BenchmarkRunTests.cs new file mode 100644 index 0000000..e7deda3 --- /dev/null +++ b/tests/BenchmarkGate.Core.Tests/Model/BenchmarkRunTests.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using Bijecta.BenchmarkGate.Core.Model; +using FluentAssertions; +using Xunit; + +namespace Bijecta.BenchmarkGate.Core.Tests.Model; + +public sealed class BenchmarkRunTests +{ + [Fact] + public void Environment_Null_MeansNoEnvironmentDocumentSupplied() + { + var run = new BenchmarkRun(Environment: null, Observations: new List()); + + run.Environment.Should().BeNull(); + } + + [Fact] + public void Environment_PresentButAllFieldsNull_IsDistinctFromNoEnvironment() + { + var partialEnvironment = new BenchmarkEnvironment( + BenchmarkDotNetCaption: null, + BenchmarkDotNetVersion: null, + OsVersion: null, + ProcessorName: null, + PhysicalProcessorCount: null, + PhysicalCoreCount: null, + LogicalCoreCount: null, + RuntimeVersion: null, + Architecture: null, + HasAttachedDebugger: null, + HasRyuJit: null, + Configuration: null, + DotNetCliVersion: null, + ChronometerFrequencyHertz: null, + HardwareTimerKind: null); + + var runWithoutEnvironment = new BenchmarkRun(Environment: null, Observations: new List()); + var runWithPartialEnvironment = new BenchmarkRun(Environment: partialEnvironment, Observations: new List()); + + runWithoutEnvironment.Environment.Should().BeNull(); + runWithPartialEnvironment.Environment.Should().NotBeNull(); + runWithoutEnvironment.Should().NotBe(runWithPartialEnvironment); + } + + [Fact] + public void Observations_PreservesReadOnlyListReference() + { + IReadOnlyList observations = new List(); + + var run = new BenchmarkRun(Environment: null, Observations: observations); + + run.Observations.Should().BeSameAs(observations); + } +} \ No newline at end of file diff --git a/tests/BenchmarkGate.Core.Tests/Model/EnvironmentEnumsTests.cs b/tests/BenchmarkGate.Core.Tests/Model/EnvironmentEnumsTests.cs new file mode 100644 index 0000000..8fc948b --- /dev/null +++ b/tests/BenchmarkGate.Core.Tests/Model/EnvironmentEnumsTests.cs @@ -0,0 +1,45 @@ +using System; +using Bijecta.BenchmarkGate.Core.Model; +using FluentAssertions; +using Xunit; + +namespace Bijecta.BenchmarkGate.Core.Tests.Model; + +public sealed class EnvironmentEnumsTests +{ + [Fact] + public void BenchmarkHardwareTimerKind_HasExpectedMembers() + { + var members = Enum.GetNames(); + + members.Should().Equal("System", "Tsc", "Acpi", "Hpet", "Unknown"); + } + + [Fact] + public void BenchmarkArchitecture_HasExpectedMembers() + { + var members = Enum.GetNames(); + + members.Should().Equal( + "AnyCpu", "X86", "X64", "Arm", "Arm64", "Wasm", + "S390x", "LoongArch64", "Armv6", "Ppc64le", "RiscV64", "Unknown"); + } + + [Fact] + public void EnvironmentCompatibilityRole_HasExactlyThreeMembers() + { + var members = Enum.GetNames(); + + members.Should().Equal("Filter", "Advisory", "None"); + } + + [Fact] + public void EnvironmentDimension_HasOneMemberPerBenchmarkEnvironmentProperty() + { + var dimensionCount = Enum.GetValues().Length; + var propertyCount = typeof(BenchmarkEnvironment).GetProperties().Length; + + dimensionCount.Should().Be(15); + dimensionCount.Should().Be(propertyCount); + } +} \ No newline at end of file