Windows: tests whose exe imports a .prx hang under ctest when the registration lacks the unpatched-dir PATH prepend #7637

Closed
opened 2026-10-18 18:53:04 +00:00 by akkadbakkad89 · 6 comments
akkadbakkad89 commented 2026-10-18 18:53:04 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T18:53:04Z.


Symptom

On Windows, a test whose executable imports libc.prx/libSceAgcDriver.prx (i.e. links a prx target) but whose add_test registration lacks

if(WIN32)
    set_tests_properties(<test> PROPERTIES ENVIRONMENT_MODIFICATION
        "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()

never reaches main(). The loader resolves lib*.prx imports to the patched copy in libs/ (or fails to find one at all), shows "The procedure entry point ... could not be located" (0xC0000139), and the process blocks on the modal dialog until ctest reports Timeout — a dialog, not a readable failure.

Repro

Live instance in open PR #7627: agc_driver_depth_bounds_state is registered without the WIN32 ENVIRONMENT_MODIFICATION its sibling registrations get. Under ctest -R agc_driver_depth_bounds_state on Windows it exhausts the timeout on both NVIDIA RTX 3070 and Intel UHD 630; run by hand with libs\unpatched on PATH it passes in ~1 s (Depth bounds state checks passed).

The same mechanism makes any direct run of these exes fail with 0xC0000139 for a developer who does not know to prepend the unpatched dir first.

Why it keeps happening

The prepend is manual per-test boilerplate repeated ~570 times across ~95 CMakeLists.txt files; every new registration must remember it, and nothing checks that it did. Linux/macOS never need it (rpath), so authors on those platforms cannot see the breakage.

Proposed fix

Stage each test executable's linked .prx runtime artifacts next to the exe (the executable's own directory outranks PATH in the Windows DLL search order) via $<TARGET_RUNTIME_DLLS:...> in add_test_executable — no registration then needs the prepend, future omissions stop mattering, and hand-running a test exe works with no environment setup. Existing ENVIRONMENT_MODIFICATION lines stay harmless.

I intend to implement this. Filing first for visibility in case the approach is wrong.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5912952739 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7637). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-18T18:53:04Z. --- ## Symptom On Windows, a test whose executable imports `libc.prx`/`libSceAgcDriver.prx` (i.e. links a prx target) but whose `add_test` registration lacks ``` if(WIN32) set_tests_properties(<test> PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>") endif() ``` never reaches `main()`. The loader resolves `lib*.prx` imports to the **patched** copy in `libs/` (or fails to find one at all), shows "The procedure entry point ... could not be located" (`0xC0000139`), and the process blocks on the modal dialog until ctest reports **Timeout** — a dialog, not a readable failure. ## Repro Live instance in open PR #7627: `agc_driver_depth_bounds_state` is registered without the WIN32 `ENVIRONMENT_MODIFICATION` its sibling registrations get. Under `ctest -R agc_driver_depth_bounds_state` on Windows it exhausts the timeout on both NVIDIA RTX 3070 and Intel UHD 630; run by hand with `libs\unpatched` on `PATH` it passes in ~1 s (`Depth bounds state checks passed`). The same mechanism makes any *direct* run of these exes fail with `0xC0000139` for a developer who does not know to prepend the unpatched dir first. ## Why it keeps happening The prepend is manual per-test boilerplate repeated ~570 times across ~95 `CMakeLists.txt` files; every new registration must remember it, and nothing checks that it did. Linux/macOS never need it (rpath), so authors on those platforms cannot see the breakage. ## Proposed fix Stage each test executable's linked `.prx` runtime artifacts next to the exe (the executable's own directory outranks `PATH` in the Windows DLL search order) via `$<TARGET_RUNTIME_DLLS:...>` in `add_test_executable` — no registration then needs the prepend, future omissions stop mattering, and hand-running a test exe works with no environment setup. Existing `ENVIRONMENT_MODIFICATION` lines stay harmless. I intend to implement this. Filing first for visibility in case the approach is wrong.
MarcZX10 commented 2026-10-18 18:54:12 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:54:12Z.


I verified the reported omission in open PR #7627: agc_driver_graphics_tests links libc, but agc_driver_depth_bounds_state has no Windows PATH prepend while sibling cases do. I also checked the proposed TARGET_RUNTIME_DLLS direction against the root add_test_executable helper: test executables share ${CMAKE_BINARY_DIR}/tests, and the helper currently handles MinGW entry wrapping only. Please validate that staging runtime files there cannot collide across tests and that CMake includes the custom .prx targets before replacing the registration-level fix; I will not duplicate the implementation while you are preparing it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253796660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7637#issuecomment-6253796660). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T18:54:12Z. --- I verified the reported omission in open PR #7627: `agc_driver_graphics_tests` links `libc`, but `agc_driver_depth_bounds_state` has no Windows `PATH` prepend while sibling cases do. I also checked the proposed `TARGET_RUNTIME_DLLS` direction against the root `add_test_executable` helper: test executables share `${CMAKE_BINARY_DIR}/tests`, and the helper currently handles MinGW entry wrapping only. Please validate that staging runtime files there cannot collide across tests and that CMake includes the custom `.prx` targets before replacing the registration-level fix; I will not duplicate the implementation while you are preparing it.
MarcZX10 commented 2026-10-18 18:55:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:55:09Z.


Update: the concrete missing-PATH case is now fixed in #7627 at 33f65a7ebaf. I had overlooked the author’s follow-up when I raised the shared-directory staging concern; that concern does not apply to the focused registration fix. The broader automatic-staging proposal remains unimplemented, and I do not have evidence yet that the shared helper can safely stage every custom .prx dependency without collisions.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253806292 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7637#issuecomment-6253806292). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T18:55:09Z. --- Update: the concrete missing-PATH case is now fixed in #7627 at `33f65a7ebaf`. I had overlooked the author’s follow-up when I raised the shared-directory staging concern; that concern does not apply to the focused registration fix. The broader automatic-staging proposal remains unimplemented, and I do not have evidence yet that the shared helper can safely stage every custom `.prx` dependency without collisions.
akkadbakkad89 commented 2026-10-18 19:03:12 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T19:03:12Z.


Both questions checked on a working branch (fix/test-prx-dll-staging, add_test_executable gained a POST_BUILD cmake -E copy -t $<TARGET_FILE_DIR:t> $<TARGET_RUNTIME_DLLS:t>):

  • Custom .prx targets are covered: agc_driver_graphics_tests links libc/libkernel/libSceAgcDriver and the generated build line copies exactly those three unpatched/*.prx files into tests/. Confirmed on disk: tests/libSceAgcDriver.prx, tests/libkernel.prx, tests/libc.prx. Exes with no shared-library deps (nid_buffer_validation_tests) build clean - empty $<TARGET_RUNTIME_DLLS> is a no-op.
  • No collision in the shared tests/ dir: every prx target emits the same libs/unpatched output set, so all exes stage identical bytes; copy -t overwrite is idempotent. Single-config Ninja tree, one variant per build. Where it can still bite: a stale exe kept across a head switch loads a stale staged copy - but that hazard already exists today via the prepend (PATH points at unpatched/, which is equally stale in that scenario), so the change is risk-neutral there.

End-to-end proof: agc_driver_graphics_tests.exe run directly with PATH=C:\Windows\System32;C:\Windows (no unpatched dir anywhere) passes the whole graphics suite - the loader resolves the .prx imports from the exe's own directory. And a ctest sweep (agc_write_tracking, agc_buffer_pool, recorder import/storage modes, guest_kernel_sys, guest_cpu_time_clocks, nid_buffer_validation, host-import cases): 14/14 pass, 1 skip by design. RTX 3070, driver 617.42, Windows 11, MinGW GCC 15.2.0, Release.

Existing ENVIRONMENT_MODIFICATION prepends stay in place; this removes the trap for the next registration that forgets them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253887431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7637#issuecomment-6253887431). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-18T19:03:12Z. --- Both questions checked on a working branch (`fix/test-prx-dll-staging`, `add_test_executable` gained a POST_BUILD `cmake -E copy -t $<TARGET_FILE_DIR:t> $<TARGET_RUNTIME_DLLS:t>`): - **Custom `.prx` targets are covered**: `agc_driver_graphics_tests` links `libc`/`libkernel`/`libSceAgcDriver` and the generated build line copies exactly those three `unpatched/*.prx` files into `tests/`. Confirmed on disk: `tests/libSceAgcDriver.prx`, `tests/libkernel.prx`, `tests/libc.prx`. Exes with no shared-library deps (`nid_buffer_validation_tests`) build clean - empty `$<TARGET_RUNTIME_DLLS>` is a no-op. - **No collision in the shared `tests/` dir**: every prx target emits the *same* `libs/unpatched` output set, so all exes stage identical bytes; `copy -t` overwrite is idempotent. Single-config Ninja tree, one variant per build. Where it can still bite: a stale exe kept across a head switch loads a stale staged copy - but that hazard already exists today via the prepend (PATH points at `unpatched/`, which is equally stale in that scenario), so the change is risk-neutral there. End-to-end proof: `agc_driver_graphics_tests.exe` run directly with `PATH=C:\Windows\System32;C:\Windows` (no unpatched dir anywhere) passes the whole graphics suite - the loader resolves the `.prx` imports from the exe's own directory. And a ctest sweep (`agc_write_tracking`, `agc_buffer_pool`, recorder import/storage modes, `guest_kernel_sys`, `guest_cpu_time_clocks`, `nid_buffer_validation`, host-import cases): 14/14 pass, 1 skip by design. RTX 3070, driver 617.42, Windows 11, MinGW GCC 15.2.0, Release. Existing `ENVIRONMENT_MODIFICATION` prepends stay in place; this removes the trap for the next registration that forgets them.
MarcZX10 commented 2026-10-18 19:21:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:21:26Z.


I tested the proposed POST_BUILD staging command with CMake 3.25.1 and a MinGW Windows cross-target. cmake -E copy -t "$<TARGET_FILE_DIR:t>" "$<TARGET_RUNTIME_DLLS:t>" fails for both one and three linked .prx targets: copy -t treats the final expanded runtime file as the target, then reports that it is not a directory. The staging direction still works when using cmake -E copy_if_different "$<TARGET_RUNTIME_DLLS:t>" "$<TARGET_FILE_DIR:t>/" with COMMAND_EXPAND_LISTS; I verified the generated command and copied all three artifacts beside the executable in the cross-target build. Since you have a working branch, could you update that command and submit the PR? I won’t open a competing PR while you’re actively preparing this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254090142 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7637#issuecomment-6254090142). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T19:21:26Z. --- I tested the proposed POST_BUILD staging command with CMake 3.25.1 and a MinGW Windows cross-target. `cmake -E copy -t "$<TARGET_FILE_DIR:t>" "$<TARGET_RUNTIME_DLLS:t>"` fails for both one and three linked `.prx` targets: `copy -t` treats the final expanded runtime file as the target, then reports that it is not a directory. The staging direction still works when using `cmake -E copy_if_different "$<TARGET_RUNTIME_DLLS:t>" "$<TARGET_FILE_DIR:t>/"` with `COMMAND_EXPAND_LISTS`; I verified the generated command and copied all three artifacts beside the executable in the cross-target build. Since you have a working branch, could you update that command and submit the PR? I won’t open a competing PR while you’re actively preparing this change.
akkadbakkad89 commented 2026-10-18 19:22:28 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T19:22:28Z.


Implementation is up: #7645 stages each test exe's linked .prx runtime files next to the executable in add_test_executable, so the loader resolves them from the exe directory instead of the PATH prepend.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254100654 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7637#issuecomment-6254100654). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-18T19:22:28Z. --- Implementation is up: #7645 stages each test exe's linked `.prx` runtime files next to the executable in `add_test_executable`, so the loader resolves them from the exe directory instead of the PATH prepend.
akkadbakkad89 commented 2026-10-18 19:25:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T19:25:04Z.


Good catch - cmake -E copy -t is indeed newer-than-3.25 syntax. Updated #7645 to your verified form plus one guard:

COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:${target}>
        "$<TARGET_FILE:${target}>" "$<TARGET_FILE_DIR:${target}>/"
COMMAND_EXPAND_LISTS

$<TARGET_FILE> is listed as a trailing source so a target with zero shared-library dependencies still gets a well-formed command (self-copy of an identical file is a no-op; an empty copy_if_different errors on old cmake). Re-verified on cmake 4.4.4: agc_driver_graphics_tests stages libc/libkernel/libSceAgcDriver.prx, nid_buffer_validation_tests builds clean, direct run with scrubbed PATH passes the full graphics suite, ctest sweep green. New head d2fbfd925.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254127364 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7637#issuecomment-6254127364). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-18T19:25:04Z. --- Good catch - `cmake -E copy -t` is indeed newer-than-3.25 syntax. Updated #7645 to your verified form plus one guard: ``` COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:${target}> "$<TARGET_FILE:${target}>" "$<TARGET_FILE_DIR:${target}>/" COMMAND_EXPAND_LISTS ``` `$<TARGET_FILE>` is listed as a trailing source so a target with zero shared-library dependencies still gets a well-formed command (self-copy of an identical file is a no-op; an empty `copy_if_different` errors on old cmake). Re-verified on cmake 4.4.4: `agc_driver_graphics_tests` stages libc/libkernel/libSceAgcDriver.prx, `nid_buffer_validation_tests` builds clean, direct run with scrubbed PATH passes the full graphics suite, ctest sweep green. New head `d2fbfd925`.
Sign in to join this conversation.
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#7637
No description provided.