diff options
| author | Christopher Ferris <cferris@google.com> | 2018-06-29 16:30:55 -0700 |
|---|---|---|
| committer | Christopher Ferris <cferris@google.com> | 2018-07-12 12:45:31 -0700 |
| commit | 5afddb06370dc8b3d04a31f6f3ae04a5fa379cde (patch) | |
| tree | 274864d812331b87c63c44c344db70967d9b4033 /libunwindstack/tests | |
| parent | 32960e54b44042eb74c845fc9ae50aeb8b74841c (diff) | |
| download | system_core-5afddb06370dc8b3d04a31f6f3ae04a5fa379cde.tar.gz system_core-5afddb06370dc8b3d04a31f6f3ae04a5fa379cde.tar.bz2 system_core-5afddb06370dc8b3d04a31f6f3ae04a5fa379cde.zip | |
Remove Memory::ReadField.
In almost all cases, it is faster to read the entire structure rather
than do multiple reads using ReadField. The only case where it would be
slower is if doing a remote unwind and ptrace is the only way to read. In
all other cases, it's a single system call. In the ptrace call, it will be
multiple calls. Given that it is unusual to be forced to use ptrace,
it's better to avoid it.
It also reduces the code complexity to do a single read, and avoids
issues where the code forgets to read the field it needs.
Test: Unit tests pass on host and target.
Change-Id: I7b3875b2c85d0d88115b1776e1be28521dc0b932
Diffstat (limited to 'libunwindstack/tests')
| -rw-r--r-- | libunwindstack/tests/ElfInterfaceArmTest.cpp | 33 | ||||
| -rw-r--r-- | libunwindstack/tests/MemoryTest.cpp | 34 |
2 files changed, 5 insertions, 62 deletions
diff --git a/libunwindstack/tests/ElfInterfaceArmTest.cpp b/libunwindstack/tests/ElfInterfaceArmTest.cpp index a8bb4aaf4..43c6a9734 100644 --- a/libunwindstack/tests/ElfInterfaceArmTest.cpp +++ b/libunwindstack/tests/ElfInterfaceArmTest.cpp @@ -242,44 +242,21 @@ TEST_F(ElfInterfaceArmTest, iterate) { ASSERT_EQ(0xa020U, entries[4]); } -TEST_F(ElfInterfaceArmTest, HandleType_not_arm_exidx) { +TEST_F(ElfInterfaceArmTest, HandleUnknownType_arm_exidx) { ElfInterfaceArmFake interface(&memory_); - ASSERT_FALSE(interface.HandleType(0x1000, PT_NULL)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_LOAD)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_DYNAMIC)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_INTERP)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_NOTE)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_SHLIB)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_PHDR)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_TLS)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_LOOS)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_HIOS)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_LOPROC)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_HIPROC)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_GNU_EH_FRAME)); - ASSERT_FALSE(interface.HandleType(0x1000, PT_GNU_STACK)); -} - -TEST_F(ElfInterfaceArmTest, HandleType_arm_exidx) { - ElfInterfaceArmFake interface(&memory_); - - Elf32_Phdr phdr = {}; interface.FakeSetStartOffset(0x1000); interface.FakeSetTotalEntries(100); - phdr.p_offset = 0x2000; - phdr.p_filesz = 0xa00; - // Verify that if reads fail, we don't set the values but still get true. - ASSERT_TRUE(interface.HandleType(0x1000, 0x70000001)); + // Verify that if the type is not the one we want, we don't set the values. + interface.HandleUnknownType(0x70000000, 0x2000, 320); ASSERT_EQ(0x1000U, interface.start_offset()); ASSERT_EQ(100U, interface.total_entries()); // Everything is correct and present. - memory_.SetMemory(0x1000, &phdr, sizeof(phdr)); - ASSERT_TRUE(interface.HandleType(0x1000, 0x70000001)); + interface.HandleUnknownType(0x70000001, 0x2000, 320); ASSERT_EQ(0x2000U, interface.start_offset()); - ASSERT_EQ(320U, interface.total_entries()); + ASSERT_EQ(40U, interface.total_entries()); } TEST_F(ElfInterfaceArmTest, StepExidx) { diff --git a/libunwindstack/tests/MemoryTest.cpp b/libunwindstack/tests/MemoryTest.cpp index 4a9ed9f58..365598499 100644 --- a/libunwindstack/tests/MemoryTest.cpp +++ b/libunwindstack/tests/MemoryTest.cpp @@ -51,40 +51,6 @@ struct FakeStruct { uint64_t four; }; -TEST(MemoryTest, read_field) { - MemoryFakeAlwaysReadZero memory; - - FakeStruct data; - memset(&data, 0xff, sizeof(data)); - ASSERT_TRUE(memory.ReadField(0, &data, &data.one, sizeof(data.one))); - ASSERT_EQ(0, data.one); - - memset(&data, 0xff, sizeof(data)); - ASSERT_TRUE(memory.ReadField(0, &data, &data.two, sizeof(data.two))); - ASSERT_FALSE(data.two); - - memset(&data, 0xff, sizeof(data)); - ASSERT_TRUE(memory.ReadField(0, &data, &data.three, sizeof(data.three))); - ASSERT_EQ(0U, data.three); - - memset(&data, 0xff, sizeof(data)); - ASSERT_TRUE(memory.ReadField(0, &data, &data.four, sizeof(data.four))); - ASSERT_EQ(0U, data.four); -} - -TEST(MemoryTest, read_field_fails) { - MemoryFakeAlwaysReadZero memory; - - FakeStruct data; - memset(&data, 0xff, sizeof(data)); - - ASSERT_FALSE(memory.ReadField(UINT64_MAX, &data, &data.three, sizeof(data.three))); - - // Field and start reversed, should fail. - ASSERT_FALSE(memory.ReadField(100, &data.two, &data, sizeof(data.two))); - ASSERT_FALSE(memory.ReadField(0, &data.two, &data, sizeof(data.two))); -} - TEST(MemoryTest, read_string) { std::string name("string_in_memory"); |
