Skip to contentSkip to conversation

use nop CQE32 tests to test some assumptions

PATCH Applied Pavel Begunkov 2 participants 5 messages Jun 17, 2022 io_uring

lore
Share & tools
lore
#0 lore raw

cover use nop CQE32 tests to test some assumptions

Pavel Begunkov (2):
Revert "test/nop: kill cqe32 test code"
tests: fix and improve nop tests

 test/nop.c | 54 +++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 13 deletions(-)
Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/2 Revert "test/nop: kill cqe32 test code"

This reverts commit e5d017ab9cd9605248db68168ae5451f830e646c.

---
 test/nop.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
test/nop.c +31 -0
index 01e41a6..ce223b3 100644
@@ -20,6 +20,7 @@ static int test_single_nop(struct io_uring *ring)
 	struct io_uring_cqe *cqe;
 	struct io_uring_sqe *sqe;
 	int ret;
+	bool cqe32 = (ring->flags & IORING_SETUP_CQE32);
 
 	sqe = io_uring_get_sqe(ring);
 	if (!sqe) {
@@ -28,6 +29,10 @@ static int test_single_nop(struct io_uring *ring)
 	}
 
 	io_uring_prep_nop(sqe);
+	if (cqe32) {
+		sqe->addr = 1234;
+		sqe->addr2 = 5678;
+	}
 	sqe->user_data = ++seq;
 
 	ret = io_uring_submit(ring);
@@ -45,6 +50,17 @@ static int test_single_nop(struct io_uring *ring)
 		fprintf(stderr, "Unexpected 0 user_data\n");
 		goto err;
 	}
+	if (cqe32) {
+		if (cqe->big_cqe[0] != 1234) {
+			fprintf(stderr, "Unexpected extra1\n");
+			goto err;
+
+		}
+		if (cqe->big_cqe[1] != 5678) {
+			fprintf(stderr, "Unexpected extra2\n");
+			goto err;
+		}
+	}
 	io_uring_cqe_seen(ring, cqe);
 	return 0;
 err:
@@ -56,6 +72,7 @@ static int test_barrier_nop(struct io_uring *ring)
 	struct io_uring_cqe *cqe;
 	struct io_uring_sqe *sqe;
 	int ret, i;
+	bool cqe32 = (ring->flags & IORING_SETUP_CQE32);
 
 	for (i = 0; i < 8; i++) {
 		sqe = io_uring_get_sqe(ring);
@@ -67,6 +84,10 @@ static int test_barrier_nop(struct io_uring *ring)
 		io_uring_prep_nop(sqe);
 		if (i == 4)
 			sqe->flags = IOSQE_IO_DRAIN;
+		if (cqe32) {
+			sqe->addr = 1234;
+			sqe->addr2 = 5678;
+		}
 		sqe->user_data = ++seq;
 	}
 
@@ -89,6 +110,16 @@ static int test_barrier_nop(struct io_uring *ring)
 			fprintf(stderr, "Unexpected 0 user_data\n");
 			goto err;
 		}
+		if (cqe32) {
+			if (cqe->big_cqe[0] != 1234) {
+				fprintf(stderr, "Unexpected extra1\n");
+				goto err;
+			}
+			if (cqe->big_cqe[1] != 5678) {
+				fprintf(stderr, "Unexpected extra2\n");
+				goto err;
+			}
+		}
 		io_uring_cqe_seen(ring, cqe);
 	}
 
Signature · 1 line
2.36.1
#2 lore raw

PATCH 2/2 tests: fix and improve nop tests

In reply to Pavel Begunkov

We removed CQE32 for nops from the kernel, fix the tests and instead test that we return zeroes in the extra fields instead of garbage. Loop over the tests multiple times so it exhausts CQ and we also test CQ entries recycling and internal caching mechanism. Also excersie IOSQE_ASYNC.

---
 test/nop.c | 47 ++++++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 25 deletions(-)
test/nop.c +22 -25
index ce223b3..1aa88fc 100644
@@ -15,7 +15,7 @@
 
 static int seq;
 
-static int test_single_nop(struct io_uring *ring)
+static int test_single_nop(struct io_uring *ring, unsigned req_flags)
 {
 	struct io_uring_cqe *cqe;
 	struct io_uring_sqe *sqe;
@@ -29,11 +29,8 @@ static int test_single_nop(struct io_uring *ring)
 	}
 
 	io_uring_prep_nop(sqe);
-	if (cqe32) {
-		sqe->addr = 1234;
-		sqe->addr2 = 5678;
-	}
 	sqe->user_data = ++seq;
+	sqe->flags |= req_flags;
 
 	ret = io_uring_submit(ring);
 	if (ret <= 0) {
@@ -51,12 +48,12 @@ static int test_single_nop(struct io_uring *ring)
 		goto err;
 	}
 	if (cqe32) {
-		if (cqe->big_cqe[0] != 1234) {
+		if (cqe->big_cqe[0] != 0) {
 			fprintf(stderr, "Unexpected extra1\n");
 			goto err;
 
 		}
-		if (cqe->big_cqe[1] != 5678) {
+		if (cqe->big_cqe[1] != 0) {
 			fprintf(stderr, "Unexpected extra2\n");
 			goto err;
 		}
@@ -67,7 +64,7 @@ err:
 	return 1;
 }
 
-static int test_barrier_nop(struct io_uring *ring)
+static int test_barrier_nop(struct io_uring *ring, unsigned req_flags)
 {
 	struct io_uring_cqe *cqe;
 	struct io_uring_sqe *sqe;
@@ -84,11 +81,8 @@ static int test_barrier_nop(struct io_uring *ring)
 		io_uring_prep_nop(sqe);
 		if (i == 4)
 			sqe->flags = IOSQE_IO_DRAIN;
-		if (cqe32) {
-			sqe->addr = 1234;
-			sqe->addr2 = 5678;
-		}
 		sqe->user_data = ++seq;
+		sqe->flags |= req_flags;
 	}
 
 	ret = io_uring_submit(ring);
@@ -111,11 +105,11 @@ static int test_barrier_nop(struct io_uring *ring)
 			goto err;
 		}
 		if (cqe32) {
-			if (cqe->big_cqe[0] != 1234) {
+			if (cqe->big_cqe[0] != 0) {
 				fprintf(stderr, "Unexpected extra1\n");
 				goto err;
 			}
-			if (cqe->big_cqe[1] != 5678) {
+			if (cqe->big_cqe[1] != 0) {
 				fprintf(stderr, "Unexpected extra2\n");
 				goto err;
 			}
@@ -132,7 +126,7 @@ static int test_ring(unsigned flags)
 {
 	struct io_uring ring;
 	struct io_uring_params p = { };
-	int ret;
+	int ret, i;
 
 	p.flags = flags;
 	ret = io_uring_queue_init_params(8, &ring, &p);
@@ -143,18 +137,21 @@ static int test_ring(unsigned flags)
 		return 1;
 	}
 
-	ret = test_single_nop(&ring);
-	if (ret) {
-		fprintf(stderr, "test_single_nop failed\n");
-		goto err;
-	}
+	for (i = 0; i < 1000; i++) {
+		unsigned req_flags = (i & 1) ? IOSQE_ASYNC : 0;
 
-	ret = test_barrier_nop(&ring);
-	if (ret) {
-		fprintf(stderr, "test_barrier_nop failed\n");
-		goto err;
-	}
+		ret = test_single_nop(&ring, req_flags);
+		if (ret) {
+			fprintf(stderr, "test_single_nop failed\n");
+			goto err;
+		}
 
+		ret = test_barrier_nop(&ring, req_flags);
+		if (ret) {
+			fprintf(stderr, "test_barrier_nop failed\n");
+			goto err;
+		}
+	}
 err:
 	io_uring_queue_exit(&ring);
 	return ret;
Signature · 1 line
2.36.1
maintainer
#3 lore raw

Re: [PATCH liburing 2/2] tests: fix and improve nop tests

Quoted 5 lines · Pavel Begunkov

We removed CQE32 for nops from the kernel, fix the tests and instead test that we return zeroes in the extra fields instead of garbage. Loop over the tests multiple times so it exhausts CQ and we also test CQ entries recycling and internal caching mechanism. Also excersie IOSQE_ASYNC.

Yes that's not a bad idea, thanks!

Signature · 1 line
Jens Axboe
maintainer Applied
#4 lore raw
In reply to Pavel Begunkov
Quoted 8 lines · Pavel Begunkov

Pavel Begunkov (2):
Revert "test/nop: kill cqe32 test code"
tests: fix and improve nop tests

test/nop.c | 54 +++++++++++++++++++++++++++++++++++++++++-------------

 1 file changed, 41 insertions(+), 13 deletions(-)

[...]

Applied, thanks!

[1/2] Revert "test/nop: kill cqe32 test code"

      commit: 203abdf5f0bf78a58d59f3f4a4e8561cb76b10f4
[2/2] tests: fix and improve nop tests
      commit: 540ca1c11016ed50940e3f6f555a986356578646

Best regards,

Signature · 1 line
Jens Axboe