summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-02-07 09:01:32 -0700
committerJens Axboe <axboe@kernel.dk>2020-02-07 09:01:32 -0700
commite93e3414cc21374fa82584d3aa4838851aa1a46e (patch)
tree57e14928b37542f0c8a1482f54c006a5fa8e4a9e
parentdd15d761d0ec015661f8c779904c7198704437b1 (diff)
downloadliburing-e93e3414cc21374fa82584d3aa4838851aa1a46e.tar.gz
liburing-e93e3414cc21374fa82584d3aa4838851aa1a46e.tar.bz2
Add relative path testing
This adds AT_FDCWD test cases for openat2 and open-close. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--test/open-close.c34
-rw-r--r--test/openat2.c34
2 files changed, 48 insertions, 20 deletions
diff --git a/test/open-close.c b/test/open-close.c
index 00cf035..fdd7403 100644
--- a/test/open-close.c
+++ b/test/open-close.c
@@ -61,7 +61,7 @@ err:
return -1;
}
-static int test_openat(struct io_uring *ring, const char *path)
+static int test_openat(struct io_uring *ring, const char *path, int dfd)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
@@ -72,7 +72,7 @@ static int test_openat(struct io_uring *ring, const char *path)
fprintf(stderr, "get sqe failed\n");
goto err;
}
- io_uring_prep_openat(sqe, -1, path, O_RDONLY, 0);
+ io_uring_prep_openat(sqe, dfd, path, O_RDONLY, 0);
ret = io_uring_submit(ring);
if (ret <= 0) {
@@ -95,7 +95,7 @@ err:
int main(int argc, char *argv[])
{
struct io_uring ring;
- const char *fname;
+ const char *path, *path_rel;
int ret, do_unlink;
ret = io_uring_queue_init(8, &ring, 0);
@@ -105,25 +105,37 @@ int main(int argc, char *argv[])
}
if (argc > 1) {
- fname = argv[1];
+ path = "/tmp/.open.close";
+ path_rel = argv[1];
do_unlink = 0;
} else {
- fname = "/tmp/.open.close";
+ path = "/tmp/.open.close";
+ path_rel = ".open.close";
do_unlink = 1;
}
- if (create_file(fname, 4096)) {
+ if (create_file(path, 4096)) {
+ fprintf(stderr, "file create failed\n");
+ return 1;
+ }
+ if (do_unlink && create_file(path_rel, 4096)) {
fprintf(stderr, "file create failed\n");
return 1;
}
- ret = test_openat(&ring, fname);
+ ret = test_openat(&ring, path, -1);
if (ret < 0) {
if (ret == -EINVAL) {
fprintf(stdout, "Open not supported, skipping\n");
goto done;
}
- fprintf(stderr, "test_openat failed: %d\n", ret);
+ fprintf(stderr, "test_openat absolute failed: %d\n", ret);
+ goto err;
+ }
+
+ ret = test_openat(&ring, path_rel, AT_FDCWD);
+ if (ret < 0) {
+ fprintf(stderr, "test_openat relative failed: %d\n", ret);
goto err;
}
@@ -140,11 +152,13 @@ int main(int argc, char *argv[])
}
done:
+ unlink(path);
if (do_unlink)
- unlink(fname);
+ unlink(path_rel);
return 0;
err:
+ unlink(path);
if (do_unlink)
- unlink(fname);
+ unlink(path_rel);
return 1;
}
diff --git a/test/openat2.c b/test/openat2.c
index 89f2b1b..462bc9b 100644
--- a/test/openat2.c
+++ b/test/openat2.c
@@ -30,7 +30,7 @@ static int create_file(const char *file, size_t size)
return ret != size;
}
-static int test_openat2(struct io_uring *ring, const char *path)
+static int test_openat2(struct io_uring *ring, const char *path, int dfd)
{
struct io_uring_cqe *cqe;
struct io_uring_sqe *sqe;
@@ -44,7 +44,7 @@ static int test_openat2(struct io_uring *ring, const char *path)
}
memset(&how, 0, sizeof(how));
how.flags = O_RDONLY;
- io_uring_prep_openat2(sqe, -1, path, &how);
+ io_uring_prep_openat2(sqe, dfd, path, &how);
ret = io_uring_submit(ring);
if (ret <= 0) {
@@ -67,7 +67,7 @@ err:
int main(int argc, char *argv[])
{
struct io_uring ring;
- const char *fname;
+ const char *path, *path_rel;
int ret, do_unlink;
ret = io_uring_queue_init(8, &ring, 0);
@@ -77,34 +77,48 @@ int main(int argc, char *argv[])
}
if (argc > 1) {
- fname = argv[1];
+ path = "/tmp/.open.close";
+ path_rel = argv[1];
do_unlink = 0;
} else {
- fname = "/tmp/.open.close";
+ path = "/tmp/.open.close";
+ path_rel = ".open.close";
do_unlink = 1;
}
- if (create_file(fname, 4096)) {
+ if (create_file(path, 4096)) {
+ fprintf(stderr, "file create failed\n");
+ return 1;
+ }
+ if (do_unlink && create_file(path_rel, 4096)) {
fprintf(stderr, "file create failed\n");
return 1;
}
- ret = test_openat2(&ring, fname);
+ ret = test_openat2(&ring, path, -1);
if (ret < 0) {
if (ret == -EINVAL) {
fprintf(stdout, "openat2 not supported, skipping\n");
goto done;
}
- fprintf(stderr, "test_openat2 failed: %d\n", ret);
+ fprintf(stderr, "test_openat2 absolute failed: %d\n", ret);
+ goto err;
+ }
+
+ ret = test_openat2(&ring, path_rel, AT_FDCWD);
+ if (ret < 0) {
+ fprintf(stderr, "test_openat2 relative failed: %d\n", ret);
goto err;
}
done:
+ unlink(path);
if (do_unlink)
- unlink(fname);
+ unlink(path_rel);
return 0;
err:
+ unlink(path);
if (do_unlink)
- unlink(fname);
+ unlink(path_rel);
return 1;
}