summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2019-02-22 00:13:48 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-02-22 00:13:48 +0000
commit0c7c5a310de5db8e3c45dfd6179a299a4fce9170 (patch)
treed5c3e1865b5e16f7d98b9e179a18d86fe84602d5
parent1e73bcce67e3fbc3e0281fdaf52d83e3708fac47 (diff)
parent422fec375b83c4e8fd5bf8cd19d285b12f715826 (diff)
downloadextras-android-cts-9.0_r8.tar.gz
Merge "Snap for 5328068 from 429c4770daf538112ba0424b919450e5e1228754 to pie-cts-release" into pie-cts-releaseandroid-cts-9.0_r8android-cts-9.0_r7
-rw-r--r--simpleperf/cmd_record_test.cpp66
-rw-r--r--simpleperf/cmd_report_test.cpp2
-rw-r--r--simpleperf/cmd_stat_test.cpp1
-rw-r--r--simpleperf/environment.cpp13
-rw-r--r--simpleperf/environment.h2
-rw-r--r--simpleperf/environment_test.cpp7
-rw-r--r--simpleperf/test_util.h9
7 files changed, 98 insertions, 2 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp
index 8fea4382..216fe2d1 100644
--- a/simpleperf/cmd_record_test.cpp
+++ b/simpleperf/cmd_record_test.cpp
@@ -57,9 +57,13 @@ static bool RunRecordCmd(std::vector<std::string> v,
return RecordCmd()->Run(v);
}
-TEST(record_cmd, no_options) { ASSERT_TRUE(RunRecordCmd({})); }
+TEST(record_cmd, no_options) {
+ TEST_REQUIRE_HW_COUNTER();
+ ASSERT_TRUE(RunRecordCmd({}));
+}
TEST(record_cmd, system_wide_option) {
+ TEST_REQUIRE_HW_COUNTER();
TEST_IN_ROOT(ASSERT_TRUE(RunRecordCmd({"-a"})));
}
@@ -86,6 +90,7 @@ void CheckEventType(const std::string& record_file, const std::string event_type
}
TEST(record_cmd, sample_period_option) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({"-c", "100000"}, tmpfile.path));
CheckEventType(tmpfile.path, "cpu-cycles", 100000u, 0);
@@ -96,6 +101,7 @@ TEST(record_cmd, event_option) {
}
TEST(record_cmd, freq_option) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({"-f", "99"}, tmpfile.path));
CheckEventType(tmpfile.path, "cpu-cycles", 0, 99u);
@@ -105,6 +111,7 @@ TEST(record_cmd, freq_option) {
}
TEST(record_cmd, multiple_freq_or_sample_period_option) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({"-f", "99", "-e", "cpu-cycles", "-c", "1000000", "-e",
"cpu-clock"}, tmpfile.path));
@@ -113,11 +120,13 @@ TEST(record_cmd, multiple_freq_or_sample_period_option) {
}
TEST(record_cmd, output_file_option) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RecordCmd()->Run({"-o", tmpfile.path, "sleep", SLEEP_SEC}));
}
TEST(record_cmd, dump_kernel_mmap) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({}, tmpfile.path));
std::unique_ptr<RecordFileReader> reader =
@@ -141,6 +150,7 @@ TEST(record_cmd, dump_kernel_mmap) {
}
TEST(record_cmd, dump_build_id_feature) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({}, tmpfile.path));
std::unique_ptr<RecordFileReader> reader =
@@ -157,6 +167,7 @@ TEST(record_cmd, tracepoint_event) {
}
TEST(record_cmd, branch_sampling) {
+ TEST_REQUIRE_HW_COUNTER();
if (IsBranchSamplingSupported()) {
ASSERT_TRUE(RunRecordCmd({"-b"}));
ASSERT_TRUE(RunRecordCmd({"-j", "any,any_call,any_ret,ind_call"}));
@@ -170,14 +181,17 @@ TEST(record_cmd, branch_sampling) {
}
TEST(record_cmd, event_modifier) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(RunRecordCmd({"-e", "cpu-cycles:u"}));
}
TEST(record_cmd, fp_callchain_sampling) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(RunRecordCmd({"--call-graph", "fp"}));
}
TEST(record_cmd, fp_callchain_sampling_warning_on_arm) {
+ TEST_REQUIRE_HW_COUNTER();
if (GetBuildArch() != ARCH_ARM) {
GTEST_LOG_(INFO) << "This test does nothing as it only tests on arm arch.";
return;
@@ -190,6 +204,7 @@ TEST(record_cmd, fp_callchain_sampling_warning_on_arm) {
}
TEST(record_cmd, system_wide_fp_callchain_sampling) {
+ TEST_REQUIRE_HW_COUNTER();
TEST_IN_ROOT(ASSERT_TRUE(RunRecordCmd({"-a", "--call-graph", "fp"})));
}
@@ -216,7 +231,26 @@ bool IsInNativeAbi() {
return in_native_abi == 1;
}
+bool HasHardwareCounter() {
+ static int has_hw_counter = -1;
+ if (has_hw_counter == -1) {
+ has_hw_counter = 1;
+#if defined(__arm__)
+ std::string cpu_info;
+ if (android::base::ReadFileToString("/proc/cpuinfo", &cpu_info)) {
+ std::string hardware = GetHardwareFromCpuInfo(cpu_info);
+ if (std::regex_search(hardware, std::regex(R"(i\.MX6.*Quad)")) ||
+ std::regex_search(hardware, std::regex(R"(SC7731e)")) ) {
+ has_hw_counter = 0;
+ }
+ }
+#endif
+ }
+ return has_hw_counter == 1;
+}
+
TEST(record_cmd, dwarf_callchain_sampling) {
+ TEST_REQUIRE_HW_COUNTER();
OMIT_TEST_ON_NON_NATIVE_ABIS();
ASSERT_TRUE(IsDwarfCallChainSamplingSupported());
std::vector<std::unique_ptr<Workload>> workloads;
@@ -229,12 +263,14 @@ TEST(record_cmd, dwarf_callchain_sampling) {
}
TEST(record_cmd, system_wide_dwarf_callchain_sampling) {
+ TEST_REQUIRE_HW_COUNTER();
OMIT_TEST_ON_NON_NATIVE_ABIS();
ASSERT_TRUE(IsDwarfCallChainSamplingSupported());
TEST_IN_ROOT(RunRecordCmd({"-a", "--call-graph", "dwarf"}));
}
TEST(record_cmd, no_unwind_option) {
+ TEST_REQUIRE_HW_COUNTER();
OMIT_TEST_ON_NON_NATIVE_ABIS();
ASSERT_TRUE(IsDwarfCallChainSamplingSupported());
ASSERT_TRUE(RunRecordCmd({"--call-graph", "dwarf", "--no-unwind"}));
@@ -242,6 +278,7 @@ TEST(record_cmd, no_unwind_option) {
}
TEST(record_cmd, no_post_unwind_option) {
+ TEST_REQUIRE_HW_COUNTER();
OMIT_TEST_ON_NON_NATIVE_ABIS();
ASSERT_TRUE(IsDwarfCallChainSamplingSupported());
std::vector<std::unique_ptr<Workload>> workloads;
@@ -254,6 +291,7 @@ TEST(record_cmd, no_post_unwind_option) {
}
TEST(record_cmd, existing_processes) {
+ TEST_REQUIRE_HW_COUNTER();
std::vector<std::unique_ptr<Workload>> workloads;
CreateProcesses(2, &workloads);
std::string pid_list = android::base::StringPrintf(
@@ -262,6 +300,7 @@ TEST(record_cmd, existing_processes) {
}
TEST(record_cmd, existing_threads) {
+ TEST_REQUIRE_HW_COUNTER();
std::vector<std::unique_ptr<Workload>> workloads;
CreateProcesses(2, &workloads);
// Process id can also be used as thread id in linux.
@@ -271,6 +310,7 @@ TEST(record_cmd, existing_threads) {
}
TEST(record_cmd, no_monitored_threads) {
+ TEST_REQUIRE_HW_COUNTER();
ScopedAppPackageName scoped_package_name("");
TemporaryFile tmpfile;
ASSERT_FALSE(RecordCmd()->Run({"-o", tmpfile.path}));
@@ -278,11 +318,13 @@ TEST(record_cmd, no_monitored_threads) {
}
TEST(record_cmd, more_than_one_event_types) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(RunRecordCmd({"-e", "cpu-cycles,cpu-clock"}));
ASSERT_TRUE(RunRecordCmd({"-e", "cpu-cycles", "-e", "cpu-clock"}));
}
TEST(record_cmd, mmap_page_option) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(RunRecordCmd({"-m", "1"}));
ASSERT_FALSE(RunRecordCmd({"-m", "0"}));
ASSERT_FALSE(RunRecordCmd({"-m", "7"}));
@@ -307,6 +349,7 @@ static void CheckKernelSymbol(const std::string& path, bool need_kallsyms,
}
TEST(record_cmd, kernel_symbol) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({"--no-dump-symbols"}, tmpfile.path));
bool success;
@@ -358,6 +401,7 @@ static void CheckDsoSymbolRecords(const std::string& path,
}
TEST(record_cmd, no_dump_symbols) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({}, tmpfile.path));
bool success;
@@ -380,6 +424,7 @@ TEST(record_cmd, no_dump_symbols) {
}
TEST(record_cmd, dump_kernel_symbols) {
+ TEST_REQUIRE_HW_COUNTER();
if (!IsRoot()) {
GTEST_LOG_(INFO) << "Test requires root privilege";
return;
@@ -405,15 +450,20 @@ TEST(record_cmd, dump_kernel_symbols) {
}
TEST(record_cmd, group_option) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(RunRecordCmd({"--group", "cpu-cycles,cpu-clock", "-m", "16"}));
ASSERT_TRUE(RunRecordCmd({"--group", "cpu-cycles,cpu-clock", "--group",
"cpu-cycles:u,cpu-clock:u", "--group",
"cpu-cycles:k,cpu-clock:k", "-m", "16"}));
}
-TEST(record_cmd, symfs_option) { ASSERT_TRUE(RunRecordCmd({"--symfs", "/"})); }
+TEST(record_cmd, symfs_option) {
+ TEST_REQUIRE_HW_COUNTER();
+ ASSERT_TRUE(RunRecordCmd({"--symfs", "/"}));
+}
TEST(record_cmd, duration_option) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RecordCmd()->Run({"--duration", "1.2", "-p",
std::to_string(getpid()), "-o", tmpfile.path, "--in-app"}));
@@ -431,6 +481,7 @@ TEST(record_cmd, support_modifier_for_clock_events) {
}
TEST(record_cmd, handle_SIGHUP) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
int pipefd[2];
ASSERT_EQ(0, pipe(pipefd));
@@ -450,6 +501,7 @@ TEST(record_cmd, handle_SIGHUP) {
}
TEST(record_cmd, stop_when_no_more_targets) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
std::atomic<int> tid(0);
std::thread thread([&]() {
@@ -462,6 +514,7 @@ TEST(record_cmd, stop_when_no_more_targets) {
}
TEST(record_cmd, donot_stop_when_having_targets) {
+ TEST_REQUIRE_HW_COUNTER();
std::vector<std::unique_ptr<Workload>> workloads;
CreateProcesses(1, &workloads);
std::string pid = std::to_string(workloads[0]->GetPid());
@@ -473,6 +526,7 @@ TEST(record_cmd, donot_stop_when_having_targets) {
}
TEST(record_cmd, start_profiling_fd_option) {
+ TEST_REQUIRE_HW_COUNTER();
int pipefd[2];
ASSERT_EQ(0, pipe(pipefd));
int read_fd = pipefd[0];
@@ -491,6 +545,7 @@ TEST(record_cmd, start_profiling_fd_option) {
}
TEST(record_cmd, record_meta_info_feature) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RunRecordCmd({}, tmpfile.path));
std::unique_ptr<RecordFileReader> reader = RecordFileReader::CreateInstance(tmpfile.path);
@@ -516,6 +571,7 @@ TEST(record_cmd, cpu_clock_for_a_long_time) {
}
TEST(record_cmd, dump_regs_for_tracepoint_events) {
+ TEST_REQUIRE_HW_COUNTER();
TEST_REQUIRE_HOST_ROOT();
OMIT_TEST_ON_NON_NATIVE_ABIS();
// Check if the kernel can dump registers for tracepoint events.
@@ -525,6 +581,7 @@ TEST(record_cmd, dump_regs_for_tracepoint_events) {
}
TEST(record_cmd, trace_offcpu_option) {
+ TEST_REQUIRE_HW_COUNTER();
// On linux host, we need root privilege to read tracepoint events.
TEST_REQUIRE_HOST_ROOT();
OMIT_TEST_ON_NON_NATIVE_ABIS();
@@ -539,10 +596,12 @@ TEST(record_cmd, trace_offcpu_option) {
}
TEST(record_cmd, exit_with_parent_option) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(RunRecordCmd({"--exit-with-parent"}));
}
TEST(record_cmd, clockid_option) {
+ TEST_REQUIRE_HW_COUNTER();
if (!IsSettingClockIdSupported()) {
ASSERT_FALSE(RunRecordCmd({"--clockid", "monotonic"}));
} else {
@@ -557,6 +616,7 @@ TEST(record_cmd, clockid_option) {
}
TEST(record_cmd, generate_samples_by_hw_counters) {
+ TEST_REQUIRE_HW_COUNTER();
std::vector<std::string> events = {"cpu-cycles", "instructions"};
for (auto& event : events) {
TemporaryFile tmpfile;
@@ -575,11 +635,13 @@ TEST(record_cmd, generate_samples_by_hw_counters) {
}
TEST(record_cmd, callchain_joiner_options) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(RunRecordCmd({"--no-callchain-joiner"}));
ASSERT_TRUE(RunRecordCmd({"--callchain-joiner-min-matching-nodes", "2"}));
}
TEST(record_cmd, dashdash) {
+ TEST_REQUIRE_HW_COUNTER();
TemporaryFile tmpfile;
ASSERT_TRUE(RecordCmd()->Run({"-o", tmpfile.path, "--", "sleep", "1"}));
}
diff --git a/simpleperf/cmd_report_test.cpp b/simpleperf/cmd_report_test.cpp
index 6ebbf31e..4dc22c3d 100644
--- a/simpleperf/cmd_report_test.cpp
+++ b/simpleperf/cmd_report_test.cpp
@@ -499,6 +499,7 @@ static std::unique_ptr<Command> RecordCmd() {
}
TEST_F(ReportCommandTest, dwarf_callgraph) {
+ TEST_REQUIRE_HW_COUNTER();
OMIT_TEST_ON_NON_NATIVE_ABIS();
ASSERT_TRUE(IsDwarfCallChainSamplingSupported());
std::vector<std::unique_ptr<Workload>> workloads;
@@ -521,6 +522,7 @@ TEST_F(ReportCommandTest, report_dwarf_callgraph_of_nativelib_in_apk) {
}
TEST_F(ReportCommandTest, exclude_kernel_callchain) {
+ TEST_REQUIRE_HW_COUNTER();
TEST_REQUIRE_HOST_ROOT();
OMIT_TEST_ON_NON_NATIVE_ABIS();
std::vector<std::unique_ptr<Workload>> workloads;
diff --git a/simpleperf/cmd_stat_test.cpp b/simpleperf/cmd_stat_test.cpp
index c24ccbc9..87bbcb70 100644
--- a/simpleperf/cmd_stat_test.cpp
+++ b/simpleperf/cmd_stat_test.cpp
@@ -52,6 +52,7 @@ TEST(stat_cmd, tracepoint_event) {
}
TEST(stat_cmd, event_modifier) {
+ TEST_REQUIRE_HW_COUNTER();
ASSERT_TRUE(
StatCmd()->Run({"-e", "cpu-cycles:u,cpu-cycles:k", "sleep", "1"}));
}
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index 48f4ad54..870d6488 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -727,3 +727,16 @@ bool SignalIsIgnored(int signo) {
return act.sa_handler == SIG_IGN;
}
+
+std::string GetHardwareFromCpuInfo(const std::string& cpu_info) {
+ for (auto& line : android::base::Split(cpu_info, "\n")) {
+ size_t pos = line.find(':');
+ if (pos != std::string::npos) {
+ std::string key = android::base::Trim(line.substr(0, pos));
+ if (key == "Hardware") {
+ return android::base::Trim(line.substr(pos + 1));
+ }
+ }
+ }
+ return "";
+}
diff --git a/simpleperf/environment.h b/simpleperf/environment.h
index 84794f2c..7f8683de 100644
--- a/simpleperf/environment.h
+++ b/simpleperf/environment.h
@@ -118,4 +118,6 @@ class ScopedTempFiles {
bool SignalIsIgnored(int signo);
+std::string GetHardwareFromCpuInfo(const std::string& cpu_info);
+
#endif // SIMPLE_PERF_ENVIRONMENT_H_
diff --git a/simpleperf/environment_test.cpp b/simpleperf/environment_test.cpp
index 5b7c81e6..e61108d0 100644
--- a/simpleperf/environment_test.cpp
+++ b/simpleperf/environment_test.cpp
@@ -44,3 +44,10 @@ TEST(environment, PrepareVdsoFile) {
ASSERT_TRUE(dso != nullptr);
ASSERT_NE(dso->GetDebugFilePath(), "[vdso]");
}
+
+TEST(environment, GetHardwareFromCpuInfo) {
+ std::string cpu_info = "CPU revision : 10\n\n"
+ "Hardware : Symbol i.MX6 Freeport_Plat Quad/DualLite (Device Tree)\n";
+ ASSERT_EQ("Symbol i.MX6 Freeport_Plat Quad/DualLite (Device Tree)",
+ GetHardwareFromCpuInfo(cpu_info));
+}
diff --git a/simpleperf/test_util.h b/simpleperf/test_util.h
index 054acdea..cd74f645 100644
--- a/simpleperf/test_util.h
+++ b/simpleperf/test_util.h
@@ -72,3 +72,12 @@ class ScopedAppPackageName {
private:
std::string saved_name_;
};
+
+bool HasHardwareCounter();
+#define TEST_REQUIRE_HW_COUNTER() \
+ do { \
+ if (!HasHardwareCounter()) { \
+ GTEST_LOG_(INFO) << "Skip this test as the machine doesn't have hardware PMU counters."; \
+ return; \
+ } \
+ } while (0)