Repository navigation
tools/semantic_mutants.py: op-scoped mutation testing for tests/seman… - #6548
Open
BeegSchmooze wants to merge 2 commits into
Open
BeegSchmooze wants to merge 2 commits into
BeegSchmooze wants to merge 2 commits into
Conversation
…tic files
Finds the translator code for an op in tools/rdna2spirv.py (the if/elif
branch naming it, a method, or a line range), makes one-line mutants with
standard operators (opcode and GLSL.std.450 pairs, comparisons, small
self.cu() constants +-1, swapped OpSelect arms, a repeated last operand),
writes each into a private copy of tools/ and runs the given test file
against it through LEONIDA_TOOLS_DIR, as tests/semantic/test_mutations.py
does. Prints which mutants the file still passes; exit 1 if any survive,
2 on a usage or baseline error. The repository's tools/ is never touched.
tests/test_semantic_mutants.py: branch lookup (multi-line conditions,
shared branches), mutant generation (operators, comments and other
branches left alone), and an end-to-end run on v_sad_u8's UMax line: a
test with only S0 >= S1 inputs lets `UMax {xa} {xa}` survive, one with a
reversed case catches it. tests/semantic/README.md documents the tool.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 23, 2026
Many ops are translated through a lookup table rather than an `if op` branch (F1 for rcp/rsq/sqrt/exp/log/floor/..., LDS_ATOMICS for the LDS atomics), and those got no mutants. With --op, an entry `"op": "Value"` in a dict literal now also gets each other value of the same table (up to 6): v_rsq_f32 -> "Sqrt", ds_sub_u32 -> "OpAtomicIAdd", and so on. An op found only in a table is no longer an error. tests/test_semantic_mutants.py: a table unit test (commented values are not candidates) and a --list check on the real translator's v_rsq_f32. 8 tests OK; docs tests 33/33. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Update
AI-assisted (Claude Code). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: #6214 (comment) (new TEST item)
What and why
Of 23 open tests/semantic PRs I mutation-checked by hand (summary: #6089 (comment)), 10 let a wrong translation pass. The usual reason is that a case named test_mutation_* or a negative control asserts on the file's own Python model, not on translated output. Another is inputs that can't tell the variants apart. tests/semantic/test_mutations.py guards a fixed list of 13 mutations against test_ps_semantics.py only. Nothing lets an author or reviewer check a new test file.
tools/semantic_mutants.py does that:
python -I tools/semantic_mutants.py tests/semantic/test_valu_sad_u8_hw.py --op v_sad_u8
python -I tools/semantic_mutants.py tests/semantic/test_x.py --function swizzle
python -I tools/semantic_mutants.py tests/semantic/test_x.py --lines 8375-8414
It finds the code that translates the op in tools/rdna2spirv.py: the if/elif op branch naming it (conditions over several lines included), a method, or a line range.
It makes one-line mutants inside that code: opcode pairs (OpIAdd/OpISub, And/Or/Xor, shifts, conversions, atomics), GLSL.std.450 pairs (UMin/UMax, SMin/UMin, NMin/FMin, Floor/Ceil, ...), comparisons made strict/non-strict or of the other signedness, small self.cu(N) constants ±1, swapped OpSelect arms, and an emitted instruction's last operand replaced by the one before it. Comment lines and comments are left alone.
Each mutant goes into one private copy of tools/, and the test file runs against it through LEONIDA_TOOLS_DIR, as test_mutations.py does. The repository's tools/ is never modified. The unmutated copy must pass first.
Output: caught / SURVIVED per mutant. Exit 1 if any survive, 2 on a usage or baseline error. For a branch shared by several ops it prints the others, since a test of one op can't be expected to catch their lines.
A survivor is a lead, not a verdict. Some mutants are equivalent (e.g. UMax → SMax on byte values), and the README says so.
Tested
Windows 11, Python 3.13, on main @ 561b65a. No game files, no GPU.
tests/test_semantic_mutants.py: 6 tests OK (47 s). They cover branch lookup on multi-line and shared conditions, a missing op, methods; the operators; comments and other branches left alone; and an end-to-end run on v_sad_u8's UMax line. A synthetic test with only an S0 ≥ S1 input lets UMax {xa} {xa} survive (exit 1), and adding a reversed case catches it.
On real PR test files (the tool copied into those PRs' trees):
#5694's v_sad_u8 test: 10 of 19 caught. The survivors include UMax {xa} {xa}, the missing-abs weakness I'd found by hand, and OpBitFieldUExtract → SExtract on S1 (no case has an S1 byte ≥ 0x80). The others are v_msad_u8/v_sad_hi_u8 lines in the shared branch, or equivalent.
#5835's 3-input bundle: 19 of 22 caught. The 3 survivors are OR ↔ XOR swaps, a lead my hand-picked mutations had missed (its inputs have no overlapping bits).
Docs tests 33/33. test_runtime_paths, test_check_no_game_data and test_text_write_line_endings pass.
AI-assisted: yes (Claude Code)
Checklist
No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)
🤖 Generated with Claude Code