test(libs): load every patched library with its imports bound

ctest loads the libraries from libs/unpatched, so an import that nid_patcher
renames out of another library's exports only shows when a title loads the
patched prx. patched_libraries loads each patched .prx with LoadLibraryEx on
Windows and dlopen(RTLD_NOW) on Linux, and depends on the libs target so the
patched files are current.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LeandroLP23
2026-10-08 22:22:01 +02:00
parent f145139676
commit 06f78c2030
2 changed files with 43 additions and 0 deletions
+7
View File
@@ -131,6 +131,13 @@ endforeach()
add_custom_target(libs DEPENDS ${PATCHED_OUTPUTS})
if(BUILD_TESTING)
add_test_executable(patched_libraries_tests tests/PatchedLibraries.cpp)
add_dependencies(patched_libraries_tests libs)
if(MINGW)
target_compile_options(patched_libraries_tests PRIVATE -fasynchronous-unwind-tables)
target_link_options(patched_libraries_tests PRIVATE -static -static-libgcc -static-libstdc++)
endif()
add_test(NAME patched_libraries COMMAND patched_libraries_tests ${PATCHED_DIR})
add_test_executable(guest_offline_imports_tests tests/GuestOfflineImports.cpp)
target_include_directories(guest_offline_imports_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(guest_offline_imports_tests PRIVATE libSceHttp libSceNpEntitlementAccess libSceRudp libc)
+36
View File
@@ -0,0 +1,36 @@
#include <cstdio>
#include <filesystem>
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
int main(int argc, char** argv) {
if (argc != 2) {
std::fprintf(stderr, "usage: %s <patched libraries directory>\n", argv[0]);
return 2;
}
int loaded = 0;
int failed = 0;
for (const auto& entry : std::filesystem::directory_iterator(argv[1])) {
if (entry.path().extension() != ".prx") continue;
#ifdef _WIN32
if (LoadLibraryExW(entry.path().c_str(), nullptr, LOAD_WITH_ALTERED_SEARCH_PATH) != nullptr) {
++loaded;
continue;
}
std::fprintf(stderr, "%s: LoadLibraryEx failed with error %lu\n", entry.path().filename().string().c_str(), GetLastError());
#else
if (dlopen(entry.path().c_str(), RTLD_NOW | RTLD_LOCAL) != nullptr) {
++loaded;
continue;
}
std::fprintf(stderr, "%s\n", dlerror());
#endif
++failed;
}
std::printf("%d patched libraries loaded, %d failed\n", loaded, failed);
return loaded > 0 && failed == 0 ? 0 : 1;
}