• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <procinfo/process_map.h>
18 
19 #include <string>
20 
21 #include <android-base/file.h>
22 
23 #include <gtest/gtest.h>
24 
TEST(process_map,ReadMapFile)25 TEST(process_map, ReadMapFile) {
26   std::string map_file = android::base::GetExecutableDirectory() + "/testdata/maps";
27   std::vector<android::procinfo::MapInfo> maps;
28   ASSERT_TRUE(android::procinfo::ReadMapFile(
29       map_file,
30       [&](uint64_t start, uint64_t end, uint16_t flags, uint64_t pgoff, ino_t inode,
31           const char* name) { maps.emplace_back(start, end, flags, pgoff, inode, name); }));
32   ASSERT_EQ(2043u, maps.size());
33   ASSERT_EQ(maps[0].start, 0x12c00000ULL);
34   ASSERT_EQ(maps[0].end, 0x2ac00000ULL);
35   ASSERT_EQ(maps[0].flags, PROT_READ | PROT_WRITE);
36   ASSERT_EQ(maps[0].pgoff, 0ULL);
37   ASSERT_EQ(maps[0].inode, 10267643UL);
38   ASSERT_EQ(maps[0].name, "[anon:dalvik-main space (region space)]");
39   ASSERT_EQ(maps[876].start, 0x70e6c4f000ULL);
40   ASSERT_EQ(maps[876].end, 0x70e6c6b000ULL);
41   ASSERT_EQ(maps[876].flags, PROT_READ | PROT_EXEC);
42   ASSERT_EQ(maps[876].pgoff, 0ULL);
43   ASSERT_EQ(maps[876].inode, 2407UL);
44   ASSERT_EQ(maps[876].name, "/system/lib64/libutils.so");
45   ASSERT_EQ(maps[1260].start, 0x70e96fa000ULL);
46   ASSERT_EQ(maps[1260].end, 0x70e96fb000ULL);
47   ASSERT_EQ(maps[1260].flags, PROT_READ);
48   ASSERT_EQ(maps[1260].pgoff, 0ULL);
49   ASSERT_EQ(maps[1260].inode, 10266154UL);
50   ASSERT_EQ(maps[1260].name,
51             "[anon:dalvik-classes.dex extracted in memory from "
52             "/data/app/com.google.sample.tunnel-HGGRU03Gu1Mwkf_-RnFmvw==/base.apk]");
53 }
54 
TEST(process_map,ReadProcessMaps)55 TEST(process_map, ReadProcessMaps) {
56   std::vector<android::procinfo::MapInfo> maps;
57   ASSERT_TRUE(android::procinfo::ReadProcessMaps(
58       getpid(),
59       [&](uint64_t start, uint64_t end, uint16_t flags, uint64_t pgoff, ino_t inode,
60           const char* name) { maps.emplace_back(start, end, flags, pgoff, inode, name); }));
61   ASSERT_GT(maps.size(), 0u);
62   maps.clear();
63   ASSERT_TRUE(android::procinfo::ReadProcessMaps(getpid(), &maps));
64   ASSERT_GT(maps.size(), 0u);
65 }
66