• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
16 #include "subcommand_report_test.h"
17 
18 #include "subcommand.h"
19 #include "subcommand_report.h"
20 #include "subcommand_test.h"
21 
22 using namespace testing::ext;
23 using namespace std;
24 using namespace OHOS::HiviewDFX;
25 namespace OHOS {
26 namespace Developtools {
27 namespace HiPerf {
28 
29 constexpr int DEFAULT_RUN_TIMEOUT_MS = 10000;
30 
31 class SubCommandReportTest : public testing::Test {
32 public:
33 #if is_ohos
34     const std::string RESOURCE_PATH = "/data/test/resource/testdata/";
35 #else
36     const std::string RESOURCE_PATH = "./resource/testdata/";
37 #endif
38     static void SetUpTestCase(void);
39     static void TearDownTestCase(void);
40     void SetUp();
41     void TearDown();
42 
43     bool FindExpectStr(const std::string &stringOut, const std::string &counterNames) const;
44     bool FindExpectStrList(const std::string &stringOut,
45                            const std::vector<std::string> &counterNames) const;
46     bool FileCompare(const std::string &stringOut, const std::string &targetFile) const;
47     const std::vector<std::string> expectStr_ = {
48         "Heating", "count", "comm", "pid", "tid", "dso", "func",
49     };
50 };
SetUpTestCase()51 void SubCommandReportTest::SetUpTestCase() {}
52 
TearDownTestCase()53 void SubCommandReportTest::TearDownTestCase() {
54 }
55 
SetUp()56 void SubCommandReportTest::SetUp()
57 {
58     ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
59     ASSERT_EQ(SubCommandReport::RegisterSubCommandReport(), true);
60     SubCommand::RegisterSubCommand("TEST_CMD_1", std::make_unique<SubCommandTest>("TEST_CMD_1"));
61 }
62 
TearDown()63 void SubCommandReportTest::TearDown()
64 {
65     SubCommand::ClearSubCommands();
66     ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
67     MemoryHold::Get().Clean();
68 }
69 
FindExpectStr(const std::string & stringOut,const std::string & counterNames) const70 bool SubCommandReportTest::FindExpectStr(const std::string &stringOut,
71                                          const std::string &counterNames) const
72 {
73     auto lines = StringSplit(stringOut, "\n");
74     for (auto line : lines) {
75         if (line.find(counterNames.c_str()) != std::string::npos) {
76             return true;
77         }
78     }
79     return false;
80 }
81 
FindExpectStrList(const std::string & stringOut,const std::vector<std::string> & counterNames) const82 bool SubCommandReportTest::FindExpectStrList(const std::string &stringOut,
83                                              const std::vector<std::string> &counterNames) const
84 {
85     for (auto name : counterNames) {
86         if (stringOut.find(name) != std::string::npos) {
87             return true;
88         }
89     }
90     return false;
91 }
92 
FileCompare(const std::string & stringOut,const std::string & targetFile) const93 bool SubCommandReportTest::FileCompare(const std::string &stringOut,
94                                        const std::string &targetFile) const
95 {
96     std::vector<std::string> actualLines = StringSplit(stringOut, "\n");
97     std::vector<std::string> expectLines = StringSplit(ReadFileToString(targetFile), "\n");
98 
99     for (int i = 0; i < (int)actualLines.size(); i++) {
100         actualLines[i].erase(actualLines[i].find_last_not_of(" ") + 1);
101     }
102 
103     for (int y = 0; y < (int)expectLines.size(); y++) {
104         expectLines[y].erase(expectLines[y].find_last_not_of(" ") + 1);
105     }
106     auto actual = actualLines.begin();
107     auto expect = expectLines.begin();
108     EXPECT_EQ(actualLines.size(), expectLines.size());
109 
110     while (actual != actualLines.end() and expect != expectLines.end() and !HasFailure()) {
111         EXPECT_STREQ(actual->c_str(), expect->c_str());
112         actual++;
113         expect++;
114     }
115     return !HasFailure();
116 }
117 
118 /**
119  * @tc.name: TestParseOption
120  * @tc.desc:
121  * @tc.type: FUNC
122  */
123 HWTEST_F(SubCommandReportTest, TestParseOption, TestSize.Level1)
124 {
125     SubCommandReport mSubCommandReport;
126     std::vector<std::string> args;
127     args = {"-i"};
128     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
129     args = {"-o"};
130     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
131     args = {"--diff"};
132     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
133     args = {"--sort"};
134     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
135     args = {"--symbol-dir"};
136     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
137     args = {"--limit-percent"};
138     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
139     args = {"-s"};
140     EXPECT_EQ(mSubCommandReport.ParseOption(args), true);
141     args = {"--call-stack"};
142     EXPECT_EQ(mSubCommandReport.ParseOption(args), true);
143     args = {"--call-stack-limit-percent"};
144     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
145     args = {"--comms"};
146     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
147     args = {"--pids"};
148     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
149     args = {"--tids"};
150     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
151     args = {"--dsos"};
152     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
153     args = {"--funcs"};
154     EXPECT_EQ(mSubCommandReport.ParseOption(args), false);
155     args = {"--from-dsos"};
156     EXPECT_EQ(mSubCommandReport.ParseOption(args), true);
157     args = {"--from-funcs"};
158     EXPECT_EQ(mSubCommandReport.ParseOption(args), true);
159     args = {"--proto"};
160     EXPECT_EQ(mSubCommandReport.ParseOption(args), true);
161     args = {"--json"};
162     EXPECT_EQ(mSubCommandReport.ParseOption(args), true);
163     args = {"--branch"};
164     EXPECT_EQ(mSubCommandReport.ParseOption(args), true);
165     args.clear();
166 }
167 
168 /**
169  * @tc.name: TestDumpOptions
170  * @tc.desc:
171  * @tc.type: FUNC
172  */
173 HWTEST_F(SubCommandReportTest, TestDumpOptions, TestSize.Level1)
174 {
175     StdoutRecord stdoutRecord;
176     stdoutRecord.Start();
177     SubCommandReport mSubCommandReport;
178     mSubCommandReport.DumpOptions();
179     std::string stringOut = stdoutRecord.Stop();
180     EXPECT_TRUE(stringOut.find("comm,pid,tid,dso,func") != std::string::npos);
181 }
182 
183 /**
184  * @tc.name: TestOnSubCommand_i
185  * @tc.desc:
186  * @tc.type: FUNC
187  */
188 HWTEST_F(SubCommandReportTest, TestOnSubCommand_i, TestSize.Level1)
189 {
190     StdoutRecord stdoutRecord;
191     stdoutRecord.Start();
192     const auto startTime = chrono::steady_clock::now();
193     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data"), true);
194     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
195         chrono::steady_clock::now() - startTime);
196     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
197 
198     std::string stringOut = stdoutRecord.Stop();
199     if (HasFailure()) {
200         printf("output:\n%s", stringOut.c_str());
201     }
202     std::string targetFile = RESOURCE_PATH + "report_test_i.txt";
203     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
204 }
205 
206 /**
207  * @tc.name: TestOnSubCommand_i1
208  * @tc.desc:
209  * @tc.type: FUNC
210  */
211 HWTEST_F(SubCommandReportTest, TestOnSubCommand_i1, TestSize.Level1)
212 {
213     StdoutRecord stdoutRecord;
214     stdoutRecord.Start();
215     const auto startTime = chrono::steady_clock::now();
216     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "perf1.data"), false);
217     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
218         chrono::steady_clock::now() - startTime);
219     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
220 
221     std::string stringOut = stdoutRecord.Stop();
222     if (HasFailure()) {
223         printf("output:\n%s", stringOut.c_str());
224     }
225     const std::string expectStr =
226         "Can not access data file /data/test/resource/testdata/perf1.data";
227     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
228 }
229 
230 /**
231  * @tc.name: TestOnSubCommand_i2
232  * @tc.desc:
233  * @tc.type: FUNC
234  */
235 HWTEST_F(SubCommandReportTest, TestOnSubCommand_i2, TestSize.Level1)
236 {
237     StdoutRecord stdoutRecord;
238     stdoutRecord.Start();
239     const auto startTime = chrono::steady_clock::now();
240     EXPECT_EQ(Command::DispatchCommand("report " + RESOURCE_PATH + "report_test.data -i"), false);
241     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
242         chrono::steady_clock::now() - startTime);
243     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
244 
245     std::string stringOut = stdoutRecord.Stop();
246     if (HasFailure()) {
247         printf("output:\n%s", stringOut.c_str());
248     }
249     const std::string expectStr = "option -i value missed";
250     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
251 }
252 
253 /**
254  * @tc.name: TestOnSubCommand_diff
255  * @tc.desc:
256  * @tc.type: FUNC
257  */
258 HWTEST_F(SubCommandReportTest, TestOnSubCommand_diff, TestSize.Level1)
259 {
260     StdoutRecord stdoutRecord;
261     stdoutRecord.Start();
262     const auto startTime = chrono::steady_clock::now();
263     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "perf1.data --diff " +
264                                        RESOURCE_PATH + "report_test.data"),
265               false);
266     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
267         chrono::steady_clock::now() - startTime);
268     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
269 
270     std::string stringOut = stdoutRecord.Stop();
271     if (HasFailure()) {
272         printf("output:\n%s", stringOut.c_str());
273     }
274     const std::string expectStr =
275         "Can not access data file /data/test/resource/testdata/perf1.data";
276     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
277 }
278 
279 /**
280  * @tc.name: TestOnSubCommand_Diff_Same
281  * @tc.desc:
282  * @tc.type: FUNC
283  */
284 HWTEST_F(SubCommandReportTest, TestOnSubCommand_Diff_Same, TestSize.Level1)
285 {
286     StdoutRecord stdoutRecord;
287     stdoutRecord.Start();
288     const auto startTime = chrono::steady_clock::now();
289 
290     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --diff " +
291                                        RESOURCE_PATH + "report_test.data"),
292               true);
293     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
294         chrono::steady_clock::now() - startTime);
295     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
296 
297     std::string stringOut = stdoutRecord.Stop();
298     if (HasFailure()) {
299         printf("output:\n%s", stringOut.c_str());
300     }
301     std::string targetFile = RESOURCE_PATH + "report_test_diff.txt";
302     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
303 }
304 
305 /**
306  * @tc.name: TestOnSubCommand_sort
307  * @tc.desc:
308  * @tc.type: FUNC
309  */
310 HWTEST_F(SubCommandReportTest, TestOnSubCommand_sort, TestSize.Level1)
311 {
312     StdoutRecord stdoutRecord;
313     stdoutRecord.Start();
314     const auto startTime = chrono::steady_clock::now();
315     EXPECT_EQ(
316         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --sort pid"),
317         true);
318     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
319         chrono::steady_clock::now() - startTime);
320     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
321 
322     std::string stringOut = stdoutRecord.Stop();
323     if (HasFailure()) {
324         printf("output:\n%s", stringOut.c_str());
325     }
326     const std::string expectStr = "100.00%  271445 1204";
327     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
328 }
329 
330 /**
331  * @tc.name: TestOnSubCommand_sort1
332  * @tc.desc:
333  * @tc.type: FUNC
334  */
335 HWTEST_F(SubCommandReportTest, TestOnSubCommand_sort1, TestSize.Level1)
336 {
337     StdoutRecord stdoutRecord;
338     stdoutRecord.Start();
339     const auto startTime = chrono::steady_clock::now();
340     EXPECT_EQ(
341         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --sort pid,tid"),
342         true);
343     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
344         chrono::steady_clock::now() - startTime);
345     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
346 
347     std::string stringOut = stdoutRecord.Stop();
348     if (HasFailure()) {
349         printf("output:\n%s", stringOut.c_str());
350     }
351     std::string targetFile = RESOURCE_PATH + "report_test_sort1.txt";
352     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
353 }
354 
355 /**
356  * @tc.name: TestOnSubCommand_sort2
357  * @tc.desc:
358  * @tc.type: FUNC
359  */
360 HWTEST_F(SubCommandReportTest, TestOnSubCommand_sort2, TestSize.Level1)
361 {
362     StdoutRecord stdoutRecord;
363     stdoutRecord.Start();
364     const auto startTime = chrono::steady_clock::now();
365     EXPECT_EQ(
366         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --sort func"),
367         true);
368     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
369         chrono::steady_clock::now() - startTime);
370     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
371 
372     std::string stringOut = stdoutRecord.Stop();
373     if (HasFailure()) {
374         printf("output:\n%s", stringOut.c_str());
375     }
376     std::string targetFile = RESOURCE_PATH + "report_test_sort2.txt";
377     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
378 }
379 
380 /**
381  * @tc.name: TestOnSubCommand_sort3
382  * @tc.desc:
383  * @tc.type: FUNC
384  */
385 HWTEST_F(SubCommandReportTest, TestOnSubCommand_sort3, TestSize.Level1)
386 {
387     StdoutRecord stdoutRecord;
388     stdoutRecord.Start();
389     const auto startTime = chrono::steady_clock::now();
390     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "perf1.data --sort pid"),
391               false);
392     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
393         chrono::steady_clock::now() - startTime);
394     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
395 
396     std::string stringOut = stdoutRecord.Stop();
397     if (HasFailure()) {
398         printf("output:\n%s", stringOut.c_str());
399     }
400     const std::string expectStr =
401         "Can not access data file /data/test/resource/testdata/perf1.data";
402     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
403 }
404 
405 /**
406  * @tc.name: TestOnSubCommand_sort4
407  * @tc.desc:
408  * @tc.type: FUNC
409  */
410 HWTEST_F(SubCommandReportTest, TestOnSubCommand_sort4, TestSize.Level1)
411 {
412     StdoutRecord stdoutRecord;
413     stdoutRecord.Start();
414     const auto startTime = chrono::steady_clock::now();
415     EXPECT_EQ(
416         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --sort pids"),
417         false);
418     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
419         chrono::steady_clock::now() - startTime);
420     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
421 
422     std::string stringOut = stdoutRecord.Stop();
423     if (HasFailure()) {
424         printf("output:\n%s", stringOut.c_str());
425     }
426     const std::string expectStr = "unknown sort key name 'pids'";
427     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
428 }
429 
430 /**
431  * @tc.name: TestOnSubCommand_symbol
432  * @tc.desc:
433  * @tc.type: FUNC
434  */
435 HWTEST_F(SubCommandReportTest, TestOnSubCommand_symbol, TestSize.Level1)
436 {
437     StdoutRecord stdoutRecord;
438     stdoutRecord.Start();
439     const auto startTime = chrono::steady_clock::now();
440     EXPECT_EQ(
441         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --symbol-dir ./"),
442         true);
443     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
444         chrono::steady_clock::now() - startTime);
445     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
446 
447     std::string stringOut = stdoutRecord.Stop();
448     if (HasFailure()) {
449         printf("output:\n%s", stringOut.c_str());
450     }
451     std::string targetFile = RESOURCE_PATH + "report_test_symbol.txt";
452     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
453 }
454 
455 /**
456  * @tc.name: TestOnSubCommand_limit
457  * @tc.desc:
458  * @tc.type: FUNC
459  */
460 HWTEST_F(SubCommandReportTest, TestOnSubCommand_limit, TestSize.Level1)
461 {
462     StdoutRecord stdoutRecord;
463     stdoutRecord.Start();
464     const auto startTime = chrono::steady_clock::now();
465     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
466                                        "report_test.data --limit-percent 5"),
467               true);
468     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
469         chrono::steady_clock::now() - startTime);
470     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
471 
472     std::string stringOut = stdoutRecord.Stop();
473     if (HasFailure()) {
474         printf("output:\n%s", stringOut.c_str());
475     }
476     std::string targetFile = RESOURCE_PATH + "report_test_limit.txt";
477     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
478 }
479 
480 /**
481  * @tc.name: TestOnSubCommand_limit1
482  * @tc.desc:
483  * @tc.type: FUNC
484  */
485 HWTEST_F(SubCommandReportTest, TestOnSubCommand_limit1, TestSize.Level1)
486 {
487     StdoutRecord stdoutRecord;
488     stdoutRecord.Start();
489     const auto startTime = chrono::steady_clock::now();
490     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
491                                        "report_test.data --limit-percent 1"),
492               true);
493     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
494         chrono::steady_clock::now() - startTime);
495     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
496 
497     std::string stringOut = stdoutRecord.Stop();
498     if (HasFailure()) {
499         printf("output:\n%s", stringOut.c_str());
500     }
501     std::string targetFile = RESOURCE_PATH + "report_test_limit1.txt";
502     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
503 }
504 
505 /**
506  * @tc.name: TestOnSubCommand_limit2
507  * @tc.desc:
508  * @tc.type: FUNC
509  */
510 HWTEST_F(SubCommandReportTest, TestOnSubCommand_limit2, TestSize.Level1)
511 {
512     StdoutRecord stdoutRecord;
513     stdoutRecord.Start();
514     const auto startTime = chrono::steady_clock::now();
515     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
516                                        "report_test.data --limit-percent 99"),
517               true);
518     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
519         chrono::steady_clock::now() - startTime);
520     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
521 
522     std::string stringOut = stdoutRecord.Stop();
523     if (HasFailure()) {
524         printf("output:\n%s", stringOut.c_str());
525     }
526     const std::string expectStr = "kernel.kallsyms";
527     EXPECT_EQ(FindExpectStr(stringOut, expectStr), false);
528 }
529 
530 /**
531  * @tc.name: TestOnSubCommand_limit3
532  * @tc.desc:
533  * @tc.type: FUNC
534  */
535 HWTEST_F(SubCommandReportTest, TestOnSubCommand_limit3, TestSize.Level1)
536 {
537     StdoutRecord stdoutRecord;
538     stdoutRecord.Start();
539     const auto startTime = chrono::steady_clock::now();
540     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
541                                        "report_test.data --limit-percent -1"),
542               false);
543     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
544         chrono::steady_clock::now() - startTime);
545     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
546 
547     std::string stringOut = stdoutRecord.Stop();
548     if (HasFailure()) {
549         printf("output:\n%s", stringOut.c_str());
550     }
551     const std::string expectStr = "head limit error. must in (0 <= limit < 100)";
552     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
553 }
554 
555 /**
556  * @tc.name: TestOnSubCommand_limit4
557  * @tc.desc:
558  * @tc.type: FUNC
559  */
560 HWTEST_F(SubCommandReportTest, TestOnSubCommand_limit4, TestSize.Level1)
561 {
562     StdoutRecord stdoutRecord;
563     stdoutRecord.Start();
564     const auto startTime = chrono::steady_clock::now();
565     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
566                                        "report_test.data --limit-percent 101"),
567               false);
568     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
569         chrono::steady_clock::now() - startTime);
570     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
571 
572     std::string stringOut = stdoutRecord.Stop();
573     if (HasFailure()) {
574         printf("output:\n%s", stringOut.c_str());
575     }
576     const std::string expectStr = "head limit error. must in (0 <= limit < 100)";
577     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
578 }
579 
580 /**
581  * @tc.name: TestOnSubCommand_callstack
582  * @tc.desc:
583  * @tc.type: FUNC
584  */
585 HWTEST_F(SubCommandReportTest, TestOnSubCommand_callstack, TestSize.Level1)
586 {
587     StdoutRecord stdoutRecord;
588     stdoutRecord.Start();
589     const auto startTime = chrono::steady_clock::now();
590     EXPECT_EQ(
591         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --call-stack"),
592         true);
593     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
594         chrono::steady_clock::now() - startTime);
595     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
596 
597     std::string stringOut = stdoutRecord.Stop();
598     if (HasFailure()) {
599         printf("output:\n%s", stringOut.c_str());
600     }
601     std::string targetFile = RESOURCE_PATH + "report_test_callstack.txt";
602     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
603 }
604 
605 /**
606  * @tc.name: TestOnSubCommand_comms
607  * @tc.desc:
608  * @tc.type: FUNC
609  */
610 HWTEST_F(SubCommandReportTest, TestOnSubCommand_comms, TestSize.Level1)
611 {
612     StdoutRecord stdoutRecord;
613     stdoutRecord.Start();
614     const auto startTime = chrono::steady_clock::now();
615     EXPECT_EQ(
616         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --comms hiperf"),
617         true);
618     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
619         chrono::steady_clock::now() - startTime);
620     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
621 
622     std::string stringOut = stdoutRecord.Stop();
623     if (HasFailure()) {
624         printf("output:\n%s", stringOut.c_str());
625     }
626     std::string targetFile = RESOURCE_PATH + "report_test_i.txt";
627     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
628 }
629 
630 /**
631  * @tc.name: TestOnSubCommand_pids
632  * @tc.desc:
633  * @tc.type: FUNC
634  */
635 HWTEST_F(SubCommandReportTest, TestOnSubCommand_pids, TestSize.Level1)
636 {
637     StdoutRecord stdoutRecord;
638     stdoutRecord.Start();
639     const auto startTime = chrono::steady_clock::now();
640     EXPECT_EQ(
641         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --pids 1204"),
642         true);
643     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
644         chrono::steady_clock::now() - startTime);
645     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
646 
647     std::string stringOut = stdoutRecord.Stop();
648     if (HasFailure()) {
649         printf("output:\n%s", stringOut.c_str());
650     }
651     std::string targetFile = RESOURCE_PATH + "report_test_i.txt";
652     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
653 }
654 
655 /**
656  * @tc.name: TestOnSubCommand_pids1
657  * @tc.desc:
658  * @tc.type: FUNC
659  */
660 HWTEST_F(SubCommandReportTest, TestOnSubCommand_pids1, TestSize.Level1)
661 {
662     StdoutRecord stdoutRecord;
663     stdoutRecord.Start();
664     const auto startTime = chrono::steady_clock::now();
665     EXPECT_EQ(
666         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --pids 485"),
667         true);
668     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
669         chrono::steady_clock::now() - startTime);
670     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
671 
672     std::string stringOut = stdoutRecord.Stop();
673     if (HasFailure()) {
674         printf("output:\n%s", stringOut.c_str());
675     }
676     std::string targetFile = RESOURCE_PATH + "report_test_tids1.txt";
677     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
678 }
679 
680 /**
681  * @tc.name: TestOnSubCommand_pids2
682  * @tc.desc:
683  * @tc.type: FUNC
684  */
685 HWTEST_F(SubCommandReportTest, TestOnSubCommand_pids2, TestSize.Level1)
686 {
687     StdoutRecord stdoutRecord;
688     stdoutRecord.Start();
689     const auto startTime = chrono::steady_clock::now();
690     EXPECT_EQ(
691         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --pids 11111"),
692         true);
693     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
694         chrono::steady_clock::now() - startTime);
695     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
696 
697     std::string stringOut = stdoutRecord.Stop();
698     if (HasFailure()) {
699         printf("output:\n%s", stringOut.c_str());
700     }
701     std::string targetFile = RESOURCE_PATH + "report_test_tids1.txt";
702     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
703 }
704 
705 /**
706  * @tc.name: TestOnSubCommand_pids3
707  * @tc.desc:
708  * @tc.type: FUNC
709  */
710 HWTEST_F(SubCommandReportTest, TestOnSubCommand_pids3, TestSize.Level1)
711 {
712     StdoutRecord stdoutRecord;
713     stdoutRecord.Start();
714     const auto startTime = chrono::steady_clock::now();
715     EXPECT_EQ(
716         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --pids -106"),
717         false);
718     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
719         chrono::steady_clock::now() - startTime);
720     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
721 
722     std::string stringOut = stdoutRecord.Stop();
723     if (HasFailure()) {
724         printf("output:\n%s", stringOut.c_str());
725     }
726     const std::string expectStr = "error number for pid";
727     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
728 }
729 
730 /**
731  * @tc.name: TestOnSubCommand_tids
732  * @tc.desc:
733  * @tc.type: FUNC
734  */
735 HWTEST_F(SubCommandReportTest, TestOnSubCommand_tids, TestSize.Level1)
736 {
737     StdoutRecord stdoutRecord;
738     stdoutRecord.Start();
739     const auto startTime = chrono::steady_clock::now();
740     EXPECT_EQ(
741         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --tids 1205"),
742         true);
743     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
744         chrono::steady_clock::now() - startTime);
745     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
746 
747     std::string stringOut = stdoutRecord.Stop();
748     if (HasFailure()) {
749         printf("output:\n%s", stringOut.c_str());
750     }
751     std::string targetFile = RESOURCE_PATH + "report_test_tids.txt";
752     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
753 }
754 
755 /**
756  * @tc.name: TestOnSubCommand_tids1
757  * @tc.desc:
758  * @tc.type: FUNC
759  */
760 HWTEST_F(SubCommandReportTest, TestOnSubCommand_tids1, TestSize.Level1)
761 {
762     StdoutRecord stdoutRecord;
763     stdoutRecord.Start();
764     const auto startTime = chrono::steady_clock::now();
765     EXPECT_EQ(
766         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --tids 905"),
767         true);
768     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
769         chrono::steady_clock::now() - startTime);
770     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
771 
772     std::string stringOut = stdoutRecord.Stop();
773     if (HasFailure()) {
774         printf("output:\n%s", stringOut.c_str());
775     }
776     std::string targetFile = RESOURCE_PATH + "report_test_tids1.txt";
777     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
778 }
779 
780 /**
781  * @tc.name: TestOnSubCommand_tids2
782  * @tc.desc:
783  * @tc.type: FUNC
784  */
785 HWTEST_F(SubCommandReportTest, TestOnSubCommand_tids2, TestSize.Level1)
786 {
787     StdoutRecord stdoutRecord;
788     stdoutRecord.Start();
789     const auto startTime = chrono::steady_clock::now();
790     EXPECT_EQ(
791         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --tids 11111"),
792         true);
793     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
794         chrono::steady_clock::now() - startTime);
795     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
796 
797     std::string stringOut = stdoutRecord.Stop();
798     if (HasFailure()) {
799         printf("output:\n%s", stringOut.c_str());
800     }
801     std::string targetFile = RESOURCE_PATH + "report_test_tids1.txt";
802     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
803 }
804 
805 /**
806  * @tc.name: TestOnSubCommand_tids3
807  * @tc.desc:
808  * @tc.type: FUNC
809  */
810 HWTEST_F(SubCommandReportTest, TestOnSubCommand_tids3, TestSize.Level1)
811 {
812     StdoutRecord stdoutRecord;
813     stdoutRecord.Start();
814     const auto startTime = chrono::steady_clock::now();
815     EXPECT_EQ(
816         Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --tids -109"),
817         false);
818     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
819         chrono::steady_clock::now() - startTime);
820     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
821 
822     std::string stringOut = stdoutRecord.Stop();
823     if (HasFailure()) {
824         printf("output:\n%s", stringOut.c_str());
825     }
826     const std::string expectStr = "error number for tid";
827     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
828 }
829 
830 /**
831  * @tc.name: TestOnSubCommand_dsos
832  * @tc.desc:
833  * @tc.type: FUNC
834  */
835 HWTEST_F(SubCommandReportTest, TestOnSubCommand_dsos, TestSize.Level1)
836 {
837     StdoutRecord stdoutRecord;
838     stdoutRecord.Start();
839     const auto startTime = chrono::steady_clock::now();
840     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
841                                        "report_test.data --dsos [kernel.kallsyms]"),
842               true);
843     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
844         chrono::steady_clock::now() - startTime);
845     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
846 
847     std::string stringOut = stdoutRecord.Stop();
848     if (HasFailure()) {
849         printf("output:\n%s", stringOut.c_str());
850     }
851     std::string targetFile = RESOURCE_PATH + "report_test_dsos.txt";
852     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
853 }
854 
855 /**
856  * @tc.name: TestOnSubCommand_dsos1
857  * @tc.desc:
858  * @tc.type: FUNC
859  */
860 HWTEST_F(SubCommandReportTest, TestOnSubCommand_dsos1, TestSize.Level1)
861 {
862     StdoutRecord stdoutRecord;
863     stdoutRecord.Start();
864     const auto startTime = chrono::steady_clock::now();
865     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
866                                        "report_test.data --dsos /system/lib/libcamera.so"),
867               true);
868     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
869         chrono::steady_clock::now() - startTime);
870     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
871 
872     std::string stringOut = stdoutRecord.Stop();
873     if (HasFailure()) {
874         printf("output:\n%s", stringOut.c_str());
875     }
876     std::string targetFile = RESOURCE_PATH + "report_test_tids1.txt";
877     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
878 }
879 
880 /**
881  * @tc.name: TestOnSubCommand_dsos2
882  * @tc.desc:
883  * @tc.type: FUNC
884  */
885 HWTEST_F(SubCommandReportTest, TestOnSubCommand_dsos2, TestSize.Level1)
886 {
887     StdoutRecord stdoutRecord;
888     stdoutRecord.Start();
889     const auto startTime = chrono::steady_clock::now();
890     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --dso"),
891               false);
892     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
893         chrono::steady_clock::now() - startTime);
894     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
895 
896     std::string stringOut = stdoutRecord.Stop();
897     if (HasFailure()) {
898         printf("output:\n%s", stringOut.c_str());
899     }
900     const std::string expectStr = "unknown option";
901     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
902 }
903 
904 /**
905  * @tc.name: TestOnSubCommand_funcs
906  * @tc.desc:
907  * @tc.type: FUNC
908  */
909 HWTEST_F(SubCommandReportTest, TestOnSubCommand_funcs, TestSize.Level1)
910 {
911     StdoutRecord stdoutRecord;
912     stdoutRecord.Start();
913     const auto startTime = chrono::steady_clock::now();
914     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH +
915                                        "report_test.data --funcs finish_task_switch"),
916               true);
917     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
918         chrono::steady_clock::now() - startTime);
919     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
920 
921     std::string stringOut = stdoutRecord.Stop();
922     if (HasFailure()) {
923         printf("output:\n%s", stringOut.c_str());
924     }
925     std::string targetFile = RESOURCE_PATH + "report_test_funcs.txt";
926     EXPECT_EQ(FileCompare(stringOut, targetFile), true);
927 }
928 
929 /**
930  * @tc.name: TestOnSubCommand_funcs1
931  * @tc.desc:
932  * @tc.type: FUNC
933  */
934 HWTEST_F(SubCommandReportTest, TestOnSubCommand_funcs1, TestSize.Level1)
935 {
936     StdoutRecord stdoutRecord;
937     stdoutRecord.Start();
938     const auto startTime = chrono::steady_clock::now();
939     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --func"),
940               false);
941     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
942         chrono::steady_clock::now() - startTime);
943     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
944 
945     std::string stringOut = stdoutRecord.Stop();
946     if (HasFailure()) {
947         printf("output:\n%s", stringOut.c_str());
948     }
949     const std::string expectStr = "unknown option";
950     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
951 }
952 
953 /**
954  * @tc.name: TestOnSubCommand_json
955  * @tc.desc:
956  * @tc.type: FUNC
957  */
958 HWTEST_F(SubCommandReportTest, TestOnSubCommand_json, TestSize.Level1)
959 {
960     StdoutRecord stdoutRecord;
961     stdoutRecord.Start();
962     const auto startTime = chrono::steady_clock::now();
963     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --json"),
964               true);
965     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
966         chrono::steady_clock::now() - startTime);
967     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
968 
969     std::string stringOut = stdoutRecord.Stop();
970     if (HasFailure()) {
971         printf("output:\n%s", stringOut.c_str());
972     }
973     const std::string expectStr = "report will save at 'perf.json'";
974     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
975 }
976 
977 /**
978  * @tc.name: TestOnSubCommand_json1
979  * @tc.desc:
980  * @tc.type: FUNC
981  */
982 HWTEST_F(SubCommandReportTest, TestOnSubCommand_json1, TestSize.Level1)
983 {
984     StdoutRecord stdoutRecord;
985     stdoutRecord.Start();
986     const auto startTime = chrono::steady_clock::now();
987     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "perf1.data --json"), false);
988     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
989         chrono::steady_clock::now() - startTime);
990     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
991 
992     std::string stringOut = stdoutRecord.Stop();
993     if (HasFailure()) {
994         printf("output:\n%s", stringOut.c_str());
995     }
996     const std::string expectStr =
997         "Can not access data file /data/test/resource/testdata/perf1.data";
998     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
999 }
1000 
1001 /**
1002  * @tc.name: TestOnSubCommand_proto
1003  * @tc.desc:
1004  * @tc.type: FUNC
1005  */
1006 HWTEST_F(SubCommandReportTest, TestOnSubCommand_proto, TestSize.Level1)
1007 {
1008     StdoutRecord stdoutRecord;
1009     stdoutRecord.Start();
1010     const auto startTime = chrono::steady_clock::now();
1011     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data --proto"),
1012               true);
1013     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
1014         chrono::steady_clock::now() - startTime);
1015     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
1016 
1017     std::string stringOut = stdoutRecord.Stop();
1018     if (HasFailure()) {
1019         printf("output:\n%s", stringOut.c_str());
1020     }
1021     const std::string expectStr = "create proto buf file succeed";
1022     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
1023 }
1024 
1025 /**
1026  * @tc.name: TestOnSubCommand_proto1
1027  * @tc.desc:
1028  * @tc.type: FUNC
1029  */
1030 HWTEST_F(SubCommandReportTest, TestOnSubCommand_proto1, TestSize.Level1)
1031 {
1032     StdoutRecord stdoutRecord;
1033     stdoutRecord.Start();
1034     const auto startTime = chrono::steady_clock::now();
1035     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "perf1.data --proto"), false);
1036     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
1037         chrono::steady_clock::now() - startTime);
1038     EXPECT_LE(costMs.count(), DEFAULT_RUN_TIMEOUT_MS);
1039 
1040     std::string stringOut = stdoutRecord.Stop();
1041     if (HasFailure()) {
1042         printf("output:\n%s", stringOut.c_str());
1043     }
1044     const std::string expectStr =
1045         "Can not access data file /data/test/resource/testdata/perf1.data";
1046     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
1047 }
1048 
1049 /**
1050  * @tc.name: TestLoadPerfData
1051  * @tc.desc:
1052  * @tc.type: FUNC
1053  */
1054 HWTEST_F(SubCommandReportTest, TestLoadPerfData, TestSize.Level1)
1055 {
1056     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data -o " +
1057                                        RESOURCE_PATH + "perfnew2.data"),
1058               true);
1059     EXPECT_EQ(IsPath(RESOURCE_PATH + "report_test.data"), true);
1060 }
1061 
1062 /**
1063  * @tc.name: TestOutputReport
1064  * @tc.desc:
1065  * @tc.type: FUNC
1066  */
1067 HWTEST_F(SubCommandReportTest, TestOutputReport, TestSize.Level1)
1068 {
1069     EXPECT_EQ(Command::DispatchCommand("report -i " + RESOURCE_PATH + "report_test.data -o " +
1070                                        RESOURCE_PATH + "perfnew2.data"),
1071               true);
1072     EXPECT_EQ(IsPath(RESOURCE_PATH + "perfnew2.data"), true);
1073 }
1074 
1075 /**
1076  * @tc.name: TestVerifyOption
1077  * @tc.desc:
1078  * @tc.type: FUNC
1079  */
1080 HWTEST_F(SubCommandReportTest, TestVerifyOption, TestSize.Level1)
1081 {
1082     SubCommandReport mSubCommandReport;
1083     std::string recordFile;
1084     std::vector<std::string> args;
1085     args = {"report", "-i", RESOURCE_PATH + "/report_test.data", "--limit-percent", "60"};
1086     ASSERT_EQ(
1087         Option::GetOptionValue(args, "--limit-percent", mSubCommandReport.reportOption_.heatLimit_),
1088         true);
1089     ASSERT_EQ(Option::GetOptionValue(args, "-i", recordFile), true);
1090 
1091     EXPECT_EQ(mSubCommandReport.VerifyOption(), true);
1092 
1093     mSubCommandReport.reportOption_.heatLimit_ = 101.0;
1094     EXPECT_EQ(mSubCommandReport.VerifyOption(), false);
1095 }
1096 
1097 /**
1098  * @tc.name: TestVerifyDisplayOption
1099  * @tc.desc:
1100  * @tc.type: FUNC
1101  */
1102 HWTEST_F(SubCommandReportTest, TestVerifyDisplayOption, TestSize.Level1)
1103 {
1104     SubCommandReport mSubCommandReport;
1105     std::string recordFile;
1106     std::vector<std::string> args;
1107     args = {"report", "-i", RESOURCE_PATH + "report_test.data ", "--pids", "-1"};
1108     ASSERT_EQ(Option::GetOptionValue(args, "--pids", mSubCommandReport.reportOption_.displayPids_),
1109               true);
1110     ASSERT_EQ(Option::GetOptionValue(args, "-i", recordFile), true);
1111     EXPECT_EQ(mSubCommandReport.VerifyDisplayOption(), false);
1112 
1113     mSubCommandReport.reportOption_.displayPids_.clear();
1114     args = {"report -i " + RESOURCE_PATH + "report_test.data --pids "};
1115     EXPECT_EQ(mSubCommandReport.VerifyDisplayOption(), true);
1116 }
1117 
1118 /**
1119  * @tc.name: TestDwarfCompress
1120  * @tc.desc:
1121  * @tc.type: FUNC
1122  */
1123 HWTEST_F(SubCommandReportTest, TestDwarfCompress, TestSize.Level1)
1124 {
1125     StdoutRecord stdoutRecord;
1126     stdoutRecord.Start();
1127     EXPECT_EQ(
1128         Command::DispatchCommand("report -s -i " + RESOURCE_PATH + "dwarf.compress.data"),
1129         true);
1130     std::string stringOut = stdoutRecord.Stop();
1131     if (HasFailure()) {
1132         printf("output:\n%s", stringOut.c_str());
1133     }
1134     const std::string expectStr = "--dedup_stack";
1135     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
1136     const std::string expectPercentageStr = "|- 28.67% futex_wait_queue_me";
1137     EXPECT_EQ(FindExpectStr(stringOut, expectPercentageStr), true);
1138 }
1139 
1140 /**
1141  * @tc.name: TestFpCompress
1142  * @tc.desc:
1143  * @tc.type: FUNC
1144  */
1145 HWTEST_F(SubCommandReportTest, TestFpCompress, TestSize.Level1)
1146 {
1147     StdoutRecord stdoutRecord;
1148     stdoutRecord.Start();
1149     EXPECT_EQ(
1150         Command::DispatchCommand("report -s -i " + RESOURCE_PATH + "fp.compress.data"),
1151         true);
1152     std::string stringOut = stdoutRecord.Stop();
1153     if (HasFailure()) {
1154         printf("output:\n%s", stringOut.c_str());
1155     }
1156     const std::string expectStr = "--dedup_stack";
1157     EXPECT_EQ(FindExpectStr(stringOut, expectStr), true);
1158     const std::string expectPercentageStr = "el0_sync_compat_handler";
1159     EXPECT_EQ(FindExpectStr(stringOut, expectPercentageStr), true);
1160 }
1161 
1162 /**
1163  * @tc.name: TestDwarfUnCompress
1164  * @tc.desc:
1165  * @tc.type: FUNC
1166  */
1167 HWTEST_F(SubCommandReportTest, TestDwarfUnCompress, TestSize.Level1)
1168 {
1169     StdoutRecord stdoutRecord;
1170     stdoutRecord.Start();
1171     EXPECT_EQ(
1172         Command::DispatchCommand("report -s -i " + RESOURCE_PATH + "dwarf.uncompress.data"),
1173         true);
1174     std::string stringOut = stdoutRecord.Stop();
1175     if (HasFailure()) {
1176         printf("output:\n%s", stringOut.c_str());
1177     }
1178     const std::string expectStr = "--dedup_stack";
1179     EXPECT_EQ(FindExpectStr(stringOut, expectStr), false);
1180     const std::string expectPercentageStr = "|-  7.63% __schedule";
1181     EXPECT_EQ(FindExpectStr(stringOut, expectPercentageStr), true);
1182 }
1183 
1184 /**
1185  * @tc.name: TestFpUnCompress
1186  * @tc.desc:
1187  * @tc.type: FUNC
1188  */
1189 HWTEST_F(SubCommandReportTest, TestFpUnCompress, TestSize.Level1)
1190 {
1191     StdoutRecord stdoutRecord;
1192     stdoutRecord.Start();
1193     EXPECT_EQ(
1194         Command::DispatchCommand("report -s -i " + RESOURCE_PATH + "fp.uncompress.data"),
1195         true);
1196     std::string stringOut = stdoutRecord.Stop();
1197     if (HasFailure()) {
1198         printf("output:\n%s", stringOut.c_str());
1199     }
1200     const std::string expectStr = "--dedup_stack";
1201     EXPECT_EQ(FindExpectStr(stringOut, expectStr), false);
1202     const std::string expectPercentageStr = "|- 53.27% __kmalloc_reserve";
1203     EXPECT_EQ(FindExpectStr(stringOut, expectPercentageStr), true);
1204 }
1205 } // namespace HiPerf
1206 } // namespace Developtools
1207 } // namespace OHOS
1208