1//===-- Unittests for epoll_wait ------------------------------------------===//
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#include "hdr/sys_epoll_macros.h"
9#include "hdr/types/struct_epoll_event.h"
10#include "src/sys/epoll/epoll_create1.h"
11#include "src/sys/epoll/epoll_ctl.h"
12#include "src/sys/epoll/epoll_wait.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
19using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
20using LlvmLibcEpollWaitTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
21
22TEST_F(LlvmLibcEpollWaitTest, 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 // Timeout of 0 causes immediate return. We just need to check that the
39 // interface works, we're not testing the kernel behavior here.
40 ASSERT_THAT(LIBC_NAMESPACE::epoll_wait(epfd, &event, 1, 0), Succeeds());
41
42 ASSERT_THAT(LIBC_NAMESPACE::epoll_wait(-1, &event, 1, 0), Fails(EBADF));
43
44 ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event),
45 Succeeds());
46
47 ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());
48 ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());
49 ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds());
50}
51

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of libc/test/src/sys/epoll/linux/epoll_wait_test.cpp