1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License.
5800b99b8Sopenharmony_ci * You may obtain a copy of the License at
6800b99b8Sopenharmony_ci *
7800b99b8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8800b99b8Sopenharmony_ci *
9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and
13800b99b8Sopenharmony_ci * limitations under the License.
14800b99b8Sopenharmony_ci */
15800b99b8Sopenharmony_ci
16800b99b8Sopenharmony_ci#include <fstream>
17800b99b8Sopenharmony_ci#include <gtest/gtest.h>
18800b99b8Sopenharmony_ci#include <securec.h>
19800b99b8Sopenharmony_ci#include <string>
20800b99b8Sopenharmony_ci#include <thread>
21800b99b8Sopenharmony_ci#include <unistd.h>
22800b99b8Sopenharmony_ci#include <vector>
23800b99b8Sopenharmony_ci
24800b99b8Sopenharmony_ci#include "dfx_dump_catcher.h"
25800b99b8Sopenharmony_ci#include "dfx_test_util.h"
26800b99b8Sopenharmony_ci#include "file_util.h"
27800b99b8Sopenharmony_ci#include "procinfo.h"
28800b99b8Sopenharmony_ci
29800b99b8Sopenharmony_ciusing namespace testing::ext;
30800b99b8Sopenharmony_ciusing namespace std;
31800b99b8Sopenharmony_ci
32800b99b8Sopenharmony_cinamespace OHOS {
33800b99b8Sopenharmony_cinamespace HiviewDFX {
34800b99b8Sopenharmony_ciclass DumpCatcherSystemTest : public testing::Test {
35800b99b8Sopenharmony_cipublic:
36800b99b8Sopenharmony_ci    static void SetUpTestCase(void);
37800b99b8Sopenharmony_ci    static void TearDownTestCase(void);
38800b99b8Sopenharmony_ci    void SetUp();
39800b99b8Sopenharmony_ci    void TearDown();
40800b99b8Sopenharmony_ci};
41800b99b8Sopenharmony_ci
42800b99b8Sopenharmony_civoid DumpCatcherSystemTest::SetUpTestCase(void)
43800b99b8Sopenharmony_ci{
44800b99b8Sopenharmony_ci    chmod("/data/crasher_c", 0755); // 0755 : -rwxr-xr-x
45800b99b8Sopenharmony_ci    chmod("/data/crasher_cpp", 0755); // 0755 : -rwxr-xr-x
46800b99b8Sopenharmony_ci}
47800b99b8Sopenharmony_ci
48800b99b8Sopenharmony_civoid DumpCatcherSystemTest::TearDownTestCase(void)
49800b99b8Sopenharmony_ci{
50800b99b8Sopenharmony_ci}
51800b99b8Sopenharmony_ci
52800b99b8Sopenharmony_civoid DumpCatcherSystemTest::SetUp(void)
53800b99b8Sopenharmony_ci{
54800b99b8Sopenharmony_ci}
55800b99b8Sopenharmony_ci
56800b99b8Sopenharmony_civoid DumpCatcherSystemTest::TearDown(void)
57800b99b8Sopenharmony_ci{
58800b99b8Sopenharmony_ci}
59800b99b8Sopenharmony_ci
60800b99b8Sopenharmony_cinamespace {
61800b99b8Sopenharmony_cistatic const int ROOT_UID = 0;
62800b99b8Sopenharmony_cistatic const int BMS_UID = 1000;
63800b99b8Sopenharmony_cistatic const int OTHER_UID = 10000;
64800b99b8Sopenharmony_ci
65800b99b8Sopenharmony_cistatic const int MULTITHREAD_TEST_COUNT = 50;
66800b99b8Sopenharmony_cistatic const int ARRAY_SIZE = 100;
67800b99b8Sopenharmony_cistatic pid_t g_rootTid[ARRAY_SIZE] = { -1 };
68800b99b8Sopenharmony_cistatic pid_t g_appTid[ARRAY_SIZE] = { -1 };
69800b99b8Sopenharmony_cistatic pid_t g_sysTid[ARRAY_SIZE] = { -1 };
70800b99b8Sopenharmony_ci
71800b99b8Sopenharmony_cistatic pid_t g_loopSysPid = 0;
72800b99b8Sopenharmony_cistatic pid_t g_loopRootPid = 0;
73800b99b8Sopenharmony_cistatic pid_t g_loopCppPid = 0;
74800b99b8Sopenharmony_cistatic pid_t g_loopAppPid = 0;
75800b99b8Sopenharmony_cistatic unsigned int g_unsignedLoopSysPid = 0;
76800b99b8Sopenharmony_cistatic int g_checkCnt = 0;
77800b99b8Sopenharmony_ci
78800b99b8Sopenharmony_cienum CrasherRunType {
79800b99b8Sopenharmony_ci    ROOT,           // rus as root uid
80800b99b8Sopenharmony_ci    SYSTEM,         // run as system uid
81800b99b8Sopenharmony_ci    APP_CRASHER_C,  // crasher_c run as app uid
82800b99b8Sopenharmony_ci    APP_CRASHER_CPP // crasher_cpp run as app uid
83800b99b8Sopenharmony_ci};
84800b99b8Sopenharmony_ci}
85800b99b8Sopenharmony_ci
86800b99b8Sopenharmony_cistatic string GetPidMax()
87800b99b8Sopenharmony_ci{
88800b99b8Sopenharmony_ci    const string defaultPidMax = "32768"; // 32768 pid max
89800b99b8Sopenharmony_ci    const string path = "/proc/sys/kernel/pid_max";
90800b99b8Sopenharmony_ci    string pidMax = defaultPidMax;
91800b99b8Sopenharmony_ci    OHOS::HiviewDFX::LoadStringFromFile(path, pidMax);
92800b99b8Sopenharmony_ci    return pidMax;
93800b99b8Sopenharmony_ci}
94800b99b8Sopenharmony_ci
95800b99b8Sopenharmony_cistatic string GetTidMax()
96800b99b8Sopenharmony_ci{
97800b99b8Sopenharmony_ci    const string defaultTidMax = "8825"; // 8825 tid max
98800b99b8Sopenharmony_ci    const string path = "/proc/sys/kernel/threads-max";
99800b99b8Sopenharmony_ci    string tidMax = defaultTidMax;
100800b99b8Sopenharmony_ci    OHOS::HiviewDFX::LoadStringFromFile(path, tidMax);
101800b99b8Sopenharmony_ci    return tidMax;
102800b99b8Sopenharmony_ci}
103800b99b8Sopenharmony_ci
104800b99b8Sopenharmony_cistatic void GetCrasherThreads(const int pid, const int uid)
105800b99b8Sopenharmony_ci{
106800b99b8Sopenharmony_ci    if (pid <= 0) {
107800b99b8Sopenharmony_ci        return;
108800b99b8Sopenharmony_ci    }
109800b99b8Sopenharmony_ci
110800b99b8Sopenharmony_ci    usleep(5); // 5 : sleep 5us
111800b99b8Sopenharmony_ci    std::vector<int> tids;
112800b99b8Sopenharmony_ci    if (!GetTidsByPidWithFunc(pid, tids, nullptr)) {
113800b99b8Sopenharmony_ci        return;
114800b99b8Sopenharmony_ci    }
115800b99b8Sopenharmony_ci    for (size_t i = 0; i < tids.size(); ++i) {
116800b99b8Sopenharmony_ci        if (uid == ROOT_UID) {
117800b99b8Sopenharmony_ci            g_rootTid[i] = tids[i];
118800b99b8Sopenharmony_ci        } else if (uid == BMS_UID) {
119800b99b8Sopenharmony_ci            g_sysTid[i] = tids[i];
120800b99b8Sopenharmony_ci        } else {
121800b99b8Sopenharmony_ci            g_appTid[i] = tids[i];
122800b99b8Sopenharmony_ci        }
123800b99b8Sopenharmony_ci    }
124800b99b8Sopenharmony_ci}
125800b99b8Sopenharmony_ci
126800b99b8Sopenharmony_cistatic void StartCrasherLoopForUnsignedPidAndTid(const CrasherType type)
127800b99b8Sopenharmony_ci{
128800b99b8Sopenharmony_ci    setuid(BMS_UID);
129800b99b8Sopenharmony_ci    if (type == CRASHER_C) {
130800b99b8Sopenharmony_ci        system("/data/crasher_c thread-Loop &");
131800b99b8Sopenharmony_ci    } else {
132800b99b8Sopenharmony_ci        system("/data/crasher_cpp thread-Loop &");
133800b99b8Sopenharmony_ci    }
134800b99b8Sopenharmony_ci    string procCmd = "pgrep 'crasher'";
135800b99b8Sopenharmony_ci    std::string shellRes = ExecuteCommands(procCmd);
136800b99b8Sopenharmony_ci    if (shellRes.empty()) {
137800b99b8Sopenharmony_ci        exit(1);
138800b99b8Sopenharmony_ci    }
139800b99b8Sopenharmony_ci    g_unsignedLoopSysPid = atoi(shellRes.c_str());
140800b99b8Sopenharmony_ci    if (g_unsignedLoopSysPid == 0) {
141800b99b8Sopenharmony_ci        exit(0);
142800b99b8Sopenharmony_ci    }
143800b99b8Sopenharmony_ci
144800b99b8Sopenharmony_ci    GetCrasherThreads(g_unsignedLoopSysPid, BMS_UID);
145800b99b8Sopenharmony_ci}
146800b99b8Sopenharmony_ci
147800b99b8Sopenharmony_cistatic void LaunchCrasher(const CrasherType type, const int uid)
148800b99b8Sopenharmony_ci{
149800b99b8Sopenharmony_ci    setuid(uid);
150800b99b8Sopenharmony_ci    if (type == CRASHER_C) {
151800b99b8Sopenharmony_ci        system("/data/crasher_c thread-Loop &");
152800b99b8Sopenharmony_ci    } else {
153800b99b8Sopenharmony_ci        system("/data/crasher_cpp thread-Loop &");
154800b99b8Sopenharmony_ci    }
155800b99b8Sopenharmony_ci
156800b99b8Sopenharmony_ci    string procCmd = "pgrep 'crasher'";
157800b99b8Sopenharmony_ci    std::vector<std::string> ress;
158800b99b8Sopenharmony_ci    ExecuteCommands(procCmd, ress);
159800b99b8Sopenharmony_ci    if (ress.empty()) {
160800b99b8Sopenharmony_ci        exit(0);
161800b99b8Sopenharmony_ci    }
162800b99b8Sopenharmony_ci
163800b99b8Sopenharmony_ci    pid_t curPid = 0;
164800b99b8Sopenharmony_ci    for (size_t i = 0; i < ress.size(); ++i) {
165800b99b8Sopenharmony_ci        pid_t pid = atoi(ress[i].c_str());
166800b99b8Sopenharmony_ci        if (pid <= 0) {
167800b99b8Sopenharmony_ci            continue;
168800b99b8Sopenharmony_ci        }
169800b99b8Sopenharmony_ci
170800b99b8Sopenharmony_ci        if (uid == ROOT_UID) {
171800b99b8Sopenharmony_ci            if (g_loopSysPid == pid) {
172800b99b8Sopenharmony_ci                continue;
173800b99b8Sopenharmony_ci            }
174800b99b8Sopenharmony_ci            if (type == CRASHER_CPP) {
175800b99b8Sopenharmony_ci                g_loopCppPid = pid;
176800b99b8Sopenharmony_ci            } else {
177800b99b8Sopenharmony_ci                g_loopRootPid = pid;
178800b99b8Sopenharmony_ci            }
179800b99b8Sopenharmony_ci            curPid = g_loopRootPid;
180800b99b8Sopenharmony_ci            GTEST_LOG_(INFO) << "Root ID: " << g_loopRootPid;
181800b99b8Sopenharmony_ci        } else if (uid == BMS_UID) {
182800b99b8Sopenharmony_ci            g_loopSysPid = pid;
183800b99b8Sopenharmony_ci            curPid = g_loopSysPid;
184800b99b8Sopenharmony_ci            GTEST_LOG_(INFO) << "System ID: " << g_loopSysPid;
185800b99b8Sopenharmony_ci        } else {
186800b99b8Sopenharmony_ci            if ((g_loopSysPid == pid) || (g_loopRootPid == pid)) {
187800b99b8Sopenharmony_ci                continue;
188800b99b8Sopenharmony_ci            } else {
189800b99b8Sopenharmony_ci                g_loopAppPid = pid;
190800b99b8Sopenharmony_ci            }
191800b99b8Sopenharmony_ci            curPid = g_loopAppPid;
192800b99b8Sopenharmony_ci            GTEST_LOG_(INFO) << "APP ID: " << g_loopAppPid;
193800b99b8Sopenharmony_ci        }
194800b99b8Sopenharmony_ci    }
195800b99b8Sopenharmony_ci    GetCrasherThreads(curPid, uid);
196800b99b8Sopenharmony_ci}
197800b99b8Sopenharmony_ci
198800b99b8Sopenharmony_cistatic void StartCrasherLoop(const CrasherRunType type)
199800b99b8Sopenharmony_ci{
200800b99b8Sopenharmony_ci    switch (type) {
201800b99b8Sopenharmony_ci        case ROOT:
202800b99b8Sopenharmony_ci            LaunchCrasher(CRASHER_C, ROOT_UID);
203800b99b8Sopenharmony_ci            break;
204800b99b8Sopenharmony_ci        case SYSTEM:
205800b99b8Sopenharmony_ci            LaunchCrasher(CRASHER_C, BMS_UID);
206800b99b8Sopenharmony_ci            break;
207800b99b8Sopenharmony_ci        case APP_CRASHER_C:
208800b99b8Sopenharmony_ci            LaunchCrasher(CRASHER_C, OTHER_UID);
209800b99b8Sopenharmony_ci            break;
210800b99b8Sopenharmony_ci        case APP_CRASHER_CPP:
211800b99b8Sopenharmony_ci            LaunchCrasher(CRASHER_CPP, OTHER_UID);
212800b99b8Sopenharmony_ci            break;
213800b99b8Sopenharmony_ci        default:
214800b99b8Sopenharmony_ci            return;
215800b99b8Sopenharmony_ci    }
216800b99b8Sopenharmony_ci    setuid(OTHER_UID);
217800b99b8Sopenharmony_ci}
218800b99b8Sopenharmony_ci
219800b99b8Sopenharmony_cistatic void StopCrasherLoop(const CrasherRunType type)
220800b99b8Sopenharmony_ci{
221800b99b8Sopenharmony_ci    switch (type) {
222800b99b8Sopenharmony_ci        case ROOT:
223800b99b8Sopenharmony_ci            setuid(ROOT_UID);
224800b99b8Sopenharmony_ci            system(("kill -9 " + to_string(g_loopRootPid)).c_str());
225800b99b8Sopenharmony_ci            break;
226800b99b8Sopenharmony_ci        case SYSTEM:
227800b99b8Sopenharmony_ci            setuid(BMS_UID);
228800b99b8Sopenharmony_ci            system(("kill -9 " + to_string(g_loopSysPid)).c_str());
229800b99b8Sopenharmony_ci            break;
230800b99b8Sopenharmony_ci        case APP_CRASHER_C:
231800b99b8Sopenharmony_ci            setuid(ROOT_UID);
232800b99b8Sopenharmony_ci            system(("kill -9 " + to_string(g_loopAppPid)).c_str());
233800b99b8Sopenharmony_ci            break;
234800b99b8Sopenharmony_ci        case APP_CRASHER_CPP:
235800b99b8Sopenharmony_ci            setuid(BMS_UID);
236800b99b8Sopenharmony_ci            system(("kill -9 " + to_string(g_unsignedLoopSysPid)).c_str());
237800b99b8Sopenharmony_ci            break;
238800b99b8Sopenharmony_ci        default:
239800b99b8Sopenharmony_ci            break;
240800b99b8Sopenharmony_ci    }
241800b99b8Sopenharmony_ci}
242800b99b8Sopenharmony_ci
243800b99b8Sopenharmony_ci/**
244800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest001
245800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(app), TID(0)
246800b99b8Sopenharmony_ci * @tc.type: FUNC
247800b99b8Sopenharmony_ci */
248800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest001, TestSize.Level2)
249800b99b8Sopenharmony_ci{
250800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest001: start.";
251800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
252800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
253800b99b8Sopenharmony_ci    string msg = "";
254800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "appPid: " << g_loopAppPid;
255800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, 0, msg);
256800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
257800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
258800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest001 Failed";
259800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
260800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest001: end.";
261800b99b8Sopenharmony_ci}
262800b99b8Sopenharmony_ci
263800b99b8Sopenharmony_ci/**
264800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest002
265800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(app), TID(PID)
266800b99b8Sopenharmony_ci * @tc.type: FUNC
267800b99b8Sopenharmony_ci */
268800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest002, TestSize.Level2)
269800b99b8Sopenharmony_ci{
270800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest002: start.";
271800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
272800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
273800b99b8Sopenharmony_ci    string msg = "";
274800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, g_loopAppPid, msg);
275800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
276800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest002 Failed";
277800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
278800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest002: end.";
279800b99b8Sopenharmony_ci}
280800b99b8Sopenharmony_ci
281800b99b8Sopenharmony_ci/**
282800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest003
283800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(app), TID(<>PID)
284800b99b8Sopenharmony_ci * @tc.type: FUNC
285800b99b8Sopenharmony_ci */
286800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest003, TestSize.Level2)
287800b99b8Sopenharmony_ci{
288800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest003: start.";
289800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
290800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
291800b99b8Sopenharmony_ci    string msg = "";
292800b99b8Sopenharmony_ci    int tid = g_appTid[0];
293800b99b8Sopenharmony_ci    if (g_loopAppPid == g_appTid[0]) {
294800b99b8Sopenharmony_ci        tid = g_appTid[1];
295800b99b8Sopenharmony_ci    }
296800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, tid, msg);
297800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest003 Failed";
298800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
299800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest003: end.";
300800b99b8Sopenharmony_ci}
301800b99b8Sopenharmony_ci
302800b99b8Sopenharmony_ci/**
303800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest004
304800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(system), TID(0)
305800b99b8Sopenharmony_ci * @tc.type: FUNC
306800b99b8Sopenharmony_ci */
307800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest004, TestSize.Level2)
308800b99b8Sopenharmony_ci{
309800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest004: start.";
310800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
311800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
312800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
313800b99b8Sopenharmony_ci    string msg = "";
314800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopSysPid, 0, msg);
315800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
316800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
317800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest004 Failed";
318800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
319800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
320800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest004: end.";
321800b99b8Sopenharmony_ci}
322800b99b8Sopenharmony_ci
323800b99b8Sopenharmony_ci/**
324800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest005
325800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(root), TID(0)
326800b99b8Sopenharmony_ci * @tc.type: FUNC
327800b99b8Sopenharmony_ci */
328800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest005, TestSize.Level2)
329800b99b8Sopenharmony_ci{
330800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest005: start.";
331800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
332800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
333800b99b8Sopenharmony_ci    setuid(OTHER_UID);
334800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
335800b99b8Sopenharmony_ci    string msg = "";
336800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopRootPid, 0, msg);
337800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
338800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
339800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest005 Failed";
340800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
341800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
342800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest005: end.";
343800b99b8Sopenharmony_ci}
344800b99b8Sopenharmony_ci
345800b99b8Sopenharmony_ci/**
346800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest006
347800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(9999), TID(0)
348800b99b8Sopenharmony_ci * @tc.type: FUNC
349800b99b8Sopenharmony_ci */
350800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest006, TestSize.Level2)
351800b99b8Sopenharmony_ci{
352800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest006: start.";
353800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
354800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
355800b99b8Sopenharmony_ci    string msg = "";
356800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(9999, 0, msg);
357800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
358800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
359800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest006 Failed";
360800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
361800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest006: end.";
362800b99b8Sopenharmony_ci}
363800b99b8Sopenharmony_ci
364800b99b8Sopenharmony_ci/**
365800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest007
366800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(app), TID(9999)
367800b99b8Sopenharmony_ci * @tc.type: FUNC
368800b99b8Sopenharmony_ci */
369800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest007, TestSize.Level2)
370800b99b8Sopenharmony_ci{
371800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest007: start.";
372800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
373800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
374800b99b8Sopenharmony_ci    string msg = "";
375800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, 9999, msg);
376800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
377800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
378800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest007 Failed";
379800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
380800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest007: end.";
381800b99b8Sopenharmony_ci}
382800b99b8Sopenharmony_ci
383800b99b8Sopenharmony_ci/**
384800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest008
385800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(app), TID(system)
386800b99b8Sopenharmony_ci * @tc.type: FUNC
387800b99b8Sopenharmony_ci */
388800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest008, TestSize.Level2)
389800b99b8Sopenharmony_ci{
390800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest008 start.";
391800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
392800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
393800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
394800b99b8Sopenharmony_ci    string msg = "";
395800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, g_loopSysPid, msg);
396800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
397800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
398800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest008 Failed";
399800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
400800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
401800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest008: end.";
402800b99b8Sopenharmony_ci}
403800b99b8Sopenharmony_ci
404800b99b8Sopenharmony_ci/**
405800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest009
406800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(0), TID(app)
407800b99b8Sopenharmony_ci * @tc.type: FUNC
408800b99b8Sopenharmony_ci */
409800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest009, TestSize.Level2)
410800b99b8Sopenharmony_ci{
411800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest009 start.";
412800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
413800b99b8Sopenharmony_ci    setuid(OTHER_UID);
414800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
415800b99b8Sopenharmony_ci    string msg = "";
416800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(0, g_loopAppPid, msg);
417800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
418800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
419800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest009 Failed";
420800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
421800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest009: end.";
422800b99b8Sopenharmony_ci}
423800b99b8Sopenharmony_ci
424800b99b8Sopenharmony_ci/**
425800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest010
426800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: PID(-11), TID(0)
427800b99b8Sopenharmony_ci * @tc.type: FUNC
428800b99b8Sopenharmony_ci */
429800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest010, TestSize.Level2)
430800b99b8Sopenharmony_ci{
431800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest010 start.";
432800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
433800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
434800b99b8Sopenharmony_ci    string msg = "";
435800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(-11, 0, msg);
436800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
437800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
438800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest010 Failed";
439800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
440800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest010: end.";
441800b99b8Sopenharmony_ci}
442800b99b8Sopenharmony_ci
443800b99b8Sopenharmony_ci/**
444800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest011
445800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: PID(root), TID(-11)
446800b99b8Sopenharmony_ci * @tc.type: FUNC
447800b99b8Sopenharmony_ci */
448800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest011, TestSize.Level2)
449800b99b8Sopenharmony_ci{
450800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest011 start.";
451800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
452800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
453800b99b8Sopenharmony_ci    string msg = "";
454800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopRootPid, -11, msg);
455800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
456800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
457800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest011 Failed";
458800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
459800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest011: end.";
460800b99b8Sopenharmony_ci}
461800b99b8Sopenharmony_ci
462800b99b8Sopenharmony_ci/**
463800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest012
464800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: system PID(system), TID(0)
465800b99b8Sopenharmony_ci * @tc.type: FUNC
466800b99b8Sopenharmony_ci */
467800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest012, TestSize.Level2)
468800b99b8Sopenharmony_ci{
469800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest012: start.";
470800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
471800b99b8Sopenharmony_ci    setuid(BMS_UID);
472800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
473800b99b8Sopenharmony_ci    string msg = "";
474800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopSysPid, 0, msg);
475800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "g_loopSysPid : \n" << g_loopSysPid;
476800b99b8Sopenharmony_ci    string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
477800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopSysPid) + ", Name:crasher";
478800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
479800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
480800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
481800b99b8Sopenharmony_ci    setuid(OTHER_UID);
482800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest012 Failed";
483800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
484800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest012: end.";
485800b99b8Sopenharmony_ci}
486800b99b8Sopenharmony_ci
487800b99b8Sopenharmony_ci/**
488800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest013
489800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: root PID(root), TID(0)
490800b99b8Sopenharmony_ci * @tc.type: FUNC
491800b99b8Sopenharmony_ci */
492800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest013, TestSize.Level2)
493800b99b8Sopenharmony_ci{
494800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest013: start.";
495800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
496800b99b8Sopenharmony_ci    setuid(ROOT_UID);
497800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
498800b99b8Sopenharmony_ci    string msg = "";
499800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopRootPid, 0, msg);
500800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "g_loopRootPid : \n" << g_loopRootPid;
501800b99b8Sopenharmony_ci    string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
502800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopRootPid) + ", Name:crasher";
503800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
504800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
505800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
506800b99b8Sopenharmony_ci    setuid(OTHER_UID);
507800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest013 Failed";
508800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
509800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest013: end.";
510800b99b8Sopenharmony_ci}
511800b99b8Sopenharmony_ci
512800b99b8Sopenharmony_ci/**
513800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest014
514800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: system PID(app), TID(0)
515800b99b8Sopenharmony_ci * @tc.type: FUNC
516800b99b8Sopenharmony_ci */
517800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest014, TestSize.Level2)
518800b99b8Sopenharmony_ci{
519800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest014: start.";
520800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
521800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
522800b99b8Sopenharmony_ci    setuid(BMS_UID);
523800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
524800b99b8Sopenharmony_ci    string msg = "";
525800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, 0, msg);
526800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
527800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
528800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "g_loopAppPid : \n" << g_loopAppPid;
529800b99b8Sopenharmony_ci    string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
530800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopAppPid) + ", Name:crasher";
531800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
532800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
533800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
534800b99b8Sopenharmony_ci    setuid(OTHER_UID);
535800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest014 Failed";
536800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
537800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
538800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest014: end.";
539800b99b8Sopenharmony_ci}
540800b99b8Sopenharmony_ci
541800b99b8Sopenharmony_ci/**
542800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest015
543800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: system PID(root), TID(0)
544800b99b8Sopenharmony_ci * @tc.type: FUNC
545800b99b8Sopenharmony_ci */
546800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest015, TestSize.Level2)
547800b99b8Sopenharmony_ci{
548800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest015: start.";
549800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
550800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
551800b99b8Sopenharmony_ci    setuid(BMS_UID);
552800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
553800b99b8Sopenharmony_ci    string msg = "";
554800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopRootPid, 0, msg);
555800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
556800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
557800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "g_loopRootPid : \n" << g_loopRootPid;
558800b99b8Sopenharmony_ci    string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
559800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopRootPid) + ", Name:crasher";
560800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
561800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
562800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
563800b99b8Sopenharmony_ci    setuid(OTHER_UID);
564800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest015 Failed";
565800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
566800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
567800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest015: end.";
568800b99b8Sopenharmony_ci}
569800b99b8Sopenharmony_ci
570800b99b8Sopenharmony_ci/**
571800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest016
572800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: root PID(system), TID(0)
573800b99b8Sopenharmony_ci * @tc.type: FUNC
574800b99b8Sopenharmony_ci */
575800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest016, TestSize.Level2)
576800b99b8Sopenharmony_ci{
577800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest016: start.";
578800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
579800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
580800b99b8Sopenharmony_ci    setuid(ROOT_UID);
581800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
582800b99b8Sopenharmony_ci    string msg = "";
583800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopSysPid, 0, msg);
584800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
585800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
586800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "g_loopSysPid : \n" << g_loopSysPid;
587800b99b8Sopenharmony_ci    string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
588800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopSysPid) + ", Name:crasher";
589800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
590800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
591800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
592800b99b8Sopenharmony_ci    setuid(OTHER_UID);
593800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest016 Failed";
594800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
595800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
596800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest016: end.";
597800b99b8Sopenharmony_ci}
598800b99b8Sopenharmony_ci
599800b99b8Sopenharmony_ci/**
600800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest017
601800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: root PID(app), TID(0)
602800b99b8Sopenharmony_ci * @tc.type: FUNC
603800b99b8Sopenharmony_ci */
604800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest017, TestSize.Level2)
605800b99b8Sopenharmony_ci{
606800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest017: start.";
607800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
608800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
609800b99b8Sopenharmony_ci    setuid(ROOT_UID);
610800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
611800b99b8Sopenharmony_ci    string msg = "";
612800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, 0, msg);
613800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
614800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
615800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "g_loopAppPid : \n" << g_loopAppPid;
616800b99b8Sopenharmony_ci    string log[] = { "Tid:", "#00", "/data/crasher", "Name:SubTestThread", "usleep"};
617800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopAppPid) + ", Name:crasher";
618800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret : \n" << ret;
619800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
620800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
621800b99b8Sopenharmony_ci    setuid(OTHER_UID);
622800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest017 Failed";
623800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
624800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
625800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest017: end.";
626800b99b8Sopenharmony_ci}
627800b99b8Sopenharmony_ci
628800b99b8Sopenharmony_ci/**
629800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest018
630800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app PID(app), TID(root)
631800b99b8Sopenharmony_ci * @tc.type: FUNC
632800b99b8Sopenharmony_ci */
633800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest018, TestSize.Level2)
634800b99b8Sopenharmony_ci{
635800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest018 start.";
636800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
637800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
638800b99b8Sopenharmony_ci    string msg = "";
639800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, g_loopRootPid, msg);
640800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
641800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
642800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest018 Failed";
643800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
644800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest018: end.";
645800b99b8Sopenharmony_ci}
646800b99b8Sopenharmony_ci
647800b99b8Sopenharmony_ci/**
648800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest019
649800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: PID(root), TID(app)
650800b99b8Sopenharmony_ci * @tc.type: FUNC
651800b99b8Sopenharmony_ci */
652800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest019, TestSize.Level2)
653800b99b8Sopenharmony_ci{
654800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest019 start.";
655800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
656800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
657800b99b8Sopenharmony_ci    string msg = "";
658800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopRootPid, g_loopAppPid, msg);
659800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
660800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
661800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest019 Failed";
662800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
663800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest019: end.";
664800b99b8Sopenharmony_ci}
665800b99b8Sopenharmony_ci
666800b99b8Sopenharmony_ci/**
667800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest020
668800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: dumpcatcher -p apppid
669800b99b8Sopenharmony_ci * @tc.type: FUNC
670800b99b8Sopenharmony_ci */
671800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest020, TestSize.Level2)
672800b99b8Sopenharmony_ci{
673800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest020: start uid:" << getuid();
674800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
675800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid);
676800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
677800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
678800b99b8Sopenharmony_ci    string log[] = {"Failed"};
679800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
680800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
681800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest020 Failed";
682800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
683800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest020: end.";
684800b99b8Sopenharmony_ci}
685800b99b8Sopenharmony_ci
686800b99b8Sopenharmony_ci/**
687800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest021
688800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: dumpcatcher -p apppid -t apppid
689800b99b8Sopenharmony_ci * @tc.type: FUNC
690800b99b8Sopenharmony_ci */
691800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest021, TestSize.Level2)
692800b99b8Sopenharmony_ci{
693800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest021: start uid:" << getuid();
694800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
695800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid) + " -t " + to_string(g_loopAppPid);
696800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
697800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
698800b99b8Sopenharmony_ci    string log[] = {"Failed"};
699800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
700800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
701800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest021 Failed";
702800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
703800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest021: end.";
704800b99b8Sopenharmony_ci}
705800b99b8Sopenharmony_ci
706800b99b8Sopenharmony_ci/**
707800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest022
708800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: dumpcatcher -p apppid -t apptid
709800b99b8Sopenharmony_ci * @tc.type: FUNC
710800b99b8Sopenharmony_ci */
711800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest022, TestSize.Level2)
712800b99b8Sopenharmony_ci{
713800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest022: start uid:" << getuid();
714800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
715800b99b8Sopenharmony_ci    int tid = g_appTid[0];
716800b99b8Sopenharmony_ci    if (g_loopAppPid == g_appTid[0]) {
717800b99b8Sopenharmony_ci        tid = g_appTid[1];
718800b99b8Sopenharmony_ci    }
719800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid) + " -t " + to_string(tid);
720800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
721800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
722800b99b8Sopenharmony_ci    string log[] = {"Failed"};
723800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
724800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
725800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest022 Failed";
726800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
727800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest022: end.";
728800b99b8Sopenharmony_ci}
729800b99b8Sopenharmony_ci
730800b99b8Sopenharmony_ci/**
731800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest023
732800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p systempid
733800b99b8Sopenharmony_ci * @tc.type: FUNC
734800b99b8Sopenharmony_ci */
735800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest023, TestSize.Level2)
736800b99b8Sopenharmony_ci{
737800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest023: start.";
738800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
739800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
740800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopSysPid) + " -t " + to_string(g_loopSysPid);
741800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
742800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
743800b99b8Sopenharmony_ci    string log[] = {"Failed"};
744800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
745800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
746800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest023 Failed";
747800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
748800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
749800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest023: end.";
750800b99b8Sopenharmony_ci}
751800b99b8Sopenharmony_ci
752800b99b8Sopenharmony_ci/**
753800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest024
754800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p rootpid
755800b99b8Sopenharmony_ci * @tc.type: FUNC
756800b99b8Sopenharmony_ci */
757800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest024, TestSize.Level2)
758800b99b8Sopenharmony_ci{
759800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest024: start.";
760800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
761800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
762800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopRootPid) + " -t " + to_string(g_loopRootPid);
763800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
764800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
765800b99b8Sopenharmony_ci    string log[] = {"Failed"};
766800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
767800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
768800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest024 Failed";
769800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
770800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
771800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest024: end.";
772800b99b8Sopenharmony_ci}
773800b99b8Sopenharmony_ci
774800b99b8Sopenharmony_ci/**
775800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest025
776800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p 9999 -t apppid
777800b99b8Sopenharmony_ci * @tc.type: FUNC
778800b99b8Sopenharmony_ci */
779800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest025, TestSize.Level2)
780800b99b8Sopenharmony_ci{
781800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest025: start.";
782800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
783800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p 9999 -t "+ to_string(g_loopAppPid);
784800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
785800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
786800b99b8Sopenharmony_ci    string log[] = {"Failed"};
787800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
788800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
789800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest025 Failed";
790800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
791800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest025: end.";
792800b99b8Sopenharmony_ci}
793800b99b8Sopenharmony_ci
794800b99b8Sopenharmony_ci/**
795800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest026
796800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid -t 9999
797800b99b8Sopenharmony_ci * @tc.type: FUNC
798800b99b8Sopenharmony_ci */
799800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest026, TestSize.Level2)
800800b99b8Sopenharmony_ci{
801800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest026: start.";
802800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
803800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid) + " -t 9999";
804800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
805800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
806800b99b8Sopenharmony_ci    string log[] = {"Failed"};
807800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
808800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
809800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest026 Failed";
810800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
811800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest026: end.";
812800b99b8Sopenharmony_ci}
813800b99b8Sopenharmony_ci
814800b99b8Sopenharmony_ci/**
815800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest027
816800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid -t systempid
817800b99b8Sopenharmony_ci * @tc.type: FUNC
818800b99b8Sopenharmony_ci */
819800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest027, TestSize.Level2)
820800b99b8Sopenharmony_ci{
821800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest027: start.";
822800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
823800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
824800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid) + " -t " + to_string(g_loopSysPid);
825800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
826800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
827800b99b8Sopenharmony_ci    string log[] = {"Failed"};
828800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
829800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
830800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest027 Failed";
831800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
832800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
833800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest027: end.";
834800b99b8Sopenharmony_ci}
835800b99b8Sopenharmony_ci
836800b99b8Sopenharmony_ci/**
837800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest028
838800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p systempid -t apppid
839800b99b8Sopenharmony_ci * @tc.type: FUNC
840800b99b8Sopenharmony_ci */
841800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest028, TestSize.Level2)
842800b99b8Sopenharmony_ci{
843800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest028: start.";
844800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
845800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
846800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopSysPid) + " -t " + to_string(g_loopAppPid);
847800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
848800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
849800b99b8Sopenharmony_ci    string log[] = {"Failed"};
850800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
851800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
852800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest028 Failed";
853800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
854800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
855800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest028: end.";
856800b99b8Sopenharmony_ci}
857800b99b8Sopenharmony_ci
858800b99b8Sopenharmony_ci/**
859800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest029
860800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p  -t apppid
861800b99b8Sopenharmony_ci * @tc.type: FUNC
862800b99b8Sopenharmony_ci */
863800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest029, TestSize.Level2)
864800b99b8Sopenharmony_ci{
865800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest029: start.";
866800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
867800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p  -t " + to_string(g_loopAppPid);
868800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
869800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
870800b99b8Sopenharmony_ci    string log[] = {"Failed"};
871800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
872800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
873800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest029 Failed";
874800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
875800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest029: end.";
876800b99b8Sopenharmony_ci}
877800b99b8Sopenharmony_ci
878800b99b8Sopenharmony_ci/**
879800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest030
880800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid -t
881800b99b8Sopenharmony_ci * @tc.type: FUNC
882800b99b8Sopenharmony_ci */
883800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest030, TestSize.Level2)
884800b99b8Sopenharmony_ci{
885800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest030: start.";
886800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
887800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid) + " -t ";
888800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
889800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
890800b99b8Sopenharmony_ci    string log[] = {"Usage:", "dump the stacktrace"};
891800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
892800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
893800b99b8Sopenharmony_ci    EXPECT_EQ(count, 2) << "DumpCatcherSystemTest030 Failed";
894800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
895800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest030: end.";
896800b99b8Sopenharmony_ci}
897800b99b8Sopenharmony_ci
898800b99b8Sopenharmony_ci/**
899800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest031
900800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p -11 -t apppid
901800b99b8Sopenharmony_ci * @tc.type: FUNC
902800b99b8Sopenharmony_ci */
903800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest031, TestSize.Level2)
904800b99b8Sopenharmony_ci{
905800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest031: start.";
906800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
907800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p -11 -t " + to_string(g_loopAppPid);
908800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
909800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
910800b99b8Sopenharmony_ci    string log[] = {"Failed"};
911800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
912800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
913800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest031 Failed";
914800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
915800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest031: end.";
916800b99b8Sopenharmony_ci}
917800b99b8Sopenharmony_ci
918800b99b8Sopenharmony_ci/**
919800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest032
920800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid -t -11
921800b99b8Sopenharmony_ci * @tc.type: FUNC
922800b99b8Sopenharmony_ci */
923800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest032, TestSize.Level2)
924800b99b8Sopenharmony_ci{
925800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest032: start.";
926800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
927800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid) + " -t -11";
928800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
929800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
930800b99b8Sopenharmony_ci    string log[] = {"Failed"};
931800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
932800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
933800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest032 Failed";
934800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
935800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest032: end.";
936800b99b8Sopenharmony_ci}
937800b99b8Sopenharmony_ci
938800b99b8Sopenharmony_ci/**
939800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest033
940800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p systempid
941800b99b8Sopenharmony_ci * @tc.type: FUNC
942800b99b8Sopenharmony_ci */
943800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest033, TestSize.Level2)
944800b99b8Sopenharmony_ci{
945800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest033: start.";
946800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
947800b99b8Sopenharmony_ci    setuid(BMS_UID);
948800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopSysPid);
949800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
950800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
951800b99b8Sopenharmony_ci    string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
952800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopSysPid);
953800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
954800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
955800b99b8Sopenharmony_ci    setuid(OTHER_UID);
956800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest033 Failed";
957800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
958800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest033: end.";
959800b99b8Sopenharmony_ci}
960800b99b8Sopenharmony_ci
961800b99b8Sopenharmony_ci/**
962800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest034
963800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p rootpid
964800b99b8Sopenharmony_ci * @tc.type: FUNC
965800b99b8Sopenharmony_ci */
966800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest034, TestSize.Level2)
967800b99b8Sopenharmony_ci{
968800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest034: start.";
969800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
970800b99b8Sopenharmony_ci    setuid(ROOT_UID);
971800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopRootPid);
972800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
973800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
974800b99b8Sopenharmony_ci    string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
975800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopRootPid);
976800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
977800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
978800b99b8Sopenharmony_ci    setuid(OTHER_UID);
979800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest034 Failed";
980800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
981800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest034: end.";
982800b99b8Sopenharmony_ci}
983800b99b8Sopenharmony_ci
984800b99b8Sopenharmony_ci/**
985800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest035
986800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid
987800b99b8Sopenharmony_ci * @tc.type: FUNC
988800b99b8Sopenharmony_ci */
989800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest035, TestSize.Level2)
990800b99b8Sopenharmony_ci{
991800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest035: start.";
992800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
993800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
994800b99b8Sopenharmony_ci    setuid(BMS_UID);
995800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid);
996800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
997800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
998800b99b8Sopenharmony_ci    string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
999800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopAppPid);
1000800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1001800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1002800b99b8Sopenharmony_ci    setuid(OTHER_UID);
1003800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest035 Failed";
1004800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1005800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
1006800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest035: end.";
1007800b99b8Sopenharmony_ci}
1008800b99b8Sopenharmony_ci
1009800b99b8Sopenharmony_ci/**
1010800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest036
1011800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid
1012800b99b8Sopenharmony_ci * @tc.type: FUNC
1013800b99b8Sopenharmony_ci */
1014800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest036, TestSize.Level2)
1015800b99b8Sopenharmony_ci{
1016800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest036: start.";
1017800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
1018800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
1019800b99b8Sopenharmony_ci    setuid(BMS_UID);
1020800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopRootPid);
1021800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1022800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1023800b99b8Sopenharmony_ci    string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher"};
1024800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_loopRootPid);
1025800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1026800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1027800b99b8Sopenharmony_ci    setuid(OTHER_UID);
1028800b99b8Sopenharmony_ci    EXPECT_EQ(count, 5) << "DumpCatcherSystemTest036 Failed";
1029800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
1030800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
1031800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest036: end.";
1032800b99b8Sopenharmony_ci}
1033800b99b8Sopenharmony_ci
1034800b99b8Sopenharmony_ci/**
1035800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest037
1036800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid
1037800b99b8Sopenharmony_ci * @tc.type: FUNC
1038800b99b8Sopenharmony_ci */
1039800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest037, TestSize.Level2)
1040800b99b8Sopenharmony_ci{
1041800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest037: start.";
1042800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
1043800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
1044800b99b8Sopenharmony_ci    setuid(ROOT_UID);
1045800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid);
1046800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1047800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1048800b99b8Sopenharmony_ci    string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher", ""};
1049800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_appTid[0]);
1050800b99b8Sopenharmony_ci    log[5] = log[5] + to_string(g_appTid[1]);
1051800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1052800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1053800b99b8Sopenharmony_ci    setuid(OTHER_UID);
1054800b99b8Sopenharmony_ci    EXPECT_EQ(count, 6) << "DumpCatcherSystemTest037 Failed";
1055800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1056800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
1057800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest037: end.";
1058800b99b8Sopenharmony_ci}
1059800b99b8Sopenharmony_ci
1060800b99b8Sopenharmony_ci/**
1061800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest038
1062800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p sytempid
1063800b99b8Sopenharmony_ci * @tc.type: FUNC
1064800b99b8Sopenharmony_ci */
1065800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest038, TestSize.Level2)
1066800b99b8Sopenharmony_ci{
1067800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest038: start.";
1068800b99b8Sopenharmony_ci    StartCrasherLoop(SYSTEM);
1069800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
1070800b99b8Sopenharmony_ci    setuid(ROOT_UID);
1071800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopSysPid);
1072800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1073800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1074800b99b8Sopenharmony_ci    string log[] = {"", "Name:crasher", "Name:SubTestThread", "#00", "/data/crasher", ""};
1075800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_sysTid[0]);
1076800b99b8Sopenharmony_ci    log[5] = log[5] + to_string(g_sysTid[1]);
1077800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1078800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1079800b99b8Sopenharmony_ci    setuid(OTHER_UID);
1080800b99b8Sopenharmony_ci    EXPECT_EQ(count, 6) << "DumpCatcherSystemTest038 Failed";
1081800b99b8Sopenharmony_ci    StopCrasherLoop(SYSTEM);
1082800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
1083800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest038: end.";
1084800b99b8Sopenharmony_ci}
1085800b99b8Sopenharmony_ci
1086800b99b8Sopenharmony_ci/**
1087800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest039
1088800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p apppid -t rootpid
1089800b99b8Sopenharmony_ci * @tc.type: FUNC
1090800b99b8Sopenharmony_ci */
1091800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest039, TestSize.Level2)
1092800b99b8Sopenharmony_ci{
1093800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest039: start.";
1094800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
1095800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
1096800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid) + " -t " + to_string(g_loopRootPid);
1097800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1098800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1099800b99b8Sopenharmony_ci    string log[] = {"Failed"};
1100800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1101800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1102800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest039 Failed";
1103800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
1104800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1105800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest039: end.";
1106800b99b8Sopenharmony_ci}
1107800b99b8Sopenharmony_ci
1108800b99b8Sopenharmony_ci/**
1109800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest040
1110800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p rootpid, -t apppid
1111800b99b8Sopenharmony_ci * @tc.type: FUNC
1112800b99b8Sopenharmony_ci */
1113800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest040, TestSize.Level2)
1114800b99b8Sopenharmony_ci{
1115800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest040: start.";
1116800b99b8Sopenharmony_ci    StartCrasherLoop(ROOT);
1117800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
1118800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopRootPid) + " -t " + to_string(g_loopAppPid);
1119800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1120800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1121800b99b8Sopenharmony_ci    string log[] = {"Failed"};
1122800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1123800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest040 Failed";
1124800b99b8Sopenharmony_ci    StopCrasherLoop(ROOT);
1125800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1126800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest040: end.";
1127800b99b8Sopenharmony_ci}
1128800b99b8Sopenharmony_ci
1129800b99b8Sopenharmony_ci/**
1130800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest041
1131800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p pid-max, -t threads_max
1132800b99b8Sopenharmony_ci * @tc.type: FUNC
1133800b99b8Sopenharmony_ci */
1134800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest041, TestSize.Level2)
1135800b99b8Sopenharmony_ci{
1136800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest041: start.";
1137800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
1138800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + GetPidMax() + " -t " + GetTidMax();
1139800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1140800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1141800b99b8Sopenharmony_ci    string log[] = {"Failed"};
1142800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1143800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1144800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest041 Failed";
1145800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1146800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest041: end.";
1147800b99b8Sopenharmony_ci}
1148800b99b8Sopenharmony_ci
1149800b99b8Sopenharmony_ci/**
1150800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest042
1151800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p 65535, -t 65535
1152800b99b8Sopenharmony_ci * @tc.type: FUNC
1153800b99b8Sopenharmony_ci */
1154800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest042, TestSize.Level2)
1155800b99b8Sopenharmony_ci{
1156800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest042: start.";
1157800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
1158800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p 65535 -t 65535";
1159800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1160800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1161800b99b8Sopenharmony_ci    string log[] = {"Failed"};
1162800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1163800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1164800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest042 Failed";
1165800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1166800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest042: end.";
1167800b99b8Sopenharmony_ci}
1168800b99b8Sopenharmony_ci
1169800b99b8Sopenharmony_ci/**
1170800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest043
1171800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p 65536, -t 65536
1172800b99b8Sopenharmony_ci * @tc.type: FUNC
1173800b99b8Sopenharmony_ci */
1174800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest043, TestSize.Level2)
1175800b99b8Sopenharmony_ci{
1176800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest043: start.";
1177800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
1178800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p 65536 -t 65536";
1179800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1180800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1181800b99b8Sopenharmony_ci    string log[] = {"Failed"};
1182800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1183800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1184800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest043 Failed";
1185800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1186800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest043: end.";
1187800b99b8Sopenharmony_ci}
1188800b99b8Sopenharmony_ci
1189800b99b8Sopenharmony_ci/**
1190800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest044
1191800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p 65534, -t 65534
1192800b99b8Sopenharmony_ci * @tc.type: FUNC
1193800b99b8Sopenharmony_ci */
1194800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest044, TestSize.Level2)
1195800b99b8Sopenharmony_ci{
1196800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest117: start.";
1197800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_C);
1198800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p 65534 -t 65534";
1199800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1200800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1201800b99b8Sopenharmony_ci    string log[] = {"Failed"};
1202800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1203800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest044 Failed";
1204800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1205800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest044: end.";
1206800b99b8Sopenharmony_ci}
1207800b99b8Sopenharmony_ci
1208800b99b8Sopenharmony_ci/**
1209800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest045
1210800b99b8Sopenharmony_ci * @tc.desc: test CPP DumpCatch API: PID(apppid), TID(0)
1211800b99b8Sopenharmony_ci * @tc.type: FUNC
1212800b99b8Sopenharmony_ci */
1213800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest045, TestSize.Level2)
1214800b99b8Sopenharmony_ci{
1215800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest045: start uid:" << getuid();
1216800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_CPP);
1217800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
1218800b99b8Sopenharmony_ci    string msg = "";
1219800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_loopAppPid, 0, msg);
1220800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
1221800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "dump log : \n" << msg;
1222800b99b8Sopenharmony_ci    EXPECT_FALSE(ret) << "DumpCatcherSystemTest045 Failed";
1223800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1224800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest045: end.";
1225800b99b8Sopenharmony_ci}
1226800b99b8Sopenharmony_ci
1227800b99b8Sopenharmony_ci/**
1228800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest046
1229800b99b8Sopenharmony_ci * @tc.desc: test dumpcatcher command: -p rootpid
1230800b99b8Sopenharmony_ci * @tc.type: FUNC
1231800b99b8Sopenharmony_ci */
1232800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest046, TestSize.Level2)
1233800b99b8Sopenharmony_ci{
1234800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest046: start uid:" << getuid();
1235800b99b8Sopenharmony_ci    StartCrasherLoop(APP_CRASHER_CPP);
1236800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(g_loopAppPid);
1237800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1238800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1239800b99b8Sopenharmony_ci    string log[] = {"Failed"};
1240800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1241800b99b8Sopenharmony_ci    EXPECT_EQ(count, 1) << "DumpCatcherSystemTest046 Failed";
1242800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_C);
1243800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest046: end.";
1244800b99b8Sopenharmony_ci}
1245800b99b8Sopenharmony_ci
1246800b99b8Sopenharmony_ci/**
1247800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest047
1248800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app unsigned PID(systempid), unsigned TID(systempid)
1249800b99b8Sopenharmony_ci * @tc.type: FUNC
1250800b99b8Sopenharmony_ci */
1251800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest,  DumpCatcherSystemTest047, TestSize.Level2)
1252800b99b8Sopenharmony_ci{
1253800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest047: start.";
1254800b99b8Sopenharmony_ci    StartCrasherLoopForUnsignedPidAndTid(CRASHER_C);
1255800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
1256800b99b8Sopenharmony_ci    string msg = "";
1257800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_unsignedLoopSysPid, g_unsignedLoopSysPid, msg);
1258800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
1259800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << msg;
1260800b99b8Sopenharmony_ci    string log[] = {"Tid:", "Name:crasher", "#00", "/data/crasher"};
1261800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_unsignedLoopSysPid);
1262800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
1263800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1264800b99b8Sopenharmony_ci    EXPECT_EQ(count, 4) << "DumpCatcherSystemTest047 Failed";
1265800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_CPP);
1266800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest047: end.";
1267800b99b8Sopenharmony_ci}
1268800b99b8Sopenharmony_ci
1269800b99b8Sopenharmony_ci/**
1270800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest048
1271800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: app unsigned PID(systempid), unsigned TID(systempid)
1272800b99b8Sopenharmony_ci * @tc.type: FUNC
1273800b99b8Sopenharmony_ci */
1274800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest,  DumpCatcherSystemTest048, TestSize.Level2)
1275800b99b8Sopenharmony_ci{
1276800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest048: start.";
1277800b99b8Sopenharmony_ci    StartCrasherLoopForUnsignedPidAndTid(CRASHER_CPP);
1278800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
1279800b99b8Sopenharmony_ci    string msg = "";
1280800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(g_unsignedLoopSysPid, g_unsignedLoopSysPid, msg);
1281800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << ret;
1282800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << msg;
1283800b99b8Sopenharmony_ci    string log[] = {"Tid:", "Name:crasher", "#00", "/data/crasher"};
1284800b99b8Sopenharmony_ci    log[0] = log[0] + to_string(g_unsignedLoopSysPid);
1285800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
1286800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1287800b99b8Sopenharmony_ci    EXPECT_EQ(count, 4) << "DumpCatcherSystemTest048 Failed";
1288800b99b8Sopenharmony_ci    StopCrasherLoop(APP_CRASHER_CPP);
1289800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest048: end.";
1290800b99b8Sopenharmony_ci}
1291800b99b8Sopenharmony_ci
1292800b99b8Sopenharmony_ciNOINLINE int TestFunc6(std::atomic_int* tid, std::atomic_bool* done)
1293800b99b8Sopenharmony_ci{
1294800b99b8Sopenharmony_ci    tid->store(gettid());
1295800b99b8Sopenharmony_ci    while (!done->load()) {
1296800b99b8Sopenharmony_ci        usleep(100); // 100 : pause for 100 microseconds to avoid excessive CPU resource consumption in the loop.
1297800b99b8Sopenharmony_ci    }
1298800b99b8Sopenharmony_ci    return 1;
1299800b99b8Sopenharmony_ci}
1300800b99b8Sopenharmony_ci
1301800b99b8Sopenharmony_ciNOINLINE int TestFunc5(std::atomic_int* tid, std::atomic_bool* done)
1302800b99b8Sopenharmony_ci{
1303800b99b8Sopenharmony_ci    int val = TestFunc6(tid, done);
1304800b99b8Sopenharmony_ci    return val * val + 1;
1305800b99b8Sopenharmony_ci}
1306800b99b8Sopenharmony_ci
1307800b99b8Sopenharmony_ciNOINLINE int TestFunc4(std::atomic_int* tid, std::atomic_bool* done)
1308800b99b8Sopenharmony_ci{
1309800b99b8Sopenharmony_ci    int val = TestFunc5(tid, done);
1310800b99b8Sopenharmony_ci    return val * val + 1;
1311800b99b8Sopenharmony_ci}
1312800b99b8Sopenharmony_ci
1313800b99b8Sopenharmony_ciNOINLINE int TestFunc3(std::atomic_int* tid, std::atomic_bool* done)
1314800b99b8Sopenharmony_ci{
1315800b99b8Sopenharmony_ci    int val = TestFunc4(tid, done);
1316800b99b8Sopenharmony_ci    return val * val + 1;
1317800b99b8Sopenharmony_ci}
1318800b99b8Sopenharmony_ci
1319800b99b8Sopenharmony_ciNOINLINE int TestFunc2(std::atomic_int* tid, std::atomic_bool* done)
1320800b99b8Sopenharmony_ci{
1321800b99b8Sopenharmony_ci    int val = TestFunc3(tid, done);
1322800b99b8Sopenharmony_ci    return val * val + 1;
1323800b99b8Sopenharmony_ci}
1324800b99b8Sopenharmony_ci
1325800b99b8Sopenharmony_ciNOINLINE int TestFunc1(std::atomic_int* tid, std::atomic_bool* done)
1326800b99b8Sopenharmony_ci{
1327800b99b8Sopenharmony_ci    int val = TestFunc2(tid, done);
1328800b99b8Sopenharmony_ci    return val * val + 1;
1329800b99b8Sopenharmony_ci}
1330800b99b8Sopenharmony_ci
1331800b99b8Sopenharmony_ci/**
1332800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest049
1333800b99b8Sopenharmony_ci * @tc.desc: test DumpCatch API: PID(getpid), unsigned TID(0)
1334800b99b8Sopenharmony_ci * @tc.type: FUNC
1335800b99b8Sopenharmony_ci */
1336800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest,  DumpCatcherSystemTest049, TestSize.Level2)
1337800b99b8Sopenharmony_ci{
1338800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest049: start.";
1339800b99b8Sopenharmony_ci    std::atomic_int otherTid;
1340800b99b8Sopenharmony_ci    std::atomic_bool done(false);
1341800b99b8Sopenharmony_ci    std::thread th1([&otherTid, &done] {
1342800b99b8Sopenharmony_ci        otherTid = gettid();
1343800b99b8Sopenharmony_ci        TestFunc1(&otherTid, &done);
1344800b99b8Sopenharmony_ci    });
1345800b99b8Sopenharmony_ci    sleep(1);
1346800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
1347800b99b8Sopenharmony_ci    string msg = "";
1348800b99b8Sopenharmony_ci    int32_t pid = getpid();
1349800b99b8Sopenharmony_ci    bool ret = dumplog.DumpCatch(pid, 0, msg);
1350800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "ret: " << ret;
1351800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "msg:\n" << msg;
1352800b99b8Sopenharmony_ci    string log[] = {"#00", "test_faultloggerd", "Tid:", "Name", "Tid:"};
1353800b99b8Sopenharmony_ci    log[2].append(std::to_string(pid));
1354800b99b8Sopenharmony_ci    log[4].append(std::to_string(otherTid));
1355800b99b8Sopenharmony_ci    int logSize = sizeof(log) / sizeof(log[0]);
1356800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, logSize);
1357800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << count;
1358800b99b8Sopenharmony_ci    EXPECT_EQ(count, logSize) << "DumpCatcherSystemTest049 Failed";
1359800b99b8Sopenharmony_ci    done.store(true);
1360800b99b8Sopenharmony_ci    th1.join();
1361800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest049: end.";
1362800b99b8Sopenharmony_ci}
1363800b99b8Sopenharmony_ci
1364800b99b8Sopenharmony_ci/**
1365800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest101
1366800b99b8Sopenharmony_ci * @tc.desc: test using dumpcatcher command tools to dump the signal stop process
1367800b99b8Sopenharmony_ci * @tc.type: FUNC
1368800b99b8Sopenharmony_ci */
1369800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest101, TestSize.Level2)
1370800b99b8Sopenharmony_ci{
1371800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest101: start uid:" << getuid();
1372800b99b8Sopenharmony_ci    pid_t pid = fork();
1373800b99b8Sopenharmony_ci    if (pid < 0) {
1374800b99b8Sopenharmony_ci        FAIL() << "DumpCatcherSystemTest101: Failed to fork a test process";
1375800b99b8Sopenharmony_ci    } else if (pid == 0) {
1376800b99b8Sopenharmony_ci        sleep(3); // 3 : sleep 3 seconds
1377800b99b8Sopenharmony_ci    }
1378800b99b8Sopenharmony_ci    kill(pid, SIGSTOP);
1379800b99b8Sopenharmony_ci    string procCMD = "dumpcatcher -p " + to_string(pid);
1380800b99b8Sopenharmony_ci    string procDumpLog = ExecuteCommands(procCMD);
1381800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog;
1382800b99b8Sopenharmony_ci    string log[] = { "Failed", "status:", "Name:", "nonvoluntary_ctxt_switches:", "wchan:", "Tid:" };
1383800b99b8Sopenharmony_ci    int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0]));
1384800b99b8Sopenharmony_ci    kill(pid, SIGKILL);
1385800b99b8Sopenharmony_ci    EXPECT_EQ(count, sizeof(log) / sizeof(log[0])) << "DumpCatcherSystemTest101 Failed";
1386800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest101: end.";
1387800b99b8Sopenharmony_ci}
1388800b99b8Sopenharmony_ci
1389800b99b8Sopenharmony_ci/**
1390800b99b8Sopenharmony_ci * @tc.name: DumpCatcherSystemTest102
1391800b99b8Sopenharmony_ci * @tc.desc: test calling dumpcatcher interfaces to dump the signal stop process
1392800b99b8Sopenharmony_ci * @tc.type: FUNC
1393800b99b8Sopenharmony_ci */
1394800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest102, TestSize.Level2)
1395800b99b8Sopenharmony_ci{
1396800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest102: start uid:" << getuid();
1397800b99b8Sopenharmony_ci    pid_t pid = fork();
1398800b99b8Sopenharmony_ci    if (pid < 0) {
1399800b99b8Sopenharmony_ci        FAIL() << "DumpCatcherSystemTest102: Failed to fork a test process";
1400800b99b8Sopenharmony_ci    } else if (pid == 0) {
1401800b99b8Sopenharmony_ci        sleep(3); // 3 : sleep 3 seconds
1402800b99b8Sopenharmony_ci    }
1403800b99b8Sopenharmony_ci    kill(pid, SIGSTOP);
1404800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
1405800b99b8Sopenharmony_ci    string msg = "";
1406800b99b8Sopenharmony_ci    if (!dumplog.DumpCatch(pid, 0, msg)) {
1407800b99b8Sopenharmony_ci        GTEST_LOG_(ERROR) << "DumpCatcherSystemTest102: Failed to dump target process.";
1408800b99b8Sopenharmony_ci    }
1409800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << msg;
1410800b99b8Sopenharmony_ci    string log[] = { "timeout", "status:", "Name:", "nonvoluntary_ctxt_switches:", "wchan:", "Tid:" };
1411800b99b8Sopenharmony_ci    int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
1412800b99b8Sopenharmony_ci    kill(pid, SIGKILL);
1413800b99b8Sopenharmony_ci    EXPECT_EQ(count, sizeof(log) / sizeof(log[0])) << "DumpCatcherSystemTest102 Failed";
1414800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest102: end.";
1415800b99b8Sopenharmony_ci}
1416800b99b8Sopenharmony_ci
1417800b99b8Sopenharmony_cistatic void TestDumpCatch(const int targetPid, const string& processName, const int threadIdx)
1418800b99b8Sopenharmony_ci{
1419800b99b8Sopenharmony_ci    DfxDumpCatcher dumplog;
1420800b99b8Sopenharmony_ci    string msg = "";
1421800b99b8Sopenharmony_ci    if (dumplog.DumpCatch(targetPid, 0, msg)) {
1422800b99b8Sopenharmony_ci        GTEST_LOG_(INFO) << "threadIdx(" << threadIdx << ") dump sucessfully.";
1423800b99b8Sopenharmony_ci        string log[] = {"Pid:" + to_string(targetPid), "Tid:" + to_string(targetPid), "Name:" + processName,
1424800b99b8Sopenharmony_ci                        "#00", "#01", "#02"};
1425800b99b8Sopenharmony_ci        int expectNum = sizeof(log) / sizeof(log[0]);
1426800b99b8Sopenharmony_ci        int cnt = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0]));
1427800b99b8Sopenharmony_ci        EXPECT_EQ(cnt, expectNum) << "Check stack trace key words failed.";
1428800b99b8Sopenharmony_ci        if (cnt == expectNum) {
1429800b99b8Sopenharmony_ci            g_checkCnt++;
1430800b99b8Sopenharmony_ci        }
1431800b99b8Sopenharmony_ci    } else {
1432800b99b8Sopenharmony_ci        GTEST_LOG_(INFO) << "threadIdx(" << threadIdx << ") dump failed.";
1433800b99b8Sopenharmony_ci        if (msg.find("Result: pid(" + to_string(targetPid) + ") is dumping.") == string::npos) {
1434800b99b8Sopenharmony_ci            GTEST_LOG_(ERROR) << "threadIdx(" << threadIdx << ") dump error message is unexpectly.";
1435800b99b8Sopenharmony_ci            FAIL();
1436800b99b8Sopenharmony_ci        }
1437800b99b8Sopenharmony_ci    }
1438800b99b8Sopenharmony_ci}
1439800b99b8Sopenharmony_ci
1440800b99b8Sopenharmony_ci/**
1441800b99b8Sopenharmony_ci* @tc.name: DumpCatcherSystemTest201
1442800b99b8Sopenharmony_ci* @tc.desc: Calling DumpCatch Func for same process in multiple threads at same time
1443800b99b8Sopenharmony_ci* @tc.type: FUNC
1444800b99b8Sopenharmony_ci*/
1445800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest201, TestSize.Level2)
1446800b99b8Sopenharmony_ci{
1447800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest201: start.";
1448800b99b8Sopenharmony_ci    int accountmgrPid = GetProcessPid(ACCOUNTMGR_NAME);
1449800b99b8Sopenharmony_ci    g_checkCnt = 0;
1450800b99b8Sopenharmony_ci    for (int threadIdx = 0; threadIdx < MULTITHREAD_TEST_COUNT; threadIdx++) {
1451800b99b8Sopenharmony_ci        thread(TestDumpCatch, accountmgrPid, ACCOUNTMGR_NAME, threadIdx).detach();
1452800b99b8Sopenharmony_ci    }
1453800b99b8Sopenharmony_ci    sleep(2); // 2 : sleep 2 seconds
1454800b99b8Sopenharmony_ci    EXPECT_GT(g_checkCnt, 0) << "DumpCatcherSystemTest201 failed";
1455800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest201: end.";
1456800b99b8Sopenharmony_ci}
1457800b99b8Sopenharmony_ci
1458800b99b8Sopenharmony_ci/**
1459800b99b8Sopenharmony_ci* @tc.name: DumpCatcherSystemTest202
1460800b99b8Sopenharmony_ci* @tc.desc: Calling DumpCatch Func for different process in multiple threads at same time
1461800b99b8Sopenharmony_ci* @tc.type: FUNC
1462800b99b8Sopenharmony_ci*/
1463800b99b8Sopenharmony_ciHWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest202, TestSize.Level2)
1464800b99b8Sopenharmony_ci{
1465800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest202: start.";
1466800b99b8Sopenharmony_ci    vector<string> testProcessNameVecs = {ACCOUNTMGR_NAME, FOUNDATION_NAME, APPSPAWN_NAME};
1467800b99b8Sopenharmony_ci    vector<int> testPidVecs;
1468800b99b8Sopenharmony_ci    for (auto processName : testProcessNameVecs) {
1469800b99b8Sopenharmony_ci        testPidVecs.emplace_back(GetProcessPid(processName));
1470800b99b8Sopenharmony_ci    }
1471800b99b8Sopenharmony_ci    g_checkCnt = 0;
1472800b99b8Sopenharmony_ci    auto testProcessListSize = testProcessNameVecs.size();
1473800b99b8Sopenharmony_ci    for (auto idx = 0; idx < testProcessListSize; idx++) {
1474800b99b8Sopenharmony_ci        thread(TestDumpCatch, testPidVecs[idx], testProcessNameVecs[idx], idx).detach();
1475800b99b8Sopenharmony_ci    }
1476800b99b8Sopenharmony_ci    sleep(2); // 2 : sleep 2 seconds
1477800b99b8Sopenharmony_ci    EXPECT_EQ(g_checkCnt, 3) << "DumpCatcherSystemTest202 failed";
1478800b99b8Sopenharmony_ci    GTEST_LOG_(INFO) << "DumpCatcherSystemTest202: end.";
1479800b99b8Sopenharmony_ci}
1480800b99b8Sopenharmony_ci} // namespace HiviewDFX
1481800b99b8Sopenharmony_ci} // namespace OHOS
1482