1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
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 <gtest/gtest.h>
17 #include <iostream>
18
19 #define private public
20 #define protected public
21 #include "sched_policy.h"
22 #include "supervisor.h"
23 #include "cgroup_adjuster.h"
24 #undef private
25 #undef protected
26
27 using namespace testing::ext;
28 using namespace OHOS::ResourceSchedule::CgroupSetting;
29
30 namespace OHOS {
31 namespace ResourceSchedule {
32 namespace CgroupSetting {
33 class ProcessGroupSubTest : public testing::Test {
34 public:
35 static void SetUpTestCase(void);
36 static void TearDownTestCase(void);
37 void SetUp();
38 void TearDown();
39 };
40
SetUpTestCase(void)41 void ProcessGroupSubTest::SetUpTestCase(void)
42 {
43 }
44
TearDownTestCase(void)45 void ProcessGroupSubTest::TearDownTestCase(void)
46 {
47 }
48
SetUp(void)49 void ProcessGroupSubTest::SetUp(void)
50 {
51 }
52
TearDown(void)53 void ProcessGroupSubTest::TearDown(void)
54 {
55 }
56
57 /**
58 * @tc.name: ProcessGroupSubTest_SchedPolicyType_001
59 * @tc.desc: Get SchedPolicy Type
60 * @tc.type: FUNC
61 * @tc.require: issueI798UT
62 * @tc.desc:
63 */
64 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_001, Function | MediumTest | Level0)
65 {
66 EXPECT_EQ(SP_BACKGROUND, 1);
67 }
68
69 /*
70 * @tc.number: ProcessGroupSubTest_SchedPolicyType_002
71 * @tc.name: Get SchedPolicy Type
72 * @tc.type: FUNC
73 * @tc.require: issueI798UT
74 * @tc.desc:
75 */
76 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_002, Function | MediumTest | Level0)
77 {
78 EXPECT_EQ(SP_FOREGROUND, 2);
79 }
80
81 /*
82 * @tc.number: ProcessGroupSubTest_SchedPolicyType_003
83 * @tc.name: Get SchedPolicy Full Name
84 * @tc.type: FUNC
85 * @tc.require: issueI798UT
86 * @tc.desc:
87 */
88 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_003, Function | MediumTest | Level0)
89 {
90 const char* policyName = GetSchedPolicyFullName(SP_DEFAULT);
91 EXPECT_TRUE(!strcmp(policyName, "sp_default"));
92 }
93
94 /*
95 * @tc.number: ProcessGroupSubTest_SchedPolicyType_004
96 * @tc.name: Get SchedPolicy Full Name
97 * @tc.type: FUNC
98 * @tc.require: issueI798UT
99 * @tc.desc:
100 */
101 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_004, Function | MediumTest | Level0)
102 {
103 const char* policyName = GetSchedPolicyFullName(SP_BACKGROUND);
104 EXPECT_TRUE(!strcmp(policyName, "sp_background"));
105 }
106
107 /*
108 * @tc.number: ProcessGroupSubTest_SchedPolicyType_005
109 * @tc.name: Get SchedPolicy Full Name
110 * @tc.type: FUNC
111 * @tc.require: issueI798UT
112 * @tc.desc:
113 */
114 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_005, Function | MediumTest | Level0)
115 {
116 const char* policyName = GetSchedPolicyFullName(SP_FOREGROUND);
117 EXPECT_TRUE(!strcmp(policyName, "sp_foreground"));
118 }
119
120 /*
121 * @tc.number: ProcessGroupSubTest_SchedPolicyType_006
122 * @tc.name: Get SchedPolicy Full Name
123 * @tc.type: FUNC
124 * @tc.require: issueI798UT
125 * @tc.desc:
126 */
127 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_006, Function | MediumTest | Level0)
128 {
129 const char* policyName = GetSchedPolicyFullName(SP_SYSTEM_BACKGROUND);
130 EXPECT_TRUE(!strcmp(policyName, "sp_system_background"));
131 }
132
133 /*
134 * @tc.number: ProcessGroupSubTest_SchedPolicyType_007
135 * @tc.name: Get SchedPolicy Full Name
136 * @tc.type: FUNC
137 * @tc.require: issueI798UT
138 * @tc.desc:
139 */
140 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_007, Function | MediumTest | Level0)
141 {
142 const char* policyName = GetSchedPolicyFullName(SP_TOP_APP);
143 EXPECT_TRUE(!strcmp(policyName, "sp_top_app"));
144 }
145
146 /*
147 * @tc.number: ProcessGroupSubTest_SchedPolicyType_008
148 * @tc.name: Get SchedPolicy Shortened Name
149 * @tc.type: FUNC
150 * @tc.require: issueI798UT
151 * @tc.desc:
152 */
153 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_008, Function | MediumTest | Level0)
154 {
155 const char* policyName = GetSchedPolicyShortenedName(SP_DEFAULT);
156 EXPECT_TRUE(!strcmp(policyName, "df"));
157 }
158
159 /*
160 * @tc.number: ProcessGroupSubTest_SchedPolicyType_009
161 * @tc.name: Get SchedPolicy Shortened Name
162 * @tc.type: FUNC
163 * @tc.require: issueI798UT
164 * @tc.desc:
165 */
166 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_009, Function | MediumTest | Level0)
167 {
168 const char* policyName = GetSchedPolicyShortenedName(SP_FOREGROUND);
169 EXPECT_TRUE(!strcmp(policyName, "fg"));
170 }
171
172 /*
173 * @tc.number: ProcessGroupSubTest_SchedPolicyType_010
174 * @tc.name: Get SchedPolicy Shortened Name
175 * @tc.type: FUNC
176 * @tc.require: issueI798UT
177 * @tc.desc:
178 */
179 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_SchedPolicyType_010, Function | MediumTest | Level0)
180 {
181 const char* policyName = GetSchedPolicyShortenedName(SP_BACKGROUND);
182 EXPECT_TRUE(!strcmp(policyName, "bg"));
183 }
184
185 /*
186 * @tc.number: ProcessGroupSubTest_AdjustProcess_001
187 * @tc.name: Adjust Fork Process Schedule
188 * @tc.type: FUNC
189 * @tc.require: issueI9TPCH
190 * @tc.desc:
191 */
192 HWTEST_F(ProcessGroupSubTest, ProcessGroupSubTest_AdjustProcess_001, Function | MediumTest | Level1)
193 {
194 auto application = new Application(20150011);
195 EXPECT_TRUE(application != nullptr);
196 auto pr = new ProcessRecord(20150011, 9050);
197 EXPECT_TRUE(pr != nullptr);
198 CgroupAdjuster::GetInstance().AdjustForkProcessGroup(*application, *pr);
199 SUCCEED();
200 }
201 } // namespace CgroupSetting
202 } // namespace ResourceSchedule
203 } // namespace OHOS
204