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 <netinet/in.h>
30 #include <sys/stat.h>
31 #include <sys/mman.h>
32 #include <sys/socket.h>
33 #include <sys/sysinfo.h>
34 #include <sys/types.h>
35 #include <sys/prctl.h>
36 #include "securec.h"
37
38 using namespace testing::ext;
39
40 struct RobustList {
41 struct RobustList *next;
42 };
43
SetRobustList(int tid,void * list,size_t len)44 int SetRobustList(int tid, void *list, size_t len)
45 {
46 return syscall(__NR_set_robust_list, tid, list, len);
47 }
48
49 class HatsSetrobustlistTest : public testing::Test {
50 public:
51 static void SetUpTestCase();
52 static void TearDownTestCase();
53 void SetUp();
54 void TearDown();
55 private:
56 };
SetUp()57 void HatsSetrobustlistTest::SetUp()
58 {
59 }
60
TearDown()61 void HatsSetrobustlistTest::TearDown()
62 {
63 }
64
SetUpTestCase()65 void HatsSetrobustlistTest::SetUpTestCase()
66 {
67 }
68
TearDownTestCase()69 void HatsSetrobustlistTest::TearDownTestCase()
70 {
71 }
72
73 /*
74 * @tc.number : SUB_KERNEL_SYSCALL_SETROBUSTLIST_0100
75 * @tc.name : SetrobustlistFailed_0001
76 * @tc.desc : Set robust_list failed.
77 * @tc.size : MediumTest
78 * @tc.type : Function
79 * @tc.level : Level 2
80 */
81 HWTEST_F(HatsSetrobustlistTest, SetrobustlistFailed_0001, Function | MediumTest | Level2)
82 {
83 pid_t tid = pthread_self();
84 struct RobustList *setRobustList = (struct RobustList *)malloc(sizeof(struct RobustList));
85 setRobustList->next = nullptr;
86
87 int ret = SetRobustList(tid, setRobustList, sizeof(struct RobustList));
88 EXPECT_EQ(ret, -1);
89 EXPECT_EQ(errno, EINVAL);
90 }
91