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