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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#include "../config-host.h"
/* SPDX-License-Identifier: MIT */
/*
* Description: test pollfree wakeups
*/
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/signalfd.h>
#include <unistd.h>
#include <stdlib.h>
#include "liburing.h"
#include "helpers.h"
static int no_signalfd;
static int child(int flags)
{
struct io_uring_sqe *sqe;
struct io_uring ring;
struct signalfd_siginfo si;
static unsigned long index;
sigset_t mask;
int ret, fd;
ret = io_uring_queue_init(4, &ring, flags);
if (ret) {
if (ret == -EINVAL)
return 0;
fprintf(stderr, "queue init failed %d\n", ret);
return ret;
}
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
fd = signalfd(-1, &mask, SFD_NONBLOCK);
if (fd < 0) {
no_signalfd = 1;
perror("signalfd");
return 1;
}
sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fd, &si, sizeof(si), 0);
sqe->user_data = 1;
io_uring_submit(&ring);
sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fd, &si, sizeof(si), 0);
sqe->user_data = 2;
sqe->flags |= IOSQE_ASYNC;
io_uring_submit(&ring);
sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fd, &si, sizeof(si), 0);
sqe->user_data = 3;
io_uring_submit(&ring);
if (!(++index & 7))
usleep(100);
return 0;
}
static int run_test(int flags)
{
pid_t pid;
int ret;
pid = fork();
if (pid < 0) {
perror("fork");
return 1;
} else if (!pid) {
ret = child(flags);
_exit(ret);
} else {
int wstatus;
pid_t childpid;
do {
childpid = waitpid(pid, &wstatus, 0);
} while (childpid == (pid_t) -1 && (errno == EINTR));
if (errno == ECHILD)
wstatus = 0;
return wstatus;
}
}
static int test(int flags)
{
struct timeval start;
int ret;
gettimeofday(&start, NULL);
do {
ret = run_test(flags);
if (ret) {
fprintf(stderr, "test failed with flags %x\n", flags);
return 1;
}
if (no_signalfd)
break;
} while (mtime_since_now(&start) < 2500);
return 0;
}
int main(int argc, char *argv[])
{
int ret;
if (argc > 1)
return T_EXIT_SKIP;
ret = test(0);
if (ret) {
fprintf(stderr, "test 0 failed: %d\n", ret);
return ret;
}
if (no_signalfd)
return T_EXIT_SKIP;
ret = test(IORING_SETUP_SQPOLL);
if (ret) {
fprintf(stderr, "test SQPOLL failed: %d\n", ret);
return ret;
}
ret = test(IORING_SETUP_COOP_TASKRUN);
if (ret) {
fprintf(stderr, "test COOP failed: %d\n", ret);
return ret;
}
ret = test(IORING_SETUP_DEFER_TASKRUN|IORING_SETUP_SINGLE_ISSUER);
if (ret) {
fprintf(stderr, "test DEFER failed: %d\n", ret);
return ret;
}
return T_EXIT_PASS;
}
|