• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     if (dfxmap!=nullptr) {
56         dfxmap->SetMapBegin(input);
57         output = dfxmap->GetMapBegin();
58     }
59     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest001 Failed";
60     GTEST_LOG_(INFO) << "DfxMapsRequestTest001: end.";
61 }
62 
63 /**
64  * @tc.name: DfxMapsRequestTest002
65  * @tc.desc: test get begin
66  * @tc.type: FUNC
67  */
68 HWTEST_F (DfxMapsTest, DfxMapsRequestTest002, TestSize.Level2)
69 {
70     GTEST_LOG_(INFO) << "DfxMapsRequestTest002: start.";
71     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
72     uint64_t input = 165;
73     uint64_t output = 0;
74     if (dfxmap != nullptr) {
75         dfxmap->SetMapBegin(input);
76         output = dfxmap->GetMapBegin();
77     }
78     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest002 Failed";
79     GTEST_LOG_(INFO) << "DfxMapsRequestTest002: end.";
80 }
81 
82 /**
83  * @tc.name: DfxMapsRequestTest003
84  * @tc.desc: test get begin
85  * @tc.type: FUNC
86  */
87 HWTEST_F (DfxMapsTest, DfxMapsRequestTest003, TestSize.Level2)
88 {
89     GTEST_LOG_(INFO) << "DfxMapsRequestTest003: start.";
90     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
91     uint64_t input = -1;
92     uint64_t output = 0;
93     if (dfxmap != nullptr) {
94         dfxmap->SetMapBegin(input);
95         output = dfxmap->GetMapBegin();
96     }
97     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest003 Failed";
98     GTEST_LOG_(INFO) << "DfxMapsRequestTest003: end.";
99 }
100 
101 /**
102  * @tc.name: DfxMapsRequestTest004
103  * @tc.desc: test get begin
104  * @tc.type: FUNC
105  */
106 HWTEST_F (DfxMapsTest, DfxMapsRequestTest004, TestSize.Level2)
107 {
108     GTEST_LOG_(INFO) << "DfxMapsRequestTest004: start.";
109     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
110     uint64_t input = 1;
111     uint64_t output = 0;
112     if (dfxmap != nullptr) {
113         dfxmap->SetMapEnd(input);
114         output = dfxmap->GetMapEnd();
115     }
116     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest004 Failed";
117     GTEST_LOG_(INFO) << "DfxMapsRequestTest004: end.";
118 }
119 
120 /**
121  * @tc.name: DfxMapsRequestTest005
122  * @tc.desc: test get end
123  * @tc.type: FUNC
124  */
125 HWTEST_F (DfxMapsTest, DfxMapsRequestTest005, TestSize.Level2)
126 {
127     GTEST_LOG_(INFO) << "DfxMapsRequestTest006: start.";
128     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
129     uint64_t input = 165;
130     uint64_t output = 0;
131     if (dfxmap != nullptr) {
132         dfxmap->SetMapEnd(input);
133         output = dfxmap->GetMapEnd();
134     }
135     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest005 Failed";
136     GTEST_LOG_(INFO) << "DfxMapsRequestTest005: end.";
137 }
138 
139 /**
140  * @tc.name: DfxMapsRequestTest006
141  * @tc.desc: test get end
142  * @tc.type: FUNC
143  */
144 HWTEST_F (DfxMapsTest, DfxMapsRequestTest006, TestSize.Level2)
145 {
146     GTEST_LOG_(INFO) << "DfxMapsRequestTest006: start.";
147     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
148     uint64_t input = -1;
149     uint64_t output = 0;
150     if (dfxmap != nullptr) {
151         dfxmap->SetMapEnd(input);
152         output = dfxmap->GetMapEnd();
153     }
154     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest006 Failed";
155     GTEST_LOG_(INFO) << "DfxMapsRequestTest006: end.";
156 }
157 
158 /**
159  * @tc.name: DfxMapsRequestTest007
160  * @tc.desc: test get offect
161  * @tc.type: FUNC
162  */
163 HWTEST_F (DfxMapsTest, DfxMapsRequestTest007, TestSize.Level2)
164 {
165     GTEST_LOG_(INFO) << "DfxMapsRequestTest007: start.";
166     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
167     uint64_t input = 1;
168     uint64_t output = 0;
169     if (dfxmap != nullptr) {
170         dfxmap->SetMapOffset(input);
171         output = dfxmap->GetMapOffset();
172     }
173     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest007 Failed";
174     GTEST_LOG_(INFO) << "DfxMapsRequestTest007: end.";
175 }
176 
177 /**
178  * @tc.name: DfxMapsRequestTest008
179  * @tc.desc: test get offect
180  * @tc.type: FUNC
181  */
182 HWTEST_F (DfxMapsTest, DfxMapsRequestTest008, TestSize.Level2)
183 {
184     GTEST_LOG_(INFO) << "DfxMapsRequestTest008: start.";
185     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
186     uint64_t input = 165;
187     uint64_t output = 0;
188     if (dfxmap != nullptr) {
189         dfxmap->SetMapOffset(input);
190         output = dfxmap->GetMapOffset();
191     }
192     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest008 Failed";
193     GTEST_LOG_(INFO) << "DfxMapsRequestTest008: end.";
194 }
195 
196 /**
197  * @tc.name: DfxMapsRequestTest009
198  * @tc.desc: test get offect
199  * @tc.type: FUNC
200  */
201 HWTEST_F (DfxMapsTest, DfxMapsRequestTest009, TestSize.Level2)
202 {
203     GTEST_LOG_(INFO) << "DfxMapsRequestTest009: start.";
204     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
205     uint64_t input = -1;
206     uint64_t output = 0;
207     if (dfxmap != nullptr) {
208         dfxmap->SetMapOffset(input);
209         output = dfxmap->GetMapOffset();
210     }
211     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest009 Failed";
212     GTEST_LOG_(INFO) << "DfxMapsRequestTest009: end.";
213 }
214 
215 /**
216  * @tc.name: DfxMapsRequestTest010
217  * @tc.desc: test get perms
218  * @tc.type: FUNC
219  */
220 HWTEST_F (DfxMapsTest, DfxMapsRequestTest010, TestSize.Level2)
221 {
222     GTEST_LOG_(INFO) << "DfxMapsRequestTest015: start.";
223     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
224     std::string input = "11111";
225     std::string output = "0000";
226     if (dfxmap != nullptr) {
227         dfxmap->SetMapPerms(input, sizeof(input));
228         output = dfxmap->GetMapPerms();
229     }
230     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest010 Failed";
231     GTEST_LOG_(INFO) << "DfxMapsRequestTest010: end.";
232 }
233 
234 /**
235  * @tc.name: DfxMapsRequestTest010
236  * @tc.desc: test get perms
237  * @tc.type: FUNC
238  */
239 HWTEST_F (DfxMapsTest, DfxMapsRequestTest011, TestSize.Level2)
240 {
241     GTEST_LOG_(INFO) << "DfxMapsRequestTest011: start.";
242     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
243     std::string input = "24861";
244     std::string output = "245154";
245     if (dfxmap != nullptr) {
246         dfxmap->SetMapPerms(input, sizeof(input));
247         output = dfxmap->GetMapPerms();
248     }
249     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest011 Failed";
250     GTEST_LOG_(INFO) << "DfxMapsRequestTest011: end.";
251 }
252 
253 /**
254  * @tc.name: DfxMapsRequestTest012
255  * @tc.desc: test get perms
256  * @tc.type: FUNC
257  */
258 HWTEST_F (DfxMapsTest, DfxMapsRequestTest012, TestSize.Level2)
259 {
260     GTEST_LOG_(INFO) << "DfxMapsRequestTest012: start.";
261     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
262     std::string input = "";
263     std::string output = "1111";
264     if (dfxmap != nullptr) {
265         dfxmap->SetMapPerms(input, sizeof(input));
266         output = dfxmap->GetMapPerms();
267     }
268     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest012 Failed";
269     GTEST_LOG_(INFO) << "DfxMapsRequestTest012: end.";
270 }
271 
272 /**
273  * @tc.name: DfxMapsRequestTest013
274  * @tc.desc: test get path
275  * @tc.type: FUNC
276  */
277 HWTEST_F (DfxMapsTest, DfxMapsRequestTest013, TestSize.Level2)
278 {
279     GTEST_LOG_(INFO) << "DfxMapsRequestTest013: start.";
280     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
281     std::string input = "1";
282     std::string output = "2";
283     if (dfxmap != nullptr) {
284         dfxmap->SetMapPath(input);
285         output = dfxmap->GetMapPath();
286     }
287     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest013 Failed";
288     GTEST_LOG_(INFO) << "DfxMapsRequestTest013: end.";
289 }
290 
291 /**
292  * @tc.name: DfxMapsRequestTest014
293  * @tc.desc: test get path
294  * @tc.type: FUNC
295  */
296 HWTEST_F (DfxMapsTest, DfxMapsRequestTest014, TestSize.Level2)
297 {
298     GTEST_LOG_(INFO) << "DfxMapsRequestTest014: start.";
299     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
300     std::string input = "165";
301     std::string output = "156";
302     if (dfxmap != nullptr) {
303         dfxmap->SetMapPath(input);
304         output = dfxmap->GetMapPath();
305     }
306     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest014 Failed";
307     GTEST_LOG_(INFO) << "DfxMapsRequestTest014: end.";
308 }
309 
310 /**
311  * @tc.name: DfxMapsRequestTest015
312  * @tc.desc: test get path
313  * @tc.type: FUNC
314  */
315 HWTEST_F (DfxMapsTest, DfxMapsRequestTest015, TestSize.Level2)
316 {
317     GTEST_LOG_(INFO) << "DfxMapsRequestTest015: start.";
318     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
319     std::string input = "";
320     std::string output = "  ";
321     if (dfxmap != nullptr) {
322         dfxmap->SetMapPath(input);
323         output = dfxmap->GetMapPath();
324     }
325     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest015 Failed";
326     GTEST_LOG_(INFO) << "DfxMapsRequestTest015: end.";
327 }
328 
329 /**
330  * @tc.name: DfxMapsRequestTest016
331  * @tc.desc: test get image
332  * @tc.type: FUNC
333  */
334 HWTEST_F (DfxMapsTest, DfxMapsRequestTest016, TestSize.Level2)
335 {
336     GTEST_LOG_(INFO) << "DfxMapsRequestTest016: start.";
337     std::shared_ptr<DfxElfMap> dfxmap = std::make_shared<DfxElfMap>();
338     std::shared_ptr<DfxElf> input;
339     std::shared_ptr<DfxElf> output;
340     if (dfxmap != nullptr) {
341         dfxmap->SetMapImage(input);
342         output = dfxmap->GetMapImage();
343     }
344     EXPECT_EQ(true, input == output) << "DfxMapsRequestTest016 Failed";
345     GTEST_LOG_(INFO) << "DfxMapsRequestTest016: end.";
346 }
347 
348 /**
349  * @tc.name: DfxMapsRequestTest017
350  * @tc.desc: test find map by path
351  * @tc.type: FUNC
352  */
353 HWTEST_F (DfxMapsTest, DfxMapsRequestTest017, TestSize.Level2)
354 {
355     GTEST_LOG_(INFO) << "DfxMapsRequestTest017: start.";
356     std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
357     const std::string path = "/data";
358     std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
359     bool flag = false;
360     if (dfxmap != nullptr && map != nullptr) {
361         flag = dfxmap->FindMapByPath(path, map);
362     }
363     EXPECT_EQ(true, flag != true);
364     GTEST_LOG_(INFO) << "DfxMapsRequestTest017: end.";
365 }
366 
367 /**
368  * @tc.name: DfxMapsRequestTest018
369  * @tc.desc: test find map by addr
370  * @tc.type: FUNC
371  */
372 HWTEST_F (DfxMapsTest, DfxMapsRequestTest018, TestSize.Level2)
373 {
374     GTEST_LOG_(INFO) << "DfxMapsRequestTest018: start.";
375     std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
376     std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
377     bool flag = false;
378     if (dfxmap != nullptr && map != nullptr) {
379         uintptr_t address = 1;
380         flag = dfxmap->FindMapByAddr(address, map);
381     }
382     EXPECT_EQ(true, flag != true);
383     GTEST_LOG_(INFO) << "DfxMapsRequestTest018: end.";
384 }
385 
386 /**
387  * @tc.name: DfxMapsRequestTest019
388  * @tc.desc: test find map by addr
389  * @tc.type: FUNC
390  */
391 HWTEST_F (DfxMapsTest, DfxMapsRequestTest019, TestSize.Level2)
392 {
393     GTEST_LOG_(INFO) << "DfxMapsRequestTest019: start.";
394     std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
395     std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
396     bool flag = false;
397     if (dfxmap != nullptr && map != nullptr) {
398         uintptr_t address = 100;
399         flag = dfxmap->FindMapByAddr(address, map);
400     }
401     EXPECT_EQ(true, flag != true);
402     GTEST_LOG_(INFO) << "DfxMapsRequestTest019: end.";
403 }
404 
405 /**
406  * @tc.name: DfxMapsRequestTest020
407  * @tc.desc: test find map by addr
408  * @tc.type: FUNC
409  */
410 HWTEST_F (DfxMapsTest, DfxMapsRequestTest020, TestSize.Level2)
411 {
412     GTEST_LOG_(INFO) << "DfxMapsRequestTest020: start.";
413     std::shared_ptr<DfxElfMaps> dfxmap = std::make_shared<DfxElfMaps>();
414     std::shared_ptr<DfxElfMap> map = std::make_shared<DfxElfMap>();
415     bool flag = false;
416     if (dfxmap != nullptr && map != nullptr) {
417         uintptr_t address = -1;
418         flag = dfxmap->FindMapByAddr(address, map);
419     }
420     EXPECT_EQ(true, flag != true);
421     GTEST_LOG_(INFO) << "DfxMapsRequestTest020: end.";
422 }
423