1 /*
2 * Copyright (c) 2021 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 /* This files is process dump map module unittest. */
17
18 #include "dfx_maps_test.h"
19
20 #include <memory>
21 #include <sys/types.h>
22 #include "dfx_maps.h"
23
24 using namespace OHOS::HiviewDFX;
25 using namespace testing::ext;
26 using namespace std;
27
SetUpTestCase(void)28 void DfxMapsTest::SetUpTestCase(void)
29 {
30 }
31
TearDownTestCase(void)32 void DfxMapsTest::TearDownTestCase(void)
33 {
34 }
35
SetUp(void)36 void DfxMapsTest::SetUp(void)
37 {
38 }
39
TearDown(void)40 void DfxMapsTest::TearDown(void)
41 {
42 }
43
44 /**
45 * @tc.name: DfxMapsRequestTest001
46 * @tc.desc: test get begin
47 * @tc.type: FUNC
48 */
49 HWTEST_F (DfxMapsTest, DfxMapsRequestTest001, TestSize.Level2)
50 {
51 GTEST_LOG_(INFO) << "DfxMapsRequestTest001: start.";
52 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
53 uint64_t input = 1;
54 uint64_t output = 0;
55 dfxmap->SetMapBegin(input);
56 output = dfxmap->GetMapBegin();
57 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest001 Failed";
58 GTEST_LOG_(INFO) << "DfxMapsRequestTest001: end.";
59 }
60
61 /**
62 * @tc.name: DfxMapsRequestTest002
63 * @tc.desc: test get begin
64 * @tc.type: FUNC
65 */
66 HWTEST_F (DfxMapsTest, DfxMapsRequestTest002, TestSize.Level2)
67 {
68 GTEST_LOG_(INFO) << "DfxMapsRequestTest002: start.";
69 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
70 uint64_t input = 165;
71 uint64_t output = 0;
72 dfxmap->SetMapBegin(input);
73 output = dfxmap->GetMapBegin();
74 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest002 Failed";
75 GTEST_LOG_(INFO) << "DfxMapsRequestTest002: end.";
76 }
77
78 /**
79 * @tc.name: DfxMapsRequestTest003
80 * @tc.desc: test get begin
81 * @tc.type: FUNC
82 */
83 HWTEST_F (DfxMapsTest, DfxMapsRequestTest003, TestSize.Level2)
84 {
85 GTEST_LOG_(INFO) << "DfxMapsRequestTest003: start.";
86 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
87 uint64_t input = -1;
88 uint64_t output = 0;
89 dfxmap->SetMapBegin(input);
90 output = dfxmap->GetMapBegin();
91 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest003 Failed";
92 GTEST_LOG_(INFO) << "DfxMapsRequestTest003: end.";
93 }
94
95 /**
96 * @tc.name: DfxMapsRequestTest004
97 * @tc.desc: test get begin
98 * @tc.type: FUNC
99 */
100 HWTEST_F (DfxMapsTest, DfxMapsRequestTest004, TestSize.Level2)
101 {
102 GTEST_LOG_(INFO) << "DfxMapsRequestTest004: start.";
103 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
104 uint64_t input = 1;
105 uint64_t output = 0;
106 dfxmap->SetMapEnd(input);
107 output = dfxmap->GetMapEnd();
108 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest004 Failed";
109 GTEST_LOG_(INFO) << "DfxMapsRequestTest004: end.";
110 }
111
112 /**
113 * @tc.name: DfxMapsRequestTest005
114 * @tc.desc: test get end
115 * @tc.type: FUNC
116 */
117 HWTEST_F (DfxMapsTest, DfxMapsRequestTest005, TestSize.Level2)
118 {
119 GTEST_LOG_(INFO) << "DfxMapsRequestTest006: start.";
120 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
121 uint64_t input = 165;
122 uint64_t output = 0;
123 dfxmap->SetMapEnd(input);
124 output = dfxmap->GetMapEnd();
125 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest005 Failed";
126 GTEST_LOG_(INFO) << "DfxMapsRequestTest005: end.";
127 }
128
129 /**
130 * @tc.name: DfxMapsRequestTest006
131 * @tc.desc: test get end
132 * @tc.type: FUNC
133 */
134 HWTEST_F (DfxMapsTest, DfxMapsRequestTest006, TestSize.Level2)
135 {
136 GTEST_LOG_(INFO) << "DfxMapsRequestTest006: start.";
137 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
138 uint64_t input = -1;
139 uint64_t output = 0;
140 dfxmap->SetMapEnd(input);
141 output = dfxmap->GetMapEnd();
142 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest006 Failed";
143 GTEST_LOG_(INFO) << "DfxMapsRequestTest006: end.";
144 }
145
146 /**
147 * @tc.name: DfxMapsRequestTest007
148 * @tc.desc: test get offect
149 * @tc.type: FUNC
150 */
151 HWTEST_F (DfxMapsTest, DfxMapsRequestTest007, TestSize.Level2)
152 {
153 GTEST_LOG_(INFO) << "DfxMapsRequestTest007: start.";
154 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
155 uint64_t input = 1;
156 uint64_t output = 0;
157 dfxmap->SetMapOffset(input);
158 output = dfxmap->GetMapOffset();
159 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest007 Failed";
160 GTEST_LOG_(INFO) << "DfxMapsRequestTest007: end.";
161 }
162
163 /**
164 * @tc.name: DfxMapsRequestTest008
165 * @tc.desc: test get offect
166 * @tc.type: FUNC
167 */
168 HWTEST_F (DfxMapsTest, DfxMapsRequestTest008, TestSize.Level2)
169 {
170 GTEST_LOG_(INFO) << "DfxMapsRequestTest008: start.";
171 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
172 uint64_t input = 165;
173 uint64_t output = 0;
174 dfxmap->SetMapOffset(input);
175 output = dfxmap->GetMapOffset();
176 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest008 Failed";
177 GTEST_LOG_(INFO) << "DfxMapsRequestTest008: end.";
178 }
179
180 /**
181 * @tc.name: DfxMapsRequestTest009
182 * @tc.desc: test get offect
183 * @tc.type: FUNC
184 */
185 HWTEST_F (DfxMapsTest, DfxMapsRequestTest009, TestSize.Level2)
186 {
187 GTEST_LOG_(INFO) << "DfxMapsRequestTest009: start.";
188 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
189 uint64_t input = -1;
190 uint64_t output = 0;
191 dfxmap->SetMapOffset(input);
192 output = dfxmap->GetMapOffset();
193 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest009 Failed";
194 GTEST_LOG_(INFO) << "DfxMapsRequestTest009: end.";
195 }
196
197 /**
198 * @tc.name: DfxMapsRequestTest010
199 * @tc.desc: test get perms
200 * @tc.type: FUNC
201 */
202 HWTEST_F (DfxMapsTest, DfxMapsRequestTest010, TestSize.Level2)
203 {
204 GTEST_LOG_(INFO) << "DfxMapsRequestTest015: start.";
205 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
206 std::string input = "11111";
207 std::string output = "0000";
208 dfxmap->SetMapPerms(input, sizeof(input));
209 output = dfxmap->GetMapPerms();
210 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest010 Failed";
211 GTEST_LOG_(INFO) << "DfxMapsRequestTest010: end.";
212 }
213
214 /**
215 * @tc.name: DfxMapsRequestTest010
216 * @tc.desc: test get perms
217 * @tc.type: FUNC
218 */
219 HWTEST_F (DfxMapsTest, DfxMapsRequestTest011, TestSize.Level2)
220 {
221 GTEST_LOG_(INFO) << "DfxMapsRequestTest011: start.";
222 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
223 std::string input = "24861";
224 std::string output = "245154";
225 dfxmap->SetMapPerms(input, sizeof(input));
226 output = dfxmap->GetMapPerms();
227 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest011 Failed";
228 GTEST_LOG_(INFO) << "DfxMapsRequestTest011: end.";
229 }
230
231 /**
232 * @tc.name: DfxMapsRequestTest012
233 * @tc.desc: test get perms
234 * @tc.type: FUNC
235 */
236 HWTEST_F (DfxMapsTest, DfxMapsRequestTest012, TestSize.Level2)
237 {
238 GTEST_LOG_(INFO) << "DfxMapsRequestTest012: start.";
239 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
240 std::string input = "";
241 std::string output = "1111";
242 dfxmap->SetMapPerms(input, sizeof(input));
243 output = dfxmap->GetMapPerms();
244 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest012 Failed";
245 GTEST_LOG_(INFO) << "DfxMapsRequestTest012: end.";
246 }
247
248 /**
249 * @tc.name: DfxMapsRequestTest013
250 * @tc.desc: test get path
251 * @tc.type: FUNC
252 */
253 HWTEST_F (DfxMapsTest, DfxMapsRequestTest013, TestSize.Level2)
254 {
255 GTEST_LOG_(INFO) << "DfxMapsRequestTest013: start.";
256 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
257 std::string input = "1";
258 std::string output = "2";
259 dfxmap->SetMapPath(input);
260 output = dfxmap->GetMapPath();
261 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest013 Failed";
262 GTEST_LOG_(INFO) << "DfxMapsRequestTest013: end.";
263 }
264
265 /**
266 * @tc.name: DfxMapsRequestTest014
267 * @tc.desc: test get path
268 * @tc.type: FUNC
269 */
270 HWTEST_F (DfxMapsTest, DfxMapsRequestTest014, TestSize.Level2)
271 {
272 GTEST_LOG_(INFO) << "DfxMapsRequestTest014: start.";
273 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
274 std::string input = "165";
275 std::string output = "156";
276 dfxmap->SetMapPath(input);
277 output = dfxmap->GetMapPath();
278 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest014 Failed";
279 GTEST_LOG_(INFO) << "DfxMapsRequestTest014: end.";
280 }
281
282 /**
283 * @tc.name: DfxMapsRequestTest015
284 * @tc.desc: test get path
285 * @tc.type: FUNC
286 */
287 HWTEST_F (DfxMapsTest, DfxMapsRequestTest015, TestSize.Level2)
288 {
289 GTEST_LOG_(INFO) << "DfxMapsRequestTest015: start.";
290 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
291 std::string input = "";
292 std::string output = " ";
293 dfxmap->SetMapPath(input);
294 output = dfxmap->GetMapPath();
295 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest015 Failed";
296 GTEST_LOG_(INFO) << "DfxMapsRequestTest015: end.";
297 }
298
299 /**
300 * @tc.name: DfxMapsRequestTest016
301 * @tc.desc: test get image
302 * @tc.type: FUNC
303 */
304 HWTEST_F (DfxMapsTest, DfxMapsRequestTest016, TestSize.Level2)
305 {
306 GTEST_LOG_(INFO) << "DfxMapsRequestTest016: start.";
307 std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
308 std::shared_ptr<DfxElf> input;
309 std::shared_ptr<DfxElf> output;
310 dfxmap->SetMapImage(input);
311 output = dfxmap->GetMapImage();
312 EXPECT_EQ(true, input == output) << "DfxMapsRequestTest016 Failed";
313 GTEST_LOG_(INFO) << "DfxMapsRequestTest016: end.";
314 }
315
316 /**
317 * @tc.name: DfxMapsRequestTest017
318 * @tc.desc: test find map by path
319 * @tc.type: FUNC
320 */
321 HWTEST_F (DfxMapsTest, DfxMapsRequestTest017, TestSize.Level2)
322 {
323 GTEST_LOG_(INFO) << "DfxMapsRequestTest017: start.";
324 std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
325 const std::string path = "/data";
326 std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
327 bool flag = dfxmap->FindMapByPath(path, map);
328 EXPECT_EQ(false, flag);
329 GTEST_LOG_(INFO) << "DfxMapsRequestTest017: end.";
330 }
331
332 /**
333 * @tc.name: DfxMapsRequestTest018
334 * @tc.desc: test find map by addr
335 * @tc.type: FUNC
336 */
337 HWTEST_F (DfxMapsTest, DfxMapsRequestTest018, TestSize.Level2)
338 {
339 GTEST_LOG_(INFO) << "DfxMapsRequestTest018: start.";
340 std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
341 std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
342 uintptr_t address = 1;
343 bool flag = dfxmap->FindMapByAddr(address, map);
344 EXPECT_EQ(false, flag);
345 GTEST_LOG_(INFO) << "DfxMapsRequestTest018: end.";
346 }
347
348 /**
349 * @tc.name: DfxMapsRequestTest019
350 * @tc.desc: test find map by addr
351 * @tc.type: FUNC
352 */
353 HWTEST_F (DfxMapsTest, DfxMapsRequestTest019, TestSize.Level2)
354 {
355 GTEST_LOG_(INFO) << "DfxMapsRequestTest019: start.";
356 std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
357 std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
358 uintptr_t address = 100;
359 bool flag = dfxmap->FindMapByAddr(address, map);
360 EXPECT_EQ(false, flag);
361 GTEST_LOG_(INFO) << "DfxMapsRequestTest019: end.";
362 }
363
364 /**
365 * @tc.name: DfxMapsRequestTest020
366 * @tc.desc: test find map by addr
367 * @tc.type: FUNC
368 */
369 HWTEST_F (DfxMapsTest, DfxMapsRequestTest020, TestSize.Level2)
370 {
371 GTEST_LOG_(INFO) << "DfxMapsRequestTest020: start.";
372 std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
373 std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
374 uintptr_t address = -1;
375 bool flag = dfxmap->FindMapByAddr(address, map);
376 EXPECT_EQ(false, flag);
377 GTEST_LOG_(INFO) << "DfxMapsRequestTest020: end.";
378 }
379