From efd2967e060a3a7ca3de589a23511bb38151ed8b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 24 Feb 2021 12:45:26 +0100 Subject: swrap: introduce a socket_wrapper_noop.so and socket_wrapper.h to provide noop stubs Applications with the need to call socket_wrapper_enabled() should link against -lsocket_wrapper_noop in order to resolve the symbol at link time. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14640 Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- tests/CMakeLists.txt | 3 +- tests/test_public_functions.c | 78 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/test_public_functions.c (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index db36bf3..2f98af1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -56,6 +56,7 @@ set(SWRAP_TESTS test_echo_udp_sendmsg_recvmsg test_swrap_unit test_max_sockets + test_public_functions test_close_failure test_tcp_socket_overwrite ${SWRAP_THREADED_TESTS}) @@ -111,7 +112,7 @@ foreach(_SWRAP_TEST ${SWRAP_TESTS}) add_cmocka_test(${_SWRAP_TEST} SOURCES ${_SWRAP_TEST}.c COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE - LINK_LIBRARIES ${TORTURE_LIBRARY} + LINK_LIBRARIES ${TORTURE_LIBRARY} socket_wrapper_noop LINK_OPTIONS ${DEFAULT_LINK_FLAGS}) add_cmocka_test_environment(${_SWRAP_TEST}) endforeach() diff --git a/tests/test_public_functions.c b/tests/test_public_functions.c new file mode 100644 index 0000000..11d03ef --- /dev/null +++ b/tests/test_public_functions.c @@ -0,0 +1,78 @@ +#include "torture.h" + +#include +#include +#include +#include +#include + +#include + +static int setup_enabled(void **state) +{ + torture_setup_socket_dir(state); + + return 0; +} + +static int teardown_enabled(void **state) +{ + torture_teardown_socket_dir(state); + + return 0; +} + +static int setup_disabled(void **state) +{ + (void) state; /* unused */ + + unsetenv("SOCKET_WRAPPER_DIR"); + unsetenv("SOCKET_WRAPPER_DEFAULT_IFACE"); + unsetenv("SOCKET_WRAPPER_PCAP_FILE"); + + return 0; +} + +static int teardown_disabled(void **state) +{ + (void) state; /* unused */ + + return 0; +} + +static void test_call_enabled_true(void **state) +{ + char *s = getenv("SOCKET_WRAPPER_DIR"); + + (void) state; /* unused */ + + assert_true(socket_wrapper_enabled()); + assert_true(s != NULL); +} + +static void test_call_enabled_false(void **state) +{ + char *s = getenv("SOCKET_WRAPPER_DIR"); + + (void) state; /* unused */ + + assert_false(socket_wrapper_enabled()); + assert_false(s != NULL); +} + +int main(void) { + int rc; + + const struct CMUnitTest max_sockets_tests[] = { + cmocka_unit_test_setup_teardown(test_call_enabled_true, + setup_enabled, + teardown_enabled), + cmocka_unit_test_setup_teardown(test_call_enabled_false, + setup_disabled, + teardown_disabled), + }; + + rc = cmocka_run_group_tests(max_sockets_tests, NULL, NULL); + + return rc; +} -- cgit