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 2/8] syscalls: Add epoll_wait08
Date: Thu, 23 Apr 2026 14:03:03 +0200	[thread overview]
Message-ID: <20260423120309.18049-3-chrubis@suse.cz> (raw)
In-Reply-To: <20260423120309.18049-1-chrubis@suse.cz>

Tests that epoll_wait() can be interrupted by a signal and returns
EINTR.

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

diff --git a/runtest/syscalls b/runtest/syscalls
index d890c5516..99cdd1db8 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_wait01 epoll_wait01
 epoll_wait02 epoll_wait02
 epoll_wait03 epoll_wait03
@@ -194,6 +195,8 @@ epoll_wait04 epoll_wait04
 epoll_wait05 epoll_wait05
 epoll_wait06 epoll_wait06
 epoll_wait07 epoll_wait07
+epoll_wait08 epoll_wait08
+
 epoll_pwait01 epoll_pwait01
 epoll_pwait02 epoll_pwait02
 epoll_pwait03 epoll_pwait03
diff --git a/testcases/kernel/syscalls/epoll_wait/.gitignore b/testcases/kernel/syscalls/epoll_wait/.gitignore
index 66ac18ae2..f3b208950 100644
--- a/testcases/kernel/syscalls/epoll_wait/.gitignore
+++ b/testcases/kernel/syscalls/epoll_wait/.gitignore
@@ -5,3 +5,4 @@ epoll_wait04
 epoll_wait05
 epoll_wait06
 epoll_wait07
+epoll_wait08
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait08.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait08.c
new file mode 100644
index 000000000..9d10984ef
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait08.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2026
+ */
+
+/*\
+ * Verify that epoll_wait fails with EINTR when a signal arrives while waiting
+ * for events.
+ *
+ * [Algorithm]
+ *
+ * - Create an epoll instance and register a socket fd for EPOLLIN.
+ * - Fork a child that waits for the parent to enter epoll_wait, then sends
+ *   SIGUSR1 to interrupt it.
+ * - Verify that epoll_wait returns -1 with errno set to EINTR.
+ */
+
+#include <stdlib.h>
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "tst_epoll.h"
+
+static int efd = -1;
+
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
+{
+}
+
+static void setup(void)
+{
+	static struct sigaction sa = {
+		.sa_handler = sighandler,
+	};
+
+	SAFE_SIGEMPTYSET(&sa.sa_mask);
+	SAFE_SIGACTION(SIGUSR1, &sa, NULL);
+
+	efd = SAFE_EPOLL_CREATE1(0);
+}
+
+static void run(void)
+{
+	pid_t pid = SAFE_FORK();
+
+	if (!pid) {
+		struct epoll_event ev;
+
+		TST_EXP_FAIL(epoll_wait(efd, &ev, 1, -1), EINTR,
+			     "epoll_wait() interrupted by signal");
+		exit(0);
+	}
+
+	TST_PROCESS_STATE_WAIT(pid, 'S', 0);
+	SAFE_KILL(pid, SIGUSR1);
+}
+
+static void cleanup(void)
+{
+	if (efd != -1)
+		SAFE_CLOSE(efd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+};
-- 
2.52.0


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

  parent reply	other threads:[~2026-04-23 12:03 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 ` [LTP] [PATCH v2 1/8] syscalls: Add epoll_create03 Cyril Hrubis
2026-04-23 12:41   ` Petr Vorel
2026-04-23 13:43   ` [LTP] " linuxtestproject.agent
2026-04-23 12:03 ` Cyril Hrubis [this message]
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-3-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