1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include <string> 18 #include <unistd.h> 19 #include <vector> 20 21 #include "dfx_buffer_writer.h" 22 #include "dfx_cutil.h" 23 #include "dfx_define.h" 24 #include "dfx_test_util.h" 25 #include "dfx_util.h" 26 #include "decorative_dump_info.h" 27 #include "process_dump_config.h" 28 29 using namespace OHOS::HiviewDFX; 30 using namespace testing::ext; 31 using namespace std; 32 33 namespace OHOS { 34 namespace HiviewDFX { 35 class ProcessDumpConfigTest : public testing::Test { 36 public: SetUpTestCase(void)37 static void SetUpTestCase(void) {} TearDownTestCase(void)38 static void TearDownTestCase(void) {} SetUp()39 void SetUp() {} TearDown()40 void TearDown() {} 41 }; 42 } // namespace HiviewDFX 43 } // namespace OHOS 44 45 namespace { 46 /** 47 * @tc.name: ProcessDumpConfigTest001 48 * @tc.desc: test process dump config 49 * @tc.type: FUNC 50 */ 51 HWTEST_F(ProcessDumpConfigTest, ProcessDumpConfigTest001, TestSize.Level2) 52 { 53 GTEST_LOG_(INFO) << "ProcessDumpConfigTest001: start."; 54 auto config = ProcessDumpConfig::GetInstance().GetConfig(); 55 ASSERT_EQ(config.extendPcLrPrinting, false); 56 ASSERT_EQ(config.faultStackHighAddrStep, 512); 57 ASSERT_EQ(config.faultStackLowAddrStep, 32); 58 ASSERT_EQ(config.maxFrameNums, 256); 59 ASSERT_EQ(config.logFileCutoffSizeBytes, 0); 60 ASSERT_EQ(config.simplifyVmaPrinting, false); 61 ASSERT_EQ(config.reservedParseSymbolTime, 100); 62 std::vector<std::string> dumpInfoCppCrash = { 63 "KeyThreadDumpInfo", "DumpInfoHeader", "SubmitterStack", 64 "Registers", "ExtraCrashInfo", "OtherThreadDumpInfo", 65 "MemoryNearRegister", "FaultStack", "Maps", "OpenFiles", 66 }; 67 ASSERT_EQ(dumpInfoCppCrash, config.dumpInfo[ProcessDumpType::DUMP_TYPE_CPP_CRASH]); 68 69 std::vector<std::string> dumpInfoDumpCatch = { 70 "KeyThreadDumpInfo", "DumpInfoHeader", "OtherThreadDumpInfo", 71 }; 72 ASSERT_EQ(dumpInfoDumpCatch, config.dumpInfo[ProcessDumpType::DUMP_TYPE_DUMP_CATCH]); 73 74 std::vector<std::string> dumpInfoMemLeak = { 75 "KeyThreadDumpInfo", "DumpInfoHeader", "Registers", 76 "MemoryNearRegister", "FaultStack", "Maps", 77 }; 78 ASSERT_EQ(dumpInfoMemLeak, config.dumpInfo[ProcessDumpType::DUMP_TYPE_MEM_LEAK]); 79 80 std::vector<std::string> dumpInfoFdSan = { 81 "KeyThreadDumpInfo", "DumpInfoHeader", "Registers", 82 "MemoryNearRegister", "FaultStack", "Maps", "OpenFiles", 83 }; 84 ASSERT_EQ(dumpInfoFdSan, config.dumpInfo[ProcessDumpType::DUMP_TYPE_FDSAN]); 85 86 std::vector<std::string> dumpInfoJeMalloc = { 87 "KeyThreadDumpInfo", "DumpInfoHeader", "Registers", 88 "MemoryNearRegister", "FaultStack", "Maps", 89 }; 90 ASSERT_EQ(dumpInfoJeMalloc, config.dumpInfo[ProcessDumpType::DUMP_TYPE_JEMALLOC]); 91 92 std::vector<std::string> dumpInfoBadFd = { 93 "KeyThreadDumpInfo", "DumpInfoHeader", "Registers", 94 "MemoryNearRegister", "FaultStack", "Maps", "OpenFiles", 95 }; 96 ASSERT_EQ(dumpInfoBadFd, config.dumpInfo[ProcessDumpType::DUMP_TYPE_BADFD]); 97 98 std::vector<std::string> dumpInfoCoreDump = { 99 "KeyThreadDumpInfo", "Registers", "OtherThreadDumpInfo", 100 }; 101 ASSERT_EQ(dumpInfoCoreDump, config.dumpInfo[ProcessDumpType::DUMP_TYPE_COREDUMP]); 102 GTEST_LOG_(INFO) << "ProcessDumpConfigTest001: end."; 103 } 104 } 105