[PATCH wayland v3 4/7] tests: Add test case for wl_os_set_cloexec_or_close

Bryce Harrington bryce at osg.samsung.com
Mon Dec 7 22:49:16 PST 2015


Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 tests/os-wrappers-test.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/tests/os-wrappers-test.c b/tests/os-wrappers-test.c
index b636b62..b838b93 100644
--- a/tests/os-wrappers-test.c
+++ b/tests/os-wrappers-test.c
@@ -162,6 +162,51 @@ TEST(os_wrappers_socket_cloexec_fallback)
 	do_os_wrappers_socket_cloexec(1);
 }
 
+
+static void
+do_os_wrappers_set_cloexec_or_close(int n)
+{
+	int fd;
+	int nr_fds;
+	long flags;
+
+	nr_fds = count_open_fds();
+
+        /* Create a basic socket */
+        fd = socket(PF_LOCAL, SOCK_STREAM, 0);
+        assert(fd > 0);
+
+	/* Verify we can set it to close on exec */
+	assert(wl_os_set_cloexec_or_close(fd) == fd);
+
+	/* Verify the fd is now cloexec */
+	flags = fcntl(fd, F_GETFD);
+	assert(flags & FD_CLOEXEC);
+
+	/*
+	 * Must have 2 calls if falling back, but must also allow
+	 * falling back without a forced fallback.
+	 */
+	assert(wrapped_calls_fcntl > n);
+
+	exec_fd_leak_check(nr_fds);
+}
+
+TEST(os_wrappers_set_cloexec_or_close)
+{
+	/* normal case */
+	init_fallbacks(0);
+	do_os_wrappers_set_cloexec_or_close(0);
+}
+
+TEST(os_wrappers_set_cloexec_or_close_fallback)
+{
+	/* forced fallback */
+	init_fallbacks(1);
+	do_os_wrappers_set_cloexec_or_close(1);
+}
+
+
 static void
 do_os_wrappers_dupfd_cloexec(int n)
 {
-- 
1.9.1



More information about the wayland-devel mailing list