From 91e7931281662354c5e7bb50f1ff1e3d5115b073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=84=9A=E8=80=85=40yj20200618?= Date: Wed, 24 Apr 2024 10:37:46 +0800 Subject: [PATCH] fix:Dumpcatch JSON return optimization and fix MST and add UT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 愚者@yj20200618 --- .../dump_catcher/dfx_dump_catcher.cpp | 10 +++++--- test/moduletest/faultloggerd_module_test.cpp | 1 + test/unittest/unwind/unwinder_test.cpp | 25 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp index afb72ceb..0588690a 100644 --- a/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp +++ b/interfaces/innerkits/dump_catcher/dfx_dump_catcher.cpp @@ -228,6 +228,11 @@ bool DfxDumpCatcher::DoDumpCatchRemote(int pid, int tid, std::string& msg, bool default: break; } + + if (!ret && isJson && msg != "") { + DFXLOG_INFO("%s :: %s json msg not empty!", DFXDUMPCATCHER_TAG.c_str(), __func__);\ + ret = true; + } DFXLOG_INFO("%s :: %s :: pid(%d) ret: %d", DFXDUMPCATCHER_TAG.c_str(), __func__, pid, ret); return ret; } @@ -360,12 +365,11 @@ bool DfxDumpCatcher::DoReadBuf(int fd, std::string& msg) bool DfxDumpCatcher::DoReadRes(int fd, bool &ret, std::string& msg) { int32_t res = DumpErrorCode::DUMP_ESUCCESS; - ssize_t nread = read(fd, &res, sizeof(res)); - if (nread != sizeof(res)) { + ssize_t nread = OHOS_TEMP_FAILURE_RETRY(read(fd, &res, sizeof(res))); + if (nread <= 0 || nread != sizeof(res)) { DFXLOG_WARN("%s :: %s :: read error", DFXDUMPCATCHER_TAG.c_str(), __func__); return false; } - if (res == DumpErrorCode::DUMP_ESUCCESS) { ret = true; } diff --git a/test/moduletest/faultloggerd_module_test.cpp b/test/moduletest/faultloggerd_module_test.cpp index c8b1cd0e..0c703331 100644 --- a/test/moduletest/faultloggerd_module_test.cpp +++ b/test/moduletest/faultloggerd_module_test.cpp @@ -150,6 +150,7 @@ HWTEST_F(FaultloggerdModuleTest, FaultloggerdClientFdRquestTest004, TestSize.Lev */ HWTEST_F(FaultloggerdModuleTest, FaultloggerdClientPipeFdRquestTest001, TestSize.Level0) { + sleep(10); RequestSdkDump(getpid(), getpid()); int32_t pipeFd = RequestPipeFd(getpid(), FaultLoggerPipeType::PIPE_FD_READ_BUF); ASSERT_NE(pipeFd, -1); diff --git a/test/unittest/unwind/unwinder_test.cpp b/test/unittest/unwind/unwinder_test.cpp index 09dd4ffc..af514de3 100644 --- a/test/unittest/unwind/unwinder_test.cpp +++ b/test/unittest/unwind/unwinder_test.cpp @@ -907,6 +907,31 @@ HWTEST_F(UnwinderTest, GetSymbolByPcTest001, TestSize.Level2) ASSERT_FALSE(unwinder->GetSymbolByPc(pc0, maps, funcName, funcOffset)); // Get elf is null GTEST_LOG_(INFO) << "GetSymbolByPcTest001: end."; } + +/** + * @tc.name: AccessMemTest001 + * @tc.desc: test unwinder AccessMem interface + * @tc.type: FUNC + */ +HWTEST_F(UnwinderTest, AccessMemTest001, TestSize.Level2) +{ + GTEST_LOG_(INFO) << "AccessMemTest001: start."; + auto unwinder = std::make_shared(); + auto acc = std::make_shared(); + auto memory = std::make_shared(acc); + uintptr_t val; + EXPECT_FALSE(memory->ReadReg(0, &val)); + uintptr_t regs[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa}; + UnwindContext ctx; + ctx.regs = DfxRegs::CreateFromRegs(UnwindMode::DWARF_UNWIND, regs); + memory->SetCtx(&ctx); + EXPECT_FALSE(memory->ReadReg(-1, &val)); + + uint8_t values[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8}; + uintptr_t addr = (uintptr_t)(&values[0]); + EXPECT_FALSE(unwinder->AccessMem(&memory, addr, nullptr)); + GTEST_LOG_(INFO) << "AccessMemTest001: end."; +} } // namespace HiviewDFX } // namepsace OHOS -- Gitee