The branch, master has been updated via bfeac80 tests: Rename testsuite to test_ioctl. via 580a75e tests: Remove unused code. via 17c7a05 tests: Remove FIONBIO cause it doesn't work on x86. from 25d0e92 echo_srv: Fix a build warning.
http://gitweb.samba.org/?p=socket_wrapper.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit bfeac80c3ca82acd9fba6fafcf92f6201b1be906 Author: Andreas Schneider <a...@samba.org> Date: Thu Dec 12 21:26:15 2013 +0100 tests: Rename testsuite to test_ioctl. commit 580a75ec306dc939f0d325ed639ea41ea7e482e2 Author: Andreas Schneider <a...@samba.org> Date: Thu Dec 12 21:25:01 2013 +0100 tests: Remove unused code. commit 17c7a05f564d7349503b6effed3e4ddb6eb1e87e Author: Andreas Schneider <a...@samba.org> Date: Thu Dec 12 21:24:07 2013 +0100 tests: Remove FIONBIO cause it doesn't work on x86. ----------------------------------------------------------------------- Summary of changes: tests/CMakeLists.txt | 2 +- tests/test_ioctl.c | 99 ++++++++++++++++++++++++++++++++++++ tests/testsuite.c | 136 -------------------------------------------------- 3 files changed, 100 insertions(+), 137 deletions(-) create mode 100644 tests/test_ioctl.c delete mode 100644 tests/testsuite.c Changeset truncated at 500 lines: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9de698e..cce34a2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,7 +17,7 @@ target_link_libraries(${TORTURE_LIBRARY} ${CMOCKA_LIBRARY} ${SWRAP_REQUIRED_LIBRARIES}) -set(SWRAP_TESTS testsuite test_echo_udp_sendto_recvfrom) +set(SWRAP_TESTS test_ioctl test_echo_udp_sendto_recvfrom) foreach(_SWRAP_TEST ${SWRAP_TESTS}) add_cmocka_test(${_SWRAP_TEST} ${_SWRAP_TEST}.c ${TORTURE_LIBRARY}) diff --git a/tests/test_ioctl.c b/tests/test_ioctl.c new file mode 100644 index 0000000..0c9bfc6 --- /dev/null +++ b/tests/test_ioctl.c @@ -0,0 +1,99 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/ioctl.h> + +#include <errno.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +static void setup(void **state) +{ + char test_tmpdir[256]; + const char *p; + + (void) state; /* unused */ + + snprintf(test_tmpdir, sizeof(test_tmpdir), "/tmp/test_socket_wrapper_XXXXXX"); + + p = mkdtemp(test_tmpdir); + assert_non_null(p); + + setenv("SOCKET_WRAPPER_DIR", p, 1); + setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "11", 1); +} + +static void teardown(void **state) +{ + char remove_cmd[256] = {0}; + const char *swrap_dir = getenv("SOCKET_WRAPPER_DIR"); + int rc; + + (void) state; /* unused */ + + if (swrap_dir != NULL) { + snprintf(remove_cmd, sizeof(remove_cmd), "rm -rf %s", swrap_dir); + } + + rc = system(remove_cmd); + if (rc < 0) { + fprintf(stderr, "%s failed: %s", remove_cmd, strerror(errno)); + } +} + +static void test_swrap_socket(void **state) +{ + int rc; + + (void) state; /* unused */ + + rc = socket(1337, 1337, 0); + assert_int_equal(rc, -1); + assert_int_equal(errno, EAFNOSUPPORT); + + rc = socket(AF_INET, 1337, 0); + assert_int_equal(rc, -1); + assert_int_equal(errno, EPROTONOSUPPORT); + + rc = socket(AF_INET, SOCK_DGRAM, 10); + assert_int_equal(rc, -1); + assert_int_equal(errno, EPROTONOSUPPORT); +} + +static void test_swrap_ioctl_sock(void **state) +{ + int fd; + int rc; + int grp = -127; + + (void) state; /* unused */ + + fd = socket(AF_INET, SOCK_DGRAM, 0); + assert_int_not_equal(fd, -1); + +#ifdef SIOCGPGRP + rc = ioctl(fd, SIOCGPGRP, &grp); + assert_int_equal(rc, 0); + + assert_int_not_equal(grp, -127); +#endif +} + +int main(void) { + int rc; + + const UnitTest tests[] = { + unit_test_setup_teardown(test_swrap_socket, setup, teardown), + unit_test_setup_teardown(test_swrap_ioctl_sock, setup, teardown), + }; + + rc = run_tests(tests); + + return rc; +} diff --git a/tests/testsuite.c b/tests/testsuite.c deleted file mode 100644 index 70ffe8e..0000000 --- a/tests/testsuite.c +++ /dev/null @@ -1,136 +0,0 @@ -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> - -#include <errno.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -static void setup(void **state) -{ - char test_tmpdir[256]; - const char *p; - - (void) state; /* unused */ - - snprintf(test_tmpdir, sizeof(test_tmpdir), "/tmp/test_socket_wrapper_XXXXXX"); - - p = mkdtemp(test_tmpdir); - assert_non_null(p); - - setenv("SOCKET_WRAPPER_DIR", p, 1); - setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "11", 1); -} - -static void teardown(void **state) -{ - char remove_cmd[256] = {0}; - const char *swrap_dir = getenv("SOCKET_WRAPPER_DIR"); - int rc; - - (void) state; /* unused */ - - if (swrap_dir != NULL) { - snprintf(remove_cmd, sizeof(remove_cmd), "rm -rf %s", swrap_dir); - } - - rc = system(remove_cmd); - if (rc < 0) { - fprintf(stderr, "%s failed: %s", remove_cmd, strerror(errno)); - } -} - -#if 0 -static void test_socket_wrapper_dir(void **state) -{ - backup_env(); - - setenv("SOCKET_WRAPPER_DIR", "foo", 1); - assert_string_equal(socket_wrapper_dir(), "foo"); - setenv("SOCKET_WRAPPER_DIR", "./foo", 1); - assert_string_equal(socket_wrapper_dir(), "foo"); - unsetenv("SOCKET_WRAPPER_DIR"); - assert_non_null(socket_wrapper_dir()); - - restore_env(); -} -#endif - -static void test_swrap_ioctl_sock(void **state) -{ - int fd; - int rc; - int grp = -127; - - (void) state; /* unused */ - - fd = socket(AF_INET, SOCK_DGRAM, 0); - assert_int_not_equal(fd, -1); - -#ifdef FIONBIO - rc = ioctl(fd, FIONBIO); - assert_int_equal(rc, 0); -#endif - -#ifdef SIOCGPGRP - rc = ioctl(fd, SIOCGPGRP, &grp); - assert_int_equal(rc, 0); - - assert_int_not_equal(grp, -127); -#endif -} - -static void test_swrap_socket(void **state) -{ - int rc; - - (void) state; /* unused */ - - rc = socket(1337, 1337, 0); - assert_int_equal(rc, -1); - assert_int_equal(errno, EAFNOSUPPORT); - - rc = socket(AF_INET, 1337, 0); - assert_int_equal(rc, -1); - assert_int_equal(errno, EPROTONOSUPPORT); - - rc = socket(AF_INET, SOCK_DGRAM, 10); - assert_int_equal(rc, -1); - assert_int_equal(errno, EPROTONOSUPPORT); -} - -#if 0 -unsigned int socket_wrapper_default_iface(void); -static bool test_socket_wrapper_default_iface(struct torture_context *tctx) -{ - backup_env(); - unsetenv("SOCKET_WRAPPER_DEFAULT_IFACE"); - torture_assert_int_equal(tctx, socket_wrapper_default_iface(), 1, "unset"); - setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "2", 1); - torture_assert_int_equal(tctx, socket_wrapper_default_iface(), 2, "unset"); - setenv("SOCKET_WRAPPER_DEFAULT_IFACE", "bla", 1); - torture_assert_int_equal(tctx, socket_wrapper_default_iface(), 1, "unset"); - restore_env(); - return true; -} -#endif - -int main(void) { - int rc; - - const UnitTest tests[] = { - unit_test_setup_teardown(test_swrap_socket, setup, teardown), - unit_test_setup_teardown(test_swrap_ioctl_sock, setup, teardown), - }; - - rc = run_tests(tests); - - return rc; -} -- Socket Wrapper Repository