project(tests C)
+add_library(uwrap_fake_socket_wrapper SHARED uwrap_fake_socket_wrapper.c)
+target_compile_options(uwrap_fake_socket_wrapper
+ PRIVATE
+ ${DEFAULT_C_COMPILE_FLAGS}
+ -D_GNU_SOURCE)
+target_include_directories(uwrap_fake_socket_wrapper
+ PRIVATE ${CMAKE_BINARY_DIR} ${CMOCKA_INCLUDE_DIR})
+set(UWRAP_FAKE_SOCKET_WRAPPER_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}uwrap_fake_socket_wrapper${CMAKE_SHARED_LIBRARY_SUFFIX}")
+
function(ADD_CMOCKA_TEST_ENVIRONMENT _TEST_NAME)
if (CMAKE_BUILD_TYPE)
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
if (ASAN_LIBRARY)
list(APPEND PRELOAD_LIBRARIES ${ASAN_LIBRARY})
endif()
+ list(APPEND PRELOAD_LIBRARIES ${UWRAP_FAKE_SOCKET_WRAPPER_LOCATION})
list(APPEND PRELOAD_LIBRARIES ${UID_WRAPPER_LOCATION})
if (OSX)
${UWRAP_GID_TESTS}
test_setgroups
test_syscall
+ test_syscall_swrap
${UWRAP_SYSCALL_UID_TESTS}
test_syscall_gid)
--- /dev/null
+#include "config.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdbool.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h>
+#endif
+
+#include "uwrap_fake_socket_wrapper.h"
+
+static void test_uwrap_syscall_swrap(void **state)
+{
+ long int rc;
+
+ (void) state; /* unused */
+
+ rc = syscall(__FAKE_SOCKET_WRAPPER_SYSCALL_NO);
+ assert_int_equal(rc, __FAKE_SOCKET_WRAPPER_SYSCALL_RC);
+
+ signal(SIGSYS, SIG_IGN);
+ rc = syscall(__FAKE_SOCKET_WRAPPER_SYSCALL_NO+1);
+ signal(SIGSYS, SIG_DFL);
+ assert_int_equal(rc, -1);
+ assert_int_equal(errno, ENOSYS);
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest uwrap_tests[] = {
+ cmocka_unit_test(test_uwrap_syscall_swrap),
+ };
+
+ rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);
+
+ return rc;
+}
--- /dev/null
+#include "config.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdbool.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYSCALL_H
+#include <syscall.h>
+#endif
+
+#include "uwrap_fake_socket_wrapper.h"
+
+/* simulate socket_wrapper hooks */
+bool socket_wrapper_syscall_valid(long int sysno)
+{
+ if (sysno == __FAKE_SOCKET_WRAPPER_SYSCALL_NO) {
+ return true;
+ }
+
+ return false;
+}
+
+long int socket_wrapper_syscall_va(long int sysno, va_list va)
+{
+ (void) va; /* unused */
+
+ if (sysno == __FAKE_SOCKET_WRAPPER_SYSCALL_NO) {
+ errno = 0;
+ return __FAKE_SOCKET_WRAPPER_SYSCALL_RC;
+ }
+
+ errno = ENOSYS;
+ return -1;
+}
--- /dev/null
+#include <stdbool.h>
+
+/* simulate socket_wrapper hooks */
+#define __FAKE_SOCKET_WRAPPER_SYSCALL_NO 123456789
+#define __FAKE_SOCKET_WRAPPER_SYSCALL_RC 987654321
+bool socket_wrapper_syscall_valid(long int sysno);
+long int socket_wrapper_syscall_va(long int sysno, va_list va);