Skip to content

Commit 025745a

Browse files
committed
simpleperf: port cmd_report_test to nonlinux.
And fix one build_id bug introduced by previous patch. Bug: 26962895 Change-Id: Ibb8bd6ec77ee862bb01c26342d3b3024468e75b2 (cherry picked from commit 6e51bef)
1 parent cc9bc34 commit 025745a

16 files changed

+285
-97
lines changed

simpleperf/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ include $(BUILD_HOST_EXECUTABLE)
176176
# simpleperf_unit_test
177177
# =========================================================
178178
simpleperf_unit_test_src_files := \
179+
cmd_report_test.cpp \
179180
command_test.cpp \
180181
gtest_main.cpp \
181182
read_apk_test.cpp \
@@ -187,7 +188,6 @@ simpleperf_unit_test_src_files_linux := \
187188
cmd_dumprecord_test.cpp \
188189
cmd_list_test.cpp \
189190
cmd_record_test.cpp \
190-
cmd_report_test.cpp \
191191
cmd_stat_test.cpp \
192192
environment_test.cpp \
193193
record_file_test.cpp \

simpleperf/cmd_dumprecord_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <gtest/gtest.h>
1818

1919
#include "command.h"
20+
#include "test_util.h"
2021

2122
class DumpRecordCommandTest : public ::testing::Test {
2223
protected:
@@ -32,11 +33,11 @@ class DumpRecordCommandTest : public ::testing::Test {
3233
};
3334

3435
TEST_F(DumpRecordCommandTest, no_options) {
35-
ASSERT_TRUE(record_cmd->Run({"-a", "sleep", "1"}));
36+
ASSERT_TRUE(record_cmd->Run({"-a", "sleep", SLEEP_SEC}));
3637
ASSERT_TRUE(dumprecord_cmd->Run({}));
3738
}
3839

3940
TEST_F(DumpRecordCommandTest, record_file_option) {
40-
ASSERT_TRUE(record_cmd->Run({"-a", "-o", "perf2.data", "sleep", "1"}));
41+
ASSERT_TRUE(record_cmd->Run({"-a", "-o", "perf2.data", "sleep", SLEEP_SEC}));
4142
ASSERT_TRUE(dumprecord_cmd->Run({"perf2.data"}));
4243
}

simpleperf/cmd_record_test.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,32 @@ static std::unique_ptr<Command> RecordCmd() {
3232
}
3333

3434
TEST(record_cmd, no_options) {
35-
ASSERT_TRUE(RecordCmd()->Run({"sleep", "1"}));
35+
ASSERT_TRUE(RecordCmd()->Run({"sleep", SLEEP_SEC}));
3636
}
3737

3838
TEST(record_cmd, system_wide_option) {
39-
ASSERT_TRUE(RecordCmd()->Run({"-a", "sleep", "1"}));
39+
ASSERT_TRUE(RecordCmd()->Run({"-a", "sleep", SLEEP_SEC}));
4040
}
4141

4242
TEST(record_cmd, sample_period_option) {
43-
ASSERT_TRUE(RecordCmd()->Run({"-c", "100000", "sleep", "1"}));
43+
ASSERT_TRUE(RecordCmd()->Run({"-c", "100000", "sleep", SLEEP_SEC}));
4444
}
4545

4646
TEST(record_cmd, event_option) {
47-
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-clock", "sleep", "1"}));
47+
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-clock", "sleep", SLEEP_SEC}));
4848
}
4949

5050
TEST(record_cmd, freq_option) {
51-
ASSERT_TRUE(RecordCmd()->Run({"-f", "99", "sleep", "1"}));
52-
ASSERT_TRUE(RecordCmd()->Run({"-F", "99", "sleep", "1"}));
51+
ASSERT_TRUE(RecordCmd()->Run({"-f", "99", "sleep", SLEEP_SEC}));
52+
ASSERT_TRUE(RecordCmd()->Run({"-F", "99", "sleep", SLEEP_SEC}));
5353
}
5454

5555
TEST(record_cmd, output_file_option) {
56-
ASSERT_TRUE(RecordCmd()->Run({"-o", "perf2.data", "sleep", "1"}));
56+
ASSERT_TRUE(RecordCmd()->Run({"-o", "perf2.data", "sleep", SLEEP_SEC}));
5757
}
5858

5959
TEST(record_cmd, dump_kernel_mmap) {
60-
ASSERT_TRUE(RecordCmd()->Run({"sleep", "1"}));
60+
ASSERT_TRUE(RecordCmd()->Run({"sleep", SLEEP_SEC}));
6161
std::unique_ptr<RecordFileReader> reader = RecordFileReader::CreateInstance("perf.data");
6262
ASSERT_TRUE(reader != nullptr);
6363
std::vector<std::unique_ptr<Record>> records = reader->DataSection();
@@ -76,7 +76,7 @@ TEST(record_cmd, dump_kernel_mmap) {
7676
}
7777

7878
TEST(record_cmd, dump_build_id_feature) {
79-
ASSERT_TRUE(RecordCmd()->Run({"sleep", "1"}));
79+
ASSERT_TRUE(RecordCmd()->Run({"sleep", SLEEP_SEC}));
8080
std::unique_ptr<RecordFileReader> reader = RecordFileReader::CreateInstance("perf.data");
8181
ASSERT_TRUE(reader != nullptr);
8282
const FileHeader& file_header = reader->FileHeader();
@@ -85,35 +85,35 @@ TEST(record_cmd, dump_build_id_feature) {
8585
}
8686

8787
TEST(record_cmd, tracepoint_event) {
88-
ASSERT_TRUE(RecordCmd()->Run({"-a", "-e", "sched:sched_switch", "sleep", "1"}));
88+
ASSERT_TRUE(RecordCmd()->Run({"-a", "-e", "sched:sched_switch", "sleep", SLEEP_SEC}));
8989
}
9090

9191
TEST(record_cmd, branch_sampling) {
9292
if (IsBranchSamplingSupported()) {
93-
ASSERT_TRUE(RecordCmd()->Run({"-a", "-b", "sleep", "1"}));
94-
ASSERT_TRUE(RecordCmd()->Run({"-j", "any,any_call,any_ret,ind_call", "sleep", "1"}));
95-
ASSERT_TRUE(RecordCmd()->Run({"-j", "any,k", "sleep", "1"}));
96-
ASSERT_TRUE(RecordCmd()->Run({"-j", "any,u", "sleep", "1"}));
97-
ASSERT_FALSE(RecordCmd()->Run({"-j", "u", "sleep", "1"}));
93+
ASSERT_TRUE(RecordCmd()->Run({"-a", "-b", "sleep", SLEEP_SEC}));
94+
ASSERT_TRUE(RecordCmd()->Run({"-j", "any,any_call,any_ret,ind_call", "sleep", SLEEP_SEC}));
95+
ASSERT_TRUE(RecordCmd()->Run({"-j", "any,k", "sleep", SLEEP_SEC}));
96+
ASSERT_TRUE(RecordCmd()->Run({"-j", "any,u", "sleep", SLEEP_SEC}));
97+
ASSERT_FALSE(RecordCmd()->Run({"-j", "u", "sleep", SLEEP_SEC}));
9898
} else {
9999
GTEST_LOG_(INFO)
100100
<< "This test does nothing as branch stack sampling is not supported on this device.";
101101
}
102102
}
103103

104104
TEST(record_cmd, event_modifier) {
105-
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-cycles:u", "sleep", "1"}));
105+
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-cycles:u", "sleep", SLEEP_SEC}));
106106
}
107107

108108
TEST(record_cmd, fp_callchain_sampling) {
109-
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "fp", "sleep", "1"}));
109+
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "fp", "sleep", SLEEP_SEC}));
110110
}
111111

112112
TEST(record_cmd, dwarf_callchain_sampling) {
113113
if (IsDwarfCallChainSamplingSupported()) {
114-
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf", "sleep", "1"}));
115-
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf,16384", "sleep", "1"}));
116-
ASSERT_TRUE(RecordCmd()->Run({"-g", "sleep", "1"}));
114+
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf", "sleep", SLEEP_SEC}));
115+
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf,16384", "sleep", SLEEP_SEC}));
116+
ASSERT_TRUE(RecordCmd()->Run({"-g", "sleep", SLEEP_SEC}));
117117
} else {
118118
GTEST_LOG_(INFO)
119119
<< "This test does nothing as dwarf callchain sampling is not supported on this device.";
@@ -122,24 +122,24 @@ TEST(record_cmd, dwarf_callchain_sampling) {
122122

123123
TEST(record_cmd, no_unwind_option) {
124124
if (IsDwarfCallChainSamplingSupported()) {
125-
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf", "--no-unwind", "sleep", "1"}));
125+
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf", "--no-unwind", "sleep", SLEEP_SEC}));
126126
} else {
127127
GTEST_LOG_(INFO)
128128
<< "This test does nothing as dwarf callchain sampling is not supported on this device.";
129129
}
130-
ASSERT_FALSE(RecordCmd()->Run({"--no-unwind", "sleep", "1"}));
130+
ASSERT_FALSE(RecordCmd()->Run({"--no-unwind", "sleep", SLEEP_SEC}));
131131
}
132132

133133
TEST(record_cmd, post_unwind_option) {
134134
if (IsDwarfCallChainSamplingSupported()) {
135-
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf", "--post-unwind", "sleep", "1"}));
135+
ASSERT_TRUE(RecordCmd()->Run({"--call-graph", "dwarf", "--post-unwind", "sleep", SLEEP_SEC}));
136136
} else {
137137
GTEST_LOG_(INFO)
138138
<< "This test does nothing as dwarf callchain sampling is not supported on this device.";
139139
}
140-
ASSERT_FALSE(RecordCmd()->Run({"--post-unwind", "sleep", "1"}));
140+
ASSERT_FALSE(RecordCmd()->Run({"--post-unwind", "sleep", SLEEP_SEC}));
141141
ASSERT_FALSE(
142-
RecordCmd()->Run({"--call-graph", "dwarf", "--no-unwind", "--post-unwind", "sleep", "1"}));
142+
RecordCmd()->Run({"--call-graph", "dwarf", "--no-unwind", "--post-unwind", "sleep", SLEEP_SEC}));
143143
}
144144

145145
TEST(record_cmd, existing_processes) {
@@ -164,17 +164,17 @@ TEST(record_cmd, no_monitored_threads) {
164164
}
165165

166166
TEST(record_cmd, more_than_one_event_types) {
167-
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-cycles,cpu-clock", "sleep", "1"}));
168-
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-cycles", "-e", "cpu-clock", "sleep", "1"}));
167+
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-cycles,cpu-clock", "sleep", SLEEP_SEC}));
168+
ASSERT_TRUE(RecordCmd()->Run({"-e", "cpu-cycles", "-e", "cpu-clock", "sleep", SLEEP_SEC}));
169169
}
170170

171171
TEST(record_cmd, cpu_option) {
172-
ASSERT_TRUE(RecordCmd()->Run({"--cpu", "0", "sleep", "1"}));
173-
ASSERT_TRUE(RecordCmd()->Run({"--cpu", "0", "-a", "sleep", "1"}));
172+
ASSERT_TRUE(RecordCmd()->Run({"--cpu", "0", "sleep", SLEEP_SEC}));
173+
ASSERT_TRUE(RecordCmd()->Run({"--cpu", "0", "-a", "sleep", SLEEP_SEC}));
174174
}
175175

176176
TEST(record_cmd, mmap_page_option) {
177-
ASSERT_TRUE(RecordCmd()->Run({"-m", "1", "sleep", "1"}));
178-
ASSERT_FALSE(RecordCmd()->Run({"-m", "0", "sleep", "1"}));
179-
ASSERT_FALSE(RecordCmd()->Run({"-m", "7", "sleep", "1"}));
177+
ASSERT_TRUE(RecordCmd()->Run({"-m", "1", "sleep", SLEEP_SEC}));
178+
ASSERT_FALSE(RecordCmd()->Run({"-m", "0", "sleep", SLEEP_SEC}));
179+
ASSERT_FALSE(RecordCmd()->Run({"-m", "7", "sleep", SLEEP_SEC}));
180180
}

0 commit comments

Comments
 (0)