diff options
author | David Srbecky <dsrbecky@google.com> | 2018-03-24 00:29:14 +0000 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-07-20 10:48:59 -0700 |
commit | 02d0f7962d17fc05efdebb947e908817d304673d (patch) | |
tree | e484208856858cfe8d9d256987ba2ab40af31d44 /libunwindstack/tests/DexFileTest.cpp | |
parent | fcc16c53e10d90a7f92d5953b44fdb4c00d909f2 (diff) |
Create lookup table of DEX symbols.
Create fast lookup table instead of iterating every single time.
This will create the cache as methods are searched for.
Test: 137-cfi
Change-Id: I4be190bb1a637fef5d385b993be6a7e2203a6814
Diffstat (limited to 'libunwindstack/tests/DexFileTest.cpp')
-rw-r--r-- | libunwindstack/tests/DexFileTest.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/libunwindstack/tests/DexFileTest.cpp b/libunwindstack/tests/DexFileTest.cpp index 0b02c5bf1..4dd8cb046 100644 --- a/libunwindstack/tests/DexFileTest.cpp +++ b/libunwindstack/tests/DexFileTest.cpp @@ -206,15 +206,42 @@ TEST(DexFileTest, get_method) { std::string method; uint64_t method_offset; - dex_file->GetMethodInformation(0x102, &method, &method_offset); + ASSERT_TRUE(dex_file->GetMethodInformation(0x102, &method, &method_offset)); EXPECT_EQ("Main.<init>", method); EXPECT_EQ(2U, method_offset); - method = "not_in_a_method"; - method_offset = 0x123; - dex_file->GetMethodInformation(0x100000, &method, &method_offset); - EXPECT_EQ("not_in_a_method", method); - EXPECT_EQ(0x123U, method_offset); + ASSERT_TRUE(dex_file->GetMethodInformation(0x118, &method, &method_offset)); + EXPECT_EQ("Main.main", method); + EXPECT_EQ(0U, method_offset); + + // Make sure that any data that is cached is still retrievable. + ASSERT_TRUE(dex_file->GetMethodInformation(0x104, &method, &method_offset)); + EXPECT_EQ("Main.<init>", method); + EXPECT_EQ(4U, method_offset); + + ASSERT_TRUE(dex_file->GetMethodInformation(0x119, &method, &method_offset)); + EXPECT_EQ("Main.main", method); + EXPECT_EQ(1U, method_offset); +} + +TEST(DexFileTest, get_method_empty) { + MemoryFake memory; + memory.SetMemory(0x4000, kDexData, sizeof(kDexData)); + MapInfo info(0x100, 0x10000, 0x200, 0x5, ""); + std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, &memory, &info)); + ASSERT_TRUE(dex_file != nullptr); + + std::string method; + uint64_t method_offset; + EXPECT_FALSE(dex_file->GetMethodInformation(0x100000, &method, &method_offset)); + + EXPECT_FALSE(dex_file->GetMethodInformation(0x98, &method, &method_offset)); + + // Make sure that once the whole dex file has been cached, no problems occur. + EXPECT_FALSE(dex_file->GetMethodInformation(0x98, &method, &method_offset)); + + // Choose a value that is in the cached map, but not in a valid method. + EXPECT_FALSE(dex_file->GetMethodInformation(0x110, &method, &method_offset)); } } // namespace unwindstack |