• 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 namespace OHOS {
32 namespace Developtools {
33 namespace HiPerf {
34 class UniqueStackTableTest : public testing::Test {
35 public:
36     static void SetUpTestCase(void);
37     static void TearDownTestCase(void);
38     void SetUp();
39     void TearDown();
40 };
41 
SetUpTestCase()42 void UniqueStackTableTest::SetUpTestCase()
43 {
44 }
45 
TearDownTestCase()46 void UniqueStackTableTest::TearDownTestCase() {}
47 
SetUp()48 void UniqueStackTableTest::SetUp()
49 {
50 }
51 
TearDown()52 void UniqueStackTableTest::TearDown()
53 {
54 }
55 
56 /**
57  * @tc.name: Test_Normal
58  * @tc.desc: Test stack compress normal function
59  * @tc.type: FUNC
60  */
61 HWTEST_F(UniqueStackTableTest, Test_Normal, TestSize.Level0)
62 {
63     u64 baseips[] = {0x6bcc,
64                     0x35A8,
65                     0x880,
66                     0x04};
67 
68     u64 partips[] = {0x01,
69                     0x02,
70                     0x03};
71 
72     u64 partips1[] = {0x02,
73                     0x03,
74                     0x04};
75 
76     std::shared_ptr<UniqueStackTable> table = std::make_shared<UniqueStackTable>(1);
77 
78     StackId stackId = {0};
79     StackId stackIdpart = {0};
80     StackId stackIdpart1 = {0};
81 
82     EXPECT_NE(table->PutIpsInTable(&stackId, baseips, sizeof(baseips)/sizeof(uint64_t)), 0);
83     EXPECT_NE(table->PutIpsInTable(&stackIdpart, partips, sizeof(partips)/sizeof(uint64_t)), 0);
84     EXPECT_NE(table->PutIpsInTable(&stackIdpart1, partips1, sizeof(partips1)/sizeof(uint64_t)), 0);
85     EXPECT_NE(stackId.value, 0);
86     EXPECT_NE(stackIdpart.value, 0);
87     EXPECT_NE(stackIdpart1.value, 0);
88 
89     std::vector<u64> checkbaseips;
90     std::vector<u64> checkpartips;
91     std::vector<u64> checkpartips1;
92     table->GetIpsByStackId(stackId, checkbaseips);
93     table->GetIpsByStackId(stackIdpart, checkpartips);
94     table->GetIpsByStackId(stackIdpart1, checkpartips1);
95 
96     EXPECT_EQ(memcmp(baseips, checkbaseips.data(), checkbaseips.size()*sizeof(u64)), 0);
97 }
98 
99 HWTEST_F(UniqueStackTableTest, Test_Resize, TestSize.Level1)
100 {
101     uint32_t maxsize = 64 * 1024 * 1024;
102     std::shared_ptr<UniqueStackTable> table = std::make_shared<UniqueStackTable>(1, maxsize);
103     EXPECT_EQ(table->Resize(), false);
104 }
105 
106 HWTEST_F(UniqueStackTableTest, Test_Oversize, TestSize.Level2)
107 {
108     uint32_t oversize = 128 * 1024 * 1024;
109     std::shared_ptr<UniqueStackTable> table = std::make_shared<UniqueStackTable>(1, oversize);
110 
111     u64 baseips[] = {0x6bcc,
112                     0x35A8,
113                     0x880,
114                     0x04};
115     StackId stackId = {0};
116 
117     EXPECT_EQ(table->PutIpsInTable(&stackId, baseips, sizeof(baseips)/sizeof(uint64_t)), 0);
118 }
119 
120 } // namespace HiPerf
121 } // namespace Developtools
122 } // namespace OHOS
123