[LTP] [PATCH 2/2] Add regression test for epoll_pwait2() timeout
Martin Doucha
mdoucha@suse.cz
Tue Jun 3 16:13:17 CEST 2025
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
Note: The test will get killed by SIGALRM on failure.
runtest/syscalls | 1 +
.../kernel/syscalls/epoll_pwait/.gitignore | 1 +
.../syscalls/epoll_pwait/epoll_pwait06.c | 86 +++++++++++++++++++
3 files changed, 88 insertions(+)
create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
diff --git a/runtest/syscalls b/runtest/syscalls
index e7bc7b27b..2a968099a 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -192,6 +192,7 @@ epoll_pwait02 epoll_pwait02
epoll_pwait03 epoll_pwait03
epoll_pwait04 epoll_pwait04
epoll_pwait05 epoll_pwait05
+epoll_pwait06 epoll_pwait06
eventfd01 eventfd01
eventfd02 eventfd02
diff --git a/testcases/kernel/syscalls/epoll_pwait/.gitignore b/testcases/kernel/syscalls/epoll_pwait/.gitignore
index fafb2d782..81e77b8d0 100644
--- a/testcases/kernel/syscalls/epoll_pwait/.gitignore
+++ b/testcases/kernel/syscalls/epoll_pwait/.gitignore
@@ -3,3 +3,4 @@ epoll_pwait02
epoll_pwait03
epoll_pwait04
epoll_pwait05
+epoll_pwait06
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
new file mode 100644
index 000000000..487992744
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 SUSE LLC <mdoucha@suse.cz>
+ */
+
+/*\
+ * Verify that various timeout values don't get misinterpreted as infinity
+ * by epoll_pwait() and epoll_pwait2()
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "tst_timer.h"
+#include "epoll_pwait_var.h"
+
+static int efd;
+
+static void run(void)
+{
+ struct timespec timeout = {};
+ struct epoll_event e = {};
+ int ret;
+
+ e.events = EPOLLIN;
+
+ TST_FD_FOREACH(fd_in) {
+ /* File descriptor types not supported by epoll */
+ switch (fd_in.type) {
+ case TST_FD_FILE:
+ case TST_FD_PATH:
+ case TST_FD_DIR:
+ case TST_FD_DEV_ZERO:
+ case TST_FD_PROC_MAPS:
+ case TST_FD_FSOPEN:
+ case TST_FD_FSPICK:
+ case TST_FD_OPEN_TREE:
+ case TST_FD_MEMFD:
+ case TST_FD_MEMFD_SECRET:
+ continue;
+ default:
+ break;
+ }
+
+ tst_res(TINFO, "Testing %s", tst_fd_desc(&fd_in));
+ timeout.tv_nsec = 1000000000;
+ ret = epoll_ctl(efd, EPOLL_CTL_ADD, fd_in.fd, &e);
+
+ if (ret)
+ tst_brk(TBROK | TERRNO, "epoll_ctl(EPOLL_CTL_ADD)");
+
+ do {
+ alarm(1);
+ timeout.tv_nsec /= 10;
+ do_epoll_pwait(efd, &e, 1, &timeout, NULL);
+ alarm(0);
+ } while (timeout.tv_nsec);
+
+ if (epoll_ctl(efd, EPOLL_CTL_DEL, fd_in.fd, &e))
+ tst_brk(TBROK | TERRNO, "epoll_ctl(EPOLL_CTL_DEL)");
+ }
+
+ tst_res(TPASS, "Timeout works correctly");
+}
+
+static void setup(void)
+{
+ epoll_pwait_init();
+ efd = epoll_create(1);
+
+ if (efd == -1)
+ tst_brk(TBROK | TERRNO, "epoll_create()");
+}
+
+static void cleanup(void)
+{
+ if (efd > 0)
+ SAFE_CLOSE(efd);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_variants = TEST_VARIANTS,
+};
--
2.49.0
More information about the ltp
mailing list