diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp index db3cf89d4db95001c6f4a1df1e238ec44cd7c5ae..1703143ed0df81fa72827865517a5d29b4c94233 100644 --- a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp +++ b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp @@ -426,7 +426,9 @@ void DfxDumpCatcher::CollectKernelStack(pid_t pid, int waitMilliSeconds) void DfxDumpCatcher::AsyncGetAllTidKernelStack(pid_t pid, int waitMilliSeconds) { ReadProcessStatus(halfProcStatus_, pid); - ReadProcessWchan(halfProcWchan_, pid, false, true); + if (IsLinuxKernel()) { + ReadProcessWchan(halfProcWchan_, pid, false, true); + } if (g_asyncThreadRunning) { DFXLOG_INFO("pid(%d) get kernel stack thread is running, not get pid(%d)", g_kernelStackPid, pid); return; diff --git a/test/systemtest/dumpcatcher_system_test.cpp b/test/systemtest/dumpcatcher_system_test.cpp index b02945ed2bde3112e1c40456706a66708c9341d4..21946be5fbf138a9fea287f097d197b276f9519f 100644 --- a/test/systemtest/dumpcatcher_system_test.cpp +++ b/test/systemtest/dumpcatcher_system_test.cpp @@ -1379,10 +1379,15 @@ HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest101, TestSize.Level2) string procCMD = "dumpcatcher -p " + to_string(pid); string procDumpLog = ExecuteCommands(procCMD); GTEST_LOG_(INFO) << "procDumpLog: " << procDumpLog; - string log[] = { "Failed", "status:", "Name:", "nonvoluntary_ctxt_switches:", "wchan:", "Tid:" }; - int count = GetKeywordsNum(procDumpLog, log, sizeof(log) / sizeof(log[0])); + std::vector matchWords = { "Failed", "status:", "Name:", "nonvoluntary_ctxt_switches:" }; + if (IsLinuxKernel()) { + matchWords.emplace_back("wchan:"); + matchWords.emplace_back("Tid:"); + } + int matchCount = static_cast(matchWords.size()); + int count = GetKeywordsNum(procDumpLog, matchWords.data(), matchCount); kill(pid, SIGKILL); - EXPECT_EQ(count, sizeof(log) / sizeof(log[0])) << "DumpCatcherSystemTest101 Failed"; + EXPECT_EQ(count, matchCount) << "DumpCatcherSystemTest101 Failed"; GTEST_LOG_(INFO) << "DumpCatcherSystemTest101: end."; } @@ -1407,10 +1412,16 @@ HWTEST_F(DumpCatcherSystemTest, DumpCatcherSystemTest102, TestSize.Level2) GTEST_LOG_(ERROR) << "DumpCatcherSystemTest102: Failed to dump target process."; } GTEST_LOG_(INFO) << msg; - string log[] = { "timeout", "status:", "Name:", "nonvoluntary_ctxt_switches:", "wchan:", "Tid:" }; - int count = GetKeywordsNum(msg, log, sizeof(log) / sizeof(log[0])); + + std::vector matchWords = { "timeout", "status:", "Name:", "nonvoluntary_ctxt_switches:" }; + if (IsLinuxKernel()) { + matchWords.emplace_back("wchan:"); + matchWords.emplace_back("Tid:"); + } + int matchCount = static_cast(matchWords.size()); + int count = GetKeywordsNum(msg, matchWords.data(), matchCount); kill(pid, SIGKILL); - EXPECT_EQ(count, sizeof(log) / sizeof(log[0])) << "DumpCatcherSystemTest102 Failed"; + EXPECT_EQ(count, matchCount) << "DumpCatcherSystemTest102 Failed"; GTEST_LOG_(INFO) << "DumpCatcherSystemTest102: end."; } diff --git a/test/utils/dfx_test_util.cpp b/test/utils/dfx_test_util.cpp index 70acb486701f22941ee08b4097fd515838596188..eb49aace83649f787bcf82215f6d0f79c8a8758c 100644 --- a/test/utils/dfx_test_util.cpp +++ b/test/utils/dfx_test_util.cpp @@ -295,5 +295,21 @@ void CheckResourceUsage(uint32_t fdCount, uint32_t mapsCount, uint64_t memCount) printf("AfterTest Memory New: %lu\n", static_cast(curMemSize)); printf("Memory Old: %lu\n", static_cast(memCount)); } + +bool IsLinuxKernel() +{ + static bool isLinux = [] { + std::string content; + LoadStringFromFile("/proc/version", content); + if (content.empty()) { + return true; + } + if (content.find("Linux") != std::string::npos) { + return true; + } + return false; + }(); + return isLinux; +} } // namespace HiviewDFX } // namespace OHOS \ No newline at end of file diff --git a/test/utils/dfx_test_util.h b/test/utils/dfx_test_util.h index 566b2fdc502a669c4a477c8cdbd05bfbeac59d98..65971fb45f1fd9ac04dd31b3a220e28bc24704cb 100644 --- a/test/utils/dfx_test_util.h +++ b/test/utils/dfx_test_util.h @@ -89,6 +89,7 @@ uint32_t GetSelfFdCount(); uint32_t GetSelfMapsCount(); uint64_t GetSelfMemoryCount(); void CheckResourceUsage(uint32_t fdCount, uint32_t mapsCount, uint64_t memCount); +bool IsLinuxKernel(); } // namespace HiviewDFX } // namespace OHOS #endif // DFX_TEST_UTIL \ No newline at end of file