diff options
| author | Stefan Metzmacher <metze@samba.org> | 2021-02-24 12:45:26 +0100 |
|---|---|---|
| committer | Andreas Schneider <asn@samba.org> | 2021-03-15 08:04:58 +0100 |
| commit | efd2967e060a3a7ca3de589a23511bb38151ed8b (patch) | |
| tree | 1d26874505b7c381f16f0f5bcf59dcd392d3742e /tests | |
| parent | 4ad5a5af0bdf94497f068f10d6c09520702fd50f (diff) | |
| download | socket_wrapper-efd2967e060a3a7ca3de589a23511bb38151ed8b.tar.gz socket_wrapper-efd2967e060a3a7ca3de589a23511bb38151ed8b.tar.xz socket_wrapper-efd2967e060a3a7ca3de589a23511bb38151ed8b.zip | |
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 <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | tests/test_public_functions.c | 78 |
2 files changed, 80 insertions, 1 deletions
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 <errno.h> +#include <stdio.h> +#include <cmocka.h> +#include <unistd.h> +#include <stdlib.h> + +#include <socket_wrapper.h> + +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; +} |
