diff options
author | Christopher Ferris <cferris@google.com> | 2018-10-30 16:16:45 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-10-30 16:16:45 +0000 |
commit | b31badf70f7734d1ef6d1a95ee73dc57ebd2b19d (patch) | |
tree | b150ea58a97519c38abf33f0654eb709d0c9846f /libunwindstack/tests/DexFilesTest.cpp | |
parent | 1d0ee36de7af27ee43e5075b99e9427130a1f0f1 (diff) | |
parent | 4568f4bc0f116f097a13b1d931de93cf525ae204 (diff) |
Merge "Verify that the elf matches the expected arch."
Diffstat (limited to 'libunwindstack/tests/DexFilesTest.cpp')
-rw-r--r-- | libunwindstack/tests/DexFilesTest.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/libunwindstack/tests/DexFilesTest.cpp b/libunwindstack/tests/DexFilesTest.cpp index 3ac3ca61b..1ea9e5c03 100644 --- a/libunwindstack/tests/DexFilesTest.cpp +++ b/libunwindstack/tests/DexFilesTest.cpp @@ -36,12 +36,20 @@ namespace unwindstack { class DexFilesTest : 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("__dex_debug_descriptor", 0x800); + map_info->elf.reset(elf); + } + void Init(ArchEnum arch) { dex_files_.reset(new DexFiles(process_memory_)); - dex_files_->SetArch(ARCH_ARM); + dex_files_->SetArch(arch); maps_.reset( new BufferMaps("1000-4000 ---s 00000000 00:00 0 /fake/elf\n" @@ -58,35 +66,24 @@ class DexFilesTest : public ::testing::Test { // Global variable in a section that is not readable. MapInfo* map_info = maps_->Get(kMapGlobalNonReadable); 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("__dex_debug_descriptor", 0x800); - map_info->elf.reset(elf); + CreateFakeElf(map_info); // Global variable not set by default. map_info = maps_->Get(kMapGlobalSetToZero); ASSERT_TRUE(map_info != nullptr); - memory = new MemoryFake; - elf = new ElfFake(memory); - elf->FakeSetValid(true); - interface = new ElfInterfaceFake(memory); - elf->FakeSetInterface(interface); - interface->FakeSetGlobalVariable("__dex_debug_descriptor", 0x800); - map_info->elf.reset(elf); + CreateFakeElf(map_info); // Global variable set in this map. map_info = maps_->Get(kMapGlobal); ASSERT_TRUE(map_info != nullptr); - memory = new MemoryFake; - elf = new ElfFake(memory); - elf->FakeSetValid(true); - interface = new ElfInterfaceFake(memory); - elf->FakeSetInterface(interface); - interface->FakeSetGlobalVariable("__dex_debug_descriptor", 0x800); - map_info->elf.reset(elf); + CreateFakeElf(map_info); + } + + void SetUp() override { + memory_ = new MemoryFake; + process_memory_.reset(memory_); + + Init(ARCH_ARM); } void WriteDescriptor32(uint64_t addr, uint32_t head); @@ -169,11 +166,12 @@ TEST_F(DexFilesTest, get_method_information_32) { } TEST_F(DexFilesTest, get_method_information_64) { + Init(ARCH_ARM64); + std::string method_name = "nothing"; uint64_t method_offset = 0x124; MapInfo* info = maps_->Get(kMapDexFiles); - dex_files_->SetArch(ARCH_ARM64); WriteDescriptor64(0xf800, 0x200000); WriteEntry64(0x200000, 0, 0, 0x301000); WriteDex(0x301000); @@ -199,11 +197,12 @@ TEST_F(DexFilesTest, get_method_information_not_first_entry_32) { } TEST_F(DexFilesTest, get_method_information_not_first_entry_64) { + Init(ARCH_ARM64); + std::string method_name = "nothing"; uint64_t method_offset = 0x124; MapInfo* info = maps_->Get(kMapDexFiles); - dex_files_->SetArch(ARCH_ARM64); WriteDescriptor64(0xf800, 0x200000); WriteEntry64(0x200000, 0x200100, 0, 0x100000); WriteEntry64(0x200100, 0, 0x200000, 0x300000); @@ -297,6 +296,8 @@ TEST_F(DexFilesTest, get_method_information_global_skip_zero_32) { } TEST_F(DexFilesTest, get_method_information_global_skip_zero_64) { + Init(ARCH_ARM64); + std::string method_name = "nothing"; uint64_t method_offset = 0x124; MapInfo* info = maps_->Get(kMapDexFiles); @@ -308,7 +309,6 @@ TEST_F(DexFilesTest, get_method_information_global_skip_zero_64) { WriteEntry64(0x200000, 0, 0, 0x300000); WriteDex(0x300000); - dex_files_->SetArch(ARCH_ARM64); dex_files_->GetMethodInformation(maps_.get(), info, 0x300100, &method_name, &method_offset); EXPECT_EQ("Main.<init>", method_name); EXPECT_EQ(0U, method_offset); |