tests: test_mutations copies tools/ once and runs only the test each mutation must break (TEST-MUTATIONS-COST) #1516
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1516"
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?
Imported from ubiquitarianism/leonida. Originally posted by milk4sale on 2026-11-25T03:03:15Z.
Claimed in the coordination issue as: TEST-MUTATIONS-COST (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7150964147)
What and why
tests/semantic/test_mutations.pywas the last file still running in all 23semantic-tests (windows-latest)runs measured for #1462, and in the 14 of them that were cancelled at the 10-minute limit it was the only file still running. For each of its 14 runs oftest_ps_semantics.py(the baseline and 13 mutations) it copiedtools/(332 files, 8.6 MB) into a new temporary folder, deleted it afterwards, and ran the whole file.Now
test_each_mutation_is_caughtmakes one copy for all 13 mutations. Each mutation starts from the original translator and writes it back in afinally, so withtest_baseline_copy_passes's own copy, 14 copies oftools/become 2: about 660 files written and deleted instead of about 4,650. Each mutation runs only the test it must break,test_ps_semantics.TranslatorSemantics.<test>, so the 13 mutation runs translate 13 shaders instead of 78.failed_testsnow counts only failures reported forTranslatorSemantics. A test name the class does not have fails too, asERROR: test_x (unittest.loader._FailedTest.test_x), so with one test per run the old pattern would have counted a misspelled expected test as caught (checked below).What the file checks stays the same: the whole of
test_ps_semantics.pypasses on an unmutated copy, each anchor must match exactly once, each mutation must make its test fail,test_anchors_match_crlf_translator_copiesis untouched, and the repository's owntools/is never written. The children keepPYTHONDONTWRITEBYTECODE=1. Now that the translator is rewritten in place, that also stops a.pycof one mutant being run for a later mutant of the same size written in the same second. A comment says so.Why I expect it to help on Windows (a hypothesis, not measured there)
Per-file times of the two legs of the same run, from the job logs of the 9 runs in #1462's table that ran to their end (the
Ran N tests in X sof each file):test_mutationsWindowsThe rest of the suite took 0.76-1.61 times as long on Windows as on Linux;
test_mutationstook 5.8-11.1 times as long. Most of what its children do is the same CPU work the other files do (compiling and running the translator), so I expect most of the difference to come from what only this file does: writing and deleting about 330 files 14 times, and starting 14 Python processes that each import the translator from a folder created just before. This change removes 12 of the 14 copies. It keeps the 14 processes and their 14 compiles of the 1.1 MB translator, which are the main cost on Linux. Only a Windows run can confirm it. The Windows leg runs on the first push tomainafter this merges; GitHub blocked my fork's Actions on 25 November, so I could not dispatch one.Tested
On Linux (Ryzen 9 7900X, 24 threads, Python 3.14.10; CI uses 3.12), with
mainatf78385646and this change on top of it, each exported to its own folder, alternating between the two in every round:mainrun_semantic_tests.py tests/semantic -p test_mutations.py, median of 8 (load average 6-12)test_each_mutation_is_caught(unittest --durations), median of 6test_anchors_match_crlf_translator_copies(unchanged)test_baseline_copy_passes(unchanged)The gain on Linux is small: copying
tools/takes about 16 ms here, and a child spends about 0.19 s of its 0.25 s import compilingrdna2spirv.py(-X importtime). Most of the time the file still takes goes into 27 compiles of the translator, 14 in the children and 13 in the CRLF test.sext()) changed, run against this branch's file andmain's: a misspelled expected test (test_ps_sdwz), a real test that mutation does not break (test_ps_ops), a replacement that changes nothing, and an anchor that no longer matches. Every one fails on both, with only that subtest failing and the other 12 mutations passing. With the oldfailed_testspattern put back, the misspelled name passes on this branch; that is why the pattern now names the class.test_each_mutation_is_caught. Each of the 13 children saw the original translator with only its own mutation applied (13 different texts), and the copy's translator was byte-identical totools/rdna2spirv.pybefore each mutation and at the end.python -I scripts/run_semantic_tests.py tests/semanticon this branch (onmainatb07b9ecb0): 487 files, 6,279 tests, 0 files failed in 69 s with 24 jobs.python -I scripts/check_no_game_data.py tests/semantic/test_mutations.py: clean.python -I tests/test_text_write_line_endings.py: passes.GPUs tested: n/a (one test file)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase). No open pull request changestests/semantic/test_mutations.py.docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by ytsodacan on 2026-11-25T03:34:03Z.
[KEEP]
tests/semantic/test_mutations.py; one sharedtools/copy, original restored in afinally, and thefailed_testsregex now requiresTranslatorSemantics, so a misspelled expected test can no longer count as caught.change-scopeandno-game-dataare still pending, and the Windowssemantic-testsleg this targets has not reported yet.Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T23:01:14Z.
Native Windows 11 Verification (
a94c7e0c4d) — PASSDiff-audited
tests/semantic/test_mutations.py(+24/-10) and verified Red -> Green merged ontoorigin/main(adfb3821a2) on Windows 11 (10.0.26200, NTFS, Python3.12.10with-I).Results
_FailedTestfalse-positive guard onorigin/main): Passing synthetic loader failure outputERROR: test_bogus (unittest.loader._FailedTest.test_bogus)totest_mutations.failed_tests(...)onorigin/mainfalsely matched{'test_bogus'}, meaning a typoedMUTATIONStarget method name would silently passself.assertIn(expect, failed_tests(out)).PR #1516merged ontoorigin/main):failed_tests(...)on the sameunittest.loader._FailedTestline returnsset()because the regex now anchors(test_ps_semantics.TranslatorSemantics\b.python -I tests/semantic/test_mutations.py:Ran 3 tests — OK(rc=0), catching all 13 translator mutants while reusing a single temporarytools/copy (1shutil.copytreeinstead of14on NTFS) withPYTHONDONTWRITEBYTECODE=1andtry/finallybyte-exact original-source restoration between mutants.run_semantics(tools)14.37svsrun_semantics(tools, 'test_ps_sdwa')14.95s) is dominated byPYTHONDONTWRITEBYTECODE=1re-parsing the ~20k-linetools/rdna2spirv.pymodule on each child startup rather than shader translation (< 0.2s), so wall-clock time stays roughly comparable on Windows while eliminating 13 directory-tree copies and closing the_FailedTestfalse-positive hole.scripts/check_no_game_data.py,tests/test_ci_registration.py(18/18), andtests/test_text_write_line_endings.py(3/3) all pass (rc=0).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:17:14Z.
Tested
a94c7e0c4merged (no commit) withmain829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only.check_no_game_data.pyis clean.tests/semantic/test_mutations.py, 3 tests pass (206 s). Themainversion passes too.No blocker from my side.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T14:17:56Z.
Ready for testing: merges cleanly with
main3535eb5c4. Not inmainyet:git cherryfinds 1 commit(s) not there, and 7 of the 22 lines it adds are already present. No duplicate found: its claimTEST-MUTATIONS-COSTappears in no other open pull request and in nomaincommit.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T15:43:59Z.
RUN report for #1516 (TEST-MUTATIONS-COST)
Kind: tests only (one file,
tests/semantic/test_mutations.py), so there is no non-test change to revert for a red.Heads: PR head
a94c7e0c4, based onb07b9ecb0; origin/mainbd643e46e(merged locally withgit merge --no-edit --no-ff, clean, 1 file).Command (one process, repo root):
python -I scripts/run_semantic_tests.py tests/semantic -p test_mutations.py -j 1 -v(Python 3.13.12).Results:
test_anchors_match_crlf_translator_copies,test_baseline_copy_passes,test_each_mutation_is_caught), 585 s.TranslatorSemanticsdoes not have: FAIL for that subtest ("'test_ps_sdwz' not found in set()", the child reportsunittest.loader._FailedTest), the file as a whole FAILED (failures=1). This is the case the newfailed_testspattern is for.^(?:FAIL|ERROR): (test_\w+)put back: the file passes (3 of 3 OK). That is the false green the new pattern prevents.tools/become 2); one pair of runs here is consistent with a gain but is not proof. The whole file takes about 10 minutes on this machine, against 6 s on Linux in the PR text.tests/semanticsuite (the PR touches only this file).Machine: Windows 11 Pro x64, RTX 3090 24 GB, NVIDIA 621.40, Python 3.13.12 (
python -I).Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:36:36Z.
Review: APPROVED
LGTM. Reusing one
tools/copy (restoring each mutated file infinally), running only the targetedTranslatorSemantics.<expect>case per mutation, and tighteningfailed_tests()to matchtest_ps_semantics.TranslatorSemantics(preventingunittest.loader._FailedTestfalse positives) intests/semantic/test_mutations.pyis clean and well-verified. Clean-room verified andMERGEABLE; holding merge until a fresh green CI pass completes on currentmain.(AI-assisted review.)