* [PATCH liburing 0/2] tests for deferred multishot completions
@ 2022-11-24 10:30 Dylan Yudaken
2022-11-24 10:30 ` [PATCH liburing 1/2] Add a test for errors in multishot recv Dylan Yudaken
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dylan Yudaken @ 2022-11-24 10:30 UTC (permalink / raw)
To: Jens Axboe, Pavel Begunkov; +Cc: io-uring, Dylan Yudaken
Hi,
This adds a couple of tests that expose some trickier corner cases for
multishot APIS, specifically in light of the latest series to batch &
defer multishot completion.
Dylan Yudaken (2):
Add a test for errors in multishot recv
add a test for multishot downgrading
test/poll-mshot-overflow.c | 105 ++++++++++++++++++++++++++++++++++++-
test/recv-multishot.c | 85 ++++++++++++++++++++++++++++++
2 files changed, 188 insertions(+), 2 deletions(-)
base-commit: b90a28636e5b5efe6dc1383acc90aec61814d9ba
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH liburing 1/2] Add a test for errors in multishot recv
2022-11-24 10:30 [PATCH liburing 0/2] tests for deferred multishot completions Dylan Yudaken
@ 2022-11-24 10:30 ` Dylan Yudaken
2022-11-24 10:30 ` [PATCH liburing 2/2] add a test for multishot downgrading Dylan Yudaken
2022-11-24 13:25 ` [PATCH liburing 0/2] tests for deferred multishot completions Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Dylan Yudaken @ 2022-11-24 10:30 UTC (permalink / raw)
To: Jens Axboe, Pavel Begunkov; +Cc: io-uring, Dylan Yudaken
In a later kernel release there will be deferred completions of multishot
ops. Add a test to ensure ordering is preserved when there is an error
during the multishot operation.
Signed-off-by: Dylan Yudaken <[email protected]>
---
test/recv-multishot.c | 85 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/test/recv-multishot.c b/test/recv-multishot.c
index ed26a5f78759..08a2e8629f5b 100644
--- a/test/recv-multishot.c
+++ b/test/recv-multishot.c
@@ -9,6 +9,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
+#include <assert.h>
#include "liburing.h"
#include "helpers.h"
@@ -469,6 +470,84 @@ cleanup:
return ret;
}
+static int test_enobuf(void)
+{
+ struct io_uring ring;
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqes[16];
+ char buffs[256];
+ int ret, i, fds[2];
+
+ if (t_create_ring(8, &ring, 0) != T_SETUP_OK) {
+ fprintf(stderr, "ring create\n");
+ return -1;
+ }
+
+ ret = t_create_socket_pair(fds, false);
+ if (ret) {
+ fprintf(stderr, "t_create_socket_pair\n");
+ return ret;
+ }
+
+ sqe = io_uring_get_sqe(&ring);
+ assert(sqe);
+ /* deliberately only 2 provided buffers */
+ io_uring_prep_provide_buffers(sqe, &buffs[0], 1, 2, 0, 0);
+ io_uring_sqe_set_data64(sqe, 0);
+
+ sqe = io_uring_get_sqe(&ring);
+ assert(sqe);
+ io_uring_prep_recv_multishot(sqe, fds[0], NULL, 0, 0);
+ io_uring_sqe_set_data64(sqe, 1);
+ sqe->buf_group = 0;
+ sqe->flags |= IOSQE_BUFFER_SELECT;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 2) {
+ fprintf(stderr, "bad submit %d\n", ret);
+ return -1;
+ }
+ for (i = 0; i < 3; i++) {
+ do {
+ ret = write(fds[1], "?", 1);
+ } while (ret == -1 && errno == EINTR);
+ }
+
+ ret = io_uring_wait_cqes(&ring, &cqes[0], 4, NULL, NULL);
+ if (ret) {
+ fprintf(stderr, "wait cqes\n");
+ return ret;
+ }
+
+ ret = io_uring_peek_batch_cqe(&ring, &cqes[0], 4);
+ if (ret != 4) {
+ fprintf(stderr, "peek batch cqes\n");
+ return -1;
+ }
+
+ /* provide buffers */
+ assert(cqes[0]->user_data == 0);
+ assert(cqes[0]->res == 0);
+
+ /* valid recv */
+ assert(cqes[1]->user_data == 1);
+ assert(cqes[2]->user_data == 1);
+ assert(cqes[1]->res == 1);
+ assert(cqes[2]->res == 1);
+ assert(cqes[1]->flags & (IORING_CQE_F_BUFFER | IORING_CQE_F_MORE));
+ assert(cqes[2]->flags & (IORING_CQE_F_BUFFER | IORING_CQE_F_MORE));
+
+ /* missing buffer */
+ assert(cqes[3]->user_data == 1);
+ assert(cqes[3]->res == -ENOBUFS);
+ assert(!(cqes[3]->flags & (IORING_CQE_F_BUFFER | IORING_CQE_F_MORE)));
+
+ close(fds[0]);
+ close(fds[1]);
+ io_uring_queue_exit(&ring);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret;
@@ -509,5 +588,11 @@ int main(int argc, char *argv[])
}
}
+ ret = test_enobuf();
+ if (ret) {
+ fprintf(stderr, "test_enobuf() failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
return T_EXIT_PASS;
}
base-commit: b90a28636e5b5efe6dc1383acc90aec61814d9ba
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH liburing 2/2] add a test for multishot downgrading
2022-11-24 10:30 [PATCH liburing 0/2] tests for deferred multishot completions Dylan Yudaken
2022-11-24 10:30 ` [PATCH liburing 1/2] Add a test for errors in multishot recv Dylan Yudaken
@ 2022-11-24 10:30 ` Dylan Yudaken
2022-11-24 13:25 ` [PATCH liburing 0/2] tests for deferred multishot completions Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Dylan Yudaken @ 2022-11-24 10:30 UTC (permalink / raw)
To: Jens Axboe, Pavel Begunkov; +Cc: io-uring, Dylan Yudaken
If the poll overflows we expect multishot poll to eventually downgrade to
single shot. Also the ordering of CQE's must be consistent, so check that.
Signed-off-by: Dylan Yudaken <[email protected]>
---
test/poll-mshot-overflow.c | 105 ++++++++++++++++++++++++++++++++++++-
1 file changed, 104 insertions(+), 1 deletion(-)
diff --git a/test/poll-mshot-overflow.c b/test/poll-mshot-overflow.c
index 431a337f19ae..0dc8ee5eb6f8 100644
--- a/test/poll-mshot-overflow.c
+++ b/test/poll-mshot-overflow.c
@@ -137,20 +137,123 @@ static int test(bool defer_taskrun)
return ret;
}
+static int test_downgrade(bool support_defer)
+{
+ struct io_uring_cqe cqes[128];
+ struct io_uring_cqe *cqe;
+ struct io_uring_sqe *sqe;
+ struct io_uring ring;
+ int fds[2];
+ int ret, i, cqe_count, tmp = 0, more_cqe_count;
+
+ if (pipe(fds) != 0) {
+ perror("pipe");
+ return -1;
+ }
+
+ struct io_uring_params params = {
+ .flags = IORING_SETUP_CQSIZE,
+ .cq_entries = 2
+ };
+
+ ret = io_uring_queue_init_params(2, &ring, ¶ms);
+ if (ret) {
+ fprintf(stderr, "queue init: %d\n", ret);
+ return -1;
+ }
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "get sqe failed\n");
+ return -1;
+ }
+ io_uring_prep_poll_multishot(sqe, fds[0], POLLIN);
+ io_uring_sqe_set_data64(sqe, 1);
+ io_uring_submit(&ring);
+
+ for (i = 0; i < 8; i++) {
+ ret = write(fds[1], &tmp, sizeof(tmp));
+ if (ret != sizeof(tmp)) {
+ perror("write");
+ return -1;
+ }
+ ret = read(fds[0], &tmp, sizeof(tmp));
+ if (ret != sizeof(tmp)) {
+ perror("read");
+ return -1;
+ }
+ }
+
+ cqe_count = 0;
+ while (!io_uring_peek_cqe(&ring, &cqe)) {
+ cqes[cqe_count++] = *cqe;
+ io_uring_cqe_seen(&ring, cqe);
+ }
+
+ /* Some kernels might allow overflows to poll,
+ * but if they didn't it should stop the MORE flag
+ */
+ if (cqe_count < 3) {
+ fprintf(stderr, "too few cqes: %d\n", cqe_count);
+ return -1;
+ } else if (cqe_count == 8) {
+ more_cqe_count = cqe_count;
+ /* downgrade only available since support_defer */
+ if (support_defer) {
+ fprintf(stderr, "did not downgrade on overflow\n");
+ return -1;
+ }
+ } else {
+ more_cqe_count = cqe_count - 1;
+ cqe = &cqes[cqe_count - 1];
+ if (cqe->flags & IORING_CQE_F_MORE) {
+ fprintf(stderr, "incorrect MORE flag %x\n", cqe->flags);
+ return -1;
+ }
+ }
+
+ for (i = 0; i < more_cqe_count; i++) {
+ cqe = &cqes[i];
+ if (!(cqe->flags & IORING_CQE_F_MORE)) {
+ fprintf(stderr, "missing MORE flag\n");
+ return -1;
+ }
+ if (cqe->res < 0) {
+ fprintf(stderr, "bad res: %d\n", cqe->res);
+ return -1;
+ }
+ }
+
+ close(fds[0]);
+ close(fds[1]);
+ io_uring_queue_exit(&ring);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret;
+ bool support_defer;
if (argc > 1)
return T_EXIT_SKIP;
+ support_defer = t_probe_defer_taskrun();
+ ret = test_downgrade(support_defer);
+ if (ret) {
+ fprintf(stderr, "%s: test_downgrade(%d) failed\n", argv[0], support_defer);
+ return T_EXIT_FAIL;
+ }
+
ret = test(false);
+ if (ret == T_EXIT_SKIP)
+ return ret;
if (ret != T_EXIT_PASS) {
fprintf(stderr, "%s: test(false) failed\n", argv[0]);
return ret;
}
- if (t_probe_defer_taskrun()) {
+ if (support_defer) {
ret = test(true);
if (ret != T_EXIT_PASS) {
fprintf(stderr, "%s: test(true) failed\n", argv[0]);
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH liburing 0/2] tests for deferred multishot completions
2022-11-24 10:30 [PATCH liburing 0/2] tests for deferred multishot completions Dylan Yudaken
2022-11-24 10:30 ` [PATCH liburing 1/2] Add a test for errors in multishot recv Dylan Yudaken
2022-11-24 10:30 ` [PATCH liburing 2/2] add a test for multishot downgrading Dylan Yudaken
@ 2022-11-24 13:25 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2022-11-24 13:25 UTC (permalink / raw)
To: Dylan Yudaken, Pavel Begunkov; +Cc: io-uring
On Thu, 24 Nov 2022 02:30:40 -0800, Dylan Yudaken wrote:
> This adds a couple of tests that expose some trickier corner cases for
> multishot APIS, specifically in light of the latest series to batch &
> defer multishot completion.
>
>
> Dylan Yudaken (2):
> Add a test for errors in multishot recv
> add a test for multishot downgrading
>
> [...]
Applied, thanks!
[1/2] Add a test for errors in multishot recv
(no commit info)
[2/2] add a test for multishot downgrading
(no commit info)
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-24 13:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-24 10:30 [PATCH liburing 0/2] tests for deferred multishot completions Dylan Yudaken
2022-11-24 10:30 ` [PATCH liburing 1/2] Add a test for errors in multishot recv Dylan Yudaken
2022-11-24 10:30 ` [PATCH liburing 2/2] add a test for multishot downgrading Dylan Yudaken
2022-11-24 13:25 ` [PATCH liburing 0/2] tests for deferred multishot completions Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox