• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <ctime>
18 #include <securec.h>
19 #include <string>
20 #include <vector>
21 
22 #include "dfx_regs.h"
23 #include "dfx_regs_define.h"
24 
25 using namespace OHOS::HiviewDFX;
26 using namespace testing::ext;
27 using namespace std;
28 
29 namespace OHOS {
30 namespace HiviewDFX {
31 class DfxRegsTest : public testing::Test {
32 public:
SetUpTestCase(void)33     static void SetUpTestCase(void) {}
TearDownTestCase(void)34     static void TearDownTestCase(void) {}
SetUp()35     void SetUp() {}
TearDown()36     void TearDown() {}
37 };
38 
39 namespace {
40 /**
41  * @tc.name: DfxRegsTest001
42  * @tc.desc: test DfxRegs SetRegsData & GetRegsData functions
43  * @tc.type: FUNC
44  */
45 HWTEST_F(DfxRegsTest, DfxRegsTest001, TestSize.Level2)
46 {
47     GTEST_LOG_(INFO) << "DfxRegsTest001: start.";
48     auto dfxRegs = DfxRegs::Create();
49     ASSERT_NE(dfxRegs, nullptr);
50     std::vector<uintptr_t> setRegs {};
51     for (size_t i = 0; i < 10; i++) { // test 10 regs
52         setRegs.push_back(i);
53     }
54     dfxRegs->SetRegsData(setRegs);
55     auto getRegs = dfxRegs->GetRegsData();
56     ASSERT_EQ(setRegs, getRegs);
57     GTEST_LOG_(INFO) << "DfxRegsTest001: end.";
58 }
59 
60 /**
61  * @tc.name: DfxRegsTest002
62  * @tc.desc: test DfxRegs GetSpecialRegisterName
63  * @tc.type: FUNC
64  */
65 HWTEST_F(DfxRegsTest, DfxRegsTest002, TestSize.Level2)
66 {
67     GTEST_LOG_(INFO) << "DfxRegsTest002: start.";
68     auto dfxRegs = DfxRegs::Create();
69     uintptr_t val = 0x00000001;
70     dfxRegs->pc_ = val;
71     auto name = dfxRegs->GetSpecialRegisterName(val);
72     ASSERT_EQ(name, "pc");
73     GTEST_LOG_(INFO) << "DfxRegsTest002: end.";
74 }
75 }
76 } // namespace HiviewDFX
77 } // namespace OHOS
78