Skip to content

Commit

Permalink
test: return skipped if we don't have permission to open file
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
axboe committed Sep 3, 2024
1 parent aa2e09b commit b0cf23d
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 16 deletions.
7 changes: 5 additions & 2 deletions test/d4ae271dfaae.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions test/defer-taskrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/defer-tw-timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/fadvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion test/fdinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion test/file-verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/io_uring_passthrough.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions test/iopoll-leak.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/iopoll-overflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/iopoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
4 changes: 4 additions & 0 deletions test/open-close.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions test/openat2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion test/poll-v-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <sys/epoll.h>

#include "liburing.h"
#include "helpers.h"

struct thread_data {
struct io_uring *ring;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions test/read-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions test/ringbuf-read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/sq-poll-dup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/sq-poll-share.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions test/statx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion test/submit-reuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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[])
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/thread-exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -140,4 +142,7 @@ int main(int argc, char *argv[])
err:
free_g_buf();
return 1;
skip:
free_g_buf();
return T_EXIT_SKIP;
}

0 comments on commit b0cf23d

Please sign in to comment.