Skip to content

vk_fuzz_run: validate wave, clean up temp dir on error, read index as utf-8-sig, and guard exact_verdict - #6700

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
Shnimlz:fix/vk-fuzz-run-guards
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
Shnimlz:fix/vk-fuzz-run-guards

Conversation

@Shnimlz

@Shnimlz Shnimlz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #6603 (#6603 (comment)).

Problem

In tools/vk_fuzz_run.py (added in #6306):

  1. run_programs() validates words in (1, 2, 4, 8) but does not validate wave in (32, 64), so an invalid wave size silently emits broken compute assembly and mis-sized dumps.
  2. shutil.rmtree(work) ran only on normal return without try...finally, leaking vk_fuzz_* temp directories if mc_command.mc_command() or a subprocess raises.
  3. spirv/index.json was opened as strict utf-8 instead of utf-8-sig.
  4. exact_verdict() raised IndexError when len(hw) != len(got), when len(lines) < n_obs, or when an observation line did not contain ", ".

Fix

  • Validate wave in (32, 64) in run_programs() (ValueError).
  • Wrap work usage in try...finally so temp directories are removed on error too (still honoring VK_FUZZ_KEEP).
  • Open spirv/index.json with encoding="utf-8-sig".
  • Guard exact_verdict() on mismatched lengths and fallback register labels when observation lines are absent or lack ", ".
  • Add unit tests in tests/test_vk_fuzz_run.py.

Testing

  • python3 -m compileall -q tools/vk_fuzz_run.py tests/test_vk_fuzz_run.py
  • python3 -I tests/test_vk_fuzz_run.py -v: 9/9 passed (Arch Linux, Python 3.13).
  • Live GPU check (vk_fuzz_run.run_programs wave32 + wave64 on synthetic v_mov_b32 program): OK on AMD Radeon RX 5500 XT (RADV NAVI14, Mesa 26.3.1-arch3.5, Vulkan 1.4.363).
  • Synthetic programs only; no game files.
  • AI-assisted (Antigravity).

Copilot AI balanced review requested due to automatic review settings November 23, 2026 14:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Tested from this Linux box at head 74919640c against current main 1cc6e3c1, minutes apart (RTX 3080,
llvm-mc 20.1.2, Python 3.12.3 with pytest 9.2.0 and numpy 2.5.5, no game files).

Two of your four points reproduce cleanly here as real on main and fixed on your branch (tools/vk_fuzz_run.py
driven directly, build=/work_parent= pointed at a scratch directory):

Call main 1cc6e3c1 your head 74919640c
run_programs([], words=4, wave=16) no validation — proceeds and dies later with FileNotFoundError: vk_compute_test not found in runtime/build ValueError: wave must be 32 or 64
run_programs([["s_nop 0"]], …) with the assemble step raising left a temp dir behind: 1 ['vk_fuzz_yy2fto3v'] 0 [] — cleaned by the finally

Your exact_verdict guards are covered by your own file, which passes here: python -I tests/test_vk_fuzz_run.py →
OK on your head (and on main's older copy of the file).

What I did not exercise: the index.json utf-8-sig line. That branch of run_programs only runs when a real
translated folder exists, and this box holds no game corpus, so I only read the code (open(index_path, encoding="utf-8-sig")); a probe of mine that opened the file as strict utf-8 is not a test of your line and I am not
counting it.

One unrelated failure to flag. The translator pytest set gives 1761 passed, 1 failed at your head — and the
same command on main minutes later gives the identical single failure, so it is not yours:
tests/test_user_sgpr_census.py::test_json_report_refuses_to_overwrite_index[folding-volume-case] → DID NOT RAISE SystemExit (the case-insensitive-name guard does not trigger under our case-sensitive Linux filesystem, even with
same_name_on_folding_volume patched to True and os.path.samefile patched to raise). Nearest commits on that file
are #6271, #6276, #6299. Caveat for whoever picks it up: our pytest is 9.2.0, so if the CI job is green the difference
may be the pytest version rather than the code.

Small usability note for Linux testers of this tool: the docstring example passes build="runtime/build", while our
Linux build tree is runtime/build/linux, so callers here have to pass that explicitly (same on main and your head).

AI-assisted testing, counts read through by hand.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

tools/vk_fuzz_run.py: run_programs() rejects wave outside 32/64, wraps its body in try/finally so the vk_fuzz_* temp directory is removed even when llvm-mc raises, and reads index.json as utf-8-sig. exact_verdict() now reports word-count differences and tolerates short or malformed observation lines instead of indexing past them. Tests cover each guard.

Why merge

Prevents leftover temp directories on exceptions, handles BOM-bearing indexes, and gives a clear verdict when programs produce different word counts.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

tools/vk_fuzz_run.py: run_programs() rejects wave outside 32/64, wraps its body in try/finally so the vk_fuzz_* temp directory is removed even when llvm-mc raises, and reads index.json as utf-8-sig. exact_verdict() now reports word-count differences and tolerates short or malformed observation lines instead of indexing past them. Tests cover each guard.

Why merge

Prevents leftover temp directories on exceptions, handles BOM-bearing indexes, and gives a clear verdict when programs produce different word counts.

Verdict: Approve

@shayderrr
shayderrr merged commit 829e5ed into ItsNotRexed:main Nov 23, 2026
0 of 2 checks passed
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.

4 participants