• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <poll.h>
2 #include <fortify/poll.h>
3 #include <gtest/gtest.h>
4 
5 using namespace testing::ext;
6 constexpr int TIME_OUT = 1000;
7 
8 class FortifyPollchkTest : public testing::Test {
SetUp()9     void SetUp() override {}
TearDown()10     void TearDown() override {}
11 };
12 
13 class FortifyPollchkDeathTest : public testing::Test {
SetUp()14     void SetUp() override {}
TearDown()15     void TearDown() override {}
16 };
17 
18 /**
19  * @tc.name: __ppoll_chk_001
20  * @tc.desc: Verify if the __poll_chk is functioning properly.
21  * @tc.type: FUNC
22  * */
23 HWTEST_F(FortifyPollchkTest, __poll_chk_001, TestSize.Level1)
24 {
25     struct pollfd fds[1];
26     fds[0].fd = 0;
27     fds[0].events = POLLIN;
28     int ret = __poll_chk(fds, 0, 1, sizeof(fds));
29     EXPECT_GE(ret, 0);
30 }
31 
32 /**
33  * @tc.name: __poll_chk_002
34  * @tc.desc: Pass an incorrect buffer size to the function.
35  * @tc.type: FUNC
36  * */
37 HWTEST_F(FortifyPollchkDeathTest, __poll_chk_002, TestSize.Level1)
38 {
39     struct pollfd fds[1];
40     fds[0].fd = 1;
41     fds[0].events = POLLIN;
42     nfds_t nfds = 1;
43     size_t fdsLen = sizeof(struct pollfd) * (nfds - 1);
44     EXPECT_DEATH(__poll_chk(fds, nfds, TIME_OUT, fdsLen), "");
45 }