Skip to content

tests: test_mutations copies tools/ once and runs only the test each mutation must break (TEST-MUTATIONS-COST) - #1516

Open
milk4sale wants to merge 1 commit into
ProjectLeonida:mainfrom
milk4sale:tests/mutations-one-copy
Open

milk4sale wants to merge 1 commit into
ProjectLeonida:mainfrom
milk4sale:tests/mutations-one-copy

Conversation

@milk4sale

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-MUTATIONS-COST (#14 (comment))

What and why

tests/semantic/test_mutations.py was the last file still running in all 23 semantic-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 of test_ps_semantics.py (the baseline and 13 mutations) it copied tools/ (332 files, 8.6 MB) into a new temporary folder, deleted it afterwards, and ran the whole file.

Now test_each_mutation_is_caught makes one copy for all 13 mutations. Each mutation starts from the original translator and writes it back in a finally, so with test_baseline_copy_passes's own copy, 14 copies of tools/ 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_tests now counts only failures reported for TranslatorSemantics. A test name the class does not have fails too, as ERROR: 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.py passes on an unmutated copy, each anchor must match exactly once, each mutation must make its test fail, test_anchors_match_crlf_translator_copies is untouched, and the repository's own tools/ is never written. The children keep PYTHONDONTWRITEBYTECODE=1. Now that the translator is rewritten in place, that also stops a .pyc of 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 s of each file):

Run (fork) test_mutations Windows Linux Windows / Linux All other files, Windows / Linux
45335997425 340 s 33.2 s 10.2x 911 s / 565 s = 1.61x
45360123747 269 s 33.9 s 7.9x 792 s / 682 s = 1.16x
45398596589 264 s 45.2 s 5.8x 804 s / 961 s = 0.84x
45420340290 250 s 41.3 s 6.1x 705 s / 928 s = 0.76x
45432144669 316 s 46.0 s 6.9x 798 s / 970 s = 0.82x
45455214398 297 s 45.4 s 6.5x 913 s / 983 s = 0.93x
45466210143 381 s 34.2 s 11.1x 940 s / 757 s = 1.24x
45504536550 288 s 36.5 s 7.9x 1012 s / 682 s = 1.48x
45514815352 352 s 42.9 s 8.2x 976 s / 1027 s = 0.95x

The rest of the suite took 0.76-1.61 times as long on Windows as on Linux; test_mutations took 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 to main after 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 main at f783856 and this change on top of it, each exported to its own folder, alternating between the two in every round:

main this branch
run_semantic_tests.py tests/semantic -p test_mutations.py, median of 8 (load average 6-12) 6.93 s wall, 6.86 s CPU 6.43 s wall, 6.35 s CPU
the same, median of 6, while another job loaded the machine (load average 27-29) 11.40 s wall, 10.68 s CPU 10.19 s wall, 9.58 s CPU
test_each_mutation_is_caught (unittest --durations), median of 6 4.42 s 3.84 s
test_anchors_match_crlf_translator_copies (unchanged) 2.21 s 2.20 s
test_baseline_copy_passes (unchanged) 0.32 s 0.33 s

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 compiling rdna2spirv.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.

  • Sabotage checks. Each is a copy of the file with its first mutation (SDWA sext()) changed, run against this branch's file and main'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 old failed_tests pattern put back, the misspelled name passes on this branch; that is why the pattern now names the class.
  • An instrumented run of 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 to tools/rdna2spirv.py before each mutation and at the end.
  • python -I scripts/run_semantic_tests.py tests/semantic on this branch (on main at b07b9ec): 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase). No open pull request changes tests/semantic/test_mutations.py.
  • One topic; follow-up work goes in a new pull request.
  • 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. (No translator change.)

🤖 Generated with Claude Code

…mutation must break (TEST-MUTATIONS-COST)

test_mutations.py is the last file still running in every semantic-tests (windows-latest) run measured for ProjectLeonida#1462,
250-381 s there against 33-46 s on the Linux leg of the same runs, while the rest of the suite took 0.76-1.61 times
as long on Windows as on Linux. For each of its 14 runs of test_ps_semantics.py (the baseline and 13 mutations) it
copied tools/ (about 330 files) into a new temporary folder, deleted it afterwards, and ran the whole file.

test_each_mutation_is_caught now makes one copy for all 13 mutations: each starts from the original translator and
writes it back in a finally, so 14 copies become 2. Each mutation runs only the test it must break
(test_ps_semantics.TranslatorSemantics.<test>), so its child translates one shader instead of six. failed_tests
counts only failures reported for TranslatorSemantics: a name the class does not have fails too, as
"ERROR: test_x (unittest.loader._FailedTest.test_x)", and with one test per run the old pattern would have counted
a misspelled expected test as caught.

What the file checks is unchanged: the whole of test_ps_semantics.py passes on an unmutated copy, each anchor
matches exactly once, each mutation makes its test fail, the CRLF anchor test is untouched and the repository's
tools/ is never written. The children keep PYTHONDONTWRITEBYTECODE=1, which now also keeps a .pyc of an earlier
mutant from being run for a later one of the same size written in the same second; a comment says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ytsodacan

ytsodacan commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

[KEEP]

  • Change looks sound and tightly scoped: only tests/semantic/test_mutations.py; one shared tools/ copy, original restored in a finally, and the failed_tests regex now requires TranslatorSemantics, so a misspelled expected test can no longer count as caught.
  • CI has not finished: change-scope and no-game-data are still pending, and the Windows semantic-tests leg this targets has not reported yet.
  • The PR states the Windows speedup is a hypothesis, not measured. Hold until a green Windows run shows the file completes well inside the limit.
  • No duplicate open PR; ci: give the Windows semantic-tests leg 20 minutes; it was cancelled at 10 in 14 of 23 runs (CI-SEMANTIC-WIN-TIME-LIMIT) #1462 (Windows time limit) is related but complementary.
  • Re-triage once CI is green; this should then be mergeable.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Native Windows 11 Verification (a94c7e0c4d) — PASS

Diff-audited tests/semantic/test_mutations.py (+24/-10) and verified Red -> Green merged onto origin/main (adfb3821a2) on Windows 11 (10.0.26200, NTFS, Python 3.12.10 with -I).

Results

  • Red (_FailedTest false-positive guard on origin/main): Passing synthetic loader failure output ERROR: test_bogus (unittest.loader._FailedTest.test_bogus) to test_mutations.failed_tests(...) on origin/main falsely matched {'test_bogus'}, meaning a typoed MUTATIONS target method name would silently pass self.assertIn(expect, failed_tests(out)).
  • Green (PR #1516 merged onto origin/main):
    • failed_tests(...) on the same unittest.loader._FailedTest line returns set() because the regex now anchors (test_ps_semantics.TranslatorSemantics\b.
    • Full suite python -I tests/semantic/test_mutations.py: Ran 3 tests — OK (rc=0), catching all 13 translator mutants while reusing a single temporary tools/ copy (1 shutil.copytree instead of 14 on NTFS) with PYTHONDONTWRITEBYTECODE=1 and try/finally byte-exact original-source restoration between mutants.
    • Windows Timing Observation: Isolated single-subprocess timing on Windows (run_semantics(tools) 14.37s vs run_semantics(tools, 'test_ps_sdwa') 14.95s) is dominated by PYTHONDONTWRITEBYTECODE=1 re-parsing the ~20k-line tools/rdna2spirv.py module 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 _FailedTest false-positive hole.
    • Policy & Hygiene: scripts/check_no_game_data.py, tests/test_ci_registration.py (18/18), and tests/test_text_write_line_endings.py (3/3) all pass (rc=0).

AI-assisted.

@TheGeogeo

Copy link
Copy Markdown
Contributor

Tested a94c7e0c4 merged (no commit) with main 829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Test-only change: tests/semantic/test_mutations.py, 3 tests pass (206 s). The main version passes too.
  • There is no red to show, since no other file changes.

No blocker from my side.

AI-assisted (Claude Code).

@TheGeogeo

Copy link
Copy Markdown
Contributor

Ready for testing: merges cleanly with main 3535eb5c4. Not in main yet: git cherry finds 1 commit(s) not there, and 7 of the 22 lines it adds are already present. No duplicate found: its claim TEST-MUTATIONS-COST appears in no other open pull request and in no main commit.

AI-assisted (Claude Code).

@enlight3d

Copy link
Copy Markdown
Contributor

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 on b07b9ecb0; origin/main bd643e46e (merged locally with git 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:

  • GREEN at PR head: 3 of 3 tests OK (test_anchors_match_crlf_translator_copies, test_baseline_copy_passes, test_each_mutation_is_caught), 585 s.
  • GREEN merged into origin/main: 3 of 3 OK, 632 s (two other runs were going on the same machine).
  • Plain origin/main: 3 of 3 OK, 704 s.
  • RED: no red from reverting, since the PR changes only the test. I ran the PR's own sabotage checks instead, on copies of the PR file (untracked, deleted afterwards):
    • (a) first mutation's expected test renamed to a name TranslatorSemantics does not have: FAIL for that subtest ("'test_ps_sdwz' not found in set()", the child reports unittest.loader._FailedTest), the file as a whole FAILED (failures=1). This is the case the new failed_tests pattern is for.
    • (b) the same rename with the old pattern ^(?:FAIL|ERROR): (test_\w+) put back: the file passes (3 of 3 OK). That is the false green the new pattern prevents.
  • Timing (Windows, single samples, not a benchmark): 704 s on main vs 585 s on the PR head, about 17 percent less. The PR text gives a hypothesis for Windows (14 copies of 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.
  • Not run: the whole tests/semantic suite (the PR touches only this file).

Machine: Windows 11 Pro x64, RTX 3090 24 GB, NVIDIA 621.40, Python 3.13.12 (python -I).

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.

5 participants