From: Jinseok Kim <always.starving0@gmail.com>
To: chrubis@suse.cz
Cc: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 1/2] poll: add basic POLLHUP semantics test
Date: Wed, 25 Feb 2026 20:28:58 +0900 [thread overview]
Message-ID: <20260225112903.1978-1-always.starving0@gmail.com> (raw)
In-Reply-To: <aZ7Q-PB-_LV2K1xK@yuki.lan>
Add a basic poll() test to verify that POLLHUP is reported when the
peer end of a pipe is closed.
The test creates a pipe, closes the write end, and polls the read end
for POLLIN events. poll() is expected to return successfully and set
POLLHUP in revents.
This covers basic poll() lifecycle semantics that were not previously
tested.
Signed-off-by: Jinseok Kim <always.starving0@gmail.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/poll/.gitignore | 1 +
testcases/kernel/syscalls/poll/poll03.c | 61 +++++++++++++++++++++++
3 files changed, 63 insertions(+)
create mode 100644 testcases/kernel/syscalls/poll/poll03.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 05bb3ceb1..15df7c414 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1092,6 +1092,7 @@ pivot_root01 pivot_root01
poll01 poll01
poll02 poll02
+poll03 poll03
ppoll01 ppoll01
diff --git a/testcases/kernel/syscalls/poll/.gitignore b/testcases/kernel/syscalls/poll/.gitignore
index 83be0ddf8..e3f66f4e6 100644
--- a/testcases/kernel/syscalls/poll/.gitignore
+++ b/testcases/kernel/syscalls/poll/.gitignore
@@ -1,2 +1,3 @@
/poll01
/poll02
+/poll03
diff --git a/testcases/kernel/syscalls/poll/poll03.c b/testcases/kernel/syscalls/poll/poll03.c
new file mode 100644
index 000000000..182d8bd3c
--- /dev/null
+++ b/testcases/kernel/syscalls/poll/poll03.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Jinseok Kim <always.starving0@gmail.com>
+ */
+
+/*\
+ * Check that poll() reports POLLHUP on a pipe read end
+ * after the write end has been closed.
+ */
+#include <unistd.h>
+#include <errno.h>
+#include <sys/poll.h>
+
+#include "tst_test.h"
+
+static int fds[2];
+
+static void verify_pollhup(void)
+{
+ struct pollfd pfd = {
+ .fd = fds[0], .events = POLLIN,
+ };
+
+ TEST(poll(&pfd, 1, -1));
+
+ if (TST_RET == -1) {
+ tst_res(TFAIL | TTERRNO, "poll() failed");
+ return;
+ }
+
+ if (TST_RET != 1) {
+ tst_res(TFAIL, "Unexpected poll() return value %ld", TST_RET);
+ return;
+ }
+
+ TST_EXP_EXPR(pfd.revents & POLLHUP);
+ TST_EXP_EXPR((pfd.revents & ~POLLHUP) == 0);
+
+ tst_res(TPASS, "poll() reported POLLHUP");
+}
+
+static void setup(void)
+{
+ SAFE_PIPE(fds);
+ SAFE_CLOSE(fds[1]);
+}
+
+static void cleanup(void)
+{
+ if (fds[0] > 0)
+ SAFE_CLOSE(fds[0]);
+
+ if (fds[1] > 0)
+ SAFE_CLOSE(fds[1]);
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_pollhup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-02-25 11:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 16:36 [LTP] [PATCH 1/2] poll: add basic POLLHUP semantics test Jinseok Kim
2026-02-19 16:36 ` [LTP] [PATCH 2/2] poll: add test for POLLNVAL on invalid fd Jinseok Kim
2026-02-20 10:05 ` Cyril Hrubis
2026-02-21 13:33 ` [LTP] [PATCH v2 1/2] poll: add basic POLLHUP semantics test Jinseok Kim
2026-02-21 13:40 ` Jinseok Kim
2026-02-21 13:40 ` [LTP] [PATCH v2 2/2] poll: add test for POLLNVAL on invalid fd Jinseok Kim
2026-02-24 15:36 ` Cyril Hrubis
2026-02-24 17:15 ` [LTP] [PATCH v3 1/2] poll: add basic POLLHUP semantics test Jinseok Kim
2026-02-24 17:15 ` [LTP] [PATCH v3 2/2] poll: add test for POLLNVAL on invalid fd Jinseok Kim
2026-02-25 10:36 ` Cyril Hrubis
2026-02-25 10:37 ` [LTP] [PATCH v3 1/2] poll: add basic POLLHUP semantics test Cyril Hrubis
2026-02-25 11:28 ` Jinseok Kim [this message]
2026-02-25 11:28 ` [LTP] [PATCH v4 2/2] poll: add test for POLLNVAL on invalid fd Jinseok Kim
2026-02-25 11:34 ` Andrea Cervesato via ltp
2026-02-25 11:34 ` [LTP] [PATCH v4 1/2] poll: add basic POLLHUP semantics test Andrea Cervesato via ltp
2026-02-25 11:39 ` [LTP] [PATCH v3 " Andrea Cervesato
2026-02-24 15:31 ` [LTP] [PATCH v2 " Cyril Hrubis
2026-02-24 17:02 ` Jinseok Kim
2026-02-20 9:51 ` [LTP] [PATCH " 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=20260225112903.1978-1-always.starving0@gmail.com \
--to=always.starving0@gmail.com \
--cc=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