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