• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <pthread.h>
26 #include <syscall.h>
27 #include <arpa/inet.h>
28 #include <gtest/gtest.h>
29 #include <linux/futex.h>
30 #include <netinet/in.h>
31 #include <sys/stat.h>
32 #include <sys/mman.h>
33 #include <sys/socket.h>
34 #include <sys/sysinfo.h>
35 #include <sys/types.h>
36 #include <sys/prctl.h>
37 #include "securec.h"
38 
39 using namespace testing::ext;
40 
41 static const int INVALID_FLAGS = -1;
42 
43 class HatsGetrobustlistTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47     void SetUp();
48     void TearDown();
49 private:
50 };
SetUp()51 void HatsGetrobustlistTest::SetUp()
52 {
53 }
54 
TearDown()55 void HatsGetrobustlistTest::TearDown()
56 {
57 }
58 
SetUpTestCase()59 void HatsGetrobustlistTest::SetUpTestCase()
60 {
61 }
62 
TearDownTestCase()63 void HatsGetrobustlistTest::TearDownTestCase()
64 {
65 }
66 
67 /*
68  * @tc.number : SUB_KERNEL_SYSCALL_GETROBUSTLIST_0100
69  * @tc.name   : GetrobustlistSuccess_0001
70  * @tc.desc   : Get robust_list success.
71  * @tc.size   : MediumTest
72  * @tc.type   : Function
73  * @tc.level  : Level 1
74  */
75 HWTEST_F(HatsGetrobustlistTest, GetrobustlistSuccess_0001, Function | MediumTest | Level1)
76 {
77     struct robust_list_head head;
78     int len = sizeof(struct robust_list_head);
79     int ret = syscall(__NR_get_robust_list, 0, &head, &len);
80     EXPECT_EQ(ret, 0);
81 }
82 
83 /*
84  * @tc.number : SUB_KERNEL_SYSCALL_GETROBUSTLIST_0200
85  * @tc.name   : GetrobustlistInvalidFlagFailed_0002
86  * @tc.desc   : Get robust_list invalid Flags failed errno ESRCH.
87  * @tc.size   : MediumTest
88  * @tc.type   : Function
89  * @tc.level  : Level 2
90  */
91 HWTEST_F(HatsGetrobustlistTest, GetrobustlistInvalidFlagFailed_0002, Function | MediumTest | Level2)
92 {
93     struct robust_list_head head;
94     int len = sizeof(struct robust_list_head);
95     errno = 0;
96     int ret = syscall(__NR_get_robust_list, INVALID_FLAGS, &head, &len);
97     EXPECT_EQ(ret, -1);
98     EXPECT_EQ(errno, ESRCH);
99 }
100 
101 /*
102  * @tc.number : SUB_KERNEL_SYSCALL_GETROBUSTLIST_0300
103  * @tc.name   : GetrobustlistNullptrFailed_0003
104  * @tc.desc   : Get robust_list nullptr failed errno EFAULT.
105  * @tc.size   : MediumTest
106  * @tc.type   : Function
107  * @tc.level  : Level 2
108  */
109 HWTEST_F(HatsGetrobustlistTest, GetrobustlistNullptrFailed_0003, Function | MediumTest | Level2)
110 {
111     errno = 0;
112     int ret = syscall(__NR_get_robust_list, 0, nullptr, nullptr);
113     EXPECT_EQ(ret, -1);
114     EXPECT_EQ(errno, EFAULT);
115 }