Skip to content

sad_diff: treat translator/interpreter crashes and bad exports as harness errors - #9795

Open
mynzjerko wants to merge 1 commit into
ProjectLeonida:mainfrom
mynzjerko:fix/sad-diff-errors-and-validation
Open

mynzjerko wants to merge 1 commit into
ProjectLeonida:mainfrom
mynzjerko:fix/sad-diff-errors-and-validation

Conversation

@mynzjerko

Copy link
Copy Markdown
Contributor

Claim: #9677 (comment)

Summary

Fixes four harness and input-validation gaps in tools/sad_diff.py with synthetic regression coverage in tests/test_sad_diff.py:

  1. Surface translator/interpreter/reference crashes as HarnessError (run_one):
    • Let HarnessError from reference() propagate instead of turning it into "skip".
    • Keep (rdna2spirv.Unsupported, UnsupportedConstruct) mapped to "skip", re-raise HarnessError, and convert any other unexpected exception from translate_listing() (including KeyError, ValueError, IndexError, and spirv_mini_interp.InvalidModule) into HarnessError so main() reports harness error: ... and exits 2.
  2. Validate %out_mrt0 export word count (translate_listing, _first_mismatch, check, run_one):
    • Require len(words) == len(EXPORT_REGS) (4) in translate_listing() and len(got) == len(want) in _first_mismatch(), raising HarnessError instead of accepting empty/truncated exports as None or ("match", "").
  3. Harden reference parser (_parse_hex, _DEC, _single_word, _pair_words, _dst_index, step, reference):
    • Raise HarnessError on malformed hex literals ("0xZZ"), malformed signed decimals ("+-5", "--5"), invalid s_mov_b32 destinations ("sfoo"), and wrong operand counts, and skip whitespace-only lines in reference().
  4. Normalize --ops CLI parsing (main):
    • Strip/drop empty comma-separated items, deduplicate while preserving order, and exit 2 when --ops names no opcode (e.g. --ops "" or --ops " , "). (--programs/--max-ops validation was left untouched.)

Negative Controls (unmodified tools/sad_diff.py)

  • Patched translate_listing raising KeyError("boom") after one match caused main() (--no-sweep --programs 2) to exit 0; InvalidModule("bad spirv") escaped run_one() uncaught; run_one(["v_unknown v8, v8, v9, v10"], ...) returned ('skip', ...).
  • Patched translate_listing returning [] caused check(["v_mov_b32 v8, 1"]) to return None and run_one(...) to return ('match', ''); patched run_fragment returning {"%out_mrt0": [0]} caused translate_listing(...) to return [0].
  • _single_word("0xZZ", {}, {}), _single_word("+-5", {}, {}), _pair_words("--5", {}, {}), step("s_mov_b32 sfoo, 1", {}, {}), step("v_sad_u8 v8, v8, v9", {}, {}), and reference([" "]) raised raw ValueError/IndexError.
  • --ops "" silently defaulted to ops = None; --ops "v_sad_u8," failed with unknown op(s) ['']; --ops "v_sad_u8,v_sad_u8" kept duplicate ['v_sad_u8', 'v_sad_u8'].

Verification (0770ad19d)

  • python -I tests/test_sad_diff.py -v — Ran 16 tests in 2.573s, OK (exit 0; includes 4 new tests in HarnessErrorAndParsingTests).
  • python -I tools/sad_diff.py --self-test — exit 0.
  • python -I tools/sad_diff.py --no-sweep --programs 10 --ops "v_sad_u8,v_qsad_pk_u16_u8," — random: 10/10 programs match, 0 mismatch; skips: {} (2 of 7 ops, exit 0).
  • python -I scripts/check_no_game_data.py — exit 0.
  • git diff --check — exit 0.
  • git merge-tree --write-tree origin/main HEAD — exit 0 (clean merge with origin/main 2d53a8055).

Synthetic inputs only; no game files or GPU used.
AI-assisted (Antigravity).

@pablo-biasco-411953

Copy link
Copy Markdown

checked: #97950770ad1 | with: PR diff applied on main 7e39a81, python -m pytest -q tests/test_sad_diff.py | on: Windows 11, CPython 3.11.9, pytest 9.2.0, CPU only, no game files | result: pass, 16 passed; no new failures against the same tests on main | agent: yes

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified at head 0770ad1: the focused suite is 16 passed; the same test on base source fails four checks. Malformed inputs now raise a harness error instead of being treated as a comparison result. Approving. AI-assisted (OpenCode).

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.

3 participants