1800b99b8Sopenharmony_ci/* 2800b99b8Sopenharmony_ci * Copyright (c) 2021-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 <cerrno> 17800b99b8Sopenharmony_ci#include <fstream> 18800b99b8Sopenharmony_ci#include <gtest/gtest.h> 19800b99b8Sopenharmony_ci#include <map> 20800b99b8Sopenharmony_ci#include <securec.h> 21800b99b8Sopenharmony_ci#include <string> 22800b99b8Sopenharmony_ci#include <sys/mman.h> 23800b99b8Sopenharmony_ci#include <thread> 24800b99b8Sopenharmony_ci#include <unistd.h> 25800b99b8Sopenharmony_ci#include <vector> 26800b99b8Sopenharmony_ci 27800b99b8Sopenharmony_ci#include "dfx_test_util.h" 28800b99b8Sopenharmony_ci#include "directory_ex.h" 29800b99b8Sopenharmony_ci#include "dfx_define.h" 30800b99b8Sopenharmony_ci#include "dfx_util.h" 31800b99b8Sopenharmony_ci#include "procinfo.h" 32800b99b8Sopenharmony_ci 33800b99b8Sopenharmony_ciusing namespace testing::ext; 34800b99b8Sopenharmony_ciusing namespace std; 35800b99b8Sopenharmony_ci 36800b99b8Sopenharmony_ci#define NSPID_PATH "/data/nspid" 37800b99b8Sopenharmony_ci 38800b99b8Sopenharmony_cinamespace OHOS { 39800b99b8Sopenharmony_cinamespace HiviewDFX { 40800b99b8Sopenharmony_ciclass FaultLoggerdSystemTest : public testing::Test { 41800b99b8Sopenharmony_cipublic: 42800b99b8Sopenharmony_ci static void SetUpTestCase(void); 43800b99b8Sopenharmony_ci static void TearDownTestCase(void); 44800b99b8Sopenharmony_ci void SetUp(); 45800b99b8Sopenharmony_ci void TearDown(); 46800b99b8Sopenharmony_ci}; 47800b99b8Sopenharmony_ci 48800b99b8Sopenharmony_civoid FaultLoggerdSystemTest::SetUpTestCase(void) 49800b99b8Sopenharmony_ci{ 50800b99b8Sopenharmony_ci chmod("/data/crasher_c", 0755); // 0755 : -rwxr-xr-x 51800b99b8Sopenharmony_ci chmod("/data/crasher_cpp", 0755); // 0755 : -rwxr-xr-x 52800b99b8Sopenharmony_ci} 53800b99b8Sopenharmony_ci 54800b99b8Sopenharmony_civoid FaultLoggerdSystemTest::TearDownTestCase(void) 55800b99b8Sopenharmony_ci{ 56800b99b8Sopenharmony_ci} 57800b99b8Sopenharmony_ci 58800b99b8Sopenharmony_civoid FaultLoggerdSystemTest::SetUp(void) 59800b99b8Sopenharmony_ci{ 60800b99b8Sopenharmony_ci} 61800b99b8Sopenharmony_ci 62800b99b8Sopenharmony_civoid FaultLoggerdSystemTest::TearDown(void) 63800b99b8Sopenharmony_ci{ 64800b99b8Sopenharmony_ci} 65800b99b8Sopenharmony_ci 66800b99b8Sopenharmony_cinamespace { 67800b99b8Sopenharmony_cistatic const int CPPCRASH_FILENAME_MIN_LENGTH = 36; // 36 : length of /data/log/faultlog/temp/cppcrash-x-x 68800b99b8Sopenharmony_cistatic const int SIGNAL_TEST_NUM = 50; 69800b99b8Sopenharmony_ci} 70800b99b8Sopenharmony_ci 71800b99b8Sopenharmony_cistatic pid_t ForkAndExecuteCrasher(const string& option, const CrasherType type) 72800b99b8Sopenharmony_ci{ 73800b99b8Sopenharmony_ci pid_t pid = fork(); 74800b99b8Sopenharmony_ci if (pid < 0) { 75800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Fork failed"; 76800b99b8Sopenharmony_ci return pid; 77800b99b8Sopenharmony_ci } else if (pid == 0) { 78800b99b8Sopenharmony_ci if (type == CRASHER_C) { 79800b99b8Sopenharmony_ci execl("/data/crasher_c", "crasher_c", option.c_str(), nullptr); 80800b99b8Sopenharmony_ci } else { 81800b99b8Sopenharmony_ci execl("/data/crasher_cpp", "crasher_cpp", option.c_str(), nullptr); 82800b99b8Sopenharmony_ci } 83800b99b8Sopenharmony_ci } 84800b99b8Sopenharmony_ci 85800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "forked pid:" << pid; 86800b99b8Sopenharmony_ci constexpr time_t maxWaitingTime = 60; // 60 : 60s timeout 87800b99b8Sopenharmony_ci time_t remainedTime = maxWaitingTime; 88800b99b8Sopenharmony_ci while (remainedTime > 0) { 89800b99b8Sopenharmony_ci time_t startTime = time(nullptr); 90800b99b8Sopenharmony_ci int status = 0; 91800b99b8Sopenharmony_ci waitpid(pid, &status, WNOHANG); 92800b99b8Sopenharmony_ci if (WIFEXITED(status)) { 93800b99b8Sopenharmony_ci break; 94800b99b8Sopenharmony_ci } 95800b99b8Sopenharmony_ci sleep(1); 96800b99b8Sopenharmony_ci time_t duration = time(nullptr) - startTime; 97800b99b8Sopenharmony_ci remainedTime = (remainedTime > duration) ? (remainedTime - duration) : 0; 98800b99b8Sopenharmony_ci } 99800b99b8Sopenharmony_ci return pid; 100800b99b8Sopenharmony_ci} 101800b99b8Sopenharmony_ci 102800b99b8Sopenharmony_cistatic pid_t TriggerCrasherAndGetFileName(const string& option, const CrasherType type, string& crashFileName, 103800b99b8Sopenharmony_ci int waitSec = 1, const std::string& tempPath = TEMP_DIR) 104800b99b8Sopenharmony_ci{ 105800b99b8Sopenharmony_ci auto pid = ForkAndExecuteCrasher(option, type); 106800b99b8Sopenharmony_ci int recheckCount = 0; 107800b99b8Sopenharmony_ci 108800b99b8Sopenharmony_ci // 6: means recheck times 109800b99b8Sopenharmony_ci while (recheckCount < 6) { 110800b99b8Sopenharmony_ci sleep(waitSec); 111800b99b8Sopenharmony_ci crashFileName = GetCppCrashFileName(pid, tempPath); 112800b99b8Sopenharmony_ci if (crashFileName.size() > 0) { 113800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "get crash file:" << crashFileName; 114800b99b8Sopenharmony_ci break; 115800b99b8Sopenharmony_ci } 116800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "recheck crash file, pid" << pid; 117800b99b8Sopenharmony_ci recheckCount++; 118800b99b8Sopenharmony_ci } 119800b99b8Sopenharmony_ci return pid; 120800b99b8Sopenharmony_ci} 121800b99b8Sopenharmony_ci 122800b99b8Sopenharmony_cistatic bool CheckCountNum(const string& filePath, const pid_t& pid, const string& option) 123800b99b8Sopenharmony_ci{ 124800b99b8Sopenharmony_ci map<string, string> optionReasonMap = { 125800b99b8Sopenharmony_ci#if defined(__LP64__) 126800b99b8Sopenharmony_ci { string("triSIGTRAP"), string("SIGILL") }, 127800b99b8Sopenharmony_ci#else 128800b99b8Sopenharmony_ci { string("triSIGTRAP"), string("SIGTRAP") }, 129800b99b8Sopenharmony_ci#endif 130800b99b8Sopenharmony_ci { string("triSIGILL"), string("SIGILL") }, 131800b99b8Sopenharmony_ci { string("triSIGSEGV"), string("SIGSEGV") }, 132800b99b8Sopenharmony_ci { string("MaxStack"), string("SIGSEGV") }, 133800b99b8Sopenharmony_ci { string("MaxMethod"), string("SIGSEGV") }, 134800b99b8Sopenharmony_ci { string("STACKOF"), string("SIGSEGV") }, 135800b99b8Sopenharmony_ci { string("OOM"), string("SIGABRT") }, 136800b99b8Sopenharmony_ci }; 137800b99b8Sopenharmony_ci string reason = option; 138800b99b8Sopenharmony_ci auto iter = optionReasonMap.find(option); 139800b99b8Sopenharmony_ci if (iter != optionReasonMap.end()) { 140800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "optionReasonMap matched"; 141800b99b8Sopenharmony_ci reason = iter->second; 142800b99b8Sopenharmony_ci } 143800b99b8Sopenharmony_ci string log[] = { 144800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", reason, "Tid:", "#00", "Registers:", REGISTERS, "FaultStack:", 145800b99b8Sopenharmony_ci "Maps:", "/crasher" 146800b99b8Sopenharmony_ci }; 147800b99b8Sopenharmony_ci int minRegIdx = 6; // 6 : index of first REGISTERS - 1 148800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 149800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 150800b99b8Sopenharmony_ci} 151800b99b8Sopenharmony_ci 152800b99b8Sopenharmony_cistatic bool CheckCountNumAbort(const string& filePath, const pid_t& pid) 153800b99b8Sopenharmony_ci{ 154800b99b8Sopenharmony_ci string log[] = { 155800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGABRT", "LastFatalMessage:", "ABORT!", "Tid:", "#00", 156800b99b8Sopenharmony_ci "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher" 157800b99b8Sopenharmony_ci }; 158800b99b8Sopenharmony_ci int minRegIdx = 8; // 8 : index of first REGISTERS - 1 159800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 160800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 161800b99b8Sopenharmony_ci} 162800b99b8Sopenharmony_ci 163800b99b8Sopenharmony_ci 164800b99b8Sopenharmony_cistatic bool CheckCountNumNullpointer(const string& filePath, const pid_t& pid) 165800b99b8Sopenharmony_ci{ 166800b99b8Sopenharmony_ci string log[] = { 167800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGSEGV", "NULL", "pointer", "dereference", "Tid:", "#00", 168800b99b8Sopenharmony_ci "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher" 169800b99b8Sopenharmony_ci }; 170800b99b8Sopenharmony_ci int minRegIdx = 9; // 7 : index of first REGISTERS - 1 171800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 172800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 173800b99b8Sopenharmony_ci} 174800b99b8Sopenharmony_ci 175800b99b8Sopenharmony_cistatic bool CheckCountNumStackOverFlow(const string& filePath, const pid_t& pid) 176800b99b8Sopenharmony_ci{ 177800b99b8Sopenharmony_ci string log[] = { 178800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGSEGV", "stack-buffer-overflow", "Tid:", "#00", 179800b99b8Sopenharmony_ci "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher" 180800b99b8Sopenharmony_ci }; 181800b99b8Sopenharmony_ci int minRegIdx = 7; // 7 : index of first REGISTERS - 1 182800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 183800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 184800b99b8Sopenharmony_ci} 185800b99b8Sopenharmony_ci 186800b99b8Sopenharmony_cistatic bool CheckCountNumPCZero(const string& filePath, const pid_t& pid) 187800b99b8Sopenharmony_ci{ 188800b99b8Sopenharmony_ci string log[] = { 189800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGSEGV", "Tid:", "#00", "Registers:", REGISTERS, "FaultStack:", 190800b99b8Sopenharmony_ci "Maps:", "/crasher" 191800b99b8Sopenharmony_ci }; 192800b99b8Sopenharmony_ci int minRegIdx = 6; // 6 : index of first REGISTERS - 1 193800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 194800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 195800b99b8Sopenharmony_ci} 196800b99b8Sopenharmony_ci 197800b99b8Sopenharmony_cistatic bool CheckCountNumOverStack(const string& filePath, const pid_t& pid) 198800b99b8Sopenharmony_ci{ 199800b99b8Sopenharmony_ci string log[] = { 200800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGSEGV", "Tid:", "#56", "Registers:", REGISTERS, "FaultStack:", 201800b99b8Sopenharmony_ci "Maps:", "/crasher" 202800b99b8Sopenharmony_ci }; 203800b99b8Sopenharmony_ci int minRegIdx = 6; // 6 : index of first REGISTERS - 1 204800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 205800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 206800b99b8Sopenharmony_ci} 207800b99b8Sopenharmony_ci 208800b99b8Sopenharmony_cistatic bool CheckCountNumMultiThread(const string& filePath, const pid_t& pid) 209800b99b8Sopenharmony_ci{ 210800b99b8Sopenharmony_ci string log[] = { 211800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGSEGV", "Tid:", "#00", 212800b99b8Sopenharmony_ci "Registers:", REGISTERS, "FaultStack:", "Maps:", 213800b99b8Sopenharmony_ci "/crasher" 214800b99b8Sopenharmony_ci }; 215800b99b8Sopenharmony_ci int minRegIdx = 6; // 6 : index of first REGISTERS - 1 216800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 217800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 218800b99b8Sopenharmony_ci} 219800b99b8Sopenharmony_ci 220800b99b8Sopenharmony_cistatic string GetStackTop(void) 221800b99b8Sopenharmony_ci{ 222800b99b8Sopenharmony_ci ifstream spFile; 223800b99b8Sopenharmony_ci spFile.open("/data/sp"); 224800b99b8Sopenharmony_ci string sp; 225800b99b8Sopenharmony_ci spFile >> sp; 226800b99b8Sopenharmony_ci spFile.close(); 227800b99b8Sopenharmony_ci int ret = remove("/data/sp"); 228800b99b8Sopenharmony_ci if (ret != 0) { 229800b99b8Sopenharmony_ci printf("remove failed!"); 230800b99b8Sopenharmony_ci } 231800b99b8Sopenharmony_ci int leftZero = REGISTER_FORMAT_LENGTH - sp.length(); 232800b99b8Sopenharmony_ci while (leftZero > 0) { 233800b99b8Sopenharmony_ci sp = "0" + sp; 234800b99b8Sopenharmony_ci leftZero--; 235800b99b8Sopenharmony_ci } 236800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "sp:" << sp; 237800b99b8Sopenharmony_ci return sp; 238800b99b8Sopenharmony_ci} 239800b99b8Sopenharmony_ci 240800b99b8Sopenharmony_cistatic void WriteRealPid(int realPid) 241800b99b8Sopenharmony_ci{ 242800b99b8Sopenharmony_ci ofstream file; 243800b99b8Sopenharmony_ci file.open(NSPID_PATH); 244800b99b8Sopenharmony_ci file << std::to_string(realPid); 245800b99b8Sopenharmony_ci file.close(); 246800b99b8Sopenharmony_ci} 247800b99b8Sopenharmony_ci 248800b99b8Sopenharmony_cistatic int ReadRealPid(void) 249800b99b8Sopenharmony_ci{ 250800b99b8Sopenharmony_ci ifstream file; 251800b99b8Sopenharmony_ci file.open(NSPID_PATH); 252800b99b8Sopenharmony_ci string pid; 253800b99b8Sopenharmony_ci file >> pid; 254800b99b8Sopenharmony_ci file.close(); 255800b99b8Sopenharmony_ci int ret = remove(NSPID_PATH); 256800b99b8Sopenharmony_ci if (ret != 0) { 257800b99b8Sopenharmony_ci printf("remove failed!"); 258800b99b8Sopenharmony_ci } 259800b99b8Sopenharmony_ci int realPid = atoi(pid.c_str()); 260800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "real pid:" << realPid; 261800b99b8Sopenharmony_ci return realPid; 262800b99b8Sopenharmony_ci} 263800b99b8Sopenharmony_ci 264800b99b8Sopenharmony_cistatic bool CheckCountNumStackTop(const string& filePath, const pid_t& pid) 265800b99b8Sopenharmony_ci{ 266800b99b8Sopenharmony_ci string log[] = { 267800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGSEGV", "Tid:", "#00", "Registers:", REGISTERS, "FaultStack:", 268800b99b8Sopenharmony_ci "Maps:", "/crasher" 269800b99b8Sopenharmony_ci }; 270800b99b8Sopenharmony_ci string sp = GetStackTop(); 271800b99b8Sopenharmony_ci for (auto& keyword : log) { 272800b99b8Sopenharmony_ci if (keyword == "sp:") { 273800b99b8Sopenharmony_ci keyword += sp; 274800b99b8Sopenharmony_ci } 275800b99b8Sopenharmony_ci } 276800b99b8Sopenharmony_ci int minRegIdx = 6; // 6 : index of first REGISTERS - 1 277800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 278800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 279800b99b8Sopenharmony_ci} 280800b99b8Sopenharmony_ci 281800b99b8Sopenharmony_cistatic bool CheckCppCrashAllLabelKeywords(const string& filePath, const pid_t& pid) 282800b99b8Sopenharmony_ci{ 283800b99b8Sopenharmony_ci string log[] = { 284800b99b8Sopenharmony_ci "Timestamp:", "Pid:" + to_string(pid), "Uid:", "Process", "Reason:", "LastFatalMessage:", "Fault", "thread", 285800b99b8Sopenharmony_ci "info:", "Tid:", "#00", "Registers:", REGISTERS, "Memory", "near", "registers:", "FaultStack:", "Maps:", 286800b99b8Sopenharmony_ci "/crasher" 287800b99b8Sopenharmony_ci }; 288800b99b8Sopenharmony_ci int minRegIdx = 11; // 11 : index of first REGISTERS - 1 289800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 290800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 291800b99b8Sopenharmony_ci} 292800b99b8Sopenharmony_ci 293800b99b8Sopenharmony_ci#if defined(__aarch64__) 294800b99b8Sopenharmony_cistatic bool CheckCppCrashAsyncStackEnableKeywords(const string& filePath, const pid_t& pid) 295800b99b8Sopenharmony_ci{ 296800b99b8Sopenharmony_ci string log[] = { 297800b99b8Sopenharmony_ci "Timestamp:", "Pid:" + to_string(pid), "Uid:", "Process", "Reason:", "Fault", "thread", "info:", 298800b99b8Sopenharmony_ci "Tid:", "#00", "SubmitterStacktrace", "Registers:", REGISTERS, "Memory", "near", "registers:", 299800b99b8Sopenharmony_ci "FaultStack:", "Maps:", "/crasher" 300800b99b8Sopenharmony_ci }; 301800b99b8Sopenharmony_ci int minRegIdx = 11; // 11 : index of first REGISTERS - 1 302800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 303800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 304800b99b8Sopenharmony_ci} 305800b99b8Sopenharmony_ci 306800b99b8Sopenharmony_cistatic bool CheckCppCrashAsyncStackDisableKeywords(const string& filePath, const pid_t& pid) 307800b99b8Sopenharmony_ci{ 308800b99b8Sopenharmony_ci string log[] = { 309800b99b8Sopenharmony_ci "Timestamp:", "Pid:" + to_string(pid), "Uid:", "Process", "Reason:", "Fault", "thread", "info:", 310800b99b8Sopenharmony_ci "Tid:", "#00", "Registers:", REGISTERS, "Memory", "near", "registers:", 311800b99b8Sopenharmony_ci "FaultStack:", "Maps:", "/crasher" 312800b99b8Sopenharmony_ci }; 313800b99b8Sopenharmony_ci int minRegIdx = 10; // 10 : index of first REGISTERS - 1 314800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 315800b99b8Sopenharmony_ci if (CheckKeyWords(filePath, log, expectNum, minRegIdx) != expectNum) { 316800b99b8Sopenharmony_ci return false; 317800b99b8Sopenharmony_ci } 318800b99b8Sopenharmony_ci string key[] = { 319800b99b8Sopenharmony_ci "SubmitterStacktrace" 320800b99b8Sopenharmony_ci }; 321800b99b8Sopenharmony_ci return CheckKeyWords(filePath, key, 1, -1) == 0; 322800b99b8Sopenharmony_ci} 323800b99b8Sopenharmony_ci 324800b99b8Sopenharmony_cistatic bool CheckTestGetCrashObj(const string& filePath, const pid_t& pid) 325800b99b8Sopenharmony_ci{ 326800b99b8Sopenharmony_ci string log[] = { 327800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "SIGABRT", "LastFatalMessage:", "crashObject.", 328800b99b8Sopenharmony_ci "Tid:", "#00", "Registers:", REGISTERS, "FaultStack:", "Maps:", "/crasher" 329800b99b8Sopenharmony_ci }; 330800b99b8Sopenharmony_ci int minRegIdx = 8; // 8 : index of first REGISTERS - 1 331800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 332800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 333800b99b8Sopenharmony_ci} 334800b99b8Sopenharmony_ci#endif 335800b99b8Sopenharmony_ci 336800b99b8Sopenharmony_ci/** 337800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest001 338800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: SIGFPE 339800b99b8Sopenharmony_ci * @tc.type: FUNC 340800b99b8Sopenharmony_ci */ 341800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest001, TestSize.Level2) 342800b99b8Sopenharmony_ci{ 343800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest001: start."; 344800b99b8Sopenharmony_ci string cmd = "SIGFPE"; 345800b99b8Sopenharmony_ci string fileName; 346800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 347800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 348800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 349800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 350800b99b8Sopenharmony_ci FAIL(); 351800b99b8Sopenharmony_ci } 352800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "ProcessDfxRequestTest001 Failed"; 353800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest001: end."; 354800b99b8Sopenharmony_ci} 355800b99b8Sopenharmony_ci 356800b99b8Sopenharmony_ci/** 357800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest002 358800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: SIGFPE 359800b99b8Sopenharmony_ci * @tc.type: FUNC 360800b99b8Sopenharmony_ci */ 361800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest002, TestSize.Level2) 362800b99b8Sopenharmony_ci{ 363800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest002: start."; 364800b99b8Sopenharmony_ci string cmd = "SIGFPE"; 365800b99b8Sopenharmony_ci string fileName; 366800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 367800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 368800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 369800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 370800b99b8Sopenharmony_ci FAIL(); 371800b99b8Sopenharmony_ci } 372800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest002 Failed"; 373800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest002: end."; 374800b99b8Sopenharmony_ci} 375800b99b8Sopenharmony_ci 376800b99b8Sopenharmony_ci/** 377800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest003 378800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: SIGILL 379800b99b8Sopenharmony_ci * @tc.type: FUNC 380800b99b8Sopenharmony_ci */ 381800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest003, TestSize.Level2) 382800b99b8Sopenharmony_ci{ 383800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest003: start."; 384800b99b8Sopenharmony_ci string cmd = "SIGILL"; 385800b99b8Sopenharmony_ci string fileName; 386800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 387800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 388800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 389800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 390800b99b8Sopenharmony_ci FAIL(); 391800b99b8Sopenharmony_ci } 392800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest003 Failed"; 393800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest003: end."; 394800b99b8Sopenharmony_ci} 395800b99b8Sopenharmony_ci 396800b99b8Sopenharmony_ci/** 397800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest004 398800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: SIGILL 399800b99b8Sopenharmony_ci * @tc.type: FUNC 400800b99b8Sopenharmony_ci */ 401800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest004, TestSize.Level2) 402800b99b8Sopenharmony_ci{ 403800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest004: start."; 404800b99b8Sopenharmony_ci string cmd = "SIGILL"; 405800b99b8Sopenharmony_ci string fileName; 406800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 407800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 408800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 409800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 410800b99b8Sopenharmony_ci FAIL(); 411800b99b8Sopenharmony_ci } 412800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest004 Failed"; 413800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest004: end."; 414800b99b8Sopenharmony_ci} 415800b99b8Sopenharmony_ci 416800b99b8Sopenharmony_ci/** 417800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest005 418800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: triSIGILL 419800b99b8Sopenharmony_ci* @tc.type: FUNC 420800b99b8Sopenharmony_ci*/ 421800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest005, TestSize.Level2) 422800b99b8Sopenharmony_ci{ 423800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest005: start."; 424800b99b8Sopenharmony_ci string cmd = "triSIGILL"; 425800b99b8Sopenharmony_ci string fileName; 426800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 427800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 428800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 429800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 430800b99b8Sopenharmony_ci FAIL(); 431800b99b8Sopenharmony_ci } 432800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest005 Failed"; 433800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest005: end."; 434800b99b8Sopenharmony_ci} 435800b99b8Sopenharmony_ci 436800b99b8Sopenharmony_ci/** 437800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest006 438800b99b8Sopenharmony_ci* @tc.desc: test CPP crasher application: triSIGILL 439800b99b8Sopenharmony_ci* @tc.type: FUNC 440800b99b8Sopenharmony_ci*/ 441800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest006, TestSize.Level2) 442800b99b8Sopenharmony_ci{ 443800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest006: start."; 444800b99b8Sopenharmony_ci string cmd = "triSIGILL"; 445800b99b8Sopenharmony_ci string fileName; 446800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 447800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 448800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 449800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 450800b99b8Sopenharmony_ci FAIL(); 451800b99b8Sopenharmony_ci } 452800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest006 Failed"; 453800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest006: end."; 454800b99b8Sopenharmony_ci} 455800b99b8Sopenharmony_ci 456800b99b8Sopenharmony_ci/** 457800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest007 458800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: SIGSEGV 459800b99b8Sopenharmony_ci * @tc.type: FUNC 460800b99b8Sopenharmony_ci */ 461800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest007, TestSize.Level2) 462800b99b8Sopenharmony_ci{ 463800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest007: start."; 464800b99b8Sopenharmony_ci string cmd = "SIGSEGV"; 465800b99b8Sopenharmony_ci string fileName; 466800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 467800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 468800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 469800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 470800b99b8Sopenharmony_ci FAIL(); 471800b99b8Sopenharmony_ci } 472800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest007 Failed"; 473800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest007: end."; 474800b99b8Sopenharmony_ci} 475800b99b8Sopenharmony_ci 476800b99b8Sopenharmony_ci/** 477800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest008 478800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: SIGSEGV 479800b99b8Sopenharmony_ci * @tc.type: FUNC 480800b99b8Sopenharmony_ci */ 481800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest008, TestSize.Level2) 482800b99b8Sopenharmony_ci{ 483800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest008: start."; 484800b99b8Sopenharmony_ci string cmd = "SIGSEGV"; 485800b99b8Sopenharmony_ci string fileName; 486800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 487800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 488800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 489800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 490800b99b8Sopenharmony_ci FAIL(); 491800b99b8Sopenharmony_ci } 492800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest008 Failed"; 493800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest008: end."; 494800b99b8Sopenharmony_ci} 495800b99b8Sopenharmony_ci 496800b99b8Sopenharmony_ci/** 497800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest009 498800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: triSIGSEGV 499800b99b8Sopenharmony_ci* @tc.type: FUNC 500800b99b8Sopenharmony_ci*/ 501800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest009, TestSize.Level2) 502800b99b8Sopenharmony_ci{ 503800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest009: start."; 504800b99b8Sopenharmony_ci string cmd = "triSIGSEGV"; 505800b99b8Sopenharmony_ci string fileName; 506800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 507800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 508800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 509800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 510800b99b8Sopenharmony_ci FAIL(); 511800b99b8Sopenharmony_ci } 512800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest009 Failed"; 513800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest009: end."; 514800b99b8Sopenharmony_ci} 515800b99b8Sopenharmony_ci 516800b99b8Sopenharmony_ci/** 517800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest010 518800b99b8Sopenharmony_ci* @tc.desc: test CPP crasher application: triSIGSEGV 519800b99b8Sopenharmony_ci* @tc.type: FUNC 520800b99b8Sopenharmony_ci*/ 521800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest010, TestSize.Level2) 522800b99b8Sopenharmony_ci{ 523800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest010: start."; 524800b99b8Sopenharmony_ci string cmd = "triSIGSEGV"; 525800b99b8Sopenharmony_ci string fileName; 526800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 527800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 528800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 529800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 530800b99b8Sopenharmony_ci FAIL(); 531800b99b8Sopenharmony_ci } 532800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest010 Failed"; 533800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest010: end."; 534800b99b8Sopenharmony_ci} 535800b99b8Sopenharmony_ci 536800b99b8Sopenharmony_ci/** 537800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest011 538800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: SIGTRAP 539800b99b8Sopenharmony_ci * @tc.type: FUNC 540800b99b8Sopenharmony_ci */ 541800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest011, TestSize.Level2) 542800b99b8Sopenharmony_ci{ 543800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest011: start."; 544800b99b8Sopenharmony_ci string cmd = "SIGTRAP"; 545800b99b8Sopenharmony_ci string fileName; 546800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 547800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 548800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 549800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 550800b99b8Sopenharmony_ci FAIL(); 551800b99b8Sopenharmony_ci } 552800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest011 Failed"; 553800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest011: end."; 554800b99b8Sopenharmony_ci} 555800b99b8Sopenharmony_ci 556800b99b8Sopenharmony_ci/** 557800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest012 558800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: SIGTRAP 559800b99b8Sopenharmony_ci * @tc.type: FUNC 560800b99b8Sopenharmony_ci */ 561800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest012, TestSize.Level2) 562800b99b8Sopenharmony_ci{ 563800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest012: start."; 564800b99b8Sopenharmony_ci string cmd = "SIGTRAP"; 565800b99b8Sopenharmony_ci string fileName; 566800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 567800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 568800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 569800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 570800b99b8Sopenharmony_ci FAIL(); 571800b99b8Sopenharmony_ci } 572800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest012 Failed"; 573800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest012: end."; 574800b99b8Sopenharmony_ci} 575800b99b8Sopenharmony_ci 576800b99b8Sopenharmony_ci/** 577800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest013 578800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: triSIGTRAP 579800b99b8Sopenharmony_ci* @tc.type: FUNC 580800b99b8Sopenharmony_ci*/ 581800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest013, TestSize.Level2) 582800b99b8Sopenharmony_ci{ 583800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest013: start."; 584800b99b8Sopenharmony_ci string cmd = "triSIGTRAP"; 585800b99b8Sopenharmony_ci string fileName; 586800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 587800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 588800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 589800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 590800b99b8Sopenharmony_ci FAIL(); 591800b99b8Sopenharmony_ci } 592800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest013 Failed"; 593800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest013: end."; 594800b99b8Sopenharmony_ci} 595800b99b8Sopenharmony_ci 596800b99b8Sopenharmony_ci/** 597800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest014 598800b99b8Sopenharmony_ci* @tc.desc: test CPP crasher application: triSIGTRAP 599800b99b8Sopenharmony_ci* @tc.type: FUNC 600800b99b8Sopenharmony_ci*/ 601800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest014, TestSize.Level2) 602800b99b8Sopenharmony_ci{ 603800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest014: start."; 604800b99b8Sopenharmony_ci string cmd = "triSIGTRAP"; 605800b99b8Sopenharmony_ci string fileName; 606800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 607800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 608800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 609800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 610800b99b8Sopenharmony_ci FAIL(); 611800b99b8Sopenharmony_ci } 612800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest014 Failed"; 613800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest014: end."; 614800b99b8Sopenharmony_ci} 615800b99b8Sopenharmony_ci 616800b99b8Sopenharmony_ci/** 617800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest015 618800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: SIGABRT 619800b99b8Sopenharmony_ci * @tc.type: FUNC 620800b99b8Sopenharmony_ci */ 621800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest015, TestSize.Level2) 622800b99b8Sopenharmony_ci{ 623800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest015: start."; 624800b99b8Sopenharmony_ci string cmd = "SIGABRT"; 625800b99b8Sopenharmony_ci string fileName; 626800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 627800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 628800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 629800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 630800b99b8Sopenharmony_ci FAIL(); 631800b99b8Sopenharmony_ci } 632800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumAbort(fileName, pid)) << "FaultLoggerdSystemTest015 Failed"; 633800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest015: end."; 634800b99b8Sopenharmony_ci} 635800b99b8Sopenharmony_ci 636800b99b8Sopenharmony_ci/** 637800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest016 638800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: SIGABRT 639800b99b8Sopenharmony_ci * @tc.type: FUNC 640800b99b8Sopenharmony_ci */ 641800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest016, TestSize.Level2) 642800b99b8Sopenharmony_ci{ 643800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest016: start."; 644800b99b8Sopenharmony_ci string cmd = "SIGABRT"; 645800b99b8Sopenharmony_ci string fileName; 646800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 647800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 648800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 649800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 650800b99b8Sopenharmony_ci FAIL(); 651800b99b8Sopenharmony_ci } 652800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumAbort(fileName, pid)) << "FaultLoggerdSystemTest016 Failed"; 653800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest016: end."; 654800b99b8Sopenharmony_ci} 655800b99b8Sopenharmony_ci 656800b99b8Sopenharmony_ci/** 657800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest017 658800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: triSIGABRT 659800b99b8Sopenharmony_ci* @tc.type: FUNC 660800b99b8Sopenharmony_ci*/ 661800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest017, TestSize.Level2) 662800b99b8Sopenharmony_ci{ 663800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest017: start."; 664800b99b8Sopenharmony_ci string cmd = "triSIGABRT"; 665800b99b8Sopenharmony_ci string fileName; 666800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 667800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 668800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 669800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 670800b99b8Sopenharmony_ci FAIL(); 671800b99b8Sopenharmony_ci } 672800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumAbort(fileName, pid)) << "FaultLoggerdSystemTest017 Failed"; 673800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest017: end."; 674800b99b8Sopenharmony_ci} 675800b99b8Sopenharmony_ci 676800b99b8Sopenharmony_ci/** 677800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest018 678800b99b8Sopenharmony_ci* @tc.desc: test CPP crasher application: triSIGABRT 679800b99b8Sopenharmony_ci* @tc.type: FUNC 680800b99b8Sopenharmony_ci*/ 681800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest018, TestSize.Level2) 682800b99b8Sopenharmony_ci{ 683800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest018: start."; 684800b99b8Sopenharmony_ci string cmd = "triSIGABRT"; 685800b99b8Sopenharmony_ci string fileName; 686800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 687800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 688800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 689800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 690800b99b8Sopenharmony_ci FAIL(); 691800b99b8Sopenharmony_ci } 692800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumAbort(fileName, pid)) << "FaultLoggerdSystemTest018 Failed"; 693800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest018: end."; 694800b99b8Sopenharmony_ci} 695800b99b8Sopenharmony_ci 696800b99b8Sopenharmony_ci/** 697800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest019 698800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: SIGBUS 699800b99b8Sopenharmony_ci* @tc.type: FUNC 700800b99b8Sopenharmony_ci*/ 701800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest019, TestSize.Level2) 702800b99b8Sopenharmony_ci{ 703800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest019: start."; 704800b99b8Sopenharmony_ci string cmd = "SIGBUS"; 705800b99b8Sopenharmony_ci string fileName; 706800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 707800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 708800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 709800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 710800b99b8Sopenharmony_ci FAIL(); 711800b99b8Sopenharmony_ci } 712800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest019 Failed"; 713800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest019: end."; 714800b99b8Sopenharmony_ci} 715800b99b8Sopenharmony_ci 716800b99b8Sopenharmony_ci/** 717800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest020 718800b99b8Sopenharmony_ci* @tc.desc: test CPP crasher application: SIGBUS 719800b99b8Sopenharmony_ci* @tc.type: FUNC 720800b99b8Sopenharmony_ci*/ 721800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest020, TestSize.Level2) 722800b99b8Sopenharmony_ci{ 723800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest020: start."; 724800b99b8Sopenharmony_ci string cmd = "SIGBUS"; 725800b99b8Sopenharmony_ci string fileName; 726800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 727800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 728800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 729800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 730800b99b8Sopenharmony_ci FAIL(); 731800b99b8Sopenharmony_ci } 732800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest020 Failed"; 733800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest020: end."; 734800b99b8Sopenharmony_ci} 735800b99b8Sopenharmony_ci 736800b99b8Sopenharmony_ci/** 737800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest021 738800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: MaxStack 739800b99b8Sopenharmony_ci* @tc.type: FUNC 740800b99b8Sopenharmony_ci*/ 741800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest021, TestSize.Level2) 742800b99b8Sopenharmony_ci{ 743800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest021: start."; 744800b99b8Sopenharmony_ci string cmd = "MaxStack"; 745800b99b8Sopenharmony_ci string fileName; 746800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 747800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 748800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 749800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 750800b99b8Sopenharmony_ci FAIL(); 751800b99b8Sopenharmony_ci } 752800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest021 Failed"; 753800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest021: end."; 754800b99b8Sopenharmony_ci} 755800b99b8Sopenharmony_ci 756800b99b8Sopenharmony_ci/** 757800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest022 758800b99b8Sopenharmony_ci* @tc.desc: test CPPcrasher application: MaxStack 759800b99b8Sopenharmony_ci* @tc.type: FUNC 760800b99b8Sopenharmony_ci*/ 761800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest022, TestSize.Level2) 762800b99b8Sopenharmony_ci{ 763800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest022: start."; 764800b99b8Sopenharmony_ci string cmd = "MaxStack"; 765800b99b8Sopenharmony_ci string fileName; 766800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 767800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 768800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 769800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 770800b99b8Sopenharmony_ci FAIL(); 771800b99b8Sopenharmony_ci } 772800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest022 Failed"; 773800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest022: end."; 774800b99b8Sopenharmony_ci} 775800b99b8Sopenharmony_ci 776800b99b8Sopenharmony_ci/** 777800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest023 778800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: MaxMethod 779800b99b8Sopenharmony_ci* @tc.type: FUNC 780800b99b8Sopenharmony_ci*/ 781800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest023, TestSize.Level2) 782800b99b8Sopenharmony_ci{ 783800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest023: start."; 784800b99b8Sopenharmony_ci string cmd = "MaxMethod"; 785800b99b8Sopenharmony_ci string fileName; 786800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 787800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 788800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 789800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 790800b99b8Sopenharmony_ci FAIL(); 791800b99b8Sopenharmony_ci } 792800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest023 Failed"; 793800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest023: end."; 794800b99b8Sopenharmony_ci} 795800b99b8Sopenharmony_ci 796800b99b8Sopenharmony_ci/** 797800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest024 798800b99b8Sopenharmony_ci* @tc.desc: test CPP crasher application: MaxMethod 799800b99b8Sopenharmony_ci* @tc.type: FUNC 800800b99b8Sopenharmony_ci*/ 801800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest024, TestSize.Level2) 802800b99b8Sopenharmony_ci{ 803800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest024: start."; 804800b99b8Sopenharmony_ci string cmd = "MaxMethod"; 805800b99b8Sopenharmony_ci string fileName; 806800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 807800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 808800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 809800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 810800b99b8Sopenharmony_ci FAIL(); 811800b99b8Sopenharmony_ci } 812800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest024 Failed"; 813800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest024: end."; 814800b99b8Sopenharmony_ci} 815800b99b8Sopenharmony_ci 816800b99b8Sopenharmony_ci/** 817800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest025 818800b99b8Sopenharmony_ci* @tc.desc: test C crasher application: STACKOF 819800b99b8Sopenharmony_ci* @tc.type: FUNC 820800b99b8Sopenharmony_ci*/ 821800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest025, TestSize.Level2) 822800b99b8Sopenharmony_ci{ 823800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest025: start."; 824800b99b8Sopenharmony_ci string cmd = "STACKOF"; 825800b99b8Sopenharmony_ci string fileName; 826800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 827800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 828800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 829800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 830800b99b8Sopenharmony_ci FAIL(); 831800b99b8Sopenharmony_ci } 832800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest025 Failed"; 833800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest025: end."; 834800b99b8Sopenharmony_ci} 835800b99b8Sopenharmony_ci 836800b99b8Sopenharmony_ci/** 837800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest026 838800b99b8Sopenharmony_ci* @tc.desc: test CPP crasher application: STACKOF 839800b99b8Sopenharmony_ci* @tc.type: FUNC 840800b99b8Sopenharmony_ci*/ 841800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest026, TestSize.Level2) 842800b99b8Sopenharmony_ci{ 843800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest026: start."; 844800b99b8Sopenharmony_ci string cmd = "STACKOF"; 845800b99b8Sopenharmony_ci string fileName; 846800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 847800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 848800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 849800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 850800b99b8Sopenharmony_ci FAIL(); 851800b99b8Sopenharmony_ci } 852800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest026 Failed"; 853800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest026: end."; 854800b99b8Sopenharmony_ci} 855800b99b8Sopenharmony_ci 856800b99b8Sopenharmony_ci/** 857800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest027 858800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: OOM 859800b99b8Sopenharmony_ci * @tc.type: FUNC 860800b99b8Sopenharmony_ci */ 861800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest027, TestSize.Level2) 862800b99b8Sopenharmony_ci{ 863800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest027: start."; 864800b99b8Sopenharmony_ci string cmd = "OOM"; 865800b99b8Sopenharmony_ci string fileName; 866800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 867800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 868800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 869800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 870800b99b8Sopenharmony_ci FAIL(); 871800b99b8Sopenharmony_ci } 872800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest027 Failed"; 873800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest027: end."; 874800b99b8Sopenharmony_ci} 875800b99b8Sopenharmony_ci 876800b99b8Sopenharmony_ci/** 877800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest028 878800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: OOM 879800b99b8Sopenharmony_ci * @tc.type: FUNC 880800b99b8Sopenharmony_ci */ 881800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest028, TestSize.Level2) 882800b99b8Sopenharmony_ci{ 883800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest028: start."; 884800b99b8Sopenharmony_ci string cmd = "OOM"; 885800b99b8Sopenharmony_ci string fileName; 886800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 887800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 888800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 889800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 890800b99b8Sopenharmony_ci FAIL(); 891800b99b8Sopenharmony_ci } 892800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest028 Failed"; 893800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest028: end."; 894800b99b8Sopenharmony_ci} 895800b99b8Sopenharmony_ci/** 896800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest029 897800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: PCZero 898800b99b8Sopenharmony_ci * @tc.type: FUNC 899800b99b8Sopenharmony_ci */ 900800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest029, TestSize.Level2) 901800b99b8Sopenharmony_ci{ 902800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest029: start."; 903800b99b8Sopenharmony_ci string cmd = "PCZero"; 904800b99b8Sopenharmony_ci string fileName; 905800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 906800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 907800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 908800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 909800b99b8Sopenharmony_ci FAIL(); 910800b99b8Sopenharmony_ci } 911800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumPCZero(fileName, pid)) << "FaultLoggerdSystemTest029 Failed"; 912800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest029: end."; 913800b99b8Sopenharmony_ci} 914800b99b8Sopenharmony_ci 915800b99b8Sopenharmony_ci/** 916800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest030 917800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: PCZero 918800b99b8Sopenharmony_ci * @tc.type: FUNC 919800b99b8Sopenharmony_ci */ 920800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest030, TestSize.Level2) 921800b99b8Sopenharmony_ci{ 922800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest030: start."; 923800b99b8Sopenharmony_ci string cmd = "PCZero"; 924800b99b8Sopenharmony_ci string fileName; 925800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 926800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 927800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 928800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 929800b99b8Sopenharmony_ci FAIL(); 930800b99b8Sopenharmony_ci } 931800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumPCZero(fileName, pid)) << "FaultLoggerdSystemTest030 Failed"; 932800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest030: end."; 933800b99b8Sopenharmony_ci} 934800b99b8Sopenharmony_ci 935800b99b8Sopenharmony_ci/** 936800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest031 937800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: MTCrash 938800b99b8Sopenharmony_ci * @tc.type: FUNC 939800b99b8Sopenharmony_ci */ 940800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest031, TestSize.Level2) 941800b99b8Sopenharmony_ci{ 942800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest031: start."; 943800b99b8Sopenharmony_ci string cmd = "MTCrash"; 944800b99b8Sopenharmony_ci string fileName; 945800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName, 2); // 2 : sleep 2s for waiting cppcrash file 946800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 947800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 948800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 949800b99b8Sopenharmony_ci FAIL(); 950800b99b8Sopenharmony_ci } 951800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumMultiThread(fileName, pid)) << "FaultLoggerdSystemTest031 Failed"; 952800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest031: end."; 953800b99b8Sopenharmony_ci} 954800b99b8Sopenharmony_ci 955800b99b8Sopenharmony_ci/** 956800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest032 957800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: MTCrash 958800b99b8Sopenharmony_ci * @tc.type: FUNC 959800b99b8Sopenharmony_ci */ 960800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest032, TestSize.Level2) 961800b99b8Sopenharmony_ci{ 962800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest032: start."; 963800b99b8Sopenharmony_ci string cmd = "MTCrash"; 964800b99b8Sopenharmony_ci string fileName; 965800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName, 2); // 2 : sleep 2s for waiting cppcrash file 966800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 967800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 968800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 969800b99b8Sopenharmony_ci FAIL(); 970800b99b8Sopenharmony_ci } 971800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumMultiThread(fileName, pid)) << "FaultLoggerdSystemTest032 Failed"; 972800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest032: end."; 973800b99b8Sopenharmony_ci} 974800b99b8Sopenharmony_ci 975800b99b8Sopenharmony_ci/** 976800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest033 977800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: StackOver64 978800b99b8Sopenharmony_ci * @tc.type: FUNC 979800b99b8Sopenharmony_ci */ 980800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest033, TestSize.Level2) 981800b99b8Sopenharmony_ci{ 982800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest033: start."; 983800b99b8Sopenharmony_ci string cmd = "StackOver64"; 984800b99b8Sopenharmony_ci string fileName; 985800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 986800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 987800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 988800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 989800b99b8Sopenharmony_ci FAIL(); 990800b99b8Sopenharmony_ci } 991800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumOverStack(fileName, pid)) << "FaultLoggerdSystemTest033 Failed"; 992800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest033: end."; 993800b99b8Sopenharmony_ci} 994800b99b8Sopenharmony_ci 995800b99b8Sopenharmony_ci/** 996800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest034 997800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: StackOver64 998800b99b8Sopenharmony_ci * @tc.type: FUNC 999800b99b8Sopenharmony_ci */ 1000800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest034, TestSize.Level2) 1001800b99b8Sopenharmony_ci{ 1002800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest034: start."; 1003800b99b8Sopenharmony_ci string cmd = "StackOver64"; 1004800b99b8Sopenharmony_ci string fileName; 1005800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 1006800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1007800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1008800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1009800b99b8Sopenharmony_ci FAIL(); 1010800b99b8Sopenharmony_ci } 1011800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumOverStack(fileName, pid)) << "FaultLoggerdSystemTest034 Failed"; 1012800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest034: end."; 1013800b99b8Sopenharmony_ci} 1014800b99b8Sopenharmony_ci 1015800b99b8Sopenharmony_ci/** 1016800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest035 1017800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: StackTop 1018800b99b8Sopenharmony_ci * @tc.type: FUNC 1019800b99b8Sopenharmony_ci */ 1020800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest035, TestSize.Level2) 1021800b99b8Sopenharmony_ci{ 1022800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest035: start."; 1023800b99b8Sopenharmony_ci string cmd = "StackTop"; 1024800b99b8Sopenharmony_ci string fileName; 1025800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 1026800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1027800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1028800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1029800b99b8Sopenharmony_ci FAIL(); 1030800b99b8Sopenharmony_ci } 1031800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumStackTop(fileName, pid)) << "FaultLoggerdSystemTest035 Failed"; 1032800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest035: end."; 1033800b99b8Sopenharmony_ci} 1034800b99b8Sopenharmony_ci 1035800b99b8Sopenharmony_ci/** 1036800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest036 1037800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: StackTop 1038800b99b8Sopenharmony_ci * @tc.type: FUNC 1039800b99b8Sopenharmony_ci */ 1040800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest036, TestSize.Level2) 1041800b99b8Sopenharmony_ci{ 1042800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest036: start."; 1043800b99b8Sopenharmony_ci string cmd = "StackTop"; 1044800b99b8Sopenharmony_ci string fileName; 1045800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1046800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1047800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1048800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1049800b99b8Sopenharmony_ci FAIL(); 1050800b99b8Sopenharmony_ci } 1051800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumStackTop(fileName, pid)) << "FaultLoggerdSystemTest036 Failed"; 1052800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest036: end."; 1053800b99b8Sopenharmony_ci} 1054800b99b8Sopenharmony_ci 1055800b99b8Sopenharmony_civoid GenerateCrashLogFiles() 1056800b99b8Sopenharmony_ci{ 1057800b99b8Sopenharmony_ci for (int i = 0; i < SIGNAL_TEST_NUM; i++) { 1058800b99b8Sopenharmony_ci system("/data/crasher_c CrashTest &"); 1059800b99b8Sopenharmony_ci } 1060800b99b8Sopenharmony_ci sleep(10); // 10 : sleep for 10 seconds 1061800b99b8Sopenharmony_ci} 1062800b99b8Sopenharmony_ci 1063800b99b8Sopenharmony_ci/** 1064800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest101 1065800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: 50 Abnormal signal 1066800b99b8Sopenharmony_ci * @tc.type: FUNC 1067800b99b8Sopenharmony_ci */ 1068800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest101, TestSize.Level2) 1069800b99b8Sopenharmony_ci{ 1070800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest0009: start."; 1071800b99b8Sopenharmony_ci string clearTempFilesCmd = "rm -rf /data/log/faultlog/temp/*"; 1072800b99b8Sopenharmony_ci system(clearTempFilesCmd.c_str()); 1073800b99b8Sopenharmony_ci GenerateCrashLogFiles(); 1074800b99b8Sopenharmony_ci vector<string> files; 1075800b99b8Sopenharmony_ci OHOS::GetDirFiles("/data/log/faultlog/temp/", files); 1076800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << files.size(); 1077800b99b8Sopenharmony_ci EXPECT_EQ(files.size(), SIGNAL_TEST_NUM) << "FaultLoggerdSystemTest101 Failed"; 1078800b99b8Sopenharmony_ci} 1079800b99b8Sopenharmony_ci 1080800b99b8Sopenharmony_cistatic void CrashInChildThread() 1081800b99b8Sopenharmony_ci{ 1082800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "CrashInChildThread(): TID = " << gettid(); 1083800b99b8Sopenharmony_ci raise(SIGSEGV); 1084800b99b8Sopenharmony_ci} 1085800b99b8Sopenharmony_ci 1086800b99b8Sopenharmony_cistatic int RunInNewPidNs(void* arg) 1087800b99b8Sopenharmony_ci{ 1088800b99b8Sopenharmony_ci (void)arg; 1089800b99b8Sopenharmony_ci struct ProcInfo g_nsProcInfo; 1090800b99b8Sopenharmony_ci GetProcStatus(g_nsProcInfo); 1091800b99b8Sopenharmony_ci WriteRealPid(g_nsProcInfo.pid); 1092800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "RunInNewPidNs(): real pid = " << g_nsProcInfo.pid; 1093800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "RunInNewPidNs(): PID = " << getpid(); 1094800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "RunInNewPidNs(): TID = " << gettid(); 1095800b99b8Sopenharmony_ci thread childThread(CrashInChildThread); 1096800b99b8Sopenharmony_ci childThread.join(); 1097800b99b8Sopenharmony_ci _exit(0); 1098800b99b8Sopenharmony_ci} 1099800b99b8Sopenharmony_ci 1100800b99b8Sopenharmony_ci/** 1101800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest102 1102800b99b8Sopenharmony_ci * @tc.desc: test crash in process with pid namespace 1103800b99b8Sopenharmony_ci * @tc.type: FUNC 1104800b99b8Sopenharmony_ci */ 1105800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest102, TestSize.Level2) 1106800b99b8Sopenharmony_ci{ 1107800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest102: start."; 1108800b99b8Sopenharmony_ci const int stackSz = 1024 * 1024 * 1024; // 1M 1109800b99b8Sopenharmony_ci void* cloneStack = mmap(nullptr, stackSz, 1110800b99b8Sopenharmony_ci PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, 1, 0); 1111800b99b8Sopenharmony_ci if (cloneStack == nullptr) { 1112800b99b8Sopenharmony_ci FAIL(); 1113800b99b8Sopenharmony_ci } 1114800b99b8Sopenharmony_ci cloneStack = static_cast<void *>(static_cast<uint8_t *>(cloneStack) + stackSz - 1); 1115800b99b8Sopenharmony_ci int childPid = clone(RunInNewPidNs, cloneStack, CLONE_NEWPID | SIGCHLD, nullptr); 1116800b99b8Sopenharmony_ci bool isSuccess = childPid > 0; 1117800b99b8Sopenharmony_ci if (!isSuccess) { 1118800b99b8Sopenharmony_ci ASSERT_FALSE(isSuccess); 1119800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest102: Failed to clone new process. errno:" << errno; 1120800b99b8Sopenharmony_ci return; 1121800b99b8Sopenharmony_ci } 1122800b99b8Sopenharmony_ci // wait for log generation 1123800b99b8Sopenharmony_ci sleep(3); // 3 : sleep 3s 1124800b99b8Sopenharmony_ci int readPid = ReadRealPid(); 1125800b99b8Sopenharmony_ci string fileName = GetCppCrashFileName(readPid); 1126800b99b8Sopenharmony_ci EXPECT_NE(0, fileName.size()); 1127800b99b8Sopenharmony_ci printf("PidNs Crash File:%s\n", fileName.c_str()); 1128800b99b8Sopenharmony_ci string log[] = { 1129800b99b8Sopenharmony_ci "Pid:", "Uid", "SIGSEGV", "Tid:", "#00", 1130800b99b8Sopenharmony_ci "Registers:", REGISTERS, "FaultStack:", "Maps:" 1131800b99b8Sopenharmony_ci }; 1132800b99b8Sopenharmony_ci int minRegIdx = 5; // 5 : index of first REGISTERS - 1 1133800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 1134800b99b8Sopenharmony_ci int count = CheckKeyWords(fileName, log, expectNum, minRegIdx); 1135800b99b8Sopenharmony_ci EXPECT_EQ(count, expectNum); 1136800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest102: end."; 1137800b99b8Sopenharmony_ci} 1138800b99b8Sopenharmony_ci 1139800b99b8Sopenharmony_ci/** 1140800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest103 1141800b99b8Sopenharmony_ci * @tc.desc: test the aging mechanism of the temp directory 1142800b99b8Sopenharmony_ci * @tc.type: FUNC 1143800b99b8Sopenharmony_ci */ 1144800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest103, TestSize.Level2) 1145800b99b8Sopenharmony_ci{ 1146800b99b8Sopenharmony_ci string clearTempFilesCmd = "rm -rf /data/log/faultlog/temp/*"; 1147800b99b8Sopenharmony_ci system(clearTempFilesCmd.c_str()); 1148800b99b8Sopenharmony_ci system("/data/crasher_c SIGSEGV"); // trigger aging mechanism 1149800b99b8Sopenharmony_ci sleep(1); // 1 : sleep for 1 seconds 1150800b99b8Sopenharmony_ci vector<string> files; 1151800b99b8Sopenharmony_ci OHOS::GetDirFiles("/data/log/faultlog/temp/", files); 1152800b99b8Sopenharmony_ci string oldcrash = ""; 1153800b99b8Sopenharmony_ci if (!files.empty()) { 1154800b99b8Sopenharmony_ci oldcrash = files[0]; 1155800b99b8Sopenharmony_ci } 1156800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << oldcrash; 1157800b99b8Sopenharmony_ci files.clear(); 1158800b99b8Sopenharmony_ci for (int i = 0; i < 25; i++) { // 25 : the count of crash file 1159800b99b8Sopenharmony_ci system("/data/crasher_c SIGSEGV"); 1160800b99b8Sopenharmony_ci } 1161800b99b8Sopenharmony_ci for (int i = 0; i < 25; i++) { // 25 : the count of crash file 1162800b99b8Sopenharmony_ci sleep(3); //3 : sleep for 3 seconds 1163800b99b8Sopenharmony_ci system("/data/crasher_c SIGSEGV"); 1164800b99b8Sopenharmony_ci } 1165800b99b8Sopenharmony_ci OHOS::GetDirFiles("/data/log/faultlog/temp/", files); 1166800b99b8Sopenharmony_ci for (size_t i = 0; i < files.size(); i++) { 1167800b99b8Sopenharmony_ci if (files[i] == oldcrash) { 1168800b99b8Sopenharmony_ci FAIL(); 1169800b99b8Sopenharmony_ci } 1170800b99b8Sopenharmony_ci } 1171800b99b8Sopenharmony_ci int fileCount = files.size(); 1172800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << fileCount; 1173800b99b8Sopenharmony_ci system("/data/crasher_c SIGSEGV"); // trigger aging mechanism 1174800b99b8Sopenharmony_ci sleep(1); // 1 : sleep for 1 seconds 1175800b99b8Sopenharmony_ci files.clear(); 1176800b99b8Sopenharmony_ci OHOS::GetDirFiles("/data/log/faultlog/temp/", files); 1177800b99b8Sopenharmony_ci EXPECT_EQ(fileCount, files.size()) << "FaultLoggerdSystemTest103 Failed"; 1178800b99b8Sopenharmony_ci} 1179800b99b8Sopenharmony_ci 1180800b99b8Sopenharmony_ci/** 1181800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest0104 1182800b99b8Sopenharmony_ci * @tc.desc: test crash log build-id 1183800b99b8Sopenharmony_ci * @tc.type: FUNC 1184800b99b8Sopenharmony_ci */ 1185800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest104, TestSize.Level2) 1186800b99b8Sopenharmony_ci{ 1187800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest104: start."; 1188800b99b8Sopenharmony_ci string cmd = "SIGSEGV"; 1189800b99b8Sopenharmony_ci string fileName; 1190800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 1191800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1192800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1193800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1194800b99b8Sopenharmony_ci FAIL(); 1195800b99b8Sopenharmony_ci } 1196800b99b8Sopenharmony_ci std::ifstream file; 1197800b99b8Sopenharmony_ci file.open(fileName.c_str(), std::ios::in); 1198800b99b8Sopenharmony_ci while (!file.eof()) { 1199800b99b8Sopenharmony_ci string s; 1200800b99b8Sopenharmony_ci file >> s; 1201800b99b8Sopenharmony_ci if (s.find("/data/crasher_c") != string::npos) { 1202800b99b8Sopenharmony_ci string buildId; 1203800b99b8Sopenharmony_ci size_t leftBraceIdx = s.find('('); 1204800b99b8Sopenharmony_ci size_t rightBraceIdx = s.find(')'); 1205800b99b8Sopenharmony_ci if (leftBraceIdx != string::npos && rightBraceIdx != string::npos) { 1206800b99b8Sopenharmony_ci buildId = s.substr(leftBraceIdx + 1, rightBraceIdx - leftBraceIdx - 1); 1207800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "build-id = " << buildId; 1208800b99b8Sopenharmony_ci } 1209800b99b8Sopenharmony_ci EXPECT_FALSE(buildId.empty()) << "FaultLoggerdSystemTest104 Failed"; 1210800b99b8Sopenharmony_ci break; 1211800b99b8Sopenharmony_ci } 1212800b99b8Sopenharmony_ci } 1213800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest104: end."; 1214800b99b8Sopenharmony_ci} 1215800b99b8Sopenharmony_ci 1216800b99b8Sopenharmony_ci/** 1217800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest105 1218800b99b8Sopenharmony_ci * @tc.desc: test C crasher application: SIGABRT, and check all label keywords 1219800b99b8Sopenharmony_ci * @tc.type: FUNC 1220800b99b8Sopenharmony_ci */ 1221800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest105, TestSize.Level2) 1222800b99b8Sopenharmony_ci{ 1223800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest105: start."; 1224800b99b8Sopenharmony_ci string cmd = "SIGABRT"; 1225800b99b8Sopenharmony_ci string fileName; 1226800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 1227800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1228800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1229800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1230800b99b8Sopenharmony_ci FAIL(); 1231800b99b8Sopenharmony_ci } 1232800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAllLabelKeywords(fileName, pid)) << "FaultLoggerdSystemTest105 Failed"; 1233800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest105: end."; 1234800b99b8Sopenharmony_ci} 1235800b99b8Sopenharmony_ci 1236800b99b8Sopenharmony_ci/** 1237800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest106 1238800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: NullPointerDeref0 1239800b99b8Sopenharmony_ci * @tc.type: FUNC 1240800b99b8Sopenharmony_ci */ 1241800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest106, TestSize.Level2) 1242800b99b8Sopenharmony_ci{ 1243800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest106: start."; 1244800b99b8Sopenharmony_ci string cmd = "NullPointerDeref0"; 1245800b99b8Sopenharmony_ci string fileName; 1246800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1247800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1248800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1249800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1250800b99b8Sopenharmony_ci FAIL(); 1251800b99b8Sopenharmony_ci } 1252800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumNullpointer(fileName, pid)) << "FaultLoggerdSystemTest106 Failed"; 1253800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest106: end."; 1254800b99b8Sopenharmony_ci} 1255800b99b8Sopenharmony_ci 1256800b99b8Sopenharmony_ci/** 1257800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest107 1258800b99b8Sopenharmony_ci * @tc.desc: test CPP crasher application: STACKOF 1259800b99b8Sopenharmony_ci * @tc.type: FUNC 1260800b99b8Sopenharmony_ci */ 1261800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest107, TestSize.Level2) 1262800b99b8Sopenharmony_ci{ 1263800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest107: start."; 1264800b99b8Sopenharmony_ci string cmd = "STACKOF"; 1265800b99b8Sopenharmony_ci string fileName; 1266800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1267800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1268800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1269800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1270800b99b8Sopenharmony_ci FAIL(); 1271800b99b8Sopenharmony_ci } 1272800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNumStackOverFlow(fileName, pid)) << "FaultLoggerdSystemTest107 Failed"; 1273800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest107: end."; 1274800b99b8Sopenharmony_ci} 1275800b99b8Sopenharmony_ci 1276800b99b8Sopenharmony_ci/** 1277800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest108 1278800b99b8Sopenharmony_ci * @tc.desc: test Cpp crasher application: StackCorruption, and check all label keywords 1279800b99b8Sopenharmony_ci * @tc.type: FUNC 1280800b99b8Sopenharmony_ci */ 1281800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest108, TestSize.Level2) 1282800b99b8Sopenharmony_ci{ 1283800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest108: start."; 1284800b99b8Sopenharmony_ci string cmd = "StackCorruption"; 1285800b99b8Sopenharmony_ci string fileName; 1286800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1287800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1288800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1289800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1290800b99b8Sopenharmony_ci FAIL(); 1291800b99b8Sopenharmony_ci } 1292800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAllLabelKeywords(fileName, pid)) << "FaultLoggerdSystemTest108 Failed"; 1293800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest108: end."; 1294800b99b8Sopenharmony_ci} 1295800b99b8Sopenharmony_ci 1296800b99b8Sopenharmony_ci#if defined(PROCESSDUMP_MINIDEBUGINFO) 1297800b99b8Sopenharmony_cistatic bool CheckMinidebugSymbols(const string& filePath, const pid_t& pid, const string& option) 1298800b99b8Sopenharmony_ci{ 1299800b99b8Sopenharmony_ci map<string, string> optionSymbolMap = { 1300800b99b8Sopenharmony_ci { string("triSIGSEGV"), string("SegmentFaultException") }, 1301800b99b8Sopenharmony_ci { string("triSIGARBT"), string("Abort") } 1302800b99b8Sopenharmony_ci }; 1303800b99b8Sopenharmony_ci string symbol; 1304800b99b8Sopenharmony_ci auto iter = optionSymbolMap.find(option); 1305800b99b8Sopenharmony_ci if (iter != optionSymbolMap.end()) { 1306800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "optionSymbolMap matched"; 1307800b99b8Sopenharmony_ci symbol = iter->second; 1308800b99b8Sopenharmony_ci } 1309800b99b8Sopenharmony_ci string log[] = { 1310800b99b8Sopenharmony_ci "Pid:" + to_string(pid), "Uid", ":crasher", "Tid:", "#00", 1311800b99b8Sopenharmony_ci symbol, "ParseAndDoCrash", "main", REGISTERS 1312800b99b8Sopenharmony_ci }; 1313800b99b8Sopenharmony_ci int minRegIdx = 7; // 7 : index of first REGISTERS - 1 1314800b99b8Sopenharmony_ci int expectNum = sizeof(log) / sizeof(log[0]); 1315800b99b8Sopenharmony_ci return CheckKeyWords(filePath, log, expectNum, minRegIdx) == expectNum; 1316800b99b8Sopenharmony_ci} 1317800b99b8Sopenharmony_ci 1318800b99b8Sopenharmony_ci/** 1319800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest109 1320800b99b8Sopenharmony_ci * @tc.desc: trigger crasher_c SIGSEGV and check minidebug synbols 1321800b99b8Sopenharmony_ci * @tc.type: FUNC 1322800b99b8Sopenharmony_ci */ 1323800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest109, TestSize.Level2) 1324800b99b8Sopenharmony_ci{ 1325800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest109: start."; 1326800b99b8Sopenharmony_ci string cmd = "triSIGSEGV"; 1327800b99b8Sopenharmony_ci string fileName; 1328800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 1329800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1330800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1331800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1332800b99b8Sopenharmony_ci FAIL(); 1333800b99b8Sopenharmony_ci } 1334800b99b8Sopenharmony_ci EXPECT_TRUE(CheckMinidebugSymbols(fileName, pid, cmd)) << "FaultLoggerdSystemTest109 Failed"; 1335800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest109: end."; 1336800b99b8Sopenharmony_ci} 1337800b99b8Sopenharmony_ci 1338800b99b8Sopenharmony_ci/** 1339800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest110 1340800b99b8Sopenharmony_ci * @tc.desc: trigger crasher_cpp SIGSEGV and check minidebug synbols 1341800b99b8Sopenharmony_ci * @tc.type: FUNC 1342800b99b8Sopenharmony_ci */ 1343800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest110, TestSize.Level2) 1344800b99b8Sopenharmony_ci{ 1345800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest110: start."; 1346800b99b8Sopenharmony_ci string cmd = "triSIGSEGV"; 1347800b99b8Sopenharmony_ci string fileName; 1348800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1349800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1350800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1351800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1352800b99b8Sopenharmony_ci FAIL(); 1353800b99b8Sopenharmony_ci } 1354800b99b8Sopenharmony_ci EXPECT_TRUE(CheckMinidebugSymbols(fileName, pid, cmd)) << "FaultLoggerdSystemTest110 Failed"; 1355800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest110: end."; 1356800b99b8Sopenharmony_ci} 1357800b99b8Sopenharmony_ci 1358800b99b8Sopenharmony_ci/** 1359800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest111 1360800b99b8Sopenharmony_ci * @tc.desc: trigger crasher_c SIGABRT and check minidebug synbols 1361800b99b8Sopenharmony_ci * @tc.type: FUNC 1362800b99b8Sopenharmony_ci */ 1363800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest111, TestSize.Level2) 1364800b99b8Sopenharmony_ci{ 1365800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest111: start."; 1366800b99b8Sopenharmony_ci string cmd = "triSIGABRT"; 1367800b99b8Sopenharmony_ci string fileName; 1368800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_C, fileName); 1369800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1370800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1371800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1372800b99b8Sopenharmony_ci FAIL(); 1373800b99b8Sopenharmony_ci } 1374800b99b8Sopenharmony_ci EXPECT_TRUE(CheckMinidebugSymbols(fileName, pid, cmd)) << "FaultLoggerdSystemTest111 Failed"; 1375800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest111: end."; 1376800b99b8Sopenharmony_ci} 1377800b99b8Sopenharmony_ci 1378800b99b8Sopenharmony_ci/** 1379800b99b8Sopenharmony_ci * @tc.name: FaultLoggerdSystemTest112 1380800b99b8Sopenharmony_ci * @tc.desc: trigger crasher_cpp SIGABRT and check minidebug synbols 1381800b99b8Sopenharmony_ci * @tc.type: FUNC 1382800b99b8Sopenharmony_ci */ 1383800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest112, TestSize.Level2) 1384800b99b8Sopenharmony_ci{ 1385800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest112: start."; 1386800b99b8Sopenharmony_ci string cmd = "triSIGABRT"; 1387800b99b8Sopenharmony_ci string fileName; 1388800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1389800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1390800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1391800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1392800b99b8Sopenharmony_ci FAIL(); 1393800b99b8Sopenharmony_ci } 1394800b99b8Sopenharmony_ci EXPECT_TRUE(CheckMinidebugSymbols(fileName, pid, cmd)) << "FaultLoggerdSystemTest112 Failed"; 1395800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest112: end."; 1396800b99b8Sopenharmony_ci} 1397800b99b8Sopenharmony_ci#endif 1398800b99b8Sopenharmony_ci 1399800b99b8Sopenharmony_ci/** 1400800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest113 1401800b99b8Sopenharmony_ci* @tc.desc: test fetch last fatal message from libc 1402800b99b8Sopenharmony_ci* @tc.type: FUNC 1403800b99b8Sopenharmony_ci*/ 1404800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest113, TestSize.Level2) 1405800b99b8Sopenharmony_ci{ 1406800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest113: start."; 1407800b99b8Sopenharmony_ci string cmd = "FatalMessage"; 1408800b99b8Sopenharmony_ci string fileName; 1409800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1410800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1411800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1412800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1413800b99b8Sopenharmony_ci FAIL(); 1414800b99b8Sopenharmony_ci } 1415800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAllLabelKeywords(fileName, pid)) << "FaultLoggerdSystemTest113 Failed"; 1416800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest113: end."; 1417800b99b8Sopenharmony_ci} 1418800b99b8Sopenharmony_ci 1419800b99b8Sopenharmony_ci#if defined(__aarch64__) 1420800b99b8Sopenharmony_ci/** 1421800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest114 1422800b99b8Sopenharmony_ci* @tc.desc: Test async stacktrace enable in nomal thread crash case 1423800b99b8Sopenharmony_ci* @tc.type: FUNC 1424800b99b8Sopenharmony_ci*/ 1425800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest114, TestSize.Level2) 1426800b99b8Sopenharmony_ci{ 1427800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest114: start."; 1428800b99b8Sopenharmony_ci string cmd = "AsyncStack"; 1429800b99b8Sopenharmony_ci string fileName; 1430800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1431800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1432800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1433800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1434800b99b8Sopenharmony_ci FAIL(); 1435800b99b8Sopenharmony_ci } 1436800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackEnableKeywords(fileName, pid)) << "FaultLoggerdSystemTest114 Failed"; 1437800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest114: end."; 1438800b99b8Sopenharmony_ci} 1439800b99b8Sopenharmony_ci 1440800b99b8Sopenharmony_ci/** 1441800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest115 1442800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api enable in ffrt crash case 1443800b99b8Sopenharmony_ci* @tc.type: FUNC 1444800b99b8Sopenharmony_ci*/ 1445800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest115, TestSize.Level2) 1446800b99b8Sopenharmony_ci{ 1447800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest115: start."; 1448800b99b8Sopenharmony_ci string cmd = "CrashInFFRT true"; 1449800b99b8Sopenharmony_ci string fileName; 1450800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1451800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1452800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1453800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1454800b99b8Sopenharmony_ci FAIL(); 1455800b99b8Sopenharmony_ci } 1456800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackEnableKeywords(fileName, pid)) << "FaultLoggerdSystemTest115 Failed"; 1457800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest115: end."; 1458800b99b8Sopenharmony_ci} 1459800b99b8Sopenharmony_ci 1460800b99b8Sopenharmony_ci/** 1461800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest116 1462800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api enable in work callback crash case 1463800b99b8Sopenharmony_ci* @tc.type: FUNC 1464800b99b8Sopenharmony_ci*/ 1465800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest116, TestSize.Level2) 1466800b99b8Sopenharmony_ci{ 1467800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest116: start."; 1468800b99b8Sopenharmony_ci string cmd = "CrashInLibuvWork true"; 1469800b99b8Sopenharmony_ci string fileName; 1470800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1471800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1472800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1473800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1474800b99b8Sopenharmony_ci FAIL(); 1475800b99b8Sopenharmony_ci } 1476800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackEnableKeywords(fileName, pid)) << "FaultLoggerdSystemTest116 Failed"; 1477800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest116: end."; 1478800b99b8Sopenharmony_ci} 1479800b99b8Sopenharmony_ci 1480800b99b8Sopenharmony_ci/** 1481800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest117 1482800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api enable in timer callback crash case 1483800b99b8Sopenharmony_ci* @tc.type: FUNC 1484800b99b8Sopenharmony_ci*/ 1485800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest117, TestSize.Level2) 1486800b99b8Sopenharmony_ci{ 1487800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest117: start."; 1488800b99b8Sopenharmony_ci string cmd = "CrashInLibuvTimer true"; 1489800b99b8Sopenharmony_ci string fileName; 1490800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1491800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1492800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1493800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1494800b99b8Sopenharmony_ci FAIL(); 1495800b99b8Sopenharmony_ci } 1496800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackEnableKeywords(fileName, pid)) << "FaultLoggerdSystemTest117 Failed"; 1497800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest117: end."; 1498800b99b8Sopenharmony_ci} 1499800b99b8Sopenharmony_ci 1500800b99b8Sopenharmony_ci/** 1501800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest118 1502800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api enalbe in work callback done crash case 1503800b99b8Sopenharmony_ci* @tc.type: FUNC 1504800b99b8Sopenharmony_ci*/ 1505800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest118, TestSize.Level2) 1506800b99b8Sopenharmony_ci{ 1507800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest118: start."; 1508800b99b8Sopenharmony_ci string cmd = "CrashInLibuvWorkDone true"; 1509800b99b8Sopenharmony_ci string fileName; 1510800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1511800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1512800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1513800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1514800b99b8Sopenharmony_ci FAIL(); 1515800b99b8Sopenharmony_ci } 1516800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackEnableKeywords(fileName, pid)) << "FaultLoggerdSystemTest118 Failed"; 1517800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest118: end."; 1518800b99b8Sopenharmony_ci} 1519800b99b8Sopenharmony_ci 1520800b99b8Sopenharmony_ci/** 1521800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest119 1522800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api disable in ffrt crash case 1523800b99b8Sopenharmony_ci* @tc.type: FUNC 1524800b99b8Sopenharmony_ci*/ 1525800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest119, TestSize.Level2) 1526800b99b8Sopenharmony_ci{ 1527800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest119: start."; 1528800b99b8Sopenharmony_ci string cmd = "CrashInFFRT false"; 1529800b99b8Sopenharmony_ci string fileName; 1530800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1531800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1532800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1533800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1534800b99b8Sopenharmony_ci FAIL(); 1535800b99b8Sopenharmony_ci } 1536800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackDisableKeywords(fileName, pid)) << "FaultLoggerdSystemTest119 Failed"; 1537800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest119: end."; 1538800b99b8Sopenharmony_ci} 1539800b99b8Sopenharmony_ci 1540800b99b8Sopenharmony_ci/** 1541800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest120 1542800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api disable in work callback crash case 1543800b99b8Sopenharmony_ci* @tc.type: FUNC 1544800b99b8Sopenharmony_ci*/ 1545800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest120, TestSize.Level2) 1546800b99b8Sopenharmony_ci{ 1547800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest120: start."; 1548800b99b8Sopenharmony_ci string cmd = "CrashInLibuvWork false"; 1549800b99b8Sopenharmony_ci string fileName; 1550800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1551800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1552800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1553800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1554800b99b8Sopenharmony_ci FAIL(); 1555800b99b8Sopenharmony_ci } 1556800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackDisableKeywords(fileName, pid)) << "FaultLoggerdSystemTest120 Failed"; 1557800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest120: end."; 1558800b99b8Sopenharmony_ci} 1559800b99b8Sopenharmony_ci 1560800b99b8Sopenharmony_ci/** 1561800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest121 1562800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api disable in timer callback crash case 1563800b99b8Sopenharmony_ci* @tc.type: FUNC 1564800b99b8Sopenharmony_ci*/ 1565800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest121, TestSize.Level2) 1566800b99b8Sopenharmony_ci{ 1567800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest121: start."; 1568800b99b8Sopenharmony_ci string cmd = "CrashInLibuvTimer false"; 1569800b99b8Sopenharmony_ci string fileName; 1570800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1571800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1572800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1573800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1574800b99b8Sopenharmony_ci FAIL(); 1575800b99b8Sopenharmony_ci } 1576800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackDisableKeywords(fileName, pid)) << "FaultLoggerdSystemTest121 Failed"; 1577800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest121: end."; 1578800b99b8Sopenharmony_ci} 1579800b99b8Sopenharmony_ci 1580800b99b8Sopenharmony_ci/** 1581800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest122 1582800b99b8Sopenharmony_ci* @tc.desc: Test async-stacktrace api disable in work callback done crash case 1583800b99b8Sopenharmony_ci* @tc.type: FUNC 1584800b99b8Sopenharmony_ci*/ 1585800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest122, TestSize.Level2) 1586800b99b8Sopenharmony_ci{ 1587800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest122: start."; 1588800b99b8Sopenharmony_ci string cmd = "CrashInLibuvWorkDone false"; 1589800b99b8Sopenharmony_ci string fileName; 1590800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1591800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1592800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1593800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1594800b99b8Sopenharmony_ci FAIL(); 1595800b99b8Sopenharmony_ci } 1596800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCppCrashAsyncStackDisableKeywords(fileName, pid)) << "FaultLoggerdSystemTest122 Failed"; 1597800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest122: end."; 1598800b99b8Sopenharmony_ci} 1599800b99b8Sopenharmony_ci 1600800b99b8Sopenharmony_ci/** 1601800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest123 1602800b99b8Sopenharmony_ci* @tc.desc: Test crash log to /log/crash when faultloggerd unstart case 1603800b99b8Sopenharmony_ci* @tc.type: FUNC 1604800b99b8Sopenharmony_ci*/ 1605800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest123, TestSize.Level2) 1606800b99b8Sopenharmony_ci{ 1607800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest123: start."; 1608800b99b8Sopenharmony_ci string clearCrashFilesCmd = "rm -rf /log/crash/*"; 1609800b99b8Sopenharmony_ci system(clearCrashFilesCmd.c_str()); 1610800b99b8Sopenharmony_ci 1611800b99b8Sopenharmony_ci string stopFaultLoggerd = "service_control stop faultloggerd"; 1612800b99b8Sopenharmony_ci (void)ExecuteCommands(stopFaultLoggerd); 1613800b99b8Sopenharmony_ci 1614800b99b8Sopenharmony_ci string cmd = "SIGABRT"; 1615800b99b8Sopenharmony_ci string fileName; 1616800b99b8Sopenharmony_ci string crashDir = "/log/crash/"; 1617800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName, 1, crashDir); 1618800b99b8Sopenharmony_ci 1619800b99b8Sopenharmony_ci string startFaultLoggerd = "service_control start faultloggerd"; 1620800b99b8Sopenharmony_ci (void)ExecuteCommands(startFaultLoggerd); 1621800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1622800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1623800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1624800b99b8Sopenharmony_ci FAIL(); 1625800b99b8Sopenharmony_ci } 1626800b99b8Sopenharmony_ci EXPECT_TRUE(CheckCountNum(fileName, pid, cmd)) << "FaultLoggerdSystemTest123 Failed"; 1627800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest123: end."; 1628800b99b8Sopenharmony_ci} 1629800b99b8Sopenharmony_ci 1630800b99b8Sopenharmony_ci/** 1631800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest124 1632800b99b8Sopenharmony_ci* @tc.desc: Test get crash object 1633800b99b8Sopenharmony_ci* @tc.type: FUNC 1634800b99b8Sopenharmony_ci*/ 1635800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest124, TestSize.Level2) 1636800b99b8Sopenharmony_ci{ 1637800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest124: start."; 1638800b99b8Sopenharmony_ci string cmd = "TestGetCrashObj"; 1639800b99b8Sopenharmony_ci string fileName; 1640800b99b8Sopenharmony_ci pid_t pid = TriggerCrasherAndGetFileName(cmd, CRASHER_CPP, fileName); 1641800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "test pid(" << pid << ")" << " cppcrash file name : " << fileName; 1642800b99b8Sopenharmony_ci if (pid < 0 || fileName.size() < CPPCRASH_FILENAME_MIN_LENGTH) { 1643800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Trigger Crash Failed."; 1644800b99b8Sopenharmony_ci FAIL(); 1645800b99b8Sopenharmony_ci } 1646800b99b8Sopenharmony_ci EXPECT_TRUE(CheckTestGetCrashObj(fileName, pid)) << "FaultLoggerdSystemTest124 Failed"; 1647800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest124: end."; 1648800b99b8Sopenharmony_ci} 1649800b99b8Sopenharmony_ci#endif 1650800b99b8Sopenharmony_ci 1651800b99b8Sopenharmony_ci/** 1652800b99b8Sopenharmony_ci* @tc.name: FaultLoggerdSystemTest125 1653800b99b8Sopenharmony_ci* @tc.desc: Test process exit after being killed 1654800b99b8Sopenharmony_ci* @tc.type: FUNC 1655800b99b8Sopenharmony_ci*/ 1656800b99b8Sopenharmony_ciHWTEST_F(FaultLoggerdSystemTest, FaultLoggerdSystemTest125, TestSize.Level2) 1657800b99b8Sopenharmony_ci{ 1658800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest125: start."; 1659800b99b8Sopenharmony_ci InstallTestHap("/data/FaultloggerdJsTest.hap"); 1660800b99b8Sopenharmony_ci string testBundleName = TEST_BUNDLE_NAME; 1661800b99b8Sopenharmony_ci string testAbiltyName = testBundleName + ".MainAbility"; 1662800b99b8Sopenharmony_ci for (int i = 0; i < 2; i++) { // 2 : check again 1663800b99b8Sopenharmony_ci int pid = LaunchTestHap(testAbiltyName, testBundleName); 1664800b99b8Sopenharmony_ci if (pid == 0) { 1665800b99b8Sopenharmony_ci GTEST_LOG_(ERROR) << "Failed to launch target hap."; 1666800b99b8Sopenharmony_ci continue; 1667800b99b8Sopenharmony_ci } 1668800b99b8Sopenharmony_ci kill(pid, SIGABRT); 1669800b99b8Sopenharmony_ci sleep(2); // 2 : sleep 2s 1670800b99b8Sopenharmony_ci int newPid = GetProcessPid(TEST_BUNDLE_NAME); 1671800b99b8Sopenharmony_ci EXPECT_NE(pid, newPid) << "FaultLoggerdSystemTest125 Failed"; 1672800b99b8Sopenharmony_ci } 1673800b99b8Sopenharmony_ci StopTestHap(TEST_BUNDLE_NAME); 1674800b99b8Sopenharmony_ci UninstallTestHap(TEST_BUNDLE_NAME); 1675800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "FaultLoggerdSystemTest125: end."; 1676800b99b8Sopenharmony_ci} 1677800b99b8Sopenharmony_ci} // namespace HiviewDFX 1678800b99b8Sopenharmony_ci} // namespace OHOS 1679