[PATCH 1/5] syscalls: Add epoll_ctl07
Cyril Hrubis <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
The epoll_ctl05 excercies the loop detector with a longer chain this tests does the same but only with two epoll fds. Signed-off-by: Cyril Hrubis <[email protected]> --- runtest/syscalls | 1 + .../kernel/syscalls/epoll_ctl/.gitignore | 1 + .../kernel/syscalls/epoll_ctl/epoll_ctl07.c | 60 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl07.c diff --git a/runtest/syscalls b/runtest/syscalls index 789d1550d..9f46e28de 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -188,6 +188,7 @@ epoll_ctl03 epoll_ctl03 epoll_ctl04 epoll_ctl04 epoll_ctl05 epoll_ctl05 epoll_ctl06 epoll_ctl06 +epoll_ctl07 epoll_ctl07 epoll_wait01 epoll_wait01 epoll_wait02 epoll_wait02 diff --git a/testcases/kernel/syscalls/epoll_ctl/.gitignore b/testcases/kernel/syscalls/epoll_ctl/.gitignore index 9c555f41b..66da2dbfb 100644 --- a/testcases/kernel/syscalls/epoll_ctl/.gitignore +++ b/testcases/kernel/syscalls/epoll_ctl/.gitignore @@ -4,3 +4,4 @@ epoll_ctl03 epoll_ctl04 epoll_ctl05 epoll_ctl06 +epoll_ctl07 diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl07.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl07.c new file mode 100644 index 000000000..6e9b3a1a2 --- /dev/null +++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl07.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 Cyril Hrubis <[email protected]> + */ + +/*\ + * Verify that :manpage:`epoll_ctl(2)` fails with ELOOP when an + * ``EPOLL_CTL_ADD`` operation would create a minimal two-instance cycle of + * epoll instances monitoring one another. + * + * This is the shortest path through the kernel loop detector. The existing + * epoll_ctl05 test exercises a long chain closed into a loop. + * + * [Algorithm] + * + * - create two epoll instances ep_a and ep_b + * - add ep_b into ep_a with EPOLL_CTL_ADD (succeeds) + * - add ep_a into ep_b with EPOLL_CTL_ADD, which must fail with ELOOP + */ + +#include <sys/epoll.h> + +#include "tst_test.h" +#include "tst_epoll.h" + +static int ep_a = -1, ep_b = -1; + +static void setup(void) +{ + struct epoll_event ev = {.events = EPOLLIN}; + + ep_a = SAFE_EPOLL_CREATE1(0); + ep_b = SAFE_EPOLL_CREATE1(0); + + ev.data.fd = ep_b; + SAFE_EPOLL_CTL(ep_a, EPOLL_CTL_ADD, ep_b, &ev); +} + +static void cleanup(void) +{ + if (ep_a != -1) + SAFE_CLOSE(ep_a); + + if (ep_b != -1) + SAFE_CLOSE(ep_b); +} + +static void run(void) +{ + struct epoll_event ev = {.events = EPOLLIN, .data.fd = ep_a}; + + TST_EXP_FAIL(epoll_ctl(ep_b, EPOLL_CTL_ADD, ep_a, &ev), ELOOP, + "epoll_ctl(EPOLL_CTL_ADD) closing a two-instance cycle"); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, +}; -- 2.54.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp