• 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 "stats_powermgr_test.h"
17 
18 #include <call_manager_inner_type.h>
19 #include <hisysevent.h>
20 
21 #include "battery_stats_client.h"
22 #include "stats_hisysevent.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS::HiviewDFX;
26 using namespace OHOS::PowerMgr;
27 using namespace OHOS::Telephony;
28 using namespace OHOS;
29 using namespace std;
30 
31 
SetUpTestCase()32 void StatsPowerMgrTest::SetUpTestCase()
33 {
34     ParserAveragePowerFile();
35     system("hidumper -s 3302 -a -u");
36 }
37 
TearDownTestCase()38 void StatsPowerMgrTest::TearDownTestCase()
39 {
40     system("hidumper -s 3302 -a -r");
41 }
42 
SetUp()43 void StatsPowerMgrTest::SetUp()
44 {
45     auto& statsClient = BatteryStatsClient::GetInstance();
46     statsClient.SetOnBattery(true);
47 }
48 
TearDown()49 void StatsPowerMgrTest::TearDown()
50 {
51     auto& statsClient = BatteryStatsClient::GetInstance();
52     statsClient.SetOnBattery(false);
53 }
54 
55 namespace {
56 /**
57  * @tc.name: StatsPowerMgrTest_009
58  * @tc.desc: test GetTotalTimeSecond function(Sensor Gravity)
59  * @tc.type: FUNC
60  */
61 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_009, TestSize.Level0)
62 {
63     auto& statsClient = BatteryStatsClient::GetInstance();
64     statsClient.Reset();
65 
66     int32_t stateOn = 1;
67     int32_t stateOff = 0;
68     int32_t uid = 10003;
69     int32_t pid = 3458;
70 
71     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
72         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
73     usleep(POWER_CONSUMPTION_DURATION_US);
74     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
75         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
76 
77     long expectedTime = round(POWER_CONSUMPTION_DURATION_US / US_PER_SECOND);
78     long actualTime = statsClient.GetTotalTimeSecond(StatsUtils::STATS_TYPE_SENSOR_GRAVITY_ON, uid);
79     GTEST_LOG_(INFO) << __func__ << ": expected time = " << expectedTime << " seconds";
80     GTEST_LOG_(INFO) << __func__ << ": actual time = " <<  actualTime << " seconds";
81     EXPECT_EQ(expectedTime, actualTime);
82 }
83 
84 /**
85  * @tc.name: StatsPowerMgrTest_010
86  * @tc.desc: test GetAppStatsMah function(Sensor Gravity)
87  * @tc.type: FUNC
88  */
89 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_010, TestSize.Level0)
90 {
91     auto& statsClient = BatteryStatsClient::GetInstance();
92     statsClient.Reset();
93 
94     double sensorGravityOnAverageMa = g_statsParser->GetAveragePowerMa(StatsUtils::CURRENT_SENSOR_GRAVITY);
95     int32_t uid = 10003;
96     int32_t pid = 3458;
97     int32_t stateOn = 1;
98     int32_t stateOff = 0;
99 
100     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
101         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
102     usleep(POWER_CONSUMPTION_DURATION_US);
103     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
104         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
105 
106     double expectedPower = POWER_CONSUMPTION_DURATION_US * sensorGravityOnAverageMa / US_PER_HOUR;
107     double actualPower = statsClient.GetAppStatsMah(uid);
108     double devPrecent = abs(expectedPower - actualPower) / expectedPower;
109     GTEST_LOG_(INFO) << __func__ << ": expected consumption = " << expectedPower << " mAh";
110     GTEST_LOG_(INFO) << __func__ << ": actual consumption = " << actualPower << " mAh";
111     EXPECT_LE(devPrecent, DEVIATION_PERCENT_THRESHOLD);
112 }
113 
114 /**
115  * @tc.name: StatsPowerMgrTest_011
116  * @tc.desc: test GetAppStatsPercent function(Sensor Gravity)
117  * @tc.type: FUNC
118  */
119 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_011, TestSize.Level0)
120 {
121     auto& statsClient = BatteryStatsClient::GetInstance();
122     statsClient.Reset();
123 
124     int32_t uid = 10003;
125     int32_t pid = 3458;
126     int32_t stateOn = 1;
127     int32_t stateOff = 0;
128     double fullPercent = 1;
129     double zeroPercent = 0;
130 
131     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
132         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
133     usleep(POWER_CONSUMPTION_DURATION_US);
134     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
135         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
136     double actualPercent = statsClient.GetAppStatsPercent(uid);
137     GTEST_LOG_(INFO) << __func__ << ": actual percent = " << actualPercent;
138     EXPECT_TRUE(actualPercent >= zeroPercent && actualPercent <= fullPercent);
139 }
140 
141 /**
142  * @tc.name: StatsPowerMgrTest_012
143  * @tc.desc: test GetAppStatsMah(Sensor Gravity) and GetAppStatsPercent(Sensor Proximity) function
144  * @tc.type: FUNC
145  */
146 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_012, TestSize.Level0)
147 {
148     auto& statsClient = BatteryStatsClient::GetInstance();
149     statsClient.Reset();
150 
151     double sensorGravityOnAverageMa = g_statsParser->GetAveragePowerMa(StatsUtils::CURRENT_SENSOR_GRAVITY);
152     int32_t uid = 10003;
153     int32_t pid = 3458;
154     int32_t stateOn = 1;
155     int32_t stateOff = 0;
156 
157     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
158         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
159     usleep(POWER_CONSUMPTION_DURATION_US);
160     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_GRAVITY,
161         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
162 
163     double expectedPower = POWER_CONSUMPTION_DURATION_US * sensorGravityOnAverageMa / US_PER_HOUR;
164     double actualPower = statsClient.GetAppStatsMah(uid);
165     double devPrecent = abs(expectedPower - actualPower) / expectedPower;
166     GTEST_LOG_(INFO) << __func__ << ": expected consumption = " << expectedPower << " mAh";
167     GTEST_LOG_(INFO) << __func__ << ": actual consumption = " << actualPower << " mAh";
168     EXPECT_LE(devPrecent, DEVIATION_PERCENT_THRESHOLD);
169 
170     uid = 10004;
171     pid = 3459;
172     stateOn = 1;
173     stateOff = 0;
174     double fullPercent = 1;
175     double zeroPercent = 0;
176 
177     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
178         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
179     usleep(POWER_CONSUMPTION_DURATION_US);
180     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
181         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
182     double actualPercent = statsClient.GetAppStatsPercent(uid);
183     GTEST_LOG_(INFO) << __func__ << ": actual percent = " << actualPercent;
184     EXPECT_TRUE(actualPercent >= zeroPercent && actualPercent <= fullPercent);
185 }
186 
187 /**
188  * @tc.name: StatsPowerMgrTest_013
189  * @tc.desc: test GetTotalTimeSecond function(Sensor Proximity)
190  * @tc.type: FUNC
191  */
192 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_013, TestSize.Level0)
193 {
194     auto& statsClient = BatteryStatsClient::GetInstance();
195     statsClient.Reset();
196 
197     int32_t stateOn = 1;
198     int32_t stateOff = 0;
199     int32_t uid = 10003;
200     int32_t pid = 3458;
201 
202     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
203         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
204     usleep(POWER_CONSUMPTION_DURATION_US);
205     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
206         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
207 
208     double expectedPower = StatsUtils::DEFAULT_VALUE;
209     double actualPower = statsClient.GetTotalTimeSecond(StatsUtils::STATS_TYPE_SENSOR_PROXIMITY_ON, uid);
210     GTEST_LOG_(INFO) << __func__ << ": expected consumption = " << expectedPower << " mAh";
211     GTEST_LOG_(INFO) << __func__ << ": actual consumption = " << actualPower << " mAh";
212     EXPECT_EQ(expectedPower, actualPower);
213 }
214 
215 /**
216  * @tc.name: StatsPowerMgrTest_014
217  * @tc.desc: test GetAppStatsMah function(Sensor Proximity)
218  * @tc.type: FUNC
219  */
220 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_014, TestSize.Level0)
221 {
222     auto& statsClient = BatteryStatsClient::GetInstance();
223     statsClient.Reset();
224 
225     double sensorProximityOnAverageMa = g_statsParser->GetAveragePowerMa(StatsUtils::CURRENT_SENSOR_PROXIMITY);
226     int32_t uid = 10003;
227     int32_t pid = 3458;
228     int32_t stateOn = 1;
229     int32_t stateOff = 0;
230 
231     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
232         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
233     usleep(POWER_CONSUMPTION_DURATION_US);
234     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
235         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
236 
237     double expectedPower = POWER_CONSUMPTION_DURATION_US * sensorProximityOnAverageMa / US_PER_HOUR;
238     double actualPower = statsClient.GetAppStatsMah(uid);
239     double devPrecent = abs(expectedPower - actualPower) / expectedPower;
240     GTEST_LOG_(INFO) << __func__ << ": expected consumption = " << expectedPower << " mAh";
241     GTEST_LOG_(INFO) << __func__ << ": actual consumption = " << actualPower << " mAh";
242     EXPECT_LE(devPrecent, DEVIATION_PERCENT_THRESHOLD);
243 }
244 
245 /**
246  * @tc.name: StatsPowerMgrTest_015
247  * @tc.desc: test GetAppStatsPercent function(Sensor Proximity)
248  * @tc.type: FUNC
249  */
250 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_015, TestSize.Level0)
251 {
252     auto& statsClient = BatteryStatsClient::GetInstance();
253     statsClient.Reset();
254 
255     int32_t uid = 10003;
256     int32_t pid = 3458;
257     int32_t stateOn = 1;
258     int32_t stateOff = 0;
259     double fullPercent = 1;
260     double zeroPercent = 0;
261 
262     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
263         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
264     usleep(POWER_CONSUMPTION_DURATION_US);
265     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
266         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
267     double actualPercent = statsClient.GetAppStatsPercent(uid);
268     GTEST_LOG_(INFO) << __func__ << ": actual percent = " << actualPercent;
269     EXPECT_TRUE(actualPercent >= zeroPercent && actualPercent <= fullPercent);
270 }
271 
272 /**
273  * @tc.name: StatsPowerMgrTest_016
274  * @tc.desc: test GetAppStatsMah(Sensor Proximity) and GetAppStatsPercent(Torch) function
275  * @tc.type: FUNC
276  */
277 HWTEST_F (StatsPowerMgrTest, StatsPowerMgrTest_016, TestSize.Level0)
278 {
279     auto& statsClient = BatteryStatsClient::GetInstance();
280     statsClient.Reset();
281 
282     double sensorProximityOnAverageMa = g_statsParser->GetAveragePowerMa(StatsUtils::CURRENT_SENSOR_PROXIMITY);
283     int32_t uid = 10003;
284     int32_t pid = 3458;
285     int32_t stateOn = 1;
286     int32_t stateOff = 0;
287 
288     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
289         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
290     usleep(POWER_CONSUMPTION_DURATION_US);
291     HiSysEventWrite(HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_SENSOR_PROXIMITY,
292         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
293 
294     double expectedPower = POWER_CONSUMPTION_DURATION_US * sensorProximityOnAverageMa / US_PER_HOUR;
295     double actualPower = statsClient.GetAppStatsMah(uid);
296     double devPrecent = abs(expectedPower - actualPower) / expectedPower;
297     GTEST_LOG_(INFO) << __func__ << ": expected consumption = " << expectedPower << " mAh";
298     GTEST_LOG_(INFO) << __func__ << ": actual consumption = " << actualPower << " mAh";
299     EXPECT_LE(devPrecent, DEVIATION_PERCENT_THRESHOLD);
300 
301     uid = 10004;
302     pid = 3459;
303     stateOn = 1;
304     stateOff = 0;
305     double fullPercent = 1;
306     double zeroPercent = 0;
307 
308     HiSysEventWrite(HiSysEvent::Domain::CAMERA, StatsHiSysEvent::TORCH_STATE,
309         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOn);
310     usleep(POWER_CONSUMPTION_DURATION_US);
311     HiSysEventWrite(HiSysEvent::Domain::CAMERA, StatsHiSysEvent::TORCH_STATE,
312         HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", stateOff);
313     double actualPercent = statsClient.GetAppStatsPercent(uid);
314     GTEST_LOG_(INFO) << __func__ << ": actual percent = " << actualPercent;
315     EXPECT_TRUE(actualPercent >= zeroPercent && actualPercent <= fullPercent);
316 }
317 
318 /**
319  * @tc.name: BatteryStatsInfo_001
320  * @tc.desc: test class BatteryStatsInfo function
321  * @tc.type: FUNC
322  * @tc.require: issueI5X13X
323  */
324 HWTEST_F (StatsPowerMgrTest, BatteryStatsInfo_001, TestSize.Level0)
325 {
326     std::shared_ptr<BatteryStatsInfo> sptrStatsInfo = std::make_shared<BatteryStatsInfo>();
327     EXPECT_NE(sptrStatsInfo, nullptr);
328     int32_t uid = 1004;
329     int32_t userId = 10005;
330     BatteryStatsInfo::ConsumptionType consumptionType = BatteryStatsInfo::CONSUMPTION_TYPE_APP;
331     double totalPowerMah = 1000.0;
332     double partPowerMah = 200.0;
333 
334     EXPECT_EQ(StatsUtils::INVALID_VALUE, sptrStatsInfo->GetUid());
335     sptrStatsInfo->SetPower(partPowerMah);
336     EXPECT_EQ(partPowerMah, sptrStatsInfo->GetPower());
337 
338     sptrStatsInfo->SetUid(uid);
339     sptrStatsInfo->SetUserId(userId);
340     sptrStatsInfo->SetConsumptioType(consumptionType);
341     sptrStatsInfo->SetPower(totalPowerMah);
342     EXPECT_EQ(uid, sptrStatsInfo->GetUid());
343     EXPECT_EQ(userId, sptrStatsInfo->GetUserId());
344     EXPECT_EQ(consumptionType, sptrStatsInfo->GetConsumptionType());
345     EXPECT_EQ(totalPowerMah, sptrStatsInfo->GetPower());
346 
347     sptrStatsInfo->SetUid(StatsUtils::INVALID_VALUE);
348     EXPECT_EQ(uid, sptrStatsInfo->GetUid());
349     sptrStatsInfo->SetUserId(StatsUtils::INVALID_VALUE);
350     EXPECT_EQ(userId, sptrStatsInfo->GetUserId());
351 
352     Parcel infoParcel = {};
353     EXPECT_EQ(nullptr, sptrStatsInfo->Unmarshalling(infoParcel));
354 
355     sptrStatsInfo->Marshalling(infoParcel);
356     auto unmarshalInfo = sptrStatsInfo->Unmarshalling(infoParcel);
357     EXPECT_EQ(uid, unmarshalInfo->GetUid());
358     EXPECT_EQ(consumptionType, unmarshalInfo->GetConsumptionType());
359     EXPECT_EQ(totalPowerMah, unmarshalInfo->GetPower());
360 }
361 
362 /**
363  * @tc.name: BatteryStatsInfo_002
364  * @tc.desc: test class ConvertConsumptionType function
365  * @tc.type: FUNC
366  * @tc.require: issueI5X13X
367  */
368 HWTEST_F (StatsPowerMgrTest, BatteryStatsInfo_002, TestSize.Level0)
369 {
370     EXPECT_EQ("", BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_INVALID));
371     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_APP),
372         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_APP));
373     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_BLUETOOTH),
374         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_BLUETOOTH));
375     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_IDLE),
376         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_IDLE));
377     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_PHONE),
378         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_PHONE));
379     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_SCREEN),
380         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_SCREEN));
381     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_USER),
382         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_USER));
383     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_WIFI),
384         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_WIFI));
385     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_CAMERA),
386         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_CAMERA));
387     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_FLASHLIGHT),
388         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_FLASHLIGHT));
389     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_AUDIO),
390         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_AUDIO));
391     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_SENSOR),
392         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_SENSOR));
393     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_GNSS),
394         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_GNSS));
395     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_CPU),
396         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_CPU));
397     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_WAKELOCK),
398         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_WAKELOCK));
399     EXPECT_EQ(GET_VARIABLE_NAME(CONSUMPTION_TYPE_ALARM),
400         BatteryStatsInfo::ConvertConsumptionType(BatteryStatsInfo::CONSUMPTION_TYPE_ALARM));
401 }
402 
403 /**
404  * @tc.name: BatteryStatsParser_001
405  * @tc.desc: test class BatteryStatsParser function
406  * @tc.type: FUNC
407  * @tc.require: issueI5X13X
408  */
409 HWTEST_F (StatsPowerMgrTest, BatteryStatsParser_001, TestSize.Level0)
410 {
411     uint16_t normalLevel = 0;
412     uint16_t errorRadioOnLevel = 10;
413     EXPECT_EQ(0.0, g_statsParser->GetAveragePowerMa(StatsUtils::CURRENT_INVALID));
414     EXPECT_EQ(0.0, g_statsParser->GetAveragePowerMa(StatsUtils::CURRENT_INVALID, normalLevel));
415     EXPECT_EQ(0.0, g_statsParser->GetAveragePowerMa(StatsUtils::CURRENT_RADIO_ON, errorRadioOnLevel));
416 
417     uint16_t expectClusterNum = 3;
418     EXPECT_EQ(expectClusterNum, g_statsParser->GetClusterNum());
419 
420     uint16_t speedClusterZero = 0;
421     uint16_t expectSpeedCluster0Num = 14;
422     uint16_t errorSpeedCluster = 3;
423     EXPECT_EQ(expectSpeedCluster0Num, g_statsParser->GetSpeedNum(speedClusterZero));
424     EXPECT_EQ(StatsUtils::DEFAULT_VALUE, g_statsParser->GetSpeedNum(errorSpeedCluster));
425 }
426 
427 /**
428  * @tc.name: BatteryStatsRadio_001
429  * @tc.desc: test class BatteryStatsClient function with radio type
430  * @tc.type: FUNC
431  * @tc.require: issueI6ZT17
432  */
433 HWTEST_F (StatsPowerMgrTest, BatteryStatsRadio_001, TestSize.Level0)
434 {
435     auto& statsClient = BatteryStatsClient::GetInstance();
436     statsClient.Reset();
437 
438     double actualPower = statsClient.GetPartStatsMah(BatteryStatsInfo::CONSUMPTION_TYPE_RADIO);
439     double actualPercent = statsClient.GetPartStatsPercent(BatteryStatsInfo::CONSUMPTION_TYPE_RADIO);
440     EXPECT_TRUE(actualPower == StatsUtils::DEFAULT_VALUE && actualPercent == StatsUtils::DEFAULT_VALUE);
441 }
442 }