• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #ifndef DFX_TEST_UTIL
17 #define DFX_TEST_UTIL
18 
19 #include <string>
20 #include <vector>
21 
22 static const std::string ACCOUNTMGR_NAME = "accountmgr";
23 static const std::string FOUNDATION_NAME = "foundation";
24 static const std::string APPSPAWN_NAME = "appspawn";
25 
26 #if defined(__arm__)
27 #define REGISTERS           "r0:","r1:","r2:","r3:","r4:","r5:","r6:",\
28                             "r7:","r8:","r9:","r10:","fp:","ip:","sp:","lr:","pc:"
29 #define REGISTERS_NUM       16
30 #define REGISTER_FORMAT_LENGTH    8
31 #elif defined(__aarch64__)
32 #define REGISTERS           "x0:","x1:","x2:","x3:","x4:","x5:","x6:","x7:","x8:",\
33                             "x9:","x10:","x11:","x12:","x13:","x14:","x15:","x16:",\
34                             "x17:","x18:","x19:","x20:","x21:","x22:","x23:","x24:",\
35                             "x25:","x26:","x27:","x28:","x29:","lr:","sp:","pc:"
36 #define REGISTERS_NUM       33
37 #define REGISTER_FORMAT_LENGTH    16
38 #endif
39 
40 namespace OHOS {
41 namespace HiviewDFX {
42 enum CrasherType {
43     CRASHER_C,
44     CRASHER_CPP
45 };
46 std::string ExecuteCommands(const std::string& cmds);
47 bool ExecuteCommands(const std::string& cmds, std::vector<std::string>& ress);
48 int GetProcessPid(const std::string& processName);
49 int LaunchTestHap(const std::string& abilityName, const std::string& bundleName);
50 void StopTestHap(const std::string& bundleName);
51 void InstallTestHap(const std::string& hapName);
52 void UninstallTestHap(const std::string& bundleName);
53 int CountLines(const std::string& fileName);
54 bool CheckProcessComm(int pid, const std::string& name);
55 int CheckKeyWords(const std::string& filePath, std::string *keywords, int length, int minRegIdx);
56 bool CheckContent(const std::string& content, const std::string& keyContent, bool checkExist);
57 int GetKeywordsNum(const std::string& msg, std::string *keywords, int length);
58 std::string GetCppCrashFileName(const pid_t pid);
59 uint32_t GetSelfFdCount();
60 uint32_t GetSelfMapsCount();
61 uint64_t GetSelfMemoryCount();
62 } // namespace HiviewDFX
63 } // namespace OHOS
64 #endif // DFX_TEST_UTIL