* [LTP] [PATCH v4] Add epoll_wait07 test
@ 2023-08-25 10:30 Andrea Cervesato
2023-09-06 8:46 ` Richard Palethorpe
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Cervesato @ 2023-08-25 10:30 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that EPOLLONESHOT is correctly handled by
epoll_wait.
Implements: https://github.com/linux-test-project/ltp/issues/860
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/epoll_wait/.gitignore | 1 +
.../kernel/syscalls/epoll_wait/epoll_wait07.c | 73 +++++++++++++++++++
3 files changed, 75 insertions(+)
create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait07.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 88e868a74..1cdba11ce 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -175,6 +175,7 @@ epoll_wait01 epoll_wait01
epoll_wait02 epoll_wait02
epoll_wait03 epoll_wait03
epoll_wait04 epoll_wait04
+epoll_wait07 epoll_wait07
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 222955dd2..c0be9a88e 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_wait07
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait07.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait07.c
new file mode 100644
index 000000000..dfabd0d87
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait07.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that EPOLLONESHOT is correctly handled by epoll_wait.
+ * We open a channel, write in it two times and verify that EPOLLIN has been
+ * received only once.
+ */
+
+#include <poll.h>
+#include <sys/epoll.h>
+#include "tst_test.h"
+#include "tst_epoll.h"
+
+static int fds[2];
+static int epfd;
+
+static void cleanup(void)
+{
+ if (epfd > 0)
+ SAFE_CLOSE(epfd);
+
+ if (fds[0] > 0)
+ SAFE_CLOSE(fds[0]);
+
+ if (fds[1] > 0)
+ SAFE_CLOSE(fds[1]);
+}
+
+static void run(void)
+{
+ struct epoll_event evt_receive;
+ char buff = 'a';
+
+ SAFE_PIPE(fds);
+
+ tst_res(TINFO, "Polling on channel with EPOLLONESHOT");
+
+ epfd = SAFE_EPOLL_CREATE1(0);
+
+ SAFE_EPOLL_CTL(epfd, EPOLL_CTL_ADD, fds[0], &((struct epoll_event) {
+ .events = EPOLLIN | EPOLLONESHOT,
+ .data.fd = fds[0],
+ }));
+
+ tst_res(TINFO, "Write channel for the 1st time. EPOLLIN expected");
+
+ SAFE_WRITE(0, fds[1], &buff, 1);
+ TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 10, 0), 1);
+ TST_EXP_EQ_LI(evt_receive.events & EPOLLIN, EPOLLIN);
+ TST_EXP_EQ_LI(evt_receive.data.fd, fds[0]);
+
+ SAFE_READ(1, fds[0], &buff, 1);
+ TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 10, 0), 0);
+
+ tst_res(TINFO, "Write channel for the 2nd time. No events expected");
+
+ SAFE_WRITE(0, fds[1], &buff, 1);
+ TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 10, 0), 0);
+
+ SAFE_CLOSE(epfd);
+ SAFE_CLOSE(fds[0]);
+ SAFE_CLOSE(fds[1]);
+}
+
+static struct tst_test test = {
+ .cleanup = cleanup,
+ .test_all = run,
+};
--
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 v4] Add epoll_wait07 test
2023-08-25 10:30 [LTP] [PATCH v4] Add epoll_wait07 test Andrea Cervesato
@ 2023-09-06 8:46 ` Richard Palethorpe
0 siblings, 0 replies; 2+ messages in thread
From: Richard Palethorpe @ 2023-09-06 8:46 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hello,
Pushed!
Andrea Cervesato <andrea.cervesato@suse.de> writes:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> This test verifies that EPOLLONESHOT is correctly handled by
> epoll_wait.
>
> Implements: https://github.com/linux-test-project/ltp/issues/860
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> runtest/syscalls | 1 +
> .../kernel/syscalls/epoll_wait/.gitignore | 1 +
> .../kernel/syscalls/epoll_wait/epoll_wait07.c | 73 +++++++++++++++++++
> 3 files changed, 75 insertions(+)
> create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait07.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 88e868a74..1cdba11ce 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -175,6 +175,7 @@ epoll_wait01 epoll_wait01
> epoll_wait02 epoll_wait02
> epoll_wait03 epoll_wait03
> epoll_wait04 epoll_wait04
> +epoll_wait07 epoll_wait07
> 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 222955dd2..c0be9a88e 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_wait07
> diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait07.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait07.c
> new file mode 100644
> index 000000000..dfabd0d87
> --- /dev/null
> +++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait07.c
> @@ -0,0 +1,73 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Verify that EPOLLONESHOT is correctly handled by epoll_wait.
> + * We open a channel, write in it two times and verify that EPOLLIN has been
> + * received only once.
> + */
> +
> +#include <poll.h>
> +#include <sys/epoll.h>
> +#include "tst_test.h"
> +#include "tst_epoll.h"
> +
> +static int fds[2];
> +static int epfd;
> +
> +static void cleanup(void)
> +{
> + if (epfd > 0)
> + SAFE_CLOSE(epfd);
> +
> + if (fds[0] > 0)
> + SAFE_CLOSE(fds[0]);
> +
> + if (fds[1] > 0)
> + SAFE_CLOSE(fds[1]);
> +}
> +
> +static void run(void)
> +{
> + struct epoll_event evt_receive;
> + char buff = 'a';
> +
> + SAFE_PIPE(fds);
> +
> + tst_res(TINFO, "Polling on channel with EPOLLONESHOT");
> +
> + epfd = SAFE_EPOLL_CREATE1(0);
> +
> + SAFE_EPOLL_CTL(epfd, EPOLL_CTL_ADD, fds[0], &((struct epoll_event) {
> + .events = EPOLLIN | EPOLLONESHOT,
> + .data.fd = fds[0],
> + }));
> +
> + tst_res(TINFO, "Write channel for the 1st time. EPOLLIN expected");
> +
> + SAFE_WRITE(0, fds[1], &buff, 1);
> + TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 10, 0), 1);
> + TST_EXP_EQ_LI(evt_receive.events & EPOLLIN, EPOLLIN);
> + TST_EXP_EQ_LI(evt_receive.data.fd, fds[0]);
> +
> + SAFE_READ(1, fds[0], &buff, 1);
> + TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 10, 0), 0);
> +
> + tst_res(TINFO, "Write channel for the 2nd time. No events expected");
> +
> + SAFE_WRITE(0, fds[1], &buff, 1);
> + TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 10, 0), 0);
> +
> + SAFE_CLOSE(epfd);
> + SAFE_CLOSE(fds[0]);
> + SAFE_CLOSE(fds[1]);
> +}
> +
> +static struct tst_test test = {
> + .cleanup = cleanup,
> + .test_all = run,
> +};
> --
> 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:[~2023-09-06 8:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25 10:30 [LTP] [PATCH v4] Add epoll_wait07 test Andrea Cervesato
2023-09-06 8:46 ` Richard Palethorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox