summaryrefslogtreecommitdiff
path: root/simpleperf/dso_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'simpleperf/dso_test.cpp')
-rw-r--r--simpleperf/dso_test.cpp60
1 files changed, 58 insertions, 2 deletions
diff --git a/simpleperf/dso_test.cpp b/simpleperf/dso_test.cpp
index 53f62a57..11bcde19 100644
--- a/simpleperf/dso_test.cpp
+++ b/simpleperf/dso_test.cpp
@@ -140,7 +140,6 @@ TEST(DebugElfFileFinder, build_id_mismatch) {
DebugElfFileFinder finder;
finder.SetSymFsDir(GetTestDataDir());
CapturedStderr capture;
- capture.Start();
BuildId mismatch_build_id("0c12a384a9f4a3f3659b7171ca615dbec3a81f71");
std::string debug_file = finder.FindDebugFile(ELF_FILE, false, mismatch_build_id);
capture.Stop();
@@ -250,6 +249,15 @@ TEST(dso, find_vmlinux_in_symdirs) {
std::unique_ptr<Dso> dso = Dso::CreateDso(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME);
ASSERT_TRUE(dso);
ASSERT_EQ(dso->GetDebugFilePath(), vmlinux_path);
+ ASSERT_EQ(0x400927, dso->IpToVaddrInFile(0x800527, 0x800000, 0));
+
+ // Find vmlinux by CreateDsoWithBuildId.
+ Dso::SetBuildIds({});
+ BuildId build_id(ELF_FILE_BUILD_ID);
+ dso = Dso::CreateDsoWithBuildId(DSO_KERNEL, DEFAULT_KERNEL_MMAP_NAME, build_id);
+ ASSERT_TRUE(dso);
+ ASSERT_EQ(dso->GetDebugFilePath(), vmlinux_path);
+ ASSERT_EQ(0x400927, dso->IpToVaddrInFile(0x800527, 0x800000, 0));
}
TEST(dso, kernel_module) {
@@ -315,10 +323,58 @@ TEST(dso, search_debug_file_only_when_needed) {
Dso::SetBuildIds({std::make_pair("/elf", BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))});
Dso::SetSymFsDir(GetTestDataDir());
CapturedStderr capture;
- capture.Start();
auto dso = Dso::CreateDso(DSO_ELF_FILE, "/elf");
ASSERT_EQ(capture.str().find("build id mismatch"), std::string::npos);
ASSERT_EQ(dso->GetDebugFilePath(), "/elf");
ASSERT_NE(capture.str().find("build id mismatch"), std::string::npos);
capture.Stop();
}
+
+TEST(dso, read_symbol_warning) {
+ {
+ // Don't warn when the file may not be an ELF file.
+ auto dso = Dso::CreateDso(DSO_ELF_FILE, GetTestData("not_exist_file"));
+ CapturedStderr capture;
+ dso->LoadSymbols();
+ ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos);
+ }
+ {
+ // Don't warn when the file may not be an ELF file.
+ auto dso = Dso::CreateDso(DSO_ELF_FILE, GetTestData("base.vdex"));
+ CapturedStderr capture;
+ dso->LoadSymbols();
+ ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos);
+ }
+ {
+ // Warn when the file is an ELF file (having a build id).
+ std::string file_path = GetTestData("not_exist_file");
+ Dso::SetBuildIds(
+ {std::make_pair(file_path, BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))});
+ auto dso = Dso::CreateDso(DSO_ELF_FILE, file_path);
+ CapturedStderr capture;
+ dso->LoadSymbols();
+ ASSERT_NE(capture.str().find("failed to read symbols"), std::string::npos);
+ }
+ {
+ // Don't warn when we already have symbols.
+ std::string file_path = GetTestData("not_exist_file");
+ Dso::SetBuildIds(
+ {std::make_pair(file_path, BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))});
+ auto dso = Dso::CreateDso(DSO_ELF_FILE, file_path);
+ std::vector<Symbol> symbols;
+ symbols.emplace_back("fake_symbol", 0x1234, 0x60);
+ dso->SetSymbols(&symbols);
+ CapturedStderr capture;
+ dso->LoadSymbols();
+ ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos);
+ }
+}
+
+TEST(dso, demangle) {
+ ASSERT_EQ(Dso::Demangle("main"), "main");
+ ASSERT_EQ(Dso::Demangle("_ZN4main4main17h2a68d4d833d7495aE"), "main::main::h2a68d4d833d7495a");
+#if defined(__linux__) || defined(__darwin__)
+ // Demangling rust symbol is only supported on linux and darwin.
+ ASSERT_EQ(Dso::Demangle("_RNvC6_123foo3bar"), "123foo::bar");
+#endif
+}