fix(tests): end Windows test processes through libc before DLL detach #6986

Merged
oneandonlydean merged 1 commit from upstream-pr/6986 into main 2026-10-17 02:15:48 +00:00
oneandonlydean commented 2026-10-17 01:48:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T01:48:54Z.


Windows CI times out single tests at 120 s after they have already finished (#6791). It's not specific to any test: agc_driver_pm4_ring_invalid, agc_interpolant_mapping, guest_shader_link and others hit it, and a re-run moves it to another test.

The cause is the exit path. A test returning from main ends through exit -> ExitProcess, which kills every other thread and only then runs the prx DLLs' static destructors at DLL_PROCESS_DETACH. Detached host threads are still alive at that point (the driver's async log thread, AsyncLog.hpp:196; libkernel's file-watch and alarm threads), and they die holding locks. A destructor that then flushes the async log, locks one of those mutexes or destroys a condition variable (winpthreads' pthread_cond_destroy waits without a timeout) never returns. Linux doesn't see it, because exit runs destructors while the threads are still alive. That's also why tests that already call LibcRunShutdown before returning (the approach in #6925) still hang: the detached threads outlive it, and DLL detach still runs after they're gone.

This wraps main for every test executable on MinGW (LINKER:--wrap=main in add_test_executable, cmake/WindowsTestExit.cpp). After main returns, the wrapper runs the executable's own exit handlers and static destructors (_cexit), flushes the streams and ends the process with LibcTerminate_nid_no_patch (the path guest exit already uses: end-flush, then TerminateProcess). The driver log is flushed while its thread is alive, and no DLL_PROCESS_DETACH work runs after the threads are gone. The libc shutdown callbacks are not run, matching a plain return from main on Linux. A test that doesn't load libc.prx returns as before. Linux and macOS are unchanged.

It replaces the per-test approach in #6925, which becomes redundant but harmless.

Validation: I don't have a Windows machine, so this PR's Windows CI is also its first compile. I'll repeat the full Windows run several times and compare the timeout count with main (about 5 timeouts in 11 runs on 10-16).

Refs #6791, #6925.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4896312433 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6986). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T01:48:54Z. --- Windows CI times out single tests at 120 s after they have already finished (#6791). It's not specific to any test: `agc_driver_pm4_ring_invalid`, `agc_interpolant_mapping`, `guest_shader_link` and others hit it, and a re-run moves it to another test. The cause is the exit path. A test returning from `main` ends through `exit` -> `ExitProcess`, which kills every other thread and only then runs the prx DLLs' static destructors at `DLL_PROCESS_DETACH`. Detached host threads are still alive at that point (the driver's async log thread, `AsyncLog.hpp:196`; libkernel's file-watch and alarm threads), and they die holding locks. A destructor that then flushes the async log, locks one of those mutexes or destroys a condition variable (winpthreads' `pthread_cond_destroy` waits without a timeout) never returns. Linux doesn't see it, because `exit` runs destructors while the threads are still alive. That's also why tests that already call `LibcRunShutdown` before returning (the approach in #6925) still hang: the detached threads outlive it, and DLL detach still runs after they're gone. This wraps `main` for every test executable on MinGW (`LINKER:--wrap=main` in `add_test_executable`, `cmake/WindowsTestExit.cpp`). After `main` returns, the wrapper runs the executable's own exit handlers and static destructors (`_cexit`), flushes the streams and ends the process with `LibcTerminate_nid_no_patch` (the path guest exit already uses: end-flush, then `TerminateProcess`). The driver log is flushed while its thread is alive, and no `DLL_PROCESS_DETACH` work runs after the threads are gone. The libc shutdown callbacks are not run, matching a plain return from `main` on Linux. A test that doesn't load `libc.prx` returns as before. Linux and macOS are unchanged. It replaces the per-test approach in #6925, which becomes redundant but harmless. Validation: I don't have a Windows machine, so this PR's Windows CI is also its first compile. I'll repeat the full Windows run several times and compare the timeout count with main (about 5 timeouts in 11 runs on 10-16). Refs #6791, #6925.
MarcZX10 commented 2026-10-17 01:59:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T01:59:32Z.


The current conventions check fails because the PR body is missing the template sections What, Tested and Checklist. Please restore those headings and fill them in; the check reports all three as empty.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228234287 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6986#issuecomment-6228234287). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T01:59:32Z. --- The current conventions check fails because the PR body is missing the template sections `What`, `Tested` and `Checklist`. Please restore those headings and fill them in; the check reports all three as empty.
github-actions[bot] commented 2026-10-17 02:11:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T02:11:42Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 674 CMakeLists.txt
PR 1835 CMakeLists.txt
PR 5021 CMakeLists.txt
PR 6044 CMakeLists.txt
PR 6879 CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228351282 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6986#issuecomment-6228351282). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T02:11:42Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 674](https://www.github.com/boykopovar/AnyPS5/pull/674) | `CMakeLists.txt` | | [PR 1835](https://www.github.com/boykopovar/AnyPS5/pull/1835) | `CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `CMakeLists.txt` |
johnmaia commented 2026-10-17 02:23:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-17T02:23:34Z.


Windows run: i7-13700K, RTX 4080 (617.42) and Intel UHD 770 (101.6129), WinLibs GCC 15.2.0, Release. Tested #6986 (ea33174d7) merged onto main f643e61d9.

guest_shader_link alone on the UHD 770, 15 runs, 60 s timeout

passed timed out
main 0c4e47016 (earlier run, same machine) 11 4
this PR 15 0

Full ctest -j4 --timeout 300, 1351 tests: no timeouts on either GPU. Without this PR, guest_shader_link timed out on the UHD in our full runs.

Failures that remain, all failing on plain main f643e61d9 too (checked by rerunning them there), so none come from this PR:

  • both GPUs: agc_driver_gpu_map_on_fiber ("started 1 host threads for its import instead of importing on the fiber's host stack"), guest_kqueue (0xc0000409)
  • UHD only: agc_driver_bindless_images, agc_driver_image_sint8, agc_driver_image_table, agc_driver_image_table_cache_bounds / _reuse (0xc0000409), agc_driver_sample_multisample_target ("sample 1 of pixel (0, 0) does not hold the stored color")

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228457472 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6986#issuecomment-6228457472). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-17T02:23:34Z. --- Windows run: i7-13700K, RTX 4080 (617.42) and Intel UHD 770 (101.6129), WinLibs GCC 15.2.0, Release. Tested #6986 (ea33174d7) merged onto main f643e61d9. **guest_shader_link alone on the UHD 770, 15 runs, 60 s timeout** | | passed | timed out | |---|---|---| | main 0c4e47016 (earlier run, same machine) | 11 | 4 | | this PR | **15** | **0** | **Full `ctest -j4 --timeout 300`, 1351 tests:** no timeouts on either GPU. Without this PR, guest_shader_link timed out on the UHD in our full runs. Failures that remain, all failing on plain main f643e61d9 too (checked by rerunning them there), so none come from this PR: - both GPUs: `agc_driver_gpu_map_on_fiber` ("started 1 host threads for its import instead of importing on the fiber's host stack"), `guest_kqueue` (0xc0000409) - UHD only: `agc_driver_bindless_images`, `agc_driver_image_sint8`, `agc_driver_image_table`, `agc_driver_image_table_cache_bounds` / `_reuse` (0xc0000409), `agc_driver_sample_multisample_target` ("sample 1 of pixel (0, 0) does not hold the stored color") AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-17 03:14:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T03:14:37Z.


Thanks @johnmaia, that's very useful. The fiber import and guest_kqueue failures are being looked at against #6993 and #6599/#6173. For the UHD-only 0xc0000409 group (agc_driver_bindless_images, agc_driver_image_sint8, agc_driver_image_table, agc_driver_image_table_cache_bounds / _reuse), I couldn't find an existing issue. Could you open one with the ctest --output-on-failure output for one of them on the UHD 770, plus the driver version and main commit? A debugger backtrace for the 0xc0000409 would help most, if you can get one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6228922275 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6986#issuecomment-6228922275). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T03:14:37Z. --- Thanks @johnmaia, that's very useful. The fiber import and `guest_kqueue` failures are being looked at against #6993 and #6599/#6173. For the UHD-only 0xc0000409 group (`agc_driver_bindless_images`, `agc_driver_image_sint8`, `agc_driver_image_table`, `agc_driver_image_table_cache_bounds` / `_reuse`), I couldn't find an existing issue. Could you open one with the `ctest --output-on-failure` output for one of them on the UHD 770, plus the driver version and main commit? A debugger backtrace for the 0xc0000409 would help most, if you can get one.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!6986
No description provided.