* [LTP] [PATCH v1] Add epoll_wait05 test
@ 2022-10-10 10:18 Andrea Cervesato via ltp
2022-10-20 9:10 ` Richard Palethorpe
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Cervesato via ltp @ 2022-10-10 10:18 UTC (permalink / raw)
To: ltp
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>
---
.../kernel/syscalls/epoll_wait/.gitignore | 1 +
.../kernel/syscalls/epoll_wait/epoll_wait05.c | 74 +++++++++++++++++++
2 files changed, 75 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..7909a6586
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c
@@ -0,0 +1,74 @@
+// 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"
+
+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 res;
+ struct epoll_event evt_req;
+ struct epoll_event evt_rec;
+
+ sockfd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+
+ epfd = epoll_create1(0);
+ if (epfd == -1)
+ tst_brk(TBROK | TERRNO, "fail to create epoll instance");
+
+ tst_res(TINFO, "Polling on socket");
+
+ evt_req.events = EPOLLRDHUP;
+ res = epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &evt_req);
+ if (res == -1)
+ tst_brk(TBROK | TERRNO, "epoll_ctl failure");
+
+ tst_res(TINFO, "Hang reading half-socket");
+ shutdown(sockfd, SHUT_RD);
+
+ res = epoll_wait(epfd, &evt_rec, 1, 2000);
+ if (res <= 0) {
+ tst_res(TFAIL | TERRNO, "epoll_wait() returned %i", res);
+ return;
+ }
+
+ if (evt_rec.events & EPOLLHUP)
+ tst_res(TPASS, "Received EPOLLHUP");
+ else
+ tst_res(TFAIL, "EPOLLHUP has not been received");
+
+ if (evt_rec.events & EPOLLRDHUP)
+ tst_res(TPASS, "Received EPOLLRDHUP");
+ else
+ tst_res(TFAIL, "EPOLLRDHUP has not been received");
+
+ SAFE_CLOSE(epfd);
+}
+
+static struct tst_test test = {
+ .cleanup = cleanup,
+ .test_all = run,
+ .forks_child = 1,
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH v1] Add epoll_wait05 test
2022-10-10 10:18 [LTP] [PATCH v1] Add epoll_wait05 test Andrea Cervesato via ltp
@ 2022-10-20 9:10 ` Richard Palethorpe
0 siblings, 0 replies; 2+ messages in thread
From: Richard Palethorpe @ 2022-10-20 9:10 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
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>
> ---
> .../kernel/syscalls/epoll_wait/.gitignore | 1 +
> .../kernel/syscalls/epoll_wait/epoll_wait05.c | 74 +++++++++++++++++++
> 2 files changed, 75 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..7909a6586
> --- /dev/null
> +++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait05.c
> @@ -0,0 +1,74 @@
> +// 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"
> +
> +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 res;
> + struct epoll_event evt_req;
> + struct epoll_event evt_rec;
> +
> + sockfd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
> +
> + epfd = epoll_create1(0);
I added safe epoll functions in an unmerged patch-set; see:
https://patchwork.ozlabs.org/project/ltp/patch/20220927161408.23743-2-rpalethorpe@suse.com/
I will merge that so you can use it here.
> + if (epfd == -1)
> + tst_brk(TBROK | TERRNO, "fail to create epoll instance");
> +
> + tst_res(TINFO, "Polling on socket");
> +
> + evt_req.events = EPOLLRDHUP;
> + res = epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &evt_req);
> + if (res == -1)
> + tst_brk(TBROK | TERRNO, "epoll_ctl failure");
> +
> + tst_res(TINFO, "Hang reading half-socket");
> + shutdown(sockfd, SHUT_RD);
We should check the return value. It will help with debugging if the
test fails.
> +
> + res = epoll_wait(epfd, &evt_rec, 1, 2000);
> + if (res <= 0) {
> + tst_res(TFAIL | TERRNO, "epoll_wait() returned %i", res);
> + return;
> + }
> +
> + if (evt_rec.events & EPOLLHUP)
> + tst_res(TPASS, "Received EPOLLHUP");
> + else
> + tst_res(TFAIL, "EPOLLHUP has not been received");
> +
> + if (evt_rec.events & EPOLLRDHUP)
> + tst_res(TPASS, "Received EPOLLRDHUP");
> + else
> + tst_res(TFAIL, "EPOLLRDHUP has not been received");
> +
> + SAFE_CLOSE(epfd);
> +}
> +
> +static struct tst_test test = {
> + .cleanup = cleanup,
> + .test_all = run,
> + .forks_child = 1,
> +};
> --
> 2.35.3
--
Thank you,
Richard.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-20 9:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-10 10:18 [LTP] [PATCH v1] Add epoll_wait05 test Andrea Cervesato via ltp
2022-10-20 9:10 ` Richard Palethorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox