diff options
author | Jens Axboe <axboe@kernel.dk> | 2020-01-24 10:17:31 -0700 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2020-01-24 10:17:31 -0700 |
commit | b769750865618d56cc8f201f2eb65f157315004f (patch) | |
tree | ee79aa6b3a464b73dd529fd9fc76481cdd5da9cd | |
parent | 69e4cf92793e25ee21299aa0efff317894a6904a (diff) | |
download | liburing-b769750865618d56cc8f201f2eb65f157315004f.tar.gz liburing-b769750865618d56cc8f201f2eb65f157315004f.tar.bz2 |
Add test case for IORING_SETUP_ATTACH_WQ
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | test/Makefile | 4 | ||||
-rw-r--r-- | test/shared-wq.c | 107 |
2 files changed, 109 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile index ae70581..efdc3aa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -19,7 +19,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register poll-many b5837bd5311d-test accept-test d77a67ed5f27-test \ connect 7ad0e4b2f83c-test submit-reuse fallocate open-close \ file-update statx accept-reuse poll-v-poll fadvise madvise \ - short-read openat2 probe + short-read openat2 probe shared-wq include ../Makefile.quiet @@ -45,7 +45,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \ b5837bd5311d-test.c accept-test.c d77a67ed5f27-test.c connect.c \ 7ad0e4b2f83c-test.c submit-reuse.c fallocate.c open-close.c \ file-update.c statx.c accept-reuse.c poll-v-poll.c fadvise.c \ - madvise.c short-read.c openat2.c probe.c + madvise.c short-read.c openat2.c probe.c shared-wq.c test_objs := $(patsubst %.c,%.ol,$(test_srcs)) diff --git a/test/shared-wq.c b/test/shared-wq.c new file mode 100644 index 0000000..957df80 --- /dev/null +++ b/test/shared-wq.c @@ -0,0 +1,107 @@ +/* + * Description: test wq sharing + */ +#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> + +#include "liburing.h" + +static int test_attach_id_no_flag(void) +{ + struct io_uring_params p; + struct io_uring ring; + int ret; + + memset(&p, 0, sizeof(p)); + p.id = 1; + ret = io_uring_queue_init_params(1, &ring, &p); + if (ret != -EINVAL) { + fprintf(stderr, "Attach to one: %d\n", ret); + goto err; + } + return 0; +err: + return 1; +} + + +static int test_attach_zero(void) +{ + struct io_uring_params p; + struct io_uring ring; + int ret; + + memset(&p, 0, sizeof(p)); + p.flags = IORING_SETUP_ATTACH_WQ; + p.id = 0; + ret = io_uring_queue_init_params(1, &ring, &p); + if (ret != -EINVAL) { + fprintf(stderr, "Attach to zero: %d\n", ret); + goto err; + } + return 0; +err: + return 1; +} + +static int test_attach(struct io_uring_params *org) +{ + struct io_uring_params p; + struct io_uring ring2; + int ret; + + memset(&p, 0, sizeof(p)); + p.flags = IORING_SETUP_ATTACH_WQ; + p.id = org->id; + ret = io_uring_queue_init_params(1, &ring2, &p); + if (ret == -EINVAL) { + fprintf(stdout, "Sharing not supported, skipping\n"); + return 0; + } else if (ret) { + fprintf(stderr, "Attach to id: %d\n", ret); + goto err; + } + io_uring_queue_exit(&ring2); + return 0; +err: + return 1; +} + + +int main(int argc, char *argv[]) +{ + struct io_uring_params p; + struct io_uring ring; + int ret; + + memset(&p, 0, sizeof(p)); + ret = io_uring_queue_init_params(8, &ring, &p); + if (ret) { + fprintf(stderr, "ring setup failed\n"); + return 1; + } + + ret = test_attach_zero(); + if (ret) { + fprintf(stderr, "test_attach_zero failed\n"); + return ret; + } + + ret = test_attach_id_no_flag(); + if (ret) { + fprintf(stderr, "test_attach_id_no_flag failed\n"); + return ret; + } + + ret = test_attach(&p); + if (ret) { + fprintf(stderr, "test_attach failed\n"); + return ret; + } + + return 0; +} |