summaryrefslogtreecommitdiff
path: root/libunwindstack/tests/JitDebugTest.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-10-30 16:16:45 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-10-30 16:16:45 +0000
commitb31badf70f7734d1ef6d1a95ee73dc57ebd2b19d (patch)
treeb150ea58a97519c38abf33f0654eb709d0c9846f /libunwindstack/tests/JitDebugTest.cpp
parent1d0ee36de7af27ee43e5075b99e9427130a1f0f1 (diff)
parent4568f4bc0f116f097a13b1d931de93cf525ae204 (diff)
Merge "Verify that the elf matches the expected arch."
Diffstat (limited to 'libunwindstack/tests/JitDebugTest.cpp')
-rw-r--r--libunwindstack/tests/JitDebugTest.cpp51
1 files changed, 25 insertions, 26 deletions
diff --git a/libunwindstack/tests/JitDebugTest.cpp b/libunwindstack/tests/JitDebugTest.cpp
index 459852632..b1ca111cb 100644
--- a/libunwindstack/tests/JitDebugTest.cpp
+++ b/libunwindstack/tests/JitDebugTest.cpp
@@ -35,12 +35,19 @@ namespace unwindstack {
class JitDebugTest : public ::testing::Test {
protected:
- void SetUp() override {
- memory_ = new MemoryFake;
- process_memory_.reset(memory_);
+ void CreateFakeElf(MapInfo* map_info) {
+ MemoryFake* memory = new MemoryFake;
+ ElfFake* elf = new ElfFake(memory);
+ elf->FakeSetValid(true);
+ ElfInterfaceFake* interface = new ElfInterfaceFake(memory);
+ elf->FakeSetInterface(interface);
+ interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x800);
+ map_info->elf.reset(elf);
+ }
+ void Init(ArchEnum arch) {
jit_debug_.reset(new JitDebug(process_memory_));
- jit_debug_->SetArch(ARCH_ARM);
+ jit_debug_->SetArch(arch);
maps_.reset(
new BufferMaps("1000-4000 ---s 00000000 00:00 0 /fake/elf1\n"
@@ -57,33 +64,22 @@ class JitDebugTest : public ::testing::Test {
MapInfo* map_info = maps_->Get(3);
ASSERT_TRUE(map_info != nullptr);
- MemoryFake* memory = new MemoryFake;
- ElfFake* elf = new ElfFake(memory);
- elf->FakeSetValid(true);
- ElfInterfaceFake* interface = new ElfInterfaceFake(memory);
- elf->FakeSetInterface(interface);
- interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x800);
- map_info->elf.reset(elf);
+ CreateFakeElf(map_info);
map_info = maps_->Get(5);
ASSERT_TRUE(map_info != nullptr);
- memory = new MemoryFake;
- elf = new ElfFake(memory);
- elf->FakeSetValid(true);
- interface = new ElfInterfaceFake(memory);
- elf->FakeSetInterface(interface);
- interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x800);
- map_info->elf.reset(elf);
+ CreateFakeElf(map_info);
map_info = maps_->Get(7);
ASSERT_TRUE(map_info != nullptr);
- memory = new MemoryFake;
- elf = new ElfFake(memory);
- elf->FakeSetValid(true);
- interface = new ElfInterfaceFake(memory);
- elf->FakeSetInterface(interface);
- interface->FakeSetGlobalVariable("__jit_debug_descriptor", 0x800);
- map_info->elf.reset(elf);
+ CreateFakeElf(map_info);
+ }
+
+ void SetUp() override {
+ memory_ = new MemoryFake;
+ process_memory_.reset(memory_);
+
+ Init(ARCH_ARM);
}
template <typename EhdrType, typename ShdrType>
@@ -326,6 +322,8 @@ TEST_F(JitDebugTest, get_multiple_jit_debug_descriptors_valid) {
}
TEST_F(JitDebugTest, get_elf_x86) {
+ Init(ARCH_X86);
+
CreateElf<Elf32_Ehdr, Elf32_Shdr>(0x4000, ELFCLASS32, EM_ARM, 0x1500, 0x200);
WriteDescriptor32(0xf800, 0x200000);
@@ -343,12 +341,13 @@ TEST_F(JitDebugTest, get_elf_x86) {
}
TEST_F(JitDebugTest, get_elf_64) {
+ Init(ARCH_ARM64);
+
CreateElf<Elf64_Ehdr, Elf64_Shdr>(0x4000, ELFCLASS64, EM_AARCH64, 0x1500, 0x200);
WriteDescriptor64(0xf800, 0x200000);
WriteEntry64(0x200000, 0, 0, 0x4000, 0x1000);
- jit_debug_->SetArch(ARCH_ARM64);
Elf* elf = jit_debug_->GetElf(maps_.get(), 0x1500);
ASSERT_TRUE(elf != nullptr);