1 /*
2 * Copyright (c) 2021-2024 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 "thermal_action_test.h"
17
18 #ifdef THERMAL_GTEST
19 #define private public
20 #define protected public
21 #endif
22
23 #include <memory>
24 #include <singleton.h>
25 #include "action_airplane.h"
26 #include "action_application_process.h"
27 #include "action_charger.h"
28 #include "action_cpu_big.h"
29 #include "action_cpu_med.h"
30 #include "action_cpu_lit.h"
31 #include "action_cpu_isolate.h"
32 #include "action_display.h"
33 #include "action_gpu.h"
34 #include "action_node.h"
35 #include "action_shutdown.h"
36 #include "action_thermal_level.h"
37 #include "action_popup.h"
38 #include "action_volume.h"
39 #include "action_voltage.h"
40 #include "file_operation.h"
41 #include "iremote_object.h"
42 #include "mock_thermal_remote_object.h"
43 #include "thermal_service.h"
44 #include "thermal_timer.h"
45
46 using namespace testing::ext;
47 using namespace OHOS::PowerMgr;
48 using namespace OHOS;
49 using namespace std;
50
51 namespace {
52 constexpr int32_t BUF_LEN = 32;
53 static sptr<ThermalService> g_service = nullptr;
54 std::shared_ptr<ActionApplicationProcess> g_actionApplicationProcess =
55 std::make_shared<ActionApplicationProcess>("process_ctrl");
56 std::shared_ptr<ActionAirplane> g_actionAirplane = std::make_shared<ActionAirplane>("airplane");
57 std::shared_ptr<ActionCharger> g_actionCharger = std::make_shared<ActionCharger>("current_sc");
58 std::shared_ptr<ActionCpuBig> g_actionCpuBig = std::make_shared<ActionCpuBig>("cpu_big");
59 std::shared_ptr<ActionCpuMed> g_actionCpuMed = std::make_shared<ActionCpuMed>("cpu_med");
60 std::shared_ptr<ActionCpuLit> g_actionCpuLit = std::make_shared<ActionCpuLit>("cpu_lit");
61 std::shared_ptr<ActionCpuIsolate> g_actionCpuIsolate = std::make_shared<ActionCpuIsolate>("isolate");
62 std::shared_ptr<ActionDisplay> g_actionDisplay = std::make_shared<ActionDisplay>("lcd");
63 std::shared_ptr<ActionGpu> g_actionGpu = std::make_shared<ActionGpu>("gpu");
64 std::shared_ptr<ActionPopup> g_actionPopup = std::make_shared<ActionPopup>("popup");
65 std::shared_ptr<ActionShutdown> g_actionShutdown = std::make_shared<ActionShutdown>("shut_down");
66 std::shared_ptr<ActionThermalLevel> g_actionThermalLevel = std::make_shared<ActionThermalLevel>("thermallevel");
67 std::shared_ptr<ActionVolume> g_actionVolume = std::make_shared<ActionVolume>("volume");
68 std::shared_ptr<ActionVoltage> g_actionVoltage = std::make_shared<ActionVoltage>("voltage");
69 std::shared_ptr<ActionNode> g_actionNode = std::make_shared<ActionNode>("action_node");
70 }
71
SetUpTestCase()72 void ThermalActionTest::SetUpTestCase()
73 {
74 g_service = ThermalService::GetInstance();
75 g_service->InitSystemTestModules();
76 g_service->OnStart();
77 }
78
TearDownTestCase()79 void ThermalActionTest::TearDownTestCase()
80 {
81 g_service->OnStop();
82 }
83
SetUp()84 void ThermalActionTest::SetUp() {}
85
TearDown()86 void ThermalActionTest::TearDown() {}
87
88 namespace {
89 /**
90 * @tc.name: ThermalActionTest001
91 * @tc.desc: Action Volume Function Test
92 * @tc.type: FUNC
93 */
94 HWTEST_F(ThermalActionTest, ThermalActionTest001, TestSize.Level0)
95 {
96 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest001 start");
97 g_actionVolume->InitParams("volume");
98 g_actionVolume->SetEnableEvent(false);
99 g_actionVolume->AddActionValue(0, "");
100 g_actionVolume->AddActionValue(0, "1.0");
101 g_actionVolume->Execute();
102 g_actionVolume->SetStrict(true);
103 g_actionVolume->AddActionValue(0, "2.0");
104 g_actionVolume->GetActionValue();
105 g_actionVolume->VolumeRequest(1.0);
106 int32_t ret = g_actionVolume->VolumeExecution(1.0);
107 EXPECT_TRUE(ret == ERR_OK);
108 std::shared_ptr<IThermalAction> g_actionVolume2 = g_actionVolume;
109 PolicyDelayAction delayAction;
110 delayAction.delayTime = 10000;
111 g_actionVolume2->AddActionDelayTime(1, delayAction);
112 g_actionVolume2->AddActionValue(1, "1.0");
113 PolicyDelayAction delayAction2;
114 delayAction2.delayTime = 10000;
115 g_actionVolume2->AddActionDelayTime(2, delayAction2);
116 g_actionVolume2->AddActionValue(2, "1.0");
117 g_actionVolume2->Execute();
118 PolicyDelayAction delayAction3;
119 delayAction3.delayTime = 10000;
120 g_actionVolume2->AddActionDelayTime(2, delayAction3);
121 g_actionVolume2->AddActionValue(2, "1.0");
122 g_actionVolume2->Execute();
123 PolicyDelayAction delayAction4;
124 delayAction4.delayTime = 10000;
125 g_actionVolume2->AddActionDelayTime(4, delayAction4);
126 g_actionVolume2->AddActionValue(4, "1.0");
127 g_actionVolume2->Execute();
128 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest001 end");
129 }
130
131 /**
132 * @tc.name: ThermalActionTest002
133 * @tc.desc: Action Voltage Function Test
134 * @tc.type: FUNC
135 */
136 HWTEST_F(ThermalActionTest, ThermalActionTest002, TestSize.Level0)
137 {
138 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest002 start");
139 g_actionVoltage->AddActionValue(0, "");
140 g_actionVoltage->AddActionValue(0, "1.0");
141 g_actionVoltage->Execute();
142 g_actionVoltage->SetStrict(true);
143 g_actionVoltage->AddActionValue(0, "2.0");
144 g_actionVoltage->GetActionValue();
145 g_actionVoltage->SetVoltage(123456);
146 g_actionVoltage->ExecuteVoltageLimit();
147 int32_t ret = g_actionVoltage->WriteMockNode(123456);
148 EXPECT_FALSE(ret == ERR_OK);
149 PolicyDelayAction delayAction;
150 delayAction.delayTime = 10000;
151 std::shared_ptr<IThermalAction> g_actionVoltage2 = g_actionVoltage;
152 g_actionVoltage2->AddActionDelayTime(1, delayAction);
153 g_actionVoltage2->AddActionValue(1, "1.0");
154 PolicyDelayAction delayAction2;
155 delayAction2.delayTime = 10000;
156 g_actionVoltage2->AddActionDelayTime(2, delayAction2);
157 g_actionVoltage2->AddActionValue(2, "1.0");
158 g_actionVoltage2->Execute();
159 PolicyDelayAction delayAction3;
160 delayAction3.delayTime = 10000;
161 g_actionVoltage2->AddActionDelayTime(2, delayAction3);
162 g_actionVoltage2->AddActionValue(2, "1.0");
163 g_actionVoltage2->Execute();
164 PolicyDelayAction delayAction4;
165 delayAction4.delayTime = 10000;
166 g_actionVoltage2->AddActionDelayTime(4, delayAction4);
167 g_actionVoltage2->AddActionValue(4, "1.0");
168 g_actionVoltage2->Execute();
169 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest002 end");
170 }
171
172 /**
173 * @tc.name: ThermalActionTest003
174 * @tc.desc: Action Thermal Level Function Test
175 * @tc.type: FUNC
176 */
177 HWTEST_F(ThermalActionTest, ThermalActionTest003, TestSize.Level0)
178 {
179 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest003 start");
180 g_actionThermalLevel->AddActionValue(0, "");
181 g_actionThermalLevel->AddActionValue(0, "1.0");
182 g_actionThermalLevel->Execute();
183 g_actionThermalLevel->GetThermalLevel();
184 g_actionThermalLevel->LevelRequest(1);
185 g_actionThermalLevel->LevelRequest(9);
186 g_actionThermalLevel->LevelRequest(-1);
187 g_actionThermalLevel->SetStrict(true);
188 g_actionThermalLevel->AddActionValue(0, "2.0");
189 g_actionThermalLevel->GetActionValue();
190 g_actionThermalLevel->SubscribeThermalLevelCallback(nullptr);
191 g_actionThermalLevel->UnSubscribeThermalLevelCallback(nullptr);
192 std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient =
193 std::make_shared<ActionThermalLevel::ThermalLevelCallbackDeathRecipient>();
194 wptr<IRemoteObject> remoteObj = nullptr;
195 EXPECT_NE(deathRecipient, nullptr);
196 deathRecipient->OnRemoteDied(remoteObj);
197
198 sptr<IRemoteObject> sptrRemoteObj = new MockThermalRemoteObject();
199 EXPECT_FALSE(sptrRemoteObj == nullptr);
200 deathRecipient->OnRemoteDied(sptrRemoteObj);
201
202 g_actionThermalLevel->NotifyThermalLevelChanged(1);
203 bool ret = g_actionThermalLevel->
204 PublishLevelChangedEvents(ThermalCommonEventCode::CODE_THERMAL_LEVEL_CHANGED, 1);
205 EXPECT_TRUE(ret);
206 PolicyDelayAction delayAction;
207 delayAction.delayTime = 10000;
208 std::shared_ptr<IThermalAction> g_actionThermalLevel2 = g_actionThermalLevel;
209 g_actionThermalLevel2->AddActionDelayTime(1, delayAction);
210 g_actionThermalLevel2->AddActionValue(1, "1.0");
211 PolicyDelayAction delayAction2;
212 delayAction2.delayTime = 10000;
213 g_actionThermalLevel2->AddActionDelayTime(2, delayAction2);
214 g_actionThermalLevel2->AddActionValue(2, "1.0");
215 g_actionThermalLevel2->Execute();
216 PolicyDelayAction delayAction3;
217 delayAction3.delayTime = 10000;
218 g_actionThermalLevel2->AddActionDelayTime(2, delayAction3);
219 g_actionThermalLevel2->AddActionValue(2, "1.0");
220 g_actionThermalLevel2->Execute();
221 PolicyDelayAction delayAction4;
222 delayAction4.delayTime = 10000;
223 g_actionThermalLevel2->AddActionDelayTime(4, delayAction4);
224 g_actionThermalLevel2->AddActionValue(4, "1.0");
225 g_actionThermalLevel2->Execute();
226 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest003 end");
227 }
228
229 /**
230 * @tc.name: ThermalActionTest004
231 * @tc.desc: Action Shutdown Function Test
232 * @tc.type: FUNC
233 */
234 HWTEST_F(ThermalActionTest, ThermalActionTest004, TestSize.Level0)
235 {
236 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest004 start");
237 g_actionShutdown->AddActionValue(0, "");
238 g_actionShutdown->AddActionValue(0, "1.0");
239 g_actionShutdown->Execute();
240 g_actionShutdown->SetStrict(true);
241 g_actionShutdown->AddActionValue(0, "2.0");
242 g_actionShutdown->GetActionValue();
243 int32_t ret = g_actionShutdown->ShutdownRequest(false);
244 EXPECT_TRUE(ret == ERR_OK);
245 g_actionShutdown->ShutdownExecution(false);
246 g_actionShutdown->ShutdownExecution(false);
247 ret = g_actionShutdown->DelayShutdown(false, 0, 0);
248 EXPECT_TRUE(ret == ERR_OK);
249 PolicyDelayAction delayAction;
250 delayAction.delayTime = 10000;
251 std::shared_ptr<IThermalAction> g_actionShutdown2 = g_actionShutdown;
252 g_actionShutdown2->AddActionDelayTime(1, delayAction);
253 g_actionShutdown2->AddActionValue(1, "1.0");
254 PolicyDelayAction delayAction2;
255 delayAction2.delayTime = 10000;
256 g_actionShutdown2->AddActionDelayTime(2, delayAction2);
257 g_actionShutdown2->AddActionValue(2, "1.0");
258 g_actionShutdown2->Execute();
259 PolicyDelayAction delayAction3;
260 delayAction3.delayTime = 10000;
261 g_actionShutdown2->AddActionDelayTime(2, delayAction3);
262 g_actionShutdown2->AddActionValue(2, "1.0");
263 g_actionShutdown2->Execute();
264 PolicyDelayAction delayAction4;
265 delayAction4.delayTime = 10000;
266 g_actionShutdown2->AddActionDelayTime(4, delayAction4);
267 g_actionShutdown2->AddActionValue(4, "1.0");
268 g_actionShutdown2->Execute();
269 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest004 end");
270 }
271
272 /**
273 * @tc.name: ThermalActionTest005
274 * @tc.desc: Action Display Function Test
275 * @tc.type: FUNC
276 * @tc.require: issueI6KRS8
277 */
278 HWTEST_F(ThermalActionTest, ThermalActionTest005, TestSize.Level0)
279 {
280 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest005 start");
281 g_actionDisplay->AddActionValue(0, "");
282 g_actionDisplay->AddActionValue(0, "1.0");
283 g_actionDisplay->Execute();
284 g_actionDisplay->SetStrict(true);
285 g_actionDisplay->AddActionValue(0, "2.0");
286 g_actionDisplay->GetActionValue();
287 EXPECT_FALSE(g_actionDisplay->valueList_.empty());
288 PolicyDelayAction delayAction;
289 delayAction.delayTime = 10000;
290 std::shared_ptr<IThermalAction> g_actionDisplay2 = g_actionDisplay;
291 g_actionDisplay2->AddActionDelayTime(1, delayAction);
292 g_actionDisplay2->AddActionValue(1, "1.0");
293 PolicyDelayAction delayAction2;
294 delayAction2.delayTime = 10000;
295 g_actionDisplay2->AddActionDelayTime(2, delayAction2);
296 g_actionDisplay2->AddActionValue(2, "1.0");
297 g_actionDisplay2->Execute();
298 PolicyDelayAction delayAction3;
299 delayAction3.delayTime = 10000;
300 g_actionDisplay2->AddActionDelayTime(2, delayAction3);
301 g_actionDisplay2->AddActionValue(2, "1.0");
302 g_actionDisplay2->Execute();
303 PolicyDelayAction delayAction4;
304 delayAction4.delayTime = 10000;
305 g_actionDisplay2->AddActionDelayTime(4, delayAction4);
306 g_actionDisplay2->AddActionValue(4, "1.0");
307 g_actionDisplay2->Execute();
308 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest005 end");
309 }
310
311 /**
312 * @tc.name: ThermalActionTest006
313 * @tc.desc: Action Charger Function Test
314 * @tc.type: FUNC
315 */
316 HWTEST_F(ThermalActionTest, ThermalActionTest006, TestSize.Level0)
317 {
318 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest006 start");
319 g_actionCharger->AddActionValue(0, "");
320 g_actionCharger->AddActionValue(0, "1.0");
321 g_actionCharger->Execute();
322 g_actionCharger->ChargerRequest(0);
323 g_actionCharger->ExecuteCurrentLimit();
324 int32_t ret = g_actionCharger->WriteSimValue(0);
325 EXPECT_TRUE(ret);
326 PolicyDelayAction delayAction;
327 delayAction.delayTime = 10000;
328 std::shared_ptr<IThermalAction> g_actionCharger2 = g_actionCharger;
329 g_actionCharger2->AddActionDelayTime(1, delayAction);
330 g_actionCharger2->AddActionValue(1, "1.0");
331 PolicyDelayAction delayAction2;
332 delayAction2.delayTime = 10000;
333 g_actionCharger2->AddActionDelayTime(2, delayAction2);
334 g_actionCharger2->AddActionValue(2, "1.0");
335 g_actionCharger2->Execute();
336 PolicyDelayAction delayAction3;
337 delayAction3.delayTime = 10000;
338 g_actionCharger2->AddActionDelayTime(2, delayAction3);
339 g_actionCharger2->AddActionValue(2, "1.0");
340 g_actionCharger2->Execute();
341 PolicyDelayAction delayAction4;
342 delayAction4.delayTime = 10000;
343 g_actionCharger2->AddActionDelayTime(4, delayAction4);
344 g_actionCharger2->AddActionValue(4, "1.0");
345 g_actionCharger2->Execute();
346 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest006 end");
347 }
348
349 /**
350 * @tc.name: ThermalActionTest007
351 * @tc.desc: Action Application Process Test
352 * @tc.type: FUNC
353 */
354 HWTEST_F(ThermalActionTest, ThermalActionTest007, TestSize.Level0)
355 {
356 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest007 start");
357 g_actionApplicationProcess->InitParams("");
358 g_actionApplicationProcess->AddActionValue(0, "");
359 g_actionApplicationProcess->AddActionValue(0, "1");
360 g_actionApplicationProcess->Execute();
361 g_actionApplicationProcess->KillApplicationAction("");
362 g_actionApplicationProcess->ProcessAppActionRequest(0);
363 g_actionApplicationProcess->ProcessAppActionRequest(1);
364 g_actionApplicationProcess->ProcessAppActionRequest(2);
365 g_actionApplicationProcess->ProcessAppActionRequest(3);
366 g_actionApplicationProcess->ProcessAppActionExecution(0);
367 EXPECT_TRUE(g_actionApplicationProcess->valueList_.empty());
368 PolicyDelayAction delayAction;
369 delayAction.delayTime = 10000;
370 std::shared_ptr<IThermalAction> g_actionApplicationProcess2 = g_actionApplicationProcess;
371 g_actionApplicationProcess2->AddActionDelayTime(1, delayAction);
372 g_actionApplicationProcess2->AddActionValue(1, "1.0");
373 PolicyDelayAction delayAction2;
374 delayAction2.delayTime = 10000;
375 g_actionApplicationProcess2->AddActionDelayTime(2, delayAction2);
376 g_actionApplicationProcess2->AddActionValue(2, "1.0");
377 g_actionApplicationProcess2->Execute();
378 PolicyDelayAction delayAction3;
379 delayAction3.delayTime = 10000;
380 g_actionApplicationProcess2->AddActionDelayTime(2, delayAction3);
381 g_actionApplicationProcess2->AddActionValue(2, "1.0");
382 g_actionApplicationProcess2->Execute();
383 PolicyDelayAction delayAction4;
384 delayAction4.delayTime = 10000;
385 g_actionApplicationProcess2->AddActionDelayTime(4, delayAction4);
386 g_actionApplicationProcess2->AddActionValue(4, "1.0");
387 g_actionApplicationProcess2->Execute();
388 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest007 end");
389 }
390
391 /**
392 * @tc.name: ThermalActionTest008
393 * @tc.desc: Action CPU Big Test
394 * @tc.type: FUNC
395 * @tc.require: issueI6KRS8
396 */
397 HWTEST_F(ThermalActionTest, ThermalActionTest008, TestSize.Level0)
398 {
399 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest008 start");
400 g_actionCpuBig->AddActionValue(0, "");
401 g_actionCpuBig->AddActionValue(0, "1.0");
402 g_actionCpuBig->Execute();
403 EXPECT_TRUE(g_actionCpuBig->valueList_.empty());
404 PolicyDelayAction delayAction;
405 delayAction.delayTime = 10000;
406 std::shared_ptr<IThermalAction> g_actionCpuBig2 = g_actionCpuBig;
407 g_actionCpuBig2->AddActionDelayTime(1, delayAction);
408 g_actionCpuBig2->AddActionValue(1, "1.0");
409 PolicyDelayAction delayAction2;
410 delayAction2.delayTime = 10000;
411 g_actionCpuBig2->AddActionDelayTime(2, delayAction2);
412 g_actionCpuBig2->AddActionValue(2, "1.0");
413 g_actionCpuBig2->Execute();
414 PolicyDelayAction delayAction3;
415 delayAction3.delayTime = 10000;
416 g_actionCpuBig2->AddActionDelayTime(2, delayAction3);
417 g_actionCpuBig2->AddActionValue(2, "1.0");
418 g_actionCpuBig2->Execute();
419 PolicyDelayAction delayAction4;
420 delayAction4.delayTime = 10000;
421 g_actionCpuBig2->AddActionDelayTime(4, delayAction4);
422 g_actionCpuBig2->AddActionValue(4, "1.0");
423 g_actionCpuBig2->Execute();
424 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest008 end");
425 }
426
427 /**
428 * @tc.name: ThermalActionTest009
429 * @tc.desc: Action CPU Med Test
430 * @tc.type: FUNC
431 * @tc.require: issueI6KRS8
432 */
433 HWTEST_F(ThermalActionTest, ThermalActionTest009, TestSize.Level0)
434 {
435 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest009 start");
436 g_actionCpuMed->AddActionValue(0, "");
437 g_actionCpuMed->AddActionValue(0, "1.0");
438 g_actionCpuMed->Execute();
439 EXPECT_TRUE(g_actionCpuMed->valueList_.empty());
440 PolicyDelayAction delayAction;
441 delayAction.delayTime = 10000;
442 std::shared_ptr<IThermalAction> g_actionCpuMed2 = g_actionCpuMed;
443 g_actionCpuMed2->AddActionDelayTime(1, delayAction);
444 g_actionCpuMed2->AddActionValue(1, "1.0");
445 PolicyDelayAction delayAction2;
446 delayAction2.delayTime = 10000;
447 g_actionCpuMed2->AddActionDelayTime(2, delayAction2);
448 g_actionCpuMed2->AddActionValue(2, "1.0");
449 g_actionCpuMed2->Execute();
450 PolicyDelayAction delayAction3;
451 delayAction3.delayTime = 10000;
452 g_actionCpuMed2->AddActionDelayTime(2, delayAction3);
453 g_actionCpuMed2->AddActionValue(2, "1.0");
454 g_actionCpuMed2->Execute();
455 PolicyDelayAction delayAction4;
456 delayAction4.delayTime = 10000;
457 g_actionCpuMed2->AddActionDelayTime(4, delayAction4);
458 g_actionCpuMed2->AddActionValue(4, "1.0");
459 g_actionCpuMed2->Execute();
460 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest009 end");
461 }
462
463 /**
464 * @tc.name: ThermalActionTest010
465 * @tc.desc: Action CPU Lit Test
466 * @tc.type: FUNC
467 * @tc.require: issueI6KRS8
468 */
469 HWTEST_F(ThermalActionTest, ThermalActionTest010, TestSize.Level0)
470 {
471 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest010 start");
472 g_actionCpuLit->AddActionValue(0, "");
473 g_actionCpuLit->AddActionValue(0, "1.0");
474 g_actionCpuLit->Execute();
475 EXPECT_TRUE(g_actionCpuLit->valueList_.empty());
476 PolicyDelayAction delayAction;
477 delayAction.delayTime = 10000;
478 std::shared_ptr<IThermalAction> g_actionCpuLit2 = g_actionCpuLit;
479 g_actionCpuLit2->AddActionDelayTime(1, delayAction);
480 g_actionCpuLit2->AddActionValue(1, "1.0");
481 PolicyDelayAction delayAction2;
482 delayAction2.delayTime = 10000;
483 g_actionCpuLit2->AddActionDelayTime(2, delayAction2);
484 g_actionCpuLit2->AddActionValue(2, "1.0");
485 g_actionCpuLit2->Execute();
486 PolicyDelayAction delayAction3;
487 delayAction3.delayTime = 10000;
488 g_actionCpuLit2->AddActionDelayTime(2, delayAction3);
489 g_actionCpuLit2->AddActionValue(2, "1.0");
490 g_actionCpuLit2->Execute();
491 PolicyDelayAction delayAction4;
492 delayAction4.delayTime = 10000;
493 g_actionCpuLit2->AddActionDelayTime(4, delayAction4);
494 g_actionCpuLit2->AddActionValue(4, "1.0");
495 g_actionCpuLit2->Execute();
496 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest010 end");
497 }
498
499 /**
500 * @tc.name: ThermalActionTest011
501 * @tc.desc: Action GPU Test
502 * @tc.type: FUNC
503 * @tc.require: issueI6KRS8
504 */
505 HWTEST_F(ThermalActionTest, ThermalActionTest011, TestSize.Level0)
506 {
507 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest011 start");
508 g_actionGpu->AddActionValue(0, "");
509 g_actionGpu->AddActionValue(0, "1.0");
510 g_actionGpu->Execute();
511 EXPECT_TRUE(g_actionGpu->valueList_.empty());
512 PolicyDelayAction delayAction;
513 delayAction.delayTime = 10000;
514 std::shared_ptr<IThermalAction> g_actionGpu2 = g_actionGpu;
515 g_actionGpu2->AddActionDelayTime(1, delayAction);
516 g_actionGpu2->AddActionValue(1, "1.0");
517 PolicyDelayAction delayAction2;
518 delayAction2.delayTime = 10000;
519 g_actionGpu2->AddActionDelayTime(2, delayAction2);
520 g_actionGpu2->AddActionValue(2, "1.0");
521 g_actionGpu2->Execute();
522 PolicyDelayAction delayAction3;
523 delayAction3.delayTime = 10000;
524 g_actionGpu2->AddActionDelayTime(2, delayAction3);
525 g_actionGpu2->AddActionValue(2, "1.0");
526 g_actionGpu2->Execute();
527 PolicyDelayAction delayAction4;
528 delayAction4.delayTime = 10000;
529 g_actionGpu2->AddActionDelayTime(4, delayAction4);
530 g_actionGpu2->AddActionValue(4, "1.0");
531 g_actionGpu2->Execute();
532 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest011 end");
533 }
534
535 /**
536 * @tc.name: ThermalActionTest012
537 * @tc.desc: Action Isolate CPU Test
538 * @tc.type: FUNC
539 */
540 HWTEST_F(ThermalActionTest, ThermalActionTest012, TestSize.Level0)
541 {
542 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest012 start");
543 g_actionCpuIsolate->AddActionValue(0, "");
544 g_actionCpuIsolate->AddActionValue(0, "1.0");
545 g_actionCpuIsolate->Execute();
546 g_actionCpuIsolate->SetStrict(true);
547 g_actionCpuIsolate->AddActionValue(0, "2.0");
548 g_actionCpuIsolate->GetActionValue();
549 EXPECT_FALSE(g_actionCpuIsolate->valueList_.empty());
550 PolicyDelayAction delayAction;
551 delayAction.delayTime = 10000;
552 std::shared_ptr<IThermalAction> g_actionCpuIsolate2 = g_actionCpuIsolate;
553 g_actionCpuIsolate2->AddActionDelayTime(1, delayAction);
554 g_actionCpuIsolate2->AddActionValue(1, "1.0");
555 PolicyDelayAction delayAction2;
556 delayAction2.delayTime = 10000;
557 g_actionCpuIsolate2->AddActionDelayTime(2, delayAction2);
558 g_actionCpuIsolate2->AddActionValue(2, "1.0");
559 g_actionCpuIsolate2->Execute();
560 PolicyDelayAction delayAction3;
561 delayAction3.delayTime = 10000;
562 g_actionCpuIsolate2->AddActionDelayTime(2, delayAction3);
563 g_actionCpuIsolate2->AddActionValue(2, "1.0");
564 g_actionCpuIsolate2->Execute();
565 PolicyDelayAction delayAction4;
566 delayAction4.delayTime = 10000;
567 g_actionCpuIsolate2->AddActionDelayTime(4, delayAction4);
568 g_actionCpuIsolate2->AddActionValue(4, "1.0");
569 g_actionCpuIsolate2->Execute();
570 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest012 end");
571 }
572
573 /**
574 * @tc.name: ThermalActionTest013
575 * @tc.desc: Action node Test
576 * @tc.type: FUNC
577 */
578 HWTEST_F(ThermalActionTest, ThermalActionTest013, TestSize.Level0)
579 {
580 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest013 start");
581 std::string input = "1";
582 g_actionNode->InitParams("/data/service/el0/thermal/config/lcd");
583 g_actionNode->AddActionValue(0, input);
584 g_actionNode->Execute();
585 char buf[BUF_LEN];
586 FileOperation::ReadFile("/data/service/el0/thermal/config/lcd", buf, BUF_LEN);
587 std::string ret = buf;
588 EXPECT_EQ(input, ret);
589 PolicyDelayAction delayAction;
590 delayAction.delayTime = 10000;
591 std::shared_ptr<IThermalAction> g_actionNode2 = g_actionNode;
592 g_actionNode2->AddActionDelayTime(1, delayAction);
593 g_actionNode2->AddActionValue(1, "1.0");
594 PolicyDelayAction delayAction2;
595 delayAction2.delayTime = 10000;
596 g_actionNode2->AddActionDelayTime(2, delayAction2);
597 g_actionNode2->AddActionValue(2, "1.0");
598 g_actionNode2->Execute();
599 PolicyDelayAction delayAction3;
600 delayAction3.delayTime = 10000;
601 g_actionNode2->AddActionDelayTime(2, delayAction3);
602 g_actionNode2->AddActionValue(2, "1.0");
603 g_actionNode2->Execute();
604 PolicyDelayAction delayAction4;
605 delayAction4.delayTime = 10000;
606 g_actionNode2->AddActionDelayTime(4, delayAction4);
607 g_actionNode2->AddActionValue(4, "1.0");
608 g_actionNode2->Execute();
609 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest013 end");
610 }
611
612 /**
613 * @tc.name: ThermalActionTest015
614 * @tc.desc: Action Timer Test
615 * @tc.type: FUNC
616 */
617 HWTEST_F(ThermalActionTest, ThermalActionTest015, TestSize.Level0)
618 {
619 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest015 start");
620 auto timerInfo = std::make_shared<ThermalTimerInfo>();
621 ASSERT_NE(timerInfo, nullptr);
622 OHOS::PowerMgr::ThermalTimerInfo::TimerInfoCallback callback;
623 timerInfo->SetCallbackInfo(callback);
624 timerInfo->OnTrigger();
625 auto timer = std::make_shared<ThermalTimer>();
626 ASSERT_NE(timer, nullptr);
627 uint64_t triggerTime = 1;
628 std::shared_ptr<ThermalTimerInfo> info;
629 uint64_t timerId = timer->CreateTimer(info);
630 EXPECT_EQ(timerId, 0);
631 timer->StartTimer(timerId, triggerTime);
632 timer->DestroyTimer(timerId);
633 timer->StopTimer(timerId);
634 auto timerUtils = std::make_shared<ThermalTimerUtils>();
635 ASSERT_NE(timerUtils, nullptr);
636 timerUtils->Stop();
637 int delay = 1;
638 OHOS::PowerMgr::ThermalTimerUtils::NotifyTask task;
639 timerUtils->Start(delay, task);
640 timerUtils->Start(delay, task);
641 timerUtils->Stop();
642 timerUtils->Stop();
643 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest015 end");
644 }
645
646 /**
647 * @tc.name: ThermalActionTest016
648 * @tc.desc: Action Popup Test
649 * @tc.type: FUNC
650 */
651 HWTEST_F(ThermalActionTest, ThermalActionTest016, TestSize.Level0)
652 {
653 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest016 start");
654 g_actionPopup->AddActionValue(0, "pop");
655 g_actionPopup->Execute();
656 EXPECT_TRUE(g_actionPopup->valueList_.empty());
657 PolicyDelayAction delayAction;
658 delayAction.delayTime = 10000;
659 std::shared_ptr<IThermalAction> g_actionPopup2 = g_actionPopup;
660 g_actionPopup2->AddActionDelayTime(1, delayAction);
661 g_actionPopup2->AddActionValue(1, "1.0");
662 PolicyDelayAction delayAction2;
663 delayAction2.delayTime = 10000;
664 g_actionPopup2->AddActionDelayTime(2, delayAction2);
665 g_actionPopup2->AddActionValue(2, "1.0");
666 g_actionPopup2->Execute();
667 PolicyDelayAction delayAction3;
668 delayAction3.delayTime = 10000;
669 g_actionPopup2->AddActionDelayTime(2, delayAction3);
670 g_actionPopup2->AddActionValue(2, "1.0");
671 g_actionPopup2->Execute();
672 PolicyDelayAction delayAction4;
673 delayAction4.delayTime = 10000;
674 g_actionPopup2->AddActionDelayTime(4, delayAction4);
675 g_actionPopup2->AddActionValue(4, "1.0");
676 g_actionPopup2->Execute();
677 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest016 end");
678 }
679
680 /**
681 * @tc.name: ThermalActionTest014
682 * @tc.desc: Action Airplane Function Test
683 * @tc.type: FUNC
684 */
685 HWTEST_F(ThermalActionTest, ThermalActionTest014, TestSize.Level0)
686 {
687 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest014 start");
688 g_actionAirplane->InitParams("airplane");
689 g_actionAirplane->AddActionValue(0, "0");
690 g_actionAirplane->AddActionValue(0, "0");
691 g_actionAirplane->AddActionValue(0, "air");
692 g_actionAirplane->Execute();
693 EXPECT_TRUE(g_actionAirplane->valueList_.empty());
694 std::string input = "1";
695 g_actionAirplane->AddActionValue(0, input);
696 g_actionCpuIsolate->SetStrict(true);
697 uint32_t value = g_actionAirplane->GetActionValue();
698 int32_t ret = g_actionAirplane->AirplaneRequest(value);
699 g_actionAirplane->AirplaneRequest(0);
700 g_actionAirplane->AirplaneRequest(1);
701 EXPECT_TRUE(ret == ERR_OK);
702 ret = g_actionAirplane->AirplaneExecution(value);
703 EXPECT_TRUE(ret == ERR_OK);
704 PolicyDelayAction delayAction;
705 delayAction.delayTime = 10000;
706 std::shared_ptr<IThermalAction> g_actionAirplane2 = g_actionAirplane;
707 g_actionAirplane2->AddActionDelayTime(1, delayAction);
708 g_actionAirplane2->AddActionValue(1, "1.0");
709 PolicyDelayAction delayAction2;
710 delayAction2.delayTime = 10000;
711 g_actionAirplane2->AddActionDelayTime(2, delayAction2);
712 g_actionAirplane2->AddActionValue(2, "1.0");
713 g_actionAirplane2->Execute();
714 PolicyDelayAction delayAction3;
715 delayAction3.delayTime = 10000;
716 g_actionAirplane2->AddActionDelayTime(2, delayAction3);
717 g_actionAirplane2->AddActionValue(2, "1.0");
718 g_actionAirplane2->Execute();
719 PolicyDelayAction delayAction4;
720 delayAction4.delayTime = 10000;
721 g_actionAirplane2->AddActionDelayTime(4, delayAction4);
722 g_actionAirplane2->AddActionValue(4, "1.0");
723 g_actionAirplane2->Execute();
724 THERMAL_HILOGI(LABEL_TEST, "ThermalActionTest014 end");
725 }
726 } // namespace
727