1 | //===-- Unittests for epoll_ctl -------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "hdr/sys_epoll_macros.h" |
10 | #include "hdr/types/struct_epoll_event.h" |
11 | #include "src/errno/libc_errno.h" |
12 | #include "src/sys/epoll/epoll_create1.h" |
13 | #include "src/sys/epoll/epoll_ctl.h" |
14 | #include "src/unistd/close.h" |
15 | #include "src/unistd/pipe.h" |
16 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
17 | #include "test/UnitTest/Test.h" |
18 | |
19 | using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; |
20 | |
21 | TEST(LlvmLibcEpollCtlTest, Basic) { |
22 | int epfd = LIBC_NAMESPACE::epoll_create1(flags: 0); |
23 | ASSERT_GT(epfd, 0); |
24 | ASSERT_ERRNO_SUCCESS(); |
25 | |
26 | int pipefd[2]; |
27 | |
28 | ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds()); |
29 | |
30 | epoll_event event; |
31 | event.events = EPOLLOUT; |
32 | event.data.fd = pipefd[0]; |
33 | |
34 | ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), |
35 | Succeeds()); |
36 | |
37 | // adding the same file fail. |
38 | ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), |
39 | Fails(EEXIST)); |
40 | |
41 | ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event), |
42 | Succeeds()); |
43 | |
44 | ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds()); |
45 | ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds()); |
46 | ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds()); |
47 | } |
48 | |