• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_report_test.h"
17 
18 #include "securec.h"
19 #include <fcntl.h>
20 #include <string>
21 #include <unistd.h>
22 #ifdef BATTERY_MANAGER_ENABLE
23 #include "battery_srv_client.h"
24 #endif
25 #ifdef BATTERY_STATS_ENABLE
26 #include "battery_stats_client.h"
27 #endif
28 #include "power_mgr_client.h"
29 #include "thermal_config_file_parser.h"
30 #include "thermal_mgr_client.h"
31 
32 #define private   public
33 #define protected public
34 #include "thermal_service.h"
35 #include "thermal_srv_config_parser.h"
36 #include "v1_1/ithermal_interface.h"
37 #include "v1_1/thermal_types.h"
38 #undef private
39 #undef protected
40 
41 using namespace testing::ext;
42 using namespace OHOS::PowerMgr;
43 using namespace OHOS;
44 using namespace std;
45 using namespace OHOS::HDI::Thermal::V1_1;
46 
47 namespace {
48 static std::shared_ptr<ThermalConfigFileParser> g_configParser = nullptr;
49 static std::vector<std::string> g_dumpArgs;
50 static std::string g_sceneState;
51 static const std::string POLICY_CFG_NAME = "base_safe";
52 constexpr int32_t THERMAL_RATIO_BEGIN = 0;
53 constexpr int32_t THERMAL_RATIO_LENGTH = 4;
54 const std::string SYSTEM_THERMAL_SERVICE_CONFIG_PATH = "/system/etc/thermal_config/thermal_service_config.xml";
55 sptr<ThermalService> g_service = nullptr;
56 } // namespace
57 
ParserThermalSrvConfigFile()58 void ThermalActionReportTest::ParserThermalSrvConfigFile()
59 {
60     if (g_configParser == nullptr) {
61         g_configParser = std::make_shared<ThermalConfigFileParser>();
62         if (!g_configParser->Init()) {
63             THERMAL_HILOGE(LABEL_TEST, "Thermal service config file parser initialization failed");
64         }
65     }
66 }
67 
SetCondition(int32_t value,const std::string & scene)68 int32_t ThermalActionReportTest::SetCondition(int32_t value, const std::string& scene)
69 {
70     THERMAL_HILOGI(LABEL_TEST, "battery = %{public}d, scene = %{public}s", value, scene.c_str());
71     HdfThermalCallbackInfo event;
72     ThermalZoneInfo info1;
73     info1.type = "battery";
74     info1.temp = value;
75     event.info.push_back(info1);
76     g_sceneState = scene;
77     g_service->SetScene(g_sceneState);
78     return g_service->HandleThermalCallbackEvent(event);
79 }
80 
GetThermalLevel(int32_t expectValue)81 int32_t ThermalActionReportTest::GetThermalLevel(int32_t expectValue)
82 {
83     int32_t value;
84     g_service->GetThermalLevel(value);
85     THERMAL_HILOGI(LABEL_TEST, "value: %{public}d", value);
86     EXPECT_EQ(value, expectValue) << "Thermal action policy failed";
87     return value;
88 }
89 
GetActionValue(const std::string & actionName,uint32_t level)90 std::string ThermalActionReportTest::GetActionValue(const std::string& actionName, uint32_t level)
91 {
92     THERMAL_HILOGI(LABEL_TEST, "action name = %{public}s, level = %{public}d", actionName.c_str(), level);
93     std::string value = "0";
94     std::vector<PolicyAction> vAction;
95     if (!g_configParser->GetActionPolicy(POLICY_CFG_NAME, level, vAction)) {
96         THERMAL_HILOGI(LABEL_TEST, "Get policy failed name = %{public}s, return", POLICY_CFG_NAME.c_str());
97         return value;
98     }
99     return ActionDecision(actionName, vAction);
100 }
101 
ActionDecision(const std::string & actionName,std::vector<PolicyAction> & vAction)102 std::string ThermalActionReportTest::ActionDecision(const std::string& actionName, std::vector<PolicyAction>& vAction)
103 {
104     THERMAL_HILOGI(LABEL_TEST, "action name = %{public}s", actionName.c_str());
105     if (actionName == LCD_ACTION_NAME) {
106         return LcdValueDecision(actionName, vAction);
107     } else {
108         return ActionValueDecision(actionName, vAction);
109     }
110 }
111 
ActionValueDecision(const std::string & actionName,std::vector<PolicyAction> & vAction)112 std::string ThermalActionReportTest::ActionValueDecision(
113     const std::string& actionName, std::vector<PolicyAction>& vAction)
114 {
115     THERMAL_HILOGI(LABEL_TEST, "action name = %{public}s", actionName.c_str());
116     int32_t value = -1;
117     std::vector<uint32_t> valueList;
118     for (auto actionIter : vAction) {
119         if (actionIter.actionName == actionName) {
120             if (actionIter.isProp) {
121                 if (StateDecision(actionIter.actionPropMap)) {
122                     valueList.push_back(stoi(actionIter.actionValue));
123                 }
124             } else {
125                 valueList.push_back(stoi(actionIter.actionValue));
126             }
127         }
128     }
129 
130     bool strict = g_configParser->GetActionStrict(actionName);
131     if (valueList.empty()) {
132         value = 0;
133     } else {
134         if (strict) {
135             value = *max_element(valueList.begin(), valueList.end());
136         } else {
137             value = *min_element(valueList.begin(), valueList.end());
138         }
139     }
140     std::string strValue = to_string(value);
141     return strValue;
142 }
143 
LcdValueDecision(const std::string & actionName,std::vector<PolicyAction> & vAction)144 std::string ThermalActionReportTest::LcdValueDecision(const std::string& actionName, std::vector<PolicyAction>& vAction)
145 {
146     THERMAL_HILOGI(LABEL_TEST, "action name = %{public}s", actionName.c_str());
147     float value = -1.0;
148     std::vector<float> valueList;
149     std::map<std::string, std::string> sceneMap;
150     for (auto actionIter : vAction) {
151         if (actionIter.actionName == actionName) {
152             if (actionIter.isProp) {
153                 if (StateDecision(actionIter.actionPropMap)) {
154                     valueList.push_back(stof(actionIter.actionValue));
155                     sceneMap.emplace(std::pair(actionIter.actionPropMap.begin()->second, actionIter.actionValue));
156                 }
157             } else {
158                 valueList.push_back(stof(actionIter.actionValue));
159             }
160         }
161     }
162 
163     for (auto sceneIter : sceneMap) {
164         if (g_sceneState == sceneIter.first) {
165             return sceneIter.second.c_str();
166         }
167     }
168 
169     bool strict = g_configParser->GetActionStrict(actionName);
170     if (valueList.empty()) {
171         value = 0;
172     } else {
173         if (strict) {
174             value = *max_element(valueList.begin(), valueList.end());
175         } else {
176             value = *min_element(valueList.begin(), valueList.end());
177         }
178     }
179     std::string strValue = to_string(value).substr(THERMAL_RATIO_BEGIN, THERMAL_RATIO_LENGTH);
180     return strValue;
181 }
182 
StateDecision(std::map<std::string,std::string> & actionPropMap)183 bool ThermalActionReportTest::StateDecision(std::map<std::string, std::string>& actionPropMap)
184 {
185     bool ret = true;
186     std::map<std::string, std::string> stateMap;
187     GetStateMap(stateMap);
188     for (auto prop : actionPropMap) {
189         auto stateIter = stateMap.find(prop.first);
190         THERMAL_HILOGI(LABEL_TEST, "state = %{public}s, value = %{public}s", prop.first.c_str(), prop.second.c_str());
191         if (stateIter != stateMap.end()) {
192             THERMAL_HILOGI(LABEL_TEST, "state iter = %{public}s, iter value = %{public}s", stateIter->first.c_str(),
193                 stateIter->second.c_str());
194             if (stateIter->second.compare(prop.second) == 0) {
195                 continue;
196             } else {
197                 ret = false;
198                 break;
199             }
200         }
201     }
202     return ret;
203 }
204 
GetScreenState()205 std::string ThermalActionReportTest::GetScreenState()
206 {
207     std::string state = "0";
208     auto& powerMgrClient = PowerMgrClient::GetInstance();
209     if (powerMgrClient.IsScreenOn()) {
210         state = "1";
211     }
212     return state;
213 }
214 
GetChargeState()215 std::string ThermalActionReportTest::GetChargeState()
216 {
217     std::string state = "";
218 #ifdef BATTERY_MANAGER_ENABLE
219     auto& batterySrvClient = BatterySrvClient::GetInstance();
220     BatteryChargeState chargeState = batterySrvClient.GetChargingStatus();
221     if (chargeState == BatteryChargeState::CHARGE_STATE_ENABLE) {
222         state = "1";
223     } else if (chargeState == BatteryChargeState::CHARGE_STATE_NONE) {
224         state = "0";
225     }
226 #endif
227     return state;
228 }
229 
GetStateMap(std::map<std::string,std::string> & stateMap)230 void ThermalActionReportTest::GetStateMap(std::map<std::string, std::string>& stateMap)
231 {
232     std::vector<StateItem> stateItem = g_configParser->GetStateItem();
233     for (auto stateIter : stateItem) {
234         std::string state = "";
235         if (stateIter.name == "scene") {
236             state = g_sceneState;
237         } else if (stateIter.name == "screen") {
238             state = GetScreenState();
239         } else if (stateIter.name == "charge") {
240             state = GetChargeState();
241         }
242         stateMap.emplace(std::pair(stateIter.name, state));
243     }
244     for (auto iter : stateMap) {
245         THERMAL_HILOGI(
246             LABEL_TEST, "stateMap name = %{public}s, value = %{public}s", iter.first.c_str(), iter.second.c_str());
247     }
248 }
249 
ThermalActionTriggered(const std::string & actionName,int32_t level,const std::string & dumpInfo,bool isReversed)250 void ThermalActionReportTest::ThermalActionTriggered(
251     const std::string& actionName, int32_t level, const std::string& dumpInfo, bool isReversed)
252 {
253     bool enableEvent = g_configParser->GetActionEnableEvent(actionName);
254     THERMAL_HILOGI(LABEL_TEST, "action name = %{public}s, event flag = %{public}d", actionName.c_str(), enableEvent);
255     if (!enableEvent) {
256         GTEST_LOG_(INFO) << __func__ << " action name: " << actionName << " enalbe event flag is false, return";
257         return;
258     }
259     std::string value = GetActionValue(actionName, level);
260     std::string expectedDumpInfo;
261     std::string valueLabel = " Value = ";
262     if (actionName == LCD_ACTION_NAME) {
263         valueLabel = " Ratio = ";
264     }
265     expectedDumpInfo.append("Additional debug info: ")
266         .append("Event name = ACTION_TRIGGERED")
267         .append(" Action name = ")
268         .append(actionName)
269         .append(valueLabel)
270         .append(value);
271     THERMAL_HILOGI(LABEL_TEST, "value: %{public}s", value.c_str());
272     GTEST_LOG_(INFO) << __func__ << " action name: " << actionName << " expected debug info: " << expectedDumpInfo;
273 }
274 
SetUpTestCase()275 void ThermalActionReportTest::SetUpTestCase()
276 {
277     ParserThermalSrvConfigFile();
278     g_dumpArgs.push_back("-batterystats");
279     g_service = ThermalService::GetInstance();
280     g_service->InitSystemTestModules();
281     g_service->OnStart();
282     g_service->InitStateMachine();
283     g_service->InitActionManager();
284 }
285 
TearDownTestCase()286 void ThermalActionReportTest::TearDownTestCase()
287 {
288     g_service->OnStop();
289 }
290 
TearDown()291 void ThermalActionReportTest::TearDown()
292 {
293     g_service->SetScene("");
294     HdfThermalCallbackInfo event;
295     ThermalZoneInfo info1;
296     info1.type = "battery";
297     info1.temp = 0;
298     event.info.push_back(info1);
299     g_service->HandleThermalCallbackEvent(event);
300 }
301 
302 #ifdef BATTERY_STATS_ENABLE
303 namespace {
304 /**
305  * @tc.name: ThermalActionReportTest001
306  * @tc.desc: test dump info when thermal action is triggered
307  * @tc.type: FEATURE
308  * @tc.cond: Set battery temp = 40100, scence = cam
309  * @tc.result battery stats dump info
310  */
311 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest001, TestSize.Level0)
312 {
313     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.001 function start!");
314     auto& statsClient = BatteryStatsClient::GetInstance();
315     statsClient.Reset();
316 
317     int32_t ret = -1;
318     int32_t batteryTemp = 40100;
319     std::string sceneState = "cam";
320     int32_t expectLevel = 1;
321     ret = SetCondition(batteryTemp, sceneState);
322     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
323     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
324     // sleep 100ms for hisys_event handle
325     usleep(100000);
326     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
327     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
328     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
329     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
330     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
331     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
332     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
333     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
334     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
335     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
336     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
337     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
338     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
339     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
340     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.001 function end!");
341 }
342 
343 /**
344  * @tc.name: ThermalActionReportTest002
345  * @tc.desc: test dump info when thermal action is triggered
346  * @tc.type: FEATURE
347  * @tc.cond: Set battery temp = 40100, scence = call
348  * @tc.result battery stats dump info
349  */
350 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest002, TestSize.Level0)
351 {
352     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.002 function start!");
353     auto& statsClient = BatteryStatsClient::GetInstance();
354     statsClient.Reset();
355 
356     int32_t ret = -1;
357     int32_t batteryTemp = 40100;
358     std::string sceneState = "call";
359     int32_t expectLevel = 1;
360     ret = SetCondition(batteryTemp, sceneState);
361     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
362     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
363     // sleep 100ms for hisys_event handle
364     usleep(100000);
365     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
366     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
367     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
368     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
369     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
370     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
371     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
372     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
373     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
374     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
375     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
376     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
377     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
378     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
379     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.002 function end!");
380 }
381 
382 /**
383  * @tc.name: ThermalActionReportTest003
384  * @tc.desc: test dump info when thermal action is triggered
385  * @tc.type: FEATURE
386  * @tc.cond: Set battery temp = 40100, scence = game
387  * @tc.result battery stats dump info
388  */
389 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest003, TestSize.Level0)
390 {
391     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.003 function start!");
392     auto& statsClient = BatteryStatsClient::GetInstance();
393     statsClient.Reset();
394 
395     int32_t ret = -1;
396     int32_t batteryTemp = 40100;
397     std::string sceneState = "game";
398     int32_t expectLevel = 1;
399     ret = SetCondition(batteryTemp, sceneState);
400     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
401 
402     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
403     // sleep 100ms for hisys_event handle
404     usleep(100000);
405     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
406     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
407     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
408     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
409     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
410     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
411     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
412     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
413     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
414     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
415     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
416     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
417     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
418     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
419     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.003 function end!");
420 }
421 
422 /**
423  * @tc.name: ThermalActionReportTest004
424  * @tc.desc: test dump info when thermal action is triggered
425  * @tc.type: FEATURE
426  * @tc.cond: Set battery temp = 40100, scence = ""
427  * @tc.result battery stats dump info
428  */
429 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest004, TestSize.Level0)
430 {
431     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.004 function start!");
432     auto& statsClient = BatteryStatsClient::GetInstance();
433     statsClient.Reset();
434 
435     int32_t ret = -1;
436     int32_t batteryTemp = 40100;
437     std::string sceneState = "";
438     int32_t expectLevel = 1;
439     ret = SetCondition(batteryTemp, sceneState);
440     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
441 
442     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
443     // sleep 100ms for hisys_event handle
444     usleep(100000);
445     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
446     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
447     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
448     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
449     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
450     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
451     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
452     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
453     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
454     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
455     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
456     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
457     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
458     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
459     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.004 function end!");
460 }
461 
462 /**
463  * @tc.name: ThermalActionReportTest005
464  * @tc.desc: test dump info when thermal action is triggered
465  * @tc.type: FEATURE
466  * @tc.cond: Set battery temp = 43100, scence = cam
467  * @tc.result battery stats dump info
468  */
469 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest005, TestSize.Level0)
470 {
471     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.005 function start!");
472     auto& statsClient = BatteryStatsClient::GetInstance();
473     statsClient.Reset();
474 
475     int32_t ret = -1;
476     int32_t batteryTemp = 43100;
477     std::string sceneState = "cam";
478     int32_t expectLevel = 2;
479     ret = SetCondition(batteryTemp, sceneState);
480     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
481 
482     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
483     // sleep 100ms for hisys_event handle
484     usleep(100000);
485     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
486     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
487     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
488     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
489     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
490     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
491     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
492     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
493     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
494     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
495     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
496     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
497     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
498     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
499     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.005 function end!");
500 }
501 
502 /**
503  * @tc.name: ThermalActionReportTest006
504  * @tc.desc: test dump info when thermal action is triggered
505  * @tc.type: FEATURE
506  * @tc.cond: Set battery temp = 43100, scence = call
507  * @tc.result battery stats dump info
508  */
509 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest006, TestSize.Level0)
510 {
511     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.006 function start!");
512     auto& statsClient = BatteryStatsClient::GetInstance();
513     statsClient.Reset();
514 
515     int32_t ret = -1;
516     int32_t batteryTemp = 43100;
517     std::string sceneState = "call";
518     int32_t expectLevel = 2;
519     ret = SetCondition(batteryTemp, sceneState);
520     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
521 
522     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
523     // sleep 100ms for hisys_event handle
524     usleep(100000);
525     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
526     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
527     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
528     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
529     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
530     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
531     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
532     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
533     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
534     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
535     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
536     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
537     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
538     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
539     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.006 function end!");
540 }
541 
542 /**
543  * @tc.name: ThermalActionReportTest007
544  * @tc.desc: test dump info when thermal action is triggered
545  * @tc.type: FEATURE
546  * @tc.cond: Set battery temp = 43100, scence = game
547  * @tc.result battery stats dump info
548  */
549 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest007, TestSize.Level0)
550 {
551     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.007 function start!");
552     auto& statsClient = BatteryStatsClient::GetInstance();
553     statsClient.Reset();
554 
555     int32_t ret = -1;
556     int32_t batteryTemp = 43100;
557     std::string sceneState = "game";
558     int32_t expectLevel = 2;
559     ret = SetCondition(batteryTemp, sceneState);
560     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
561 
562     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
563     // sleep 100ms for hisys_event handle
564     usleep(100000);
565     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
566     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
567     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
568     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
569     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
570     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
571     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
572     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
573     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
574     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
575     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
576     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
577     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
578     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
579     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.007 function end!");
580 }
581 
582 /**
583  * @tc.name: ThermalActionReportTest008
584  * @tc.desc: test dump info when thermal action is triggered
585  * @tc.type: FEATURE
586  * @tc.cond: Set battery temp = 43100, scence = ""
587  * @tc.result battery stats dump info
588  */
589 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest008, TestSize.Level0)
590 {
591     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.008 function start!");
592     auto& statsClient = BatteryStatsClient::GetInstance();
593     statsClient.Reset();
594 
595     int32_t ret = -1;
596     int32_t batteryTemp = 43100;
597     std::string sceneState = "";
598     int32_t expectLevel = 2;
599     ret = SetCondition(batteryTemp, sceneState);
600     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
601 
602     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
603     // sleep 100ms for hisys_event handle
604     usleep(100000);
605     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
606     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
607     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
608     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
609     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
610     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
611     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
612     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
613     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
614     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
615     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
616     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
617     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
618     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo);
619     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.008 function end!");
620 }
621 
622 /**
623  * @tc.name: ThermalActionReportTest009
624  * @tc.desc: test dump info when thermal action is triggered
625  * @tc.type: FEATURE
626  * @tc.cond: Set battery temp = 46100, scence = cam
627  * @tc.result battery stats dump info
628  */
629 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest009, TestSize.Level0)
630 {
631     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.009 function start!");
632     auto& statsClient = BatteryStatsClient::GetInstance();
633     statsClient.Reset();
634 
635     int32_t ret = -1;
636     int32_t batteryTemp = 46100;
637     std::string sceneState = "cam";
638     int32_t expectLevel = 3;
639     ret = SetCondition(batteryTemp, sceneState);
640     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
641 
642     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
643     // sleep 100ms for hisys_event handle
644     usleep(100000);
645     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
646     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
647     ThermalActionReportTest::ThermalActionTriggered(AIRPLANE_ACTION_NAME, level, actualDumpInfo);
648     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
649     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
650     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
651     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
652     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
653     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
654     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
655     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
656     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
657     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
658     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
659     ThermalActionReportTest::ThermalActionTriggered(SHUTDOWN_ACTION_NAME, level, actualDumpInfo);
660     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo, true);
661     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.009 function end!");
662 }
663 
664 /**
665  * @tc.name: ThermalActionReportTest010
666  * @tc.desc: test dump info when thermal action is triggered
667  * @tc.type: FEATURE
668  * @tc.cond: Set battery temp = 46100, scence = call
669  * @tc.result battery stats dump info
670  */
671 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest010, TestSize.Level0)
672 {
673     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.010 function start!");
674     auto& statsClient = BatteryStatsClient::GetInstance();
675     statsClient.Reset();
676 
677     int32_t ret = -1;
678     int32_t batteryTemp = 46100;
679     std::string sceneState = "call";
680     int32_t expectLevel = 3;
681     ret = SetCondition(batteryTemp, sceneState);
682     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
683 
684     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
685     // sleep 100ms for hisys_event handle
686     usleep(100000);
687     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
688     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
689     ThermalActionReportTest::ThermalActionTriggered(AIRPLANE_ACTION_NAME, level, actualDumpInfo);
690     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
691     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
692     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
693     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
694     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
695     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
696     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
697     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
698     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
699     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
700     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
701     ThermalActionReportTest::ThermalActionTriggered(SHUTDOWN_ACTION_NAME, level, actualDumpInfo);
702     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo, true);
703     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.010 function end!");
704 }
705 
706 /**
707  * @tc.name: ThermalActionReportTest011
708  * @tc.desc: test dump info when thermal action is triggered
709  * @tc.type: FEATURE
710  * @tc.cond: Set battery temp = 46100, scence = game
711  * @tc.result battery stats dump info
712  */
713 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest011, TestSize.Level0)
714 {
715     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.011 function start!");
716     auto& statsClient = BatteryStatsClient::GetInstance();
717     statsClient.Reset();
718 
719     int32_t ret = -1;
720     int32_t batteryTemp = 46100;
721     std::string sceneState = "game";
722     int32_t expectLevel = 3;
723     ret = SetCondition(batteryTemp, sceneState);
724     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
725 
726     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
727     // sleep 100ms for hisys_event handle
728     usleep(100000);
729     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
730     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
731     ThermalActionReportTest::ThermalActionTriggered(AIRPLANE_ACTION_NAME, level, actualDumpInfo);
732     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
733     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
734     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
735     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
736     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
737     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
738     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
739     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
740     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
741     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
742     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
743     ThermalActionReportTest::ThermalActionTriggered(SHUTDOWN_ACTION_NAME, level, actualDumpInfo);
744     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo, true);
745     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.011 function end!");
746 }
747 
748 /**
749  * @tc.name: ThermalActionReportTest012
750  * @tc.desc: test dump info when thermal action is triggered
751  * @tc.type: FEATURE
752  * @tc.cond: Set battery temp = 46100, scence = ""
753  * @tc.result battery stats dump info
754  */
755 HWTEST_F(ThermalActionReportTest, ThermalActionReportTest012, TestSize.Level0)
756 {
757     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.012 function start!");
758     auto& statsClient = BatteryStatsClient::GetInstance();
759     statsClient.Reset();
760 
761     int32_t ret = -1;
762     int32_t batteryTemp = 46100;
763     std::string sceneState = "";
764     int32_t expectLevel = 3;
765     ret = SetCondition(batteryTemp, sceneState);
766     EXPECT_EQ(ret, ERR_OK) << " Thermal action fail due to set condition error";
767 
768     int32_t level = ThermalActionReportTest::GetThermalLevel(expectLevel);
769     // sleep 100ms for hisys_event handle
770     usleep(100000);
771     std::string actualDumpInfo = statsClient.Dump(g_dumpArgs);
772     GTEST_LOG_(INFO) << __func__ << ": actual dump info: " << actualDumpInfo;
773     ThermalActionReportTest::ThermalActionTriggered(AIRPLANE_ACTION_NAME, level, actualDumpInfo);
774     ThermalActionReportTest::ThermalActionTriggered(CPU_BIG_ACTION_NAME, level, actualDumpInfo);
775     ThermalActionReportTest::ThermalActionTriggered(CPU_MED_ACTION_NAME, level, actualDumpInfo);
776     ThermalActionReportTest::ThermalActionTriggered(CPU_LIT_ACTION_NAME, level, actualDumpInfo);
777     ThermalActionReportTest::ThermalActionTriggered(GPU_ACTION_NAME, level, actualDumpInfo);
778     ThermalActionReportTest::ThermalActionTriggered(LCD_ACTION_NAME, level, actualDumpInfo);
779     ThermalActionReportTest::ThermalActionTriggered(PROCESS_ACTION_NAME, level, actualDumpInfo);
780     ThermalActionReportTest::ThermalActionTriggered(THERMAL_LEVEL_NAME, level, actualDumpInfo);
781     ThermalActionReportTest::ThermalActionTriggered(CURRENT_SC_ACTION_NAME, level, actualDumpInfo);
782     ThermalActionReportTest::ThermalActionTriggered(CURRENT_BUCK_ACTION_NAME, level, actualDumpInfo);
783     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_SC_ACTION_NAME, level, actualDumpInfo);
784     ThermalActionReportTest::ThermalActionTriggered(VOLATAGE_BUCK_ACTION_NAME, level, actualDumpInfo);
785     ThermalActionReportTest::ThermalActionTriggered(SHUTDOWN_ACTION_NAME, level, actualDumpInfo);
786     ThermalActionReportTest::ThermalActionTriggered(CPU_BOOST_ACTION_NAME, level, actualDumpInfo, true);
787     THERMAL_HILOGI(LABEL_TEST, "Thermal action report test No.012 function end!");
788 }
789 } // namespace
790 #endif // BATTERY_STATS_ENABLE
791