[LTP] [PATCH v2 4/8] syscalls: Add epoll_ctl06

Cyril Hrubis chrubis@suse.cz
Thu Apr 23 14:03:05 CEST 2026


Test that iterates over different types of file descriptors, attempts to
add them to epoll and expects either success or a failure based on the
type of the file descriptor.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/epoll_ctl/.gitignore      |  1 +
 .../kernel/syscalls/epoll_ctl/epoll_ctl06.c   | 71 +++++++++++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 569e8bbe4..b302935d5 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -187,6 +187,7 @@ epoll_ctl02 epoll_ctl02
 epoll_ctl03 epoll_ctl03
 epoll_ctl04 epoll_ctl04
 epoll_ctl05 epoll_ctl05
+epoll_ctl06 epoll_ctl06
 
 epoll_wait01 epoll_wait01
 epoll_wait02 epoll_wait02
diff --git a/testcases/kernel/syscalls/epoll_ctl/.gitignore b/testcases/kernel/syscalls/epoll_ctl/.gitignore
index 3e05f2e1f..9c555f41b 100644
--- a/testcases/kernel/syscalls/epoll_ctl/.gitignore
+++ b/testcases/kernel/syscalls/epoll_ctl/.gitignore
@@ -3,3 +3,4 @@ epoll_ctl02
 epoll_ctl03
 epoll_ctl04
 epoll_ctl05
+epoll_ctl06
diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c
new file mode 100644
index 000000000..b2bfce252
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Verify epoll_ctl EPOLL_CTL_ADD behavior across all file descriptor types.
+ *
+ * The test iterates over all available fd types via TST_FD_FOREACH and
+ * attempts EPOLL_CTL_ADD on each. File descriptor types that implement the
+ * poll file operation are expected to succeed. The rest must fail with:
+ *
+ * - EPERM for fds that are valid but lack poll support (regular files,
+ *   directories, /dev/zero, /proc files, memfd).
+ * - EBADF for fds that are not usable for I/O (O_PATH, open_tree).
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "tst_epoll.h"
+#include "tst_fd.h"
+
+static int exp_errno(enum tst_fd_type type)
+{
+	switch (type) {
+	case TST_FD_FILE:
+	case TST_FD_DIR:
+	case TST_FD_DEV_ZERO:
+	case TST_FD_PROC_MAPS:
+	case TST_FD_MEMFD:
+	case TST_FD_MEMFD_SECRET:
+		return EPERM;
+	case TST_FD_PATH:
+	case TST_FD_OPEN_TREE:
+	case TST_FD_FSOPEN:
+	case TST_FD_FSPICK:
+		return EBADF;
+	default:
+		return 0;
+	}
+}
+
+static void run(void)
+{
+	int efd, err;
+	struct epoll_event ev = {.events = EPOLLIN};
+
+	TST_FD_FOREACH(fd) {
+		efd = SAFE_EPOLL_CREATE1(0);
+		ev.data.fd = fd.fd;
+		err = exp_errno(fd.type);
+
+		if (err) {
+			TST_EXP_FAIL(epoll_ctl(efd, EPOLL_CTL_ADD,
+				     fd.fd, &ev), err,
+				     "epoll_ctl() on %s", tst_fd_desc(&fd));
+		} else {
+			TST_EXP_PASS(epoll_ctl(efd, EPOLL_CTL_ADD,
+				     fd.fd, &ev),
+				     "epoll_ctl() on %s", tst_fd_desc(&fd));
+		}
+
+		SAFE_CLOSE(efd);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_tmpdir = 1,
+};
-- 
2.52.0



More information about the ltp mailing list