[PATCH v3 4/9] syscalls: Add epoll_ctl06

Cyril Hrubis <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
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 <[email protected]>
Reviewed-by: Andrea Cervesato <andrea.cervesato-IBi9RG/[email protected]>
---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/epoll_ctl/.gitignore      |  1 +
 .../kernel/syscalls/epoll_ctl/epoll_ctl06.c   | 72 +++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 727156950..b78d565fb 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..fb33379f4
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <[email protected]>
+ */
+
+/*\
+ * Verify :manpage: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:
+	case TST_FD_FSOPEN:
+	case TST_FD_FSPICK:
+		return EPERM;
+	case TST_FD_PATH:
+	case TST_FD_OPEN_TREE:
+		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.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.