diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-29 01:22:28 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-29 01:22:28 +0000 |
commit | b49febd6390e65f28193963f41a56a2522bce957 (patch) | |
tree | 64d3c1ce1218655137e2a455b55162d461f8b5cf | |
parent | a512eaac66230bd1da4278ea54da3ab4cfc85ca8 (diff) | |
parent | 8e9a435202341406798291588da28af3c1921027 (diff) | |
download | extras-android14-d1-release.tar.gz |
Snap for 10580647 from 8e9a435202341406798291588da28af3c1921027 to udc-d1-releaseandroid-14.0.0_r9android-14.0.0_r8android-14.0.0_r7android-14.0.0_r6android-14.0.0_r5android-14.0.0_r4android-14.0.0_r3android-14.0.0_r12android-14.0.0_r11android-14.0.0_r10android14-d1-s7-releaseandroid14-d1-s6-releaseandroid14-d1-s5-releaseandroid14-d1-s4-releaseandroid14-d1-s3-releaseandroid14-d1-s2-releaseandroid14-d1-s1-releaseandroid14-d1-release
Change-Id: I39514b757c2085d63510cc174876b6009d584a3a
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 4 | ||||
-rw-r--r-- | simpleperf/test_util.cpp | 49 | ||||
-rw-r--r-- | simpleperf/test_util.h | 7 |
3 files changed, 55 insertions, 5 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index b8300d7f..4ea71ad1 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -790,6 +790,7 @@ static void TestRecordingApps(const std::string& app_name, const std::string& ap } TEST(record_cmd, app_option_for_debuggable_app) { + OMIT_TEST_ON_NON_NATIVE_ABIS(); TEST_REQUIRE_APPS(); SetRunInAppToolForTesting(true, false); TestRecordingApps("com.android.simpleperf.debuggable", "debuggable"); @@ -798,6 +799,7 @@ TEST(record_cmd, app_option_for_debuggable_app) { } TEST(record_cmd, app_option_for_profileable_app) { + OMIT_TEST_ON_NON_NATIVE_ABIS(); TEST_REQUIRE_APPS(); SetRunInAppToolForTesting(false, true); TestRecordingApps("com.android.simpleperf.profileable", "profileable"); @@ -827,6 +829,7 @@ static void RecordJavaApp(RecordingAppHelper& helper) { TEST(record_cmd, record_java_app) { #if defined(__ANDROID__) + OMIT_TEST_ON_NON_NATIVE_ABIS(); RecordingAppHelper helper; RecordJavaApp(helper); @@ -892,6 +895,7 @@ TEST(record_cmd, record_native_app) { TEST(record_cmd, check_trampoline_after_art_jni_methods) { // Test if art jni methods are called by art_jni_trampoline. #if defined(__ANDROID__) + OMIT_TEST_ON_NON_NATIVE_ABIS(); RecordingAppHelper helper; RecordJavaApp(helper); diff --git a/simpleperf/test_util.cpp b/simpleperf/test_util.cpp index 60d8ea35..7e99b5d5 100644 --- a/simpleperf/test_util.cpp +++ b/simpleperf/test_util.cpp @@ -17,15 +17,46 @@ #include <stdio.h> +#include <optional> + #include <android-base/logging.h> #include <android-base/properties.h> +#include "command.h" #include "event_attr.h" #include "event_fd.h" #include "event_type.h" +#include "record_file.h" #include "test_util.h" -bool IsInNativeAbi() { +#if defined(__linux__) + +static std::optional<bool> CanSampleRegsFor32BitABI() { + std::vector<std::unique_ptr<Workload>> workloads; + CreateProcesses(1, &workloads); + std::string pid = std::to_string(workloads[0]->GetPid()); + std::unique_ptr<Command> cmd = CreateCommandInstance("record"); + TemporaryFile tmpfile; + if (!cmd->Run({"-p", pid, "--call-graph", "dwarf,8", "--no-unwind", "-e", "cpu-clock:u", + "--duration", "3", "-o", tmpfile.path})) { + return std::nullopt; + } + auto reader = RecordFileReader::CreateInstance(tmpfile.path); + if (!reader) { + return std::nullopt; + } + for (const std::unique_ptr<Record>& record : reader->DataSection()) { + if (record->type() == PERF_RECORD_SAMPLE) { + auto sample = static_cast<const SampleRecord*>(record.get()); + if (sample->regs_user_data.abi == PERF_SAMPLE_REGS_ABI_32) { + return true; + } + } + } + return false; +} + +std::optional<bool> IsInNativeAbi() { static int in_native_abi = -1; if (in_native_abi == -1) { FILE* fp = popen("uname -m", "re"); @@ -43,16 +74,27 @@ bool IsInNativeAbi() { if (s.find("arm") == std::string::npos && s.find("aarch64") == std::string::npos) { in_native_abi = 0; } + if (GetTargetArch() == ARCH_ARM) { + // If we can't get ARM registers in samples, probably we are running with a 32-bit + // translator on 64-bit only CPUs. Then we should make in_native_abi = 0. + if (auto result = CanSampleRegsFor32BitABI(); result.has_value()) { + in_native_abi = result.value() ? 1 : 0; + } else { + in_native_abi = 2; + } + } } else if (GetTargetArch() == ARCH_RISCV64) { if (s.find("riscv") == std::string::npos) { in_native_abi = 0; } } } + if (in_native_abi == 2) { + return std::nullopt; + } return in_native_abi == 1; } -#if defined(__linux__) // Check if we can get a non-zero instruction event count by monitoring current thread. static bool HasNonZeroInstructionEventCount() { const simpleperf::EventType* type = simpleperf::FindEventTypeByName("instructions", false); @@ -84,8 +126,9 @@ bool HasHardwareCounter() { bool is_emulator = android::base::StartsWith(fingerprint, "google/sdk_gphone") || android::base::StartsWith(fingerprint, "google/sdk_gpc") || android::base::StartsWith(fingerprint, "generic/cf"); + bool in_native_abi = IsInNativeAbi() == std::optional(true); - if (arch == ARCH_X86_64 || arch == ARCH_X86_32 || !IsInNativeAbi() || is_emulator) { + if (arch == ARCH_X86_64 || arch == ARCH_X86_32 || !in_native_abi || is_emulator) { // On x86 and x86_64, or when we are not in native abi, it's likely to run on an emulator or // vm without hardware perf counters. It's hard to enumerate them all. So check the support // at runtime. diff --git a/simpleperf/test_util.h b/simpleperf/test_util.h index 21b89a5e..16483103 100644 --- a/simpleperf/test_util.h +++ b/simpleperf/test_util.h @@ -16,6 +16,7 @@ #include <map> #include <memory> +#include <optional> #include <string> #include <vector> @@ -68,11 +69,13 @@ void CheckElfFileSymbols(const std::map<std::string, ElfFileSymbol>& symbols); #define TEST_REQUIRE_HOST_ROOT() TEST_REQUIRE_ROOT() #endif -bool IsInNativeAbi(); +std::optional<bool> IsInNativeAbi(); // Used to skip tests not supposed to run on non-native ABIs. #define OMIT_TEST_ON_NON_NATIVE_ABIS() \ do { \ - if (!IsInNativeAbi()) { \ + std::optional<bool> in_native_abi = IsInNativeAbi(); \ + ASSERT_TRUE(in_native_abi.has_value()); \ + if (!in_native_abi.value()) { \ GTEST_LOG_(INFO) << "Skip this test as it only runs on native ABIs."; \ return; \ } \ |