• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <errno.h>
2 #include <gtest/gtest.h>
3 #include <sys/epoll.h>
4 
5 using namespace testing::ext;
6 
7 class LinuxEpollctlTest : public testing::Test {
SetUp()8     void SetUp() override {}
TearDown()9     void TearDown() override {}
10 };
11 
12 /**
13  * @tc.name: epoll_ctl_001
14  * @tc.desc: This test verifies whether successfully adding a file descriptor (fds [0]) to the created epoll instance
15  *           will return a successful result.
16  * @tc.type: FUNC
17  */
18 HWTEST_F(LinuxEpollctlTest, epoll_ctl_001, TestSize.Level1)
19 {
20     int epollFd = epoll_create(1);
21     ASSERT_NE(epollFd, -1);
22     int fds[2];
23     epoll_event ev;
24     EXPECT_TRUE(epoll_ctl(epollFd, EPOLL_CTL_ADD, fds[0], &ev) != -1);
25     close(epollFd);
26 }
27 
28 /**
29  * @tc.name: epoll_ctl_002
30  * @tc.desc: This test verifies the call to epoll_ When using the ctl function, use an invalid operation parameter
31  *           EPOLL_CTL_MOD (value 3) will cause the function to return -1.
32  * @tc.type: FUNC
33  */
34 HWTEST_F(LinuxEpollctlTest, epoll_ctl_002, TestSize.Level1)
35 {
36     int epollFd = epoll_create(1);
37     ASSERT_NE(epollFd, -1);
38     int fds[2];
39     epoll_event ev;
40     EXPECT_TRUE(epoll_ctl(epollFd, EPOLL_CTL_MOD, fds[0], &ev) == -1);
41     close(epollFd);
42 }
43 
44 /**
45  * @tc.name: epoll_ctl_003
46  * @tc.desc: This test verifies the call to epoll_ When using the ctl function, use EPOLL_CTL_DEL operation parameter
47  *           deleting an unregistered file descriptor will result in the function returning -1.
48  * @tc.type: FUNC
49  */
50 HWTEST_F(LinuxEpollctlTest, epoll_ctl_003, TestSize.Level1)
51 {
52     int epollFd = epoll_create(1);
53     ASSERT_NE(epollFd, -1);
54     int fds[2];
55     epoll_event ev;
56     EXPECT_TRUE(epoll_ctl(epollFd, EPOLL_CTL_DEL, fds[0], &ev) == -1);
57     close(epollFd);
58 }
59