summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-02-24 07:31:45 -0700
committerJens Axboe <axboe@kernel.dk>2021-02-24 07:48:01 -0700
commit382bec7ea2bbcc366d04c02f37929ec5176926d7 (patch)
tree367d9136ba9fae1af6efd6698e779598dd9357ed
parentd84d90108a1de9caf7636adcc523d451a56dd275 (diff)
downloadliburing-382bec7ea2bbcc366d04c02f37929ec5176926d7.tar.gz
liburing-382bec7ea2bbcc366d04c02f37929ec5176926d7.tar.bz2
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 <axboe@kernel.dk>
-rw-r--r--test/Makefile6
-rw-r--r--test/helpers.c31
-rw-r--r--test/helpers.h16
3 files changed, 50 insertions, 3 deletions
diff --git a/test/Makefile b/test/Makefile
index 69de572..f02bbd1 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -137,13 +137,13 @@ helpers = helpers.o
all: ${helpers} $(test_targets)
helpers.o: helpers.c helpers.c
- $(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
+ $(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $< -luring
%: %.c ${helpers} helpers.h
- $(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< -luring $(XCFLAGS) ${helpers}
+ $(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< ${helpers} -luring $(XCFLAGS)
%: %.cc ${helpers} helpers.h
- $(QUIET_CXX)$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< -luring $(XCFLAGS) ${helpers}
+ $(QUIET_CXX)$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< ${helpers} -luring $(XCFLAGS)
test_srcs := \
helpers.c \
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 @@ struct iovec *t_create_buffers(size_t buf_num, size_t buf_size)
}
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);
+}
diff --git a/test/helpers.h b/test/helpers.h
index afe157c..74fe162 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -9,6 +9,13 @@
extern "C" {
#endif
+#include "liburing.h"
+
+enum t_setup_ret {
+ T_SETUP_OK = 0,
+ T_SETUP_SKIP,
+};
+
/*
* Helper for allocating memory in tests.
*/
@@ -38,6 +45,15 @@ void t_create_file(const char *file, size_t size);
* with @buf_size bytes buffer of each iovec.
*/
struct iovec *t_create_buffers(size_t buf_num, size_t buf_size);
+
+/*
+ * Helper for setting up a ring and checking for user privs
+ */
+enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring,
+ struct io_uring_params *p);
+enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
+ unsigned int flags);
+
#ifdef __cplusplus
}
#endif