test/helpers: add ring creation helpers
Particularly useful for SQPOLL, where we can choose to skip a test
if we don't have the necessary privileges to setup the ring.
Signed-off-by: Jens Axboe <[email protected]>
diff --git a/test/helpers.c b/test/helpers.c
index ea705fb..930d82a 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <sys/types.h>
#include "helpers.h"
#include "liburing.h"
@@ -83,3 +84,33 @@
}
return vecs;
}
+
+/*
+ * Helper for setting up an io_uring instance, skipping if the given user isn't
+ * allowed to.
+ */
+enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring,
+ struct io_uring_params *p)
+{
+ int ret;
+
+ ret = io_uring_queue_init_params(depth, ring, p);
+ if (!ret)
+ return T_SETUP_OK;
+ if ((p->flags & IORING_SETUP_SQPOLL) && ret == -EPERM && geteuid()) {
+ fprintf(stdout, "SQPOLL skipped for regular user\n");
+ return T_SETUP_SKIP;
+ }
+
+ fprintf(stderr, "queue_init: %s\n", strerror(-ret));
+ return ret;
+}
+
+enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
+ unsigned int flags)
+{
+ struct io_uring_params p = { };
+
+ p.flags = flags;
+ return t_create_ring_params(depth, ring, &p);
+}