diff options
author | Yabin Cui <yabinc@google.com> | 2023-07-25 10:06:16 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2023-07-28 10:35:13 -0700 |
commit | 03a2ab3e95bdc7e4b90ca1846e73a3fc86c83e59 (patch) | |
tree | ee2fe2bb817d0cbe205bd079fd0ea455991bf063 | |
parent | 266aa3bf840ab8392397cb86d59a064992db966b (diff) | |
download | extras-03a2ab3e95bdc7e4b90ca1846e73a3fc86c83e59.tar.gz |
simpleperf: Disable failed tests when running with a 32-bit translator
The CtsSimpleperfTestCases built for ARM may run with a 32-bit
translator on a 64-bit only CPU. In this situation, tests about
recording apps can fail because of the limiation of translation.
So detect this situation and diable failed tests.
Bug: 291717595
Test: run CtsSimpleperfTestCases
Change-Id: Icd9f3736d5dd84c2c502e6b733a3688b0a3de2bb
Merged-In: Icd9f3736d5dd84c2c502e6b733a3688b0a3de2bb
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 4 | ||||
-rw-r--r-- | simpleperf/test_util.cpp | 39 |
2 files changed, 42 insertions, 1 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..ad667e22 100644 --- a/simpleperf/test_util.cpp +++ b/simpleperf/test_util.cpp @@ -17,14 +17,45 @@ #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" +#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; +} + bool IsInNativeAbi() { static int in_native_abi = -1; if (in_native_abi == -1) { @@ -43,6 +74,13 @@ 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. + if (CanSampleRegsFor32BitABI() != std::optional<bool>(true)) { + in_native_abi = 0; + } + } } else if (GetTargetArch() == ARCH_RISCV64) { if (s.find("riscv") == std::string::npos) { in_native_abi = 0; @@ -52,7 +90,6 @@ bool IsInNativeAbi() { 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); |