1 #include <poll.h> 2 #include <fortify/poll.h> 3 #include <gtest/gtest.h> 4 5 using namespace testing::ext; 6 7 class FortifyPpollchkTest : public testing::Test { SetUp()8 void SetUp() override {} TearDown()9 void TearDown() override {} 10 }; 11 12 /** 13 * @tc.name: __ppoll_chk_001 14 * @tc.desc: Verify if the __ppoll_chk is functioning properly. 15 * @tc.type: FUNC 16 * */ 17 HWTEST_F(FortifyPpollchkTest, __ppoll_chk_001, TestSize.Level1) 18 { 19 struct pollfd fds[1]; 20 fds[0].fd = 0; 21 fds[0].events = POLLIN; 22 struct timespec ts; 23 ts.tv_nsec = 1000; 24 int ret = __ppoll_chk(fds, 1, &ts, nullptr, sizeof(fds)); 25 EXPECT_GE(ret, 0); 26 } 27 28 /** 29 * @tc.name: __ppoll_chk_002 30 * @tc.desc: Set the fds parameter to nullptr and verify if the function will return -1. 31 * @tc.type: FUNC 32 * */ 33 HWTEST_F(FortifyPpollchkTest, __ppoll_chk_002, TestSize.Level1) 34 { 35 int nfds = 1; 36 struct pollfd* fds = nullptr; 37 const struct timespec* timeout = nullptr; 38 const sigset_t* sigMask = nullptr; 39 int ret = __ppoll_chk(fds, nfds, timeout, sigMask, sizeof(struct pollfd)); 40 EXPECT_EQ(-1, ret); 41 }