[PR #1654] pk16_diff: restore globals, validate hardware oracle/shrink results and CLI options, and tighten RefError checks #1668

Open
opened 2026-11-26 20:22:02 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1654
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/pk16-diff-oracle-cli-and-ref


📝 Commits (1)

  • 7586cc1 pk16_diff: restore globals, validate oracle/shrink results and CLI options, and enforce RefError checks

📊 Changes

2 files changed (+158 additions, -8 deletions)

View changed files

📝 tests/test_pk16_diff.py (+94 -0)
📝 tools/pk16_diff.py (+64 -8)

📄 Description

Item ID: PK16-DIFF-ORACLE-CLI-AND-REF
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155677593

Summary

  • Module state restoration (tools/pk16_diff.py): restore KNOWN and LITERALS in main()'s finally block (and handle --list-ops/--self-test before mutating them) so in-process runs do not leak flags.
  • Hardware oracle & shrink guards: add hw_run() validating oracle is not None and exact result-list length across both run_suite() and shrink check_fn (avoiding AttributeError / IndexError on empty or short oracle returns); validate 4-word tuples/lists in _diff(); catch transient Skip during final shrunk recheck and fall back to problem.
  • CLI validation: reject empty/whitespace --hw-arch, --build, and --work.
  • Reference validation: raise RefError instead of silent ignores or raw ValueError/IndexError/TypeError on invalid operands, non-SGPR/non-VGPR destinations, wrong source counts, mismatched op_sel/op_sel_hi lengths, op_sel_hi on non-packed OPS_16 ops, and clamp on ops without clamp support.
  • Tests (tests/test_pk16_diff.py): add 4 regression tests covering all of the above.

Verification

  • python3 -W error -I tests/test_pk16_diff.py -v: 20 passed, 0 failed (2.612s).
  • Mutation check against unpatched main: ran=20, failures=7, errors=6.
  • python3 -m compileall -q tools/pk16_diff.py tests/test_pk16_diff.py, python3 -I tests/test_text_write_line_endings.py, python3 -I scripts/check_no_game_data.py: all pass.

AI-assisted: yes
GPUs tested: none (CPU unit tests with stubbed hardware oracle and spirv_mini_interp; no game data)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1654 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/pk16-diff-oracle-cli-and-ref` --- ### 📝 Commits (1) - [`7586cc1`](https://github.com/ubiquitarianism/leonida/commit/7586cc137e10809b42af3bc601690432302298c6) pk16_diff: restore globals, validate oracle/shrink results and CLI options, and enforce RefError checks ### 📊 Changes **2 files changed** (+158 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_pk16_diff.py` (+94 -0) 📝 `tools/pk16_diff.py` (+64 -8) </details> ### 📄 Description Item ID: `PK16-DIFF-ORACLE-CLI-AND-REF` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155677593 ## Summary - **Module state restoration (`tools/pk16_diff.py`)**: restore `KNOWN` and `LITERALS` in `main()`'s `finally` block (and handle `--list-ops`/`--self-test` before mutating them) so in-process runs do not leak flags. - **Hardware oracle & shrink guards**: add `hw_run()` validating `oracle is not None` and exact result-list length across both `run_suite()` and shrink `check_fn` (avoiding `AttributeError` / `IndexError` on empty or short oracle returns); validate 4-word tuples/lists in `_diff()`; catch transient `Skip` during final shrunk recheck and fall back to `problem`. - **CLI validation**: reject empty/whitespace `--hw-arch`, `--build`, and `--work`. - **Reference validation**: raise `RefError` instead of silent ignores or raw `ValueError`/`IndexError`/`TypeError` on invalid operands, non-SGPR/non-VGPR destinations, wrong source counts, mismatched `op_sel`/`op_sel_hi` lengths, `op_sel_hi` on non-packed `OPS_16` ops, and `clamp` on ops without clamp support. - **Tests (`tests/test_pk16_diff.py`)**: add 4 regression tests covering all of the above. ## Verification - `python3 -W error -I tests/test_pk16_diff.py -v`: **20 passed, 0 failed** (2.612s). - Mutation check against unpatched `main`: **ran=20, failures=7, errors=6**. - `python3 -m compileall -q tools/pk16_diff.py tests/test_pk16_diff.py`, `python3 -I tests/test_text_write_line_endings.py`, `python3 -I scripts/check_no_game_data.py`: all pass. AI-assisted: yes GPUs tested: none (CPU unit tests with stubbed hardware oracle and `spirv_mini_interp`; no game data) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
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
starred/leonida#1668
No description provided.