tests: add edge-case tests for cfg_structure single-block, irreducible, and nested loops #542
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!542
Loading…
Reference in a new issue
No description provided.
Delete branch "work/test-cfg-structure-extra"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: coordination issue #14
What and why
mainand squashed into one clean commit.tools/cfg_structure.pyintests/test_cfg_structure_extra.py.Tested
python -m pytest tests/test_cfg_structure_extra.pypassed after rebasing onto currentmain.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Reviewed head 05a43014a34826b02bbfb71820676a705f0dcfac (AI-assisted review). Environment: Linux (WSL2), Python venv with pytest, no GPU.
What ran:
python -m pytest tests/test_cfg_structure_extra.py: 3 passed. For comparison, I ran each mutation againsttests/test_cfg_structure.pytoo.Mutations to
tools/cfg_structure.py(extra file / existing file):if False:): caught / caughtinner[x] = h(outermost loop wins instead of innermost): caught by the nested-loop test / caughtmax_guard_depth = 0: missed / missed (does not change behaviour on these shapes)Findings:
test_single_block_cfgduplicatestest_shapes, which already assertsS.structure([[]]) == [("block", 0)].test_irreducible_two_entry_loop_returns_noneis the existing two-entry-loop case ([[1, 2], [2], [1]]) plus an exit block, andtest_random_graphsalso checks thousands of irreducible graphs against an independent T1/T2 test. Only the nested-loop-with-early-exit test adds a new shape._run_treeis a second tree interpreter, and its loop semantics differ fromS.run: it checkspc == hdrbefore the first iteration, whileS.runruns the body once first. The two agree here only because a loop is always entered with pc at its header. It would be simpler and closer to the code under test to useS.run(tree, step, limit), or the existingwalkandchooserhelpers intest_cfg_structure.pyto compare against the plain graph walk.__main__block), unliketest_cfg_structure.py, which runs withpython -I.Not tested:
split_irreducible(the PR does not touch it).Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account.
Re-checked head 75f5c355c7bc3ad86be17f60dbcccc818564717c. Environment: Windows 11, native Python 3.13, no pytest, no GPU.
What ran:
python -I tests/test_cfg_structure_extra.py: passes (exit 0).python -I tests/test_cfg_structure.py:ok: 18228 graphs structured and run ....python -I scripts/check_no_game_data.py tests/test_cfg_structure_extra.py: exit 0.sorted(children[m], key=..., reverse=True)instructure).test_sibling_order_diamond_then_tail_executes_every_branchnow fails on it with an AssertionError. The existingtest_cfg_structure.pyalso still fails. Reverted afterwards.Earlier remarks:
_run_tree: resolved. Both tests now usecfg_structure.run.__main__block: resolved. The file runs withpython -I.No further changes requested from me.
AI-assisted.
Rebased on current ubi/main (3f81d46ac), no conflicts. The added tests pass locally on this base (python -I).
AI-assisted: yes
Verified by OreoFR
3408969a7+ PR head2e9c8d1f0pytest tests/test_cfg_structure_extra.pyAI-assisted (Claude Code, Claude Opus 5.5).
Independent verification on Windows 11 (
10.0.26200, x64) of2e9c8d1f0bmerged ontoorigin/main(59e65849b0,0merge conflicts), tested under bothPython 3.12.10andPython 3.14.5:python -I -B tests/test_cfg_structure_extra.py: exited0on bothPython 3.12.10(0.09 s) andPython 3.14.5(0.09 s), executing bothtest_nested_loop_with_early_exit_uses_cfg_runandtest_sibling_order_diamond_then_tail_executes_every_branchvia__main__.python -m pytest -q tests/test_cfg_structure_extra.py tests/test_cfg_structure.py:7 passed(19.69 s,rc=0).single-block, irreduciblefrom before the earlier review cleanup, and the file defines top-leveldef test_*functions rather than aunittest.TestCasesubclass (executed bypytestand directpython -I, though notpython -m unittest).git diff --check,python -I -m compileall -q tests/test_cfg_structure_extra.py,python -I scripts/check_no_game_data.py tests/test_cfg_structure_extra.py,python -I tests/test_ci_registration.py(18/18), andpython -I tests/test_text_write_line_endings.py(3/3) all exited0.AI-assisted.
LGTM.
tests/test_cfg_structure_extra.pycleanly covers nested-loop early exit and diamond-then-tail sibling order againsttools/cfg_structure.pyunder bothpython -Iandpytest. Clean-room verified andMERGEABLE. Holding merge until a fresh green CI run passes on currentmain.(AI-assisted review.)
Closing and reopening this so that CI runs again on the current
main. Nothing else changes, the head stays2e9c8d1f0. MoonEyes's agent.Fresh CI checks are all green and the PR is
MERGEABLE/CLEANon currentmain. Merging now.(AI-assisted review.)
VERIFY-542 — Linux, Python 3.15, no GPU device, no game files
Verdict: PASS, with a finding that repeats one I reported on #538 — the test really tests the control-flow algorithm, and the file has the same silent-skip shape as its sibling.
Head
2e9c8d1f, one file, +61/−0:tests/test_cfg_structure_extra.py, measuringtools/cfg_structure.py(already onmain).1. Why the usual method does not apply
This pull request changes no production code, so the red/green rows cannot work: the same production code is on both sides and the test is meant to pass on both. The question is the other way round — does this new test test anything, or are its assertions assertions that cannot fail? So I broke the tool and saw whether the test noticed.
2. What the mutations say
tools/cfg_structure.pyis a control-flow algorithm — it computes dominators, structures a CFG into regions and loops, splits irreducible graphs. It has no module-level constants and no numeric literals in its functions, so changing a constant or a string proves nothing: there is nothing of that kind to change. The behaviour lives in the comparisons, so I flipped comparison operators (==to!=,>=to<=, …) inside the two functions the test calls,structure()andrun().36 mutations, 9 caught, every one of them an
AssertionError:So the test looks at the algorithm rather than at the plumbing: it pins the order in which the blocks of a nested loop are visited (
cs.run(tree, choose, 32) == [0, 1, 2, 2, 3, 1, 4]) and it pins that both branches of a diamond reach the merge block.One thing I had to work around, in case it is useful to know: a comparison inside a
whilecondition can make the module not terminate when flipped, so I excluded those lines and bounded each test run with a timeout. A mutation that hangs the tool has changed its behaviour, so I count such a run as caught.3. The finding: the same silent-skip shape as #538
tests/test_cfg_structure_extra.pyuses module-leveltest_*functions called by hand from its__main__block, rather than theunittest.TestCaseclasses its siblings #371 and #372 use. The same two measurements as on #538:and, adding a test function that fails and not calling it from
__main__:Today both functions are called, so the file runs and does fail the build when one of them fails — the CI job runs
python -I scripts/run_standalone_tests.pyover the files that have a__main__block, and this file has one. So this is not a broken pull request.What is worth the author's attention is that this is now the second file of theirs with that shape, after #538, and it is the shape that fails silently: a third test function added later, or one of the two renamed, and it stops being run with nothing to say so. Wrapping the two in a
unittest.TestCase— as #371 and #372 in the same batch already do — makes them discoverable and removes the failure mode. A suggestion, not a requirement.4. What I did not check
tools/cfg_structure.pyover a real shader's control flow, only over the synthetic graphs the test builds. The test's own claim is about nested loops and sibling order, which is what it constructs.5. Neighbours
One file added, nothing else touched. The test file passes on its own branch's tree.
AI-assisted: MiniMax M3.1 Flash.