diff mbox series

[liburing] test/read-write: add test for CQE res when removing buffers

Message ID 20230401195259.404967-1-wlukowicz01@gmail.com (mailing list archive)
State New
Headers show
Series [liburing] test/read-write: add test for CQE res when removing buffers | expand

Commit Message

Wojciech Lukowicz April 1, 2023, 7:52 p.m. UTC
When removing provided buffers, CQE res should contain the number of
removed buffers. However, in certain kernel versions, if SQE requests
removal of more buffers than available, then res will contain the number
of removed buffers + 1.

Signed-off-by: Wojciech Lukowicz <wlukowicz01@gmail.com>
---
This is a failing test, needs the patch I sent earlier.

 test/read-write.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

Comments

Jens Axboe April 1, 2023, 11:20 p.m. UTC | #1
On Sat, 01 Apr 2023 20:52:59 +0100, Wojciech Lukowicz wrote:
> When removing provided buffers, CQE res should contain the number of
> removed buffers. However, in certain kernel versions, if SQE requests
> removal of more buffers than available, then res will contain the number
> of removed buffers + 1.
> 
> 

Applied, thanks!

[1/1] test/read-write: add test for CQE res when removing buffers
      commit: ce9ef761e8d29399a079710a78cc84665466a754

Best regards,
diff mbox series

Patch

diff --git a/test/read-write.c b/test/read-write.c
index 3764f6aef47e..6f24ec919de3 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -637,6 +637,53 @@  static int test_rem_buf(int batch, int sqe_flags)
 	return ret;
 }
 
+static int test_rem_buf_single(int to_rem)
+{
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+	struct io_uring ring;
+	int ret, expected;
+	int bgid = 1;
+
+	if (no_buf_select)
+		return 0;
+
+	ret = io_uring_queue_init(64, &ring, 0);
+	if (ret) {
+		fprintf(stderr, "ring create failed: %d\n", ret);
+		return 1;
+	}
+
+	ret = provide_buffers_iovec(&ring, bgid);
+	if (ret)
+		return ret;
+
+	expected = (to_rem > BUFFERS) ? BUFFERS : to_rem;
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_remove_buffers(sqe, to_rem, bgid);
+
+	ret = io_uring_submit(&ring);
+	if (ret != 1) {
+		fprintf(stderr, "submit: %d\n", ret);
+		return -1;
+	}
+
+	ret = io_uring_wait_cqe(&ring, &cqe);
+	if (ret) {
+		fprintf(stderr, "wait_cqe=%d\n", ret);
+		return 1;
+	}
+	if (cqe->res != expected) {
+		fprintf(stderr, "cqe->res=%d, expected=%d\n", cqe->res, expected);
+		return 1;
+	}
+	io_uring_cqe_seen(&ring, cqe);
+
+	io_uring_queue_exit(&ring);
+	return ret;
+}
+
 static int test_io_link(const char *file)
 {
 	const int nr_links = 100;
@@ -950,6 +997,12 @@  int main(int argc, char *argv[])
 		}
 	}
 
+	ret = test_rem_buf_single(BUFFERS + 1);
+	if (ret) {
+		fprintf(stderr, "test_rem_buf_single(BUFFERS + 1) failed\n");
+		goto err;
+	}
+
 	if (fname != argv[1])
 		unlink(fname);
 	return 0;