A new native target, src/native/FrameLedger.NvapiBridge/, is the C ABI the managed side reaches NVAPI through: refcounted FlNvInit/FlNvShutdown, FlNvReadSample into a fixed struct with a present bit per field, FlNvNgxState for one pid, FlNvDriverVersion, and size / ABI-version / build-id queries so a drifted mirror is refused (FL_NV_BAD_SIZE) rather than read. It is the only shipped binary that links nvapi64.lib, read-only by construction, loaded by the Agent into its own process by absolute path (FrameLedger.NvapiBridge.targets) and never into a game. Infrastructure.Telemetry: NativeNvapiBridge (the second P/Invoke facade after the guard's, same absolute-path rule), NvapiTelemetrySource (L3: a clear bit is null, never 0; an Init that does not answer 0 disables the layer with zero faults; two throws disable it for the session; VRAM is not read because the vendored nvapi.h declares no non-deprecated memory-info call, so L1's PDH counter keeps it), and NvapiNgxStateProbe, the INgxDriverProbe in-process. The capture host composes L1 + L2 + L3 under the composite and no longer spawns fl-probe-nvapi.exe; the probe is no longer staged beside it. Infrastructure.Native.BesideThisAssembly is the assembly's one DllImport resolver. The runtime allows one per assembly and the guard's static constructor already set it, which the first real-hardware run of the mirror test found (TypeInitializationException: a resolver is already set). The guard claims its name as required (absent throws); the bridge as optional (absent is a missing layer that reports itself). Tests: ctest fl_nvapi_bridge (every export, BRANCH: line required); NvapiBridgeMirrorTests (both mirrors' sizes against the DLL's answers, fails rather than skips when the DLL is not staged); NvapiTelemetrySourceTests and NvapiNgxStateProbeTests over a scripted bridge. versioninfo-check.ps1 requires the new DLL's version block. Measured on the dev box (RTX 5080, 616.64 r616_41), written into 18_GPU_VENDOR_APIS §L3: core 35 °C, GPU domain 0 %, 2670 / 15001 MHz, throttle mask 0, PCIe x16; memory-temperature and fan bits clear at an idle desktop. Docs: 18_GPU_VENDOR_APIS (§Abstraction, §L3 built note, function table, measured matrix), 12_BUILD (§Targets, the .targets list), 03_METRICS and 20_OPEN_QUESTIONS §H5 (probe in-process), CLAUDE.md (pinned stack, the two facades), legal/THIRD_PARTY_NOTICES (NVAPI row), CHANGELOG. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
51 lines
2.1 KiB
C#
51 lines
2.1 KiB
C#
using System.Runtime.InteropServices;
|
|
using FluentAssertions;
|
|
using FrameLedger.Infrastructure.Telemetry;
|
|
|
|
namespace FrameLedger.Infrastructure.Tests.Telemetry;
|
|
|
|
/// <summary>
|
|
/// The managed mirrors of <c>FlNvSample</c> and <c>FlNvNgxState</c> against the DLL's own sizes, and the DLL's
|
|
/// build id against the guard's — the same mirror discipline <c>ShmLayoutMirrorTests</c> applies, one binary later.
|
|
/// Fails rather than skips when the bridge is not staged: a mirror test that quietly does nothing is a gate that cannot fail.
|
|
/// </summary>
|
|
public sealed class NvapiBridgeMirrorTests
|
|
{
|
|
[Fact]
|
|
public void TheMirrorsAreTheSizesTheBridgeAnswersAndTheAbiVersionIsTheOneWeWroteAgainst()
|
|
{
|
|
NativeNvapiBridge.IsPresent.Should().BeTrue("FrameLedger.NvapiBridge.dll must be staged beside the test binary (FrameLedger.NvapiBridge.targets)");
|
|
|
|
NativeNvapiBridge.AbiVersion().Should().Be(1u);
|
|
((uint)Marshal.SizeOf<NvapiSample>()).Should().Be(NativeNvapiBridge.SampleSize());
|
|
((uint)Marshal.SizeOf<NvapiNgxWords>()).Should().Be(NativeNvapiBridge.NgxStateSize());
|
|
NativeNvapiBridge.BuildId().Should().NotBeNullOrEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void TheRealBridgeEitherInitialisesOrSaysWhyAndNeverClaimsAFieldItDidNotRead()
|
|
{
|
|
using var bridge = new NativeNvapiBridge();
|
|
using var source = new NvapiTelemetrySource(bridge, TimeProvider.System);
|
|
|
|
source.Start();
|
|
|
|
if (source.IsDisabled)
|
|
{
|
|
// A runner without an NVIDIA driver, or no GPU: the normal branch on CI.
|
|
source.Faults.Should().Be(0);
|
|
source.LastFault.Should().NotBeNull();
|
|
return;
|
|
}
|
|
|
|
source.DriverVersion.Should().MatchRegex(@"^\d+\.\d{2} \(.+\)$");
|
|
source.TryRead(out Application.Telemetry.GpuSample? s).Should().BeTrue();
|
|
s!.AdapterName.Should().NotBeNullOrWhiteSpace();
|
|
(s.PresentFields & ~source.Capabilities).Should().Be(Application.Telemetry.GpuCapabilities.None);
|
|
if (s.LoadPct is { } load)
|
|
{
|
|
load.Should().BeInRange(0, 100);
|
|
}
|
|
}
|
|
}
|