Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/ttyio t_ptm.c: add a test case that passes ex...



details:   https://anonhg.NetBSD.org/src/rev/7ab5dcf7d92c
branches:  trunk
changeset: 375861:7ab5dcf7d92c
user:      gutteridge <gutteridge%NetBSD.org@localhost>
date:      Wed May 17 03:16:11 2023 +0000

description:
t_ptm.c: add a test case that passes extra flags

Validate that O_NONBLOCK and O_CLOEXEC are actually set by
posix_openpt(3), as until circa 9.99.101 they were not.

If/when other flags are added like close-on-fork, this test could be
adjusted. The current concern is with supporting the expectations of
components like vte3, used by various graphical terminal clients.

diffstat:

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

diffs (56 lines):

diff -r 45f5f0f19066 -r 7ab5dcf7d92c tests/lib/libc/ttyio/t_ptm.c
--- a/tests/lib/libc/ttyio/t_ptm.c      Wed May 17 01:35:00 2023 +0000
+++ b/tests/lib/libc/ttyio/t_ptm.c      Wed May 17 03:16:11 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptm.c,v 1.1 2011/01/13 03:19:57 pgoyette Exp $ */
+/* $NetBSD: t_ptm.c,v 1.2 2023/05/17 03:16:11 gutteridge Exp $ */
 
 /*
  * Copyright (c) 2004, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_ptm.c,v 1.1 2011/01/13 03:19:57 pgoyette Exp $");
+__RCSID("$NetBSD: t_ptm.c,v 1.2 2023/05/17 03:16:11 gutteridge Exp $");
 
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -164,11 +164,37 @@ ATF_TC_BODY(ptmx, tc)
        ATF_REQUIRE_EQ_MSG(sts.st_gid, gp->gr_gid, "bad slave gid");
 }
 
+ATF_TC(ptmx_extra);
+
+ATF_TC_HEAD(ptmx_extra, tc)
+{
+
+       atf_tc_set_md_var(tc, "descr", "Checks /dev/ptmx device "
+           "applies O_NONBLOCK and O_CLOEXEC");
+}
+
+ATF_TC_BODY(ptmx_extra, tc)
+{
+       int fdm;
+
+       if ((fdm = posix_openpt(O_RDWR|O_NOCTTY|O_NONBLOCK|O_CLOEXEC)) == -1) {
+               if (errno == ENOENT || errno == ENODEV)
+                       atf_tc_skip("/dev/ptmx: %s", strerror(errno));
+
+               atf_tc_fail("/dev/ptmx: %s", strerror(errno));
+       }
+
+       /* O_NOCTTY is ignored, not set. */
+       ATF_CHECK_EQ(O_RDWR|O_NONBLOCK, fcntl(fdm, F_GETFL));
+       ATF_CHECK_EQ(FD_CLOEXEC, fcntl(fdm, F_GETFD));
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
        ATF_TP_ADD_TC(tp, ptm);
        ATF_TP_ADD_TC(tp, ptmx);
+       ATF_TP_ADD_TC(tp, ptmx_extra);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index