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