#!/usr/bin/env python3 """README.md = the generated top, the fork's sections, the base board's sections.""" import json, pathlib, re, subprocess ROOT = pathlib.Path("/data/emu/pcengine-rust-fast") EXT = ROOT / "external" import os FAULTS = os.environ.get("FAULTS", "faults-final.txt") base = subprocess.run(["git", "show", "1cc528d:README.md"], cwd=ROOT, capture_output=True, text=True, check=True).stdout top = (EXT / "readme-top.md").read_text() mid = (EXT / "readme-mid.md").read_text() for key, value in json.loads((EXT / "profile-shares.json").read_text()).items(): mid = mid.replace(f"@@{key}@@", value) assert "@@" not in mid, re.findall(r"@@\w+@@", mid) fault_rows = (EXT / "readme-faults.md").read_text() results = dict(re.findall(r"^(\S+): caught by (.*)$", (EXT / FAULTS).read_text(), re.M)) if (EXT / (FAULTS + ".extra")).exists(): results.update(re.findall(r"^(\S+): caught by (.*)$", (EXT / (FAULTS + ".extra")).read_text(), re.M)) fork_count = fault_rows.count("\n") total = 48 + fork_count assert len(results) >= total, (len(results), total) body = base[base.index("## Certification"):] def rep(a, b): global body assert body.count(a) == 1, (a, body.count(a)) body = body.replace(a, b) rep("## Certification\n", """## The base board From here on this is pcengine-rust's README at the fork point (`49e3d48`): what the board is, how it was certified against the reference, how to use it and how an add-on plugs in. All of it holds for this fork, which runs the same cases from the reference cache; where the fork differs, a note in *italics* says so. ### Certification """) # the base board's own speed section is replaced by this fork's, above i, j = body.index("### Speed\n"), body.index("## Where Rust forced a difference") body = body[:i] + body[j:] rep("| `seed-low-bits` | `mt.rs` | a seeded power-on takes the low bits of each random word | rung 5 (`sock-path-rtype`) |\n", "| `seed-low-bits` | `mt.rs` | a seeded power-on takes the low bits of each random word | rung 5 (`sock-path-rtype`) |\n" + fault_rows) rep("### Seeded faults\n", f"""### Seeded faults *This fork: **{total} caught, 0 missed**: the base board's 48, each by the same check as below, and {fork_count} in the fork's own shortcuts (the last {fork_count} rows of the table; at least one on every kept change that has code), of which the unit tests of `tests/fork.rs` catch those that change the state but no bus cycle, picture or sample. The first run missed one, `next-event-forgets-the-commit`: at 12 master clocks a cycle a VRAM write's slot always falls inside the access's own stretch, so the test program now runs at high CPU speed. The faults are built without LTO (the same source).* """) rep("## Where Rust forced a difference\n", "### Where Rust forced a difference\n") rep("## Using the board (the fast fork, the browser page, an add-on)\n", "### Using the board (the browser page, an add-on)\n") rep("### How an add-on crate plugs in\n", "#### How an add-on crate plugs in\n") rep("## Layout\n", "### Layout\n") rep("## Notes on the reference\n", "### Notes on the reference\n") rep("## Reproducing\n", "## Reproducing\n\n*The fork's own:*\n\n```text\nscripts/ladder.sh [--faults] # the gate: cargo test, 275 lockstep cases from the cache, rung 6\nscripts/ab.py BIN_A BIN_B [--frames N] [--extra ARGS] # A/B two builds of pce-bench; --fps BIN for one\ncargo run --release --features profile --bin pce-profile -- IMAGE --frames 600 && scripts/profile.py\nscripts/wasm-bench.sh [--base DIR] # the five titles under Node, the PSG level table against native\nscripts/seeded_faults.py [--only REGEX] [--check]\n```\n\n*The base board's (the reference itself is only needed for a case missing from\n`external/refcache`, which is copied from pcengine-rust's `external/refcache`):*\n") rep("""Binaries: `pce-trace`, `pce-state-roundtrip`, `pce-bench`. Tests: `tests/sockets.rs` (the reference's `tests/test_sockets.py`), `pads.rs`, `cards.rs`, `state.rs`.""", """Binaries: `pce-trace`, `pce-state-roundtrip`, `pce-bench`. Tests: `tests/sockets.rs` (the reference's `tests/test_sockets.py`), `pads.rs`, `cards.rs`, `state.rs`. *The fork adds `src/bin/pce-profile.rs`, `tests/fork.rs`, `scripts/ladder.sh`, `ab.py`, `profile.py`, `wasm-bench.sh`, `wasm-bench/` (a crate of its own) and `docs/fast-brief.md`, `docs/not-kept.md`; `pce-bench` times by CPU time and prints a checksum.*""") rep("""The CPU is [huc6280-rust](../huc6280-rust)""", """The CPU is [huc6280-rust](../huc6280-rust)""") if False else None (ROOT / "README.md").write_text(top + mid + "\n" + body) print("README.md written:", len((ROOT / "README.md").read_text().splitlines()), "lines")