Skip to contentSkip to conversation

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

PATCH Applied Wojciech Lukowicz 2 participants 2 messages Apr 1, 2023 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test/read-write: add test for CQE res when removing buffers

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.

---
This is a failing test, needs the patch I sent earlier.

 test/read-write.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
test/read-write.c +53 -0
index 3764f6aef47e..6f24ec919de3 100644
@@ -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;
Signature · 1 line
2.30.2
maintainer Applied
#1 lore raw
Quoted 6 lines · Wojciech Lukowicz

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,

Signature · 1 line
Jens Axboe