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 <ctime>
20 #include <string>
21 #include <vector>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <arpa/inet.h>
25 #include <gtest/gtest.h>
26 #include <netinet/in.h>
27 #include <sys/stat.h>
28 #include <sys/socket.h>
29 #include <sys/types.h>
30 #include "securec.h"
31 
32 using namespace testing::ext;
33 
34 class HatsSchedrrgetintervalTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp();
39 void TearDown();
40 private:
41 };
SetUp()42 void HatsSchedrrgetintervalTest::SetUp()
43 {
44 }
TearDown()45 void HatsSchedrrgetintervalTest::TearDown()
46 {
47 }
SetUpTestCase()48 void HatsSchedrrgetintervalTest::SetUpTestCase()
49 {
50 }
TearDownTestCase()51 void HatsSchedrrgetintervalTest::TearDownTestCase()
52 {
53 }
54 
55 /*
56  * @tc.number : SUB_KERNEL_SYSCALL_SCHEDRRGETINTERVAL_0100
57  * @tc.name   : SchedrrgetintervalGetRRTSuccess_0001
58  * @tc.desc   : sched_rr_get_interval get RR timespec of current thread success.
59  * @tc.size   : MediumTest
60  * @tc.type   : Function
61  * @tc.level  : Level 1
62  */
HWTEST_F(HatsSchedrrgetintervalTest, SchedrrgetintervalGetRRTSuccess_0001, Function | MediumTest | Level1)63 HWTEST_F(HatsSchedrrgetintervalTest, SchedrrgetintervalGetRRTSuccess_0001, Function | MediumTest | Level1)
64 {
65     int ret;
66     struct timespec timeSpec1;
67     ret = sched_rr_get_interval(0, &timeSpec1);
68     EXPECT_TRUE(ret == 0);
69 }
70 
71 /*
72  * @tc.number : SUB_KERNEL_SYSCALL_SCHEDRRGETINTERVAL_0200
73  * @tc.name   : SchedSchedrrgetintervalInvalidPIDFail_0002
74  * @tc.desc   : sched_rr_get_interval get RR timespec of an invalid pid fail.
75  * @tc.size   : MediumTest
76  * @tc.type   : Function
77  * @tc.level  : Level 2
78  */
HWTEST_F(HatsSchedrrgetintervalTest, SchedSchedrrgetintervalInvalidPIDFail_0002, Function | MediumTest | Level2)79 HWTEST_F(HatsSchedrrgetintervalTest, SchedSchedrrgetintervalInvalidPIDFail_0002, Function | MediumTest | Level2)
80 {
81     int ret;
82     pid_t pid = -1;
83     struct timespec timeSpec1;
84 
85     errno = 0;
86     ret = sched_rr_get_interval(pid, &timeSpec1);
87     EXPECT_TRUE(ret == -1);
88     EXPECT_EQ(errno, EINVAL);
89 }
90