1/* 2 * Copyright (C) 2024 HiHope Open Source Organization. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <cerrno> 17#include <cstdio> 18#include <cstdlib> 19#include <csignal> 20#include <string> 21#include <vector> 22#include <fcntl.h> 23#include <unistd.h> 24#include <gtest/gtest.h> 25#include <sys/epoll.h> 26#include <sys/stat.h> 27#include <sys/mman.h> 28#include <sys/syscall.h> 29#include <sys/types.h> 30#include "securec.h" 31 32using namespace testing::ext; 33 34class HatsEpollPwaitTest : public testing::Test { 35public: 36 static void SetUpTestCase(); 37 static void TearDownTestCase(); 38 void SetUp(); 39 void TearDown(); 40private: 41}; 42void HatsEpollPwaitTest::SetUp() 43{ 44} 45 46void HatsEpollPwaitTest::TearDown() 47{ 48} 49 50void HatsEpollPwaitTest::SetUpTestCase() 51{ 52} 53 54void HatsEpollPwaitTest::TearDownTestCase() 55{ 56} 57 58/* 59 * @tc.number : SUB_KERNEL_SYSCALL_EPOLLPWAIT_0100 60 * @tc.name : EpollPwaitWithNoSigsetSuccess_0001 61 * @tc.desc : epoll_pwait with no sigset test success. 62 * @tc.size : MediumTest 63 * @tc.type : Function 64 * @tc.level : Level 1 65 */ 66HWTEST_F(HatsEpollPwaitTest, EpollPwaitWithNoSigsetSuccess_0001, Function | MediumTest | Level1) 67{ 68 int fd = epoll_create(1); 69 EXPECT_TRUE(fd > 0); 70 71 struct epoll_event events[1]; 72 int ret = epoll_pwait(fd, events, 1, 1, nullptr); 73 EXPECT_EQ(ret, 0); 74 75 close(fd); 76} 77 78/* 79 * @tc.number : SUB_KERNEL_SYSCALL_EPOLLPWAIT_0200 80 * @tc.name : EpollPwaitWithSIGPIPESigsetSuccess_0002 81 * @tc.desc : epoll_pwait with SIGPIPE sigset test success. 82 * @tc.size : MediumTest 83 * @tc.type : Function 84 * @tc.level : Level 1 85 */ 86HWTEST_F(HatsEpollPwaitTest, EpollPwaitWithSIGPIPESigsetSuccess_0002, Function | MediumTest | Level1) 87{ 88 int ret; 89 int fd = epoll_create(1); 90 EXPECT_TRUE(fd > 0); 91 92 struct epoll_event events[1]; 93 sigset_t ss; 94 ret = sigemptyset(&ss); 95 EXPECT_EQ(ret, 0); 96 ret = sigaddset(&ss, SIGPIPE); 97 EXPECT_EQ(ret, 0); 98 99 ret = epoll_pwait(fd, events, 1, 1, &ss); 100 EXPECT_EQ(ret, 0); 101 102 close(fd); 103} 104 105/* 106 * @tc.number : SUB_KERNEL_SYSCALL_EPOLLPWAIT_0300 107 * @tc.name : EpollPwaitUseInvalidFdFailed_0003 108 * @tc.desc : epoll_pwait use invalid fd failed. 109 * @tc.size : MediumTest 110 * @tc.type : Function 111 * @tc.level : Level 2 112 */ 113HWTEST_F(HatsEpollPwaitTest, EpollPwaitUseInvalidFdFailed_0003, Function | MediumTest | Level2) 114{ 115 struct epoll_event events[1]; 116 errno = 0; 117 int ret = epoll_pwait(-1, events, 1, 1, nullptr); 118 EXPECT_EQ(ret, -1); 119 EXPECT_EQ(errno, EBADF); 120} 121 122/* 123 * @tc.number : SUB_KERNEL_SYSCALL_EPOLLPWAIT_0400 124 * @tc.name : EpollPwaitEINVALFailed_0004 125 * @tc.desc : epoll_pwait with EINVAL failed. 126 * @tc.size : MediumTest 127 * @tc.type : Function 128 * @tc.level : Level 2 129 */ 130HWTEST_F(HatsEpollPwaitTest, EpollPwaitEINVALFailed_0004, Function | MediumTest | Level2) 131{ 132 struct epoll_event events[1]; 133 errno = 0; 134 int ret = epoll_pwait(-1, events, -1, 1, nullptr); 135 EXPECT_EQ(ret, -1); 136 EXPECT_EQ(errno, EINVAL); 137}