From e8dfdfc65291981c0f64bdd59cd5ad51aca0c8a6 Mon Sep 17 00:00:00 2001 From: morebrackets <19673572+morebrackets@users.noreply.github.com> Date: Wed, 2 Dec 2026 16:22:30 -0800 Subject: [PATCH] Replace elidable asserts in shared check_gpu_graphics_load_binary.py harness with require() Replace all 31 assert statements in check_gpu_graphics_load_binary.py (including side-effecting calls in memory_descriptor(), construct(), and main()) with _gpu_graphics_oracle_check.require() so python3 -O runs every required setup call and invariant check across all five graphics binary oracles. Add check_gpu_graphics_load_binary.py to the AST no-assert offline test. --- .../test_gpu_graphics_binary_oracles.py | 5 +- tools/check_gpu_graphics_load_binary.py | 63 ++++++++++--------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/tests/offline/test_gpu_graphics_binary_oracles.py b/tests/offline/test_gpu_graphics_binary_oracles.py index 52f95a40..b76af9b8 100644 --- a/tests/offline/test_gpu_graphics_binary_oracles.py +++ b/tests/offline/test_gpu_graphics_binary_oracles.py @@ -25,11 +25,14 @@ SCRIPTS = ( class GpuGraphicsBinaryOraclesTests(unittest.TestCase): def test_no_elidable_asserts_and_check_flag_wired(self) -> None: - for rel in SCRIPTS: + for rel in ("tools/check_gpu_graphics_load_binary.py", *SCRIPTS): src = (ROOT / rel).read_text() tree = ast.parse(src, filename=rel) asserts = [node.lineno for node in ast.walk(tree) if isinstance(node, ast.Assert)] self.assertEqual(asserts, [], f"{rel} still contains assert at lines {asserts}") + for rel in SCRIPTS: + src = (ROOT / rel).read_text() + tree = ast.parse(src, filename=rel) self.assertIn("--check", src, f"{rel} missing --check flag") self.assertIn("write_or_check_text", src, f"{rel} missing write_or_check_text") self.assertIn("write_or_check_json", src, f"{rel} missing write_or_check_json") diff --git a/tools/check_gpu_graphics_load_binary.py b/tools/check_gpu_graphics_load_binary.py index 65656178..d237eae1 100644 --- a/tools/check_gpu_graphics_load_binary.py +++ b/tools/check_gpu_graphics_load_binary.py @@ -12,6 +12,7 @@ from pathlib import Path import struct import sys import warnings +from _gpu_graphics_oracle_check import require warnings.filterwarnings("ignore", category=UserWarning) from capstone import CS_ARCH_X86, CS_MODE_64, Cs # noqa: E402 @@ -60,7 +61,7 @@ CLASSES = (("Graphics", GR), ("KernelGraphics", KGR), ("GraphicsManager", GRMGR) ("MemoryManager", MEMMGR), ("KernelFifo", KFIFO), ("OBJFIFO", OFIFO)) raw = ORIGINAL.read_bytes() -assert hashlib.sha256(raw).hexdigest() == DIGEST +require(hashlib.sha256(raw).hexdigest() == DIGEST) # Binders and property initializers per class, as this harness was validated with them # (reports/gv100-engine-hal-bindings.json of 2026-11-19 before its regeneration). They are # pinned here because that report is regenerated with other contents: it now also lists @@ -125,7 +126,7 @@ for name, blob in relocations.items(): elif kind == 10: struct.pack_into(" ".join(previous)]) - assert line - 1 == LAST_LINE + require(line - 1 == LAST_LINE) merged = [] for first, last, path in steps: # Collapse the per-TPC repetition of the GPC loop into one entry per run of paths. @@ -882,20 +883,20 @@ def main(): # The same traced inputs with the first class-enable byte (Graphics+160c) cleared by hand. # No original GV100 path does that (see class_enable_stores); this shows what the byte gates. case, status, compute = tracked_run(dict(v100, gr={0x160c: 0}), []) - assert status == 0 and "zbc:0" not in compute + require(status == 0 and "zbc:0" not in compute) compute_registers = [event for event in compute if event[0] in "rw" and event[1] == ":"] def written(events): return {int(event.split(":")[1], 16) for event in events if event.startswith("w:")} dropped = sorted(written(registers) - written(compute_registers)) - assert not written(compute_registers) - written(registers) + require(not written(compute_registers) - written(registers)) position, skipped = 0, 0 for event in registers: if position < len(compute_registers) and compute_registers[position] == event: position += 1 else: skipped += 1 - assert position == len(compute_registers), "the reduced sequence is not a subsequence" + require(position == len(compute_registers), "the reduced sequence is not a subsequence") compute_only = { "how": "Graphics+160c written 0 by the fixture before _nv033665rm; no original GV100 " "path stores 0 there", @@ -990,7 +991,7 @@ def main(): out = ROOT / "target/gpu-stage" out.mkdir(parents=True, exist_ok=True) table = struct.unpack("<96I", cpu.mem_read(by_name["_nv053876rm"], 384)) - assert all(table[index - 1] == -(-(1 << 23) // index) for index in range(1, 97)) + require(all(table[index - 1] == -(-(1 << 23) // index) for index in range(1, 97))) rows.insert(0, "T;" + " ".join(f"{value:x}" for value in table)) oracle = "\n".join(rows) + "\n" (out / "original-graphics-load.txt").write_text(oracle) @@ -1068,7 +1069,7 @@ if __name__ == "__main__": for binder, (second, third) in binder_order().items(): # A two-argument binder shows 1 for the argument it does not take. rm_first = third > second and second > 1 - assert rm_first == (binder in RM_FIRST), binder + require(rm_first == (binder in RM_FIRST), binder) print(binder, second, third, "(rm, chip)" if rm_first else "(chip, rm) or chip only") elif "--disassemble" in sys.argv: for name in sys.argv[sys.argv.index("--disassemble") + 1:]: