• 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 /* This files contains faultlog system test header modules. */
17 
18 #ifndef FAULTLOGGERD_SYSTEM_TEST_H
19 #define FAULTLOGGERD_SYSTEM_TEST_H
20 
21 #if defined(__arm__)
22     #define REGISTERS           "r0:","r1:","r2:","r3:","r4:","r5:","r6:",\
23                                 "r7:","r8:","r9:","r10:","fp:","ip:","sp:","lr:","pc:"
24     #define REGISTERS_NUM       16
25     #define REGISTERS_LENGTH    10
26 #elif defined(__aarch64__)
27     #define REGISTERS           "x0:","x1:","x2:","x3:","x4:","x5:","x6:","x7:","x8:",\
28                                 "x9:","x10:","x11:","x12:","x13:","x14:","x15:","x16:",\
29                                 "x17:","x18:","x19:","x20:","x21:","x22:","x23:","x24:",\
30                                 "x25:","x26:","x27:","x28:","x29:","lr:","sp:","pc:"
31     #define REGISTERS_NUM       33
32     #define REGISTERS_LENGTH    18
33 #endif
34 
35 #include <gtest/gtest.h>
36 #include <map>
37 
38 namespace OHOS {
39 namespace HiviewDFX {
40 
41 static const int ARRAY_SIZE_HUNDRED = 100;
42 
43 class FaultLoggerdSystemTest : public testing::Test {
44 public:
45     static void SetUpTestCase(void);
46     static void TearDownTestCase(void);
47     void SetUp();
48     void TearDown();
49 
50     static std::string GetPidMax();
51     static std::string GetTidMax();
52 
53     static std::string ForkAndRunCommands(const std::vector<std::string>& cmds, int commandStatus);
54     static std::string ForkAndCommands(int crasherType, int udid);
55 
56     static std::string ProcessDumpCommands(const std::string cmds);
57     static std::string GetfileNamePrefix(const std::string errorCMD, int commandStatus);
58     static std::string GetstackfileNamePrefix(const std::string errorCMD, int commandStatus);
59 
60     static int CountLines(std::string filename);
61     static bool IsDigit(std::string pid);
62 
63     static int CheckKeywords(std::string& filePath, std::string *keywords, int length, int minRegIdx);
64     static int CheckCountNum(std::string& filePath, std::string& pid, std::string& errorCMD);
65     static int CheckCountNumAbort(std::string& filePath, std::string& pid);
66     static int CheckCountNumPCZero(std::string& filePath, std::string& pid);
67     static int CheckStacktraceCountNum(std::string& filePath, std::string& pid);
68     static int CheckCountNumMultiThread(std::string& filePath, std::string& pid);
69     static int CheckCountNumOverStack(std::string& filePath, std::string& pid);
70     static int CheckCountNumStackTop(std::string& filePath, std::string& pid, std::string& ErrorCMD);
71     static std::string GetStackTop();
72     static int CheckCountNumKill11(std::string& filePath, std::string& pid);
73     static void Trim(std::string& str);
74 
75     static void StartCrasherLoop(int type);     // 1. system; 2. root; 3.app; 4. root+cpp
76     static void KillCrasherLoopForSomeCase(int type);
77     static void StartCrasherLoopForUnsingPidAndTid(int crasherType);    // 1.c 2.c++
78     static int crashThread(int threadID);
79     static int getApplyPid(std::string applyName);
80     static std::string GetCmdResultFromPopen(const std::string& cmd);
81     static int GetServicePid(const std::string& serviceName);
82     static int LaunchTestHap(const std::string& abilityName, const std::string& bundleName);
83     static void dumpCatchThread(int threadID);
84 
85     static std::string rootTid[ARRAY_SIZE_HUNDRED];
86     static std::string appTid[ARRAY_SIZE_HUNDRED];
87     static std::string sysTid[ARRAY_SIZE_HUNDRED];
88     static std::string testTid[ARRAY_SIZE_HUNDRED];
89 
90     static int loopSysPid;
91     static int loopRootPid;
92     static int loopCppPid;
93     static int loopAppPid;
94 
95     static char resultBufShell[ARRAY_SIZE_HUNDRED];
96     static int appTidCount;
97     static int rootTidCount;
98     static int sysTidCount;
99     static unsigned int unsigLoopSysPid;
100     static int count;
101 };
102 } // namespace HiviewDFX
103 } // namespace OHOS
104 #endif // FAULTLOGGERD_SYSTEM_TEST_H
105