diff options
author | Andreas Schneider <asn@samba.org> | 2017-07-31 19:25:41 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2017-09-07 07:57:13 +0200 |
commit | a886815fc1408382a7bf0ac056e7c7d99f494345 (patch) | |
tree | 885599b45fa75f242e7338c7e2941ab689912180 /tests/test_fcntl.c | |
parent | b5a67f495620a38371cec166e05fa7010df8298a (diff) | |
download | socket_wrapper-a886815fc1408382a7bf0ac056e7c7d99f494345.tar.gz socket_wrapper-a886815fc1408382a7bf0ac056e7c7d99f494345.tar.xz socket_wrapper-a886815fc1408382a7bf0ac056e7c7d99f494345.zip |
tests: Add a simple fnctl() test
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'tests/test_fcntl.c')
-rw-r--r-- | tests/test_fcntl.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_fcntl.c b/tests/test_fcntl.c new file mode 100644 index 0000000..7925185 --- /dev/null +++ b/tests/test_fcntl.c @@ -0,0 +1,67 @@ +#include "torture.h" + +#include <cmocka.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> + +static int setup(void **state) +{ + torture_setup_socket_dir(state); + + return 0; +} + +static int teardown(void **state) +{ + torture_teardown_socket_dir(state); + + return 0; +} + +static void test_fcntl_dupfd_existing_open_fd(void **state) +{ + int s, dup_s; + + (void) state; /* unused */ + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + assert_return_code(s, errno); + + dup_s = fcntl(s, F_DUPFD, 100); + assert_int_equal(dup_s, 100); + + close(s); + close(dup_s); +} + +static void test_fcntl_getfd_existing_open_fd(void **state) +{ + int s, rc, flags; + + (void) state; /* unused */ + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + assert_return_code(s, errno); + + rc = fcntl(s, F_SETFD, FD_CLOEXEC); + assert_int_equal(rc, 0); + + flags = fcntl(s, F_GETFD); + assert_int_equal(flags, FD_CLOEXEC); + + close(s); +} + +int main(void) { + int rc; + + const struct CMUnitTest tcp_fcntl_dupfd_tests[] = { + cmocka_unit_test(test_fcntl_dupfd_existing_open_fd), + cmocka_unit_test(test_fcntl_getfd_existing_open_fd), + }; + + rc = cmocka_run_group_tests(tcp_fcntl_dupfd_tests, setup, teardown); + + return rc; +} |