fix(tests): stage linked .prx runtime files next to test executables on Windows #7645
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7645"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T19:21:09Z.
What
add_test_executablegains a POST_BUILD step that copies$<TARGET_RUNTIME_DLLS>next to the test exe on Windows. The step is gated onCMAKE_VERSION >= 3.21(the generator expression's floor) so the declaredcmake_minimum_required(VERSION 3.20)keeps configuring; on <3.21 the step is absent and the existing per-testENVIRONMENT_MODIFICATIONPATH prepends apply unchanged (note the prepend property itself is a 3.22 feature that ctest silently ignores on 3.20-3.21, so this widens rather than narrows the working range; the loader trap below 3.22 predates this PR). The executable directory outranks PATH in the DLL search order, so a test whose registration forgot theENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>"boilerplate still resolveslibc.prx/libkernel.prx/libSceAgcDriver.prxat load - instead of spawning a modal "entry point not found" (0xC0000139) dialog that blocks until ctest reports a timeout.The prepend is manual per-test boilerplate repeated across ~95 CMakeLists files; new registrations keep missing it (live instance fixed in #7627's
agc_driver_depth_bounds_state). With staging, no registration needs it, future omissions stop mattering, and hand-running a test exe works with no environment setup. ExistingENVIRONMENT_MODIFICATIONlines stay harmless for every exe that does not opt out.Twenty-one test executables opt out with the new
NO_RUNTIME_DLL_STAGINGargument, in two classes. Class one (guest_dinkumware_fetch_tests,guest_freetype_outline_border_tests,guest_freetype_pfr_tests,guest_freetype_module_properties_tests,guest_freetype_postscript_info_tests,guest_freetype_memory_record_tests,guest_freetype_stream_tests,guest_jxr_lookup_tests,guest_libressl_protocol_tests,guest_floating_prefix_tests,guest_libressl_cmac_patched_tests,guest_libressl_bio_patched_tests) loads patched-vs-unpatched library variants selected by a${PATCHED_DIR}/UNPATCHED_DIRPATH prepend and by explicit library paths, and asserts the loaded module's on-disk path (std::filesystem::equivalenton the module handle,startup == library). Any fixed copy staged next to the exe would shadow exactly one of the two variants - an unpatched stage breaks the patched variants' asserts and keeps the patched library's NID-shaped imports from resolving against the already-loaded unpatched siblings.Class two (
guest_update_env_tests,guest_raise_except_tests,guest_floating_point_tests,guest_gets_tests,guest_index_tests,guest_fwide_tests,guest_set_env_tests,guest_timed_join_tests,guest_termios_speed_tests) both links the.prximport library and receives the same module as a$<TARGET_FILE:...>argv path. With staging, the exe's import table bindstests\libc.prx/libkernel.prxat startup whileLoadLibraryA(unpatched/...)maps a second copy of the same module at a different base - the loader dedups full-path loads by path, not by basename, so the process ends up with two module instances and split per-module state (errno, stdio FILE tables, registered unwind info).guest_getsfailed on the stdio split (gets: byte read pointer- the GetProcAddress'dgetsran in the second instance's stdio state), and the fenv tests failed because the second instance's_Unwind_RaiseExceptionnever registered the host exe's.ehfram, so astd::invalid_argumentthrown across the prx boundary unwound off the top instead of reaching the exe'scatch. Opting out restores the single-instance layout their PATH prepends already provided. Every other exe keeps the staging.Tested
Windows 11, MinGW (WinLibs GCC 15.2.0), Release, RTX 3070 (driver 617.42).
0f5d53553d, before the opt-out):ctest -R guest_dinkumware_fetch18/18 failed (startup == library/equivalentasserts - the stagedtests\libc.prxis neitherunpatched/libc.prxnorlibs/libc.prx);guest_freetype_outline_border8/8 failed including the raw variants;guest_freetype_pfr_*_patched3/3 failed;guest_freetype_module_properties_nidfastfailed (0xc0000409);guest_jxr_lookup_*_patched3/3 failed atLoadLibraryA- the patched module's NID imports cannot resolve against the staged unpatchedlibc.prx/libkernel.prx.a3ea1b93b7, cleantests/dir - all staged.prxremoved first):guest_dinkumware_fetch_*18/18,guest_freetype_outline_border_*8/8,guest_freetype_pfr_*6/6,guest_freetype_module_properties*2/2,guest_jxr_lookup_*6/6,guest_libressl_protocol*2/2 - 42/42 pass. These tests assert the loaded module's path themselves (equivalent,GetModuleHandleW("libc.prx")vsrequested/libc.prx,startup == library), so a pass is direct proof the patched libraries are the ones loaded.guest_posix_scalar_io_testsre-stagedlibc.prx+libkernel.prxand passed withPATHscrubbed toC:\Windows\System32;C:\Windows.$<TARGET_RUNTIME_DLLS>form fails generation (Expression did not evaluate to a known generator expression); the gated form configures, generates and builds clean.ebecf4e71677(CI run 41276557688windowsjob: 6 fail-fast aborts) and locally:guest_update_env/guest_raise_except/guest_floating_pointabort on the gueststd::invalid_argumentthat the exe must catch (unhandled exception 'St16invalid_argument'-> terminate -> 0xc0000409);guest_getsaborts ongets: byte read pointer;guest_timed_join_normal/_coarseabort the same way. A probe exe linking thelibcimplib thenLoadLibraryA(unpatched/libc.prx)reports two distinct module bases (tests\libc.prx+unpatched\libc.prx) - the dual-instance mechanism, confirmed directly.ctest -R guest_update_env|guest_raise_except|guest_floating_point$|guest_gets$|guest_timed_join|guest_index$|guest_set_env|guest_termios_speed- 42/42 pass on Windows 11 (excludes the three latent exes' own unchanged assertions which now also run single-instance);guest_timed_join_import_libkernel_sys/_webpass fromtests/nostage/(the per-test$<TARGET_FILE_DIR:...>copies/PATH prepends follow the exe automatically).python3 tools/check_conventions.py --base origin/main: clean;git diff --check: clean.Parallel copies: every staging POST_BUILD copies from the same
unpatched/source file into the sharedtests/dir, so concurrent copies write identical bytes.cmake -E copy_if_differentcompares first and is a no-op once the destination matches; when two builders race on a first write the destination file is opened non-shared, so the loser gets a sharing violation and the POST_BUILD fails loudly at build time - a transient retryable error, never a torn DLL, and nothing maps the file during the build (tests only run under ctest afterwards).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:22:49Z.
I rechecked the submitted diff against the cross-target reproduction from #7637. The PR currently still uses
cmake -E copy -t "$<TARGET_FILE_DIR:${target}>" $<TARGET_RUNTIME_DLLS:${target}>. WithCOMMAND_EXPAND_LISTS, CMake 3.25.1 expands this tocopy -t <exe-dir> file1.prx file2.prx file3.prx, which fails:Target (for copy command) ".../file3.prx" is not a directory. I reproduced it with one and three MinGW Windows runtime targets. The tested working form iscmake -E copy_if_different $<TARGET_RUNTIME_DLLS:${target}> "$<TARGET_FILE_DIR:${target}>/"(also withCOMMAND_EXPAND_LISTS); it generated the expected copy command and staged all three files next to the exe in the cross-target fixture. Please update the post-build command; the current Windows run in the PR description may have used a different command than the submitted one.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:23:01Z.
One more edge case from the same cross-target: a test target with no linked runtime DLLs also fails in the submitted form.
TARGET_RUNTIME_DLLSexpands empty, leavingcmake -E copy -t <exe-dir>; CMake 3.25.1 exits withError copying file "-t" to ".../build-win". Please guard the post-build command when the list is empty, or use a helper that conditionally stages only nonempty lists. Thecopy_if_differentcorrection above handles the multi-file case when the list is nonempty; it also needs the empty-list guard.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:25:32Z.
I tested the updated
copy_if_differentform from the current headd2fbfd9in the same MinGW Windows cross-target fixture. With three linked.prxtargets, the generated command now copies all three alongside the executable and succeeds. A no-runtime-DLL test also builds successfully; including$<TARGET_FILE:${target}>keeps the command nonempty, and CMake handles copying that file to its existing output directory. This closes both failures I reported in the submitted command. The hostedwindowsapp-build lane is still skipped, so this is focused cross-target validation, not a full project Windows build.Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T19:27:07Z.
Thanks for the fast re-verification on the 3.25.1 cross-target - good that the
copy_if_differentform plus the$<TARGET_FILE>guard closes both the multi-file and empty-list cases. Confirmed locally on cmake 4.4.4 as well: full graphics suite passes with PATH scrubbed, 14/14 on the ctest sweep includingnid_buffer_validation(the no-DLL case). Current headd2fbfd925carries exactly the command you validated.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:51:20Z.
Review: COMMENTED
One compatibility issue to resolve before merging: the root
CMakeLists.txtdeclarescmake_minimum_required(VERSION 3.20), but$<TARGET_RUNTIME_DLLS:...>was added in CMake 3.21 (CMake 3.21 release notes). On Windows with CMake 3.20 this generator expression is evaluated during generation and is unknown, so the newly addedif(WIN32)command can make configuration fail for a version the project currently claims to support. Could you either preserve 3.20 compatibility (for example, gate an alternate staging path by CMake version) or raise the project minimum to 3.21 and update the documented/tooling requirement? The current CMake 4.4.4 validation does not cover the declared minimum.Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T19:56:15Z.
Overlap bot report checked: all 13 shared-file PRs touch
CMakeLists.txtregions unrelated toadd_test_executable(lines 11-25). Closest: #7642 editsrequest_serializer_testsincludes at ~line 92, #7039 adjusts aTIMEOUTat ~line 173, #3998 callsadd_test_executablefor a new test (benefits from the staging automatically). No real overlap.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:09:13Z.
Review: COMMENTED
Thanks for checking the real CMake 3.20.5 behavior; the version gate correctly avoids the unknown-generator-expression failure. One remaining scope point: on 3.20 the staging command is disabled, so a test registration without the manual PATH prepend can still hit the same loader dialog, and direct-running the exe still lacks the new guarantee. Could you either add a 3.20-compatible staging fallback, or state that this general protection applies only with CMake >=3.21 (and retain the per-test PATH setup as required below that)? The current reported CMake 3.20 validation proves configuration/build, not the no-PATH runtime behavior.
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T20:09:15Z.
Good catch — fixed in
ee69ac6d0by gating the staging step on the generator expression's floor:Chose the gate over bumping the minimum so this fix stays scoped. On <3.21 the command is never created, so the unknown genex can't fail generation — and the per-test
ENVIRONMENT_MODIFICATIONPATH prepends still apply, so behavior there is exactly today's.Verified against a real CMake 3.20.5 binary (PyPI wheel) with a minimal fixture replicating the pattern:
$<TARGET_RUNTIME_DLLS:...>—Expression did not evaluate to a known generator expression(reproduces the failure you predicted on the declared floor).agc_driver_graphics_tests, all three.prxfiles staged intotests/, and the suite still passes withPATHscrubbed to System32.Side note for context, not pushback: the repo already relies on
ENVIRONMENT_MODIFICATION(3.22) in ~92 registrations, so the de-facto floor for working tests is higher than 3.20 — but those fail silently at runtime rather than breaking generation, so the gate is still the right call here.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:14:45Z.
Review: APPROVED
The current head addresses the CMake 3.20 generator-expression failure by gating the staging command at 3.21, and the updated body clearly records that the existing per-test PATH setup remains in effect below that version. The reported MinGW staging checks cover linked and no-runtime-DLL targets, and the current conventions, relinker platform, and ASan checks pass. I approve this focused test-infrastructure change.
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-18T20:15:26Z.
Fair point — taken the second option and scoped the claim in the PR body: staging applies on
CMAKE_VERSION >= 3.21; below that, behavior is byte-for-byte today's.One nuance worth noting on the fallback side:
ENVIRONMENT_MODIFICATIONis itself a CMake 3.22 feature, so on 3.20–3.21 ctest accepts the per-testPATH=path_list_prepend:...lines but silently ignores them — meaning.prx-importing tests already hit this loader trap on those versions today, prepend or no prepend. The gate therefore can't regress anything: 3.20 keeps exactly its current (already-broken-for-ctest) behavior, while 3.21 actually gains protection the prepend could never deliver there.A true 3.20 fallback would need
copy_directoryof the whole unpatched dir per exe — a second code path staging ~all prx rather than the linked set — to benefit a toolchain where ctest can't honor the existing registrations anyway. Happy to add it if you'd rather have that, but the scoped claim seemed the honest fit given the prepend is a no-op below 3.22 regardless.Imported from boykopovar/AnyPS5. Originally posted by Neithennn on 2026-10-19T10:35:28Z.
Full-suite Windows run, to cover every test executable now that each one gets the staging step (the description lists a 14-test sweep).
Windows 11 Pro 26200, NVIDIA GeForce RTX 4080 (driver 617.42), WinLibs GCC 15.2.0 r7, CMake from WinLibs, Ninja, Release, bundled dependencies,
BUILD_TESTING=ON,ANYPS5_NO_SHADER_CACHE=1. Headee69ac6d0merged onto main36f60df9e; the full build succeeds and stages 108.prxfiles inbuild/tests/.ctest -j 8 --timeout 120: 1629/1631. The two failures areshader_cache_runtime_sourcesandhardware_oracle_compare, both hitting my 120 s limit under parallel load; alone on this tree they pass 3/3 each (55 to 58 s and 11 s). On unchanged main the same run gave 1631/1631, withshader_cache_runtime_sourcesat 79 s, so that one is close to the limit either way.ANYPS5_REQUIRE_VULKAN=1:agc_driver_graphics,agc_write_tracking,agc_import_watch,agc_import_watch_other_family,guest_kernel_sys,nid_buffer_validation: pass.I did not repeat the scrubbed-
PATHdirect run.AI-assisted: yes (runs done with Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T04:04:55Z.
Review: APPROVED
Reviewed
ee69ac6d0e6f1fb9a08c9a6d9790b12d35da6985against8d17389a73852ee0e462c640589b47d49c68e8d6. No actionable findings in this focused review.Source review: Inspected the complete helper change and its existing runtime output/wrapped-main setup. Windows CMake 3.21+ stages linked runtime dependencies beside the test. COMMAND_EXPAND_LISTS preserves the DLL list, VERBATIM handles paths, and including the executable itself keeps copy_if_different valid when the dependency list is empty. Older CMake and non-Windows behavior are unchanged.
Validation: Windows, CMake 4.3.1 / MinGW GCC 15.2: a disposable project using the exact head helper and WindowsTestExit source built a shared .prx plus linked and standalone tests in directories containing spaces. Both head executables ran with exit 0; the linked .prx was staged. The same baseline fixture built but did not stage that file. Conventions and whitespace passed. This older script-registration CLI rejects --scripts; no registration pass is claimed. Effective hosted relinker matrix and ASan succeeded; full-product jobs were skipped.
Scope: Actual bounded CMake/build/runtime fixture; full AnyPS5 libraries and all test targets were not rebuilt locally.