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 <malloc.h>
25 #include <arpa/inet.h>
26 #include <gtest/gtest.h>
27 #include <netinet/in.h>
28 #include <sys/stat.h>
29 #include <sys/mman.h>
30 #include <sys/socket.h>
31 #include <sys/sysinfo.h>
32 #include <sys/types.h>
33 #include "securec.h"
34 
35 using namespace testing::ext;
36 
37 class HatsSysinfoTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43 private:
44 };
SetUp()45 void HatsSysinfoTest::SetUp()
46 {
47 }
48 
TearDown()49 void HatsSysinfoTest::TearDown()
50 {
51 }
52 
SetUpTestCase()53 void HatsSysinfoTest::SetUpTestCase()
54 {
55 }
56 
TearDownTestCase()57 void HatsSysinfoTest::TearDownTestCase()
58 {
59 }
60 
61 /*
62  * @tc.number : SUB_KERNEL_SYSCALL_SYSINFO_0100
63  * @tc.name   : SysinfoSuccess_0001
64  * @tc.desc   : Obtain system statistical information successfully.
65  * @tc.size   : MediumTest
66  * @tc.type   : Function
67  * @tc.level  : Level 1
68  */
HWTEST_F(HatsSysinfoTest, SysinfoSuccess_0001, Function | MediumTest | Level1)69 HWTEST_F(HatsSysinfoTest, SysinfoSuccess_0001, Function | MediumTest | Level1)
70 {
71     struct sysinfo info;
72     int ret = sysinfo(&info);
73     EXPECT_EQ(ret, 0);
74     EXPECT_TRUE(info.uptime > 0);
75     EXPECT_TRUE(info.mem_unit > 0);
76 }
77 
78 /*
79  * @tc.number : SUB_KERNEL_SYSCALL_SYSINFO_0200
80  * @tc.name   : SysinfoNullptrFailed_0002
81  * @tc.desc   : sysinfo nullptr failed errno EFAULT.
82  * @tc.size   : MediumTest
83  * @tc.type   : Function
84  * @tc.level  : Level 2
85  */
HWTEST_F(HatsSysinfoTest, SysinfoNullptrFailed_0002, Function | MediumTest | Level2)86 HWTEST_F(HatsSysinfoTest, SysinfoNullptrFailed_0002, Function | MediumTest | Level2)
87 {
88     errno = 0;
89     int ret = sysinfo(nullptr);
90     EXPECT_EQ(ret, -1);
91     EXPECT_EQ(errno, EFAULT);
92 }