From b85662a95ca3d570276a7e6d9bcc95f1c9500235 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Wed, 6 Sep 2023 14:50:31 -0700 Subject: simpleperf: Fix record_cmd#check_trampoline test art_jni_trampoline may appear in JIT cache. To load symbols for JIT cache (stored in the recording file), we need to call LoadBuildIdAndFileFeatures(). Bug: 335341168 Bug: 317955689 Bug: 299090869 Test: run simpleperf_unit_test Change-Id: I401b091e27e7b3ae86f003a270b53be4060c922f Merged-In: I401b091e27e7b3ae86f003a270b53be4060c922f --- simpleperf/cmd_record_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index c4d347fa..2b80b897 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -860,6 +860,7 @@ TEST(record_cmd, check_trampoline_after_art_jni_methods) { auto reader = RecordFileReader::CreateInstance(helper.GetDataPath()); ASSERT_TRUE(reader); ThreadTree thread_tree; + reader->LoadBuildIdAndFileFeatures(thread_tree); auto get_symbol_name = [&](ThreadEntry* thread, uint64_t ip) -> std::string { const MapEntry* map = thread_tree.FindMap(thread, ip, false); -- cgit v1.2.3 From 26cd565b556081e1ab09258a1112c6ef16747eb8 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Wed, 4 Oct 2023 15:50:43 -0700 Subject: simpleperf: Fix flaky test check_trampoline_after_art_jni_methods Bug: 335341168 Bug: 317955689 Bug: 299090869 Test: run simpleperf_unit_test Change-Id: I846cd2bbf1159abf05e9d754c2e96c12912c7d72 Merged-In: I846cd2bbf1159abf05e9d754c2e96c12912c7d72 --- simpleperf/cmd_record_test.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 2b80b897..e21cb86b 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -34,6 +34,7 @@ #include #include "ETMRecorder.h" +#include "JITDebugReader.h" #include "ProbeEvents.h" #include "cmd_record_impl.h" #include "command.h" @@ -882,10 +883,23 @@ TEST(record_cmd, check_trampoline_after_art_jni_methods) { if (android::base::StartsWith(sym_name, "art::Method_invoke") && i + 1 < ips.size()) { has_check = true; std::string name = get_symbol_name(thread, ips[i + 1]); - if (!android::base::EndsWith(name, "jni_trampoline")) { - GTEST_LOG_(ERROR) << "unexpected symbol after art::Method_invoke: " << name; - return false; + if (android::base::EndsWith(name, "jni_trampoline")) { + continue; } + // When the jni_trampoline function is from JIT cache, we may not get map info in time. + // To avoid test flakiness, we accept this. + // Case 1: It doesn't hit any maps. + if (name == "unknown") { + continue; + } + // Case 2: It hits an old map for JIT cache. + if (const MapEntry* map = thread_tree.FindMap(thread, ips[i + 1], false); + JITDebugReader::IsPathInJITSymFile(map->dso->Path())) { + continue; + } + + GTEST_LOG_(ERROR) << "unexpected symbol after art::Method_invoke: " << name; + return false; } } } -- cgit v1.2.3