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 #define private public
17 #define protected public
18 #undef private
19 #undef protected
20
21 #include <gtest/gtest.h>
22 #include <gtest/hwext/gtest-multithread.h>
23 #include "socperf_client.h"
24 #include "socperf.h"
25 #include "iservice_registry.h"
26 #include "system_ability_definition.h"
27
28 using namespace testing::ext;
29 using namespace testing::mt;
30
31 namespace OHOS {
32 namespace SOCPERF {
33 class SocPerfSubTest : 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 SocPerfSubTest::SetUpTestCase(void)
42 {
43 }
44
TearDownTestCase(void)45 void SocPerfSubTest::TearDownTestCase(void)
46 {
47 }
48
SetUp(void)49 void SocPerfSubTest::SetUp(void)
50 {
51 }
52
TearDown(void)53 void SocPerfSubTest::TearDown(void)
54 {
55 }
56
57 /*
58 * @tc.name: SocPerfSubTest_ActionType_001
59 * @tc.desc: action type perf
60 * @tc.type FUNC
61 * @tc.require: issueI78T3V
62 */
63 HWTEST_F(SocPerfSubTest, SocPerfSubTest_ActionType_001, Function | MediumTest | Level0)
64 {
65 EXPECT_EQ(OHOS::SOCPERF::ActionType::ACTION_TYPE_PERF, 0);
66 }
67
68 /*
69 * @tc.name: SocPerfSubTest_ActionType_002
70 * @tc.desc: action type power
71 * @tc.type FUNC
72 * @tc.require: issueI78T3V
73 */
74 HWTEST_F(SocPerfSubTest, SocPerfSubTest_ActionType_002, Function | MediumTest | Level0)
75 {
76 EXPECT_EQ(OHOS::SOCPERF::ActionType::ACTION_TYPE_POWER, 1);
77 }
78
79 /*
80 * @tc.name: SocPerfSubTest_ActionType_003
81 * @tc.desc: action type THERMAL
82 * @tc.type FUNC
83 * @tc.require: issueI78T3V
84 */
85 HWTEST_F(SocPerfSubTest, SocPerfSubTest_ActionType_003, Function | MediumTest | Level0)
86 {
87 EXPECT_EQ(OHOS::SOCPERF::ActionType::ACTION_TYPE_THERMAL, 2);
88 }
89
90 /*
91 * @tc.name: SocPerfSubTest_ActionType_004
92 * @tc.desc: action type max
93 * @tc.type FUNC
94 * @tc.require: issueI78T3V
95 */
96 HWTEST_F(SocPerfSubTest, SocPerfSubTest_ActionType_004, Function | MediumTest | Level0)
97 {
98 EXPECT_EQ(OHOS::SOCPERF::ActionType::ACTION_TYPE_MAX, 3);
99 }
100
101 /*
102 * @tc.name: SocPerfSubTest_EventType_001
103 * @tc.desc: event type off
104 * @tc.type FUNC
105 * @tc.require: issueI78T3V
106 */
107 HWTEST_F(SocPerfSubTest, SocPerfSubTest_EventType_001, Function | MediumTest | Level0)
108 {
109 EXPECT_EQ(OHOS::SOCPERF::EventType::EVENT_OFF, 0);
110 }
111
112 /*
113 * @tc.name: SocPerfSubTest_EventType_002
114 * @tc.desc: event type on
115 * @tc.type FUNC
116 * @tc.require: issueI78T3V
117 */
118 HWTEST_F(SocPerfSubTest, SocPerfSubTest_EventType_002, Function | MediumTest | Level0)
119 {
120 EXPECT_EQ(OHOS::SOCPERF::EventType::EVENT_ON, 1);
121 }
122
123 /*
124 * @tc.name: SocPerfSubTest_EventType_003
125 * @tc.desc: event type invalid
126 * @tc.type FUNC
127 * @tc.require: issueI78T3V
128 */
129 HWTEST_F(SocPerfSubTest, SocPerfSubTest_EventType_003, Function | MediumTest | Level0)
130 {
131 EXPECT_EQ(OHOS::SOCPERF::EventType::EVENT_INVALID, -1);
132 }
133
134 /*
135 * @tc.name: SocPerfSubTest_InnerEventId_001
136 * @tc.desc: init res node info
137 * @tc.type FUNC
138 * @tc.require: issueI78T3V
139 */
140 HWTEST_F(SocPerfSubTest, SocPerfSubTest_InnerEventId_001, Function | MediumTest | Level0)
141 {
142 EXPECT_EQ(INNER_EVENT_ID_INIT_RES_NODE_INFO, 0);
143 }
144
145 /*
146 * @tc.name: SocPerfSubTest_InnerEventId_002
147 * @tc.desc: init gov res node info
148 * @tc.type FUNC
149 * @tc.require: issueI78T3V
150 */
151 HWTEST_F(SocPerfSubTest, SocPerfSubTest_InnerEventId_002, Function | MediumTest | Level0)
152 {
153 EXPECT_EQ(INNER_EVENT_ID_INIT_GOV_RES_NODE_INFO, 1);
154 }
155
156 /*
157 * @tc.name: SocPerfSubTest_InnerEventId_003
158 * @tc.desc: do freq action
159 * @tc.type FUNC
160 * @tc.require: issueI78T3V
161 */
162 HWTEST_F(SocPerfSubTest, SocPerfSubTest_InnerEventId_003, Function | MediumTest | Level0)
163 {
164 EXPECT_EQ(INNER_EVENT_ID_DO_FREQ_ACTION, 2);
165 }
166
167 /*
168 * @tc.name: SocPerfSubTest_InnerEventId_004
169 * @tc.desc: do freq action delayed
170 * @tc.type FUNC
171 * @tc.require: issueI78T3V
172 */
173 HWTEST_F(SocPerfSubTest, SocPerfSubTest_InnerEventId_004, Function | MediumTest | Level0)
174 {
175 EXPECT_EQ(INNER_EVENT_ID_DO_FREQ_ACTION_DELAYED, 4);
176 }
177
178 /*
179 * @tc.name: SocPerfSubTest_InnerEventId_005
180 * @tc.desc: power limit boost freq
181 * @tc.type FUNC
182 * @tc.require: issueI78T3V
183 */
184 HWTEST_F(SocPerfSubTest, SocPerfSubTest_InnerEventId_005, Function | MediumTest | Level0)
185 {
186 EXPECT_EQ(INNER_EVENT_ID_POWER_LIMIT_BOOST_FREQ, 5);
187 }
188
189 /*
190 * @tc.name: SocPerfSubTest_InnerEventId_006
191 * @tc.desc: thermal limit boost freq
192 * @tc.type FUNC
193 * @tc.require: issueI78T3V
194 */
195 HWTEST_F(SocPerfSubTest, SocPerfSubTest_InnerEventId_006, Function | MediumTest | Level0)
196 {
197 EXPECT_EQ(INNER_EVENT_ID_THERMAL_LIMIT_BOOST_FREQ, 6);
198 }
199
200 /*
201 * @tc.name: SocPerfSubTest_GetService_001
202 * @tc.desc: get socperf service
203 * @tc.type FUNC
204 * @tc.require: issueI78T3V
205 */
206 HWTEST_F(SocPerfSubTest, SocPerfSubTest_GetService_001, Function | MediumTest | Level0)
207 {
208 sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
209 EXPECT_NE(samgr, nullptr);
210
211 sptr<IRemoteObject> object = samgr->GetSystemAbility(SOC_PERF_SERVICE_SA_ID);
212 EXPECT_NE(object, nullptr);
213 }
214
215 /*
216 * @tc.name: SocPerfSubTest_GetService_002
217 * @tc.desc: get socperf service
218 * @tc.type FUNC
219 * @tc.require: issueI78T3V
220 */
221 HWTEST_F(SocPerfSubTest, SocPerfSubTest_GetService_002, Function | MediumTest | Level0)
222 {
223 sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
224 EXPECT_NE(samgr, nullptr);
225
226 sptr<IRemoteObject> object = samgr->GetSystemAbility(RES_SCHED_SYS_ABILITY_ID);
227 EXPECT_NE(object, nullptr);
228 }
229
SocPerfSubTestGetServiceTask()230 static void SocPerfSubTestGetServiceTask()
231 {
232 sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
233 EXPECT_NE(samgr, nullptr);
234
235 sptr<IRemoteObject> object = samgr->GetSystemAbility(SOC_PERF_SERVICE_SA_ID);
236 EXPECT_NE(object, nullptr);
237
238 object = samgr->GetSystemAbility(RES_SCHED_SYS_ABILITY_ID);
239 EXPECT_NE(object, nullptr);
240 }
241
242 /*
243 * @tc.name: SocPerfSubTest_GetService_003
244 * @tc.desc: Test get socperf service in multithreading
245 * @tc.type FUNC
246 * @tc.require: issueI7G8VT
247 */
248 HWTEST_F(SocPerfSubTest, SocPerfSubTest_GetService_003, Function | MediumTest | Level0)
249 {
250 SET_THREAD_NUM(10);
251 GTEST_RUN_TASK(SocPerfSubTestGetServiceTask);
252 }
253
254 /*
255 * @tc.name: SocPerfSubTest_PerfRequest_001
256 * @tc.desc: PerfRequest
257 * @tc.type FUNC
258 * @tc.require: issueI78T3V
259 */
260 HWTEST_F(SocPerfSubTest, SocPerfSubTest_PerfRequest_001, Function | MediumTest | Level0)
261 {
262 std::string msg = "";
263 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequest(10000, msg);
264 EXPECT_EQ(msg, "");
265 }
266
267 /*
268 * @tc.name: SocPerfSubTest_PerfRequest_002
269 * @tc.desc: PerfRequestEx ON
270 * @tc.type FUNC
271 * @tc.require: issueI78T3V
272 */
273 HWTEST_F(SocPerfSubTest, SocPerfSubTest_PerfRequest_002, Function | MediumTest | Level0)
274 {
275 std::string msg = "";
276 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(10000, true, msg);
277 EXPECT_EQ(msg, "");
278 }
279
280 /*
281 * @tc.name: SocPerfSubTest_PerfRequest_003
282 * @tc.desc: PerfRequestEx OFF
283 * @tc.type FUNC
284 * @tc.require: issueI78T3V
285 */
286 HWTEST_F(SocPerfSubTest, SocPerfSubTest_PerfRequest_003, Function | MediumTest | Level0)
287 {
288 std::string msg = "";
289 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(10000, false, msg);
290 EXPECT_EQ(msg, "");
291 }
292
293 /*
294 * @tc.name: SocPerfSubTest_PowerLimitBoost_001
295 * @tc.desc: PowerLimitBoost ON
296 * @tc.type FUNC
297 * @tc.require: issueI78T3V
298 */
299 HWTEST_F(SocPerfSubTest, SocPerfSubTest_PowerLimitBoost_001, Function | MediumTest | Level0)
300 {
301 std::string msg = "";
302 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(true, msg);
303 EXPECT_EQ(msg, "");
304 }
305
306 /*
307 * @tc.name: SocPerfSubTest_PowerLimitBoost_001
308 * @tc.desc: PowerLimitBoost OFF
309 * @tc.type FUNC
310 * @tc.require: issueI78T3V
311 */
312 HWTEST_F(SocPerfSubTest, SocPerfSubTest_PowerLimitBoost_002, Function | MediumTest | Level0)
313 {
314 std::string msg = "";
315 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(false, msg);
316 EXPECT_EQ(msg, "");
317 }
318
319 /*
320 * @tc.name: SocPerfSubTest_ThermalLimitBoost_001
321 * @tc.desc: ThermalLimitBoost ON
322 * @tc.type FUNC
323 * @tc.require: issueI78T3V
324 */
325 HWTEST_F(SocPerfSubTest, SocPerfSubTest_ThermalLimitBoost_001, Function | MediumTest | Level0)
326 {
327 std::string msg = "";
328 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(true, msg);
329 EXPECT_EQ(msg, "");
330 }
331
332 /*
333 * @tc.name: SocPerfSubTest_ThermalLimitBoost_002
334 * @tc.desc: ThermalLimitBoost OFF
335 * @tc.type FUNC
336 * @tc.require: issueI78T3V
337 */
338 HWTEST_F(SocPerfSubTest, SocPerfSubTest_ThermalLimitBoost_002, Function | MediumTest | Level0)
339 {
340 std::string msg = "";
341 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(false, msg);
342 EXPECT_EQ(msg, "");
343 }
344
345 /*
346 * @tc.name: SocPerfSubTest_LimitRequest_001
347 * @tc.desc: LimitRequest thermal
348 * @tc.type FUNC
349 * @tc.require: issueI78T3V
350 */
351 HWTEST_F(SocPerfSubTest, SocPerfSubTest_LimitRequest_001, Function | MediumTest | Level0)
352 {
353 int32_t clientId_power = ACTION_TYPE_POWER;
354 std::vector<int32_t> tags;
355 tags.push_back(1001);
356 std::vector<int64_t> configs;
357 EXPECT_NE(tags.size(), configs.size());
358 configs.push_back(1608000);
359 EXPECT_EQ(tags.size(), configs.size());
360 OHOS::SOCPERF::SocPerfClient::GetInstance().LimitRequest(clientId_power, tags, configs, "");
361 }
362
363 /*
364 * @tc.name: SocPerfSubTest_LimitRequest_002
365 * @tc.desc: LimitRequest thermal
366 * @tc.type FUNC
367 * @tc.require: issueI78T3V
368 */
369 HWTEST_F(SocPerfSubTest, SocPerfSubTest_LimitRequest_002, Function | MediumTest | Level0)
370 {
371 int32_t clientId_thermal = ACTION_TYPE_THERMAL;
372 std::vector<int32_t> tags;
373 tags.push_back(1000);
374 tags.push_back(1001);
375 std::vector<int64_t> configs;
376 EXPECT_NE(tags.size(), configs.size());
377 configs.push_back(1800000);
378 configs.push_back(1992000);
379 EXPECT_EQ(tags.size(), configs.size());
380 OHOS::SOCPERF::SocPerfClient::GetInstance().LimitRequest(clientId_thermal, tags, configs, "");
381 }
382
SocPerfSubTestLimitRequestTask()383 static void SocPerfSubTestLimitRequestTask()
384 {
385 int32_t clientId_power = ACTION_TYPE_POWER;
386 std::vector<int32_t> tags;
387 constexpr int resId = 1001;
388 tags.push_back(resId);
389 std::vector<int64_t> configs;
390 EXPECT_NE(tags.size(), configs.size());
391 constexpr int freqValue = 1416000;
392 configs.push_back(freqValue);
393 EXPECT_EQ(tags.size(), configs.size());
394 OHOS::SOCPERF::SocPerfClient::GetInstance().LimitRequest(clientId_power, tags, configs, "");
395 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(true, "");
396 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(false, "");
397 }
398
399 /*
400 * @tc.name: SocPerfSubTest_LimitRequest_003
401 * @tc.desc: Test LimitRequest thermal in multithreading
402 * @tc.type FUNC
403 * @tc.require: issueI7G8VT
404 */
405 HWTEST_F(SocPerfSubTest, SocPerfSubTest_LimitRequest_003, Function | MediumTest | Level0)
406 {
407 SET_THREAD_NUM(10);
408 GTEST_RUN_TASK(SocPerfSubTestLimitRequestTask);
409 }
410
411 /*
412 * @tc.name: SocPerfSubTest_ResetClient_001
413 * @tc.desc: ResetClient
414 * @tc.type FUNC
415 * @tc.require: issueI78T3V
416 */
417 HWTEST_F(SocPerfSubTest, SocPerfSubTest_ResetClient_001, Function | MediumTest | Level0)
418 {
419 std::string msg = "";
420 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequest(10000, msg);
421 EXPECT_EQ(msg, "");
422 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(10000, true, msg);
423 EXPECT_EQ(msg, "");
424 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(10000, false, msg);
425 EXPECT_EQ(msg, "");
426 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(true, msg);
427 EXPECT_EQ(msg, "");
428 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(false, msg);
429 EXPECT_EQ(msg, "");
430 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(true, msg);
431 EXPECT_EQ(msg, "");
432 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(false, msg);
433 EXPECT_EQ(msg, "");
434 OHOS::SOCPERF::SocPerfClient::GetInstance().ResetClient();
435 }
436
SocPerfSubTestMultithreadingTask()437 static void SocPerfSubTestMultithreadingTask()
438 {
439 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequest(10000, "");
440 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(10000, true, "");
441 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(10000, false, "");
442 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(true, "");
443 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(false, "");
444 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(true, "");
445 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(false, "");
446 }
447
448 /*
449 * @tc.name: SocPerfSubTest_Multithreading_001
450 * @tc.desc: Test the service above in multithreading
451 * @tc.type FUNC
452 * @tc.require: issueI7G8VT
453 */
454 HWTEST_F(SocPerfSubTest, SocPerfSubTest_Multithreading_001, Function | MediumTest | Level0)
455 {
456 SET_THREAD_NUM(10);
457 GTEST_RUN_TASK(SocPerfSubTestMultithreadingTask);
458 }
459 } // namespace SOCPERF
460 } // namespace OHOS
461