• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "subcommand_record_test.h"
17 
18 #include <algorithm>
19 #include <chrono>
20 #include <cinttypes>
21 #include <sched.h>
22 #include <sstream>
23 #include <thread>
24 
25 #include <poll.h>
26 #include <unistd.h>
27 
28 #include "command.h"
29 #include "debug_logger.h"
30 #include "utilities.h"
31 #include <sys/stat.h>
32 
33 using namespace std::literals::chrono_literals;
34 using namespace testing::ext;
35 using namespace std;
36 using namespace OHOS::HiviewDFX;
37 namespace OHOS {
38 namespace Developtools {
39 namespace HiPerf {
40 static const std::string TEST_FILE = "/data/local/tmp/perf.data";
41 static const std::chrono::milliseconds CONTROL_WAITREPY_TOMEOUT = 2ms;
42 
43 static constexpr size_t TEST_SIZE_F100_DWARF_SYSTEM = 1.4E4 * 1024;
44 static constexpr size_t TEST_SIZE_F500_DWARF_SYSTEM = 3.6E4 * 1024;
45 static constexpr size_t TEST_SIZE_F1000_DWARF_SYSTEM = 5.9E4 * 1024;
46 static constexpr size_t TEST_SIZE_F2000_DWARF_SYSTEM = 8.3E4 * 1024;
47 static constexpr size_t TEST_SIZE_F4000_DWARF_SYSTEM = 1.7E5 * 1024;
48 static constexpr size_t TEST_SIZE_F8000_DWARF_SYSTEM = 3.5E5 * 1024;
49 static constexpr size_t TEST_SIZE_F100_FP_SYSTEM = 10E3 * 1024;
50 static constexpr size_t TEST_SIZE_F500_FP_SYSTEM = 2E4 * 1024;
51 static constexpr size_t TEST_SIZE_F1000_FP_SYSTEM = 3E4 * 1024;
52 static constexpr size_t TEST_SIZE_F2000_FP_SYSTEM = 5E4 * 1024;
53 static constexpr size_t TEST_SIZE_F4000_FP_SYSTEM = 1E5 * 1024;
54 static constexpr size_t TEST_SIZE_F8000_FP_SYSTEM = 2E5 * 1024;
55 
56 static constexpr size_t TEST_SIZE_F100_DWARF_PROCESS = 5.6E3 * 1024;
57 static constexpr size_t TEST_SIZE_F500_DWARF_PROCESS = 1.6E4 * 1024;
58 static constexpr size_t TEST_SIZE_F1000_DWARF_PROCESS = 2.9E4 * 1024;
59 static constexpr size_t TEST_SIZE_F2000_DWARF_PROCESS = 6.1E4 * 1024;
60 static constexpr size_t TEST_SIZE_F4000_DWARF_PROCESS = 5.8E4 * 1024;
61 static constexpr size_t TEST_SIZE_F8000_DWARF_PROCESS = 1.2E5 * 1024;
62 static constexpr size_t TEST_SIZE_F100_FP_PROCESS = 3.6E3 * 1024;
63 static constexpr size_t TEST_SIZE_F500_FP_PROCESS = 8.8E3 * 1024;
64 static constexpr size_t TEST_SIZE_F1000_FP_PROCESS = 1.5E4 * 1024;
65 static constexpr size_t TEST_SIZE_F2000_FP_PROCESS = 3.1E4 * 1024;
66 static constexpr size_t TEST_SIZE_F4000_FP_PROCESS = 6.2E4 * 1024;
67 static constexpr size_t TEST_SIZE_F8000_FP_PROCESS = 1.3E5 * 1024;
68 
69 class SubCommandRecordTest : public testing::Test {
70 public:
71     static void SetUpTestCase(void);
72     static void TearDownTestCase(void);
73     void SetUp();
74     void TearDown();
75 
76     void TestEvents(std::string &opt, std::string &uk, bool isFork = true);
77 
78     static void ForkAndRunTest(const std::string& cmd, bool expect = true, bool fixPid = true);
79 
80     static void TestRecordCommand(const std::string &option, bool expect = true, bool fixPid = true);
81 
82     size_t GetFileSize(const char* fileName);
83 };
84 
SetUpTestCase()85 void SubCommandRecordTest::SetUpTestCase() {}
86 
TearDownTestCase()87 void SubCommandRecordTest::TearDownTestCase() {}
88 
SetUp()89 void SubCommandRecordTest::SetUp()
90 {
91     SubCommand::ClearSubCommands(); // clear the subCommands left from other UT
92     ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
93     SubCommandRecord::RegisterSubCommandRecord();
94     ASSERT_EQ(SubCommand::GetSubCommands().size(), 1u);
95 }
96 
TearDown()97 void SubCommandRecordTest::TearDown()
98 {
99     ASSERT_EQ(SubCommand::GetSubCommands().size(), 1u);
100     SubCommand::ClearSubCommands();
101     ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
102     MemoryHold::Get().Clean();
103 }
104 
ForkAndRunTest(const std::string & cmd,bool expect,bool fixPid)105 void SubCommandRecordTest::ForkAndRunTest(const std::string& cmd, bool expect, bool fixPid)
106 {
107     pid_t pid = fork();
108     if (pid < 0) {
109         FAIL() << "Fork test process failed";
110         return;
111     }
112     if (pid == 0) {
113         TestRecordCommand(cmd, expect, fixPid);
114         _exit(0);
115     }
116     int status;
117     int ret = wait(&status);
118     GTEST_LOG_(INFO) << "Status:" << status << " Result:" << ret;
119     ASSERT_EQ(status, 0);
120 }
121 
TestRecordCommand(const std::string & option,bool expect,bool fixPid)122 void SubCommandRecordTest::TestRecordCommand(const std::string &option, bool expect, bool fixPid)
123 {
124     StdoutRecord stdoutRecord;
125 
126     std::string cmdString = "record ";
127     if (fixPid) {
128         cmdString += "--app com.ohos.launcher ";
129     }
130     cmdString += " " + option;
131     printf("command : %s\n", cmdString.c_str());
132 
133     // it need load some symbols and much more log
134     stdoutRecord.Start();
135     const auto startTime = chrono::steady_clock::now();
136     bool ret = Command::DispatchCommand(cmdString);
137     const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
138         chrono::steady_clock::now() - startTime);
139     std::string stringOut = stdoutRecord.Stop();
140 
141     printf("run %" PRId64 " ms return %s(expect %s)\n", (uint64_t)costMs.count(), ret ? "true" : "false",
142            expect ? "true" : "false");
143     EXPECT_EQ(expect, ret);
144 }
145 
GetFileSize(const char * fileName)146 size_t SubCommandRecordTest::GetFileSize(const char* fileName)
147 {
148     if (fileName == nullptr) {
149         return 0;
150     }
151     struct stat statbuf;
152     stat(fileName, &statbuf);
153     size_t fileSize = statbuf.st_size;
154     return fileSize;
155 }
156 
157 // app package name
158 HWTEST_F(SubCommandRecordTest, PackageName, TestSize.Level1)
159 {
160     ForkAndRunTest("-d 2  --app com.ohos.launcher ", true, false);
161 }
162 
163 HWTEST_F(SubCommandRecordTest, PackageNameErr, TestSize.Level1)
164 {
165     TestRecordCommand("-d 2  --app package_name ", false, false);
166 }
167 
168 // check app milliseconds
169 /**
170  * @tc.name: CheckAppMsMin
171  * @tc.desc: Test chkms minimum value
172  * @tc.type: FUNC
173  * @tc.require: issueI5R305
174  */
175 HWTEST_F(SubCommandRecordTest, CheckAppMsMin, TestSize.Level1)
176 {
177     ForkAndRunTest("-d 0.5 --chkms 1 ");
178 }
179 
180 /**
181  * @tc.name: CheckAppMsMinErr
182  * @tc.desc: Test chkms less than minimum value
183  * @tc.type: FUNC
184  * @tc.require: issueI5R305
185  */
186 HWTEST_F(SubCommandRecordTest, CheckAppMsMinErr, TestSize.Level1)
187 {
188     TestRecordCommand("-d 0.5 --chkms 0 ", false);
189 }
190 
191 /**
192  * @tc.name: CheckAppMsMax
193  * @tc.desc: Test chkms maximum value
194  * @tc.type: FUNC
195  * @tc.require: issueI5R305
196  */
197 HWTEST_F(SubCommandRecordTest, CheckAppMsMax, TestSize.Level1)
198 {
199     ForkAndRunTest("-d 0.5 --chkms 200 ");
200 }
201 
202 /**
203  * @tc.name: CheckAppMsMaxErr
204  * @tc.desc: Test chkms more than maximum value
205  * @tc.type: FUNC
206  * @tc.require: issueI5R305
207  */
208 HWTEST_F(SubCommandRecordTest, CheckAppMsMaxErr, TestSize.Level1)
209 {
210     TestRecordCommand("-d 0.5 --chkms 201 ", false);
211 }
212 
213 /**
214  * @tc.name: CheckAppMsInputErr
215  * @tc.desc: Test erro type of chkms
216  * @tc.type: FUNC
217  * @tc.require: issueI5R305
218  */
219 HWTEST_F(SubCommandRecordTest, CheckAppMsInputErr, TestSize.Level1)
220 {
221     TestRecordCommand("-d 0.5 --chkms abc ", false);
222 }
223 // stop seconds
224 HWTEST_F(SubCommandRecordTest, StopSecondsMin, TestSize.Level1)
225 {
226     ForkAndRunTest("-d 0.1 ");
227 }
228 
229 HWTEST_F(SubCommandRecordTest, StopSecondsMinErr, TestSize.Level1)
230 {
231     TestRecordCommand("-d 0.099 ", false);
232 }
233 
234 HWTEST_F(SubCommandRecordTest, StopSecondsMax, TestSize.Level1)
235 {
236     std::string opt = "-d 10000.0 ";
237     opt += " ls "; // because UT don't need wait so long
238     ForkAndRunTest(opt, true, false);
239 }
240 
241 HWTEST_F(SubCommandRecordTest, StopSecondsMaxErr, TestSize.Level1)
242 {
243     std::string opt = "-d 10000.1 ";
244     opt += " ";
245     TestRecordCommand(opt, false);
246 }
247 
248 // system wide
249 HWTEST_F(SubCommandRecordTest, SystemWide, TestSize.Level1)
250 {
251     ForkAndRunTest("-d 2 -a ", true, false);
252 }
253 
254 // trackedCommand_
255 HWTEST_F(SubCommandRecordTest, TrackedCommandErr, TestSize.Level1)
256 {
257     TestRecordCommand("-d 2 -a aa ", false, false);
258 }
259 
260 // --app and -p
261 HWTEST_F(SubCommandRecordTest, HasTargetErr, TestSize.Level1)
262 {
263     TestRecordCommand("--app test -p 123 -d 3 ", false, false);
264 }
265 
266 HWTEST_F(SubCommandRecordTest, HasTargetErr1, TestSize.Level1)
267 {
268     TestRecordCommand("-d 3 ", false, false);
269 }
270 
271 // exclude hiperf
272 HWTEST_F(SubCommandRecordTest, ExcludePerf, TestSize.Level1)
273 {
274     ForkAndRunTest("-d 2 -a --exclude-hiperf ", true, false);
275 }
276 
277 HWTEST_F(SubCommandRecordTest, ExcludePerfErr, TestSize.Level1)
278 {
279     TestRecordCommand("-d 2 --exclude-hiperf ", false, true);
280 }
281 
282 // select cpu
283 HWTEST_F(SubCommandRecordTest, SelectCpu, TestSize.Level1)
284 {
285     ForkAndRunTest("-d 2 -c 0 ");
286 }
287 
288 HWTEST_F(SubCommandRecordTest, SelectCpuMulti, TestSize.Level1)
289 {
290     int maxCpuid = sysconf(_SC_NPROCESSORS_CONF);
291     std::string opt = "-d 2 -e sw-task-clock -c ";
292     for (int i = 0; i < maxCpuid; i++) {
293         opt += std::to_string(i);
294         opt += ",";
295     }
296     opt.pop_back();
297     opt += " ";
298     ForkAndRunTest(opt);
299 }
300 
301 HWTEST_F(SubCommandRecordTest, SelectCpuMinErr, TestSize.Level1)
302 {
303     TestRecordCommand("-d 2 -c -1 ", false);
304 }
305 
306 HWTEST_F(SubCommandRecordTest, SelectCpuMaxErr, TestSize.Level1)
307 {
308     int maxCpuid = sysconf(_SC_NPROCESSORS_CONF);
309     std::string opt = "-d 2 -c ";
310     opt += std::to_string(maxCpuid);
311     opt += " ";
312     TestRecordCommand(opt, false);
313 }
314 
315 HWTEST_F(SubCommandRecordTest, SelectCpuInputErr, TestSize.Level1)
316 {
317     TestRecordCommand("-d 2 -c abc ", false);
318 }
319 
320 // --control
321 HWTEST_F(SubCommandRecordTest, CheckControlErr, TestSize.Level1)
322 {
323     TestRecordCommand("-a --control st", false, false);
324 }
325 
326 // cpu percent
327 HWTEST_F(SubCommandRecordTest, CpuLimitMin, TestSize.Level1)
328 {
329     ForkAndRunTest("-d 2 --cpu-limit 1 ");
330 }
331 
332 HWTEST_F(SubCommandRecordTest, CpuLimitErr, TestSize.Level1)
333 {
334     TestRecordCommand("-d 2 --cpu-limit 0 ", false);
335 }
336 
337 HWTEST_F(SubCommandRecordTest, CpuLimitMax, TestSize.Level1)
338 {
339     ForkAndRunTest("-d 2 --cpu-limit 100 ");
340 }
341 
342 HWTEST_F(SubCommandRecordTest, CpuLimitMaxErr, TestSize.Level1)
343 {
344     TestRecordCommand("-d 2 --cpu-limit 101 ", false);
345 }
346 
347 HWTEST_F(SubCommandRecordTest, CpuLimitInputErr, TestSize.Level1)
348 {
349     TestRecordCommand("-d 2 --cpu-limit abc ", false);
350 }
351 
352 // frequency
353 HWTEST_F(SubCommandRecordTest, FrequncyMin, TestSize.Level1)
354 {
355     ForkAndRunTest("-d 2 -f 1 ");
356 }
357 
358 HWTEST_F(SubCommandRecordTest, FrequncyMinErr, TestSize.Level1)
359 {
360     TestRecordCommand("-d 2 -f 0 ", false);
361 }
362 
363 HWTEST_F(SubCommandRecordTest, FrequncyMax, TestSize.Level1)
364 {
365     ForkAndRunTest("-d 2 -f 100000 ");
366 }
367 
368 HWTEST_F(SubCommandRecordTest, FrequncyMaxErr, TestSize.Level1)
369 {
370     TestRecordCommand("-d 2 -f 100001 ", false);
371 }
372 
373 HWTEST_F(SubCommandRecordTest, FrequncyInputErr, TestSize.Level1)
374 {
375     TestRecordCommand("-d 2 -f abc ", false);
376 }
377 
378 // period
379 HWTEST_F(SubCommandRecordTest, PeriodMin, TestSize.Level1)
380 {
381     ForkAndRunTest("-d 2 --period 1 ");
382 }
383 
384 HWTEST_F(SubCommandRecordTest, PeriodMinErr, TestSize.Level1)
385 {
386     TestRecordCommand("-d 2 --period 0 ", false);
387 }
388 
389 HWTEST_F(SubCommandRecordTest, PeriodMax, TestSize.Level1)
390 {
391     std::string opt = "-d 2 --period ";
392     opt += std::to_string(INT_MAX);
393     opt += " ";
394     ForkAndRunTest(opt);
395 }
396 
397 HWTEST_F(SubCommandRecordTest, PeriodMaxErr, TestSize.Level1)
398 {
399     std::string opt = "-d 2 --period ";
400     uint32_t value = static_cast<uint32_t>(INT_MAX) + 1;
401     opt += std::to_string(value);
402     opt += " ";
403     TestRecordCommand(opt, false);
404 }
405 
406 HWTEST_F(SubCommandRecordTest, PeriodInputErr, TestSize.Level1)
407 {
408     TestRecordCommand("-d 2 --period abc ", false);
409 }
410 
411 HWTEST_F(SubCommandRecordTest, PeriodAndFrequncyConflict, TestSize.Level1)
412 {
413     TestRecordCommand("-d 2 -f 2000 --period 10 ", false);
414 }
415 
TestEvents(std::string & opt,std::string & uk,bool isFork)416 void SubCommandRecordTest::TestEvents(std::string &opt, std::string &uk, bool isFork)
417 {
418     PerfEvents perfEvents;
419     for (auto type : TYPE_CONFIGS) {
420         auto configs = perfEvents.GetSupportEvents(type.first);
421         if (configs.empty()) {
422             continue;
423         }
424 
425         const int MAX_TESTEVENT = 5;
426         int testEventCount = MAX_TESTEVENT;
427         std::string cmdline = opt;
428         for (auto config : configs) {
429             if (testEventCount <= 0) {
430                 break;
431             }
432             cmdline += config.second;
433             cmdline += uk;
434             cmdline += ",";
435             testEventCount--;
436         }
437         cmdline.pop_back(); // remove the last ','
438         if (isFork) {
439             ForkAndRunTest(cmdline);
440         } else {
441             TestRecordCommand(cmdline);
442         }
443         TearDown();
444         SetUp();
445     }
446 }
447 
448 // select events
449 HWTEST_F(SubCommandRecordTest, SelectEvents, TestSize.Level1)
450 {
451     std::string opt = "-d 2 -c 0 -e ";
452     std::string uk = "";
453     TestEvents(opt, uk);
454 }
455 
456 HWTEST_F(SubCommandRecordTest, SelectEventsUser, TestSize.Level1)
457 {
458     std::string opt = "-d 2 -c 0 -e ";
459     std::string uk = ":u";
460     TestEvents(opt, uk);
461 }
462 
463 HWTEST_F(SubCommandRecordTest, SelectEventsKernel, TestSize.Level1)
464 {
465     std::string opt = "-d 2 -c 0 -e ";
466     std::string uk = ":k";
467     TestEvents(opt, uk);
468 }
469 
470 HWTEST_F(SubCommandRecordTest, SelectEventsKernel_2, TestSize.Level1)
471 {
472     std::string opt = "-d 2 -c 0 -e ";
473     std::string uk = ":k";
474     TestEvents(opt, uk, false);
475 }
476 
477 HWTEST_F(SubCommandRecordTest, SelectEventsErr, TestSize.Level1)
478 {
479     ForkAndRunTest("-d 2 -c 0 -e what ", false);
480 }
481 
482 // select group events
483 HWTEST_F(SubCommandRecordTest, GroupEvents, TestSize.Level1)
484 {
485     std::string opt = "-d 2 -c 0 -g ";
486     std::string uk = "";
487     TestEvents(opt, uk);
488 }
489 
490 HWTEST_F(SubCommandRecordTest, GroupEventsUser, TestSize.Level1)
491 {
492     std::string opt = "-d 2 -c 0 -g ";
493     std::string uk = ":u";
494     TestEvents(opt, uk);
495 }
496 
497 HWTEST_F(SubCommandRecordTest, GroupEventsKernal, TestSize.Level1)
498 {
499     std::string opt = "-d 2 -c 0 -g ";
500     std::string uk = ":k";
501     TestEvents(opt, uk);
502 }
503 
504 HWTEST_F(SubCommandRecordTest, GroupEventsErr, TestSize.Level1)
505 {
506     ForkAndRunTest("-d 2 -c 0 -g what ", false);
507 }
508 
509 HWTEST_F(SubCommandRecordTest, NoInherit, TestSize.Level1)
510 {
511     ForkAndRunTest("-d 2 --no-inherit ");
512 }
513 
514 // select pid
515 HWTEST_F(SubCommandRecordTest, SelectPid, TestSize.Level1)
516 {
517     ForkAndRunTest("-d 2 -p 1 ", true, false);
518 }
519 
520 HWTEST_F(SubCommandRecordTest, KernelSymbols, TestSize.Level1)
521 {
522     TestRecordCommand("-d 2 -p 2 -s dwarf ", true, false);
523 }
524 
525 HWTEST_F(SubCommandRecordTest, SelectPidMulti, TestSize.Level1)
526 {
527     ForkAndRunTest("-d 2 -p 1,2,3 ", true, false);
528 }
529 
530 HWTEST_F(SubCommandRecordTest, SelectPidMinErr, TestSize.Level1)
531 {
532     TestRecordCommand("-d 2 -p 0 ", false, false);
533 }
534 
535 HWTEST_F(SubCommandRecordTest, SelectPidMinErr1, TestSize.Level1)
536 {
537     TestRecordCommand("-d 2 -p -1 ", false, false);
538 }
539 
540 HWTEST_F(SubCommandRecordTest, SelectPidErr, TestSize.Level1)
541 {
542     TestRecordCommand("-d 2 -p 99999999 ", false, false);
543 }
544 
545 HWTEST_F(SubCommandRecordTest, SelectPidInputErr, TestSize.Level1)
546 {
547     TestRecordCommand("-d 2 -p abc ", false, false);
548 }
549 
550 HWTEST_F(SubCommandRecordTest, SelectPidInputConfict, TestSize.Level1)
551 {
552     ForkAndRunTest("-d 2 -a -p 1 ", false, false);
553 }
554 
555 // select tid
556 HWTEST_F(SubCommandRecordTest, SelectTid, TestSize.Level1)
557 {
558     ForkAndRunTest("-d 2 -t 1 ", true, false);
559 }
560 
561 HWTEST_F(SubCommandRecordTest, SelectTidMulti, TestSize.Level1)
562 {
563     ForkAndRunTest("-d 2 -t 1,2,3 ", true, false);
564 }
565 
566 HWTEST_F(SubCommandRecordTest, SelectTidMinErr, TestSize.Level1)
567 {
568     TestRecordCommand("-d 2 -t 0 ", false, false);
569 }
570 
571 HWTEST_F(SubCommandRecordTest, SelectTidErr, TestSize.Level1)
572 {
573     TestRecordCommand("-d 2 -t 99999999 ", false, false);
574 }
575 
576 HWTEST_F(SubCommandRecordTest, SelectTidInputErr, TestSize.Level1)
577 {
578     TestRecordCommand("-d 2 -t abc ", false, false);
579 }
580 
581 // cpu off
582 HWTEST_F(SubCommandRecordTest, CpuOff, TestSize.Level1)
583 {
584     ForkAndRunTest("-d 2 --offcpu ");
585 }
586 
587 HWTEST_F(SubCommandRecordTest, BranchFilterAny, TestSize.Level1)
588 {
589 #if is_ohos
590     TestRecordCommand("-d 2 -j any ", false); // broad doesn't support
591 #else
592     ForkAndRunTest("-d 2 -j any ");
593 #endif
594 }
595 
596 HWTEST_F(SubCommandRecordTest, BranchFilterAnyCall, TestSize.Level1)
597 {
598 #if is_ohos
599     TestRecordCommand("-d 2 -j any_call ", false); // broad doesn't support
600 #else
601     ForkAndRunTest("-d 2 -j any_call ");
602 #endif
603 }
604 
605 HWTEST_F(SubCommandRecordTest, BranchFilterIndCall, TestSize.Level1)
606 {
607 #if is_ohos
608     TestRecordCommand("-d 2 -j ind_call ", false); // broad doesn't support
609 #else
610     ForkAndRunTest("-d 2 -j ind_call ");
611 #endif
612 }
613 
614 HWTEST_F(SubCommandRecordTest, BranchFilterAnyRet, TestSize.Level1)
615 {
616 #if is_ohos
617     TestRecordCommand("-d 2 -j any_ret ", false); // broad doesn't support
618 #else
619     ForkAndRunTest("-d 2 -j any_ret ");
620 #endif
621 }
622 
623 HWTEST_F(SubCommandRecordTest, BranchFilterOnlyCall, TestSize.Level1)
624 {
625     TestRecordCommand("-d 2 -j call ", false);
626 }
627 
628 HWTEST_F(SubCommandRecordTest, BranchFilterAll, TestSize.Level1)
629 {
630 #if is_ohos
631     TestRecordCommand("-d 2 -j any,any_call,any_ret,ind_call,u,k ", false); // broad doesn't support
632 #else
633     ForkAndRunTest("-d 2 -j any,any_call,any_ret,ind_call,u,k ");
634 #endif
635 }
636 
637 HWTEST_F(SubCommandRecordTest, BranchFilterInputErr, TestSize.Level1)
638 {
639     TestRecordCommand("-d 2 -j what ", false);
640 }
641 
642 HWTEST_F(SubCommandRecordTest, BranchFilterInputMoreErr, TestSize.Level1)
643 {
644     TestRecordCommand("-d 2 -j any,n ", false);
645 }
646 
647 // call stack
648 HWTEST_F(SubCommandRecordTest, CallStackFp, TestSize.Level1)
649 {
650     ForkAndRunTest("-d 2 --call-stack fp ");
651     TearDown();
652     SetUp();
653     ForkAndRunTest("-d 2 -s fp ");
654 }
655 
656 HWTEST_F(SubCommandRecordTest, CallStackFpInputMoreErr, TestSize.Level1)
657 {
658     TestRecordCommand("-d 2 --call-stack fp,abc ", false);
659     TearDown();
660     SetUp();
661     TestRecordCommand("-d 2 -s fp,abc ", false);
662 }
663 
664 HWTEST_F(SubCommandRecordTest, CallStackInputErr, TestSize.Level1)
665 {
666     TestRecordCommand("-d 2 --call-stack what ", false);
667     TearDown();
668     SetUp();
669     TestRecordCommand("-d 2 -s what ", false);
670 }
671 
672 HWTEST_F(SubCommandRecordTest, CallStackDwarfSizeMin, TestSize.Level1)
673 {
674     // it will cause some crash in -fprofile-arcs and -ftest-coverage
675     // we will fix it latter
676     ForkAndRunTest("-d 2 --call-stack dwarf,8 ");
677     TearDown();
678     SetUp();
679     ForkAndRunTest("-d 2 -s dwarf,8 ");
680 }
681 
682 HWTEST_F(SubCommandRecordTest, CallStackDwarfSizeMinErr, TestSize.Level1)
683 {
684     TestRecordCommand("-d 2 --call-stack dwarf,7 ", false);
685     TearDown();
686     SetUp();
687     TestRecordCommand("-d 2 -s dwarf,7 ", false);
688 }
689 
690 HWTEST_F(SubCommandRecordTest, CallStackDwarfSizeMax, TestSize.Level1)
691 {
692     ForkAndRunTest("-d 2 --call-stack dwarf,65528 ");
693     TearDown();
694     SetUp();
695     ForkAndRunTest("-d 2 -s dwarf,65528 ");
696 }
697 
698 HWTEST_F(SubCommandRecordTest, CallStackDwarfSizeMaxErr, TestSize.Level1)
699 {
700     TestRecordCommand("-d 2 --call-stack dwarf,65529 ", false);
701     TearDown();
702     SetUp();
703     TestRecordCommand("-d 2 -s dwarf,65529 ", false);
704 }
705 
706 HWTEST_F(SubCommandRecordTest, CallStackDwarfSizeErr, TestSize.Level1)
707 {
708     TestRecordCommand("-d 2 --call-stack dwarf,15 ", false);
709     TearDown();
710     SetUp();
711     TestRecordCommand("-d 2 -s dwarf,15 ", false);
712 }
713 
714 HWTEST_F(SubCommandRecordTest, CallStackDwarfSizeInputErr, TestSize.Level1)
715 {
716     TestRecordCommand("-d 2 --call-stack dwarf,abc ", false);
717     TearDown();
718     SetUp();
719     TestRecordCommand("-d 2 -s dwarf,abc ", false);
720 }
721 
722 HWTEST_F(SubCommandRecordTest, CallStackDwarfSizeInputMoreErr, TestSize.Level1)
723 {
724     TestRecordCommand("-d 2 --call-stack dwarf,16,32 ", false);
725     TearDown();
726     SetUp();
727     TestRecordCommand("-d 2 -s dwarf,16,32 ", false);
728 }
729 
730 HWTEST_F(SubCommandRecordTest, CallStackUsageErr, TestSize.Level1)
731 {
732     TestRecordCommand("-d 2 -s abc --call-stack bcd", false);
733 }
734 
735 // unwind
736 HWTEST_F(SubCommandRecordTest, DlayUnwind, TestSize.Level1)
737 {
738     ForkAndRunTest("-d 2 -s dwarf,16 --delay-unwind ");
739 }
740 
741 HWTEST_F(SubCommandRecordTest, DisableUnwind, TestSize.Level1)
742 {
743     ForkAndRunTest("-d 2 -s dwarf,16 --disable-unwind ");
744 }
745 
746 HWTEST_F(SubCommandRecordTest, DisableCallstackMerge, TestSize.Level1)
747 {
748     ForkAndRunTest("-d 2 -s dwarf,16 --disable-callstack-expand ");
749 }
750 
751 // symbol dir
752 HWTEST_F(SubCommandRecordTest, SymbolDir, TestSize.Level1)
753 {
754     ForkAndRunTest("-d 2 --symbol-dir ./ ");
755 }
756 
757 HWTEST_F(SubCommandRecordTest, SymbolDirErr, TestSize.Level1)
758 {
759     TestRecordCommand("-d 2 --symbol-dir where ", false);
760 }
761 
762 // clock id
763 HWTEST_F(SubCommandRecordTest, ClockIdMonotonic, TestSize.Level1)
764 {
765     ForkAndRunTest("-d 2 --clockid monotonic ");
766 }
767 
768 HWTEST_F(SubCommandRecordTest, ClockIdMonotonicRaw, TestSize.Level1)
769 {
770     ForkAndRunTest("-d 2 --clockid monotonic_raw ");
771 }
772 
773 HWTEST_F(SubCommandRecordTest, ClockIdBoottime, TestSize.Level1)
774 {
775     ForkAndRunTest("-c 0 -d 2 -e sw-task-clock --clockid boottime ");
776 }
777 
778 HWTEST_F(SubCommandRecordTest, ClockIdRealtime, TestSize.Level1)
779 {
780     ForkAndRunTest("-c 0 -d 2 -e sw-task-clock --clockid realtime ");
781 }
782 
783 HWTEST_F(SubCommandRecordTest, ClockIdClockTai, TestSize.Level1)
784 {
785     ForkAndRunTest("-c 0 -d 2 -e sw-task-clock --clockid clock_tai ");
786 }
787 
788 HWTEST_F(SubCommandRecordTest, ClockIdInputErr, TestSize.Level1)
789 {
790     TestRecordCommand("-c 0 -d 2 --clockid what ", false);
791 }
792 
793 // mmap pages
794 HWTEST_F(SubCommandRecordTest, MmapPagesPower2Err, TestSize.Level1)
795 {
796     TestRecordCommand("-d 2 -m 101 ", false);
797 }
798 
799 HWTEST_F(SubCommandRecordTest, MmapPagesMin, TestSize.Level1)
800 {
801     ForkAndRunTest("-d 2 -m 2 ");
802 }
803 
804 HWTEST_F(SubCommandRecordTest, MmapPagesMinErr, TestSize.Level1)
805 {
806     TestRecordCommand("-d 2 -m 1 ", false);
807 }
808 
809 HWTEST_F(SubCommandRecordTest, MmapPagesMax, TestSize.Level1)
810 {
811     ForkAndRunTest("-d 2 -m 1024 ");
812 }
813 
814 HWTEST_F(SubCommandRecordTest, MmapPagesMaxErr, TestSize.Level1)
815 {
816     TestRecordCommand("-d 2 -m 1025 ", false);
817 }
818 
819 HWTEST_F(SubCommandRecordTest, MmapPagesInputErr, TestSize.Level1)
820 {
821     TestRecordCommand("-d 2 -m abc ", false);
822 }
823 
824 // output file name
825 HWTEST_F(SubCommandRecordTest, OutputFileName, TestSize.Level1)
826 {
827     ForkAndRunTest("-d 2 -o /data/local/tmp/output.perf.data ");
828 }
829 
830 HWTEST_F(SubCommandRecordTest, OutputFileNameErr, TestSize.Level1)
831 {
832     TestRecordCommand("-d 2 -o nopath/output.perf.data ", false);
833 }
834 
835 // data size limit
836 HWTEST_F(SubCommandRecordTest, DataLimit, TestSize.Level1)
837 {
838     ForkAndRunTest("-d 2 --data-limit 1K ");
839     TearDown();
840     SetUp();
841     ForkAndRunTest("-d 2 --data-limit 1M ");
842     TearDown();
843     SetUp();
844     ForkAndRunTest("-d 2 --data-limit 1G ");
845 }
846 
847 HWTEST_F(SubCommandRecordTest, DataLimit1, TestSize.Level1)
848 {
849     ForkAndRunTest("-a --data-limit 1K ", true, false);
850 }
851 
852 HWTEST_F(SubCommandRecordTest, DataLimitErr, TestSize.Level1)
853 {
854     TestRecordCommand("-d 2 --data-limit 10A ", false);
855     TearDown();
856     SetUp();
857     TestRecordCommand("-d 2 --data-limit 0G ", false);
858 }
859 
860 HWTEST_F(SubCommandRecordTest, RecordCompress, TestSize.Level1)
861 {
862     ForkAndRunTest("-d 2 -z ");
863 }
864 
865 HWTEST_F(SubCommandRecordTest, Verbose, TestSize.Level1)
866 {
867     ForkAndRunTest("-d 2 --verbose ");
868 }
869 
870 HWTEST_F(SubCommandRecordTest, DumpOptions, TestSize.Level1)
871 {
872     StdoutRecord stdoutRecord;
873     stdoutRecord.Start();
874     SubCommandRecord cmd;
875     cmd.DumpOptions();
876     std::string stringOut = stdoutRecord.Stop();
877     EXPECT_TRUE(stringOut.find("cpuPercent:	25") != std::string::npos);
878     EXPECT_TRUE(stringOut.find("mmapPages_:	1024") != std::string::npos);
879 }
880 
881 /**
882  * @tc.name: FileSizeOnFrequency100_DWARF_SYSTEM
883  * @tc.desc: Test size of file generated under system wide frequency 100 and dwarf unwind
884  * @tc.type: FUNC
885  */
886 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_DWARF_SYSTEM, TestSize.Level1)
887 {
888     ForkAndRunTest("-d 10 -a -f 100 -s dwarf", true, false);
889     std::string fileName = TEST_FILE;
890     size_t fileSize = GetFileSize(fileName.c_str());
891     EXPECT_LE(fileSize, TEST_SIZE_F100_DWARF_SYSTEM);
892 }
893 
894 /**
895  * @tc.name: FileSizeOnFrequency500_DWARF_SYSTEM
896  * @tc.desc: Test size of file generated under system wide frequency 500 and dwarf unwind
897  * @tc.type: FUNC
898  */
899 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_DWARF_SYSTEM, TestSize.Level1)
900 {
901     ForkAndRunTest("-d 10 -a -f 500 -s dwarf", true, false);
902     std::string fileName = TEST_FILE;
903     size_t fileSize = GetFileSize(fileName.c_str());
904     EXPECT_LE(fileSize, TEST_SIZE_F500_DWARF_SYSTEM);
905 }
906 
907 /**
908  * @tc.name: FileSizeOnFrequency1000_DWARF_SYSTEM
909  * @tc.desc: Test size of file generated under system wide frequency 1000 and dwarf unwind
910  * @tc.type: FUNC
911  */
912 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_DWARF_SYSTEM, TestSize.Level1)
913 {
914     ForkAndRunTest("-d 10 -a -f 1000 -s dwarf", true, false);
915     std::string fileName = TEST_FILE;
916     size_t fileSize = GetFileSize(fileName.c_str());
917     EXPECT_LE(fileSize, TEST_SIZE_F1000_DWARF_SYSTEM);
918 }
919 
920 /**
921  * @tc.name: FileSizeOnFrequency2000_DWARF_SYSTEM
922  * @tc.desc: Test size of file generated under system wide frequency 2000 and dwarf unwind
923  * @tc.type: FUNC
924  */
925 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_DWARF_SYSTEM, TestSize.Level1)
926 {
927     ForkAndRunTest("-d 10 -a -f 2000 -s dwarf", true, false);
928     std::string fileName = TEST_FILE;
929     size_t fileSize = GetFileSize(fileName.c_str());
930     EXPECT_LE(fileSize, TEST_SIZE_F2000_DWARF_SYSTEM);
931 }
932 
933 /**
934  * @tc.name: FileSizeOnFrequency4000_DWARF_SYSTEM
935  * @tc.desc: Test size of file generated under system wide frequency 4000 and dwarf unwind
936  * @tc.type: FUNC
937  */
938 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_DWARF_SYSTEM, TestSize.Level1)
939 {
940     ForkAndRunTest("-d 10 -a -f 4000 -s dwarf", true, false);
941     std::string fileName = TEST_FILE;
942     size_t fileSize = GetFileSize(fileName.c_str());
943     EXPECT_LE(fileSize, TEST_SIZE_F4000_DWARF_SYSTEM);
944 }
945 
946 /**
947  * @tc.name: FileSizeOnFrequency8000_DWARF_SYSTEM
948  * @tc.desc: Test size of file generated under system wide frequency 8000 and dwarf unwind
949  * @tc.type: FUNC
950  */
951 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_DWARF_SYSTEM, TestSize.Level1)
952 {
953     ForkAndRunTest("-d 10 -a -f 8000 -s dwarf", true, false);
954     std::string fileName = TEST_FILE;
955     size_t fileSize = GetFileSize(fileName.c_str());
956     EXPECT_LE(fileSize, TEST_SIZE_F8000_DWARF_SYSTEM);
957 }
958 
959 /**
960  * @tc.name: FileSizeOnFrequency100_FP_SYSTEM
961  * @tc.desc: Test size of file generated under system wide frequency 100 and fp unwind
962  * @tc.type: FUNC
963  */
964 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_FP_SYSTEM, TestSize.Level1)
965 {
966     ForkAndRunTest("-d 10 -a -f 100 -s fp", true, false);
967     std::string fileName = TEST_FILE;
968     size_t fileSize = GetFileSize(fileName.c_str());
969     EXPECT_LE(fileSize, TEST_SIZE_F100_FP_SYSTEM);
970 }
971 
972 /**
973  * @tc.name: FileSizeOnFrequency500_FP_SYSTEM
974  * @tc.desc: Test size of file generated under system wide frequency 500 and fp unwind
975  * @tc.type: FUNC
976  */
977 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_FP_SYSTEM, TestSize.Level1)
978 {
979     ForkAndRunTest("-d 10 -a -f 500 -s fp", true, false);
980     std::string fileName = TEST_FILE;
981     size_t fileSize = GetFileSize(fileName.c_str());
982     EXPECT_LE(fileSize, TEST_SIZE_F500_FP_SYSTEM);
983 }
984 
985 /**
986  * @tc.name: FileSizeOnFrequency1000_FP_SYSTEM
987  * @tc.desc: Test size of file generated under system wide frequency 1000 and fp unwind
988  * @tc.type: FUNC
989  */
990 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_FP_SYSTEM, TestSize.Level1)
991 {
992     ForkAndRunTest("-d 10 -a -f 1000 -s fp", true, false);
993     std::string fileName = TEST_FILE;
994     size_t fileSize = GetFileSize(fileName.c_str());
995     EXPECT_LE(fileSize, TEST_SIZE_F1000_FP_SYSTEM);
996 }
997 
998 /**
999  * @tc.name: FileSizeOnFrequency2000_FP_SYSTEM
1000  * @tc.desc: Test size of file generated under system wide frequency 2000 and fp unwind
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_FP_SYSTEM, TestSize.Level1)
1004 {
1005     ForkAndRunTest("-d 10 -a -f 2000 -s fp", true, false);
1006     std::string fileName = TEST_FILE;
1007     size_t fileSize = GetFileSize(fileName.c_str());
1008     EXPECT_LE(fileSize, TEST_SIZE_F2000_FP_SYSTEM);
1009 }
1010 
1011 /**
1012  * @tc.name: FileSizeOnFrequency4000_FP_SYSTEM
1013  * @tc.desc: Test size of file generated under system wide frequency 4000 and fp unwind
1014  * @tc.type: FUNC
1015  */
1016 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_FP_SYSTEM, TestSize.Level1)
1017 {
1018     ForkAndRunTest("-d 10 -a -f 4000 -s fp", true, false);
1019     std::string fileName = TEST_FILE;
1020     size_t fileSize = GetFileSize(fileName.c_str());
1021     EXPECT_LE(fileSize, TEST_SIZE_F4000_FP_SYSTEM);
1022 }
1023 
1024 /**
1025  * @tc.name: FileSizeOnFrequency8000_FP_SYSTEM
1026  * @tc.desc: Test size of file generated under system wide frequency 8000 and fp unwind
1027  * @tc.type: FUNC
1028  */
1029 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_FP_SYSTEM, TestSize.Level1)
1030 {
1031     ForkAndRunTest("-d 10 -a -f 8000 -s fp", true, false);
1032     std::string fileName = TEST_FILE;
1033     size_t fileSize = GetFileSize(fileName.c_str());
1034     EXPECT_LE(fileSize, TEST_SIZE_F8000_FP_SYSTEM);
1035 }
1036 
1037 /**
1038  * @tc.name: FileSizeOnFrequency100_DWARF_PROCESS
1039  * @tc.desc: Test size of file generated under one process frequency 100 and dwarf unwind
1040  * @tc.type: FUNC
1041  */
1042 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_DWARF_PROCESS, TestSize.Level1)
1043 {
1044     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 100 -s dwarf", true, false);
1045     std::string fileName = TEST_FILE;
1046     size_t fileSize = GetFileSize(fileName.c_str());
1047     EXPECT_LE(fileSize, TEST_SIZE_F100_DWARF_PROCESS);
1048 }
1049 
1050 /**
1051  * @tc.name: FileSizeOnFrequency500_DWARF_PROCESS
1052  * @tc.desc: Test size of file generated under one process frequency 500 and dwarf unwind
1053  * @tc.type: FUNC
1054  */
1055 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_DWARF_PROCESS, TestSize.Level1)
1056 {
1057     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 500 -s dwarf", true, false);
1058     std::string fileName = TEST_FILE;
1059     size_t fileSize = GetFileSize(fileName.c_str());
1060     EXPECT_LE(fileSize, TEST_SIZE_F500_DWARF_PROCESS);
1061 }
1062 
1063 /**
1064  * @tc.name: FileSizeOnFrequency1000_DWARF_PROCESS
1065  * @tc.desc: Test size of file generated under one process frequency 1000 and dwarf unwind
1066  * @tc.type: FUNC
1067  */
1068 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_DWARF_PROCESS, TestSize.Level1)
1069 {
1070     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 1000 -s dwarf", true, false);
1071     std::string fileName = TEST_FILE;
1072     size_t fileSize = GetFileSize(fileName.c_str());
1073     EXPECT_LE(fileSize, TEST_SIZE_F1000_DWARF_PROCESS);
1074 }
1075 
1076 /**
1077  * @tc.name: FileSizeOnFrequency2000_DWARF_PROCESS
1078  * @tc.desc: Test size of file generated under one process frequency 2000 and dwarf unwind
1079  * @tc.type: FUNC
1080  */
1081 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_DWARF_PROCESS, TestSize.Level1)
1082 {
1083     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 2000 -s dwarf", true, false);
1084     std::string fileName = TEST_FILE;
1085     size_t fileSize = GetFileSize(fileName.c_str());
1086     EXPECT_LE(fileSize, TEST_SIZE_F2000_DWARF_PROCESS);
1087 }
1088 
1089 /**
1090  * @tc.name: FileSizeOnFrequency4000_DWARF_PROCESS
1091  * @tc.desc: Test size of file generated under one process frequency 4000 and dwarf unwind
1092  * @tc.type: FUNC
1093  */
1094 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_DWARF_PROCESS, TestSize.Level1)
1095 {
1096     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 4000 -s dwarf", true, false);
1097     std::string fileName = TEST_FILE;
1098     size_t fileSize = GetFileSize(fileName.c_str());
1099     EXPECT_LE(fileSize, TEST_SIZE_F4000_DWARF_PROCESS);
1100 }
1101 
1102 /**
1103  * @tc.name: FileSizeOnFrequency8000_DWARF_PROCESS
1104  * @tc.desc: Test size of file generated under one process frequency 8000 and dwarf unwind
1105  * @tc.type: FUNC
1106  */
1107 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_DWARF_PROCESS, TestSize.Level1)
1108 {
1109     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 8000 -s dwarf", true, false);
1110     std::string fileName = TEST_FILE;
1111     size_t fileSize = GetFileSize(fileName.c_str());
1112     EXPECT_LE(fileSize, TEST_SIZE_F8000_DWARF_PROCESS);
1113 }
1114 
1115 /**
1116  * @tc.name: FileSizeOnFrequency100_FP_PROCESS
1117  * @tc.desc: Test size of file generated under one process frequency 100 and fp unwind
1118  * @tc.type: FUNC
1119  */
1120 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency100_FP_PROCESS, TestSize.Level1)
1121 {
1122     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 100 -s fp", true, false);
1123     std::string fileName = TEST_FILE;
1124     size_t fileSize = GetFileSize(fileName.c_str());
1125     EXPECT_LE(fileSize, TEST_SIZE_F100_FP_PROCESS);
1126 }
1127 
1128 /**
1129  * @tc.name: FileSizeOnFrequency500_FP_PROCESS
1130  * @tc.desc: Test size of file generated under one process frequency 500 and fp unwind
1131  * @tc.type: FUNC
1132  */
1133 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency500_FP_PROCESS, TestSize.Level1)
1134 {
1135     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 500 -s fp", true, false);
1136     std::string fileName = TEST_FILE;
1137     size_t fileSize = GetFileSize(fileName.c_str());
1138     EXPECT_LE(fileSize, TEST_SIZE_F500_FP_PROCESS);
1139 }
1140 
1141 /**
1142  * @tc.name: FileSizeOnFrequency1000_FP_PROCESS
1143  * @tc.desc: Test size of file generated under one process frequency 1000 and fp unwind
1144  * @tc.type: FUNC
1145  */
1146 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency1000_FP_PROCESS, TestSize.Level1)
1147 {
1148     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 1000 -s fp", true, false);
1149     std::string fileName = TEST_FILE;
1150     size_t fileSize = GetFileSize(fileName.c_str());
1151     EXPECT_LE(fileSize, TEST_SIZE_F1000_FP_PROCESS);
1152 }
1153 
1154 /**
1155  * @tc.name: FileSizeOnFrequency2000_FP_PROCESS
1156  * @tc.desc: Test size of file generated under one process frequency 2000 and fp unwind
1157  * @tc.type: FUNC
1158  */
1159 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency2000_FP_PROCESS, TestSize.Level1)
1160 {
1161     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 2000 -s fp", true, false);
1162     std::string fileName = TEST_FILE;
1163     size_t fileSize = GetFileSize(fileName.c_str());
1164     EXPECT_LE(fileSize, TEST_SIZE_F2000_FP_PROCESS);
1165 }
1166 
1167 /**
1168  * @tc.name: FileSizeOnFrequency4000_FP_PROCESS
1169  * @tc.desc: Test size of file generated under one process frequency 4000 and fp unwind
1170  * @tc.type: FUNC
1171  */
1172 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency4000_FP_PROCESS, TestSize.Level1)
1173 {
1174     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 4000 -s fp", true, false);
1175     std::string fileName = TEST_FILE;
1176     size_t fileSize = GetFileSize(fileName.c_str());
1177     EXPECT_LE(fileSize, TEST_SIZE_F4000_FP_PROCESS);
1178 }
1179 
1180 /**
1181  * @tc.name: FileSizeOnFrequency8000_FP_PROCESS
1182  * @tc.desc: Test size of file generated under one process frequency 8000 and fp unwind
1183  * @tc.type: FUNC
1184  */
1185 HWTEST_F(SubCommandRecordTest, FileSizeOnFrequency8000_FP_PROCESS, TestSize.Level1)
1186 {
1187     ForkAndRunTest("-d 10 --app com.ohos.systemui -f 8000 -s fp", true, false);
1188     std::string fileName = TEST_FILE;
1189     size_t fileSize = GetFileSize(fileName.c_str());
1190     EXPECT_LE(fileSize, TEST_SIZE_F8000_FP_PROCESS);
1191 }
1192 
1193 /**
1194  * @tc.name: ExcludeThreadName
1195  * @tc.desc: Test --exclude-thread option sucess
1196  * @tc.type: FUNC
1197  */
1198 HWTEST_F(SubCommandRecordTest, ExcludeThreadName, TestSize.Level1)
1199 {
1200     ForkAndRunTest("-d 2 --exclude-thread DfxWatchdog ", true);
1201 }
1202 
1203 /**
1204  * @tc.name: ExcludeThreadNames
1205  * @tc.desc: Test --exclude-thread option multi threads
1206  * @tc.type: FUNC
1207  */
1208 HWTEST_F(SubCommandRecordTest, ExcludeThreadNames, TestSize.Level1)
1209 {
1210     ForkAndRunTest("-d 2 --exclude-thread DfxWatchdog,GC_WorkerThread ", true);
1211 }
1212 
1213 /**
1214  * @tc.name: ExcludeErrorThreadName
1215  * @tc.desc: Test --exclude-thread option error thread name
1216  * @tc.type: FUNC
1217  */
1218 HWTEST_F(SubCommandRecordTest, ExcludeErrorThreadName, TestSize.Level1)
1219 {
1220     ForkAndRunTest("-d 2 --exclude-thread test ", true);
1221 }
1222 
1223 /**
1224  * @tc.name: ExcludeErrorThreadNames
1225  * @tc.desc: Test --exclude-thread option multi error thread names
1226  * @tc.type: FUNC
1227  */
1228 HWTEST_F(SubCommandRecordTest, ExcludeErrorThreadNames, TestSize.Level1)
1229 {
1230     ForkAndRunTest("-d 2 --exclude-thread test1,test2 ", true);
1231 }
1232 
1233 /**
1234  * @tc.name: ExcludeMixedThreadName
1235  * @tc.desc: Test --exclude-thread option mixed correct name and error name
1236  * @tc.type: FUNC
1237  */
1238 HWTEST_F(SubCommandRecordTest, ExcludeMixedThreadName, TestSize.Level1)
1239 {
1240     ForkAndRunTest("-d 2 --exclude-thread DfxWatchdog,test ", true);
1241 }
1242 
1243 // --restart
1244 HWTEST_F(SubCommandRecordTest, ReStartNotApp1, TestSize.Level1)
1245 {
1246     TestRecordCommand("-p 5 --restart ", false, false);
1247 }
1248 
1249 HWTEST_F(SubCommandRecordTest, ReStartNotApp2, TestSize.Level1)
1250 {
1251     TestRecordCommand("-a --restart ", false, false);
1252 }
1253 
1254 HWTEST_F(SubCommandRecordTest, ReStartNotApp3, TestSize.Level1)
1255 {
1256     TestRecordCommand("-p 5 -a --restart ", false, false);
1257 }
1258 
1259 HWTEST_F(SubCommandRecordTest, ReStartConflict, TestSize.Level1)
1260 {
1261     TestRecordCommand("--restart -a ", false, true);
1262 }
1263 
1264 HWTEST_F(SubCommandRecordTest, ReStart, TestSize.Level1)
1265 {
1266     TestRecordCommand("--restart ", false, true);
1267 }
1268 
1269 // --exclude-tid
1270 HWTEST_F(SubCommandRecordTest, ExcludeTidConflict, TestSize.Level1)
1271 {
1272     TestRecordCommand("--exclude-tid 5 --exclude-thread test ", false, true);
1273 }
1274 
1275 /**
1276  * @tc.name: CmdLinesSizeSucess
1277  * @tc.desc: Test --cmdline-size option
1278  * @tc.type: FUNC
1279  */
1280 HWTEST_F(SubCommandRecordTest, CmdLinesSizeSucess, TestSize.Level1)
1281 {
1282     ForkAndRunTest("-d 2 --cmdline-size 1024 ", true);
1283 }
1284 
1285 /**
1286  * @tc.name: CmdLinesSizeOutRange
1287  * @tc.desc: Test --cmdline-size option
1288  * @tc.type: FUNC
1289  */
1290 HWTEST_F(SubCommandRecordTest, CmdLinesSizeOutRange, TestSize.Level1)
1291 {
1292     TestRecordCommand("-d 2 --cmdline-size 8192 ", false);
1293 }
1294 
1295 /**
1296  * @tc.name: CmdLinesSizeNotPowerOf2
1297  * @tc.desc: Test --cmdline-size option
1298  * @tc.type: FUNC
1299  */
1300 HWTEST_F(SubCommandRecordTest, CmdLinesSizeNotPowerOf2, TestSize.Level1)
1301 {
1302     TestRecordCommand("-d 2 --cmdline-size 1000 ", false);
1303 }
1304 
1305 /**
1306  * @tc.name: EnableDebugInfoSymbolicFp
1307  * @tc.desc: Test --enable-debuginfo-symbolic option with -s fp
1308  * @tc.type: FUNC
1309  */
1310 HWTEST_F(SubCommandRecordTest, EnableDebugInfoSymbolicFp, TestSize.Level1)
1311 {
1312     ForkAndRunTest("-d 2 -s fp --enable-debuginfo-symbolic ", true);
1313 }
1314 
1315 /**
1316  * @tc.name: EnableDebugInfoSymbolicDwarf
1317  * @tc.desc: Test --enable-debuginfo-symbolic option with -s dwarf
1318  * @tc.type: FUNC
1319  */
1320 HWTEST_F(SubCommandRecordTest, EnableDebugInfoSymbolicDwarf, TestSize.Level1)
1321 {
1322     ForkAndRunTest("-d 2 -s dwarf --enable-debuginfo-symbolic ", true);
1323 }
1324 
1325 /**
1326  * @tc.name: CallChainUserOnlyFp
1327  * @tc.desc: Test --callchain-useronly option with fp
1328  * @tc.type: FUNC
1329  */
1330 HWTEST_F(SubCommandRecordTest, CallChainUserOnlyFp, TestSize.Level1)
1331 {
1332     ForkAndRunTest("-d 2 -s fp --callchain-useronly", true, true);
1333 }
1334 
1335 /**
1336  * @tc.name: CallChainUserOnlyDwarf
1337  * @tc.desc: Test --callchain-useronly option with dwarf
1338  * @tc.type: FUNC
1339  */
1340 HWTEST_F(SubCommandRecordTest, CallChainUserOnlyDwarf, TestSize.Level1)
1341 {
1342     ForkAndRunTest("-d 2 -s dwarf --callchain-useronly", true, true);
1343 }
1344 
1345 /**
1346  * @tc.name: CallChainUserOnlyError
1347  * @tc.desc: Test --callchain-useronly option without fp/dwarf
1348  * @tc.type: FUNC
1349  */
1350 HWTEST_F(SubCommandRecordTest, CallChainUserOnlyError, TestSize.Level1)
1351 {
1352     ForkAndRunTest("-d 2 --callchain-useronly", false, true);
1353 }
1354 
1355 /**
1356  * @tc.name: DedupStack
1357  * @tc.desc: Test --dedup_stack option
1358  * @tc.type: FUNC
1359  */
1360 HWTEST_F(SubCommandRecordTest, DedupStack, TestSize.Level1)
1361 {
1362     ForkAndRunTest("-d 2 -s dwarf --dedup_stack", true, true);
1363 }
1364 
1365 /**
1366  * @tc.name: DedupStackErr
1367  * @tc.desc: Test --dedup_stack option with -a
1368  * @tc.type: FUNC
1369  */
1370 HWTEST_F(SubCommandRecordTest, DedupStackErr, TestSize.Level1)
1371 {
1372     TestRecordCommand("-d 2 -a -s dwarf --dedup_stack", false, false);
1373 }
1374 
1375 /**
1376  * @tc.name: TestNoFork
1377  * @tc.desc: Test no fork
1378  * @tc.type: FUNC
1379  */
1380 HWTEST_F(SubCommandRecordTest, TestNoFork, TestSize.Level1)
1381 {
1382     TestRecordCommand("-d 2 -s dwarf --dedup_stack -f 2000 --cmdline-size 1024", true, true);
1383 }
1384 
1385 /**
1386  * @tc.name: TestAllNoFork
1387  * @tc.desc: Test no fork with -a
1388  * @tc.type: FUNC
1389  */
1390 HWTEST_F(SubCommandRecordTest, TestAllNoFork, TestSize.Level1)
1391 {
1392     TestRecordCommand("-d 2 -a -s dwarf --clockid monotonic --exclude-hiperf", true, false);
1393 }
1394 
1395 /**
1396  * @tc.name: CreateFifoServer
1397  * @tc.desc: Test create Fipo server
1398  * @tc.type: FUNC
1399  */
1400 HWTEST_F(SubCommandRecordTest, CreateFifoServer, TestSize.Level1)
1401 {
1402     SubCommandRecord cmd;
1403     EXPECT_EQ(cmd.CreateFifoServer(), false);
1404 }
1405 
1406 /**
1407  * @tc.name: SendFifoAndWaitReply
1408  * @tc.desc: Test send Fifo and wait reply
1409  * @tc.type: FUNC
1410  */
1411 HWTEST_F(SubCommandRecordTest, SendFifoAndWaitReply, TestSize.Level1)
1412 {
1413     SubCommandRecord cmd;
1414     std::string test = "test";
1415     EXPECT_EQ(cmd.SendFifoAndWaitReply(test, CONTROL_WAITREPY_TOMEOUT), false);
1416 }
1417 
1418 /**
1419  * @tc.name: ReportErr
1420  * @tc.desc: Test report option error
1421  * @tc.type: FUNC
1422  */
1423 HWTEST_F(SubCommandRecordTest, ReportErr, TestSize.Level1)
1424 {
1425     TestRecordCommand("-d 2 -a --report ", false, false);
1426 }
1427 
1428 /**
1429  * @tc.name: TestHasReport
1430  * @tc.desc: Test --report option
1431  * @tc.type: FUNC
1432  */
1433 HWTEST_F(SubCommandRecordTest, TestHasReport, TestSize.Level1)
1434 {
1435     TestRecordCommand("-d 2 -s dwarf --report", true, true);
1436 }
1437 
1438 /**
1439  * @tc.name: TraceCommand
1440  * @tc.desc: Test TraceCommand option
1441  * @tc.type: FUNC
1442  */
1443 HWTEST_F(SubCommandRecordTest, TraceCommand, TestSize.Level1)
1444 {
1445     TestRecordCommand("-d 2 -s dwarf ls", true, false);
1446 }
1447 
1448 /**
1449  * @tc.name: TraceCommandErr
1450  * @tc.desc: Test InvalidCommand option
1451  * @tc.type: FUNC
1452  */
1453 HWTEST_F(SubCommandRecordTest, TraceCommandErr, TestSize.Level1)
1454 {
1455     TestRecordCommand("-d 2 -s dwarf invalidcommand", false, false);
1456 }
1457 } // namespace HiPerf
1458 } // namespace Developtools
1459 } // namespace OHOS
1460