From f7c3454a4e45f06036ce78d16cbfe4f44cabaa40 Mon Sep 17 00:00:00 2001 From: wangqing Date: Mon, 23 Dec 2024 16:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=8D=E5=90=8C=E6=B2=99?= =?UTF-8?q?=E7=AE=B1=E8=BF=9B=E7=A8=8Bdumpcatcher=E6=8A=93=E6=A0=88ST?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangqing Change-Id: Id18c304896e2b16bba859af11d7905db4f118bb6 --- test/systemtest/dumpcatcher_system_test.cpp | 60 +++++++++++++++++++++ test/utils/dfx_test_util.cpp | 11 ++++ test/utils/dfx_test_util.h | 1 + 3 files changed, 72 insertions(+) diff --git a/test/systemtest/dumpcatcher_system_test.cpp b/test/systemtest/dumpcatcher_system_test.cpp index 7f3b2c291..cc885cf94 100644 --- a/test/systemtest/dumpcatcher_system_test.cpp +++ b/test/systemtest/dumpcatcher_system_test.cpp @@ -1361,6 +1361,66 @@ HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest049, TestSize.Level2) GTEST_LOG_(INFO) << "DumpCatcherSystemTest049: end."; } +/** + * @tc.name: DumpCatcherSystemTest050 + * @tc.desc: test dumpcatcher command for system sandbox process + * @tc.type: FUNC + */ +HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest050, TestSize.Level2) +{ + GTEST_LOG_(INFO) << "DumpCatcherSystemTest050: start."; + string getPidCMD = "pidof netmanager"; + string pid = ExecuteCommands(getPidCMD); + GTEST_LOG_(INFO) << "The pid of netmanager process: " << pid; + string procCMD = "dumpcatcher -p " + pid; + string procDumpLog = ExecuteCommands(procCMD); + GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog; + string keyword = "Tid"; + int numOfTid = GetKeywordCount(procDumpLog, keyword); + EXPECT_GE(numOfTid, 2) << "DumpCatcherSystemTest050 Failed"; + GTEST_LOG_(INFO) << "DumpCatcherSystemTest050: end."; +} + +/** + * @tc.name: DumpCatcherSystemTest051 + * @tc.desc: test dumpcatcher command for chipset sandbox process + * @tc.type: FUNC + */ +HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest051, TestSize.Level2) +{ + GTEST_LOG_(INFO) << "DumpCatcherSystemTest051: start."; + string getPidCMD = "pidof wifi_host"; + string pid = ExecuteCommands(getPidCMD); + GTEST_LOG_(INFO) << "The pid of wifi_host process: " << pid; + string procCMD = "dumpcatcher -p " + pid; + string procDumpLog = ExecuteCommands(procCMD); + GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog; + string keyword = "Tid"; + int numOfTid = GetKeywordCount(procDumpLog, keyword); + EXPECT_GE(numOfTid, 2) << "DumpCatcherSystemTest051 Failed"; + GTEST_LOG_(INFO) << "DumpCatcherSystemTest051: end."; +} + +/** + * @tc.name: DumpCatcherSystemTest052 + * @tc.desc: test dumpcatcher command for appdata sandbox process + * @tc.type: FUNC + */ +HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest052, TestSize.Level2) +{ + GTEST_LOG_(INFO) << "DumpCatcherSystemTest052: start."; + string getPidCMD = "pidof com.ohos.medialibrary.medialibrarydata"; + string pid = ExecuteCommands(getPidCMD); + GTEST_LOG_(INFO) << "The pid of com.ohos.medialibrary.medialibrarydata process: " << pid; + string procCMD = "dumpcatcher -p " + pid; + string procDumpLog = ExecuteCommands(procCMD); + GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog; + string keyword = "Tid"; + int numOfTid = GetKeywordCount(procDumpLog, keyword); + EXPECT_GE(numOfTid, 2) << "DumpCatcherSystemTest052 Failed"; + GTEST_LOG_(INFO) << "DumpCatcherSystemTest052: end."; +} + /** * @tc.name: DumpCatcherSystemTest101 * @tc.desc: test using dumpcatcher command tools to dump the signal stop process diff --git a/test/utils/dfx_test_util.cpp b/test/utils/dfx_test_util.cpp index 70acb4867..915f330d0 100644 --- a/test/utils/dfx_test_util.cpp +++ b/test/utils/dfx_test_util.cpp @@ -209,6 +209,17 @@ int GetKeywordsNum(const std::string& msg, std::string *keywords, int length) return count; } +int GetKeywordCount(const std::string& msg, const std::string& keyword) +{ + int count = 0; + auto position = msg.find(keyword); + while (position != std::string::npos) { + ++count; + position = msg.find(keyword, position + 1); + } + return count; +} + std::string GetCppCrashFileName(const pid_t pid, const std::string& tempPath) { std::string filePath = ""; diff --git a/test/utils/dfx_test_util.h b/test/utils/dfx_test_util.h index 566b2fdc5..d86f629da 100644 --- a/test/utils/dfx_test_util.h +++ b/test/utils/dfx_test_util.h @@ -84,6 +84,7 @@ bool CheckProcessComm(int pid, const std::string& name); int CheckKeyWords(const std::string& filePath, std::string *keywords, int length, int minRegIdx); bool CheckContent(const std::string& content, const std::string& keyContent, bool checkExist); int GetKeywordsNum(const std::string& msg, std::string *keywords, int length); +int GetKeywordCount(const std::string& msg, const std::string& keyword); std::string GetCppCrashFileName(const pid_t pid, const std::string& tempPath = TEMP_DIR); uint32_t GetSelfFdCount(); uint32_t GetSelfMapsCount(); -- Gitee