diff options
Diffstat (limited to 'libunwindstack/tests/ElfTest.cpp')
-rw-r--r-- | libunwindstack/tests/ElfTest.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/libunwindstack/tests/ElfTest.cpp b/libunwindstack/tests/ElfTest.cpp index bf0823b..72ceb85 100644 --- a/libunwindstack/tests/ElfTest.cpp +++ b/libunwindstack/tests/ElfTest.cpp @@ -22,7 +22,8 @@ #include <gtest/gtest.h> -#include "Elf.h" +#include <unwindstack/Elf.h> +#include <unwindstack/MapInfo.h> #include "ElfTestUtils.h" #include "MemoryFake.h" @@ -31,6 +32,8 @@ #define PT_ARM_EXIDX 0x70000001 #endif +namespace unwindstack { + class ElfTest : public ::testing::Test { protected: void SetUp() override { @@ -237,3 +240,33 @@ TEST_F(ElfTest, gnu_debugdata_init64) { elf.InitGnuDebugdata(); ASSERT_TRUE(elf.gnu_debugdata_interface() != nullptr); } + +class MockElf : public Elf { + public: + MockElf(Memory* memory) : Elf(memory) {} + virtual ~MockElf() = default; + + void set_valid(bool valid) { valid_ = valid; } + void set_elf_interface(ElfInterface* interface) { interface_.reset(interface); } +}; + +TEST_F(ElfTest, rel_pc) { + MockElf elf(memory_); + + ElfInterface* interface = new ElfInterface32(memory_); + elf.set_elf_interface(interface); + + elf.set_valid(true); + interface->set_load_bias(0); + MapInfo map_info{.start = 0x1000, .end = 0x2000}; + + ASSERT_EQ(0x101U, elf.GetRelPc(0x1101, &map_info)); + + interface->set_load_bias(0x3000); + ASSERT_EQ(0x3101U, elf.GetRelPc(0x1101, &map_info)); + + elf.set_valid(false); + ASSERT_EQ(0x101U, elf.GetRelPc(0x1101, &map_info)); +} + +} // namespace unwindstack |