Skip to content

run_wine_tests: --jobs N runs Wine tests side by side (802 s -> 129 s on 4 CPUs), depends on #4462 - #4691

Open
tedin7 wants to merge 9 commits into
ItsNotRexed:mainfrom
tedin7:speed2-wine
Open

tedin7 wants to merge 9 commits into
ItsNotRexed:mainfrom
tedin7:speed2-wine

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: #4571 (comment)

Depends on: #4462 (same file, built on its head; its commits appear here until it lands).

Why

Every Runtime run has two Wine jobs (Ubuntu's Wine and WineHQ's). In the last CI run I could read (https://github.com/ItsNotRexed/Leonida/actions/runs/45044832456, job 137330510838) the log timestamps show the runner doing one test every 1.27 s: 102 of the 112 tests took 1.2-1.3 s each (~130 s), the other 10 are the ones #4462 stops waiting 120 s for. After #4462 that ~130 s of one-test-at-a-time is the biggest part of each Wine job (apt + prefix are 45-90 s). The runner never starts a second test while the first runs, although the runner has 4 CPUs and each test is its own Wine process.

The CI queue is the bottleneck (8 concurrent slots, see #4571), so slot time is what everyone waits for: 2 Wine jobs x ~85 s x ~2,000 Runtime runs a day is the largest single item I found after #4462, #4357 and #3879 (estimate below).

What

  • --jobs N (default 1: the old behaviour, same order, same output): up to N tests run at once.
  • Tests that must not overlap do not: the tests of one program (they can share a scratch folder named after it) run on one lane in list order; every test with DEPENDS, FIXTURES_SETUP/REQUIRED/CLEANUP or RESOURCE_LOCK, and every test one of them names in DEPENDS, shares one lane in list order (CTest's order); RUN_SERIAL tests run alone, first. A program that has one ordered test keeps all its tests on the ordered lane, and when that lane holds a RUN_SERIAL test the whole lane runs alone, in order, so the test still follows its setup.
  • Each test runs in its own process group (on Windows, its own process tree). At the timeout the whole group is stopped, so a test that relaunched gta6rt or started a helper leaves nothing running beside the next tests on the shared prefix.
  • Each test keeps its own timeout. A test that hangs holds one worker for at most that long; the others go on. An unexpected exception in a worker fails that test (the runner raised ...) instead of leaving the others unreported. With --jobs 1 nothing is caught, as before.
  • Results are printed as tests finish (a lock keeps the lines whole); the summary table keeps list order, the counts and the exit code are the same.
  • runtime.yml: the Wine step passes --jobs "$(nproc)". docs/testing.md and the module docstring say what --jobs does.

Tested

On the RunPod pod: a clang-cl/xwin cross build of main (d0835dd9, 460 steps, 107 s at -j12), Wine 11.0, Mesa lavapipe (VK_ICD_FILENAMES=lvp_icd, as CI), the run pinned to 4 CPUs (taskset) with Xvfb, a fresh prefix, the runner of #4462. 156 ctest entries (114 pass, 7 fail, 35 skip: the 7 fail the same way with and without --jobs; they are host-D3D12 comparisons and a timing test that need other hardware, not something this changes).

run seconds statuses
--jobs 1, run 1 802 md5 8f847cb8...
--jobs 1, run 2 816 md5 8f847cb8...
--jobs 4, run 1 129 md5 8f847cb8...
--jobs 4, run 2 133 md5 8f847cb8...
--jobs 4, run 3 124 md5 8f847cb8...
--jobs 4, after the review fixes 120 same 156 statuses

(The md5 is of the sorted [PASS]/[FAIL]/[SKIP] name lines: all five runs have the same status for every one of the 156 tests. Median 809 s -> 129 s; the pod was at load ~20 while it ran, so the absolute seconds are noisy and slower per test than a CI runner, ~5 s a test against 1.3 s.)

  • python -I tests/test_run_wine_tests.py: 74 tests OK (63 existing + 11 new), 3 runs. New: same results as one at a time, summary in list order, the same program never overlaps while different programs do, RUN_SERIAL runs alone, a fixture is set up before the test that needs it, a hanging test (60 s, --timeout 1.5) costs its own timeout and the other tests end beside it (with --jobs 1 forced this test fails: negative control), a runner error fails that test only, --jobs must be a whole number >= 1; from an independent review: a RUN_SERIAL test with a fixture still runs after its setup, one program never overlaps itself when only one of its tests has an ordering, and a timeout also stops a process the test started (the three fail on the version before the review fixes).
  • Not measured: the real CI runner. Estimate for CI, from the log timestamps above: ~130 s serial per Wine job; with 4 jobs on 4 CPUs the pod ran 6.2x faster, so I expect 2.5-3.5x there: ~45 s, i.e. ~85 s x 2 jobs x ~2,000 runs/day = ~5,700 runner-minutes a day. If a Wine test turns out to depend on another one's side effects, --jobs goes back to 1 in the workflow (one word).
  • Update after CI: run the Wine jobs and the Windows semantic-tests leg on main only (cuts CI demand by 65%) #4657 (merged 04:04 UTC, before this PR was opened; I missed it): the Wine jobs now run only on main pushes and workflow_dispatch, not on PRs. In the 24 h before this note that was 41 runtime.yml runs on main against ~2,500 on PRs, so the CI saving is about 41 x 2 jobs x ~85 s, ~115 runner-minutes a day, not ~5,700. What stays: the Wine result on main comes back in ~2 minutes instead of ~13 after each merge round, and local Wine runs (run_wine_tests.py --jobs N) are 6x faster.

Not covered

AI-assisted (Claude Code), with an independent AI review before opening. No game files.

…nedbg

Wine starts its crash debugger for an unhandled exception, such as a call to a function it does not implement. On Xvfb nothing ends it, so the test waited for the 120 s timeout (6 tests, 720 s of one Wine job). The runner now sets AeDebug Debugger to false in the prefix for the run and restores it; the test still fails, in under a second. --keep-wine-debugger leaves the old behaviour.
…h a retry, and keep an abort a failure

Review of ItsNotRexed#4462. The Debugger value is changed only when it is exactly the REG_SZ default or the query shows it absent (another command, a wrapper, REG_EXPAND_SZ, an empty value or a failed query is left alone). A restore that fails is retried once and then reported with the command that restores it by hand. A test that Wine aborted is a failure whatever WILL_FAIL, the exit code or PASS_REGULAR_EXPRESSION say, as it was when the crash debugger kept it waiting until the timeout. docs/testing.md names the SIGKILL and shared-prefix limits.
…e all CPUs

Each test is its own Wine process and the runner ran them one after another (about 130 s for the 100 tests that are not aborted on the CI runner). --jobs N (default 1: unchanged) runs up to N at once. Tests of one program, tests with a CTest DEPENDS, fixture or RESOURCE_LOCK stay in order on one lane, RUN_SERIAL tests run alone. Every test keeps its own timeout, an error inside a worker fails that test only.
… one program per lane, and stops a timed-out test's children

A RUN_SERIAL test with DEPENDS or fixtures ran before its setup; now the ordered lane runs alone when it holds one.
A program with one ordered test and one plain test could overlap itself; all its tests now share the ordered lane.
A timeout killed only the direct child, so a relaunched gta6rt kept running beside other lanes; each test now runs in
its own process group (Windows: its own tree, taskkill /T) and the whole group is stopped.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran tests/test_run_wine_tests.py at e67782688 on Windows 11, five times: the new --jobs tests are red every run (1–2 failures, occasionally an extra error; 6 skipped each time):

FAIL test_different_programs_overlap_and_the_same_program_does_not
     AssertionError: Lists differ: ['start', 'end'] != ['start', 'end', 'start', 'end']
FAIL test_tests_of_one_program_do_not_overlap_when_only_one_has_an_ordering
     AssertionError: Lists differ: ['start', 'start', 'end'] != ['start', 'end', 'start', 'end']
ERROR test_a_test_that_hangs_costs_its_own_timeout_and_no_other_test

Runs: failures=2, failures=2, failures=1, failures=1, failures=2, errors=1. The marker log shows either only one of the two same-program entries ever ran, or its end is missing, and the hang/timeout case raises on Windows. The rest of the suite (74 tests total) passes.

Since the repository's tests also run on Windows and this PR adds the --jobs scheduler, this needs a Windows-correct implementation or a Windows skip for the three timing cases, with the failure reproduced. It also declares a dependency on #4462, which is still open. git diff --check clean. Not mergeable in this state.

…-wine

# Conflicts:
#	scripts/run_wine_tests.py
…n file

On Windows, appends from processes running side by side to one shared markers.log can lose or split lines
(the C runtime emulates append with a seek before each write), so the overlap tests saw a missing start or end
and the hang test could read a broken line (Kam471 on ItsNotRexed#4691). Each mark is now a new file; a mark cut short by a
kill records nothing.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @Kam471, that is a real bug in the new tests, not in the scheduler: every marker program appended its start/end lines to one shared markers.log with open(..., 'a'), and on Windows the C runtime emulates append with a seek before each write, so two processes running side by side can overwrite each other's line (and the handle was only flushed at interpreter exit). That gives exactly what you saw: a missing start or end for one of the same-program tests, and in the hang case a broken line the parser raised on. On Linux O_APPEND makes those small writes atomic, which is why the pod never showed it.

Fixed in a17a89f1: each mark is now its own new file (open(<uuid>, 'x'), closed right away), and a mark cut short by a kill is ignored. The scheduler code is unchanged by this commit. On Linux: 76 tests OK in 5 runs in a row.

Since the last head the branch also carries the current #4462 (rebased on main after the big merge) and keeps main's new fixture order when tests run side by side (tests/test_run_wine_test_fixtures.py has a --jobs 4 case).

Could you rerun python -I tests/test_run_wine_tests.py on Windows at a17a89f1? If test_a_test_that_hangs_costs_its_own_timeout_and_no_other_test still errors, the traceback would tell me whether it is the Windows tree kill (taskkill /T /F) rather than the marker race.

@kapitche

Copy link
Copy Markdown
Contributor

Tested a17a89f (already contains main 98fa503) on Linux (Python 3.12.16): pass - tests/test_run_wine_tests.py 76 tests OK, tests/test_run_wine_test_fixtures.py 5 tests OK; negative control: restored upstream/main's scripts/run_wine_tests.py, docs/testing.md and runtime.yml with the PR's tests kept, 4 failures + 31 errors in the first file and 7 errors in the second; restored. Wine itself was not run, so the --jobs timing (802 s -> 129 s) is not checked here.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Correction to my estimate: #4657 (merged before I opened this) moved the Wine jobs to main pushes and workflow_dispatch only. With 41 runtime.yml runs on main in the last 24 h, this saves ~115 runner-minutes a day, not ~5,700. It still turns the post-merge Wine result on main from ~13 minutes into ~2, and makes local Wine runs 6x faster. I updated the description; if that is not worth a review now, I am fine with closing it.

@memorypressure

Copy link
Copy Markdown

Verified: the per-mark-file approach is the right fix for the append race — open(..., "x") with uuid names and a reader tolerating kill-truncated files removes the shared-append dependency; all 76 tests pass under python -I and pytest (the Windows behaviour itself is unreproducible on Linux by construction). One mechanical blocker: the markers machinery these tests exercise exists only in the 900+ commit stack under this PR, not on main, so the whole --jobs section including this fix needs to land by rebase, not as-is. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks @memorypressure. On the blocker: this PR is 9 commits on top of main (98fa503f is an ancestor of the head), 7 without merges: the 4 of #4462 it depends on (d989f9eb, a39e559c, 7ae183f9, 39e6e98d) and 3 of its own (35f44fb9, e6778268, a17a89f1). The marker helpers are not from another stack: 35f44fb9 in this PR adds them together with --jobs and the tests that use them, so they land with it. Once #4462 merges, the PR shrinks to its own 3 commits; until then it carries #4462's 4, as its first line says. git rev-list --count origin/main..HEAD on the head gives 9.

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.

4 participants