xref: /aosp_15_r20/external/liburing/test/teardowns.c (revision 25da2bea747f3a93b4c30fd9708b0618ef55a0e6)
1 /* SPDX-License-Identifier: MIT */
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
8 #include <unistd.h>
9 #include <errno.h>
10 
11 #include "liburing.h"
12 
loop(void)13 static void loop(void)
14 {
15 	int i, ret = 0;
16 
17 	for (i = 0; i < 100; i++) {
18 		struct io_uring ring;
19 		int fd;
20 
21 		memset(&ring, 0, sizeof(ring));
22 		fd = io_uring_queue_init(0xa4, &ring, 0);
23 		if (fd >= 0) {
24 			close(fd);
25 			continue;
26 		}
27 		if (fd != -ENOMEM)
28 			ret++;
29 	}
30 	exit(ret);
31 }
32 
main(int argc,char * argv[])33 int main(int argc, char *argv[])
34 {
35 	int i, ret, status;
36 
37 	if (argc > 1)
38 		return 0;
39 
40 	for (i = 0; i < 12; i++) {
41 		if (!fork()) {
42 			loop();
43 			break;
44 		}
45 	}
46 
47 	ret = 0;
48 	for (i = 0; i < 12; i++) {
49 		if (waitpid(-1, &status, 0) < 0) {
50 			perror("waitpid");
51 			return 1;
52 		}
53 		if (WEXITSTATUS(status))
54 			ret++;
55 	}
56 
57 	return ret;
58 }
59