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