1800b99b8Sopenharmony_ci/* 2800b99b8Sopenharmony_ci * Copyright (c) 2022 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 <gtest/gtest.h> 17800b99b8Sopenharmony_ci#include <ctime> 18800b99b8Sopenharmony_ci#include <securec.h> 19800b99b8Sopenharmony_ci#include <string> 20800b99b8Sopenharmony_ci#include <vector> 21800b99b8Sopenharmony_ci#include "dfx_ptrace.h" 22800b99b8Sopenharmony_ci#include "dfx_regs.h" 23800b99b8Sopenharmony_ci 24800b99b8Sopenharmony_ciusing namespace OHOS::HiviewDFX; 25800b99b8Sopenharmony_ciusing namespace testing::ext; 26800b99b8Sopenharmony_ciusing namespace std; 27800b99b8Sopenharmony_ci 28800b99b8Sopenharmony_cinamespace OHOS { 29800b99b8Sopenharmony_cinamespace HiviewDFX { 30800b99b8Sopenharmony_ciclass DfxRegsTest : public testing::Test { 31800b99b8Sopenharmony_cipublic: 32800b99b8Sopenharmony_ci static void SetUpTestCase(void) {} 33800b99b8Sopenharmony_ci static void TearDownTestCase(void) {} 34800b99b8Sopenharmony_ci void SetUp() {} 35800b99b8Sopenharmony_ci void TearDown() {} 36800b99b8Sopenharmony_ci}; 37800b99b8Sopenharmony_ci 38800b99b8Sopenharmony_cinamespace { 39800b99b8Sopenharmony_ci/** 40800b99b8Sopenharmony_ci * @tc.name: DfxRegsTest001 41800b99b8Sopenharmony_ci * @tc.desc: test DfxRegs SetRegsData & GetRegsData functions 42800b99b8Sopenharmony_ci * @tc.type: FUNC 43800b99b8Sopenharmony_ci */ 44800b99b8Sopenharmony_ciHWTEST_F(DfxRegsTest, DfxRegsTest001, TestSize.Level2) 45800b99b8Sopenharmony_ci{ 46800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest001: start."; 47800b99b8Sopenharmony_ci auto dfxRegs = DfxRegs::Create(); 48800b99b8Sopenharmony_ci ASSERT_NE(dfxRegs, nullptr); 49800b99b8Sopenharmony_ci std::vector<uintptr_t> setRegs {}; 50800b99b8Sopenharmony_ci for (size_t i = 0; i < 10; i++) { // test 10 regs 51800b99b8Sopenharmony_ci setRegs.push_back(i); 52800b99b8Sopenharmony_ci } 53800b99b8Sopenharmony_ci dfxRegs->SetRegsData(setRegs); 54800b99b8Sopenharmony_ci auto getRegs = dfxRegs->GetRegsData(); 55800b99b8Sopenharmony_ci ASSERT_EQ(setRegs, getRegs); 56800b99b8Sopenharmony_ci 57800b99b8Sopenharmony_ci uintptr_t regsData[REG_LAST] = { 0 }; 58800b99b8Sopenharmony_ci dfxRegs->SetRegsData(regsData, REG_LAST); 59800b99b8Sopenharmony_ci getRegs = dfxRegs->GetRegsData(); 60800b99b8Sopenharmony_ci for (size_t i = 0; i < getRegs.size(); i++) { 61800b99b8Sopenharmony_ci ASSERT_EQ(regsData[i], getRegs[i]); 62800b99b8Sopenharmony_ci } 63800b99b8Sopenharmony_ci 64800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest001: end."; 65800b99b8Sopenharmony_ci} 66800b99b8Sopenharmony_ci 67800b99b8Sopenharmony_ci/** 68800b99b8Sopenharmony_ci * @tc.name: DfxRegsTest002 69800b99b8Sopenharmony_ci * @tc.desc: test DfxRegs GetSpecialRegisterName 70800b99b8Sopenharmony_ci * @tc.type: FUNC 71800b99b8Sopenharmony_ci */ 72800b99b8Sopenharmony_ciHWTEST_F(DfxRegsTest, DfxRegsTest002, TestSize.Level2) 73800b99b8Sopenharmony_ci{ 74800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest002: start."; 75800b99b8Sopenharmony_ci auto dfxRegs = DfxRegs::Create(); 76800b99b8Sopenharmony_ci uintptr_t val = 0x00000001; 77800b99b8Sopenharmony_ci dfxRegs->SetPc(val); 78800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetPc(), val); 79800b99b8Sopenharmony_ci auto name = dfxRegs->GetSpecialRegsName(val); 80800b99b8Sopenharmony_ci ASSERT_EQ(name, "pc"); 81800b99b8Sopenharmony_ci 82800b99b8Sopenharmony_ci val = 0x00000002; 83800b99b8Sopenharmony_ci dfxRegs->SetSp(val); 84800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSp(), val); 85800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsName(val), "sp"); 86800b99b8Sopenharmony_ci ASSERT_EQ((*dfxRegs.get())[REG_SP], val); 87800b99b8Sopenharmony_ci ASSERT_GT(dfxRegs->RegsSize(), 0U); 88800b99b8Sopenharmony_ci uintptr_t *regVal = &val; 89800b99b8Sopenharmony_ci dfxRegs->SetReg(0, regVal); 90800b99b8Sopenharmony_ci ASSERT_EQ((*dfxRegs.get())[0], *regVal); 91800b99b8Sopenharmony_ci uintptr_t fp = 0x00000001; 92800b99b8Sopenharmony_ci uintptr_t lr = 0x00000002; 93800b99b8Sopenharmony_ci uintptr_t sp = 0x00000003; 94800b99b8Sopenharmony_ci uintptr_t pc = 0x00000004; 95800b99b8Sopenharmony_ci dfxRegs->SetSpecialRegs(fp, lr, sp, pc); 96800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsName(lr), "lr"); 97800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsName(fp), "fp"); 98800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsName(pc), "pc"); 99800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsName(sp), "sp"); 100800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsName(0x0), ""); 101800b99b8Sopenharmony_ci uintptr_t fpGet; 102800b99b8Sopenharmony_ci uintptr_t lrGet; 103800b99b8Sopenharmony_ci uintptr_t spGet; 104800b99b8Sopenharmony_ci uintptr_t pcGet; 105800b99b8Sopenharmony_ci dfxRegs->GetSpecialRegs(fpGet, lrGet, spGet, pcGet); 106800b99b8Sopenharmony_ci ASSERT_EQ(fp, fpGet); 107800b99b8Sopenharmony_ci ASSERT_EQ(lr, lrGet); 108800b99b8Sopenharmony_ci ASSERT_EQ(sp, spGet); 109800b99b8Sopenharmony_ci ASSERT_EQ(pc, pcGet); 110800b99b8Sopenharmony_ci ASSERT_FALSE(dfxRegs->PrintRegs().empty()); 111800b99b8Sopenharmony_ci ASSERT_FALSE(dfxRegs->PrintSpecialRegs().empty()); 112800b99b8Sopenharmony_ci#if defined(__arm__) || defined(__aarch64__) || defined(__riscv) 113800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsNameByIndex(REG_FP), "fp"); 114800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsNameByIndex(REG_LR), "lr"); 115800b99b8Sopenharmony_ci#endif 116800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsNameByIndex(REG_PC), "pc"); 117800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetSpecialRegsNameByIndex(REG_SP), "sp"); 118800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest002: end."; 119800b99b8Sopenharmony_ci} 120800b99b8Sopenharmony_ci 121800b99b8Sopenharmony_ci/** 122800b99b8Sopenharmony_ci * @tc.name: DfxRegsTest003 123800b99b8Sopenharmony_ci * @tc.desc: test DfxRegs CreateFromUcontext 124800b99b8Sopenharmony_ci * @tc.type: FUNC 125800b99b8Sopenharmony_ci */ 126800b99b8Sopenharmony_ciHWTEST_F(DfxRegsTest, DfxRegsTest003, TestSize.Level2) 127800b99b8Sopenharmony_ci{ 128800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest003: start."; 129800b99b8Sopenharmony_ci 130800b99b8Sopenharmony_ci ucontext_t context; 131800b99b8Sopenharmony_ci#if defined(__arm__) 132800b99b8Sopenharmony_ci context.uc_mcontext.arm_r0 = 0; // 0 : the 1st register of arm 133800b99b8Sopenharmony_ci context.uc_mcontext.arm_r1 = 1; // 1 : the 2st register of arm 134800b99b8Sopenharmony_ci context.uc_mcontext.arm_r2 = 2; // 2 : the 3st register of arm 135800b99b8Sopenharmony_ci context.uc_mcontext.arm_r3 = 3; // 3 : the 4st register of arm 136800b99b8Sopenharmony_ci context.uc_mcontext.arm_r4 = 4; // 4 : the 5st register of arm 137800b99b8Sopenharmony_ci context.uc_mcontext.arm_r5 = 5; // 5 : the 6st register of arm 138800b99b8Sopenharmony_ci context.uc_mcontext.arm_r6 = 6; // 6 : the 7st register of arm 139800b99b8Sopenharmony_ci context.uc_mcontext.arm_r7 = 7; // 7 : the 8st register of arm 140800b99b8Sopenharmony_ci context.uc_mcontext.arm_r8 = 8; // 8 : the 9st register of arm 141800b99b8Sopenharmony_ci context.uc_mcontext.arm_r9 = 9; // 9 : the 10st register of arm 142800b99b8Sopenharmony_ci context.uc_mcontext.arm_r10 = 10; // 10 : the 11st register of arm 143800b99b8Sopenharmony_ci context.uc_mcontext.arm_fp = 11; // 11 : the 12st register of arm 144800b99b8Sopenharmony_ci context.uc_mcontext.arm_ip = 12; // 12 : the 13st register of arm 145800b99b8Sopenharmony_ci context.uc_mcontext.arm_sp = 13; // 13 : the 14st register of arm 146800b99b8Sopenharmony_ci context.uc_mcontext.arm_lr = 14; // 14 : the 15st register of arm 147800b99b8Sopenharmony_ci context.uc_mcontext.arm_pc = 15; // 15 : the 16st register of arm 148800b99b8Sopenharmony_ci#elif defined(__aarch64__) 149800b99b8Sopenharmony_ci for (int i = 0; i < 31; i++) { 150800b99b8Sopenharmony_ci context.uc_mcontext.regs[i] = i; 151800b99b8Sopenharmony_ci } 152800b99b8Sopenharmony_ci context.uc_mcontext.sp = 31; // 31 : the 32st register of aarch64 153800b99b8Sopenharmony_ci context.uc_mcontext.pc = 32; // 32 : the 33st register of aarch64 154800b99b8Sopenharmony_ci#elif defined(__x86_64__) 155800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RAX] = 0; // 0 : the 1st register of x86_64 156800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RDX] = 1; // 1 : the 2st register of x86_64 157800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RCX] = 2; // 2 : the 3st register of x86_64 158800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RBX] = 3; // 3 : the 4st register of x86_64 159800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RSI] = 4; // 4 : the 5st register of x86_64 160800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RDI] = 5; // 5 : the 6st register of x86_64 161800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RBP] = 6; // 6 : the 7st register of x86_64 162800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RSP] = 7; // 7 : the 8st register of x86_64 163800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R8] = 8; // 8 : the 9st register of x86_64 164800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R9] = 9; // 9 : the 10st register of x86_64 165800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R10] = 10; // 10 : the 11st register of x86_64 166800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R11] = 11; // 11 : the 12st register of x86_64 167800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R12] = 12; // 12 : the 13st register of x86_64 168800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R13] = 13; // 13 : the 14st register of x86_64 169800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R14] = 14; // 14 : the 15st register of x86_64 170800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_R15] = 15; // 15 : the 16st register of x86_64 171800b99b8Sopenharmony_ci context.uc_mcontext.gregs[REG_RIP] = 16; // 16 : the 17st register of x86_64 172800b99b8Sopenharmony_ci#endif 173800b99b8Sopenharmony_ci auto dfxRegs = DfxRegs::CreateFromUcontext(context); 174800b99b8Sopenharmony_ci for (size_t i = 0; i < REG_LAST; i++) { 175800b99b8Sopenharmony_ci ASSERT_EQ((*dfxRegs.get())[i], i); 176800b99b8Sopenharmony_ci } 177800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest003: end."; 178800b99b8Sopenharmony_ci} 179800b99b8Sopenharmony_ci 180800b99b8Sopenharmony_ci/** 181800b99b8Sopenharmony_ci * @tc.name: DfxRegsTest004 182800b99b8Sopenharmony_ci * @tc.desc: test DfxRegs SetFromQutMiniRegs SetFromFpMiniRegs 183800b99b8Sopenharmony_ci * @tc.type: FUNC 184800b99b8Sopenharmony_ci */ 185800b99b8Sopenharmony_ciHWTEST_F(DfxRegsTest, DfxRegsTest004, TestSize.Level2) 186800b99b8Sopenharmony_ci{ 187800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest004: start."; 188800b99b8Sopenharmony_ci#if defined(__arm__) 189800b99b8Sopenharmony_ci uintptr_t pushRegs[QUT_MINI_REGS_SIZE]; 190800b99b8Sopenharmony_ci for (size_t i = 0; i < QUT_MINI_REGS_SIZE; ++i) { 191800b99b8Sopenharmony_ci pushRegs[i] = i + 1; 192800b99b8Sopenharmony_ci } 193800b99b8Sopenharmony_ci uintptr_t qutRegs[QUT_MINI_REGS_SIZE] = {REG_ARM_R4, REG_ARM_R7, REG_ARM_R10, REG_ARM_R11, 194800b99b8Sopenharmony_ci REG_SP, REG_PC, REG_LR}; 195800b99b8Sopenharmony_ci uintptr_t fpRegs[FP_MINI_REGS_SIZE] = {REG_ARM_R7, REG_FP, REG_SP, REG_PC}; 196800b99b8Sopenharmony_ci auto dfxregsArm = std::make_shared<DfxRegsArm>(); 197800b99b8Sopenharmony_ci dfxregsArm->SetFromQutMiniRegs(pushRegs, QUT_MINI_REGS_SIZE); 198800b99b8Sopenharmony_ci for (size_t i = 0; i < sizeof(qutRegs) / sizeof(qutRegs[0]); ++i) { 199800b99b8Sopenharmony_ci ASSERT_EQ((*dfxregsArm.get())[qutRegs[i]], pushRegs[i]); 200800b99b8Sopenharmony_ci } 201800b99b8Sopenharmony_ci dfxregsArm->SetFromFpMiniRegs(pushRegs, FP_MINI_REGS_SIZE); 202800b99b8Sopenharmony_ci for (size_t i = 0; i < sizeof(fpRegs) / sizeof(fpRegs[0]); ++i) { 203800b99b8Sopenharmony_ci ASSERT_EQ((*dfxregsArm.get())[fpRegs[i]], pushRegs[i]); 204800b99b8Sopenharmony_ci } 205800b99b8Sopenharmony_ci 206800b99b8Sopenharmony_ci#elif defined(__aarch64__) 207800b99b8Sopenharmony_ci uintptr_t pushRegs[QUT_MINI_REGS_SIZE]; 208800b99b8Sopenharmony_ci for (size_t i = 0; i < QUT_MINI_REGS_SIZE; ++i) { 209800b99b8Sopenharmony_ci pushRegs[i] = i; 210800b99b8Sopenharmony_ci } 211800b99b8Sopenharmony_ci uintptr_t qutRegs[QUT_MINI_REGS_SIZE] = {REG_AARCH64_X0, REG_AARCH64_X20, REG_AARCH64_X28, 212800b99b8Sopenharmony_ci REG_FP, REG_SP, REG_AARCH64_PC, REG_LR}; 213800b99b8Sopenharmony_ci uintptr_t fpRegs[FP_MINI_REGS_SIZE] = {REG_FP, REG_LR, REG_SP, REG_PC}; 214800b99b8Sopenharmony_ci auto dfxregsArm64 = std::make_shared<DfxRegsArm64>(); 215800b99b8Sopenharmony_ci dfxregsArm64->SetFromQutMiniRegs(pushRegs, QUT_MINI_REGS_SIZE); 216800b99b8Sopenharmony_ci for (size_t i = 1; i < sizeof(qutRegs) / sizeof(qutRegs[0]); ++i) { 217800b99b8Sopenharmony_ci ASSERT_EQ((*dfxregsArm64.get())[qutRegs[i]], pushRegs[i]); 218800b99b8Sopenharmony_ci } 219800b99b8Sopenharmony_ci dfxregsArm64->SetFromFpMiniRegs(pushRegs, FP_MINI_REGS_SIZE); 220800b99b8Sopenharmony_ci for (size_t i = 0; i < sizeof(fpRegs) / sizeof(fpRegs[0]); ++i) { 221800b99b8Sopenharmony_ci ASSERT_EQ((*dfxregsArm64.get())[fpRegs[i]], pushRegs[i]); 222800b99b8Sopenharmony_ci } 223800b99b8Sopenharmony_ci#endif 224800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest004: end."; 225800b99b8Sopenharmony_ci} 226800b99b8Sopenharmony_ci 227800b99b8Sopenharmony_ci/** 228800b99b8Sopenharmony_ci * @tc.name: DfxRegsTest005 229800b99b8Sopenharmony_ci * @tc.desc: test DfxRegs CreateFromRegs 230800b99b8Sopenharmony_ci * @tc.type: FUNC 231800b99b8Sopenharmony_ci */ 232800b99b8Sopenharmony_ciHWTEST_F(DfxRegsTest, DfxRegsTest005, TestSize.Level2) 233800b99b8Sopenharmony_ci{ 234800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest005: start."; 235800b99b8Sopenharmony_ci#if defined(__arm__) 236800b99b8Sopenharmony_ci uintptr_t regs[QUT_MINI_REGS_SIZE]; 237800b99b8Sopenharmony_ci for (size_t i = 0; i < QUT_MINI_REGS_SIZE; ++i) { 238800b99b8Sopenharmony_ci regs[i] = i + 1; 239800b99b8Sopenharmony_ci } 240800b99b8Sopenharmony_ci uintptr_t minimal[QUT_MINI_REGS_SIZE] = {REG_ARM_R4, REG_ARM_R7, REG_ARM_R10, REG_ARM_R11, 241800b99b8Sopenharmony_ci REG_SP, REG_PC, REG_LR}; 242800b99b8Sopenharmony_ci uintptr_t framePointer[FP_MINI_REGS_SIZE] = {REG_ARM_R7, REG_FP, REG_SP, REG_PC}; 243800b99b8Sopenharmony_ci auto dfxRegs = DfxRegs::CreateFromRegs(UnwindMode::FRAMEPOINTER_UNWIND, regs, sizeof(regs) / sizeof(regs[0])); 244800b99b8Sopenharmony_ci for (size_t i = 0; i < sizeof(framePointer) / sizeof(framePointer[0]); ++i) { 245800b99b8Sopenharmony_ci ASSERT_EQ((*dfxRegs.get())[framePointer[i]], regs[i]); 246800b99b8Sopenharmony_ci } 247800b99b8Sopenharmony_ci dfxRegs = DfxRegs::CreateFromRegs(UnwindMode::MINIMAL_UNWIND, regs, sizeof(regs) / sizeof(regs[0])); 248800b99b8Sopenharmony_ci for (size_t i = 0; i < sizeof(minimal) / sizeof(minimal[0]); ++i) { 249800b99b8Sopenharmony_ci ASSERT_EQ((*dfxRegs.get())[minimal[i]], regs[i]); 250800b99b8Sopenharmony_ci } 251800b99b8Sopenharmony_ci 252800b99b8Sopenharmony_ci#elif defined(__aarch64__) 253800b99b8Sopenharmony_ci uintptr_t regs[QUT_MINI_REGS_SIZE]; 254800b99b8Sopenharmony_ci for (size_t i = 0; i < QUT_MINI_REGS_SIZE; ++i) { 255800b99b8Sopenharmony_ci regs[i] = i; 256800b99b8Sopenharmony_ci } 257800b99b8Sopenharmony_ci uintptr_t minimal[QUT_MINI_REGS_SIZE] = {REG_AARCH64_X0, REG_AARCH64_X20, REG_AARCH64_X28, 258800b99b8Sopenharmony_ci REG_FP, REG_SP, REG_PC, REG_LR}; 259800b99b8Sopenharmony_ci uintptr_t framePointer[FP_MINI_REGS_SIZE] = {REG_FP, REG_LR, REG_SP, REG_PC}; 260800b99b8Sopenharmony_ci auto dfxRegs = DfxRegs::CreateFromRegs(UnwindMode::FRAMEPOINTER_UNWIND, regs, sizeof(regs) / sizeof(regs[0])); 261800b99b8Sopenharmony_ci for (size_t i = 1; i < sizeof(framePointer) / sizeof(framePointer[0]); ++i) { 262800b99b8Sopenharmony_ci ASSERT_EQ((*dfxRegs.get())[framePointer[i]], regs[i]); 263800b99b8Sopenharmony_ci } 264800b99b8Sopenharmony_ci dfxRegs = DfxRegs::CreateFromRegs(UnwindMode::MINIMAL_UNWIND, regs, sizeof(regs) / sizeof(regs[0])); 265800b99b8Sopenharmony_ci for (size_t i = 0; i < sizeof(minimal) / sizeof(minimal[0]); ++i) { 266800b99b8Sopenharmony_ci ASSERT_EQ((*dfxRegs.get())[minimal[i]], regs[i]); 267800b99b8Sopenharmony_ci } 268800b99b8Sopenharmony_ci#endif 269800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest005: end."; 270800b99b8Sopenharmony_ci} 271800b99b8Sopenharmony_ci 272800b99b8Sopenharmony_ci 273800b99b8Sopenharmony_ci/** 274800b99b8Sopenharmony_ci * @tc.name: DfxRegsTest006 275800b99b8Sopenharmony_ci * @tc.desc: test DfxRegs CreateRemoteRegs 276800b99b8Sopenharmony_ci * @tc.type: FUNC 277800b99b8Sopenharmony_ci */ 278800b99b8Sopenharmony_ciHWTEST_F(DfxRegsTest, DfxRegsTest006, TestSize.Level2) 279800b99b8Sopenharmony_ci{ 280800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest006: start."; 281800b99b8Sopenharmony_ci static pid_t pid = getpid(); 282800b99b8Sopenharmony_ci pid_t child = fork(); 283800b99b8Sopenharmony_ci if (child == 0) { 284800b99b8Sopenharmony_ci DfxPtrace::Attach(pid); 285800b99b8Sopenharmony_ci auto dfxRegs = DfxRegs::CreateRemoteRegs(pid); 286800b99b8Sopenharmony_ci constexpr size_t maxIdx = 100; 287800b99b8Sopenharmony_ci ASSERT_NE(dfxRegs->GetReg(0), nullptr); 288800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetReg(maxIdx), nullptr); 289800b99b8Sopenharmony_ci uintptr_t value = 0; 290800b99b8Sopenharmony_ci dfxRegs->SetReg(maxIdx, &value); 291800b99b8Sopenharmony_ci uintptr_t fp = 0x80; 292800b99b8Sopenharmony_ci dfxRegs->SetFp(fp); 293800b99b8Sopenharmony_ci ASSERT_EQ(dfxRegs->GetFp(), fp); 294800b99b8Sopenharmony_ci DfxPtrace::Detach(pid); 295800b99b8Sopenharmony_ci _exit(0); 296800b99b8Sopenharmony_ci } 297800b99b8Sopenharmony_ci int status; 298800b99b8Sopenharmony_ci int ret = wait(&status); 299800b99b8Sopenharmony_ci ASSERT_EQ(status, 0); 300800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "Status:" << status << " Result:" << ret; 301800b99b8Sopenharmony_ci GTEST_LOG_(INFO) << "DfxRegsTest006: end."; 302800b99b8Sopenharmony_ci} 303800b99b8Sopenharmony_ci} 304800b99b8Sopenharmony_ci} // namespace HiviewDFX 305800b99b8Sopenharmony_ci} // namespace OHOS 306