public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] Add epoll_wait05 test
Date: Tue, 22 Nov 2022 13:26:12 +0000	[thread overview]
Message-ID: <87wn7ndr1c.fsf@suse.de> (raw)
In-Reply-To: <20221028085735.32615-1-andrea.cervesato@suse.com>

Hello,

Andrea Cervesato via ltp <ltp@lists.linux.it> writes:

> This test verifies that epoll receives EPOLLHUP/EPOLLRDHUP event
> when we hang a reading half-socket we are polling on.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> Make use of SAFE_EPOLL_* macros
>
>  .../kernel/syscalls/epoll_wait/.gitignore     |  1 +
>  .../kernel/syscalls/epoll_wait/epoll_wait05.c | 72 +++++++++++++++++++
>  2 files changed, 73 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait05.c
>
> diff --git a/testcases/kernel/syscalls/epoll_wait/.gitignore b/testcases/kernel/syscalls/epoll_wait/.gitignore
> index 222955dd2..ab5a9c010 100644
> --- a/testcases/kernel/syscalls/epoll_wait/.gitignore
> +++ b/testcases/kernel/syscalls/epoll_wait/.gitignore
> @@ -2,3 +2,4 @@ epoll_wait01
>  epoll_wait02
>  epoll_wait03
>  epoll_wait04
> +epoll_wait05
> diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c
> new file mode 100644
> index 000000000..2ed0b2ab1
> --- /dev/null
> +++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c
> @@ -0,0 +1,72 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Verify that epoll receives EPOLLHUP/EPOLLRDHUP event when we hang a reading
> + * half-socket we are polling on.
> + */
> +
> +#include <poll.h>
> +#include <sys/epoll.h>
> +#include "tst_test.h"
> +#include "tst_epoll.h"
> +
> +static int sockfd;
> +static int epfd;
> +
> +static void cleanup(void)
> +{
> +	if (epfd > 0)
> +		SAFE_CLOSE(epfd);
> +
> +	if (sockfd > 0)
> +		SAFE_CLOSE(sockfd);
> +}
> +
> +static void run(void)
> +{
> +	int ret;
> +	struct epoll_event evt_req;
> +	struct epoll_event evt_rec;
> +
> +	sockfd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
> +	epfd = SAFE_EPOLL_CREATE1(0);
> +
> +	tst_res(TINFO, "Polling on socket");
> +
> +	evt_req.events = EPOLLRDHUP;
> +	SAFE_EPOLL_CTL(epfd, EPOLL_CTL_ADD, sockfd, &evt_req);
> +
> +	tst_res(TINFO, "Hang reading half-socket");

So far a TCP socket has been created, but nothing else. No connect,
bind, listen or accept calls.

> +
> +	ret = shutdown(sockfd, SHUT_RD);
> +	if (ret == -1 && errno != ENOTCONN) {
> +		tst_brk(TBROK | TERRNO, "shutdown error");
> +		goto close;

tst_brk won't return in this case.

> +	}
> +
> +	SAFE_EPOLL_WAIT(epfd, &evt_rec, 1, 2000);
> +
> +	if (evt_rec.events & EPOLLHUP)
> +		tst_res(TPASS, "Received EPOLLHUP");
> +	else
> +		tst_res(TFAIL, "EPOLLHUP has not been received");

Why is this a fail?

The socket is not connected and shutdown returns ENOTCONN. Whether
shutdown has any effect in this case appears to be undefined.

Possibly you could use UDP instead (SOCK_DGRAM). In this case the socket
does not need to be connected to send or receive packets and you
shouldn't get ENOTCONN.

> +
> +	if (evt_rec.events & EPOLLRDHUP)
> +		tst_res(TPASS, "Received EPOLLRDHUP");
> +	else
> +		tst_res(TFAIL, "EPOLLRDHUP has not been received");

Same

> +
> +close:
> +	SAFE_CLOSE(epfd);
> +}
> +
> +static struct tst_test test = {
> +	.cleanup = cleanup,
> +	.test_all = run,
> +	.forks_child = 1,

No it doesn't



> +};
> -- 
> 2.35.3


-- 
Thank you,
Richard.

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

      reply	other threads:[~2022-11-22 14:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28  8:57 [LTP] [PATCH v2] Add epoll_wait05 test Andrea Cervesato via ltp
2022-11-22 13:26 ` Richard Palethorpe [this message]

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=87wn7ndr1c.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=andrea.cervesato@suse.com \
    --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