Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions src/BenchmarkGate.Core/Model/BenchmarkArchitecture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace Bijecta.BenchmarkGate.Core.Model;

/// <summary>
/// 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.
/// </summary>
public enum BenchmarkArchitecture
{
/// <summary>Platform-agnostic build target ("AnyCPU"). Retained for source-vocabulary fidelity; not expected on a running process's reported architecture.</summary>
AnyCpu,

/// <summary>32-bit x86.</summary>
X86,

/// <summary>64-bit x86 (x64/AMD64).</summary>
X64,

/// <summary>32-bit ARM.</summary>
Arm,

/// <summary>64-bit ARM.</summary>
Arm64,

/// <summary>WebAssembly.</summary>
Wasm,

/// <summary>IBM Z (s390x).</summary>
S390x,

/// <summary>LoongArch, 64-bit.</summary>
LoongArch64,

/// <summary>32-bit ARMv6.</summary>
Armv6,

/// <summary>PowerPC 64-bit, little-endian.</summary>
Ppc64le,

/// <summary>RISC-V, 64-bit.</summary>
RiscV64,

/// <summary>
/// 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.
/// </summary>
Unknown
}
42 changes: 42 additions & 0 deletions src/BenchmarkGate.Core/Model/BenchmarkEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Bijecta.BenchmarkGate.Core.Model;

/// <summary>
/// Benchmark execution-environment metadata captured for a single BenchmarkDotNet report
/// (ADR-0006 Decision 2). Every property is independently nullable: a property is
/// <see langword="null"/> when the source document did not provide that specific field, distinct
/// from the whole environment being absent (see <see cref="BenchmarkRun.Environment"/>, which is
/// <see langword="null"/> 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.
/// </summary>
/// <param name="BenchmarkDotNetCaption">The BenchmarkDotNet product caption reported in the source document (e.g. "BenchmarkDotNet").</param>
/// <param name="BenchmarkDotNetVersion">The BenchmarkDotNet version string that produced the report.</param>
/// <param name="OsVersion">The operating system version string reported for the run.</param>
/// <param name="ProcessorName">The processor name reported for the run.</param>
/// <param name="PhysicalProcessorCount">The number of physical processors reported for the run.</param>
/// <param name="PhysicalCoreCount">The number of physical cores reported for the run.</param>
/// <param name="LogicalCoreCount">The number of logical cores reported for the run.</param>
/// <param name="RuntimeVersion">The .NET runtime version string reported for the run.</param>
/// <param name="Architecture">The processor architecture reported for the run, normalized into a Core-owned value by the BenchmarkDotNet adapter.</param>
/// <param name="HasAttachedDebugger">Whether a debugger was attached to the process during the run, if reported.</param>
/// <param name="HasRyuJit">Whether the RyuJIT compiler was in use during the run, if reported.</param>
/// <param name="Configuration">The build configuration reported for the run (e.g. "RELEASE").</param>
/// <param name="DotNetCliVersion">The .NET CLI (SDK) version string reported for the run.</param>
/// <param name="ChronometerFrequencyHertz">The chronometer frequency, in hertz, reported for the run.</param>
/// <param name="HardwareTimerKind">The hardware timer substrate reported for the run, normalized into a Core-owned value by the BenchmarkDotNet adapter.</param>
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);
32 changes: 32 additions & 0 deletions src/BenchmarkGate.Core/Model/BenchmarkHardwareTimerKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Bijecta.BenchmarkGate.Core.Model;

/// <summary>
/// Hardware timer substrate used by BenchmarkDotNet's chronometer, normalized from
/// BenchmarkDotNet's own vocabulary (Perfolizer.Horology.HardwareTimerKind) into a Core-owned
/// type. <see cref="Unknown"/> 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 <see cref="Unknown"/> means for compatibility comparison is out of
/// scope here; that's added by the comparison logic in a later v0.5.0 issue.
/// </summary>
public enum BenchmarkHardwareTimerKind
{
/// <summary>Operating system timer.</summary>
System,

/// <summary>Time Stamp Counter.</summary>
Tsc,

/// <summary>ACPI power management timer.</summary>
Acpi,

/// <summary>High Precision Event Timer.</summary>
Hpet,

/// <summary>
/// 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.
/// </summary>
Unknown
}
15 changes: 15 additions & 0 deletions src/BenchmarkGate.Core/Model/BenchmarkRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Bijecta.BenchmarkGate.Core.Model;

/// <summary>
/// A single parsed BenchmarkDotNet report: its execution-environment metadata, if any, and its
/// observations (ADR-0006 Decision 1). <see cref="Environment"/> is <see langword="null"/> 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 <see cref="BenchmarkEnvironment"/>
/// where a document existed but some dimensions were unavailable. These two states are never
/// merged.
/// </summary>
/// <param name="Environment">The execution-environment metadata captured for this report, or <see langword="null"/> if no environment document was supplied at all.</param>
/// <param name="Observations">The benchmark observations parsed from this report.</param>
public sealed record BenchmarkRun(
BenchmarkEnvironment? Environment,
IReadOnlyList<BenchmarkObservation> Observations);
19 changes: 19 additions & 0 deletions src/BenchmarkGate.Core/Model/EnvironmentCompatibilityRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Bijecta.BenchmarkGate.Core.Model;

/// <summary>
/// The role a single <see cref="EnvironmentDimension"/> 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.
/// </summary>
public enum EnvironmentCompatibilityRole
{
/// <summary>A mismatch on this dimension can drive an environment compatibility verdict to Incompatible.</summary>
Filter,

/// <summary>A mismatch on this dimension is surfaced for visibility but never by itself drives an Incompatible verdict.</summary>
Advisory,

/// <summary>This dimension does not participate in compatibility comparison at all.</summary>
None
}
54 changes: 54 additions & 0 deletions src/BenchmarkGate.Core/Model/EnvironmentDimension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace Bijecta.BenchmarkGate.Core.Model;

/// <summary>
/// One member per captured field of <see cref="BenchmarkEnvironment"/> (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.
/// </summary>
public enum EnvironmentDimension
{
/// <summary>Corresponds to <see cref="BenchmarkEnvironment.BenchmarkDotNetCaption"/>.</summary>
BenchmarkDotNetCaption,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.BenchmarkDotNetVersion"/>.</summary>
BenchmarkDotNetVersion,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.OsVersion"/>.</summary>
OsVersion,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.ProcessorName"/>.</summary>
ProcessorName,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.PhysicalProcessorCount"/>.</summary>
PhysicalProcessorCount,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.PhysicalCoreCount"/>.</summary>
PhysicalCoreCount,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.LogicalCoreCount"/>.</summary>
LogicalCoreCount,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.RuntimeVersion"/>.</summary>
RuntimeVersion,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.Architecture"/>.</summary>
Architecture,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.HasAttachedDebugger"/>.</summary>
HasAttachedDebugger,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.HasRyuJit"/>.</summary>
HasRyuJit,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.Configuration"/>.</summary>
Configuration,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.DotNetCliVersion"/>.</summary>
DotNetCliVersion,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.ChronometerFrequencyHertz"/>.</summary>
ChronometerFrequencyHertz,

/// <summary>Corresponds to <see cref="BenchmarkEnvironment.HardwareTimerKind"/>.</summary>
HardwareTimerKind
}
81 changes: 81 additions & 0 deletions tests/BenchmarkGate.Core.Tests/Model/BenchmarkEnvironmentTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
55 changes: 55 additions & 0 deletions tests/BenchmarkGate.Core.Tests/Model/BenchmarkRunTests.cs
Original file line number Diff line number Diff line change
@@ -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<BenchmarkObservation>());

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<BenchmarkObservation>());
var runWithPartialEnvironment = new BenchmarkRun(Environment: partialEnvironment, Observations: new List<BenchmarkObservation>());

runWithoutEnvironment.Environment.Should().BeNull();
runWithPartialEnvironment.Environment.Should().NotBeNull();
runWithoutEnvironment.Should().NotBe(runWithPartialEnvironment);
}

[Fact]
public void Observations_PreservesReadOnlyListReference()
{
IReadOnlyList<BenchmarkObservation> observations = new List<BenchmarkObservation>();

var run = new BenchmarkRun(Environment: null, Observations: observations);

run.Observations.Should().BeSameAs(observations);
}
}
Loading
Loading