| Christopher Ferris | eb0772f | 2018-12-05 15:57:02 -0800 | [diff] [blame] | 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 <stdint.h> | 
|  | 18 |  | 
|  | 19 | #include <gtest/gtest.h> | 
|  | 20 |  | 
|  | 21 | #include <unwindstack/MapInfo.h> | 
|  | 22 | #include <unwindstack/Maps.h> | 
|  | 23 |  | 
|  | 24 | #include "ElfFake.h" | 
|  | 25 |  | 
|  | 26 | namespace unwindstack { | 
|  | 27 |  | 
|  | 28 | TEST(MapInfoTest, maps_constructor_const_char) { | 
|  | 29 | MapInfo prev_map(nullptr, 0, 0, 0, 0, ""); | 
|  | 30 | MapInfo map_info(&prev_map, 1, 2, 3, 4, "map"); | 
|  | 31 |  | 
|  | 32 | EXPECT_EQ(&prev_map, map_info.prev_map); | 
|  | 33 | EXPECT_EQ(1UL, map_info.start); | 
|  | 34 | EXPECT_EQ(2UL, map_info.end); | 
|  | 35 | EXPECT_EQ(3UL, map_info.offset); | 
|  | 36 | EXPECT_EQ(4UL, map_info.flags); | 
|  | 37 | EXPECT_EQ("map", map_info.name); | 
|  | 38 | EXPECT_EQ(static_cast<uint64_t>(-1), map_info.load_bias); | 
|  | 39 | EXPECT_EQ(0UL, map_info.elf_offset); | 
|  | 40 | EXPECT_TRUE(map_info.elf.get() == nullptr); | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | TEST(MapInfoTest, maps_constructor_string) { | 
|  | 44 | std::string name("string_map"); | 
|  | 45 | MapInfo prev_map(nullptr, 0, 0, 0, 0, ""); | 
|  | 46 | MapInfo map_info(&prev_map, 1, 2, 3, 4, name); | 
|  | 47 |  | 
|  | 48 | EXPECT_EQ(&prev_map, map_info.prev_map); | 
|  | 49 | EXPECT_EQ(1UL, map_info.start); | 
|  | 50 | EXPECT_EQ(2UL, map_info.end); | 
|  | 51 | EXPECT_EQ(3UL, map_info.offset); | 
|  | 52 | EXPECT_EQ(4UL, map_info.flags); | 
|  | 53 | EXPECT_EQ("string_map", map_info.name); | 
|  | 54 | EXPECT_EQ(static_cast<uint64_t>(-1), map_info.load_bias); | 
|  | 55 | EXPECT_EQ(0UL, map_info.elf_offset); | 
|  | 56 | EXPECT_TRUE(map_info.elf.get() == nullptr); | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | TEST(MapInfoTest, get_function_name) { | 
|  | 60 | ElfFake* elf = new ElfFake(nullptr); | 
|  | 61 | ElfInterfaceFake* interface = new ElfInterfaceFake(nullptr); | 
|  | 62 | elf->FakeSetInterface(interface); | 
|  | 63 | interface->FakePushFunctionData(FunctionData("function", 1000)); | 
|  | 64 |  | 
|  | 65 | MapInfo map_info(nullptr, 1, 2, 3, 4, ""); | 
|  | 66 | map_info.elf.reset(elf); | 
|  | 67 |  | 
|  | 68 | std::string name; | 
|  | 69 | uint64_t offset; | 
|  | 70 | ASSERT_TRUE(map_info.GetFunctionName(1000, &name, &offset)); | 
|  | 71 | EXPECT_EQ("function", name); | 
|  | 72 | EXPECT_EQ(1000UL, offset); | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | }  // namespace unwindstack |