1 /*
2  * Copyright (c) 2022-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 "stats_service_dump_test.h"
17 #include "stats_log.h"
18 
19 #include <display_power_info.h>
20 #include <hisysevent.h>
21 #include <running_lock_info.h>
22 #include <string_ex.h>
23 
24 #include "battery_stats_listener.h"
25 #include "battery_stats_service.h"
26 #include "hisysevent_operation.h"
27 #include "stats_hisysevent.h"
28 #include "stats_service_test_proxy.h"
29 #include "stats_service_write_event.h"
30 
31 using namespace testing::ext;
32 using namespace OHOS::HiviewDFX;
33 using namespace OHOS::PowerMgr;
34 using namespace OHOS;
35 using namespace std;
36 
37 namespace {
38 static sptr<BatteryStatsService> g_statsService = nullptr;
39 static std::shared_ptr<StatsServiceTestProxy> g_statsServiceProxy = nullptr;
40 static std::vector<std::string> dumpArgs;
41 } // namespace
42 
SetUpTestCase()43 void StatsServiceDumpTest::SetUpTestCase()
44 {
45     ParserAveragePowerFile();
46     g_statsService = BatteryStatsService::GetInstance();
47     g_statsService->OnStart();
48     g_statsService->isBootCompleted_ = true;
49 
50     if (g_statsService->listenerPtr_ == nullptr) {
51         g_statsService->listenerPtr_ = std::make_shared<BatteryStatsListener>();
52     }
53 
54     if (g_statsServiceProxy == nullptr) {
55         g_statsServiceProxy = std::make_shared<StatsServiceTestProxy>(g_statsService);
56     }
57     dumpArgs.push_back("-batterystats");
58 }
59 
TearDownTestCase()60 void StatsServiceDumpTest::TearDownTestCase()
61 {
62     g_statsService->listenerPtr_ = nullptr;
63     g_statsService->OnStop();
64 }
65 
SetUp()66 void StatsServiceDumpTest::SetUp()
67 {
68     auto statsService = BatteryStatsService::GetInstance();
69     statsService->SetOnBattery(true);
70 }
71 
TearDown()72 void StatsServiceDumpTest::TearDown()
73 {
74     auto statsService = BatteryStatsService::GetInstance();
75     statsService->SetOnBattery(false);
76 }
77 
78 namespace {
79 /**
80  * @tc.name: StatsServiceDumpTest_001
81  * @tc.desc: test Dump function(BATTERY_CHANGED)
82  * @tc.type: FUNC
83  * @tc.require: issueI663DX
84  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_001, TestSize.Level0)85 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_001, TestSize.Level0)
86 {
87     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_001 start");
88     ASSERT_NE(g_statsServiceProxy, nullptr);
89     auto statsService = BatteryStatsService::GetInstance();
90     g_statsServiceProxy->Reset();
91 
92     int32_t batteryLevel = 60;
93     int32_t batteryChargerType = 2;
94 
95     StatsWriteHiSysEvent(statsService,
96         HiSysEvent::Domain::BATTERY, StatsHiSysEvent::BATTERY_CHANGED, HiSysEvent::EventType::STATISTIC, "LEVEL",
97         batteryLevel, "CHARGER", batteryChargerType);
98 
99     std::string expectedDebugInfo;
100     expectedDebugInfo.append("Battery level = ")
101         .append(ToString(batteryLevel))
102         .append(", Charger type = ")
103         .append(ToString(batteryChargerType));
104 
105     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
106     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
107     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
108     auto index = actualDebugInfo.find(expectedDebugInfo);
109     EXPECT_TRUE(index != string::npos);
110 
111     StatsWriteHiSysEvent(statsService,
112         HiSysEvent::Domain::BATTERY, StatsHiSysEvent::BATTERY_CHANGED, HiSysEvent::EventType::STATISTIC);
113     std::string expectedMissInfo;
114     expectedMissInfo.append("Battery level = ").append(ToString(-1));
115     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
116     auto missIndex = actualMissInfo.find(expectedMissInfo);
117     EXPECT_TRUE(missIndex != string::npos);
118     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_001 end");
119 }
120 
121 /**
122  * @tc.name: StatsServiceDumpTest_002
123  * @tc.desc: test Dump function(POWER_RUNNINGLOCK)
124  * @tc.type: FUNC
125  * @tc.require: issueI663DX
126  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_002, TestSize.Level0)127 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_002, TestSize.Level0)
128 {
129     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_002 start");
130     ASSERT_NE(g_statsServiceProxy, nullptr);
131     auto statsService = BatteryStatsService::GetInstance();
132     g_statsServiceProxy->Reset();
133 
134     int32_t uid = 10001;
135     int32_t pid = 3456;
136     int32_t stateLock = 1;
137     int32_t stateUnlock = 0;
138     int32_t type = static_cast<int32_t>(RunningLockType::RUNNINGLOCK_SCREEN);
139     std::string name = " StatsServiceDumpTest_002";
140 
141     StatsWriteHiSysEvent(statsService,
142         HiSysEvent::Domain::POWER, StatsHiSysEvent::POWER_RUNNINGLOCK, HiSysEvent::EventType::STATISTIC, "PID", pid,
143         "UID", uid, "STATE", stateLock, "TYPE", type, "NAME", name);
144     usleep(US_PER_MS);
145     StatsWriteHiSysEvent(statsService,
146         HiSysEvent::Domain::POWER, StatsHiSysEvent::POWER_RUNNINGLOCK, HiSysEvent::EventType::STATISTIC, "PID", pid,
147         "UID", uid, "STATE", stateUnlock, "TYPE", type, "NAME", name);
148 
149     std::string expectedDebugInfo;
150     expectedDebugInfo.append("UID = ")
151         .append(ToString(uid))
152         .append(", PID = ")
153         .append(ToString(pid))
154         .append(", wakelock type = ")
155         .append(ToString(type))
156         .append(", wakelock name = ")
157         .append(name);
158 
159     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
160     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
161     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
162     auto index = actualDebugInfo.find(expectedDebugInfo);
163     EXPECT_TRUE(index != string::npos);
164 
165     StatsWriteHiSysEvent(statsService,
166         HiSysEvent::Domain::POWER, StatsHiSysEvent::POWER_RUNNINGLOCK, HiSysEvent::EventType::STATISTIC);
167     std::string expectedMissInfo;
168     expectedMissInfo.append(", wakelock name = ").append("");
169     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
170     auto missIndex = actualMissInfo.find(expectedMissInfo);
171     EXPECT_TRUE(missIndex != string::npos);
172     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_002 end");
173 }
174 
175 /**
176  * @tc.name: StatsServiceDumpTest_003
177  * @tc.desc: test Dump function(BACKLIGHT_DISCOUNT)
178  * @tc.type: FUNC
179  * @tc.require: issueI663DX
180  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_003, TestSize.Level0)181 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_003, TestSize.Level0)
182 {
183     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_003 start");
184     ASSERT_NE(g_statsServiceProxy, nullptr);
185     auto statsService = BatteryStatsService::GetInstance();
186     g_statsServiceProxy->Reset();
187 
188     int32_t ratio = 100;
189 
190     StatsWriteHiSysEvent(statsService,
191         HiSysEvent::Domain::DISPLAY, StatsHiSysEvent::BACKLIGHT_DISCOUNT,
192         HiSysEvent::EventType::STATISTIC, "RATIO", ratio);
193     std::string expectedDebugInfo;
194     expectedDebugInfo.append("Additional debug info: ")
195         .append("Event name = ")
196         .append(StatsHiSysEvent::BACKLIGHT_DISCOUNT)
197         .append(" Ratio = ")
198         .append(ToString(ratio));
199 
200     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
201     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
202     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
203     auto index = actualDebugInfo.find(expectedDebugInfo);
204     EXPECT_TRUE(index != string::npos);
205 
206     StatsWriteHiSysEvent(statsService,
207         HiSysEvent::Domain::DISPLAY, StatsHiSysEvent::BACKLIGHT_DISCOUNT, HiSysEvent::EventType::STATISTIC);
208     std::string expectedMissInfo;
209     expectedMissInfo.append(" Ratio = ").append("");
210     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
211     auto missIndex = actualMissInfo.find(expectedMissInfo);
212     EXPECT_TRUE(missIndex != string::npos);
213     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_003 end");
214 }
215 
216 /**
217  * @tc.name: StatsServiceDumpTest_004
218  * @tc.desc: test Dump function(POWER_WORKSCHEDULER)
219  * @tc.type: FUNC
220  * @tc.require: issueI663DX
221  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_004, TestSize.Level0)222 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_004, TestSize.Level0)
223 {
224     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_004 start");
225     ASSERT_NE(g_statsServiceProxy, nullptr);
226     auto statsService = BatteryStatsService::GetInstance();
227     g_statsServiceProxy->Reset();
228 
229     int32_t pid = 3457;
230     int32_t uid = 10002;
231     int32_t type = 1;
232     int32_t interval = 30000;
233     int32_t state = 5;
234 
235     StatsWriteHiSysEvent(statsService,
236         HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_WORKSCHEDULER,
237         HiSysEvent::EventType::STATISTIC, "PID", pid,
238         "UID", uid, "TYPE", type, "INTERVAL", interval, "STATE", state);
239 
240     std::string expectedDebugInfo;
241     expectedDebugInfo.append("UID = ")
242         .append(ToString(uid))
243         .append(", PID = ")
244         .append(ToString(pid))
245         .append(", work type = ")
246         .append(ToString(type))
247         .append(", work interval = ")
248         .append(ToString(interval))
249         .append(", work state = ")
250         .append(ToString(state));
251 
252     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
253     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
254     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
255     auto index = actualDebugInfo.find(expectedDebugInfo);
256     EXPECT_TRUE(index != string::npos);
257 
258     StatsWriteHiSysEvent(statsService,
259         HiSysEvent::Domain::STATS, StatsHiSysEvent::POWER_WORKSCHEDULER, HiSysEvent::EventType::STATISTIC);
260     std::string expectedMissInfo;
261     expectedMissInfo.append(", work interval = ").append("");
262     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
263     auto missIndex = actualMissInfo.find(expectedMissInfo);
264     EXPECT_TRUE(missIndex != string::npos);
265     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_004 end");
266 }
267 
268 /**
269  * @tc.name: StatsServiceDumpTest_005
270  * @tc.desc: test Dump function(POWER_TEMPERATURE)
271  * @tc.type: FUNC
272  * @tc.require: issueI663DX
273  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_005, TestSize.Level0)274 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_005, TestSize.Level0)
275 {
276     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_005 start");
277     ASSERT_NE(g_statsServiceProxy, nullptr);
278     auto statsService = BatteryStatsService::GetInstance();
279     g_statsServiceProxy->Reset();
280 
281     std::string partName = "Battery";
282     int32_t temperature = 40;
283 
284     StatsWriteHiSysEvent(statsService,
285         HiSysEvent::Domain::THERMAL, StatsHiSysEvent::POWER_TEMPERATURE, HiSysEvent::EventType::STATISTIC, "NAME",
286         partName, "TEMPERATURE", temperature);
287 
288     std::string expectedDebugInfo;
289     expectedDebugInfo.append("Additional debug info: ")
290         .append("Event name = POWER_TEMPERATURE")
291         .append(" Name = ")
292         .append(partName);
293 
294     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
295     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
296     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
297     auto index = actualDebugInfo.find(expectedDebugInfo);
298     EXPECT_TRUE(index != string::npos);
299 
300     StatsWriteHiSysEvent(statsService,
301         HiSysEvent::Domain::THERMAL, StatsHiSysEvent::POWER_TEMPERATURE, HiSysEvent::EventType::STATISTIC);
302     std::string expectedMissInfo;
303     expectedMissInfo.append("Additional debug info: ")
304         .append("Event name = POWER_TEMPERATURE")
305         .append(" Name = ")
306         .append("");
307     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
308     auto missIndex = actualMissInfo.find(expectedMissInfo);
309     EXPECT_TRUE(missIndex != string::npos);
310     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_005 end");
311 }
312 
313 /**
314  * @tc.name: StatsServiceDumpTest_006
315  * @tc.desc: test Dump function(START_REMOTE_ABILITY)
316  * @tc.type: FUNC
317  * @tc.require: issueI663DX
318  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_006, TestSize.Level0)319 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_006, TestSize.Level0)
320 {
321     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_006 start");
322     ASSERT_NE(g_statsServiceProxy, nullptr);
323     auto statsService = BatteryStatsService::GetInstance();
324     g_statsServiceProxy->Reset();
325 
326     std::string callType = "DUBAI_TAG_DIST_SCHED_TO_REMOTE";
327     int32_t callUid = 10003;
328     int32_t callPid = 3458;
329     std::string targetBundle = "TargetBundleName";
330     std::string targetAbility = "TargetAbilityName";
331     int32_t callAppUid = 9568;
332     int32_t result = 1;
333 
334     StatsWriteHiSysEvent(statsService,
335         HiSysEvent::Domain::DISTRIBUTED_SCHEDULE,
336         StatsHiSysEvent::START_REMOTE_ABILITY, HiSysEvent::EventType::BEHAVIOR,
337         "CALLING_TYPE", callType, "CALLING_UID", callUid, "CALLING_PID", callPid, "TARGET_BUNDLE", targetBundle,
338         "TARGET_ABILITY", targetAbility, "CALLING_APP_UID", callAppUid, "RESULT", result);
339 
340     std::string expectedDebugInfo;
341     expectedDebugInfo.append("Additional debug info: ")
342         .append("Event name = START_REMOTE_ABILITY")
343         .append(" Calling Type = ")
344         .append(callType);
345 
346     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
347     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
348     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
349     auto index = actualDebugInfo.find(expectedDebugInfo);
350     EXPECT_TRUE(index != string::npos);
351 
352     StatsWriteHiSysEvent(statsService,
353         HiSysEvent::Domain::DISTRIBUTED_SCHEDULE,
354         StatsHiSysEvent::START_REMOTE_ABILITY, HiSysEvent::EventType::BEHAVIOR);
355     std::string expectedMissInfo;
356     expectedMissInfo.append("Additional debug info: ")
357         .append("Event name = START_REMOTE_ABILITY")
358         .append(" Calling Type = ")
359         .append("");
360     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
361     auto missIndex = actualMissInfo.find(expectedMissInfo);
362     EXPECT_TRUE(missIndex != string::npos);
363     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_006 end");
364 }
365 
366 /**
367  * @tc.name: StatsServiceDumpTest_007
368  * @tc.desc: test Dump function(THERMAL_ACTION_TRIGGERED)
369  * @tc.type: FUNC
370  * @tc.require: issueI663DX
371  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_007, TestSize.Level0)372 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_007, TestSize.Level0)
373 {
374     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_007 start");
375     ASSERT_NE(g_statsServiceProxy, nullptr);
376     auto statsService = BatteryStatsService::GetInstance();
377     g_statsServiceProxy->Reset();
378 
379     std::string actionName = "thermallevel";
380     int32_t value = 3;
381     float ratio = 0.60;
382     int32_t beginPos = 0;
383     int32_t ratioLen = 4;
384 
385     StatsWriteHiSysEvent(statsService,
386         HiviewDFX::HiSysEvent::Domain::THERMAL, StatsHiSysEvent::THERMAL_ACTION_TRIGGERED,
387         HiviewDFX::HiSysEvent::EventType::STATISTIC, "ACTION", actionName, "VALUE", value, "RATIO", ratio);
388 
389     std::string expectedDebugInfo;
390     expectedDebugInfo.append("Additional debug info: ")
391         .append("Event name = ACTION_TRIGGERED")
392         .append(" Action name = ")
393         .append(actionName)
394         .append(" Value = ")
395         .append(ToString(value))
396         .append(" Ratio = ")
397         .append(std::to_string(ratio).substr(beginPos, ratioLen));
398 
399     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
400     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
401     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
402     auto index = actualDebugInfo.find(expectedDebugInfo);
403     EXPECT_TRUE(index != string::npos);
404 
405     StatsWriteHiSysEvent(statsService,
406         HiSysEvent::Domain::THERMAL, StatsHiSysEvent::THERMAL_ACTION_TRIGGERED, HiSysEvent::EventType::STATISTIC);
407     std::string expectedMissInfo;
408     expectedMissInfo.append("Additional debug info: ")
409         .append("Event name = ACTION_TRIGGERED")
410         .append(" Action name = ")
411         .append("");
412     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
413     auto missIndex = actualMissInfo.find(expectedMissInfo);
414     EXPECT_TRUE(missIndex != string::npos);
415     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_007 end");
416 }
417 
418 /**
419  * @tc.name: StatsServiceDumpTest_008
420  * @tc.desc: test Dump function(AMBIENT_LIGHT)
421  * @tc.type: FUNC
422  * @tc.require: issueI663DX
423  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_008, TestSize.Level0)424 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_008, TestSize.Level0)
425 {
426     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_008 start");
427     ASSERT_NE(g_statsServiceProxy, nullptr);
428     auto statsService = BatteryStatsService::GetInstance();
429     g_statsServiceProxy->Reset();
430 
431     int32_t type = 100;
432     int32_t level = 101;
433 
434     StatsWriteHiSysEvent(statsService,
435         HiSysEvent::Domain::DISPLAY, StatsHiSysEvent::AMBIENT_LIGHT,
436         HiSysEvent::EventType::STATISTIC, "TYPE", type, "LEVEL", level);
437 
438     std::string expectedDebugInfo;
439     expectedDebugInfo.append("Additional debug info: ")
440         .append("Event name = ")
441         .append(StatsHiSysEvent::AMBIENT_LIGHT)
442         .append(" Ambient type = ")
443         .append(ToString(type))
444         .append(" Ambient brightness = ")
445         .append(ToString(level));
446 
447     std::string actualDebugInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
448     GTEST_LOG_(INFO) << __func__ << ": expected debug info: " << expectedDebugInfo;
449     GTEST_LOG_(INFO) << __func__ << ": actual debug info: " << actualDebugInfo;
450     auto index = actualDebugInfo.find(expectedDebugInfo);
451     EXPECT_TRUE(index != string::npos);
452 
453     StatsWriteHiSysEvent(statsService,
454         HiSysEvent::Domain::DISPLAY, StatsHiSysEvent::AMBIENT_LIGHT, HiSysEvent::EventType::STATISTIC);
455     std::string expectedMissInfo;
456     expectedMissInfo.append("Additional debug info: ")
457         .append("Event name = ")
458         .append(StatsHiSysEvent::AMBIENT_LIGHT)
459         .append(" Ambient type = ")
460         .append("");
461     std::string actualMissInfo = g_statsServiceProxy->ShellDump(dumpArgs, dumpArgs.size());
462     auto missIndex = actualMissInfo.find(expectedMissInfo);
463     EXPECT_TRUE(missIndex != string::npos);
464     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_008 end");
465 }
466 
467 /**
468  * @tc.name: StatsServiceDumpTest_009
469  * @tc.desc: test Dump function(args is none or help)
470  * @tc.type: FUNC
471  * @tc.require: issueI663DX
472  */
HWTEST_F(StatsServiceDumpTest, StatsServiceDumpTest_009, TestSize.Level0)473 HWTEST_F (StatsServiceDumpTest, StatsServiceDumpTest_009, TestSize.Level0)
474 {
475     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_009 start");
476     ASSERT_NE(g_statsServiceProxy, nullptr);
477     auto statsService = BatteryStatsService::GetInstance();
478     g_statsServiceProxy->Reset();
479 
480     std::vector<std::string> dumpArgsNone {};
481     std::vector<std::string> dumpArgsHelp {};
482     dumpArgsHelp.push_back("-h");
483 
484     std::string expectedDebugInfo;
485     expectedDebugInfo.append("usage: statistics <command> [<options>]\n");
486 
487     std::string noneDebugInfo = g_statsServiceProxy->ShellDump(dumpArgsNone, dumpArgsNone.size());
488     auto noneIndex = noneDebugInfo.find(expectedDebugInfo);
489     EXPECT_TRUE(noneIndex != string::npos);
490 
491     std::string helpDebugInfo = g_statsServiceProxy->ShellDump(dumpArgsHelp, dumpArgsHelp.size());
492     auto helpIndex = helpDebugInfo.find(expectedDebugInfo);
493     EXPECT_TRUE(helpIndex != string::npos);
494     STATS_HILOGI(LABEL_TEST, "StatsServiceDumpTest_009 end");
495 }
496 }