Files
reims-vgpu/scripts/wire-oracle/wire-oracle.sh
T
Anees IqbalandClaude 3e5ecfd273 ✅ The only tests that can find a layout error reported ok while returning on their first line
Component: crates/reims-vgpu-wire and crates/reims-vgpu, test harness only. No
product behaviour changes; the two build scripts emit cfgs and nothing else.

Apple's captured records are gitignored and absent on every non-Apple checkout,
which is where this work happens. Both fixture suites handled that by returning
early inside each test body, so 36 tests across two crates printed `ok` in
0.00 s — 34 of them the only tests in the project that can find a wire *layout*
error, since every other test synthesizes its buffers from the same constants
the views read and therefore proves self-consistency and nothing else. A run
that measured nothing was indistinguishable from a run that measured everything.

Presence is now decided at build time. `oracle/fixture_presence.rs` is included
by both build scripts — one copy, because the directory override, the two file
names and the meaning of REIMS_WIRE_FIXTURES_REQUIRED must not fork between the
two suites — and emits `wire_fixtures` / `wire_inventory` for whichever oracle
outputs exist. Every test that reads one carries
`#[cfg_attr(not(...), ignore = "...")]`, so libtest prints one `ignored` line
per test with the command that regenerates them. `ignored` is the vocabulary a
reader already trusts, and unlike an env-var waiver it survives being copied
into a canonical command line.

The two outputs gate separately: `inventory.json` and `fixtures.json` come from
different runs of the capture, so having one without the other stands down only
the tests that read the missing half rather than all 34.

REQUIRED moved with it. A runtime assertion for "these must have run" cannot
fire once the tests are ignored, so absence under REQUIRED now fails the build
instead. Both loaders lost their Option and panic naming the file, which can
only mean the capture was deleted between building and running.

Proven able to fail, all three ways, before landing:

- no fixtures, REQUIRED unset -> 2 + 34 ignored with their reasons (this host);
- no fixtures, REQUIRED=1 -> build fails in the build script naming the path
  and the regenerate command;
- a hand-made fixtures.json with an empty `cases` array -> the cfg flips on, the
  tests run, and both refuse a verdict ("no fixture reached a decoder", "no
  record had an unwritten bit to poison") rather than passing on no input.

Docs corrected in the same commit: the wire crate README, the wire-oracle script
README and its own closing message all described a skip. AGENTS.md gains the
durable half — a green suite on a fixture-less checkout is not evidence about a
wire layout, and the ignored count is the one to read.

Verified: `cargo fmt --all --check`; clippy `-D warnings` on all three
reims-vgpu arms and on reims-vgpu-wire --all-targets — zero from each; full
serial suite on backend-vulkan,host-window (1381 lib, 82 integration passed,
0 failed, 3 ignored) and on reims-vgpu-wire (143 lib passed, 1 passed / 34
ignored in oracle_fixtures); `scripts/feature-matrix/feature-matrix.sh` PASS
both arms, warnings=0, lib=1381 unchanged.

Not verified: no boot was run — nothing here compiles into the staticlib QEMU
links. The fixture-present path was exercised only with a synthetic empty
capture; the real capture needs an Apple host, and neither `--all` regeneration
nor the REQUIRED=1 green run has been done from this checkout.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-05 14:36:11 +03:00

106 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerate reims-vgpu-wire's ground-truth fixtures from Apple's own
# paravirt serializer.
#
# Apple-host only, and x86_64-under-Rosetta only: the serializer bundle ships
# x86_64 and arm64e slices with no plain-arm64 one, and third-party arm64e
# needs a preview-ABI boot-arg. Rosetta is the supported route.
#
# Output is gitignored on purpose. The bytes are Apple's serializer output, so
# they are regenerated rather than committed; what the repository keeps is the
# derived layout, the expectations, and the coverage manifest.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
CRATE="$REPO_ROOT/crates/reims-vgpu-wire"
OUT_DIR="${REIMS_WIRE_FIXTURES_DIR:-$CRATE/fixtures}"
BUILD_DIR="$REPO_ROOT/target/wire-oracle"
BUNDLE=/System/Library/Extensions/AppleParavirtGPUMetal.bundle
usage() {
cat <<'EOF'
usage: wire-oracle.sh [--fixtures] [--inventory] [--all]
--fixtures capture wire operations + expectations (default)
--inventory dump every selector on the serializer classes
--all both
Writes into crates/reims-vgpu-wire/fixtures/ unless REIMS_WIRE_FIXTURES_DIR is set.
EOF
}
do_fixtures=0
do_inventory=0
case "${1:---fixtures}" in
--fixtures) do_fixtures=1 ;;
--inventory) do_inventory=1 ;;
--all) do_fixtures=1; do_inventory=1 ;;
-h|--help) usage; exit 0 ;;
*) usage; exit 2 ;;
esac
if [[ "$(uname -s)" != "Darwin" ]]; then
echo "wire-oracle: Apple host only (this is $(uname -s))." >&2
echo "The serializer being measured only exists on macOS." >&2
exit 1
fi
if [[ ! -d "$BUNDLE" ]]; then
echo "wire-oracle: $BUNDLE not present." >&2
echo "Without it there is nothing to measure against." >&2
exit 1
fi
if ! arch -x86_64 /usr/bin/true 2>/dev/null; then
echo "wire-oracle: cannot execute x86_64 binaries." >&2
echo "Rosetta is required: softwareupdate --install-rosetta" >&2
exit 1
fi
mkdir -p "$BUILD_DIR" "$OUT_DIR"
# Remove the targets before the build, not just before the run.
#
# Three things can end this script early: the compile can fail, the capture can
# abort (a case that makes Apple's serializer assert used to do exactly that),
# or the run can be interrupted. The JSON is only written at the very end, so
# any of them leaves the PREVIOUS file on disk — and every test that reads it
# afterwards then passes against stale ground truth while the run that produced
# it failed loudly and scrolled away. No file is a skip; a stale one is a lie.
#
# Written as `if` rather than `[[ … ]] && rm`, because under `set -e` a false
# `[[ … ]]` as the last statement of its own line ends the script.
if [[ $do_fixtures == 1 ]]; then
rm -f "$OUT_DIR/fixtures.json"
fi
if [[ $do_inventory == 1 ]]; then
rm -f "$OUT_DIR/inventory.json"
fi
echo "wire-oracle: building oracle (x86_64)"
clang -arch x86_64 -fobjc-arc -O1 -Wall \
-Wno-deprecated-declarations \
-framework Foundation -framework Metal \
-o "$BUILD_DIR/oracle" "$CRATE/oracle/oracle.m"
if [[ $do_fixtures == 1 ]]; then
echo "wire-oracle: capturing fixtures"
arch -x86_64 "$BUILD_DIR/oracle" fixtures "$OUT_DIR/fixtures.json"
fi
if [[ $do_inventory == 1 ]]; then
echo "wire-oracle: dumping selector inventory"
arch -x86_64 "$BUILD_DIR/oracle" inventory "$OUT_DIR/inventory.json"
fi
cat <<EOF
Fixtures are in $OUT_DIR (gitignored).
Verify against them with:
cargo test -p reims-vgpu-wire -- --test-threads=1
A run with no fixtures present reports the oracle tests as ignored, one line
each; set REIMS_WIRE_FIXTURES_REQUIRED=1 to make their absence fail the build.
EOF