Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/libs/prx/libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,18 @@ if(BUILD_TESTING)
endif()
endif()

add_test_executable(guest_libc_cnd_init_default_name_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLibcCndInitDefaultName.cpp)
target_include_directories(guest_libc_cnd_init_default_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_cnd_init_default_name_tests PRIVATE libc)
configure_windows_unwind(guest_libc_cnd_init_default_name_tests)
if(BUILD_TESTING)
set_target_properties(guest_libc_cnd_init_default_name_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
add_test(NAME guest_libc_cnd_init_default_name COMMAND guest_libc_cnd_init_default_name_tests)
if(WIN32)
set_tests_properties(guest_libc_cnd_init_default_name PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
endif()

add_test_executable(guest_libc_cnd_timed_wait_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLibcCndTimedWait.cpp)
target_include_directories(guest_libc_cnd_timed_wait_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_cnd_timed_wait_tests PRIVATE libc)
Expand Down
4 changes: 4 additions & 0 deletions core/libs/prx/libc/src/Threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ int APS5_VABI _Cnd_init_nid_postfix(void** handle) {
return threadSuccess;
}

int APS5_VABI _Cnd_init_with_default_name_override_nid_postfix(void** handle, const char*) {
return _Cnd_init_nid_postfix(handle);
}

void APS5_VABI _Cnd_destroy_nid_postfix(void** handle) {
if (!handle)
throw std::invalid_argument("_Cnd_destroy: null condition handle pointer");
Expand Down
42 changes: 42 additions & 0 deletions core/libs/tests/GuestLibcCndInitDefaultName.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstdlib>
#include <stdexcept>

extern "C" {
int APS5_VABI _Cnd_init_with_default_name_override_nid_postfix(void** handle, const char* name);
void APS5_VABI _Cnd_destroy_nid_postfix(void** handle);
int APS5_VABI _Cnd_signal_nid_postfix(void** handle);
}

static void Require(bool value) { if (!value) std::abort(); }

template<typename TException, typename TCall>
static void RequireThrows(TCall call) {
try {
call();
} catch (const TException&) {
return;
}
std::abort();
}

constexpr int success = 0;

int main() {
void* condition = nullptr;
Require(_Cnd_init_with_default_name_override_nid_postfix(&condition, "GameCond") == success);
Require(condition != nullptr);
Require(_Cnd_signal_nid_postfix(&condition) == success);
_Cnd_destroy_nid_postfix(&condition);
Require(condition == nullptr);

void* unnamed = nullptr;
Require(_Cnd_init_with_default_name_override_nid_postfix(&unnamed, nullptr) == success);
Require(unnamed != nullptr);
_Cnd_destroy_nid_postfix(&unnamed);

RequireThrows<std::invalid_argument>([] {
_Cnd_init_with_default_name_override_nid_postfix(nullptr, "NullHandle");
});
return 0;
}
Loading