7 #ifdef HAVE___CLOSE_NOCANCEL
8 extern int __close_nocancel(int fd);
11 static int setup(void **state)
13 torture_setup_socket_dir(state);
18 static int teardown(void **state)
20 torture_teardown_socket_dir(state);
25 static void test_dup2_existing_open_fd(void **state)
30 (void) state; /* unused */
32 s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
33 assert_int_not_equal(s, -1);
36 * Here we try to duplicate the existing socket fd to itself
37 * and as per man page for dup2() it must return the already
38 * open fd without any failure.
41 assert_int_equal(dup_s, s);
43 #ifdef HAVE___CLOSE_NOCANCEL
44 rc = __close_nocancel(s);
45 assert_return_code(rc, errno);
47 assert_int_equal(rc, -1);
48 assert_int_equal(errno, EBADF);
49 rc = __close_nocancel(s);
50 assert_int_equal(rc, -1);
51 assert_int_equal(errno, EBADF);
54 assert_return_code(rc, errno);
61 const struct CMUnitTest tcp_dup2_tests[] = {
62 cmocka_unit_test(test_dup2_existing_open_fd),
65 rc = cmocka_run_group_tests(tcp_dup2_tests, setup, teardown);