From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 3/3] tests: check for missing multipoll events
Date: Wed, 23 Nov 2022 11:35:10 +0000 [thread overview]
Message-ID: <4b0f4d96027b69d9b0f8392887dc973c5afffe31.1669079092.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/poll.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/test/poll.c b/test/poll.c
index f0c1c40..a7db7dc 100644
--- a/test/poll.c
+++ b/test/poll.c
@@ -11,10 +11,17 @@
#include <signal.h>
#include <poll.h>
#include <sys/wait.h>
+#include <error.h>
#include "helpers.h"
#include "liburing.h"
+static void do_setsockopt(int fd, int level, int optname, int val)
+{
+ if (setsockopt(fd, level, optname, &val, sizeof(val)))
+ error(1, errno, "setsockopt %d.%d: %d", level, optname, val);
+}
+
static int test_basic(void)
{
struct io_uring_cqe *cqe;
@@ -94,6 +101,85 @@ static int test_basic(void)
return 0;
}
+static int test_missing_events(void)
+{
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ struct io_uring ring;
+ int i, ret, sp[2];
+ char buf[2] = {};
+ int res_mask = 0;
+
+ if (!t_probe_defer_taskrun())
+ return 0;
+
+ ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER |
+ IORING_SETUP_DEFER_TASKRUN);
+ if (ret) {
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return 1;
+ }
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) {
+ perror("Failed to create Unix-domain socket pair\n");
+ return 1;
+ }
+ do_setsockopt(sp[0], SOL_SOCKET, SO_SNDBUF, 1);
+ ret = send(sp[0], buf, sizeof(buf), 0);
+ if (ret != sizeof(buf)) {
+ perror("send failed\n");
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_poll_multishot(sqe, sp[0], POLLIN|POLLOUT);
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
+ return 1;
+ }
+
+ /* trigger EPOLLIN */
+ ret = send(sp[1], buf, sizeof(buf), 0);
+ if (ret != sizeof(buf)) {
+ fprintf(stderr, "send sp[1] failed %i %i\n", ret, errno);
+ return 1;
+ }
+
+ /* trigger EPOLLOUT */
+ ret = recv(sp[1], buf, sizeof(buf), 0);
+ if (ret != sizeof(buf)) {
+ perror("recv failed\n");
+ return 1;
+ }
+
+ for (i = 0; ; i++) {
+ if (i == 0)
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ else
+ ret = io_uring_peek_cqe(&ring, &cqe);
+
+ if (i != 0 && ret == -EAGAIN) {
+ break;
+ }
+ if (ret) {
+ fprintf(stderr, "wait completion %d, %i\n", ret, i);
+ return 1;
+ }
+ res_mask |= cqe->res;
+ io_uring_cqe_seen(&ring, cqe);
+ }
+
+ if ((res_mask & (POLLIN|POLLOUT)) != (POLLIN|POLLOUT)) {
+ fprintf(stderr, "missing poll events %i\n", res_mask);
+ return 1;
+ }
+ io_uring_queue_exit(&ring);
+ close(sp[0]);
+ close(sp[1]);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret;
@@ -106,5 +192,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "test_basic() failed %i\n", ret);
return T_EXIT_FAIL;
}
+
+ ret = test_missing_events();
+ if (ret) {
+ fprintf(stderr, "test_missing_events() failed %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
return 0;
}
--
2.38.1
next prev parent reply other threads:[~2022-11-23 11:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 11:35 [PATCH liburing 0/3] test poll missing events Pavel Begunkov
2022-11-23 11:35 ` [PATCH liburing 1/3] tests: remove sigalarm from poll.c Pavel Begunkov
2022-11-23 11:35 ` [PATCH liburing 2/3] tests: refactor poll.c Pavel Begunkov
2022-11-23 11:35 ` Pavel Begunkov [this message]
2022-11-23 17:51 ` [PATCH liburing 0/3] test poll missing events Jens Axboe
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=4b0f4d96027b69d9b0f8392887dc973c5afffe31.1669079092.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
/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