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
32using namespace testing::ext;
33
34class HatsSchedrrgetintervalTest : public testing::Test {
35public:
36static void SetUpTestCase();
37static void TearDownTestCase();
38void SetUp();
39void TearDown();
40private:
41};
42void HatsSchedrrgetintervalTest::SetUp()
43{
44}
45void HatsSchedrrgetintervalTest::TearDown()
46{
47}
48void HatsSchedrrgetintervalTest::SetUpTestCase()
49{
50}
51void 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 */
63HWTEST_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 */
79HWTEST_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