1800b99b8Sopenharmony_ci/* 2800b99b8Sopenharmony_ci * Copyright (c) 2022-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 <gtest/gtest.h> 17800b99b8Sopenharmony_ci#include <fstream> 18800b99b8Sopenharmony_ci#include <map> 19800b99b8Sopenharmony_ci#include <csignal> 20800b99b8Sopenharmony_ci#include <dlfcn.h> 21800b99b8Sopenharmony_ci#include <string> 22800b99b8Sopenharmony_ci#include <syscall.h> 23800b99b8Sopenharmony_ci#include <unistd.h> 24800b99b8Sopenharmony_ci#include <vector> 25800b99b8Sopenharmony_ci 26800b99b8Sopenharmony_ci#include "dfx_config.h" 27800b99b8Sopenharmony_ci#include "dfx_define.h" 28800b99b8Sopenharmony_ci#include "dfx_logger.h" 29800b99b8Sopenharmony_ci#include "dfx_test_util.h" 30800b99b8Sopenharmony_ci#include "dfx_util.h" 31800b99b8Sopenharmony_ci#include "directory_ex.h" 32800b99b8Sopenharmony_ci#include "dfx_socket_request.h" 33800b99b8Sopenharmony_ci#include "multithread_constructor.h" 34800b99b8Sopenharmony_ci#include "process_dumper.h" 35800b99b8Sopenharmony_ci#include "faultlogger_client_msg.h" 36800b99b8Sopenharmony_ci 37800b99b8Sopenharmony_ciusing namespace OHOS::HiviewDFX; 38800b99b8Sopenharmony_ciusing namespace testing::ext; 39800b99b8Sopenharmony_ciusing namespace std; 40800b99b8Sopenharmony_ci 41800b99b8Sopenharmony_ciusing RecordAppExitReason = int (*)(int reason, const char *exitMsg); 42800b99b8Sopenharmony_ci 43800b99b8Sopenharmony_cinamespace OHOS { 44800b99b8Sopenharmony_cinamespace HiviewDFX { 45800b99b8Sopenharmony_ciclass DfxProcessDumpTest : public testing::Test { 46800b99b8Sopenharmony_cipublic: 47800b99b8Sopenharmony_ci static void SetUpTestCase(void); 48800b99b8Sopenharmony_ci static void TearDownTestCase(void); 49800b99b8Sopenharmony_ci void SetUp(); 50800b99b8Sopenharmony_ci void TearDown(); 51800b99b8Sopenharmony_ci}; 52800b99b8Sopenharmony_ci} // namespace HiviewDFX 53800b99b8Sopenharmony_ci} // namespace OHOS 54800b99b8Sopenharmony_ci 55800b99b8Sopenharmony_civoid DfxProcessDumpTest::SetUpTestCase(void) 56800b99b8Sopenharmony_ci{ 57800b99b8Sopenharmony_ci} 58800b99b8Sopenharmony_ci 59800b99b8Sopenharmony_civoid DfxProcessDumpTest::TearDownTestCase(void) 60800b99b8Sopenharmony_ci{ 61800b99b8Sopenharmony_ci} 62800b99b8Sopenharmony_ci 63800b99b8Sopenharmony_civoid DfxProcessDumpTest::SetUp(void) 64800b99b8Sopenharmony_ci{ 65800b99b8Sopenharmony_ci} 66800b99b8Sopenharmony_ci 67800b99b8Sopenharmony_civoid DfxProcessDumpTest::TearDown(void) 68800b99b8Sopenharmony_ci{ 69800b99b8Sopenharmony_ci} 70800b99b8Sopenharmony_ci 71800b99b8Sopenharmony_cistatic pid_t CreateMultiThreadProcess(int threadNum) 72800b99b8Sopenharmony_ci{ 73800b99b8Sopenharmony_ci pid_t pid = fork(); 74800b99b8Sopenharmony_ci if (pid < 0) { 75800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Failed to fork new test process."; 76800b99b8Sopenharmony_ci } else if (pid == 0) { 77800b99b8Sopenharmony_ci (void)MultiThreadConstructor(threadNum); 78800b99b8Sopenharmony_ci } 79800b99b8Sopenharmony_ci return pid; 80800b99b8Sopenharmony_ci} 81800b99b8Sopenharmony_ci 82800b99b8Sopenharmony_cistatic pid_t CreateMultiThreadForThreadCrash(int threadNum) 83800b99b8Sopenharmony_ci{ 84800b99b8Sopenharmony_ci pid_t pid = fork(); 85800b99b8Sopenharmony_ci if (pid < 0) { 86800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Failed to fork new test process."; 87800b99b8Sopenharmony_ci } else if (pid == 0) { 88800b99b8Sopenharmony_ci (void)MultiThreadConstructorForThreadCrash(threadNum); 89800b99b8Sopenharmony_ci } 90800b99b8Sopenharmony_ci return pid; 91800b99b8Sopenharmony_ci} 92800b99b8Sopenharmony_ci 93800b99b8Sopenharmony_cistatic pid_t CreateMultiThreadForThreadCrashWithOpen(int threadNum, int openNum) 94800b99b8Sopenharmony_ci{ 95800b99b8Sopenharmony_ci pid_t pid = fork(); 96800b99b8Sopenharmony_ci if (pid < 0) { 97800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Failed to fork new test process."; 98800b99b8Sopenharmony_ci } else if (pid == 0) { 99800b99b8Sopenharmony_ci for (int i = 0; i < openNum; ++i) { 100800b99b8Sopenharmony_ci fopen("/dev/null", "r"); 101800b99b8Sopenharmony_ci } 102800b99b8Sopenharmony_ci (void)MultiThreadConstructorForThreadCrash(threadNum); 103800b99b8Sopenharmony_ci } 104800b99b8Sopenharmony_ci return pid; 105800b99b8Sopenharmony_ci} 106800b99b8Sopenharmony_ci 107800b99b8Sopenharmony_cistatic bool CheckCppCrashKeyWords(const string& filePath, pid_t pid, int sig) 108800b99b8Sopenharmony_ci{ 109800b99b8Sopenharmony_ci if (filePath.empty() || pid <= 0) { 110800b99b8Sopenharmony_ci return false; 111800b99b8Sopenharmony_ci } 112800b99b8Sopenharmony_ci map<int, string> sigKey = { 113800b99b8Sopenharmony_ci { SIGILL, string("SIGILL") }, 114800b99b8Sopenharmony_ci { SIGTRAP, string("SIGTRAP") }, 115800b99b8Sopenharmony_ci { SIGABRT, string("SIGABRT") }, 116800b99b8Sopenharmony_ci { SIGBUS, string("SIGBUS") }, 117800b99b8Sopenharmony_ci { SIGFPE, string("SIGFPE") }, 118800b99b8Sopenharmony_ci { SIGSEGV, string("SIGSEGV") }, 119800b99b8Sopenharmony_ci { SIGSTKFLT, string("SIGSTKFLT") }, 120800b99b8Sopenharmony_ci { SIGSYS, string("SIGSYS") }, 121800b99b8Sopenharmony_ci }; 122800b99b8Sopenharmony_ci string sigKeyword = ""; 123800b99b8Sopenharmony_ci map<int, string>::iterator iter = sigKey.find(sig); 124800b99b8Sopenharmony_ci if (iter != sigKey.end()) { 125800b99b8Sopenharmony_ci sigKeyword = iter->second; 126800b99b8Sopenharmony_ci } 127800b99b8Sopenharmony_ci string keywords[] = { 128800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid:", "test_processdump", sigKeyword, "Tid:", "#00", "Registers:", REGISTERS, 129800b99b8Sopenharmony_ci "FaultStack:", "Maps:", "test_processdump" 130800b99b8Sopenharmony_ci }; 131800b99b8Sopenharmony_ci int length = sizeof(keywords) / sizeof(keywords[0]); 132800b99b8Sopenharmony_ci int minRegIdx = 6; // 6 : index of REGISTERS 133800b99b8Sopenharmony_ci int count = CheckKeyWords(filePath, keywords, length, minRegIdx); 134800b99b8Sopenharmony_ci return count == length; 135800b99b8Sopenharmony_ci} 136800b99b8Sopenharmony_cinamespace { 137800b99b8Sopenharmony_cibool CheckCppCrashExtraKeyWords(const string& filePath, std::string *keywords, int length, int minRegIdx) 138800b99b8Sopenharmony_ci{ 139800b99b8Sopenharmony_ci if (filePath.empty()) { 140800b99b8Sopenharmony_ci return false; 141800b99b8Sopenharmony_ci } 142800b99b8Sopenharmony_ci int count = CheckKeyWords(filePath, keywords, length, minRegIdx); 143800b99b8Sopenharmony_ci return count == length; 144800b99b8Sopenharmony_ci} 145800b99b8Sopenharmony_ci/** 146800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest001 147800b99b8Sopenharmony_ci * @tc.desc: test SIGILL crash 148800b99b8Sopenharmony_ci * @tc.type: FUNC 149800b99b8Sopenharmony_ci */ 150800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest001, TestSize.Level2) 151800b99b8Sopenharmony_ci{ 152800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest001: start."; 153800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 154800b99b8Sopenharmony_ci sleep(1); 155800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 156800b99b8Sopenharmony_ci kill(testProcess, SIGILL); 157800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 158800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 159800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 160800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGILL)); 161800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest001: end."; 162800b99b8Sopenharmony_ci} 163800b99b8Sopenharmony_ci 164800b99b8Sopenharmony_ci/** 165800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest002 166800b99b8Sopenharmony_ci * @tc.desc: test SIGTRAP crash 167800b99b8Sopenharmony_ci * @tc.type: FUNC 168800b99b8Sopenharmony_ci */ 169800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest002, TestSize.Level2) 170800b99b8Sopenharmony_ci{ 171800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest002: start."; 172800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 173800b99b8Sopenharmony_ci sleep(1); 174800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 175800b99b8Sopenharmony_ci kill(testProcess, SIGTRAP); 176800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 177800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 178800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 179800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGTRAP)); 180800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest002: end."; 181800b99b8Sopenharmony_ci} 182800b99b8Sopenharmony_ci 183800b99b8Sopenharmony_ci/** 184800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest003 185800b99b8Sopenharmony_ci * @tc.desc: test SIGABRT crash 186800b99b8Sopenharmony_ci * @tc.type: FUNC 187800b99b8Sopenharmony_ci */ 188800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest003, TestSize.Level2) 189800b99b8Sopenharmony_ci{ 190800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest003: start."; 191800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 192800b99b8Sopenharmony_ci sleep(1); 193800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 194800b99b8Sopenharmony_ci kill(testProcess, SIGABRT); 195800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 196800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 197800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 198800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGABRT)); 199800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest003: end."; 200800b99b8Sopenharmony_ci} 201800b99b8Sopenharmony_ci 202800b99b8Sopenharmony_ci/** 203800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest004 204800b99b8Sopenharmony_ci * @tc.desc: test SIGBUS crash 205800b99b8Sopenharmony_ci * @tc.type: FUNC 206800b99b8Sopenharmony_ci */ 207800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest004, TestSize.Level2) 208800b99b8Sopenharmony_ci{ 209800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest004: start."; 210800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 211800b99b8Sopenharmony_ci sleep(1); 212800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 213800b99b8Sopenharmony_ci kill(testProcess, SIGBUS); 214800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 215800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 216800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 217800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGBUS)); 218800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest004: end."; 219800b99b8Sopenharmony_ci} 220800b99b8Sopenharmony_ci 221800b99b8Sopenharmony_ci/** 222800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest005 223800b99b8Sopenharmony_ci * @tc.desc: test SIGFPE crash 224800b99b8Sopenharmony_ci * @tc.type: FUNC 225800b99b8Sopenharmony_ci */ 226800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest005, TestSize.Level2) 227800b99b8Sopenharmony_ci{ 228800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest005: start."; 229800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 230800b99b8Sopenharmony_ci sleep(1); 231800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 232800b99b8Sopenharmony_ci kill(testProcess, SIGFPE); 233800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 234800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 235800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 236800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGFPE)); 237800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest005: end."; 238800b99b8Sopenharmony_ci} 239800b99b8Sopenharmony_ci 240800b99b8Sopenharmony_ci/** 241800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest006 242800b99b8Sopenharmony_ci * @tc.desc: test SIGSEGV crash 243800b99b8Sopenharmony_ci * @tc.type: FUNC 244800b99b8Sopenharmony_ci */ 245800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest006, TestSize.Level2) 246800b99b8Sopenharmony_ci{ 247800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest006: start."; 248800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 249800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "process pid:" << testProcess; 250800b99b8Sopenharmony_ci sleep(1); 251800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 252800b99b8Sopenharmony_ci kill(testProcess, SIGSEGV); 253800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 254800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 255800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 256800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGSEGV)); 257800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest006: end."; 258800b99b8Sopenharmony_ci} 259800b99b8Sopenharmony_ci 260800b99b8Sopenharmony_ci/** 261800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest007 262800b99b8Sopenharmony_ci * @tc.desc: test SIGSTKFLT crash 263800b99b8Sopenharmony_ci * @tc.type: FUNC 264800b99b8Sopenharmony_ci */ 265800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest007, TestSize.Level2) 266800b99b8Sopenharmony_ci{ 267800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest007: start."; 268800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 269800b99b8Sopenharmony_ci sleep(1); 270800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 271800b99b8Sopenharmony_ci kill(testProcess, SIGSTKFLT); 272800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 273800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 274800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 275800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGSTKFLT)); 276800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest007: end."; 277800b99b8Sopenharmony_ci} 278800b99b8Sopenharmony_ci 279800b99b8Sopenharmony_ci/** 280800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest008 281800b99b8Sopenharmony_ci * @tc.desc: test SIGSYS crash 282800b99b8Sopenharmony_ci * @tc.type: FUNC 283800b99b8Sopenharmony_ci */ 284800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest008, TestSize.Level2) 285800b99b8Sopenharmony_ci{ 286800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest008: start."; 287800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadProcess(10); // 10 : create a process with ten threads 288800b99b8Sopenharmony_ci sleep(1); 289800b99b8Sopenharmony_ci auto curTime = GetTimeMilliSeconds(); 290800b99b8Sopenharmony_ci kill(testProcess, SIGSYS); 291800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 292800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 293800b99b8Sopenharmony_ci ASSERT_EQ(std::to_string(curTime).length(), filename.length() - filename.find_last_of('-') - 1); 294800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGSYS)); 295800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest008: end."; 296800b99b8Sopenharmony_ci} 297800b99b8Sopenharmony_ci 298800b99b8Sopenharmony_ci/** 299800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest009 300800b99b8Sopenharmony_ci * @tc.desc: test processdump command 301800b99b8Sopenharmony_ci * @tc.type: FUNC 302800b99b8Sopenharmony_ci * @tc.require: 303800b99b8Sopenharmony_ci */ 304800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest009, TestSize.Level2) 305800b99b8Sopenharmony_ci{ 306800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest009: start."; 307800b99b8Sopenharmony_ci string procCMD = "processdump"; 308800b99b8Sopenharmony_ci string procDumpLog = ExecuteCommands(procCMD); 309800b99b8Sopenharmony_ci string log[] = {"please use dumpcatcher"}; 310800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 311800b99b8Sopenharmony_ci int count = GetKeywordsNum(procDumpLog, log, expectNum); 312800b99b8Sopenharmony_ci EXPECT_EQ(count, expectNum) << "DfxProcessDumpTest009 Failed"; 313800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest009: end."; 314800b99b8Sopenharmony_ci} 315800b99b8Sopenharmony_ci 316800b99b8Sopenharmony_ci/** 317800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest010 318800b99b8Sopenharmony_ci * @tc.desc: test processdump command: -p 1 319800b99b8Sopenharmony_ci * @tc.type: FUNC 320800b99b8Sopenharmony_ci * @tc.require: 321800b99b8Sopenharmony_ci */ 322800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest010, TestSize.Level2) 323800b99b8Sopenharmony_ci{ 324800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest010: start."; 325800b99b8Sopenharmony_ci string procCMD = "processdump -p 1"; 326800b99b8Sopenharmony_ci string procDumpLog = ExecuteCommands(procCMD); 327800b99b8Sopenharmony_ci string log[] = {"please use dumpcatcher"}; 328800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 329800b99b8Sopenharmony_ci int count = GetKeywordsNum(procDumpLog, log, expectNum); 330800b99b8Sopenharmony_ci EXPECT_EQ(count, expectNum) << "DfxProcessDumpTest010 Failed"; 331800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest010: end."; 332800b99b8Sopenharmony_ci} 333800b99b8Sopenharmony_ci 334800b99b8Sopenharmony_ci/** 335800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest011 336800b99b8Sopenharmony_ci * @tc.desc: Testing the sub thread crash of multithreaded programs 337800b99b8Sopenharmony_ci * @tc.type: FUNC 338800b99b8Sopenharmony_ci */ 339800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest011, TestSize.Level2) 340800b99b8Sopenharmony_ci{ 341800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest011: start."; 342800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadForThreadCrash(10); // 10 : create a process with ten threads 343800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "process pid:" << testProcess; 344800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 345800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 346800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashKeyWords(filename, testProcess, SIGSEGV)); 347800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest011: end."; 348800b99b8Sopenharmony_ci} 349800b99b8Sopenharmony_ci 350800b99b8Sopenharmony_ci 351800b99b8Sopenharmony_ci/** 352800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest012 353800b99b8Sopenharmony_ci * @tc.desc: Testing new add key word 354800b99b8Sopenharmony_ci * @tc.type: FUNC 355800b99b8Sopenharmony_ci */ 356800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest012, TestSize.Level2) 357800b99b8Sopenharmony_ci{ 358800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest012: start."; 359800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadForThreadCrash(10); // 10 : create a process with ten threads 360800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "process pid:" << testProcess; 361800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 362800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 363800b99b8Sopenharmony_ci string keywords[] = { 364800b99b8Sopenharmony_ci "time", "OpenFiles:" 365800b99b8Sopenharmony_ci }; 366800b99b8Sopenharmony_ci int length = sizeof(keywords) / sizeof(keywords[0]); 367800b99b8Sopenharmony_ci int minRegIdx = -1; // -1 : no not check register value 368800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashExtraKeyWords(filename, keywords, length, minRegIdx)); 369800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest012: end."; 370800b99b8Sopenharmony_ci} 371800b99b8Sopenharmony_ci 372800b99b8Sopenharmony_ci/** 373800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest013 374800b99b8Sopenharmony_ci * @tc.desc: Testing new add key word 375800b99b8Sopenharmony_ci * @tc.type: FUNC 376800b99b8Sopenharmony_ci */ 377800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest013, TestSize.Level2) 378800b99b8Sopenharmony_ci{ 379800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest013: start."; 380800b99b8Sopenharmony_ci int openNum = 128; 381800b99b8Sopenharmony_ci pid_t testProcess = CreateMultiThreadForThreadCrashWithOpen(10, openNum); // 10 : create a process with ten threads 382800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "process pid:" << testProcess; 383800b99b8Sopenharmony_ci sleep(3); // 3 : wait 3s to generate cpp crash file 384800b99b8Sopenharmony_ci auto filename = GetCppCrashFileName(testProcess); 385800b99b8Sopenharmony_ci string keywords[openNum]; 386800b99b8Sopenharmony_ci string str = "FILE*"; 387800b99b8Sopenharmony_ci for (int i = 0; i < openNum; ++i) { 388800b99b8Sopenharmony_ci keywords[i] = str; 389800b99b8Sopenharmony_ci } 390800b99b8Sopenharmony_ci int length = sizeof(keywords) / sizeof(keywords[0]); 391800b99b8Sopenharmony_ci int minRegIdx = -1; // -1 : no not check register value 392800b99b8Sopenharmony_ci ASSERT_TRUE(CheckCppCrashExtraKeyWords(filename, keywords, length, minRegIdx)); 393800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest013: end."; 394800b99b8Sopenharmony_ci} 395800b99b8Sopenharmony_ci 396800b99b8Sopenharmony_ci/** 397800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest014 398800b99b8Sopenharmony_ci * @tc.desc: Testing dlopen and dlsym interfaces 399800b99b8Sopenharmony_ci * @tc.type: FUNC 400800b99b8Sopenharmony_ci */ 401800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest014, TestSize.Level2) 402800b99b8Sopenharmony_ci{ 403800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest014: start."; 404800b99b8Sopenharmony_ci void* handle = dlopen("libfaultlogger.z.so", RTLD_LAZY | RTLD_NODELETE); 405800b99b8Sopenharmony_ci ASSERT_TRUE(handle) << "Failed to dlopen libfaultlogger"; 406800b99b8Sopenharmony_ci auto addFaultLog = reinterpret_cast<void (*)(FaultDFXLOGIInner*)>(dlsym(handle, "AddFaultLog")); 407800b99b8Sopenharmony_ci ASSERT_TRUE(addFaultLog) << "Failed to dlsym addFaultLog"; 408800b99b8Sopenharmony_ci FaultDFXLOGIInner info; 409800b99b8Sopenharmony_ci info.time = time(NULL); 410800b99b8Sopenharmony_ci info.id = 0; 411800b99b8Sopenharmony_ci info.pid = 1; 412800b99b8Sopenharmony_ci info.pipeFd = -1; 413800b99b8Sopenharmony_ci info.faultLogType = 2; // 2 : CPP_CRASH_TYPE 414800b99b8Sopenharmony_ci info.module = ""; 415800b99b8Sopenharmony_ci info.reason = ""; 416800b99b8Sopenharmony_ci info.summary = ""; 417800b99b8Sopenharmony_ci info.registers = ""; 418800b99b8Sopenharmony_ci addFaultLog(&info); 419800b99b8Sopenharmony_ci dlclose(handle); 420800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest01: end."; 421800b99b8Sopenharmony_ci} 422800b99b8Sopenharmony_ci 423800b99b8Sopenharmony_ci/** 424800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest015 425800b99b8Sopenharmony_ci * @tc.desc: Testing dlopen and dlsym RecordAppExitReason 426800b99b8Sopenharmony_ci * @tc.type: FUNC 427800b99b8Sopenharmony_ci */ 428800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest015, TestSize.Level2) 429800b99b8Sopenharmony_ci{ 430800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest015: start."; 431800b99b8Sopenharmony_ci void* handle = dlopen("libability_manager_c.z.so", RTLD_LAZY | RTLD_NODELETE); 432800b99b8Sopenharmony_ci ASSERT_TRUE(handle) << "Failed to dlopen libability_manager_c"; 433800b99b8Sopenharmony_ci RecordAppExitReason recordAppExitReason = (RecordAppExitReason)dlsym(handle, "RecordAppExitReason"); 434800b99b8Sopenharmony_ci ASSERT_TRUE(recordAppExitReason) << "Failed to dlsym RecordAppExitReason"; 435800b99b8Sopenharmony_ci string reason_ = "reason"; 436800b99b8Sopenharmony_ci const int cppCrashExitReason = 2; 437800b99b8Sopenharmony_ci recordAppExitReason(cppCrashExitReason, reason_.c_str()); 438800b99b8Sopenharmony_ci dlclose(handle); 439800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest015: end."; 440800b99b8Sopenharmony_ci} 441800b99b8Sopenharmony_ci 442800b99b8Sopenharmony_ci/** 443800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest016 444800b99b8Sopenharmony_ci * @tc.desc: Testing DfxLogToSocket Function 445800b99b8Sopenharmony_ci * @tc.type: FUNC 446800b99b8Sopenharmony_ci */ 447800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest016, TestSize.Level2) 448800b99b8Sopenharmony_ci{ 449800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest016: start."; 450800b99b8Sopenharmony_ci pid_t pid = fork(); 451800b99b8Sopenharmony_ci ASSERT_TRUE(pid >= 0); 452800b99b8Sopenharmony_ci if (pid == 0) { 453800b99b8Sopenharmony_ci sleep(3); // 3 : sleep 3 seconds 454800b99b8Sopenharmony_ci } 455800b99b8Sopenharmony_ci char msg[] = "test log"; 456800b99b8Sopenharmony_ci DfxLogToSocket(msg); 457800b99b8Sopenharmony_ci kill(pid, SIGSEGV); 458800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest016: end."; 459800b99b8Sopenharmony_ci} 460800b99b8Sopenharmony_ci 461800b99b8Sopenharmony_ci/** 462800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest017 463800b99b8Sopenharmony_ci * @tc.desc: Testing InitProcessInfo、InitKeyThread、InitRegs exception 464800b99b8Sopenharmony_ci * @tc.type: FUNC 465800b99b8Sopenharmony_ci */ 466800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest017, TestSize.Level2) 467800b99b8Sopenharmony_ci{ 468800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest017: start."; 469800b99b8Sopenharmony_ci ProcessDumper& ins = ProcessDumper::GetInstance(); 470800b99b8Sopenharmony_ci std::shared_ptr<ProcessDumpRequest> request = std::make_shared<ProcessDumpRequest>(); 471800b99b8Sopenharmony_ci int result = ins.InitProcessInfo(request); 472800b99b8Sopenharmony_ci ASSERT_EQ(result, -1); 473800b99b8Sopenharmony_ci 474800b99b8Sopenharmony_ci request->pid = 1; 475800b99b8Sopenharmony_ci request->nsPid = 1; 476800b99b8Sopenharmony_ci result = ins.InitProcessInfo(request); 477800b99b8Sopenharmony_ci ASSERT_EQ(result, -1); 478800b99b8Sopenharmony_ci ins.isCrash_ = true; 479800b99b8Sopenharmony_ci result = ins.InitProcessInfo(request); 480800b99b8Sopenharmony_ci ASSERT_EQ(result, 0); 481800b99b8Sopenharmony_ci 482800b99b8Sopenharmony_ci ins.process_ = nullptr; 483800b99b8Sopenharmony_ci bool ret = ins.InitKeyThread(nullptr); 484800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 485800b99b8Sopenharmony_ci ins.InitKeyThread(request); 486800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 487800b99b8Sopenharmony_ci 488800b99b8Sopenharmony_ci ins.process_ = DfxProcess::Create(request->pid, request->nsPid); 489800b99b8Sopenharmony_ci ret = ins.InitKeyThread(nullptr); 490800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 491800b99b8Sopenharmony_ci ret = ins.InitKeyThread(request); 492800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 493800b99b8Sopenharmony_ci ins.process_->keyThread_ = nullptr; 494800b99b8Sopenharmony_ci ret = ins.InitKeyThread(request); 495800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 496800b99b8Sopenharmony_ci 497800b99b8Sopenharmony_ci ins.process_->keyThread_ = std::make_shared<DfxThread>(); 498800b99b8Sopenharmony_ci request->dumpMode = FUSION_MODE; 499800b99b8Sopenharmony_ci ret = ins.InitKeyThread(request); 500800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 501800b99b8Sopenharmony_ci request->dumpMode = SPLIT_MODE; 502800b99b8Sopenharmony_ci ret = ins.InitKeyThread(request); 503800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 504800b99b8Sopenharmony_ci ins.process_->keyThread_ = nullptr; 505800b99b8Sopenharmony_ci request->dumpMode = FUSION_MODE; 506800b99b8Sopenharmony_ci ret = ins.InitKeyThread(request); 507800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 508800b99b8Sopenharmony_ci request->dumpMode = SPLIT_MODE; 509800b99b8Sopenharmony_ci ret = ins.InitKeyThread(request); 510800b99b8Sopenharmony_ci ins.process_->keyThread_->threadInfo_.threadName = ""; 511800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 512800b99b8Sopenharmony_ci request->dumpMode = FUSION_MODE; 513800b99b8Sopenharmony_ci int dumpRes = 1; 514800b99b8Sopenharmony_ci ins.InitRegs(request, dumpRes); 515800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest017: end."; 516800b99b8Sopenharmony_ci} 517800b99b8Sopenharmony_ci 518800b99b8Sopenharmony_ci/** 519800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest018 520800b99b8Sopenharmony_ci * @tc.desc: Testing IsTargetProcessAlive exception 521800b99b8Sopenharmony_ci * @tc.type: FUNC 522800b99b8Sopenharmony_ci */ 523800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest018, TestSize.Level2) 524800b99b8Sopenharmony_ci{ 525800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest018: start."; 526800b99b8Sopenharmony_ci ProcessDumper& ins = ProcessDumper::GetInstance(); 527800b99b8Sopenharmony_ci std::shared_ptr<ProcessDumpRequest> request = std::make_shared<ProcessDumpRequest>(); 528800b99b8Sopenharmony_ci request->dumpMode = SPLIT_MODE; 529800b99b8Sopenharmony_ci ins.isCrash_ = true; 530800b99b8Sopenharmony_ci request->nsPid = syscall(SYS_getppid); 531800b99b8Sopenharmony_ci request->vmNsPid = 1; 532800b99b8Sopenharmony_ci bool ret = ins.IsTargetProcessAlive(request); 533800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 534800b99b8Sopenharmony_ci 535800b99b8Sopenharmony_ci request->dumpMode = SPLIT_MODE; 536800b99b8Sopenharmony_ci ins.isCrash_ = true; 537800b99b8Sopenharmony_ci request->nsPid = 1; 538800b99b8Sopenharmony_ci request->vmNsPid = 1; 539800b99b8Sopenharmony_ci ret = ins.IsTargetProcessAlive(request); 540800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 541800b99b8Sopenharmony_ci 542800b99b8Sopenharmony_ci request->dumpMode = SPLIT_MODE; 543800b99b8Sopenharmony_ci ins.isCrash_ = false; 544800b99b8Sopenharmony_ci request->nsPid = 1; 545800b99b8Sopenharmony_ci request->vmNsPid = syscall(SYS_getppid); 546800b99b8Sopenharmony_ci ret = ins.IsTargetProcessAlive(request); 547800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 548800b99b8Sopenharmony_ci 549800b99b8Sopenharmony_ci request->dumpMode = SPLIT_MODE; 550800b99b8Sopenharmony_ci ins.isCrash_ = false; 551800b99b8Sopenharmony_ci request->nsPid = 1; 552800b99b8Sopenharmony_ci request->vmNsPid = 1; 553800b99b8Sopenharmony_ci ret = ins.IsTargetProcessAlive(request); 554800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 555800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest018: end."; 556800b99b8Sopenharmony_ci} 557800b99b8Sopenharmony_ci 558800b99b8Sopenharmony_ci/** 559800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest019 560800b99b8Sopenharmony_ci * @tc.desc: Testing InitVmThread exception 561800b99b8Sopenharmony_ci * @tc.type: FUNC 562800b99b8Sopenharmony_ci */ 563800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest019, TestSize.Level2) 564800b99b8Sopenharmony_ci{ 565800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest019: start."; 566800b99b8Sopenharmony_ci ProcessDumper& ins = ProcessDumper::GetInstance(); 567800b99b8Sopenharmony_ci std::shared_ptr<ProcessDumpRequest> request = std::make_shared<ProcessDumpRequest>(); 568800b99b8Sopenharmony_ci ins.process_ = nullptr; 569800b99b8Sopenharmony_ci bool ret = ins.InitVmThread(nullptr); 570800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 571800b99b8Sopenharmony_ci ret = ins.InitVmThread(request); 572800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 573800b99b8Sopenharmony_ci 574800b99b8Sopenharmony_ci ins.process_ = DfxProcess::Create(request->pid, request->nsPid); 575800b99b8Sopenharmony_ci ret = ins.InitVmThread(nullptr); 576800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 577800b99b8Sopenharmony_ci ret = ins.InitVmThread(request); 578800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 579800b99b8Sopenharmony_ci ins.isCrash_ = true; 580800b99b8Sopenharmony_ci request->vmPid = 1; 581800b99b8Sopenharmony_ci ret = ins.InitVmThread(request); 582800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 583800b99b8Sopenharmony_ci request->vmNsPid = getppid(); 584800b99b8Sopenharmony_ci ret = ins.InitVmThread(request); 585800b99b8Sopenharmony_ci ASSERT_TRUE(ret); 586800b99b8Sopenharmony_ci ins.process_->vmThread_ = nullptr; 587800b99b8Sopenharmony_ci ret = ins.InitVmThread(request); 588800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 589800b99b8Sopenharmony_ci 590800b99b8Sopenharmony_ci ins.process_->vmThread_ = std::make_shared<DfxThread>(); 591800b99b8Sopenharmony_ci ret = ins.InitVmThread(request); 592800b99b8Sopenharmony_ci ASSERT_FALSE(ret); 593800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest019: end."; 594800b99b8Sopenharmony_ci} 595800b99b8Sopenharmony_ci 596800b99b8Sopenharmony_ci/** 597800b99b8Sopenharmony_ci * @tc.name: DfxProcessDumpTest020 598800b99b8Sopenharmony_ci * @tc.desc: Testing InitProcessInfo Function 599800b99b8Sopenharmony_ci * @tc.type: FUNC 600800b99b8Sopenharmony_ci */ 601800b99b8Sopenharmony_ciHWTEST_F(DfxProcessDumpTest, DfxProcessDumpTest020, TestSize.Level2) 602800b99b8Sopenharmony_ci{ 603800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest020: start."; 604800b99b8Sopenharmony_ci ProcessDumper& ins = ProcessDumper::GetInstance(); 605800b99b8Sopenharmony_ci std::shared_ptr<ProcessDumpRequest> request = std::make_shared<ProcessDumpRequest>(); 606800b99b8Sopenharmony_ci ins.isCrash_ = true; 607800b99b8Sopenharmony_ci request->siginfo.si_signo = SIGLEAK_STACK; 608800b99b8Sopenharmony_ci int result = ins.InitPrintThread(request); 609800b99b8Sopenharmony_ci ASSERT_NE(result, -1); 610800b99b8Sopenharmony_ci ins.isCrash_ = true; 611800b99b8Sopenharmony_ci request->siginfo.si_signo = CPP_CRASH; 612800b99b8Sopenharmony_ci result = ins.InitPrintThread(request); 613800b99b8Sopenharmony_ci ASSERT_NE(result, -1); 614800b99b8Sopenharmony_ci ins.isCrash_ = false; 615800b99b8Sopenharmony_ci request->siginfo.si_signo = SIGLEAK_STACK; 616800b99b8Sopenharmony_ci result = ins.InitPrintThread(request); 617800b99b8Sopenharmony_ci ASSERT_NE(result, -1); 618800b99b8Sopenharmony_ci ins.isCrash_ = false; 619800b99b8Sopenharmony_ci request->siginfo.si_signo = CPP_CRASH; 620800b99b8Sopenharmony_ci result = ins.InitPrintThread(request); 621800b99b8Sopenharmony_ci ASSERT_EQ(result, -1); 622800b99b8Sopenharmony_ci 623800b99b8Sopenharmony_ci result = ins.WriteDumpBuf(1, nullptr, 1); 624800b99b8Sopenharmony_ci ASSERT_EQ(result, -1); 625800b99b8Sopenharmony_ci ins.resFd_ = -1; 626800b99b8Sopenharmony_ci ins.WriteDumpRes(1); 627800b99b8Sopenharmony_ci ASSERT_EQ(ins.resFd_, -1); 628800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxProcessDumpTest020: end."; 629800b99b8Sopenharmony_ci} 630800b99b8Sopenharmony_ci}