blob: c0571e6d87ef4da4f21b74c67f9b5e37d23d01c8 [file] [log] [blame]
Jens Axboee5024352020-02-11 20:34:12 -07001/* SPDX-License-Identifier: MIT */
Jens Axboeb7697502020-01-24 10:17:31 -07002/*
3 * Description: test wq sharing
4 */
5#include <errno.h>
6#include <stdio.h>
7#include <unistd.h>
8#include <stdlib.h>
9#include <string.h>
10#include <fcntl.h>
11
12#include "liburing.h"
13
Jens Axboe3f78c172020-01-27 17:29:55 -070014static int test_attach_invalid(int ringfd)
Jens Axboeb7697502020-01-24 10:17:31 -070015{
16 struct io_uring_params p;
17 struct io_uring ring;
18 int ret;
19
20 memset(&p, 0, sizeof(p));
21 p.flags = IORING_SETUP_ATTACH_WQ;
Jens Axboe3f78c172020-01-27 17:29:55 -070022 p.wq_fd = ringfd;
Jens Axboeb7697502020-01-24 10:17:31 -070023 ret = io_uring_queue_init_params(1, &ring, &p);
24 if (ret != -EINVAL) {
25 fprintf(stderr, "Attach to zero: %d\n", ret);
26 goto err;
27 }
28 return 0;
29err:
30 return 1;
31}
32
Jens Axboe3f78c172020-01-27 17:29:55 -070033static int test_attach(int ringfd)
Jens Axboeb7697502020-01-24 10:17:31 -070034{
35 struct io_uring_params p;
36 struct io_uring ring2;
37 int ret;
38
39 memset(&p, 0, sizeof(p));
40 p.flags = IORING_SETUP_ATTACH_WQ;
Jens Axboe3f78c172020-01-27 17:29:55 -070041 p.wq_fd = ringfd;
Jens Axboeb7697502020-01-24 10:17:31 -070042 ret = io_uring_queue_init_params(1, &ring2, &p);
43 if (ret == -EINVAL) {
44 fprintf(stdout, "Sharing not supported, skipping\n");
45 return 0;
46 } else if (ret) {
47 fprintf(stderr, "Attach to id: %d\n", ret);
48 goto err;
49 }
50 io_uring_queue_exit(&ring2);
51 return 0;
52err:
53 return 1;
54}
55
Jens Axboeb7697502020-01-24 10:17:31 -070056int main(int argc, char *argv[])
57{
Jens Axboeb7697502020-01-24 10:17:31 -070058 struct io_uring ring;
59 int ret;
60
Jens Axboea2141fc2020-05-19 17:36:19 -060061 if (argc > 1)
62 return 0;
63
Jens Axboe34901a72020-01-28 12:51:58 -070064 ret = io_uring_queue_init(8, &ring, 0);
Jens Axboeb7697502020-01-24 10:17:31 -070065 if (ret) {
66 fprintf(stderr, "ring setup failed\n");
67 return 1;
68 }
69
Jens Axboe3f78c172020-01-27 17:29:55 -070070 /* stdout is definitely not an io_uring descriptor */
71 ret = test_attach_invalid(2);
Jens Axboeb7697502020-01-24 10:17:31 -070072 if (ret) {
Jens Axboe3f78c172020-01-27 17:29:55 -070073 fprintf(stderr, "test_attach_invalid failed\n");
Jens Axboeb7697502020-01-24 10:17:31 -070074 return ret;
75 }
76
Jens Axboe3f78c172020-01-27 17:29:55 -070077 ret = test_attach(ring.ring_fd);
Jens Axboeb7697502020-01-24 10:17:31 -070078 if (ret) {
79 fprintf(stderr, "test_attach failed\n");
80 return ret;
81 }
82
83 return 0;
84}