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 Validate basic fcntl(2) behavior for even...
details: https://anonhg.NetBSD.org/src/rev/8ba7b35aa6fc
branches: trunk
changeset: 361983:8ba7b35aa6fc
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun Feb 20 15:21:14 2022 +0000
description:
Validate basic fcntl(2) behavior for eventfd and timerfd.
diffstat:
tests/lib/libc/sys/t_eventfd.c | 44 +++++++++++++++++++++++++++++++++++++++-
tests/lib/libc/sys/t_timerfd.c | 45 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 85 insertions(+), 4 deletions(-)
diffs (152 lines):
diff -r e1fde113b3d8 -r 8ba7b35aa6fc tests/lib/libc/sys/t_eventfd.c
--- a/tests/lib/libc/sys/t_eventfd.c Sun Feb 20 14:43:39 2022 +0000
+++ b/tests/lib/libc/sys/t_eventfd.c Sun Feb 20 15:21:14 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_eventfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $ */
+/* $NetBSD: t_eventfd.c,v 1.3 2022/02/20 15:21:14 thorpej Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,11 +29,12 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2020\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_eventfd.c,v 1.2 2021/09/19 15:51:28 thorpej Exp $");
+__RCSID("$NetBSD: t_eventfd.c,v 1.3 2022/02/20 15:21:14 thorpej Exp $");
#include <sys/types.h>
#include <sys/event.h>
#include <sys/eventfd.h>
+#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/syscall.h>
@@ -776,6 +777,44 @@
/*****************************************************************************/
+ATF_TC(eventfd_fcntl);
+ATF_TC_HEAD(eventfd_fcntl, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "validates fcntl behavior");
+}
+ATF_TC_BODY(eventfd_fcntl, tc)
+{
+ int efd;
+ int val;
+
+ ATF_REQUIRE((efd = eventfd(1, 0)) >= 0);
+ ATF_REQUIRE((fcntl(efd, F_GETFL) & O_NONBLOCK) == 0);
+ ATF_REQUIRE(fcntl(efd, F_SETFL, O_NONBLOCK) == 0);
+ ATF_REQUIRE((fcntl(efd, F_GETFL) & O_NONBLOCK) != 0);
+ ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) == 0);
+
+ ATF_REQUIRE(ioctl(efd, FIONREAD, &val) == 0);
+ ATF_REQUIRE(val == sizeof(eventfd_t));
+
+ ATF_REQUIRE(ioctl(efd, FIONWRITE, &val) == 0);
+ ATF_REQUIRE(val == 0);
+
+ ATF_REQUIRE_ERRNO(ENOTTY, ioctl(efd, FIONSPACE, &val) == -1);
+ (void)close(efd);
+
+ ATF_REQUIRE((efd = eventfd(1, EFD_NONBLOCK | EFD_CLOEXEC)) >= 0);
+ ATF_REQUIRE((fcntl(efd, F_GETFL) & ~O_ACCMODE) == O_NONBLOCK);
+ ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) != 0);
+ ATF_REQUIRE(fcntl(efd, F_SETFD, 0) == 0);
+ ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) == 0);
+ ATF_REQUIRE(fcntl(efd, F_SETFD, FD_CLOEXEC) == 0);
+ ATF_REQUIRE((fcntl(efd, F_GETFD) & FD_CLOEXEC) != 0);
+ (void)close(efd);
+}
+
+/*****************************************************************************/
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, eventfd_normal);
@@ -785,6 +824,7 @@
ATF_TP_ADD_TC(tp, eventfd_select_poll_kevent_immed);
ATF_TP_ADD_TC(tp, eventfd_select_poll_kevent_block);
ATF_TP_ADD_TC(tp, eventfd_restart);
+ ATF_TP_ADD_TC(tp, eventfd_fcntl);
return atf_no_error();
}
diff -r e1fde113b3d8 -r 8ba7b35aa6fc tests/lib/libc/sys/t_timerfd.c
--- a/tests/lib/libc/sys/t_timerfd.c Sun Feb 20 14:43:39 2022 +0000
+++ b/tests/lib/libc/sys/t_timerfd.c Sun Feb 20 15:21:14 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $ */
+/* $NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $ */
/*-
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -29,10 +29,11 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2020\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_timerfd.c,v 1.3 2021/11/01 14:33:41 hannken Exp $");
+__RCSID("$NetBSD: t_timerfd.c,v 1.4 2022/02/20 15:21:14 thorpej Exp $");
#include <sys/types.h>
#include <sys/event.h>
+#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/syscall.h>
@@ -608,6 +609,45 @@
/*****************************************************************************/
+ATF_TC(timerfd_fcntl);
+ATF_TC_HEAD(timerfd_fcntl, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "validates fcntl behavior");
+}
+
+ATF_TC_BODY(timerfd_fcntl, tc)
+{
+ int tfd;
+ int val;
+
+ ATF_REQUIRE((tfd = timerfd_create(CLOCK_MONOTONIC, 0)) >= 0);
+ ATF_REQUIRE((fcntl(tfd, F_GETFL) & O_NONBLOCK) == 0);
+ ATF_REQUIRE(fcntl(tfd, F_SETFL, O_NONBLOCK) == 0);
+ ATF_REQUIRE((fcntl(tfd, F_GETFL) & O_NONBLOCK) != 0);
+ ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) == 0);
+
+ /* If the timer hasn't fired, there is no readable data. */
+ ATF_REQUIRE(ioctl(tfd, FIONREAD, &val) == 0);
+ ATF_REQUIRE(val == 0);
+
+ ATF_REQUIRE_ERRNO(ENOTTY, ioctl(tfd, FIONWRITE, &val) == -1);
+ ATF_REQUIRE_ERRNO(ENOTTY, ioctl(tfd, FIONSPACE, &val) == -1);
+ (void)close(tfd);
+
+ ATF_REQUIRE((tfd = timerfd_create(CLOCK_MONOTONIC,
+ TFD_NONBLOCK | TFD_CLOEXEC)) >= 0);
+ ATF_REQUIRE((fcntl(tfd, F_GETFL) & ~O_ACCMODE) == O_NONBLOCK);
+ ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) != 0);
+ ATF_REQUIRE(fcntl(tfd, F_SETFD, 0) == 0);
+ ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) == 0);
+ ATF_REQUIRE(fcntl(tfd, F_SETFD, FD_CLOEXEC) == 0);
+ ATF_REQUIRE((fcntl(tfd, F_GETFD) & FD_CLOEXEC) != 0);
+ (void)close(tfd);
+}
+
+/*****************************************************************************/
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, timerfd_create);
@@ -620,6 +660,7 @@
ATF_TP_ADD_TC(tp, timerfd_select_poll_kevent_immed);
ATF_TP_ADD_TC(tp, timerfd_select_poll_kevent_block);
ATF_TP_ADD_TC(tp, timerfd_restart);
+ ATF_TP_ADD_TC(tp, timerfd_fcntl);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index