• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "unique_stack_table_test.h"
17 
18 #include <algorithm>
19 #include <chrono>
20 #include <cinttypes>
21 #include <sched.h>
22 #include <sstream>
23 #include <thread>
24 
25 #include "command.h"
26 #include "debug_logger.h"
27 #include "utilities.h"
28 
29 using namespace std::literals::chrono_literals;
30 using namespace testing::ext;
31 using namespace std;
32 using namespace OHOS::HiviewDFX;
33 namespace OHOS {
34 namespace Developtools {
35 namespace HiPerf {
36 class UniqueStackTableTest : public testing::Test {
37 public:
38     static void SetUpTestCase(void);
39     static void TearDownTestCase(void);
40     void SetUp();
41     void TearDown();
42 };
43 
SetUpTestCase()44 void UniqueStackTableTest::SetUpTestCase()
45 {
46 }
47 
TearDownTestCase()48 void UniqueStackTableTest::TearDownTestCase() {}
49 
SetUp()50 void UniqueStackTableTest::SetUp()
51 {
52 }
53 
TearDown()54 void UniqueStackTableTest::TearDown()
55 {
56 }
57 
58 /**
59  * @tc.name: Test_Normal
60  * @tc.desc: Test stack compress normal function
61  * @tc.type: FUNC
62  */
63 HWTEST_F(UniqueStackTableTest, Test_Normal, TestSize.Level1)
64 {
65     u64 baseips[] = {0x6bcc,
66                     0x35A8,
67                     0x880,
68                     0x04};
69 
70     u64 partips[] = {0x01,
71                     0x02,
72                     0x03};
73 
74     u64 partips1[] = {0x02,
75                     0x03,
76                     0x04};
77 
78     std::shared_ptr<UniqueStackTable> table = std::make_shared<UniqueStackTable>(1);
79 
80     StackId stackId = {0};
81     StackId stackIdpart = {0};
82     StackId stackIdpart1 = {0};
83 
84     EXPECT_NE(table->PutIpsInTable(&stackId, baseips, sizeof(baseips)/sizeof(uint64_t)), 0);
85     EXPECT_NE(table->PutIpsInTable(&stackIdpart, partips, sizeof(partips)/sizeof(uint64_t)), 0);
86     EXPECT_NE(table->PutIpsInTable(&stackIdpart1, partips1, sizeof(partips1)/sizeof(uint64_t)), 0);
87     EXPECT_NE(stackId.value, 0);
88     EXPECT_NE(stackIdpart.value, 0);
89     EXPECT_NE(stackIdpart1.value, 0);
90 
91     std::vector<u64> checkbaseips;
92     std::vector<u64> checkpartips;
93     std::vector<u64> checkpartips1;
94     table->GetIpsByStackId(stackId, checkbaseips);
95     table->GetIpsByStackId(stackIdpart, checkpartips);
96     table->GetIpsByStackId(stackIdpart1, checkpartips1);
97 
98     EXPECT_EQ(memcmp(baseips, checkbaseips.data(), checkbaseips.size()*sizeof(u64)), 0);
99 }
100 
101 HWTEST_F(UniqueStackTableTest, Test_Resize, TestSize.Level1)
102 {
103     uint32_t maxsize = 64 * 1024 * 1024;
104     std::shared_ptr<UniqueStackTable> table = std::make_shared<UniqueStackTable>(1, maxsize);
105     EXPECT_EQ(table->Resize(), false);
106 }
107 
108 HWTEST_F(UniqueStackTableTest, Test_Oversize, TestSize.Level1)
109 {
110     uint32_t oversize = 128 * 1024 * 1024;
111     std::shared_ptr<UniqueStackTable> table = std::make_shared<UniqueStackTable>(1, oversize);
112 
113     u64 baseips[] = {0x6bcc,
114                     0x35A8,
115                     0x880,
116                     0x04};
117     StackId stackId = {0};
118 
119     EXPECT_EQ(table->PutIpsInTable(&stackId, baseips, sizeof(baseips)/sizeof(uint64_t)), 0);
120 }
121 
122 } // namespace HiPerf
123 } // namespace Developtools
124 } // namespace OHOS
125