summaryrefslogtreecommitdiff
path: root/test/shared-wq.c
blob: 7e913bb9de5bef72012aa769932c4186555984d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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.wq_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.wq_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.wq_id = org->wq_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;
}