[PATCH liburing 2/2] test: test fd msg-ring allocating indexes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



fd msg-ring requests supports IORING_FILE_INDEX_ALLOC, add a test for
that.

Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
---
 test/fd-pass.c | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/test/fd-pass.c b/test/fd-pass.c
index f3ede77..0c981fb 100644
--- a/test/fd-pass.c
+++ b/test/fd-pass.c
@@ -80,6 +80,14 @@ static int test(const char *filename, int source_fd, int target_fd)
 		fprintf(stderr, "register files failed %d\n", ret);
 		return T_EXIT_FAIL;
 	}
+	if (target_fd == IORING_FILE_INDEX_ALLOC) {
+		/* we want to test installing into a non-zero slot */
+		ret = io_uring_register_file_alloc_range(&dring, 1, 1);
+		if (ret) {
+			fprintf(stderr, "io_uring_register_file_alloc_range %d\n", ret);
+			return T_EXIT_FAIL;
+		}
+	}
 
 	/* open direct descriptor */
 	sqe = io_uring_get_sqe(&sring);
@@ -102,8 +110,14 @@ static int test(const char *filename, int source_fd, int target_fd)
 
 	/* send direct descriptor to destination ring */
 	sqe = io_uring_get_sqe(&sring);
-	io_uring_prep_msg_ring_fd(sqe, dring.ring_fd, source_fd, target_fd,
-					USER_DATA, 0);
+	if (target_fd == IORING_FILE_INDEX_ALLOC) {
+		io_uring_prep_msg_ring_fd_alloc(sqe, dring.ring_fd, source_fd,
+						USER_DATA, 0);
+	} else {
+
+		io_uring_prep_msg_ring_fd(sqe, dring.ring_fd, source_fd,
+					  target_fd, USER_DATA, 0);
+	}
 	io_uring_submit(&sring);
 
 	ret = io_uring_wait_cqe(&sring, &cqe);
@@ -111,7 +125,7 @@ static int test(const char *filename, int source_fd, int target_fd)
 		fprintf(stderr, "wait cqe failed %d\n", ret);
 		return T_EXIT_FAIL;
 	}
-	if (cqe->res) {
+	if (cqe->res < 0) {
 		if (cqe->res == -EINVAL && !no_fd_pass) {
 			no_fd_pass = 1;
 			return T_EXIT_SKIP;
@@ -131,6 +145,17 @@ static int test(const char *filename, int source_fd, int target_fd)
 		fprintf(stderr, "bad user_data %ld\n", (long) cqe->res);
 		return T_EXIT_FAIL;
 	}
+	if (cqe->res < 0) {
+		fprintf(stderr, "bad result %i\n", cqe->res);
+		return T_EXIT_FAIL;
+	}
+	if (target_fd == IORING_FILE_INDEX_ALLOC) {
+		if (cqe->res != 1) {
+			fprintf(stderr, "invalid allocated index %i\n", cqe->res);
+			return T_EXIT_FAIL;
+		}
+		target_fd = cqe->res;
+	}
 	io_uring_cqe_seen(&dring, cqe);
 
 	/* now verify we can read the sane data from the destination ring */
@@ -201,6 +226,12 @@ int main(int argc, char *argv[])
 		ret = T_EXIT_FAIL;
 	}
 
+	ret = test(fname, 1, IORING_FILE_INDEX_ALLOC);
+	if (ret == T_EXIT_FAIL) {
+		fprintf(stderr, "test failed 1 ALLOC\n");
+		ret = T_EXIT_FAIL;
+	}
+
 	unlink(fname);
 	return ret;
 }
-- 
2.39.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux