From a486a4b8aeeffb7bd0574134ca16c9ca1c061847 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Mon, 27 Jun 2016 16:00:20 -0700 Subject: [PATCH] Simpleperf: fix flaky tests. Simpleperf stat/record command may need 1 second to set security.perf_harden property. So the monitored child threads should run longer than 1 second. Bug: 29763505 Change-Id: I9bf6dcba03f3fc5c91130f38a08ce0062e104103 --- simpleperf/cmd_record_test.cpp | 5 ++--- simpleperf/cmd_stat_test.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index a89febfe..1a468e29 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -171,8 +171,7 @@ TEST(record_cmd, existing_processes) { CreateProcesses(2, &workloads); std::string pid_list = android::base::StringPrintf("%d,%d", workloads[0]->GetPid(), workloads[1]->GetPid()); - TemporaryFile tmpfile; - ASSERT_TRUE(RecordCmd()->Run({"-p", pid_list, "-o", tmpfile.path})); + ASSERT_TRUE(RunRecordCmd({"-p", pid_list})); } TEST(record_cmd, existing_threads) { @@ -182,7 +181,7 @@ TEST(record_cmd, existing_threads) { std::string tid_list = android::base::StringPrintf("%d,%d", workloads[0]->GetPid(), workloads[1]->GetPid()); TemporaryFile tmpfile; - ASSERT_TRUE(RecordCmd()->Run({"-t", tid_list, "-o", tmpfile.path})); + ASSERT_TRUE(RunRecordCmd({"-t", tid_list})); } TEST(record_cmd, no_monitored_threads) { diff --git a/simpleperf/cmd_stat_test.cpp b/simpleperf/cmd_stat_test.cpp index 27f1f091..45ed3dc5 100644 --- a/simpleperf/cmd_stat_test.cpp +++ b/simpleperf/cmd_stat_test.cpp @@ -57,7 +57,8 @@ TEST(stat_cmd, event_modifier) { void CreateProcesses(size_t count, std::vector>* workloads) { workloads->clear(); for (size_t i = 0; i < count; ++i) { - auto workload = Workload::CreateWorkload({"sleep", "1"}); + // Create a workload runs longer than profiling time. + auto workload = Workload::CreateWorkload({"sleep", "1000"}); ASSERT_TRUE(workload != nullptr); ASSERT_TRUE(workload->Start()); workloads->push_back(std::move(workload)); @@ -69,7 +70,7 @@ TEST(stat_cmd, existing_processes) { CreateProcesses(2, &workloads); std::string pid_list = android::base::StringPrintf("%d,%d", workloads[0]->GetPid(), workloads[1]->GetPid()); - ASSERT_TRUE(StatCmd()->Run({"-p", pid_list})); + ASSERT_TRUE(StatCmd()->Run({"-p", pid_list, "sleep", "1"})); } TEST(stat_cmd, existing_threads) { @@ -78,7 +79,7 @@ TEST(stat_cmd, existing_threads) { // Process id can be used as thread id in linux. std::string tid_list = android::base::StringPrintf("%d,%d", workloads[0]->GetPid(), workloads[1]->GetPid()); - ASSERT_TRUE(StatCmd()->Run({"-t", tid_list})); + ASSERT_TRUE(StatCmd()->Run({"-t", tid_list, "sleep", "1"})); } TEST(stat_cmd, no_monitored_threads) { -- 2.11.0