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

Open
opened 2026-11-26 20:21:37 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1516
Author: @milk4sale
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: tests/mutations-one-copy


📝 Commits (1)

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

📊 Changes

1 file changed (+26 additions, -12 deletions)

View changed files

📝 tests/semantic/test_mutations.py (+26 -12)

📄 Description

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.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 f78385646 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 b07b9ecb0): 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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1516 **Author:** [@milk4sale](https://github.com/milk4sale) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `tests/mutations-one-copy` --- ### 📝 Commits (1) - [`a94c7e0`](https://github.com/ubiquitarianism/leonida/commit/a94c7e0c4d24108c9cfd0c7e2993e74e170b6e91) tests: test_mutations copies tools/ once and runs only the test each mutation must break (TEST-MUTATIONS-COST) ### 📊 Changes **1 file changed** (+26 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/test_mutations.py` (+26 -12) </details> ### 📄 Description 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.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](https://github.com/milk4sale/leonida/actions/runs/45335997425) | 340 s | 33.2 s | 10.2x | 911 s / 565 s = 1.61x | | [45360123747](https://github.com/milk4sale/leonida/actions/runs/45360123747) | 269 s | 33.9 s | 7.9x | 792 s / 682 s = 1.16x | | [45398596589](https://github.com/milk4sale/leonida/actions/runs/45398596589) | 264 s | 45.2 s | 5.8x | 804 s / 961 s = 0.84x | | [45420340290](https://github.com/milk4sale/leonida/actions/runs/45420340290) | 250 s | 41.3 s | 6.1x | 705 s / 928 s = 0.76x | | [45432144669](https://github.com/milk4sale/leonida/actions/runs/45432144669) | 316 s | 46.0 s | 6.9x | 798 s / 970 s = 0.82x | | [45455214398](https://github.com/milk4sale/leonida/actions/runs/45455214398) | 297 s | 45.4 s | 6.5x | 913 s / 983 s = 0.93x | | [45466210143](https://github.com/milk4sale/leonida/actions/runs/45466210143) | 381 s | 34.2 s | 11.1x | 940 s / 757 s = 1.24x | | [45504536550](https://github.com/milk4sale/leonida/actions/runs/45504536550) | 288 s | 36.5 s | 7.9x | 1012 s / 682 s = 1.48x | | [45514815352](https://github.com/milk4sale/leonida/actions/runs/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 f78385646 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 b07b9ecb0): 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 - [x] 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`. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1547
No description provided.