[LTP] [PATCH v2 2/2] Add regression test for epoll_pwait2() timeout

Martin Doucha mdoucha@suse.cz
Tue Jun 3 17:22:42 CEST 2025


Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Changes since v1:
- Added kernel fix reference
- Use SAFE_EPOLL_*() functions

 runtest/syscalls                              |  1 +
 .../kernel/syscalls/epoll_pwait/.gitignore    |  1 +
 .../syscalls/epoll_pwait/epoll_pwait06.c      | 87 +++++++++++++++++++
 3 files changed, 89 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..3bedc2cf5
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait06.c
@@ -0,0 +1,87 @@
+// 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(). Regression fixed in:
+ *
+ * commit d9ec73301099ec5975505e1c3effbe768bab9490
+ * Author: Max Kellermann <max.kellermann@ionos.com>
+ * Date:   Tue Apr 29 20:58:27 2025 +0200
+ *
+ * fs/eventpoll: fix endless busy loop after timeout has expired
+ */
+
+#include "tst_test.h"
+#include "tst_timer.h"
+#include "tst_epoll.h"
+#include "epoll_pwait_var.h"
+
+static int efd = -1;
+
+static void run(void)
+{
+	struct timespec timeout = {};
+	struct epoll_event e = {};
+
+	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;
+		SAFE_EPOLL_CTL(efd, EPOLL_CTL_ADD, fd_in.fd, &e);
+
+		do {
+			alarm(1);
+			timeout.tv_nsec /= 10;
+			do_epoll_pwait(efd, &e, 1, &timeout, NULL);
+			alarm(0);
+		} while (timeout.tv_nsec);
+
+		SAFE_EPOLL_CTL(efd, EPOLL_CTL_DEL, fd_in.fd, &e);
+	}
+
+	tst_res(TPASS, "Timeout works correctly");
+}
+
+static void setup(void)
+{
+	epoll_pwait_init();
+	efd = SAFE_EPOLL_CREATE1(0);
+}
+
+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,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "d9ec73301099"},
+		{}
+	}
+};
-- 
2.49.0



More information about the ltp mailing list