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/sys/epoll/epoll_create1.h" |
12 | #include "src/sys/epoll/epoll_ctl.h" |
13 | #include "src/unistd/close.h" |
14 | #include "src/unistd/pipe.h" |
15 | #include "test/UnitTest/ErrnoCheckingTest.h" |
16 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
17 | #include "test/UnitTest/Test.h" |
18 | |
19 | using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; |
20 | using LlvmLibcEpollCtlTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; |
21 | |
22 | TEST_F(LlvmLibcEpollCtlTest, Basic) { |
23 | int epfd = LIBC_NAMESPACE::epoll_create1(0); |
24 | ASSERT_GT(epfd, 0); |
25 | ASSERT_ERRNO_SUCCESS(); |
26 | |
27 | int pipefd[2]; |
28 | |
29 | ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds()); |
30 | |
31 | epoll_event event; |
32 | event.events = EPOLLOUT; |
33 | event.data.fd = pipefd[0]; |
34 | |
35 | ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), |
36 | Succeeds()); |
37 | |
38 | // adding the same file fail. |
39 | ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event), |
40 | Fails(EEXIST)); |
41 | |
42 | ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event), |
43 | Succeeds()); |
44 | |
45 | ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds()); |
46 | ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds()); |
47 | ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds()); |
48 | } |
49 | |