1 /*
2 * Copyright (c) 2021 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 "subcommand_dump_test.h"
17
18 #include <algorithm>
19 #include <chrono>
20 #include <cinttypes>
21 #include <sched.h>
22 #include <sstream>
23 #include <thread>
24
25 #include "command.h"
26 #include "debug_logger.h"
27 #include "utilities.h"
28
29 using namespace std::literals::chrono_literals;
30 using namespace testing::ext;
31 namespace OHOS {
32 namespace Developtools {
33 namespace HiPerf {
34 class SubCommandDumpTest : public testing::Test {
35 public:
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
38 void SetUp();
39 void TearDown();
40
41 void TestDumpCommand(const std::string &option, bool expect = true) const;
42 };
43
SetUpTestCase()44 void SubCommandDumpTest::SetUpTestCase()
45 {
46 SubCommand::ClearSubCommands();
47 }
48
TearDownTestCase()49 void SubCommandDumpTest::TearDownTestCase() {}
50
SetUp()51 void SubCommandDumpTest::SetUp()
52 {
53 // clear the subCommands left from other UT
54 SubCommand::ClearSubCommands();
55 ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
56 SubCommand::RegisterSubCommand("dump", std::make_unique<SubCommandDump>());
57 ASSERT_EQ(SubCommand::GetSubCommands().size(), 1u);
58 }
59
TearDown()60 void SubCommandDumpTest::TearDown()
61 {
62 ASSERT_EQ(SubCommand::GetSubCommands().size(), 1u);
63 SubCommand::ClearSubCommands();
64 ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
65 }
66
TestDumpCommand(const std::string & option,bool expect) const67 void SubCommandDumpTest::TestDumpCommand(const std::string &option, bool expect) const
68 {
69 StdoutRecord stdoutRecord;
70
71 std::string cmdString = "dump";
72 cmdString += " " + option + " ";
73
74 // it need load some symbols and much more log
75
76 ScopeDebugLevel tempLogLevel {LEVEL_DEBUG};
77
78 stdoutRecord.Start();
79 const auto startTime = std::chrono::steady_clock::now();
80 bool ret = Command::DispatchCommand(cmdString);
81 const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
82 std::chrono::steady_clock::now() - startTime);
83 std::string stringOut = stdoutRecord.Stop();
84
85 printf("command : %s(run %" PRId64 " ms) return %s(expect %s)\n", cmdString.c_str(),
86 (uint64_t)costMs.count(), ret ? "true" : "false", expect ? "true" : "false");
87 EXPECT_EQ(expect, ret);
88 if (expect) {
89 EXPECT_EQ(SubStringCount(stringOut, "HILOG/E"), 0u);
90 }
91 }
92
93 /**
94 * @tc.name:
95 * @tc.desc: record
96 * @tc.type: FUNC
97 */
98
99 HWTEST_F(SubCommandDumpTest, Test_LibReport_Success, TestSize.Level1)
100 {
101 StdoutRecord stdoutRecord;
102 stdoutRecord.Start();
103 std::string cmdString = "dump -i /data/test/resource/testdata/report/perf.data.libreport";
104 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
105 std::string stringOut = stdoutRecord.Stop();
106 size_t symbolsCount = 39;
107 size_t buildIdCount = 32;
108 size_t sampleCount = 1000;
109 size_t featureCount = 10;
110
111 EXPECT_EQ(stringOut.find("magic: PERFILE2") != std::string::npos, true);
112 EXPECT_EQ(SubStringCount(stringOut, "fileid:"), symbolsCount);
113 EXPECT_EQ(SubStringCount(stringOut, "buildId:"), buildIdCount);
114 EXPECT_EQ(SubStringCount(stringOut, "record sample:"), sampleCount);
115 EXPECT_EQ(SubStringCount(stringOut, "feature:"), featureCount);
116 }
117
118 HWTEST_F(SubCommandDumpTest, DumpInputFilename1, TestSize.Level1)
119 {
120 TestDumpCommand("/data/test/resource/testdata/perf.data ", false);
121 }
122
123 HWTEST_F(SubCommandDumpTest, DumpInputFilename2, TestSize.Level2)
124 {
125 TestDumpCommand("-i /data/test/resource/testdata/perf.data ");
126 }
127
128 HWTEST_F(SubCommandDumpTest, DumpInputFilenamErr, TestSize.Level3)
129 {
130 TestDumpCommand("-i whatfile ", false);
131 }
132
133 HWTEST_F(SubCommandDumpTest, DumpHeaderAttrs, TestSize.Level0)
134 {
135 TestDumpCommand("-i /data/test/resource/testdata/perf.data --head ");
136 }
137
138 HWTEST_F(SubCommandDumpTest, DumpData, TestSize.Level2)
139 {
140 TestDumpCommand("-i /data/test/resource/testdata/perf.data -d ");
141 }
142
143 HWTEST_F(SubCommandDumpTest, DumpFeatures, TestSize.Level1)
144 {
145 TestDumpCommand("-i /data/test/resource/testdata/perf.data -f ");
146 }
147
148 HWTEST_F(SubCommandDumpTest, DumpSympath, TestSize.Level2)
149 {
150 TestDumpCommand("-i /data/test/resource/testdata/perf.data --sympath ./ ");
151 }
152
153 HWTEST_F(SubCommandDumpTest, DumpSympathErr, TestSize.Level2)
154 {
155 TestDumpCommand("-i /data/test/resource/testdata/perf.data --sympath where ", false);
156 }
157
158 HWTEST_F(SubCommandDumpTest, DumpExportUserdata0, TestSize.Level2)
159 {
160 TestDumpCommand("-i /data/test/resource/testdata/perf.data --export 0");
161 }
162
163 HWTEST_F(SubCommandDumpTest, DumpExportUserdata1, TestSize.Level2)
164 {
165 TestDumpCommand("-i /data/test/resource/testdata/perf.data --export 1");
166 }
167
168 HWTEST_F(SubCommandDumpTest, DumpElffile, TestSize.Level1)
169 {
170 TestDumpCommand("--elf /data/test/resource/testdata/elf_test ");
171 }
172
173 HWTEST_F(SubCommandDumpTest, DumpElffileErr, TestSize.Level3)
174 {
175 TestDumpCommand("--elf whatfile ", false);
176 }
177
178 HWTEST_F(SubCommandDumpTest, DumpInputElfConflict, TestSize.Level3)
179 {
180 TestDumpCommand("perf.data --elf elffile ", false);
181 }
182
183 #if defined(HAVE_PROTOBUF) && HAVE_PROTOBUF
184 HWTEST_F(SubCommandDumpTest, DumpProtofile, TestSize.Level0)
185 {
186 TestDumpCommand("--proto /data/test/resource/testdata/proto_test ");
187 }
188
189 HWTEST_F(SubCommandDumpTest, DumpProtofileErr, TestSize.Level3)
190 {
191 TestDumpCommand("--proto whatfile ", false);
192 }
193
194 HWTEST_F(SubCommandDumpTest, DumpInputProtoConflict, TestSize.Level2)
195 {
196 TestDumpCommand("perf.data --proto ptotofile ", false);
197 }
198
199 HWTEST_F(SubCommandDumpTest, DumpElfProtoConflict, TestSize.Level3)
200 {
201 TestDumpCommand("--elf elffile --proto ptotofile ", false);
202 }
203 #endif
204
205 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfStackTable, TestSize.Level1)
206 {
207 StdoutRecord stdoutRecord;
208 stdoutRecord.Start();
209 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
210 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
211 std::string stringOut = stdoutRecord.Stop();
212
213 EXPECT_EQ(stringOut.find("hiperf_stack_table") != std::string::npos, true);
214 }
215
216 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfStackid, TestSize.Level2)
217 {
218 StdoutRecord stdoutRecord;
219 stdoutRecord.Start();
220 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
221 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
222 std::string stringOut = stdoutRecord.Stop();
223
224 EXPECT_EQ(stringOut.find("stackid") != std::string::npos, true);
225 }
226
227 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfTableNums, TestSize.Level2)
228 {
229 StdoutRecord stdoutRecord;
230 stdoutRecord.Start();
231 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
232 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
233 std::string stringOut = stdoutRecord.Stop();
234
235 EXPECT_EQ(stringOut.find("TableNums") != std::string::npos, true);
236 }
237
238 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfNumNodes, TestSize.Level2)
239 {
240 StdoutRecord stdoutRecord;
241 stdoutRecord.Start();
242 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
243 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
244 std::string stringOut = stdoutRecord.Stop();
245
246 EXPECT_EQ(stringOut.find("numNodes") != std::string::npos, true);
247 }
248
249 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfStackTableContent, TestSize.Level2)
250 {
251 StdoutRecord stdoutRecord;
252 stdoutRecord.Start();
253 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
254 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
255 std::string stringOut = stdoutRecord.Stop();
256
257 EXPECT_EQ(stringOut.find("hiperf_stack_table content") != std::string::npos, true);
258 }
259
260 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfTableid, TestSize.Level2)
261 {
262 StdoutRecord stdoutRecord;
263 stdoutRecord.Start();
264 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
265 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
266 std::string stringOut = stdoutRecord.Stop();
267
268 EXPECT_EQ(stringOut.find("tableid") != std::string::npos, true);
269 }
270
271 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfTableSize, TestSize.Level2)
272 {
273 StdoutRecord stdoutRecord;
274 stdoutRecord.Start();
275 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
276 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
277 std::string stringOut = stdoutRecord.Stop();
278
279 EXPECT_EQ(stringOut.find("tableSize") != std::string::npos, true);
280 }
281
282 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfKernelUpperBoundary, TestSize.Level2)
283 {
284 StdoutRecord stdoutRecord;
285 stdoutRecord.Start();
286 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
287 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
288 std::string stringOut = stdoutRecord.Stop();
289 std::string kernelUpperBoundary = "0xffffffffffffff80";
290 EXPECT_EQ(stringOut.find(kernelUpperBoundary) != std::string::npos, true);
291 }
292
293 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfKernelLowerBoundary, TestSize.Level3)
294 {
295 StdoutRecord stdoutRecord;
296 stdoutRecord.Start();
297 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
298 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
299 std::string stringOut = stdoutRecord.Stop();
300 std::string kernelLowerBoundary = "0xfffffffffffffe00";
301 EXPECT_EQ(stringOut.find(kernelLowerBoundary) != std::string::npos, true);
302 }
303
304 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfKernelIp, TestSize.Level2)
305 {
306 StdoutRecord stdoutRecord;
307 stdoutRecord.Start();
308 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
309 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
310 std::string stringOut = stdoutRecord.Stop();
311 std::string kernelIp = "0xffffffc011605050";
312 EXPECT_EQ(stringOut.find(kernelIp) != std::string::npos, true);
313 }
314
315 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfUerIpFixZero, TestSize.Level3)
316 {
317 StdoutRecord stdoutRecord;
318 stdoutRecord.Start();
319 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
320 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
321 std::string stringOut = stdoutRecord.Stop();
322 std::string userIpFixZero = "0xffffffc0100fa3b0";
323 EXPECT_EQ(stringOut.find(userIpFixZero) != std::string::npos, true);
324 }
325
326 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfUserIp, TestSize.Level1)
327 {
328 StdoutRecord stdoutRecord;
329 stdoutRecord.Start();
330 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
331 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
332 std::string stringOut = stdoutRecord.Stop();
333 std::string userIp = "0xf7b43f50";
334 EXPECT_EQ(stringOut.find(userIp) != std::string::npos, true);
335 }
336
337 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfCallchain, TestSize.Level3)
338 {
339 StdoutRecord stdoutRecord;
340 stdoutRecord.Start();
341 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
342 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
343 std::string stringOut = stdoutRecord.Stop();
344 std::string callchain = "callchain nr=25";
345 EXPECT_EQ(stringOut.find(callchain) != std::string::npos, true);
346 }
347
348 HWTEST_F(SubCommandDumpTest, DumpCompressDwarfSymbol, TestSize.Level1)
349 {
350 StdoutRecord stdoutRecord;
351 stdoutRecord.Start();
352 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.compress.data";
353 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
354 std::string stringOut = stdoutRecord.Stop();
355 std::string symbol = "0xffffffc01160072c : __schedule";
356 EXPECT_EQ(stringOut.find(symbol) != std::string::npos, true);
357 }
358
359 HWTEST_F(SubCommandDumpTest, DumpCompressFpStackTable, TestSize.Level1)
360 {
361 StdoutRecord stdoutRecord;
362 stdoutRecord.Start();
363 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
364 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
365 std::string stringOut = stdoutRecord.Stop();
366
367 EXPECT_EQ(stringOut.find("hiperf_stack_table") != std::string::npos, true);
368 }
369
370 HWTEST_F(SubCommandDumpTest, DumpCompressFpStackid, TestSize.Level2)
371 {
372 StdoutRecord stdoutRecord;
373 stdoutRecord.Start();
374 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
375 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
376 std::string stringOut = stdoutRecord.Stop();
377
378 EXPECT_EQ(stringOut.find("stackid") != std::string::npos, true);
379 }
380
381 HWTEST_F(SubCommandDumpTest, DumpCompressFpTableNums, TestSize.Level2)
382 {
383 StdoutRecord stdoutRecord;
384 stdoutRecord.Start();
385 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
386 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
387 std::string stringOut = stdoutRecord.Stop();
388
389 EXPECT_EQ(stringOut.find("TableNums") != std::string::npos, true);
390 }
391
392 HWTEST_F(SubCommandDumpTest, DumpCompressFpNumNodes, TestSize.Level2)
393 {
394 StdoutRecord stdoutRecord;
395 stdoutRecord.Start();
396 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
397 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
398 std::string stringOut = stdoutRecord.Stop();
399
400 EXPECT_EQ(stringOut.find("numNodes") != std::string::npos, true);
401 }
402
403 HWTEST_F(SubCommandDumpTest, DumpCompressFpStackTableContent, TestSize.Level3)
404 {
405 StdoutRecord stdoutRecord;
406 stdoutRecord.Start();
407 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
408 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
409 std::string stringOut = stdoutRecord.Stop();
410
411 EXPECT_EQ(stringOut.find("hiperf_stack_table content") != std::string::npos, true);
412 }
413
414 HWTEST_F(SubCommandDumpTest, DumpCompressFpTableid, TestSize.Level2)
415 {
416 StdoutRecord stdoutRecord;
417 stdoutRecord.Start();
418 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
419 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
420 std::string stringOut = stdoutRecord.Stop();
421
422 EXPECT_EQ(stringOut.find("tableid") != std::string::npos, true);
423 }
424
425 HWTEST_F(SubCommandDumpTest, DumpCompressFpTableSize, TestSize.Level2)
426 {
427 StdoutRecord stdoutRecord;
428 stdoutRecord.Start();
429 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
430 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
431 std::string stringOut = stdoutRecord.Stop();
432
433 EXPECT_EQ(stringOut.find("tableSize") != std::string::npos, true);
434 }
435
436 HWTEST_F(SubCommandDumpTest, DumpCompressFpKernelUpperBoundary, TestSize.Level3)
437 {
438 StdoutRecord stdoutRecord;
439 stdoutRecord.Start();
440 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
441 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
442 std::string stringOut = stdoutRecord.Stop();
443 std::string kernelUpperBoundary = "0xffffffffffffff80";
444 EXPECT_EQ(stringOut.find(kernelUpperBoundary) != std::string::npos, true);
445 }
446
447 HWTEST_F(SubCommandDumpTest, DumpCompressFpKernelLowerBoundary, TestSize.Level2)
448 {
449 StdoutRecord stdoutRecord;
450 stdoutRecord.Start();
451 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
452 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
453 std::string stringOut = stdoutRecord.Stop();
454 std::string kernelLowerBoundary = "0xfffffffffffffe00";
455 EXPECT_EQ(stringOut.find(kernelLowerBoundary) != std::string::npos, true);
456 }
457
458 HWTEST_F(SubCommandDumpTest, DumpCompressFpKernelIp, TestSize.Level2)
459 {
460 StdoutRecord stdoutRecord;
461 stdoutRecord.Start();
462 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
463 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
464 std::string stringOut = stdoutRecord.Stop();
465 std::string kernelIp = "0xffffffc011605050";
466 EXPECT_EQ(stringOut.find(kernelIp) != std::string::npos, true);
467 }
468
469 HWTEST_F(SubCommandDumpTest, DumpCompressFpUerIpFixZero, TestSize.Level3)
470 {
471 StdoutRecord stdoutRecord;
472 stdoutRecord.Start();
473 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
474 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
475 std::string stringOut = stdoutRecord.Stop();
476 std::string userIpFixZero = "0xffffffc0100fa3b0";
477 EXPECT_EQ(stringOut.find(userIpFixZero) != std::string::npos, true);
478 }
479
480 HWTEST_F(SubCommandDumpTest, DumpCompressFpUserIp, TestSize.Level2)
481 {
482 StdoutRecord stdoutRecord;
483 stdoutRecord.Start();
484 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
485 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
486 std::string stringOut = stdoutRecord.Stop();
487 std::string userIp = "0xf7b43f50";
488 EXPECT_EQ(stringOut.find(userIp) != std::string::npos, true);
489 }
490
491 HWTEST_F(SubCommandDumpTest, DumpCompressFpCallchain, TestSize.Level3)
492 {
493 StdoutRecord stdoutRecord;
494 stdoutRecord.Start();
495 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
496 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
497 std::string stringOut = stdoutRecord.Stop();
498 std::string callchain = "callchain nr=21";
499 EXPECT_EQ(stringOut.find(callchain) != std::string::npos, true);
500 }
501
502 HWTEST_F(SubCommandDumpTest, DumpCompressFpSymbol, TestSize.Level2)
503 {
504 StdoutRecord stdoutRecord;
505 stdoutRecord.Start();
506 std::string cmdString = "dump -i /data/test/resource/testdata/fp.compress.data";
507 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
508 std::string stringOut = stdoutRecord.Stop();
509 std::string symbol = "0xffffffc011600984 : schedule";
510 EXPECT_EQ(stringOut.find(symbol) != std::string::npos, true);
511 }
512
513 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfStackTable, TestSize.Level1)
514 {
515 StdoutRecord stdoutRecord;
516 stdoutRecord.Start();
517 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
518 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
519 std::string stringOut = stdoutRecord.Stop();
520
521 EXPECT_EQ(stringOut.find("hiperf_stack_table") != std::string::npos, false);
522 }
523
524 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfStackid, TestSize.Level2)
525 {
526 StdoutRecord stdoutRecord;
527 stdoutRecord.Start();
528 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
529 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
530 std::string stringOut = stdoutRecord.Stop();
531
532 EXPECT_EQ(stringOut.find("stackid") != std::string::npos, false);
533 }
534
535 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfTableNums, TestSize.Level2)
536 {
537 StdoutRecord stdoutRecord;
538 stdoutRecord.Start();
539 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
540 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
541 std::string stringOut = stdoutRecord.Stop();
542
543 EXPECT_EQ(stringOut.find("TableNums") != std::string::npos, false);
544 }
545
546 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfNumNodes, TestSize.Level2)
547 {
548 StdoutRecord stdoutRecord;
549 stdoutRecord.Start();
550 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
551 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
552 std::string stringOut = stdoutRecord.Stop();
553
554 EXPECT_EQ(stringOut.find("numNodes") != std::string::npos, false);
555 }
556
557 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfStackTableContent, TestSize.Level2)
558 {
559 StdoutRecord stdoutRecord;
560 stdoutRecord.Start();
561 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
562 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
563 std::string stringOut = stdoutRecord.Stop();
564
565 EXPECT_EQ(stringOut.find("hiperf_stack_table content") != std::string::npos, false);
566 }
567
568 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfTableid, TestSize.Level2)
569 {
570 StdoutRecord stdoutRecord;
571 stdoutRecord.Start();
572 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
573 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
574 std::string stringOut = stdoutRecord.Stop();
575
576 EXPECT_EQ(stringOut.find("tableid") != std::string::npos, false);
577 }
578
579 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfTableSize, TestSize.Level2)
580 {
581 StdoutRecord stdoutRecord;
582 stdoutRecord.Start();
583 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
584 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
585 std::string stringOut = stdoutRecord.Stop();
586
587 EXPECT_EQ(stringOut.find("tableSize") != std::string::npos, false);
588 }
589
590 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfKernelUpperBoundary, TestSize.Level1)
591 {
592 StdoutRecord stdoutRecord;
593 stdoutRecord.Start();
594 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
595 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
596 std::string stringOut = stdoutRecord.Stop();
597 std::string kernelUpperBoundary = "0xffffffffffffff80";
598 EXPECT_EQ(stringOut.find(kernelUpperBoundary) != std::string::npos, true);
599 }
600
601 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfKernelLowerBoundary, TestSize.Level1)
602 {
603 StdoutRecord stdoutRecord;
604 stdoutRecord.Start();
605 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
606 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
607 std::string stringOut = stdoutRecord.Stop();
608 std::string kernelLowerBoundary = "0xfffffffffffffe00";
609 EXPECT_EQ(stringOut.find(kernelLowerBoundary) != std::string::npos, true);
610 }
611
612 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfKernelIp, TestSize.Level1)
613 {
614 StdoutRecord stdoutRecord;
615 stdoutRecord.Start();
616 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
617 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
618 std::string stringOut = stdoutRecord.Stop();
619 std::string kernelIp = "0xffffffc011605050";
620 EXPECT_EQ(stringOut.find(kernelIp) != std::string::npos, true);
621 }
622
623 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfUerIpFixZero, TestSize.Level1)
624 {
625 StdoutRecord stdoutRecord;
626 stdoutRecord.Start();
627 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
628 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
629 std::string stringOut = stdoutRecord.Stop();
630 std::string userIpFixZero = "0x00000000f7a70f67";
631 EXPECT_EQ(stringOut.find(userIpFixZero) != std::string::npos, true);
632 }
633
634 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfUserIp, TestSize.Level1)
635 {
636 StdoutRecord stdoutRecord;
637 stdoutRecord.Start();
638 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
639 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
640 std::string stringOut = stdoutRecord.Stop();
641 std::string userIp = "0xf7a70f67";
642 EXPECT_EQ(stringOut.find(userIp) != std::string::npos, true);
643 }
644
645 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfCallchain, TestSize.Level1)
646 {
647 StdoutRecord stdoutRecord;
648 stdoutRecord.Start();
649 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
650 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
651 std::string stringOut = stdoutRecord.Stop();
652 std::string callchain = "callchain nr=20";
653 EXPECT_EQ(stringOut.find(callchain) != std::string::npos, true);
654 }
655
656 HWTEST_F(SubCommandDumpTest, DumpUncompressDwarfSymbol, TestSize.Level1)
657 {
658 StdoutRecord stdoutRecord;
659 stdoutRecord.Start();
660 std::string cmdString = "dump -i /data/test/resource/testdata/dwarf.uncompress.data";
661 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
662 std::string stringOut = stdoutRecord.Stop();
663 std::string symbol = "0xffffffc0102fafa0 : ksys_read";
664 EXPECT_EQ(stringOut.find(symbol) != std::string::npos, true);
665 }
666
667 HWTEST_F(SubCommandDumpTest, DumpUncompressFpStackTable, TestSize.Level2)
668 {
669 StdoutRecord stdoutRecord;
670 stdoutRecord.Start();
671 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
672 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
673 std::string stringOut = stdoutRecord.Stop();
674
675 EXPECT_EQ(stringOut.find("hiperf_stack_table") != std::string::npos, false);
676 }
677
678 HWTEST_F(SubCommandDumpTest, DumpUncompressFpStackid, TestSize.Level2)
679 {
680 StdoutRecord stdoutRecord;
681 stdoutRecord.Start();
682 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
683 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
684 std::string stringOut = stdoutRecord.Stop();
685
686 EXPECT_EQ(stringOut.find("stackid") != std::string::npos, false);
687 }
688
689 HWTEST_F(SubCommandDumpTest, DumpUncompressFpTableNums, TestSize.Level2)
690 {
691 StdoutRecord stdoutRecord;
692 stdoutRecord.Start();
693 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
694 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
695 std::string stringOut = stdoutRecord.Stop();
696
697 EXPECT_EQ(stringOut.find("TableNums") != std::string::npos, false);
698 }
699
700 HWTEST_F(SubCommandDumpTest, DumpUncompressFpNumNodes, TestSize.Level1)
701 {
702 StdoutRecord stdoutRecord;
703 stdoutRecord.Start();
704 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
705 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
706 std::string stringOut = stdoutRecord.Stop();
707
708 EXPECT_EQ(stringOut.find("numNodes") != std::string::npos, false);
709 }
710
711 HWTEST_F(SubCommandDumpTest, DumpUncompressFpStackTableContent, TestSize.Level1)
712 {
713 StdoutRecord stdoutRecord;
714 stdoutRecord.Start();
715 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
716 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
717 std::string stringOut = stdoutRecord.Stop();
718
719 EXPECT_EQ(stringOut.find("hiperf_stack_table content") != std::string::npos, false);
720 }
721
722 HWTEST_F(SubCommandDumpTest, DumpUncompressFpTableid, TestSize.Level1)
723 {
724 StdoutRecord stdoutRecord;
725 stdoutRecord.Start();
726 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
727 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
728 std::string stringOut = stdoutRecord.Stop();
729
730 EXPECT_EQ(stringOut.find("tableid") != std::string::npos, false);
731 }
732
733 HWTEST_F(SubCommandDumpTest, DumpUncompressFpTableSize, TestSize.Level1)
734 {
735 StdoutRecord stdoutRecord;
736 stdoutRecord.Start();
737 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
738 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
739 std::string stringOut = stdoutRecord.Stop();
740
741 EXPECT_EQ(stringOut.find("tableSize") != std::string::npos, false);
742 }
743
744 HWTEST_F(SubCommandDumpTest, DumpUncompressFpKernelUpperBoundary, TestSize.Level1)
745 {
746 StdoutRecord stdoutRecord;
747 stdoutRecord.Start();
748 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
749 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
750 std::string stringOut = stdoutRecord.Stop();
751 std::string kernelUpperBoundary = "0xffffffffffffff80";
752 EXPECT_EQ(stringOut.find(kernelUpperBoundary) != std::string::npos, true);
753 }
754
755 HWTEST_F(SubCommandDumpTest, DumpUncompressFpKernelLowerBoundary, TestSize.Level1)
756 {
757 StdoutRecord stdoutRecord;
758 stdoutRecord.Start();
759 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
760 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
761 std::string stringOut = stdoutRecord.Stop();
762 std::string kernelLowerBoundary = "0xfffffffffffffe00";
763 EXPECT_EQ(stringOut.find(kernelLowerBoundary) != std::string::npos, true);
764 }
765
766 HWTEST_F(SubCommandDumpTest, DumpUncompressFpKernelIp, TestSize.Level1)
767 {
768 StdoutRecord stdoutRecord;
769 stdoutRecord.Start();
770 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
771 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
772 std::string stringOut = stdoutRecord.Stop();
773 std::string kernelIp = "0xffffffc011605050";
774 EXPECT_EQ(stringOut.find(kernelIp) != std::string::npos, true);
775 }
776
777 HWTEST_F(SubCommandDumpTest, DumpUncompressFpUerIpFixZero, TestSize.Level1)
778 {
779 StdoutRecord stdoutRecord;
780 stdoutRecord.Start();
781 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
782 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
783 std::string stringOut = stdoutRecord.Stop();
784 std::string userIpFixZero = "0x00000000f6ebfd24";
785 EXPECT_EQ(stringOut.find(userIpFixZero) != std::string::npos, true);
786 }
787
788 HWTEST_F(SubCommandDumpTest, DumpUncompressFpUserIp, TestSize.Level1)
789 {
790 StdoutRecord stdoutRecord;
791 stdoutRecord.Start();
792 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
793 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
794 std::string stringOut = stdoutRecord.Stop();
795 std::string userIp = "0xf6ebfd24";
796 EXPECT_EQ(stringOut.find(userIp) != std::string::npos, true);
797 }
798
799 HWTEST_F(SubCommandDumpTest, DumpUncompressFpCallchain, TestSize.Level1)
800 {
801 StdoutRecord stdoutRecord;
802 stdoutRecord.Start();
803 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
804 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
805 std::string stringOut = stdoutRecord.Stop();
806 std::string callchain = "callchain nr=16";
807 EXPECT_EQ(stringOut.find(callchain) != std::string::npos, true);
808 }
809
810 HWTEST_F(SubCommandDumpTest, DumpUncompressFpSymbol, TestSize.Level1)
811 {
812 StdoutRecord stdoutRecord;
813 stdoutRecord.Start();
814 std::string cmdString = "dump -i /data/test/resource/testdata/fp.uncompress.data";
815 EXPECT_EQ(Command::DispatchCommand(cmdString), true);
816 std::string stringOut = stdoutRecord.Stop();
817 std::string symbol = "0xffffffc0100030c4 : el0_sync_compat";
818 EXPECT_EQ(stringOut.find(symbol) != std::string::npos, true);
819 }
820
821 HWTEST_F(SubCommandDumpTest, DumpOutputFail, TestSize.Level1)
822 {
823 StdoutRecord stdoutRecord;
824 stdoutRecord.Start();
825 std::string cmdString = "dump -o /root/output.txt";
826 EXPECT_EQ(Command::DispatchCommand(cmdString), false);
827 std::string stringOut = stdoutRecord.Stop();
828 std::string symbol = "unable open file";
829 EXPECT_EQ(stringOut.find(symbol) != std::string::npos, true);
830 }
831
832 HWTEST_F(SubCommandDumpTest, GetInstance, TestSize.Level1)
833 {
834 StdoutRecord stdoutRecord;
835 stdoutRecord.Start();
836
837 EXPECT_EQ(SubCommandDump::GetInstance().Name(), "dump");
838 }
839 } // namespace HiPerf
840 } // namespace Developtools
841 } // namespace OHOS
842