aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/liburing/test/teardowns.c
blob: 4dfb20ef89fcbb78d162ec5dc6cfbd3c78c077f8 (plain) (blame)
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
#include "../config-host.h"
/* SPDX-License-Identifier: MIT */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>

#include "liburing.h"

static void loop(void)
{
	int i, ret = 0;

	for (i = 0; i < 100; i++) {
		struct io_uring ring;
		int fd;

		memset(&ring, 0, sizeof(ring));
		fd = io_uring_queue_init(0xa4, &ring, 0);
		if (fd >= 0) {
			close(fd);
			continue;
		}
		if (fd != -ENOMEM)
			ret++;
	}
	exit(ret);
}

int main(int argc, char *argv[])
{
	int i, ret, status;

	if (argc > 1)
		return 0;

	for (i = 0; i < 12; i++) {
		if (!fork()) {
			loop();
			break;
		}
	}

	ret = 0;
	for (i = 0; i < 12; i++) {
		if (waitpid(-1, &status, 0) < 0) {
			perror("waitpid");
			return 1;
		}
		if (WEXITSTATUS(status))
			ret++;
	}

	return ret;
}