summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-10-03 19:33:13 -0600
committerJens Axboe <axboe@kernel.dk>2019-10-03 19:33:13 -0600
commite8c7087ec9c2cb77574959114ce3c98a3e9039c7 (patch)
tree104cabf963235b7216be957b3beb6957222292e0 /test
parent9ea0e8a82a972e82672f382c25e37d76f989aed8 (diff)
downloadliburing-e8c7087ec9c2cb77574959114ce3c98a3e9039c7.tar.gz
liburing-e8c7087ec9c2cb77574959114ce3c98a3e9039c7.tar.bz2
test/file-register: add grow/shrink cases
Register file set with room for 300, but use 50. Grow to the max and see if we can get to 300. Register file set of 50, shrink to 0. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test')
-rw-r--r--test/file-register.c106
1 files changed, 102 insertions, 4 deletions
diff --git a/test/file-register.c b/test/file-register.c
index f50e32e..b25f0f5 100644
--- a/test/file-register.c
+++ b/test/file-register.c
@@ -19,14 +19,16 @@ static void close_files(int *files, int nr_files, int add)
int i;
for (i = 0; i < nr_files; i++) {
- close(files[i]);
+ if (files)
+ close(files[i]);
if (!add)
sprintf(fname, ".reg.%d", i);
else
- sprintf(fname, ".add.%d", i);
+ sprintf(fname, ".add.%d", i + add);
unlink(fname);
}
- free(files);
+ if (files)
+ free(files);
}
static int *open_files(int nr_files, int extra, int add)
@@ -41,7 +43,7 @@ static int *open_files(int nr_files, int extra, int add)
if (!add)
sprintf(fname, ".reg.%d", i);
else
- sprintf(fname, ".add.%d", i);
+ sprintf(fname, ".add.%d", i + add);
files[i] = open(fname, O_RDWR | O_CREAT, 0644);
if (files[i] < 0) {
perror("open");
@@ -58,6 +60,90 @@ static int *open_files(int nr_files, int extra, int add)
return files;
}
+static int test_shrink(struct io_uring *ring)
+{
+ struct io_uring_files_update up;
+ int ret, off, fd;
+ int *files;
+
+ files = open_files(50, 0, 0);
+ ret = io_uring_register(ring->ring_fd, IORING_REGISTER_FILES, files, 50);
+ if (ret) {
+ printf("ret=%d, errno=%d\n", ret, errno);
+ goto err;
+ }
+
+ off = 0;
+ do {
+ fd = -1;
+ up.fds = &fd;
+ up.offset = off;
+
+ ret = io_uring_register(ring->ring_fd, IORING_REGISTER_FILES_UPDATE, &up, 1);
+ if (ret != 1) {
+ if (off == 50 && errno == EINVAL)
+ break;
+ printf("ret=%d, errno=%d\n", ret, errno);
+ break;
+ }
+ off++;
+ } while (1);
+
+ ret = io_uring_register(ring->ring_fd, IORING_UNREGISTER_FILES, NULL, 0);
+ if (ret) {
+ printf("ret=%d, errno=%d\n", ret, errno);
+ goto err;
+ }
+
+ return 0;
+err:
+ return 1;
+}
+
+
+static int test_grow(struct io_uring *ring)
+{
+ struct io_uring_files_update up;
+ int ret, off;
+ int *files;
+
+ files = open_files(50, 250, 0);
+ ret = io_uring_register(ring->ring_fd, IORING_REGISTER_FILES, files, 300);
+ if (ret) {
+ printf("ret=%d, errno=%d\n", ret, errno);
+ goto err;
+ }
+
+ off = 50;
+ do {
+ up.fds = open_files(1, 0, off);
+ up.offset = off;
+
+ ret = io_uring_register(ring->ring_fd, IORING_REGISTER_FILES_UPDATE, &up, 1);
+ if (ret != 1) {
+ if (off == 300 && errno == EINVAL)
+ break;
+ printf("ret=%d, errno=%d\n", ret, errno);
+ break;
+ }
+ off++;
+ } while (1);
+
+ ret = io_uring_register(ring->ring_fd, IORING_UNREGISTER_FILES, NULL, 0);
+ if (ret) {
+ printf("ret=%d, errno=%d\n", ret, errno);
+ goto err;
+ }
+
+ close_files(files, 100, 0);
+ close_files(NULL, 251, 50);
+ return 0;
+err:
+ close_files(files, 100, 0);
+ close_files(NULL, 251, 50);
+ return 1;
+}
+
static int test_replace_all(struct io_uring *ring)
{
struct io_uring_files_update up;
@@ -328,5 +414,17 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_grow(&ring);
+ if (ret) {
+ printf("test_grow failed\n");
+ return ret;
+ }
+
+ ret = test_shrink(&ring);
+ if (ret) {
+ printf("test_shrink failed\n");
+ return ret;
+ }
+
return 0;
}