public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/8] syscalls: Add epoll_create03
Date: Thu, 23 Apr 2026 14:03:02 +0200	[thread overview]
Message-ID: <20260423120309.18049-2-chrubis@suse.cz> (raw)
In-Reply-To: <20260423120309.18049-1-chrubis@suse.cz>

Test that checks that we get EMFILE when limit on per-process file
descriptors is hit.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/epoll_create/.gitignore   |  1 +
 .../syscalls/epoll_create/epoll_create03.c    | 72 +++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_create/epoll_create03.c

diff --git a/runtest/syscalls b/runtest/syscalls
index df5dc02b5..d890c5516 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -177,6 +177,8 @@ dup3_02 dup3_02
 
 epoll_create01 epoll_create01
 epoll_create02 epoll_create02
+epoll_create03 epoll_create03
+
 epoll_create1_01 epoll_create1_01
 epoll_create1_02 epoll_create1_02
 epoll01 epoll-ltp
diff --git a/testcases/kernel/syscalls/epoll_create/.gitignore b/testcases/kernel/syscalls/epoll_create/.gitignore
index 5c16cfa8c..855bf255c 100644
--- a/testcases/kernel/syscalls/epoll_create/.gitignore
+++ b/testcases/kernel/syscalls/epoll_create/.gitignore
@@ -1,2 +1,3 @@
 epoll_create01
 epoll_create02
+epoll_create03
diff --git a/testcases/kernel/syscalls/epoll_create/epoll_create03.c b/testcases/kernel/syscalls/epoll_create/epoll_create03.c
new file mode 100644
index 000000000..d0e66c4e5
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_create/epoll_create03.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Verify that epoll_create() fails with EMFILE when the per-process limit on
+ * the number of open file descriptors has been reached.
+ */
+
+#include <stdlib.h>
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "lapi/epoll.h"
+#include "lapi/syscalls.h"
+
+#include "epoll_create.h"
+
+static int *fds;
+static int nfds;
+static long maxfds;
+
+static void setup(void)
+{
+	int fd;
+
+	variant_info();
+
+	maxfds = SAFE_SYSCONF(_SC_OPEN_MAX);
+	fds = SAFE_MALLOC(maxfds * sizeof(int));
+	memset(fds, -1, maxfds * sizeof(int));
+
+	fds[0] = SAFE_OPEN("dummy", O_RDWR | O_CREAT, 0700);
+	nfds = 1;
+
+	for (long i = 1; i < maxfds; i++) {
+		fd = dup(fds[0]);
+		if (fd == -1)
+			break;
+		fds[nfds++] = fd;
+	}
+}
+
+static void run(void)
+{
+	TST_EXP_FAIL2(do_epoll_create(1), EMFILE,
+		      "epoll_create(1) with exhausted fds");
+
+	if (TST_RET != -1)
+		SAFE_CLOSE(TST_RET);
+}
+
+static void cleanup(void)
+{
+	int i;
+
+	for (i = 0; i < nfds; i++) {
+		if (fds[i] != -1)
+			SAFE_CLOSE(fds[i]);
+	}
+
+	free(fds);
+}
+
+static struct tst_test test = {
+	.test_variants = EPOLL_CREATE_VARIANTS,
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2026-04-23 12:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 12:03 [LTP] [PATCH v2 0/8] Add more epoll tests Cyril Hrubis
2026-04-23 12:03 ` Cyril Hrubis [this message]
2026-04-23 12:41   ` [LTP] [PATCH v2 1/8] syscalls: Add epoll_create03 Petr Vorel
2026-04-23 13:43   ` [LTP] " linuxtestproject.agent
2026-04-23 12:03 ` [LTP] [PATCH v2 2/8] syscalls: Add epoll_wait08 Cyril Hrubis
2026-04-23 12:03 ` [LTP] [PATCH v2 3/8] syscalls: Add epoll_wait09 Cyril Hrubis
2026-04-23 12:03 ` [LTP] [PATCH v2 4/8] syscalls: Add epoll_ctl06 Cyril Hrubis
2026-04-23 12:03 ` [LTP] [PATCH v2 5/8] syscalls: Add epoll_wait10 Cyril Hrubis
2026-04-23 12:03 ` [LTP] [PATCH v2 6/8] syscalls: Add epoll_wait11 Cyril Hrubis
2026-04-23 12:03 ` [LTP] [PATCH v2 7/8] syscalls: Add epoll_wait12 Cyril Hrubis
2026-04-23 12:03 ` [LTP] [PATCH v2 8/8] syscalls: Remove old epoll-ltp test Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260423120309.18049-2-chrubis@suse.cz \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox