WIP: test(lift): the guest context's two definitions are checked to agree on every PC #1572

Draft
dyst wants to merge 1 commit from dyst/Longshot:test/guest-context into main
Member

Type: test · Risk: low · Tested on: Windows 11, Ryzen 9 3900X · Needs: none

TL;DR

The translated game code's register state has a second copy of its layout for the emulator-hosted build, and the check that the two match only ran in that build, which nobody makes any more. This runs that same check on every PC. A field added to one side alone fails it.

Breakdown

  • Who it helps: anyone changing the guest context (nx2/rtgen.py adds poll; local registers and the CPU rework plan's contract touch it).
  • What was wrong: nx2/rt/eden_shim.c's static asserts (SAME() per field and the size) compile only in the DLL build (nx2/build.py --dll).
  • What changes: tests/test_guest_context.py writes the generated header with rtgen.write, as the build does, and compiles those asserts, cut from the shim, against it and nx2/rt/mkw_host.h.
  • What does not change: the game, the headers, the shim.
  • How it was checked: passes on 310e7c9d; an extra field in MkwGuestContext alone fails it.
  • What is still open: nothing.
  • Risk: low: a check only.

Why

The wiki's CPU rework plan (milestone C2) asks for one definition of the guest context and a check that fails when a side differs. For the standalone game the definition is already one (the host includes the generated header). This covers the other copy.

What changed

  • tests/test_guest_context.py (new): cuts eden_shim.c from #define SAME(f) up to its first function (tests/srccut.py between), writes the generated a64.h into a temporary folder, gives the lift's two generated headers empty stand-ins (they are included after the context), and compiles with -fsyntax-only.

Measurements

Verdict: nothing to measure: a check only.

Flags and settings

None.

Testing

Tested: on Windows 11 with the Builder's clang: passes on 310e7c9d (16 field asserts and the size). With a uint64_t extra; added after poll in MkwGuestContext: fails (exit status 1); put back: passes.

Not tested: Linux.

Must be tested: None.

Risks

What could break: nothing in the game.

Turning it off: revert the commit.

Compatibility: nothing changes.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main. On 310e7c9d.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named). This check passes; the full suite not run yet.
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

🤖 Generated with Claude Code

**Type:** test · **Risk:** low · **Tested on:** Windows 11, Ryzen 9 3900X · **Needs:** none ## TL;DR The translated game code's register state has a second copy of its layout for the emulator-hosted build, and the check that the two match only ran in that build, which nobody makes any more. This runs that same check on every PC. A field added to one side alone fails it. ## Breakdown - **Who it helps:** anyone changing the guest context (`nx2/rtgen.py` adds `poll`; local registers and the CPU rework plan's contract touch it). - **What was wrong:** `nx2/rt/eden_shim.c`'s static asserts (`SAME()` per field and the size) compile only in the DLL build (`nx2/build.py --dll`). - **What changes:** `tests/test_guest_context.py` writes the generated header with `rtgen.write`, as the build does, and compiles those asserts, cut from the shim, against it and `nx2/rt/mkw_host.h`. - **What does not change:** the game, the headers, the shim. - **How it was checked:** passes on `310e7c9d`; an extra field in `MkwGuestContext` alone fails it. - **What is still open:** nothing. - **Risk:** low: a check only. ## Why The wiki's CPU rework plan (milestone C2) asks for one definition of the guest context and a check that fails when a side differs. For the standalone game the definition is already one (the host includes the generated header). This covers the other copy. ## What changed - `tests/test_guest_context.py` (new): cuts `eden_shim.c` from `#define SAME(f)` up to its first function (`tests/srccut.py` `between`), writes the generated `a64.h` into a temporary folder, gives the lift's two generated headers empty stand-ins (they are included after the context), and compiles with `-fsyntax-only`. ## Measurements **Verdict:** nothing to measure: a check only. ### Flags and settings None. ## Testing **Tested:** on Windows 11 with the Builder's clang: passes on `310e7c9d` (16 field asserts and the size). With a `uint64_t extra;` added after `poll` in `MkwGuestContext`: fails (exit status 1); put back: passes. **Not tested:** Linux. **Must be tested:** None. ## Risks **What could break:** nothing in the game. **Turning it off:** revert the commit. **Compatibility:** nothing changes. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [ ] Rebased on current `main`. *On `310e7c9d`.* - [ ] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). *This check passes; the full suite not run yet.* - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
test(lift): the guest context's two definitions are checked to agree on every PC
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
PR description / Description follows the template (pull_request_target) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 10s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 11s
Website / Website on Cloudflare (pull_request_target) Has been skipped
23ee70864a
The standalone game has one GuestContext (rt/a64.h as nx2/rtgen.py writes it, which the host
includes too). The emulator-hosted DLL has a second, MkwGuestContext in nx2/rt/mkw_host.h,
and nx2/rt/eden_shim.c's static asserts check the two, but only in the DLL build, which a
normal build never makes. tests/test_guest_context.py writes the generated header as the
build does and compiles eden_shim.c's asserts, cut from it, against it and mkw_host.h: a field
added to one side alone fails it (checked by hand).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
PR description / Description follows the template (pull_request_target) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 10s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 11s
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'test/guest-context:dyst-test/guest-context'
git switch 'dyst-test/guest-context'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1572
No description provided.