From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH liburing 6/8] tests: add region testing
Date: Fri, 15 Nov 2024 21:33:53 +0000 [thread overview]
Message-ID: <806601a1247373694c6336f229c9b7ca168fca65.1731705935.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 137 insertions(+)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 5f5a62a..13f6d51 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -178,6 +178,134 @@ err:
return ret;
}
+static int test_try_register_region(struct io_uring_mem_region_reg *pr,
+ bool disabled, bool reenable)
+{
+ struct io_uring ring;
+ int flags = 0;
+ int ret;
+
+ if (disabled)
+ flags = IORING_SETUP_R_DISABLED;
+
+ ret = io_uring_queue_init(8, &ring, flags);
+ if (ret) {
+ fprintf(stderr, "ring setup failed: %d\n", ret);
+ return 1;
+ }
+
+ if (reenable) {
+ ret = io_uring_enable_rings(&ring);
+ if (ret) {
+ fprintf(stderr, "io_uring_enable_rings failure %i\n", ret);
+ return 1;
+ }
+ }
+
+ ret = io_uring_register_region(&ring, pr);
+ io_uring_queue_exit(&ring);
+ return ret;
+}
+
+static int test_regions(void)
+{
+ struct io_uring_region_desc rd = {};
+ struct io_uring_mem_region_reg mr = {};
+ void *buffer;
+ int ret;
+
+ buffer = aligned_alloc(4096, 4096 * 4);
+ if (!buffer) {
+ fprintf(stderr, "allocation failed\n");
+ return T_EXIT_FAIL;
+ }
+
+ rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.size = 4096;
+ rd.flags = IORING_MEM_REGION_TYPE_USER;
+
+ mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
+
+ ret = test_try_register_region(&mr, true, false);
+ if (ret == -EINVAL)
+ return T_EXIT_SKIP;
+ if (ret) {
+ fprintf(stderr, "test_try_register_region(true, false) fail %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ ret = test_try_register_region(&mr, false, false);
+ if (ret != -EINVAL) {
+ fprintf(stderr, "test_try_register_region(false, false) fail %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ ret = test_try_register_region(&mr, true, true);
+ if (ret != -EINVAL) {
+ fprintf(stderr, "test_try_register_region(true, true) fail %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ rd.size = 4096 * 4;
+ ret = test_try_register_region(&mr, true, false);
+ if (ret) {
+ fprintf(stderr, "test_try_register_region() 16KB fail %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+ rd.size = 4096;
+
+ rd.user_addr = 0;
+ ret = test_try_register_region(&mr, true, false);
+ if (ret != -EFAULT) {
+ fprintf(stderr, "test_try_register_region() null uptr fail %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+ rd.user_addr = (__u64)(unsigned long)buffer;
+
+ rd.flags = 0;
+ ret = test_try_register_region(&mr, true, false);
+ if (!ret) {
+ fprintf(stderr, "test_try_register_region() kernel alloc with uptr fail %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+ rd.flags = IORING_MEM_REGION_TYPE_USER;
+
+ rd.size = 0;
+ ret = test_try_register_region(&mr, true, false);
+ if (!ret) {
+ fprintf(stderr, "test_try_register_region() 0-size fail %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+ rd.size = 4096;
+
+ mr.region_uptr = 0;
+ ret = test_try_register_region(&mr, true, false);
+ if (!ret) {
+ fprintf(stderr, "test_try_register_region() NULL region %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+ mr.region_uptr = (__u64)(unsigned long)&rd;
+
+ rd.user_addr += 16;
+ ret = test_try_register_region(&mr, true, false);
+ if (!ret) {
+ fprintf(stderr, "test_try_register_region() misaligned region %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ rd.user_addr = 0x1000;
+ ret = test_try_register_region(&mr, true, false);
+ if (!ret) {
+ fprintf(stderr, "test_try_register_region() bogus uptr %i\n", ret);
+ return T_EXIT_FAIL;
+ }
+ rd.user_addr = (__u64)(unsigned long)buffer;
+
+ free(buffer);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret;
@@ -191,6 +319,15 @@ int main(int argc, char *argv[])
return 1;
}
+ ret = test_regions();
+ if (ret == T_EXIT_SKIP) {
+ printf("regions are not supported, skip\n");
+ return 0;
+ } else if (ret) {
+ fprintf(stderr, "test_region failed\n");
+ return 1;
+ }
+
ret = test_wait_arg();
if (ret == T_EXIT_FAIL) {
fprintf(stderr, "test_wait_arg failed\n");
--
2.46.0
next prev parent reply other threads:[~2024-11-15 21:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 21:33 [PATCH liburing 0/8] update reg-wait to use region API Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 1/8] queue: break reg wait setup Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 2/8] Update io_uring.h Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 3/8] queue: add region helpers and fix up wait reg kernel api Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 4/8] examples: convert reg-wait to new api Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 5/8] tests: convert reg-wait to regions Pavel Begunkov
2024-11-15 21:33 ` Pavel Begunkov [this message]
2024-11-15 21:33 ` [PATCH liburing 7/8] tests: test arbitrary offset reg waits Pavel Begunkov
2024-11-15 21:33 ` [PATCH liburing 8/8] Remove leftovers of old reg-wait registration api Pavel Begunkov
2024-11-16 17:07 ` [PATCH liburing 0/8] update reg-wait to use region API Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=806601a1247373694c6336f229c9b7ca168fca65.1731705935.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox