summaryrefslogtreecommitdiffstats
path: root/tests/test_fcntl.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_fcntl.c')
-rw-r--r--tests/test_fcntl.c67
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;
+}