[LTP] [PATCH v2 1/2] poll: add basic POLLHUP semantics test
Cyril Hrubis
chrubis@suse.cz
Tue Feb 24 16:31:38 CET 2026
Hi!
> 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>
> ---
> testcases/kernel/syscalls/poll/poll03.c | 62 +++++++++++++++++++++++++
This is missing runtest entry in runtest/syscalls file.
> +void verify_pollhup(void)
> +{
> + struct pollfd pfd = {
> + .fd = fds[0], .events = POLLIN,
> + };
> +
> + SAFE_CLOSE(fds[1]);
Doesn't this fail the test on a second iteration? Have you tried to run
the test with -i 2?
The fd should be closed only once in the setup.
> + 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);
> +}
> +
> +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
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list