* [PATCH liburing 1/2] tests: don't skip sqpoll needlessly
2021-08-25 17:53 [PATCH liburing 0/2] non-root tests Pavel Begunkov
@ 2021-08-25 17:53 ` Pavel Begunkov
2021-08-25 17:53 ` [PATCH liburing 2/2] tests: skip when large buf register fails Pavel Begunkov
2021-08-25 17:59 ` [PATCH liburing 0/2] non-root tests Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2021-08-25 17:53 UTC (permalink / raw)
To: Jens Axboe, io-uring
Newer kernels support non-privileged SQPOLL, don't skip sqpoll testing
in sq-poll-kthread and others when it would work just fine.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/d4ae271dfaae-test.c | 5 -----
test/sq-poll-kthread.c | 14 ++++++--------
2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/test/d4ae271dfaae-test.c b/test/d4ae271dfaae-test.c
index 80d3f71..10c7e98 100644
--- a/test/d4ae271dfaae-test.c
+++ b/test/d4ae271dfaae-test.c
@@ -27,11 +27,6 @@ int main(int argc, char *argv[])
char *fname;
void *buf;
- if (geteuid()) {
- fprintf(stdout, "Test requires root, skipping\n");
- return 0;
- }
-
memset(&p, 0, sizeof(p));
p.flags = IORING_SETUP_SQPOLL;
ret = t_create_ring_params(4, &ring, &p);
diff --git a/test/sq-poll-kthread.c b/test/sq-poll-kthread.c
index ed7d0bf..0a0a75a 100644
--- a/test/sq-poll-kthread.c
+++ b/test/sq-poll-kthread.c
@@ -17,6 +17,7 @@
#include <sys/epoll.h>
#include "liburing.h"
+#include "helpers.h"
#define SQ_THREAD_IDLE 2000
#define BUF_SIZE 128
@@ -38,23 +39,20 @@ static int do_test_sq_poll_kthread_stopped(bool do_exit)
uint8_t buf[BUF_SIZE];
struct iovec iov;
- if (geteuid()) {
- fprintf(stderr, "sqpoll requires root!\n");
- return TEST_SKIPPED;
- }
-
if (pipe(pipe1) != 0) {
perror("pipe");
return TEST_FAILED;
}
memset(¶m, 0, sizeof(param));
-
param.flags |= IORING_SETUP_SQPOLL;
param.sq_thread_idle = SQ_THREAD_IDLE;
- ret = io_uring_queue_init_params(16, &ring, ¶m);
- if (ret) {
+ ret = t_create_ring_params(16, &ring, ¶m);
+ if (ret == T_SETUP_SKIP) {
+ ret = TEST_FAILED;
+ goto err_pipe;
+ } else if (ret != T_SETUP_OK) {
fprintf(stderr, "ring setup failed\n");
ret = TEST_FAILED;
goto err_pipe;
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH liburing 2/2] tests: skip when large buf register fails
2021-08-25 17:53 [PATCH liburing 0/2] non-root tests Pavel Begunkov
2021-08-25 17:53 ` [PATCH liburing 1/2] tests: don't skip sqpoll needlessly Pavel Begunkov
@ 2021-08-25 17:53 ` Pavel Begunkov
2021-08-25 17:59 ` [PATCH liburing 0/2] non-root tests Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2021-08-25 17:53 UTC (permalink / raw)
To: Jens Axboe, io-uring
Registering lots of memory will fail for non-privileged users, so skip
tests if that happens.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/helpers.c | 19 +++++++++++++++++++
test/helpers.h | 4 ++++
test/iopoll.c | 24 ++++++++++++------------
test/read-write.c | 26 +++++++++++---------------
4 files changed, 46 insertions(+), 27 deletions(-)
diff --git a/test/helpers.c b/test/helpers.c
index 930d82a..975e7cb 100644
--- a/test/helpers.c
+++ b/test/helpers.c
@@ -114,3 +114,22 @@ enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
p.flags = flags;
return t_create_ring_params(depth, ring, &p);
}
+
+enum t_setup_ret t_register_buffers(struct io_uring *ring,
+ const struct iovec *iovecs,
+ unsigned nr_iovecs)
+{
+ int ret;
+
+ ret = io_uring_register_buffers(ring, iovecs, nr_iovecs);
+ if (!ret)
+ return T_SETUP_OK;
+
+ if ((ret == -EPERM || ret == -ENOMEM) && geteuid()) {
+ fprintf(stdout, "too large non-root buffer registration, skip\n");
+ return T_SETUP_SKIP;
+ }
+
+ fprintf(stderr, "buffer register failed: %s\n", strerror(-ret));
+ return ret;
+}
diff --git a/test/helpers.h b/test/helpers.h
index 18de463..7526d46 100644
--- a/test/helpers.h
+++ b/test/helpers.h
@@ -54,6 +54,10 @@ enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring,
enum t_setup_ret t_create_ring(int depth, struct io_uring *ring,
unsigned int flags);
+enum t_setup_ret t_register_buffers(struct io_uring *ring,
+ const struct iovec *iovecs,
+ unsigned nr_iovecs);
+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#ifdef __cplusplus
diff --git a/test/iopoll.c b/test/iopoll.c
index 7037c31..de36473 100644
--- a/test/iopoll.c
+++ b/test/iopoll.c
@@ -60,14 +60,13 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int sqt
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int open_flags;
- int i, fd, ret;
+ int i, fd = -1, ret;
off_t offset;
- if (buf_select && write)
+ if (buf_select) {
write = 0;
- if (buf_select && fixed)
fixed = 0;
-
+ }
if (buf_select && provide_buffers(ring))
return 1;
@@ -77,19 +76,20 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int sqt
open_flags = O_RDONLY;
open_flags |= O_DIRECT;
- fd = open(file, open_flags);
- if (fd < 0) {
- perror("file open");
- goto err;
- }
-
if (fixed) {
- ret = io_uring_register_buffers(ring, vecs, BUFFERS);
- if (ret) {
+ ret = t_register_buffers(ring, vecs, BUFFERS);
+ if (ret == T_SETUP_SKIP)
+ return 0;
+ if (ret != T_SETUP_OK) {
fprintf(stderr, "buffer reg failed: %d\n", ret);
goto err;
}
}
+ fd = open(file, open_flags);
+ if (fd < 0) {
+ perror("file open");
+ goto err;
+ }
if (sqthread) {
ret = io_uring_register_files(ring, &fd, 1);
if (ret) {
diff --git a/test/read-write.c b/test/read-write.c
index 1cfa2d5..0c55159 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -49,7 +49,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int open_flags;
- int i, fd, ret;
+ int i, fd = -1, ret;
off_t offset;
#ifdef VERBOSE
@@ -57,13 +57,6 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
buffered, sqthread,
fixed, nonvec);
#endif
- if (sqthread && geteuid()) {
-#ifdef VERBOSE
- fprintf(stdout, "SKIPPED (not root)\n");
-#endif
- return 0;
- }
-
if (write)
open_flags = O_WRONLY;
else
@@ -71,19 +64,22 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
if (!buffered)
open_flags |= O_DIRECT;
+ if (fixed) {
+ ret = t_register_buffers(ring, vecs, BUFFERS);
+ if (ret == T_SETUP_SKIP)
+ return 0;
+ if (ret != T_SETUP_OK) {
+ fprintf(stderr, "buffer reg failed: %d\n", ret);
+ goto err;
+ }
+ }
+
fd = open(file, open_flags);
if (fd < 0) {
perror("file open");
goto err;
}
- if (fixed) {
- ret = io_uring_register_buffers(ring, vecs, BUFFERS);
- if (ret) {
- fprintf(stderr, "buffer reg failed: %d\n", ret);
- goto err;
- }
- }
if (sqthread) {
ret = io_uring_register_files(ring, &fd, 1);
if (ret) {
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread