From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH liburing 5/8] tests: convert reg-wait to regions
Date: Fri, 15 Nov 2024 21:33:52 +0000 [thread overview]
Message-ID: <c58770f162232e03ed7a7d5dd34aad371dcf7a5c.1731705935.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/reg-wait.c | 217 ++++++++++++++++++------------------------------
1 file changed, 83 insertions(+), 134 deletions(-)
diff --git a/test/reg-wait.c b/test/reg-wait.c
index 6a5123a..5f5a62a 100644
--- a/test/reg-wait.c
+++ b/test/reg-wait.c
@@ -14,123 +14,9 @@
#include "helpers.h"
#include "test.h"
+static int page_size;
static struct io_uring_reg_wait *reg;
-static int test_invalid_reg2(void)
-{
- struct io_uring ring;
- void *buf, *ptr;
- int ret;
-
- io_uring_queue_init(1, &ring, 0);
-
- if (posix_memalign(&buf, 4096, 4096))
- return T_EXIT_FAIL;
- memset(buf, 0, 4096);
- ptr = buf + 4096 - 32;
-
- ret = io_uring_register_wait_reg(&ring, ptr, 1);
- if (ret != -EINVAL) {
- fprintf(stderr, "register cqwait: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- ptr = buf + (sizeof(struct io_uring_reg_wait) / 2);
- ret = io_uring_register_wait_reg(&ring, ptr, 1);
- if (ret != -EINVAL) {
- fprintf(stderr, "register cqwait: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- free(buf);
- buf = (void *) 0x1000;
- ret = io_uring_register_wait_reg(&ring, buf, 1);
- if (ret != -EFAULT) {
- fprintf(stderr, "register cqwait: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- buf = (void *) 0x1240;
- ret = io_uring_register_wait_reg(&ring, buf, 1);
- if (ret != -EFAULT) {
- fprintf(stderr, "register cqwait: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- buf = (void *) 0x1241;
- ret = io_uring_register_wait_reg(&ring, buf, 1);
- if (ret != -EINVAL) {
- fprintf(stderr, "register cqwait: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- io_uring_queue_exit(&ring);
- return T_EXIT_PASS;
-}
-
-static int test_invalid_reg(void)
-{
- struct io_uring_reg_wait *ireg;
- struct io_uring_cqe *cqe;
- struct io_uring ring;
- struct timeval tv;
- void *buf, *ptr;
- int ret;
-
- io_uring_queue_init(1, &ring, 0);
-
- if (posix_memalign(&buf, 4096, 4096))
- return T_EXIT_FAIL;
- memset(buf, 0, 4096);
- ptr = buf + 512;
- ireg = ptr;
-
- ret = io_uring_register_wait_reg(&ring, ireg, 56);
- if (ret) {
- fprintf(stderr, "register cqwait: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- ireg = ptr;
- memset(ireg, 0, sizeof(*ireg));
- ireg->ts.tv_sec = 1;
- ireg->ts.tv_nsec = 0;
- ireg->flags = IORING_REG_WAIT_TS;
-
- gettimeofday(&tv, NULL);
- ret = io_uring_submit_and_wait_reg(&ring, &cqe, 1, 0);
- if (ret != -ETIME) {
- fprintf(stderr, "wait_reg failed: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- ret = mtime_since_now(&tv);
- /* allow some slack, should be around 1.1s */
- if (ret < 1000 || ret > 1200) {
- fprintf(stderr, "wait too long or short: %d\n", ret);
- goto err;
- }
-
- memset(ireg, 0, sizeof(*ireg));
- ireg->ts.tv_sec = 1;
- ireg->ts.tv_nsec = 0;
- ireg->flags = IORING_REG_WAIT_TS;
-
- gettimeofday(&tv, NULL);
- ret = io_uring_submit_and_wait_reg(&ring, &cqe, 1, 56);
- if (ret != -EFAULT) {
- fprintf(stderr, "out-of-range reg_wait failed: %d\n", ret);
- return T_EXIT_FAIL;
- }
-
- free(buf);
- io_uring_queue_exit(&ring);
- return T_EXIT_PASS;
-err:
- io_uring_queue_exit(&ring);
- return T_EXIT_FAIL;
-}
-
static int test_invalid_sig(struct io_uring *ring)
{
struct io_uring_cqe *cqe;
@@ -164,6 +50,39 @@ static int test_invalid_sig(struct io_uring *ring)
return T_EXIT_PASS;
}
+static int test_offsets(struct io_uring *ring)
+{
+ struct io_uring_cqe *cqe;
+ int max_index = page_size / sizeof(struct io_uring_reg_wait);
+ struct io_uring_reg_wait *rw;
+ int ret;
+
+ rw = reg + max_index;
+ memset(rw, 0, sizeof(*rw));
+ rw->ts.tv_sec = 0;
+ rw->ts.tv_nsec = 1000;
+
+ ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, 0);
+ if (ret != -EFAULT) {
+ fprintf(stderr, "max+1 index failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ rw = reg + max_index - 1;
+ memset(rw, 0, sizeof(*rw));
+ rw->flags = IORING_REG_WAIT_TS;
+ rw->ts.tv_sec = 0;
+ rw->ts.tv_nsec = 1000;
+
+ ret = io_uring_submit_and_wait_reg(ring, &cqe, 1, max_index - 1);
+ if (ret != -ETIME) {
+ fprintf(stderr, "last index failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ return 0;
+}
+
static int test_basic(struct io_uring *ring)
{
struct io_uring_cqe *cqe;
@@ -192,27 +111,50 @@ err:
return T_EXIT_FAIL;
}
-static int test_ring(void)
+static int test_wait_arg(void)
{
+ struct io_uring_region_desc rd = {};
+ struct io_uring_mem_region_reg mr = {};
struct io_uring ring;
- struct io_uring_params p = { };
+ void *buffer;
int ret;
- p.flags = 0;
- ret = io_uring_queue_init_params(8, &ring, &p);
+ ret = io_uring_queue_init(8, &ring, IORING_SETUP_R_DISABLED);
if (ret) {
+ if (ret == -EINVAL) {
+ printf("IORING_SETUP_R_DISABLED not supported, skip\n");
+ return 0;
+ }
fprintf(stderr, "ring setup failed: %d\n", ret);
+ return T_EXIT_FAIL;
+ }
+
+ buffer = aligned_alloc(page_size, page_size * 4);
+ if (!buffer) {
+ fprintf(stderr, "allocation failed\n");
+ return T_EXIT_FAIL;
+ }
+
+ rd.user_addr = (__u64)(unsigned long)buffer;
+ rd.size = page_size;
+ rd.flags = IORING_MEM_REGION_TYPE_USER;
+ mr.region_uptr = (__u64)(unsigned long)&rd;
+ mr.flags = IORING_MEM_REGION_REG_WAIT_ARG;
+
+ ret = io_uring_register_region(&ring, &mr);
+ if (ret) {
+ fprintf(stderr, "region reg failed %i\n", ret);
return 1;
}
- reg = io_uring_setup_reg_wait(&ring, 64, &ret);
- if (!reg) {
- if (ret == -EINVAL)
- return T_EXIT_SKIP;
- fprintf(stderr, "setup_reg_wait: %d\n", ret);
+ ret = io_uring_enable_rings(&ring);
+ if (ret) {
+ fprintf(stderr, "io_uring_enable_rings failure %i\n", ret);
return T_EXIT_FAIL;
}
+ reg = buffer;
+
ret = test_basic(&ring);
if (ret == T_EXIT_FAIL) {
fprintf(stderr, "test failed\n");
@@ -225,27 +167,34 @@ static int test_ring(void)
goto err;
}
- ret = test_invalid_reg();
+ ret = test_offsets(&ring);
if (ret == T_EXIT_FAIL) {
- fprintf(stderr, "test_invalid_reg failed\n");
+ fprintf(stderr, "test_offsets failed\n");
goto err;
}
-
- ret = test_invalid_reg2();
- if (ret == T_EXIT_FAIL) {
- fprintf(stderr, "test_invalid_reg2 failed\n");
- goto err;
- }
-
err:
+ free(buffer);
io_uring_queue_exit(&ring);
return ret;
}
int main(int argc, char *argv[])
{
+ int ret;
+
if (argc > 1)
return 0;
- return test_ring();
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) {
+ perror("sysconf(_SC_PAGESIZE)");
+ return 1;
+ }
+
+ ret = test_wait_arg();
+ if (ret == T_EXIT_FAIL) {
+ fprintf(stderr, "test_wait_arg failed\n");
+ return 1;
+ }
+ return 0;
}
--
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 ` Pavel Begunkov [this message]
2024-11-15 21:33 ` [PATCH liburing 6/8] tests: add region testing Pavel Begunkov
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=c58770f162232e03ed7a7d5dd34aad371dcf7a5c.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