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