1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Linux Test Project, 2021
4 * Author: Xie Ziyao <ziyaoxie@outlook.com>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Verify that the maximum number of nesting allowed inside epoll sets is 5,
11 * otherwise epoll_ctl fails with EINVAL.
12 */
13
14 #include <poll.h>
15 #include <sys/epoll.h>
16
17 #include "tst_test.h"
18
19 #define MAX_DEPTH 5
20
21 static int epfd, new_epfd;
22 static int fd[2];
23
24 static struct epoll_event events = {.events = EPOLLIN};
25
setup(void)26 static void setup(void)
27 {
28 int depth;
29
30 SAFE_PIPE(fd);
31
32 for (depth = 0, epfd = fd[0]; depth < MAX_DEPTH; depth++) {
33 new_epfd = epoll_create(1);
34 if (new_epfd == -1)
35 tst_brk(TBROK | TERRNO, "fail to create epoll instance");
36
37 events.data.fd = epfd;
38 if (epoll_ctl(new_epfd, EPOLL_CTL_ADD, epfd, &events))
39 tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
40
41 epfd = new_epfd;
42 }
43 }
44
cleanup(void)45 static void cleanup(void)
46 {
47 if (fd[0])
48 SAFE_CLOSE(fd[0]);
49
50 if (fd[1])
51 SAFE_CLOSE(fd[1]);
52 }
53
verify_epoll_ctl(void)54 static void verify_epoll_ctl(void)
55 {
56 new_epfd = epoll_create(1);
57 if (new_epfd == -1)
58 tst_brk(TBROK | TERRNO, "fail to create epoll instance");
59
60 events.data.fd = epfd;
61 TST_EXP_FAIL(epoll_ctl(new_epfd, EPOLL_CTL_ADD, epfd, &events), EINVAL,
62 "epoll_clt(..., EPOLL_CTL_ADD, ...) with number of nesting is 5");
63 }
64
65 static struct tst_test test = {
66 .setup = setup,
67 .cleanup = cleanup,
68 .test_all = verify_epoll_ctl,
69 };
70