Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys New testcase that check for close-on-exec...



details:   https://anonhg.NetBSD.org/src/rev/4370e560bf37
branches:  trunk
changeset: 770532:4370e560bf37
user:      njoly <njoly%NetBSD.org@localhost>
date:      Thu Oct 20 18:20:30 2011 +0000

description:
New testcase that check for close-on-exec flag on pipe2 syscall.

diffstat:

 tests/lib/libc/sys/t_pipe.c |  30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

diffs (59 lines):

diff -r 4ed3e96a0be1 -r 4370e560bf37 tests/lib/libc/sys/t_pipe.c
--- a/tests/lib/libc/sys/t_pipe.c       Thu Oct 20 18:18:21 2011 +0000
+++ b/tests/lib/libc/sys/t_pipe.c       Thu Oct 20 18:20:30 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_pipe.c,v 1.1 2011/10/15 06:17:02 jruoho Exp $ */
+/* $NetBSD: t_pipe.c,v 1.2 2011/10/20 18:20:30 njoly Exp $ */
 
 /*-
  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -29,12 +29,13 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_pipe.c,v 1.1 2011/10/15 06:17:02 jruoho Exp $");
+__RCSID("$NetBSD: t_pipe.c,v 1.2 2011/10/20 18:20:30 njoly Exp $");
 
 #include <sys/types.h>
 #include <sys/wait.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <poll.h>
 #include <sched.h>
 #include <signal.h>
@@ -154,9 +155,34 @@
        }
 }
 
+ATF_TC(pipe2_cloexec);
+ATF_TC_HEAD(pipe2_cloexec, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Check pipe2(2) with O_CLOEXEC");
+}
+
+ATF_TC_BODY(pipe2_cloexec, tc)
+{
+       int flag, fildes[2];
+
+       ATF_REQUIRE(pipe2(fildes, O_CLOEXEC) != -1);
+
+       flag = fcntl(fildes[0], F_GETFD);
+       ATF_REQUIRE(flag != -1);
+       ATF_CHECK((flag & FD_CLOEXEC) != 0);
+
+       flag = fcntl(fildes[1], F_GETFD);
+       ATF_REQUIRE(flag != -1);
+       ATF_CHECK((flag & FD_CLOEXEC) != 0);
+
+       ATF_REQUIRE(close(fildes[0]) != -1);
+       ATF_REQUIRE(close(fildes[1]) != -1);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, pipe_restart);
+       ATF_TP_ADD_TC(tp, pipe2_cloexec);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index