1 /* SPDX-License-Identifier: MIT */
2 /*
3 * Test that the sqthread goes to sleep around the specified time, and that
4 * the NEED_WAKEUP flag is then set.
5 */
6 #include <errno.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <sys/time.h>
11 #include "liburing.h"
12 #include "helpers.h"
13
main(int argc,char * argv[])14 int main(int argc, char *argv[])
15 {
16 struct io_uring_params p = {};
17 struct timeval tv;
18 struct io_uring ring;
19 int ret;
20
21 if (argc > 1)
22 return 0;
23
24 p.flags = IORING_SETUP_SQPOLL;
25 p.sq_thread_idle = 100;
26
27 ret = io_uring_queue_init_params(1, &ring, &p);
28 if (ret) {
29 if (geteuid()) {
30 printf("%s: skipped, not root\n", argv[0]);
31 return 0;
32 }
33 fprintf(stderr, "queue_init=%d\n", ret);
34 return 1;
35 }
36
37 gettimeofday(&tv, NULL);
38 do {
39 usleep(1000);
40 if ((*ring.sq.kflags) & IORING_SQ_NEED_WAKEUP)
41 return 0;
42 } while (mtime_since_now(&tv) < 1000);
43
44 return 1;
45 }
46