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 HatsEpollCreateTest : public testing::Test {
35public:
36    static void SetUpTestCase();
37    static void TearDownTestCase();
38    void SetUp();
39    void TearDown();
40private:
41};
42void HatsEpollCreateTest::SetUp()
43{
44}
45
46void HatsEpollCreateTest::TearDown()
47{
48}
49
50void HatsEpollCreateTest::SetUpTestCase()
51{
52}
53
54void HatsEpollCreateTest::TearDownTestCase()
55{
56}
57
58/*
59 * @tc.number : SUB_KERNEL_SYSCALL_EPOLLCREATE_0100
60 * @tc.name   : EpollCreateFdSuccess_0001
61 * @tc.desc   : epoll_create epoll fd success.
62 * @tc.size   : MediumTest
63 * @tc.type   : Function
64 * @tc.level  : Level 1
65 */
66HWTEST_F(HatsEpollCreateTest, EpollCreateFdSuccess_0001, Function | MediumTest | Level1)
67{
68    int fd = epoll_create(1);
69    EXPECT_TRUE(fd > 0);
70    close(fd);
71}
72
73/*
74 * @tc.number : SUB_KERNEL_SYSCALL_EPOLLCREATE1_0200
75 * @tc.name   : EpollCreate1FdSuccess_0002
76 * @tc.desc   : epoll_create1 epoll fd and EPOLL_CLOEXEC test success.
77 * @tc.size   : MediumTest
78 * @tc.type   : Function
79 * @tc.level  : Level 1
80 */
81HWTEST_F(HatsEpollCreateTest, EpollCreatelFdSuccess_0002, Function | MediumTest | Level1)
82{
83    int fd = epoll_create1(EPOLL_CLOEXEC);
84    EXPECT_TRUE(fd > 0);
85    close(fd);
86}
87
88/*
89 * @tc.number : SUB_KERNEL_SYSCALL_EPOLLCREATE1_0300
90 * @tc.name   : EpollCreate1UseInvalidParamFailed_0003
91 * @tc.desc   : epoll_create1 epoll fd use invalid param failed.
92 * @tc.size   : MediumTest
93 * @tc.type   : Function
94 * @tc.level  : Level 2
95 */
96HWTEST_F(HatsEpollCreateTest, EpollCreate1UseInvalidParamFailed_0003, Function | MediumTest | Level2)
97{
98    errno = 0;
99    int fd = epoll_create1(-1);
100    EXPECT_TRUE(fd < 0);
101    EXPECT_EQ(errno, EINVAL);
102    close(fd);
103}
104