• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include <gtest/gtest.h>
16 #include <map>
17 #include <cstdlib>
18 #include <unistd.h>
19 #include <vector>
20 #include <cerrno>
21 
22 #include "iservice_registry.h"
23 #include "manager/dump_implement.h"
24 #include "raw_param.h"
25 #include "dump_utils.h"
26 #include "hidumper_test_utils.h"
27 
28 using namespace testing::ext;
29 namespace OHOS {
30 namespace HiviewDFX {
31 const int SCORE_ADJ = 1000;
32 const std::string SCORE_ADJ_STR = "1000";
33 const std::string TOOL_NAME = "hidumper";
34 char g_fileName[] = "/tmp/test.XXXXXX";
35 int g_fd = -1;
36 
37 const uint64_t BASELINE_SIZE = 1353 * 1024;
38 #if defined(__LP64__)
39 const std::string LIB_PATH = "lib64/";
40 #else
41 const std::string LIB_PATH = "lib/";
42 #endif
43 vector<string> OUTPUT_PATH = {
44     "/system/etc/init/hidumper_service.cfg",
45     "/system/etc/hidumper/infos_config.json",
46     "/system/bin/hidumper",
47     "/system/" + LIB_PATH + "libhidumperclient.z.so",
48     "/system/" + LIB_PATH + "libhidumper_client.z.so",
49     "/system/" + LIB_PATH + "libhidumpermemory.z.so",
50     "/system/" + LIB_PATH + "libhidumperservice.z.so",
51     "/system/" + LIB_PATH + "libhidumperservice_cpu_source.z.so",
52     "/system/" + LIB_PATH + "platformsdk/lib_dump_usage.z.so",
53 };
54 class HiDumperManagerTest : public testing::Test {
55 public:
56     static void SetUpTestCase(void);
57     static void TearDownTestCase(void);
58     void SetUp();
59     void TearDown();
60     int GetDumpResult(int argc, char *argv[]);
61     int fd_;
62 };
63 
SetUpTestCase(void)64 void HiDumperManagerTest::SetUpTestCase(void)
65 {
66     g_fd = mkstemp(g_fileName);
67     if (g_fd == -1) {
68         printf("create tmp file fail! erro = %s", DumpUtils::ErrnoToMsg(errno).c_str());
69         return;
70     }
71 }
TearDownTestCase(void)72 void HiDumperManagerTest::TearDownTestCase(void)
73 {
74     if (g_fd != -1) {
75         close(g_fd);
76         g_fd = -1;
77     }
78     unlink(g_fileName);
79 }
SetUp(void)80 void HiDumperManagerTest::SetUp(void)
81 {
82 }
TearDown(void)83 void HiDumperManagerTest::TearDown(void)
84 {
85 }
86 
GetDumpResult(int argc,char * argv[])87 int HiDumperManagerTest::GetDumpResult(int argc, char *argv[])
88 {
89     std::vector<std::u16string> args;
90     std::shared_ptr<RawParam> rawParam = std::make_shared<RawParam>(0, 1, 0, args, g_fd);
91     return DumpImplement::GetInstance().Main(argc, argv, rawParam);
92 }
93 
94 /**
95  * @tc.name: MemoryDumperTest001
96  * @tc.desc: Test help msg has correct ret.
97  * @tc.type: FUNC
98  * @tc.require: issueI5NWZQ
99  */
100 HWTEST_F(HiDumperManagerTest, DumpTest001, TestSize.Level0)
101 {
102     char *argv[] = {
103         const_cast<char *>(TOOL_NAME.c_str()),
104         const_cast<char *>("-h"),
105         const_cast<char *>(""),
106     };
107     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
108     int ret = GetDumpResult(argc, argv);
109     ASSERT_EQ(ret, DumpStatus::DUMP_HELP);
110 }
111 
112 /**
113  * @tc.name: MemoryDumperTest002
114  * @tc.desc: Test list system has correct ret.
115  * @tc.type: FUNC
116  * @tc.require: issueI5NWZQ
117  */
118 HWTEST_F(HiDumperManagerTest, DumpTest002, TestSize.Level0)
119 {
120     char *argv[] = {
121         const_cast<char *>(TOOL_NAME.c_str()),
122         const_cast<char *>("-lc"),
123         const_cast<char *>(""),
124     };
125     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
126     int ret = GetDumpResult(argc, argv);
127     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
128 }
129 
130 /**
131  * @tc.name: MemoryDumperTest003
132  * @tc.desc: Test list aility has correct ret.
133  * @tc.type: FUNC
134  * @tc.require: issueI5NWZQ
135  */
136 HWTEST_F(HiDumperManagerTest, DumpTest003, TestSize.Level0)
137 {
138     char *argv[] = {
139         const_cast<char *>(TOOL_NAME.c_str()),
140         const_cast<char *>("-ls"),
141         const_cast<char *>(""),
142     };
143     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
144     int ret = GetDumpResult(argc, argv);
145     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
146 }
147 
148 /**
149  * @tc.name: MemoryDumperTest004
150  * @tc.desc: Test dump base information has correct ret.
151  * @tc.type: FUNC
152  * @tc.require: issueI5NWZQ
153  */
154 HWTEST_F(HiDumperManagerTest, DumpTest004, TestSize.Level0)
155 {
156     char *argv[] = {
157         const_cast<char *>(TOOL_NAME.c_str()),
158         const_cast<char *>("-c"),
159         const_cast<char *>("base"),
160         const_cast<char *>(""),
161     };
162     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
163     int ret = GetDumpResult(argc, argv);
164     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
165 }
166 
167 /**
168  * @tc.name: DumpTest005
169  * @tc.desc: Test dump system information has correct ret.
170  * @tc.type: FUNC
171  * @tc.require: issueI5NWZQ
172  */
173 HWTEST_F(HiDumperManagerTest, DumpTest005, TestSize.Level0)
174 {
175     char *argv[] = {
176         const_cast<char *>(TOOL_NAME.c_str()),
177         const_cast<char *>("-c"),
178         const_cast<char *>("system"),
179         const_cast<char *>(""),
180     };
181     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
182     int ret = GetDumpResult(argc, argv);
183     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
184 }
185 
186 /**
187  * @tc.name: MemoryDumperTest006
188  * @tc.desc: Test dump all system information has correct ret.
189  * @tc.type: FUNC
190  * @tc.require: issueI5NWZQ
191  */
192 HWTEST_F(HiDumperManagerTest, DumpTest006, TestSize.Level0)
193 {
194     char *argv[] = {
195         const_cast<char *>(TOOL_NAME.c_str()),
196         const_cast<char *>("-c"),
197         const_cast<char *>(""),
198     };
199     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
200     int ret = GetDumpResult(argc, argv);
201     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
202 }
203 
204 /**
205  * @tc.name: MemoryDumperTest007
206  * @tc.desc: Test dump all ability has correct ret.
207  * @tc.type: FUNC
208  * @tc.require: issueI5NWZQ
209  */
210 HWTEST_F(HiDumperManagerTest, DumpTest007, TestSize.Level0)
211 {
212     char *argv[] = {
213         const_cast<char *>(TOOL_NAME.c_str()),
214         const_cast<char *>("-s"),
215         const_cast<char *>(""),
216     };
217     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
218     int ret = GetDumpResult(argc, argv);
219     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
220 }
221 
222 /**
223  * @tc.name: MemoryDumperTest007
224  * @tc.desc: Test dump one ability has correct ret.
225  * @tc.type: FUNC
226  * @tc.require: issueI5NWZQ
227  */
228 HWTEST_F(HiDumperManagerTest, DumpTest008, TestSize.Level0)
229 {
230     char *argv[] = {
231         const_cast<char *>(TOOL_NAME.c_str()),
232         const_cast<char *>("-s"),
233         const_cast<char *>("1212"),
234         const_cast<char *>(""),
235     };
236     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
237     int ret = GetDumpResult(argc, argv);
238     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
239 }
240 
241 /**
242  * @tc.name: DumpTest009
243  * @tc.desc: Test dump one ability with arg has correct ret.
244  * @tc.type: FUNC
245  * @tc.require: issueI5NWZQ
246  */
247 HWTEST_F(HiDumperManagerTest, DumpTest009, TestSize.Level0)
248 {
249     char *argv[] = {
250         const_cast<char *>(TOOL_NAME.c_str()),
251         const_cast<char *>("-s"),
252         const_cast<char *>("SensorService"),
253         const_cast<char *>("-a"),
254         const_cast<char *>("-h"),
255         const_cast<char *>(""),
256     };
257     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
258     int ret = GetDumpResult(argc, argv);
259     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
260 }
261 
262 /**
263  * @tc.name: DumpTest010
264  * @tc.desc: Test dump faultlogs of crash history has correct ret.
265  * @tc.type: FUNC
266  * @tc.require: issueI5NWZQ
267  */
268 HWTEST_F(HiDumperManagerTest, DumpTest010, TestSize.Level0)
269 {
270     char *argv[] = {
271         const_cast<char *>(TOOL_NAME.c_str()),
272         const_cast<char *>("-e"),
273         const_cast<char *>(""),
274     };
275     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
276     int ret = GetDumpResult(argc, argv);
277     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
278 }
279 
280 /**
281  * @tc.name: MemoryDumperTest011
282  * @tc.desc: Test dump network information has correct ret.
283  * @tc.type: FUNC
284  * @tc.require: issueI5NWZQ
285  */
286 HWTEST_F(HiDumperManagerTest, DumpTest011, TestSize.Level0)
287 {
288     char *argv[] = {
289         const_cast<char *>(TOOL_NAME.c_str()),
290         const_cast<char *>("--net"),
291         const_cast<char *>(""),
292     };
293     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
294     int ret = GetDumpResult(argc, argv);
295     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
296 }
297 
298 /**
299  * @tc.name: MemoryDumperTest012
300  * @tc.desc: Test dump storage information has correct ret.
301  * @tc.type: FUNC
302  * @tc.require: issueI5NWZQ
303  */
304 HWTEST_F(HiDumperManagerTest, DumpTest012, TestSize.Level0)
305 {
306     char *argv[] = {
307         const_cast<char *>(TOOL_NAME.c_str()),
308         const_cast<char *>("--storage"),
309         const_cast<char *>(""),
310     };
311     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
312     int ret = GetDumpResult(argc, argv);
313     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
314 }
315 
316 /**
317  * @tc.name: MemoryDumperTest013
318  * @tc.desc: Test dump processes information has correct ret.
319  * @tc.type: FUNC
320  * @tc.require: issueI5NWZQ
321  */
322 HWTEST_F(HiDumperManagerTest, DumpTest013, TestSize.Level0)
323 {
324     char *argv[] = {
325         const_cast<char *>(TOOL_NAME.c_str()),
326         const_cast<char *>("-p"),
327         const_cast<char *>(""),
328     };
329     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
330     int ret = GetDumpResult(argc, argv);
331     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
332 }
333 
334 /**
335  * @tc.name: MemoryDumperTest014
336  * @tc.desc: Test dump one process information has correct ret.
337  * @tc.type: FUNC
338  * @tc.require: issueI5NWZQ
339  */
340 HWTEST_F(HiDumperManagerTest, DumpTest014, TestSize.Level0)
341 {
342     char *argv[] = {
343         const_cast<char *>(TOOL_NAME.c_str()),
344         const_cast<char *>("-p"),
345         const_cast<char *>(std::to_string(getpid()).c_str()),
346         const_cast<char *>(""),
347     };
348     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
349     int ret = GetDumpResult(argc, argv);
350     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
351 }
352 
353 #ifdef HIDUMPER_HIVIEWDFX_HIVIEW_ENABLE
354 /**
355  * @tc.name: MemoryDumperTest015
356  * @tc.desc: Test dump all process cpu usage has correct ret.
357  * @tc.type: FUNC
358  * @tc.require: issueI5NWZQ
359  */
360 HWTEST_F(HiDumperManagerTest, DumpTest015, TestSize.Level0)
361 {
362     char *argv[] = {
363         const_cast<char *>(TOOL_NAME.c_str()),
364         const_cast<char *>("--cpuusage"),
365         const_cast<char *>(""),
366     };
367     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
368     int ret = GetDumpResult(argc, argv);
369     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
370 }
371 
372 /**
373  * @tc.name: MemoryDumperTest016
374  * @tc.desc: Test dump one process cpu usage has correct ret.
375  * @tc.type: FUNC
376  * @tc.require: issueI5NWZQ
377  */
378 HWTEST_F(HiDumperManagerTest, DumpTest016, TestSize.Level0)
379 {
380     char *argv[] = {
381         const_cast<char *>(TOOL_NAME.c_str()),
382         const_cast<char *>("--cpuusage"),
383         const_cast<char *>(std::to_string(getpid()).c_str()),
384         const_cast<char *>(""),
385     };
386     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
387     int ret = GetDumpResult(argc, argv);
388     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
389 }
390 #endif
391 
392 /**
393  * @tc.name: MemoryDumperTest017
394  * @tc.desc: Test dumpreal CPU frequency has correct ret.
395  * @tc.type: FUNC
396  * @tc.require: issueI5NWZQ
397  */
398 HWTEST_F(HiDumperManagerTest, DumpTest017, TestSize.Level0)
399 {
400     char *argv[] = {
401         const_cast<char *>(TOOL_NAME.c_str()),
402         const_cast<char *>("--cpufreq"),
403         const_cast<char *>(""),
404     };
405     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
406     int ret = GetDumpResult(argc, argv);
407     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
408 }
409 
410 /**
411  * @tc.name: MemoryDumperTest018
412  * @tc.desc: Test dump all processes memory info has correct ret.
413  * @tc.type: FUNC
414  * @tc.require: issueI5NWZQ
415  */
416 HWTEST_F(HiDumperManagerTest, DumpTest018, TestSize.Level0)
417 {
418     char *argv[] = {
419         const_cast<char *>(TOOL_NAME.c_str()),
420         const_cast<char *>("--mem"),
421         const_cast<char *>(""),
422     };
423     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
424     int ret = GetDumpResult(argc, argv);
425     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
426 }
427 
428 /**
429  * @tc.name: MemoryDumperTest019
430  * @tc.desc: Test dump one process memory info has correct ret.
431  * @tc.type: FUNC
432  * @tc.require: issueI5NWZQ
433  */
434 HWTEST_F(HiDumperManagerTest, DumpTest019, TestSize.Level0)
435 {
436     char *argv[] = {
437         const_cast<char *>(TOOL_NAME.c_str()),
438         const_cast<char *>("--mem"),
439         const_cast<char *>(std::to_string(getpid()).c_str()),
440         const_cast<char *>(""),
441     };
442     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
443     int ret = GetDumpResult(argc, argv);
444     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
445 }
446 
447 /**
448  * @tc.name: MemoryDumperTest020
449  * @tc.desc: Test compress has correct ret.
450  * @tc.type: FUNC
451  * @tc.require: issueI5NWZQ
452  */
453 HWTEST_F(HiDumperManagerTest, DumpTest020, TestSize.Level0)
454 {
455     char *argv[] = {
456         const_cast<char *>(TOOL_NAME.c_str()),
457         const_cast<char *>("-p"),
458         const_cast<char *>("--zip"),
459         const_cast<char *>(""),
460     };
461     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
462     std::vector<std::u16string> args;
463     std::shared_ptr<RawParam> rawParam = std::make_shared<RawParam>(0, 1, 0, args, g_fd);
464     std::string srcpath = "/data/log/hilog/";
465     rawParam->SetFolder(srcpath);
466     int ret = DumpImplement::GetInstance().Main(argc, argv, rawParam);
467     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
468 }
469 
470 /**
471  * @tc.name: MemoryDumperTest023
472  * @tc.desc: Test for all infomation.
473  * @tc.type: FUNC
474  */
475 HWTEST_F(HiDumperManagerTest, DumpTest023, TestSize.Level0)
476 {
477     char *argv[] = {
478         const_cast<char *>(TOOL_NAME.c_str()),
479         const_cast<char *>(""),
480     };
481     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
482     int ret = GetDumpResult(argc, argv);
483     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
484 }
485 
486 /**
487  * @tc.name: MemoryDumperTest021
488  * @tc.desc: Test dump statistic in /proc/pid/smaps has correct ret.
489  * @tc.type: FUNC
490  */
491 HWTEST_F(HiDumperManagerTest, DumpTest021, TestSize.Level0)
492 {
493     char *argv[] = {
494         const_cast<char *>(TOOL_NAME.c_str()),
495         const_cast<char *>("--mem-smaps"),
496         const_cast<char *>(std::to_string(getpid()).c_str()),
497         const_cast<char *>(""),
498     };
499     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
500     int ret = GetDumpResult(argc, argv);
501     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
502 }
503 
504 /**
505  * @tc.name: MemoryDumperTest022
506  * @tc.desc: Test dump details in /proc/pid/smaps has correct ret.
507  * @tc.type: FUNC
508  */
509 HWTEST_F(HiDumperManagerTest, DumpTest022, TestSize.Level0)
510 {
511     char *argv[] = {
512         const_cast<char *>(TOOL_NAME.c_str()),
513         const_cast<char *>("--mem-smaps"),
514         const_cast<char *>(std::to_string(getpid()).c_str()),
515         const_cast<char *>("-v"),
516     };
517     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
518     int ret = GetDumpResult(argc, argv);
519     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
520 }
521 
522 /**
523  * @tc.name: MemoryDumperTest024
524  * @tc.desc: Test ? msg has correct ret.
525  * @tc.type: FUNC
526  * @tc.require: issueI5NWZQ
527  */
528 HWTEST_F(HiDumperManagerTest, DumpTest024, TestSize.Level0)
529 {
530     char *argv[] = {
531         const_cast<char *>(TOOL_NAME.c_str()),
532         const_cast<char *>("-?"),
533         const_cast<char *>(""),
534     };
535     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
536     int ret = GetDumpResult(argc, argv);
537     ASSERT_EQ(ret, DumpStatus::DUMP_INVALID_ARG);
538 }
539 
540 /**
541  * @tc.name: MemoryDumperTest025
542  * @tc.desc: Test ? with -vv msg has correct ret.
543  * @tc.type: FUNC
544  * @tc.require: issueI5NWZQ
545  */
546 HWTEST_F(HiDumperManagerTest, DumpTest025, TestSize.Level0)
547 {
548     char *argv[] = {
549         const_cast<char *>(TOOL_NAME.c_str()),
550         const_cast<char *>("-?"),
551         const_cast<char *>("-v"),
552     };
553     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
554     int ret = GetDumpResult(argc, argv);
555     ASSERT_EQ(ret, DumpStatus::DUMP_INVALID_ARG);
556 }
557 
558 /**
559  * @tc.name: MemoryDumperTest026
560  * @tc.desc: Test cpufreq with ? msg has correct ret.
561  * @tc.type: FUNC
562  * @tc.require: issueI5NWZQ
563  */
564 HWTEST_F(HiDumperManagerTest, DumpTest026, TestSize.Level0)
565 {
566     char *argv[] = {
567         const_cast<char *>(TOOL_NAME.c_str()),
568         const_cast<char *>("--cpufreq"),
569         const_cast<char *>("-?"),
570     };
571     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
572     int ret = GetDumpResult(argc, argv);
573     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
574 }
575 
576 /**
577  * @tc.name: MemoryDumperTest027
578  * @tc.desc: Test error msg has correct ret.
579  * @tc.type: FUNC
580  * @tc.require: issueI5NWZQ
581  */
582 HWTEST_F(HiDumperManagerTest, DumpTest027, TestSize.Level0)
583 {
584     char *argv[] = {
585         const_cast<char *>(TOOL_NAME.c_str()),
586         const_cast<char *>("--error"),
587         const_cast<char *>(""),
588     };
589     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
590     int ret = GetDumpResult(argc, argv);
591     ASSERT_EQ(ret, DumpStatus::DUMP_INVALID_ARG);
592 }
593 
594 /**
595  * @tc.name: MemoryDumperTest028
596  * @tc.desc: Test dump error process memory info has correct ret.
597  * @tc.type: FUNC
598  * @tc.require: issueI5NWZQ
599  */
600 HWTEST_F(HiDumperManagerTest, DumpTest028, TestSize.Level0)
601 {
602     char *argv[] = {
603         const_cast<char *>(TOOL_NAME.c_str()),
604         const_cast<char *>("--mem"),
605         const_cast<char *>("-1"),
606         const_cast<char *>(""),
607     };
608     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
609     int ret = GetDumpResult(argc, argv);
610     ASSERT_EQ(ret, DumpStatus::DUMP_INVALID_ARG);
611 }
612 
613 /**
614  * @tc.name: MemoryDumperTest029
615  * @tc.desc: Test dump statistic in /proc/pid/smaps has correct ret.
616  * @tc.type: FUNC
617  */
618 HWTEST_F(HiDumperManagerTest, DumpTest029, TestSize.Level0)
619 {
620     char *argv[] = {
621         const_cast<char *>(TOOL_NAME.c_str()),
622         const_cast<char *>("--mem-jsheap"),
623         const_cast<char *>(std::to_string(getpid()).c_str()),
624         const_cast<char *>(""),
625     };
626     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
627     int ret = GetDumpResult(argc, argv);
628     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
629 }
630 
631 /**
632  * @tc.name: MemoryDumperTest030
633  * @tc.desc: Test dump statistic in /proc/pid/smaps has error ret.
634  * @tc.type: FUNC
635  */
636 HWTEST_F(HiDumperManagerTest, DumpTest030, TestSize.Level0)
637 {
638     char *argv[] = {
639         const_cast<char *>(TOOL_NAME.c_str()),
640         const_cast<char *>("--mem-smaps"),
641         const_cast<char *>(""),
642     };
643     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
644     int ret = GetDumpResult(argc, argv);
645     ASSERT_EQ(ret, DumpStatus::DUMP_FAIL);
646 }
647 
648 /**
649  * @tc.name: DumpTest031
650  * @tc.desc: Test too many arguments.
651  * @tc.type: FUNC
652  */
653 HWTEST_F(HiDumperManagerTest, DumpTest031, TestSize.Level0)
654 {
655     char *argv[] = {
656         const_cast<char *>(TOOL_NAME.c_str()),
657     };
658     int argc = ARG_MAX_COUNT + 1;
659     int ret = GetDumpResult(argc, argv);
660     ASSERT_EQ(ret, DumpStatus::DUMP_FAIL);
661 }
662 
663 /**
664  * @tc.name: DumpTest032
665  * @tc.desc: Test empty argument.
666  * @tc.type: FUNC
667  */
668 HWTEST_F(HiDumperManagerTest, DumpTest032, TestSize.Level0)
669 {
670     char *argv[] = {
671         const_cast<char *>(TOOL_NAME.c_str()),
672         const_cast<char *>("--mem"),
673         const_cast<char *>("-1"),
674         const_cast<char *>(""),
675         const_cast<char *>("--mem"),
676     };
677     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
678     int ret = GetDumpResult(argc, argv);
679     ASSERT_EQ(ret, DumpStatus::DUMP_FAIL);
680 }
681 
682 /**
683  * @tc.name: DumpTest033
684  * @tc.desc: Test too long argument .
685  * @tc.type: FUNC
686  */
687 HWTEST_F(HiDumperManagerTest, DumpTest033, TestSize.Level0)
688 {
689     std::string longArg;
690     longArg.assign(SINGLE_ARG_MAXLEN + 1, 'c');
691     char *argv[] = {
692         const_cast<char *>(TOOL_NAME.c_str()),
693         const_cast<char *>("-h"),
694         const_cast<char *>(longArg.c_str()),
695     };
696     int argc = sizeof(argv) / sizeof(argv[0]);
697     int ret = GetDumpResult(argc, argv);
698     ASSERT_EQ(ret, DumpStatus::DUMP_FAIL);
699 }
700 
701 /**
702  * @tc.name: DumpTest034
703  * @tc.desc: Test null argument.
704  * @tc.type: FUNC
705  */
706 HWTEST_F(HiDumperManagerTest, DumpTest034, TestSize.Level0)
707 {
708     char *argv[] = {
709         const_cast<char *>(TOOL_NAME.c_str()),
710         nullptr,
711     };
712     int argc = sizeof(argv) / sizeof(argv[0]);
713     int ret = GetDumpResult(argc, argv);
714     ASSERT_EQ(ret, DumpStatus::DUMP_FAIL);
715 }
716 
717 /**
718  * @tc.name: DumpTest035
719  * @tc.desc: Test DumpUtils
720  * @tc.type: FUNC
721  */
722 HWTEST_F(HiDumperManagerTest, DumpTest035, TestSize.Level0)
723 {
724     DumpUtils::SetAdj(SCORE_ADJ);
725     std::string name = DumpUtils::ConvertSaIdToSaName(SCORE_ADJ_STR);
726     ASSERT_TRUE(name == SCORE_ADJ_STR);
727 }
728 
729 /**
730  * @tc.name: MemoryDumperTest36
731  * @tc.desc: Test dump statistic in /proc/pid/smaps has correct ret.
732  * @tc.type: FUNC
733  */
734 HWTEST_F(HiDumperManagerTest, DumpTest036, TestSize.Level0)
735 {
736     char *argv[] = {
737         const_cast<char *>(TOOL_NAME.c_str()),
738         const_cast<char *>("--mem-cjheap"),
739         const_cast<char *>(std::to_string(getpid()).c_str()),
740         const_cast<char *>(""),
741     };
742     int argc = sizeof(argv) / sizeof(argv[0]) - 1;
743     int ret = GetDumpResult(argc, argv);
744     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
745 }
746 
747 /**
748  * @tc.name: DumpTest037
749  * @tc.desc: Test illegal dump.
750  * @tc.type: FUNC
751  */
752 HWTEST_F(HiDumperManagerTest, DumpTest037, TestSize.Level0)
753 {
754     std::string cmd = "hidumper -t 10";
755     std::string str = "  -h                          |help text for the tool\n";
756     ASSERT_TRUE(HidumperTestUtils::GetInstance().IsExistInCmdResult(cmd, str));
757 }
758 
759 /**
760  * @tc.name: IpcStatDumpTest001
761  * @tc.desc: hidumper --ipc -a --start-stat
762  * @tc.type: FUNC
763  */
764 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest001, TestSize.Level0)
765 {
766     char *argv[] = {
767         const_cast<char *>(TOOL_NAME.c_str()),
768         const_cast<char *>("--ipc"),
769         const_cast<char *>("-a"),
770         const_cast<char *>("--start-stat"),
771     };
772     int argc = sizeof(argv) / sizeof(argv[0]);
773     int ret = GetDumpResult(argc, argv);
774     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
775 }
776 
777 /**
778  * @tc.name: IpcStatDumpTest002
779  * @tc.desc: hidumper --ipc -a --stop-stat
780  * @tc.type: FUNC
781  */
782 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest002, TestSize.Level0)
783 {
784     char *argv[] = {
785         const_cast<char *>(TOOL_NAME.c_str()),
786         const_cast<char *>("--ipc"),
787         const_cast<char *>("-a"),
788         const_cast<char *>("--stop-stat"),
789     };
790     int argc = sizeof(argv) / sizeof(argv[0]);
791     int ret = GetDumpResult(argc, argv);
792     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
793 }
794 
795 /**
796  * @tc.name: IpcStatDumpTest003
797  * @tc.desc: hidumper --ipc -a --stat
798  * @tc.type: FUNC
799  */
800 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest003, TestSize.Level0)
801 {
802     char *argv[] = {
803         const_cast<char *>(TOOL_NAME.c_str()),
804         const_cast<char *>("--ipc"),
805         const_cast<char *>("-a"),
806         const_cast<char *>("--stat"),
807     };
808     int argc = sizeof(argv) / sizeof(argv[0]);
809     int ret = GetDumpResult(argc, argv);
810     ASSERT_EQ(ret, DumpStatus::DUMP_OK);
811 }
812 
813 /**
814  * @tc.name: IpcStatDumpTest004
815  * @tc.desc: hidumper --ipc
816  * @tc.type: FUNC
817  */
818 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest004, TestSize.Level0)
819 {
820     char *argv[] = {
821         const_cast<char *>(TOOL_NAME.c_str()),
822         const_cast<char *>("--ipc"),
823     };
824     int argc = sizeof(argv) / sizeof(argv[0]);
825     int ret = GetDumpResult(argc, argv);
826     ASSERT_TRUE(ret != DumpStatus::DUMP_OK);
827 }
828 
829 /**
830  * @tc.name: IpcStatDumpTest005
831  * @tc.desc: hidumper --ipc -a
832  * @tc.type: FUNC
833  */
834 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest005, TestSize.Level0)
835 {
836     char *argv[] = {
837         const_cast<char *>(TOOL_NAME.c_str()),
838         const_cast<char *>("--ipc"),
839         const_cast<char *>("-a"),
840     };
841     int argc = sizeof(argv) / sizeof(argv[0]);
842     int ret = GetDumpResult(argc, argv);
843     ASSERT_TRUE(ret != DumpStatus::DUMP_OK);
844 }
845 
846 /**
847  * @tc.name: IpcStatDumpTest006
848  * @tc.desc: hidumper --ipc -a --start-stat --stop-stat
849  * @tc.type: FUNC
850  */
851 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest006, TestSize.Level0)
852 {
853     char *argv[] = {
854         const_cast<char *>(TOOL_NAME.c_str()),
855         const_cast<char *>("--ipc"),
856         const_cast<char *>("-a"),
857         const_cast<char *>("--start-stat"),
858         const_cast<char *>("--stop-stat"),
859     };
860     int argc = sizeof(argv) / sizeof(argv[0]);
861     int ret = GetDumpResult(argc, argv);
862     ASSERT_TRUE(ret != DumpStatus::DUMP_OK);
863 }
864 
865 /**
866  * @tc.name: IpcStatDumpTest007
867  * @tc.desc: hidumper --start-stat
868  * @tc.type: FUNC
869  */
870 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest007, TestSize.Level0)
871 {
872     char *argv[] = {
873         const_cast<char *>(TOOL_NAME.c_str()),
874         const_cast<char *>("--start-stat"),
875     };
876     int argc = sizeof(argv) / sizeof(argv[0]);
877     int ret = GetDumpResult(argc, argv);
878     ASSERT_TRUE(ret != DumpStatus::DUMP_OK);
879 }
880 
881 /**
882  * @tc.name: IpcStatDumpTest008
883  * @tc.desc: hidumper --stop-stat
884  * @tc.type: FUNC
885  */
886 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest008, TestSize.Level0)
887 {
888     char *argv[] = {
889         const_cast<char *>(TOOL_NAME.c_str()),
890         const_cast<char *>("--stop-stat"),
891     };
892     int argc = sizeof(argv) / sizeof(argv[0]);
893     int ret = GetDumpResult(argc, argv);
894     ASSERT_TRUE(ret != DumpStatus::DUMP_OK);
895 }
896 
897 /**
898  * @tc.name: IpcStatDumpTest009
899  * @tc.desc: hidumper --stat
900  * @tc.type: FUNC
901  */
902 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest009, TestSize.Level0)
903 {
904     char *argv[] = {
905         const_cast<char *>(TOOL_NAME.c_str()),
906         const_cast<char *>("--stat"),
907     };
908     int argc = sizeof(argv) / sizeof(argv[0]);
909     int ret = GetDumpResult(argc, argv);
910     ASSERT_TRUE(ret != DumpStatus::DUMP_OK);
911 }
912 
913 /**
914  * @tc.name: IpcStatDumpTest010
915  * @tc.desc: hidumper --ipc -1 --start-stat
916  * @tc.type: FUNC
917  */
918 HWTEST_F(HiDumperManagerTest, IpcStatDumpTest010, TestSize.Level0)
919 {
920     char *argv[] = {
921         const_cast<char *>(TOOL_NAME.c_str()),
922         const_cast<char *>("--ipc"),
923         const_cast<char *>("-1"),
924         const_cast<char *>("--start-stat"),
925     };
926     int argc = sizeof(argv) / sizeof(argv[0]);
927     int ret = GetDumpResult(argc, argv);
928     ASSERT_TRUE(ret != DumpStatus::DUMP_OK);
929 }
930 
931 /**
932  * @tc.name: HidumperRomTest001
933  * @tc.desc: test hidumper rom
934  * @tc.type: FUNC
935  */
936 HWTEST_F(HiDumperManagerTest, HidumperRomTest001, TestSize.Level0)
937 {
938     uint64_t realSize = 0;
939     for (int i = 0; i < OUTPUT_PATH.size(); i++) {
940         struct stat info = { 0 };
941         stat(OUTPUT_PATH[i].c_str(), &info);
942         std::cout << "path:" << OUTPUT_PATH[i].c_str() << " realSize: " << info.st_size << std::endl;
943         realSize += static_cast<uint64_t>(info.st_size);
944     }
945     std::cout << "total realSize = " << realSize << std::endl;
946     EXPECT_LT(realSize, BASELINE_SIZE * 1.05);
947 }
948 } // namespace HiviewDFX
949 } // namespace OHOS
950