Skip to content

test(cosim): pin the CpuBootTrace wire layout to a literal - #437

Merged
doublegate merged 1 commit into
mainfrom
feat/v2.4.2-boot-trace-pin
Aug 21, 2026
Merged

test(cosim): pin the CpuBootTrace wire layout to a literal#437
doublegate merged 1 commit into
mainfrom
feat/v2.4.2-boot-trace-pin

Conversation

@doublegate

Copy link
Copy Markdown
Owner

The sibling testbench now writes the oracle's CpuBootTrace format, so cpu_boot_trace_diff — already written, already tested, and already used against a third-party reference emulator — reads a device-under-test's output with no modification at all.

Demonstrated rather than asserted, on a C++-written 256-record trace:

positive control: the oracle parses and matches what this side wrote
Loaded reference: 256 records
All 256 aligned records match under the chosen comparator (skip-fields: []).

negative control: a corrupted register must be located
  -- divergence point --
  ref    cyc=307     PC=$C064 A=$64 X=$32 Y=$19 P=$24 S=$FD  NOP
  actual cyc=307     PC=$C064 A=$9B X=$32 Y=$19 P=$24 S=$FD  NOP

That is the plan's claim — a ~120-line C++ record writer buys the existing diff CLIs unmodified — met. The alternative it avoids is worth naming: a comparison written specifically for the DUT would be new, unexercised code on the one axis where new code is least welcome, namely the thing that decides whether the DUT is correct.

Why a literal, and not each other

Anchoring the two implementations to each other has a specific failure: they can agree on something wrong, and neither test notices. Anchoring both to the same hardcoded bytes means a drift on either side reddens that side's own test, at the moment it happens — rather than at co-simulation time, where a format difference is indistinguishable from a DUT defect and would be debugged as one.

It also pins the four constants the C++ header duplicates: the magic, the schema version, HEADER_SIZE, RECORD_SIZE. Those live in two repositories with nothing mechanical connecting them.

scanline = -1 is deliberate

The pre-render line is negative, and a writer that clamped or saturated instead of writing two's complement would pass every test that only ever used a positive scanline. The C++ side carries a matching check that a positive scanline encodes differently, so neither case is proving something both branches would satisfy.

Demonstrated to fail: changing the two scanline bytes in the expectation reddens the test.

Gates

Test-only in the excluded crate; the emulation core is untouched, so AccuracyCoin 141/141 and nestest 0-diff hold by construction.

fmt · clippy -D warnings · rustdoc -D warnings on the excluded crate · markdownlint.

4 excluded-crate suites / 43 passed (was 42).

The testbench in the sibling repository now writes this format, so
cpu_boot_trace_diff -- already written, already tested, and already used
against a third-party reference emulator -- reads a device-under-test's output
with no modification at all. Demonstrated rather than asserted: a C++-written
256-record trace loads and reports "All 256 aligned records match", and a
corrupted register is located at cyc=307 PC=$C064 A=$64 against A=$9B.

The pin exists so the two implementations are anchored to the SAME hardcoded
bytes rather than to each other. Anchoring them to each other has a specific
failure: they can agree on something wrong, and neither test notices. Anchoring
both to a literal means a drift on either side reddens that side's own test,
at the moment the drift happens -- rather than at co-simulation time, where a
format difference is indistinguishable from a DUT defect and would be debugged
as one.

It also pins the constants the C++ header duplicates: the magic, the schema
version, HEADER_SIZE and RECORD_SIZE. Those are four more values that live in
two repositories with nothing mechanical connecting them.

scanline = -1 in the pinned record is deliberate, not an arbitrary value. The
pre-render line is negative, and a writer that clamped or saturated instead of
writing two's complement would pass every test that only ever used a positive
scanline -- the C++ side carries a matching check that a POSITIVE scanline
encodes differently, so neither case is proving something both branches would
satisfy.

Demonstrated to fail: changing the two scanline bytes in the expectation
reddens the test.

Gates. Test-only in the excluded crate; the emulation core is untouched, so
AccuracyCoin 141/141 and nestest 0-diff hold by construction.

  fmt, clippy -D warnings and rustdoc -D warnings on the excluded crate,
  markdownlint on the changed document.

  4 excluded-crate suites / 43 passed / 0 failed  (was 42)
Copilot AI lite review requested due to automatic review settings August 21, 2026 17:54
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Warning

Your free Security trial is over. An organization admin can activate billing to continue.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6e71cdd7-625e-4a5a-8243-43d7d3298542


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions

Copy link
Copy Markdown

Antigravity review (Gemini via Ultra)

This PR pins the CpuBootTrace binary wire format to a hardcoded byte literal in a unit test to prevent silent layout drift across the co-simulation boundary.

Blocking issues

None found.

Suggestions

None.

Nitpicks

None.

Automated first-pass review by agy on a self-hosted runner -- not a human review.

@doublegate
doublegate merged commit 30311f3 into main Aug 21, 2026
27 of 28 checks passed
@doublegate
doublegate deleted the feat/v2.4.2-boot-trace-pin branch August 21, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants