summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2023-07-28 22:04:26 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-07-28 22:04:26 +0000
commit8e9a435202341406798291588da28af3c1921027 (patch)
tree64d3c1ce1218655137e2a455b55162d461f8b5cf
parent55dee47dac8743d452c4480c525e56b07e3bb432 (diff)
parentef227e781421493a25e47b16648aa0bf4c6f113c (diff)
downloadextras-8e9a435202341406798291588da28af3c1921027.tar.gz
simpleperf: check errors in CanSampleRegsFor32BitABI() am: d85e633e1f am: ef227e7814
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/extras/+/24243769 Change-Id: Ifb69bbd09ed55837a3c94ef69a1288935a9e8458 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--simpleperf/test_util.cpp16
-rw-r--r--simpleperf/test_util.h7
2 files changed, 16 insertions, 7 deletions
diff --git a/simpleperf/test_util.cpp b/simpleperf/test_util.cpp
index ad667e22..7e99b5d5 100644
--- a/simpleperf/test_util.cpp
+++ b/simpleperf/test_util.cpp
@@ -56,7 +56,7 @@ static std::optional<bool> CanSampleRegsFor32BitABI() {
return false;
}
-bool IsInNativeAbi() {
+std::optional<bool> IsInNativeAbi() {
static int in_native_abi = -1;
if (in_native_abi == -1) {
FILE* fp = popen("uname -m", "re");
@@ -76,9 +76,11 @@ bool IsInNativeAbi() {
}
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;
+ // 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) {
@@ -87,6 +89,9 @@ bool IsInNativeAbi() {
}
}
}
+ if (in_native_abi == 2) {
+ return std::nullopt;
+ }
return in_native_abi == 1;
}
@@ -121,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; \
} \