From b0cf23de76df798833f271579b31bdd70cb50863 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 3 Sep 2024 10:52:32 -0600 Subject: [PATCH] test: return skipped if we don't have permission to open file If devices/filenames are passed in to the test case and we don't have permission to open them, don't fail verbosely. Rather, just skip the test case. This makes the tests less noisy when often run as both root and as a normal user, allow you to use the same configuration for both. Signed-off-by: Jens Axboe --- test/d4ae271dfaae.c | 7 +++++-- test/defer-taskrun.c | 4 ++-- test/defer-tw-timeout.c | 2 +- test/fadvise.c | 4 ++++ test/fdinfo.c | 6 +++++- test/file-verify.c | 11 ++++++++++- test/io_uring_passthrough.c | 2 ++ test/iopoll-leak.c | 2 ++ test/iopoll-overflow.c | 2 +- test/iopoll.c | 6 +++--- test/madvise.c | 8 ++++++++ test/open-close.c | 4 ++++ test/openat2.c | 4 ++++ test/poll-v-poll.c | 5 ++++- test/read-write.c | 8 ++++++-- test/ringbuf-read.c | 4 ++++ test/sq-poll-dup.c | 2 +- test/sq-poll-share.c | 2 ++ test/statx.c | 2 ++ test/submit-reuse.c | 5 ++++- test/thread-exit.c | 5 +++++ 21 files changed, 79 insertions(+), 16 deletions(-) diff --git a/test/d4ae271dfaae.c b/test/d4ae271dfaae.c index f31de9eb8..6c0db2da4 100644 --- a/test/d4ae271dfaae.c +++ b/test/d4ae271dfaae.c @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) { struct io_uring ring; - int i, fd, ret; + int i, fd, ret, __e; struct io_uring_sqe *sqe; struct io_uring_cqe *cqe; struct iovec *iovecs; @@ -43,10 +43,13 @@ int main(int argc, char *argv[]) } fd = open(fname, O_RDONLY | O_DIRECT); + __e = errno; if (fname != argv[1]) unlink(fname); if (fd < 0) { - perror("open"); + if (__e == EINVAL || __e == EPERM || __e == EACCES) + return T_EXIT_SKIP; + fprintf(stderr, "open: %s\n", strerror(__e)); goto out; } diff --git a/test/defer-taskrun.c b/test/defer-taskrun.c index 1bb9a7be1..3ef7801ca 100644 --- a/test/defer-taskrun.c +++ b/test/defer-taskrun.c @@ -196,12 +196,12 @@ static int test_exec(const char *filename) if (filename) { fd = open(filename, O_RDONLY | O_DIRECT); - if (fd < 0 && errno == EINVAL) + if (fd < 0 && (errno == EINVAL || errno == EPERM || errno == EACCES)) return T_EXIT_SKIP; } else { t_create_file(EXEC_FILENAME, EXEC_FILESIZE); fd = open(EXEC_FILENAME, O_RDONLY | O_DIRECT); - if (fd < 0 && errno == EINVAL) { + if (fd < 0 && (errno == EINVAL || errno == EPERM || errno == EACCES)) { unlink(EXEC_FILENAME); return T_EXIT_SKIP; } diff --git a/test/defer-tw-timeout.c b/test/defer-tw-timeout.c index 4313eae9f..cd455505e 100644 --- a/test/defer-tw-timeout.c +++ b/test/defer-tw-timeout.c @@ -99,7 +99,7 @@ static int test_file(struct io_uring *ring, char *__fname) fd = open(fname, O_RDONLY | O_DIRECT); if (fd < 0) { - if (errno == EINVAL) { + if (errno == EINVAL || errno == EPERM || errno == EACCES) { if (!__fname) unlink(fname); return T_EXIT_SKIP; diff --git a/test/fadvise.c b/test/fadvise.c index 7eb117d94..b5feb3fc6 100644 --- a/test/fadvise.c +++ b/test/fadvise.c @@ -91,6 +91,8 @@ static int test_fadvise(struct io_uring *ring, const char *filename) fd = open(filename, O_RDONLY); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); return 1; } @@ -150,6 +152,8 @@ int main(int argc, char *argv[]) good = bad = 0; for (i = 0; i < LOOPS; i++) { ret = test_fadvise(&ring, fname); + if (ret == T_EXIT_SKIP) + return T_EXIT_SKIP; if (ret == 1) { fprintf(stderr, "read_fadvise failed\n"); goto err; diff --git a/test/fdinfo.c b/test/fdinfo.c index 6c0f2d0a2..4ec765535 100644 --- a/test/fdinfo.c +++ b/test/fdinfo.c @@ -80,7 +80,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write, if (fixed) { ret = t_register_buffers(ring, vecs, BUFFERS); if (ret == T_SETUP_SKIP) - return 0; + return T_EXIT_SKIP; if (ret != T_SETUP_OK) { fprintf(stderr, "buffer reg failed: %d\n", ret); goto err; @@ -91,6 +91,8 @@ static int __test_io(const char *file, struct io_uring *ring, int write, if (fd < 0) { if (errno == EINVAL) return 0; + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("file open"); goto err; } @@ -384,6 +386,8 @@ int main(int argc, char *argv[]) ret = test_io(fname, write, buffered, sqthread, fixed, nonvec, BS); + if (ret == T_EXIT_SKIP) + continue; if (ret) { fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n", write, buffered, sqthread, fixed, nonvec); diff --git a/test/file-verify.c b/test/file-verify.c index e4ad822fd..79b7fb601 100644 --- a/test/file-verify.c +++ b/test/file-verify.c @@ -346,6 +346,8 @@ static int test(struct io_uring *ring, const char *fname, int buffered, flags |= O_DIRECT; fd = open(fname, flags); if (fd < 0) { + if (errno == EINVAL || errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); return 1; } @@ -505,6 +507,8 @@ static int fill_pattern(const char *fname) fd = open(fname, O_WRONLY); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); return 1; } @@ -557,10 +561,15 @@ int main(int argc, char *argv[]) goto err; } - if (fill_pattern(fname)) + ret = fill_pattern(fname); + if (ret == T_EXIT_SKIP) + return T_EXIT_SKIP; + else if (ret) goto err; ret = test(&ring, fname, 1, 0, 0, 0, 0); + if (ret == T_EXIT_SKIP) + return T_EXIT_SKIP; if (ret) { fprintf(stderr, "Buffered novec test failed\n"); goto err; diff --git a/test/io_uring_passthrough.c b/test/io_uring_passthrough.c index a5e630f7d..345c65b1f 100644 --- a/test/io_uring_passthrough.c +++ b/test/io_uring_passthrough.c @@ -95,6 +95,8 @@ static int __test_io(const char *file, struct io_uring *ring, int tc, int read, fd = open(file, open_flags); if (fd < 0) { + if (errno == EACCES || errno == EPERM) + return T_EXIT_SKIP; perror("file open"); goto err; } diff --git a/test/iopoll-leak.c b/test/iopoll-leak.c index 0aa9b7a64..8dec15e30 100644 --- a/test/iopoll-leak.c +++ b/test/iopoll-leak.c @@ -26,6 +26,8 @@ static int do_iopoll(const char *fname) fd = open(fname, O_RDONLY | O_DIRECT); if (fd < 0) { + if (errno == EINVAL || errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); return T_EXIT_SKIP; } diff --git a/test/iopoll-overflow.c b/test/iopoll-overflow.c index 4716c4a35..52f237a37 100644 --- a/test/iopoll-overflow.c +++ b/test/iopoll-overflow.c @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) fd = open(fname, O_RDONLY | O_DIRECT); if (fd < 0) { - if (errno == EINVAL) { + if (errno == EINVAL || errno == EACCES || errno == EPERM) { if (fname != argv[1]) unlink(fname); return T_EXIT_SKIP; diff --git a/test/iopoll.c b/test/iopoll.c index 2020ae0cc..2e0f7ea2b 100644 --- a/test/iopoll.c +++ b/test/iopoll.c @@ -87,7 +87,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int sqt } fd = open(file, open_flags); if (fd < 0) { - if (errno == EINVAL) + if (errno == EINVAL || errno == EPERM || errno == EACCES) return 0; perror("file open"); goto err; @@ -230,7 +230,7 @@ static int test_io_uring_cqe_peek(const char *file) fd = open(file, O_RDONLY | O_DIRECT); if (fd < 0) { - if (errno == EINVAL) { + if (errno == EINVAL || errno == EPERM || errno == EACCES) { io_uring_queue_exit(&ring); return T_EXIT_SKIP; } @@ -302,7 +302,7 @@ static int test_io_uring_submit_enters(const char *file) open_flags = O_WRONLY | O_DIRECT; fd = open(file, open_flags); if (fd < 0) { - if (errno == EINVAL) + if (errno == EINVAL || errno == EPERM || errno == EACCES) return T_EXIT_SKIP; perror("file open"); goto err; diff --git a/test/madvise.c b/test/madvise.c index 5b92577e1..fc2deeceb 100644 --- a/test/madvise.c +++ b/test/madvise.c @@ -76,6 +76,8 @@ static int test_madvise(struct io_uring *ring, const char *filename) fd = open(filename, O_RDONLY); if (fd < 0) { + if (errno == EACCES || errno == EPERM) + return T_EXIT_SKIP; perror("open"); return 1; } @@ -146,6 +148,8 @@ int main(int argc, char *argv[]) good = bad = 0; for (i = 0; i < LOOPS; i++) { ret = test_madvise(&ring, fname); + if (ret == T_EXIT_SKIP) + goto skip; if (ret == 1) { fprintf(stderr, "test_madvise failed\n"); goto err; @@ -168,4 +172,8 @@ int main(int argc, char *argv[]) if (fname != argv[1]) unlink(fname); return T_EXIT_FAIL; +skip: + if (fname != argv[1]) + unlink(fname); + return T_EXIT_SKIP; } diff --git a/test/open-close.c b/test/open-close.c index 8afbd7867..9a85e3fc2 100644 --- a/test/open-close.c +++ b/test/open-close.c @@ -250,12 +250,16 @@ int main(int argc, char *argv[]) fprintf(stdout, "Open not supported, skipping\n"); goto done; } + if (ret == -EPERM || ret == -EACCES) + return T_EXIT_SKIP; fprintf(stderr, "test_openat absolute failed: %d\n", ret); goto err; } ret = test_openat(&ring, path_rel, AT_FDCWD); if (ret < 0) { + if (ret == -EPERM || ret == -EACCES) + return T_EXIT_SKIP; fprintf(stderr, "test_openat relative failed: %d\n", ret); goto err; } diff --git a/test/openat2.c b/test/openat2.c index 946acc37f..889b6b3cd 100644 --- a/test/openat2.c +++ b/test/openat2.c @@ -277,12 +277,16 @@ int main(int argc, char *argv[]) fprintf(stdout, "openat2 not supported, skipping\n"); goto done; } + if (ret == -EPERM || ret == -EACCES) + return T_EXIT_SKIP; fprintf(stderr, "test_openat2 absolute failed: %d\n", ret); goto err; } ret = test_openat2(&ring, path_rel, AT_FDCWD, false, 0, 0); if (ret < 0) { + if (ret == -EPERM || ret == -EACCES) + return T_EXIT_SKIP; fprintf(stderr, "test_openat2 relative failed: %d\n", ret); goto err; } diff --git a/test/poll-v-poll.c b/test/poll-v-poll.c index 1b277db91..82308ba09 100644 --- a/test/poll-v-poll.c +++ b/test/poll-v-poll.c @@ -17,6 +17,7 @@ #include #include "liburing.h" +#include "helpers.h" struct thread_data { struct io_uring *ring; @@ -174,6 +175,8 @@ static int do_fd_test(struct io_uring *ring, const char *fname, int events) fd = open(fname, O_RDONLY); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); return 1; } @@ -331,7 +334,7 @@ int main(int argc, char *argv[]) fname = argv[0]; ret = do_fd_test(&ring, fname, POLLIN); - if (ret) { + if (ret == T_EXIT_FAIL) { fprintf(stderr, "fd test IN failed\n"); return ret; } diff --git a/test/read-write.c b/test/read-write.c index 6f24ec919..27b0cc730 100644 --- a/test/read-write.c +++ b/test/read-write.c @@ -76,7 +76,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write, fd = open(file, open_flags); if (fd < 0) { - if (errno == EINVAL) + if (errno == EINVAL || errno == EPERM || errno == EACCES) return 0; perror("file open"); goto err; @@ -266,6 +266,8 @@ static int read_poll_link(const char *file) fd = open(file, O_WRONLY); if (fd < 0) { + if (errno == EACCES || errno == EPERM) + return T_EXIT_SKIP; perror("open"); return 1; } @@ -696,6 +698,8 @@ static int test_io_link(const char *file) fd = open(file, O_WRONLY); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return 0; perror("file open"); goto err; } @@ -929,7 +933,7 @@ int main(int argc, char *argv[]) } ret = read_poll_link(fname); - if (ret) { + if (ret == T_EXIT_FAIL) { fprintf(stderr, "read_poll_link failed\n"); goto err; } diff --git a/test/ringbuf-read.c b/test/ringbuf-read.c index 9eb1e18fc..f9dffc4cc 100644 --- a/test/ringbuf-read.c +++ b/test/ringbuf-read.c @@ -59,6 +59,8 @@ static int test(const char *filename, int dio, int async) fd = open(filename, O_RDONLY); } if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); return 1; } @@ -144,6 +146,8 @@ int main(int argc, char *argv[]) fd = open(fname, O_WRONLY); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); goto err; } diff --git a/test/sq-poll-dup.c b/test/sq-poll-dup.c index 83d880fa2..3ba5b8767 100644 --- a/test/sq-poll-dup.c +++ b/test/sq-poll-dup.c @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) if (fname != argv[1]) unlink(fname); - if (__e == EINVAL) + if (__e == EINVAL || __e == EPERM || __e == EACCES) return T_EXIT_SKIP; perror("open"); return -1; diff --git a/test/sq-poll-share.c b/test/sq-poll-share.c index ba079c74c..12add46ea 100644 --- a/test/sq-poll-share.c +++ b/test/sq-poll-share.c @@ -90,6 +90,8 @@ int main(int argc, char *argv[]) fd = open(fname, O_RDONLY | O_DIRECT); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open"); return -1; } diff --git a/test/statx.c b/test/statx.c index cf467389a..b26e1401c 100644 --- a/test/statx.c +++ b/test/statx.c @@ -161,6 +161,8 @@ static int test_statx_fd(struct io_uring *ring, const char *path) fd = open(path, O_RDONLY); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + return 0; perror("open"); return 1; } diff --git a/test/submit-reuse.c b/test/submit-reuse.c index 1fbcc78c2..44a02abcb 100644 --- a/test/submit-reuse.c +++ b/test/submit-reuse.c @@ -137,6 +137,8 @@ static int test_reuse(int argc, char *argv[], int split, int async) if (do_unlink) unlink(fname1); if (fd1 < 0) { + if (errno == EPERM || errno == EACCES) + return T_EXIT_SKIP; perror("open fname1"); goto err; } @@ -186,7 +188,6 @@ static int test_reuse(int argc, char *argv[], int split, int async) err: io_uring_queue_exit(&ring); return 1; - } int main(int argc, char *argv[]) @@ -200,6 +201,8 @@ int main(int argc, char *argv[]) async = (i & 2) != 0; ret = test_reuse(argc, argv, split, async); + if (ret == T_EXIT_SKIP) + continue; if (ret) { fprintf(stderr, "test_reuse %d %d failed\n", split, async); return ret; diff --git a/test/thread-exit.c b/test/thread-exit.c index 3e2043137..f94d9896c 100644 --- a/test/thread-exit.c +++ b/test/thread-exit.c @@ -102,6 +102,8 @@ int main(int argc, char *argv[]) if (do_unlink) unlink(fname); if (fd < 0) { + if (errno == EPERM || errno == EACCES) + goto skip; perror("open"); return 1; } @@ -140,4 +142,7 @@ int main(int argc, char *argv[]) err: free_g_buf(); return 1; +skip: + free_g_buf(); + return T_EXIT_SKIP; }