brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 6da070e Raw
59 lines · cpp
1//===-- Unittests for epoll_pwait2 ----------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8#include "hdr/sys_epoll_macros.h"9#include "hdr/types/struct_epoll_event.h"10#include "hdr/types/struct_timespec.h"11#include "src/sys/epoll/epoll_create1.h"12#include "src/sys/epoll/epoll_ctl.h"13#include "src/sys/epoll/epoll_pwait2.h"14#include "src/unistd/close.h"15#include "src/unistd/pipe.h"16#include "test/UnitTest/ErrnoCheckingTest.h"17#include "test/UnitTest/ErrnoSetterMatcher.h"18#include "test/UnitTest/Test.h"19 20using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;21using LlvmLibcEpollPwaitTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;22 23TEST_F(LlvmLibcEpollPwaitTest, Basic) {24  int epfd = LIBC_NAMESPACE::epoll_create1(0);25  ASSERT_GT(epfd, 0);26  ASSERT_ERRNO_SUCCESS();27 28  int pipefd[2];29 30  ASSERT_THAT(LIBC_NAMESPACE::pipe(pipefd), Succeeds());31 32  epoll_event event;33  event.events = EPOLLOUT;34  event.data.fd = pipefd[0];35 36  timespec time_spec;37  time_spec.tv_sec = 0;38  time_spec.tv_nsec = 0;39 40  ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_ADD, pipefd[0], &event),41              Succeeds());42 43  // Timeout of 0 causes immediate return. We just need to check that the44  // interface works, we're not testing the kernel behavior here.45  ASSERT_THAT(46      LIBC_NAMESPACE::epoll_pwait2(epfd, &event, 1, &time_spec, nullptr),47      Succeeds());48 49  ASSERT_THAT(LIBC_NAMESPACE::epoll_pwait2(-1, &event, 1, &time_spec, nullptr),50              Fails(EBADF));51 52  ASSERT_THAT(LIBC_NAMESPACE::epoll_ctl(epfd, EPOLL_CTL_DEL, pipefd[0], &event),53              Succeeds());54 55  ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[0]), Succeeds());56  ASSERT_THAT(LIBC_NAMESPACE::close(pipefd[1]), Succeeds());57  ASSERT_THAT(LIBC_NAMESPACE::close(epfd), Succeeds());58}59