blob: b208479111cc6c940b8faba1a6fef5fa57f1f267 [file] [log] [blame]
Yabin Cui2672dea2015-05-21 12:17:23 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
Yabin Cui6e51bef2016-02-23 21:41:03 -080019#include <set>
20#include <unordered_map>
21
Yabin Cuib1a885b2016-02-14 19:18:02 -080022#include <android-base/file.h>
Yabin Cuie3ca9982020-10-16 13:16:26 -070023#include <android-base/parseint.h>
Yabin Cui6e51bef2016-02-23 21:41:03 -080024#include <android-base/strings.h>
Yabin Cuic4d9ead2022-01-06 15:41:31 -080025#include <android-base/test_utils.h>
Yabin Cuib1a885b2016-02-14 19:18:02 -080026
Yabin Cuif00f4fc2022-11-23 15:15:30 -080027#include "RegEx.h"
Yabin Cui2672dea2015-05-21 12:17:23 -070028#include "command.h"
Yabin Cuib1a885b2016-02-14 19:18:02 -080029#include "get_test_data.h"
Yabin Cui8f680f62016-03-18 18:47:43 -070030#include "perf_regs.h"
Yabin Cuib1a885b2016-02-14 19:18:02 -080031#include "read_apk.h"
Yabin Cui6e51bef2016-02-23 21:41:03 -080032#include "test_util.h"
Yabin Cui2672dea2015-05-21 12:17:23 -070033
Yabin Cuiacbdb242020-07-07 15:56:34 -070034using namespace simpleperf;
35
Yabin Cui2672dea2015-05-21 12:17:23 -070036static std::unique_ptr<Command> ReportCmd() {
37 return CreateCommandInstance("report");
38}
39
Yabin Cui648c3e42024-04-02 13:12:45 -070040// @CddTest = 6.1/C-0-2
Yabin Cui2672dea2015-05-21 12:17:23 -070041class ReportCommandTest : public ::testing::Test {
42 protected:
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +020043 void Report(const std::string& perf_data,
Wei-Ning Huangb3f184f2024-03-22 00:49:18 +080044 const std::vector<std::string>& add_args = std::vector<std::string>(),
45 bool with_symfs = true) {
46 ReportRaw(GetTestData(perf_data), add_args, with_symfs);
Yabin Cui2672dea2015-05-21 12:17:23 -070047 }
Yabin Cui6e51bef2016-02-23 21:41:03 -080048
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +020049 void ReportRaw(const std::string& perf_data,
Wei-Ning Huangb3f184f2024-03-22 00:49:18 +080050 const std::vector<std::string>& add_args = std::vector<std::string>(),
51 bool with_symfs = true) {
Yabin Cui6e51bef2016-02-23 21:41:03 -080052 success = false;
Yabin Cuif560a6f2016-12-14 17:43:26 -080053 TemporaryFile tmp_file;
Wei-Ning Huangb3f184f2024-03-22 00:49:18 +080054 std::vector<std::string> args = {"-i", perf_data, "-o", tmp_file.path};
55
56 if (with_symfs) {
57 args.emplace_back("--symfs");
58 args.emplace_back(GetTestDataDir());
59 }
60
Yabin Cui6e51bef2016-02-23 21:41:03 -080061 args.insert(args.end(), add_args.begin(), add_args.end());
62 ASSERT_TRUE(ReportCmd()->Run(args));
63 ASSERT_TRUE(android::base::ReadFileToString(tmp_file.path, &content));
64 ASSERT_TRUE(!content.empty());
65 std::vector<std::string> raw_lines = android::base::Split(content, "\n");
66 lines.clear();
67 for (const auto& line : raw_lines) {
68 std::string s = android::base::Trim(line);
69 if (!s.empty()) {
70 lines.push_back(s);
71 }
72 }
73 ASSERT_GE(lines.size(), 2u);
74 success = true;
75 }
76
Yabin Cuie3ca9982020-10-16 13:16:26 -070077 size_t GetSampleCount() {
Yabin Cuif00f4fc2022-11-23 15:15:30 -080078 auto regex = RegEx::Create(R"(Samples: (\d+))");
79 auto match = regex->SearchAll(content);
80 if (match->IsValid()) {
Yabin Cuie3ca9982020-10-16 13:16:26 -070081 size_t count;
Yabin Cuif00f4fc2022-11-23 15:15:30 -080082 if (android::base::ParseUint(match->GetField(1), &count)) {
Yabin Cuie3ca9982020-10-16 13:16:26 -070083 return count;
84 }
85 }
86 return 0;
87 }
88
Yabin Cui6e51bef2016-02-23 21:41:03 -080089 std::string content;
90 std::vector<std::string> lines;
91 bool success;
Yabin Cui2672dea2015-05-21 12:17:23 -070092};
93
Yabin Cui648c3e42024-04-02 13:12:45 -070094// @CddTest = 6.1/C-0-2
Yabin Cui6e51bef2016-02-23 21:41:03 -080095TEST_F(ReportCommandTest, no_option) {
96 Report(PERF_DATA);
97 ASSERT_TRUE(success);
98 ASSERT_NE(content.find("GlobalFunc"), std::string::npos);
Yabin Cui2672dea2015-05-21 12:17:23 -070099}
100
Yabin Cui648c3e42024-04-02 13:12:45 -0700101// @CddTest = 6.1/C-0-2
Yabin Cui05400532016-03-17 21:18:53 -0700102TEST_F(ReportCommandTest, report_symbol_from_elf_file_with_mini_debug_info) {
103 Report(PERF_DATA_WITH_MINI_DEBUG_INFO);
104 ASSERT_TRUE(success);
105 ASSERT_NE(content.find("GlobalFunc"), std::string::npos);
106}
107
Yabin Cui648c3e42024-04-02 13:12:45 -0700108// @CddTest = 6.1/C-0-2
Yabin Cui2672dea2015-05-21 12:17:23 -0700109TEST_F(ReportCommandTest, sort_option_pid) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800110 Report(PERF_DATA, {"--sort", "pid"});
111 ASSERT_TRUE(success);
112 size_t line_index = 0;
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200113 while (line_index < lines.size() && lines[line_index].find("Pid") == std::string::npos) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800114 line_index++;
115 }
116 ASSERT_LT(line_index + 2, lines.size());
Yabin Cui2672dea2015-05-21 12:17:23 -0700117}
118
Yabin Cui648c3e42024-04-02 13:12:45 -0700119// @CddTest = 6.1/C-0-2
Yabin Cui6e51bef2016-02-23 21:41:03 -0800120TEST_F(ReportCommandTest, sort_option_more_than_one) {
121 Report(PERF_DATA, {"--sort", "comm,pid,dso,symbol"});
122 ASSERT_TRUE(success);
123 size_t line_index = 0;
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200124 while (line_index < lines.size() && lines[line_index].find("Overhead") == std::string::npos) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800125 line_index++;
126 }
127 ASSERT_LT(line_index + 1, lines.size());
128 ASSERT_NE(lines[line_index].find("Command"), std::string::npos);
129 ASSERT_NE(lines[line_index].find("Pid"), std::string::npos);
130 ASSERT_NE(lines[line_index].find("Shared Object"), std::string::npos);
131 ASSERT_NE(lines[line_index].find("Symbol"), std::string::npos);
132 ASSERT_EQ(lines[line_index].find("Tid"), std::string::npos);
Yabin Cui2672dea2015-05-21 12:17:23 -0700133}
Yabin Cui8a530e32015-06-23 20:42:01 -0700134
Yabin Cui648c3e42024-04-02 13:12:45 -0700135// @CddTest = 6.1/C-0-2
Yabin Cuiecb9a302015-07-01 10:00:52 -0700136TEST_F(ReportCommandTest, children_option) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800137 Report(CALLGRAPH_FP_PERF_DATA, {"--children", "--sort", "symbol"});
138 ASSERT_TRUE(success);
139 std::unordered_map<std::string, std::pair<double, double>> map;
140 for (size_t i = 0; i < lines.size(); ++i) {
141 char name[1024];
142 std::pair<double, double> pair;
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200143 if (sscanf(lines[i].c_str(), "%lf%%%lf%%%s", &pair.first, &pair.second, name) == 3) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800144 map.insert(std::make_pair(name, pair));
145 }
146 }
147 ASSERT_NE(map.find("GlobalFunc"), map.end());
148 ASSERT_NE(map.find("main"), map.end());
149 auto func_pair = map["GlobalFunc"];
150 auto main_pair = map["main"];
151 ASSERT_GE(main_pair.first, func_pair.first);
152 ASSERT_GE(func_pair.first, func_pair.second);
153 ASSERT_GE(func_pair.second, main_pair.second);
154}
155
156static bool CheckCalleeMode(std::vector<std::string>& lines) {
157 bool found = false;
Yabin Cuidcb2a3e2017-05-18 17:11:32 -0700158 for (size_t i = 0; i + 1 < lines.size(); ++i) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800159 if (lines[i].find("GlobalFunc") != std::string::npos &&
Yabin Cuidcb2a3e2017-05-18 17:11:32 -0700160 lines[i + 1].find("main") != std::string::npos) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800161 found = true;
162 break;
163 }
164 }
165 return found;
166}
167
168static bool CheckCallerMode(std::vector<std::string>& lines) {
169 bool found = false;
Yabin Cuidcb2a3e2017-05-18 17:11:32 -0700170 for (size_t i = 0; i + 1 < lines.size(); ++i) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800171 if (lines[i].find("main") != std::string::npos &&
Yabin Cuidcb2a3e2017-05-18 17:11:32 -0700172 lines[i + 1].find("GlobalFunc") != std::string::npos) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800173 found = true;
174 break;
175 }
176 }
177 return found;
Yabin Cuiecb9a302015-07-01 10:00:52 -0700178}
179
Yabin Cui648c3e42024-04-02 13:12:45 -0700180// @CddTest = 6.1/C-0-2
Yabin Cuiecb9a302015-07-01 10:00:52 -0700181TEST_F(ReportCommandTest, callgraph_option) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800182 Report(CALLGRAPH_FP_PERF_DATA, {"-g"});
183 ASSERT_TRUE(success);
Yabin Cui8a599d72016-07-21 18:32:53 -0700184 ASSERT_TRUE(CheckCallerMode(lines));
Yabin Cui6e51bef2016-02-23 21:41:03 -0800185 Report(CALLGRAPH_FP_PERF_DATA, {"-g", "callee"});
186 ASSERT_TRUE(success);
187 ASSERT_TRUE(CheckCalleeMode(lines));
188 Report(CALLGRAPH_FP_PERF_DATA, {"-g", "caller"});
189 ASSERT_TRUE(success);
190 ASSERT_TRUE(CheckCallerMode(lines));
191}
192
Yabin Cui767dd172016-06-02 21:02:43 -0700193static bool AllItemsWithString(std::vector<std::string>& lines,
194 const std::vector<std::string>& strs) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800195 size_t line_index = 0;
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200196 while (line_index < lines.size() && lines[line_index].find("Overhead") == std::string::npos) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800197 line_index++;
198 }
199 if (line_index == lines.size() || line_index + 1 == lines.size()) {
200 return false;
201 }
202 line_index++;
203 for (; line_index < lines.size(); ++line_index) {
204 bool exist = false;
205 for (auto& s : strs) {
206 if (lines[line_index].find(s) != std::string::npos) {
207 exist = true;
208 break;
209 }
210 }
211 if (!exist) {
212 return false;
213 }
214 }
215 return true;
Yabin Cuiecb9a302015-07-01 10:00:52 -0700216}
217
Yabin Cui648c3e42024-04-02 13:12:45 -0700218// @CddTest = 6.1/C-0-2
Yabin Cui38e573e2015-08-06 11:25:09 -0700219TEST_F(ReportCommandTest, pid_filter_option) {
Yabin Cui861f6552016-08-08 14:42:25 -0700220 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid"});
Yabin Cui6e51bef2016-02-23 21:41:03 -0800221 ASSERT_TRUE(success);
Yabin Cui861f6552016-08-08 14:42:25 -0700222 ASSERT_FALSE(AllItemsWithString(lines, {"17441"}));
223 ASSERT_FALSE(AllItemsWithString(lines, {"17441", "17443"}));
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200224 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--pids", "17441"});
Yabin Cui6e51bef2016-02-23 21:41:03 -0800225 ASSERT_TRUE(success);
Yabin Cui861f6552016-08-08 14:42:25 -0700226 ASSERT_TRUE(AllItemsWithString(lines, {"17441"}));
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200227 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--pids", "17441,17443"});
Yabin Cui861f6552016-08-08 14:42:25 -0700228 ASSERT_TRUE(success);
229 ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17443"}));
230
231 // Test that --pids option is not the same as --tids option.
232 // Thread 17445 and 17441 are in process 17441.
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200233 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid", "--pids", "17441"});
Yabin Cui861f6552016-08-08 14:42:25 -0700234 ASSERT_TRUE(success);
235 ASSERT_NE(content.find("17441"), std::string::npos);
236 ASSERT_NE(content.find("17445"), std::string::npos);
237}
238
Yabin Cui648c3e42024-04-02 13:12:45 -0700239// @CddTest = 6.1/C-0-2
Yabin Cui861f6552016-08-08 14:42:25 -0700240TEST_F(ReportCommandTest, wrong_pid_filter_option) {
241 ASSERT_EXIT(
242 {
243 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--pids", "2,bogus"});
244 exit(success ? 0 : 1);
245 },
Yabin Cui1c6be752023-02-28 11:46:37 -0800246 testing::ExitedWithCode(1), "invalid pid: bogus");
Yabin Cui38e573e2015-08-06 11:25:09 -0700247}
248
Yabin Cui648c3e42024-04-02 13:12:45 -0700249// @CddTest = 6.1/C-0-2
Yabin Cui38e573e2015-08-06 11:25:09 -0700250TEST_F(ReportCommandTest, tid_filter_option) {
Yabin Cui861f6552016-08-08 14:42:25 -0700251 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid"});
Yabin Cui6e51bef2016-02-23 21:41:03 -0800252 ASSERT_TRUE(success);
Yabin Cui861f6552016-08-08 14:42:25 -0700253 ASSERT_FALSE(AllItemsWithString(lines, {"17441"}));
254 ASSERT_FALSE(AllItemsWithString(lines, {"17441", "17445"}));
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200255 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid", "--tids", "17441"});
Yabin Cui6e51bef2016-02-23 21:41:03 -0800256 ASSERT_TRUE(success);
Yabin Cui861f6552016-08-08 14:42:25 -0700257 ASSERT_TRUE(AllItemsWithString(lines, {"17441"}));
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200258 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "tid", "--tids", "17441,17445"});
Yabin Cui861f6552016-08-08 14:42:25 -0700259 ASSERT_TRUE(success);
260 ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17445"}));
261}
262
Yabin Cui648c3e42024-04-02 13:12:45 -0700263// @CddTest = 6.1/C-0-2
Yabin Cui861f6552016-08-08 14:42:25 -0700264TEST_F(ReportCommandTest, wrong_tid_filter_option) {
265 ASSERT_EXIT(
266 {
267 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--tids", "2,bogus"});
268 exit(success ? 0 : 1);
269 },
Yabin Cuie3ca9982020-10-16 13:16:26 -0700270 testing::ExitedWithCode(1), "Invalid tid 'bogus'");
Yabin Cui38e573e2015-08-06 11:25:09 -0700271}
272
Yabin Cui648c3e42024-04-02 13:12:45 -0700273// @CddTest = 6.1/C-0-2
Yabin Cui38e573e2015-08-06 11:25:09 -0700274TEST_F(ReportCommandTest, comm_filter_option) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800275 Report(PERF_DATA, {"--sort", "comm"});
276 ASSERT_TRUE(success);
277 ASSERT_FALSE(AllItemsWithString(lines, {"t1"}));
278 ASSERT_FALSE(AllItemsWithString(lines, {"t1", "t2"}));
279 Report(PERF_DATA, {"--sort", "comm", "--comms", "t1"});
280 ASSERT_TRUE(success);
281 ASSERT_TRUE(AllItemsWithString(lines, {"t1"}));
282 Report(PERF_DATA, {"--sort", "comm", "--comms", "t1,t2"});
283 ASSERT_TRUE(success);
284 ASSERT_TRUE(AllItemsWithString(lines, {"t1", "t2"}));
Yabin Cui38e573e2015-08-06 11:25:09 -0700285}
286
Yabin Cui648c3e42024-04-02 13:12:45 -0700287// @CddTest = 6.1/C-0-2
Yabin Cui38e573e2015-08-06 11:25:09 -0700288TEST_F(ReportCommandTest, dso_filter_option) {
Yabin Cui6e51bef2016-02-23 21:41:03 -0800289 Report(PERF_DATA, {"--sort", "dso"});
290 ASSERT_TRUE(success);
291 ASSERT_FALSE(AllItemsWithString(lines, {"/t1"}));
292 ASSERT_FALSE(AllItemsWithString(lines, {"/t1", "/t2"}));
293 Report(PERF_DATA, {"--sort", "dso", "--dsos", "/t1"});
294 ASSERT_TRUE(success);
295 ASSERT_TRUE(AllItemsWithString(lines, {"/t1"}));
296 Report(PERF_DATA, {"--sort", "dso", "--dsos", "/t1,/t2"});
297 ASSERT_TRUE(success);
298 ASSERT_TRUE(AllItemsWithString(lines, {"/t1", "/t2"}));
Yabin Cui38e573e2015-08-06 11:25:09 -0700299}
300
Yabin Cui648c3e42024-04-02 13:12:45 -0700301// @CddTest = 6.1/C-0-2
Yabin Cuif79fbd12016-07-06 12:26:13 -0700302TEST_F(ReportCommandTest, symbol_filter_option) {
303 Report(PERF_DATA_WITH_SYMBOLS, {"--sort", "symbol"});
304 ASSERT_TRUE(success);
Yabin Cui05ef2ea2016-07-11 13:50:01 -0700305 ASSERT_FALSE(AllItemsWithString(lines, {"func2(int, int)"}));
306 ASSERT_FALSE(AllItemsWithString(lines, {"main", "func2(int, int)"}));
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200307 Report(PERF_DATA_WITH_SYMBOLS, {"--sort", "symbol", "--symbols", "func2(int, int)"});
Yabin Cuif79fbd12016-07-06 12:26:13 -0700308 ASSERT_TRUE(success);
Yabin Cui05ef2ea2016-07-11 13:50:01 -0700309 ASSERT_TRUE(AllItemsWithString(lines, {"func2(int, int)"}));
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200310 Report(PERF_DATA_WITH_SYMBOLS, {"--sort", "symbol", "--symbols", "main;func2(int, int)"});
Yabin Cuif79fbd12016-07-06 12:26:13 -0700311 ASSERT_TRUE(success);
Yabin Cui05ef2ea2016-07-11 13:50:01 -0700312 ASSERT_TRUE(AllItemsWithString(lines, {"main", "func2(int, int)"}));
Yabin Cuif79fbd12016-07-06 12:26:13 -0700313}
314
Yabin Cui648c3e42024-04-02 13:12:45 -0700315// @CddTest = 6.1/C-0-2
Yabin Cui4e391de2021-11-02 13:28:24 -0700316TEST_F(ReportCommandTest, dso_symbol_filter_with_children_option) {
317 // dso and symbol filter should filter different layers of the callchain separately.
318 Report("perf_display_bitmaps.data", {"--dsos", "/apex/com.android.runtime/lib64/libart.so",
319 "--children", "--raw-period", "--sort", "dso"});
320 ASSERT_TRUE(success);
321 ASSERT_NE(content.find("63500000 43250000 /apex/com.android.runtime/lib64/libart.so"),
322 std::string::npos);
323
324 Report("perf_display_bitmaps.data",
325 {"--symbols", "MterpInvokeVirtual", "--children", "--raw-period", "--sort", "symbol"});
326 ASSERT_TRUE(success);
327 ASSERT_NE(content.find("51500000 2500000 MterpInvokeVirtual"), std::string::npos);
328}
329
Yabin Cui648c3e42024-04-02 13:12:45 -0700330// @CddTest = 6.1/C-0-2
Yabin Cui6e51bef2016-02-23 21:41:03 -0800331TEST_F(ReportCommandTest, use_branch_address) {
332 Report(BRANCH_PERF_DATA, {"-b", "--sort", "symbol_from,symbol_to"});
333 std::set<std::pair<std::string, std::string>> hit_set;
334 bool after_overhead = false;
335 for (const auto& line : lines) {
336 if (!after_overhead && line.find("Overhead") != std::string::npos) {
337 after_overhead = true;
338 } else if (after_overhead) {
339 char from[80];
340 char to[80];
341 if (sscanf(line.c_str(), "%*f%%%s%s", from, to) == 2) {
342 hit_set.insert(std::make_pair<std::string, std::string>(from, to));
343 }
344 }
Yabin Cui8a530e32015-06-23 20:42:01 -0700345 }
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200346 ASSERT_NE(hit_set.find(std::make_pair<std::string, std::string>("GlobalFunc", "CalledFunc")),
Yabin Cui6e51bef2016-02-23 21:41:03 -0800347 hit_set.end());
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200348 ASSERT_NE(hit_set.find(std::make_pair<std::string, std::string>("CalledFunc", "GlobalFunc")),
Yabin Cui6e51bef2016-02-23 21:41:03 -0800349 hit_set.end());
Yabin Cui8a530e32015-06-23 20:42:01 -0700350}
Yabin Cui3c8c2132015-08-13 20:30:20 -0700351
Yabin Cui648c3e42024-04-02 13:12:45 -0700352// @CddTest = 6.1/C-0-2
Yabin Cui8f680f62016-03-18 18:47:43 -0700353TEST_F(ReportCommandTest, report_symbols_of_nativelib_in_apk) {
354 Report(NATIVELIB_IN_APK_PERF_DATA);
355 ASSERT_TRUE(success);
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200356 ASSERT_NE(content.find(GetUrlInApk(APK_FILE, NATIVELIB_IN_APK)), std::string::npos);
Yabin Cui8f680f62016-03-18 18:47:43 -0700357 ASSERT_NE(content.find("Func2"), std::string::npos);
358}
359
Yabin Cui648c3e42024-04-02 13:12:45 -0700360// @CddTest = 6.1/C-0-2
Yabin Cui2d6efe42016-04-01 20:22:35 -0700361TEST_F(ReportCommandTest, report_more_than_one_event_types) {
362 Report(PERF_DATA_WITH_TWO_EVENT_TYPES);
363 ASSERT_TRUE(success);
Yabin Cuiada97db2017-02-23 15:54:11 -0800364 size_t pos = 0;
365 ASSERT_NE(pos = content.find("cpu-cycles", pos), std::string::npos);
366 ASSERT_NE(pos = content.find("Samples:", pos), std::string::npos);
367 ASSERT_NE(pos = content.find("cpu-clock", pos), std::string::npos);
368 ASSERT_NE(pos = content.find("Samples:", pos), std::string::npos);
Yabin Cui2d6efe42016-04-01 20:22:35 -0700369}
370
Yabin Cui648c3e42024-04-02 13:12:45 -0700371// @CddTest = 6.1/C-0-2
Yabin Cuib4212972016-05-25 14:08:05 -0700372TEST_F(ReportCommandTest, report_kernel_symbol) {
373 Report(PERF_DATA_WITH_KERNEL_SYMBOL);
374 ASSERT_TRUE(success);
Yabin Cui1761a272016-06-23 17:11:14 -0700375 ASSERT_NE(content.find("perf_event_aux"), std::string::npos);
Yabin Cuib4212972016-05-25 14:08:05 -0700376}
377
Yabin Cui648c3e42024-04-02 13:12:45 -0700378// @CddTest = 6.1/C-0-2
Yabin Cui767dd172016-06-02 21:02:43 -0700379TEST_F(ReportCommandTest, report_dumped_symbols) {
380 Report(PERF_DATA_WITH_SYMBOLS);
381 ASSERT_TRUE(success);
Yabin Cui05ef2ea2016-07-11 13:50:01 -0700382 ASSERT_NE(content.find("main"), std::string::npos);
Yabin Cuic855ecc2016-07-11 17:04:54 -0700383 Report(PERF_DATA_WITH_SYMBOLS_FOR_NONZERO_MINVADDR_DSO);
384 ASSERT_TRUE(success);
Yabin Cuic5b4a312016-10-24 13:38:38 -0700385 ASSERT_NE(content.find("memcpy"), std::string::npos);
Yabin Cui767dd172016-06-02 21:02:43 -0700386}
387
Yabin Cui648c3e42024-04-02 13:12:45 -0700388// @CddTest = 6.1/C-0-2
Yabin Cuie2f10782016-12-15 12:00:44 -0800389TEST_F(ReportCommandTest, report_dumped_symbols_with_symfs_dir) {
390 // Check if we can report symbols when they appear both in perf.data and symfs dir.
391 Report(PERF_DATA_WITH_SYMBOLS, {"--symfs", GetTestDataDir()});
392 ASSERT_TRUE(success);
393 ASSERT_NE(content.find("main"), std::string::npos);
394}
395
Yabin Cui648c3e42024-04-02 13:12:45 -0700396// @CddTest = 6.1/C-0-2
Wei-Ning Huangb3f184f2024-03-22 00:49:18 +0800397TEST_F(ReportCommandTest, report_dumped_symbols_with_symdir) {
398 // Check if we can report symbols by specifying symdir.
399 Report(PERF_DATA, {"--symdir", GetTestDataDir()}, false);
400 ASSERT_TRUE(success);
401 ASSERT_NE(content.find("GlobalFunc"), std::string::npos);
402}
403
Yabin Cui648c3e42024-04-02 13:12:45 -0700404// @CddTest = 6.1/C-0-2
Yabin Cui16f93102018-11-13 11:09:20 -0800405TEST_F(ReportCommandTest, report_without_symfs_dir) {
406 TemporaryFile tmpfile;
407 ASSERT_TRUE(ReportCmd()->Run({"-i", GetTestData(PERF_DATA), "-o", tmpfile.path}));
408}
409
Yabin Cui648c3e42024-04-02 13:12:45 -0700410// @CddTest = 6.1/C-0-2
Yabin Cui9970a232016-06-29 12:18:11 -0700411TEST_F(ReportCommandTest, report_sort_vaddr_in_file) {
412 Report(PERF_DATA, {"--sort", "vaddr_in_file"});
413 ASSERT_TRUE(success);
414 ASSERT_NE(content.find("VaddrInFile"), std::string::npos);
415}
416
Yabin Cui648c3e42024-04-02 13:12:45 -0700417// @CddTest = 6.1/C-0-2
Yabin Cuieec606c2016-07-07 13:53:33 -0700418TEST_F(ReportCommandTest, check_build_id) {
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200419 Report(PERF_DATA_FOR_BUILD_ID_CHECK, {"--symfs", GetTestData(CORRECT_SYMFS_FOR_BUILD_ID_CHECK)});
Yabin Cuieec606c2016-07-07 13:53:33 -0700420 ASSERT_TRUE(success);
421 ASSERT_NE(content.find("main"), std::string::npos);
422 ASSERT_EXIT(
423 {
424 Report(PERF_DATA_FOR_BUILD_ID_CHECK,
425 {"--symfs", GetTestData(WRONG_SYMFS_FOR_BUILD_ID_CHECK)});
426 if (!success) {
427 exit(1);
428 }
429 if (content.find("main") != std::string::npos) {
430 exit(2);
431 }
432 exit(0);
433 },
Yabin Cui40b70ff2018-04-09 14:06:08 -0700434 testing::ExitedWithCode(0), "failed to read symbols from /elf_for_build_id_check");
Yabin Cuieec606c2016-07-07 13:53:33 -0700435}
436
Yabin Cui648c3e42024-04-02 13:12:45 -0700437// @CddTest = 6.1/C-0-2
Yabin Cui15475e62016-07-14 13:26:19 -0700438TEST_F(ReportCommandTest, no_show_ip_option) {
439 Report(PERF_DATA);
440 ASSERT_TRUE(success);
441 ASSERT_EQ(content.find("unknown"), std::string::npos);
442 Report(PERF_DATA, {"--no-show-ip"});
443 ASSERT_TRUE(success);
444 ASSERT_NE(content.find("unknown"), std::string::npos);
445}
446
Yabin Cui648c3e42024-04-02 13:12:45 -0700447// @CddTest = 6.1/C-0-2
Yabin Cuidec43c12016-07-29 16:40:40 -0700448TEST_F(ReportCommandTest, read_elf_file_warning) {
449 ASSERT_EXIT(
450 {
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200451 Report(PERF_DATA, {"--symfs", GetTestData(SYMFS_FOR_READ_ELF_FILE_WARNING)});
Yabin Cuidec43c12016-07-29 16:40:40 -0700452 if (!success) {
453 exit(1);
454 }
455 if (content.find("GlobalFunc") != std::string::npos) {
456 exit(2);
457 }
458 exit(0);
459 },
Yabin Cui40b70ff2018-04-09 14:06:08 -0700460 testing::ExitedWithCode(0), "failed to read symbols from /elf: File not found");
Yabin Cuidec43c12016-07-29 16:40:40 -0700461}
462
Yabin Cui648c3e42024-04-02 13:12:45 -0700463// @CddTest = 6.1/C-0-2
Yabin Cuieafa7182016-08-30 13:13:17 -0700464TEST_F(ReportCommandTest, report_data_generated_by_linux_perf) {
465 Report(PERF_DATA_GENERATED_BY_LINUX_PERF);
466 ASSERT_TRUE(success);
467}
468
Yabin Cui648c3e42024-04-02 13:12:45 -0700469// @CddTest = 6.1/C-0-2
Yabin Cuic0565bb2016-09-29 15:59:33 -0700470TEST_F(ReportCommandTest, max_stack_and_percent_limit_option) {
471 Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g"});
472 ASSERT_TRUE(success);
473 ASSERT_NE(content.find("89.03"), std::string::npos);
474
475 Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--max-stack", "0"});
476 ASSERT_TRUE(success);
477 ASSERT_EQ(content.find("89.03"), std::string::npos);
Yabin Cuidcb2a3e2017-05-18 17:11:32 -0700478 Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--max-stack", "2"});
Yabin Cuic0565bb2016-09-29 15:59:33 -0700479 ASSERT_TRUE(success);
480 ASSERT_NE(content.find("89.03"), std::string::npos);
481
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200482 Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--percent-limit", "90"});
Yabin Cuic0565bb2016-09-29 15:59:33 -0700483 ASSERT_TRUE(success);
484 ASSERT_EQ(content.find("89.03"), std::string::npos);
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200485 Report(PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT, {"-g", "--percent-limit", "70"});
Yabin Cuic0565bb2016-09-29 15:59:33 -0700486 ASSERT_TRUE(success);
487 ASSERT_NE(content.find("89.03"), std::string::npos);
488}
489
Yabin Cui648c3e42024-04-02 13:12:45 -0700490// @CddTest = 6.1/C-0-2
Yabin Cui8036c962021-08-24 10:22:50 -0700491TEST_F(ReportCommandTest, percent_limit_option) {
492 Report(PERF_DATA);
493 ASSERT_TRUE(success);
494 ASSERT_NE(content.find("7.70%"), std::string::npos);
495 ASSERT_NE(content.find("3.23%"), std::string::npos);
496 Report(PERF_DATA, {"--percent-limit", "3.24"});
497 ASSERT_TRUE(success);
498 ASSERT_NE(content.find("7.70%"), std::string::npos);
499 ASSERT_EQ(content.find("3.23%"), std::string::npos);
500}
501
Yabin Cui648c3e42024-04-02 13:12:45 -0700502// @CddTest = 6.1/C-0-2
Yabin Cui18385c42016-12-09 14:51:04 -0800503TEST_F(ReportCommandTest, kallsyms_option) {
504 Report(PERF_DATA, {"--kallsyms", GetTestData("kallsyms")});
505 ASSERT_TRUE(success);
506 ASSERT_NE(content.find("FakeKernelSymbol"), std::string::npos);
507}
508
Yabin Cui648c3e42024-04-02 13:12:45 -0700509// @CddTest = 6.1/C-0-2
Yabin Cui044861b2016-12-13 17:49:19 -0800510TEST_F(ReportCommandTest, invalid_perf_data) {
511 ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData(INVALID_PERF_DATA)}));
512}
513
Yabin Cui648c3e42024-04-02 13:12:45 -0700514// @CddTest = 6.1/C-0-2
Yabin Cuiafe99a52017-02-23 16:27:09 -0800515TEST_F(ReportCommandTest, raw_period_option) {
516 Report(PERF_DATA, {"--raw-period"});
517 ASSERT_TRUE(success);
518 ASSERT_NE(content.find("GlobalFunc"), std::string::npos);
Chih-Hung Hsiehf6d5b0d2017-08-03 14:04:06 -0700519 ASSERT_EQ(content.find('%'), std::string::npos);
Yabin Cuiafe99a52017-02-23 16:27:09 -0800520}
521
Yabin Cui648c3e42024-04-02 13:12:45 -0700522// @CddTest = 6.1/C-0-2
Yabin Cuidcb2a3e2017-05-18 17:11:32 -0700523TEST_F(ReportCommandTest, full_callgraph_option) {
524 Report(CALLGRAPH_FP_PERF_DATA, {"-g"});
Yabin Cui0c093f32017-04-19 11:48:44 -0700525 ASSERT_TRUE(success);
526 ASSERT_NE(content.find("skipped in brief callgraph mode"), std::string::npos);
Yabin Cuidcb2a3e2017-05-18 17:11:32 -0700527 Report(CALLGRAPH_FP_PERF_DATA, {"-g", "--full-callgraph"});
528 ASSERT_TRUE(success);
529 ASSERT_EQ(content.find("skipped in brief callgraph mode"), std::string::npos);
Yabin Cui0c093f32017-04-19 11:48:44 -0700530}
531
Yabin Cui648c3e42024-04-02 13:12:45 -0700532// @CddTest = 6.1/C-0-2
Yabin Cui68b83832017-07-19 17:54:57 -0700533TEST_F(ReportCommandTest, report_offcpu_time) {
534 Report(PERF_DATA_WITH_TRACE_OFFCPU, {"--children"});
535 ASSERT_TRUE(success);
536 ASSERT_NE(content.find("Time in ns"), std::string::npos);
537 bool found = false;
538 for (auto& line : lines) {
539 if (line.find("SleepFunction") != std::string::npos) {
Yabin Cui8b5a3522018-06-18 17:44:27 -0700540 ASSERT_NE(line.find("38.76%"), std::string::npos);
Yabin Cui68b83832017-07-19 17:54:57 -0700541 found = true;
542 break;
543 }
544 }
545 ASSERT_TRUE(found);
546}
547
Yabin Cui648c3e42024-04-02 13:12:45 -0700548// @CddTest = 6.1/C-0-2
Yabin Cui8cd92332018-03-21 14:34:29 -0700549TEST_F(ReportCommandTest, report_big_trace_data) {
550 Report(PERF_DATA_WITH_BIG_TRACE_DATA);
551 ASSERT_TRUE(success);
552}
553
Yabin Cui648c3e42024-04-02 13:12:45 -0700554// @CddTest = 6.1/C-0-2
Yabin Cui30cc3c52020-05-27 13:37:18 -0700555TEST_F(ReportCommandTest, csv_option) {
556 Report(PERF_DATA, {"--csv"});
557 ASSERT_TRUE(success);
558 ASSERT_NE(content.find("EventCount,EventName"), std::string::npos);
559
560 Report(CALLGRAPH_FP_PERF_DATA, {"--children", "--csv"});
561 ASSERT_TRUE(success);
562 ASSERT_NE(content.find("AccEventCount,SelfEventCount,EventName"), std::string::npos);
563}
564
Yabin Cui648c3e42024-04-02 13:12:45 -0700565// @CddTest = 6.1/C-0-2
Yabin Cui51dca6f2021-12-16 19:00:41 -0800566TEST_F(ReportCommandTest, csv_separator_option) {
567 Report(PERF_DATA, {"--csv", "--csv-separator", ";"});
568 ASSERT_TRUE(success);
569 ASSERT_NE(content.find("EventCount;EventName"), std::string::npos);
570 ASSERT_NE(content.find(";cpu-cycles"), std::string::npos);
571}
572
Yabin Cui648c3e42024-04-02 13:12:45 -0700573// @CddTest = 6.1/C-0-2
Yabin Cui075dd182020-08-05 19:51:36 +0000574TEST_F(ReportCommandTest, dso_path_for_jit_cache) {
575 Report("perf_with_jit_symbol.data", {"--sort", "dso"});
576 ASSERT_TRUE(success);
577 ASSERT_NE(content.find("[JIT app cache]"), std::string::npos);
578
579 // Check if we can filter dso by "[JIT app cache]".
580 Report("perf_with_jit_symbol.data", {"--dsos", "[JIT app cache]"});
581 ASSERT_TRUE(success);
582 ASSERT_NE(content.find("[JIT app cache]"), std::string::npos);
583}
584
Yabin Cui648c3e42024-04-02 13:12:45 -0700585// @CddTest = 6.1/C-0-2
Evgeny Eltsin3775b142020-08-28 13:00:04 +0200586TEST_F(ReportCommandTest, generic_jit_symbols) {
587 Report("perf_with_generic_git_symbols.data", {"--sort", "symbol"});
588 ASSERT_TRUE(success);
589 ASSERT_NE(std::string::npos, content.find("generic_jit_symbol_one"));
590}
591
Yabin Cui648c3e42024-04-02 13:12:45 -0700592// @CddTest = 6.1/C-0-2
Yabin Cuie3ca9982020-10-16 13:16:26 -0700593TEST_F(ReportCommandTest, cpu_option) {
594 Report("perf.data");
595 ASSERT_TRUE(success);
596 ASSERT_EQ(2409, GetSampleCount());
597 Report("perf.data", {"--cpu", "2"});
598 ASSERT_TRUE(success);
599 ASSERT_EQ(603, GetSampleCount());
600 Report("perf.data", {"--cpu", "2-6,16"});
601 ASSERT_TRUE(success);
602 ASSERT_EQ(1806, GetSampleCount());
603 Report("perf.data", {"--cpu", "2-6", "--cpu", "16"});
604 ASSERT_TRUE(success);
605 ASSERT_EQ(1806, GetSampleCount());
606 ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData("perf.data"), "--cpu", "-2"}));
607}
608
Yabin Cui648c3e42024-04-02 13:12:45 -0700609// @CddTest = 6.1/C-0-2
Yabin Cui32b96272021-12-22 11:45:30 -0800610TEST_F(ReportCommandTest, print_event_count_option) {
611 // Report record file not recorded with --add-counter.
612 Report("perf.data", {"--print-event-count"});
613 ASSERT_TRUE(success);
614 ASSERT_NE(content.find("EventCount"), std::string::npos);
Yabin Cuif00f4fc2022-11-23 15:15:30 -0800615 ASSERT_TRUE(
616 RegEx::Create(R"(325005586\s+elf\s+26083\s+26083\s+/elf\s+GlobalFunc)")->Search(content));
Yabin Cui32b96272021-12-22 11:45:30 -0800617
618 // Report record file recorded with --add-counter.
619 const std::string record_file = "perf_with_add_counter.data";
620 Report(record_file, {"--print-event-count"});
621 ASSERT_TRUE(success);
Yabin Cuif00f4fc2022-11-23 15:15:30 -0800622 ASSERT_TRUE(RegEx::Create(R"(EventCount_cpu-cycles\s+EventCount_instructions)")->Search(content));
Yabin Cui32b96272021-12-22 11:45:30 -0800623 ASSERT_TRUE(
Yabin Cuif00f4fc2022-11-23 15:15:30 -0800624 RegEx::Create(R"(175099\s+140443\s+sleep\s+689664\s+689664.+_dl_addr)")->Search(content));
Yabin Cui32b96272021-12-22 11:45:30 -0800625
626 // Report accumulated event counts.
627 Report(record_file, {"--print-event-count", "--children"});
628 ASSERT_TRUE(success);
Yabin Cuif00f4fc2022-11-23 15:15:30 -0800629 ASSERT_TRUE(
630 RegEx::Create(
Yabin Cui32b96272021-12-22 11:45:30 -0800631 R"(AccEventCount_cpu-cycles\s+SelfEventCount_cpu-cycles\s+AccEventCount_instructions\s+)"
Yabin Cuif00f4fc2022-11-23 15:15:30 -0800632 R"(SelfEventCount_instructions)")
633 ->Search(content));
634 ASSERT_TRUE(
635 RegEx::Create(R"(175099\s+175099\s+140443\s+140443\s+sleep\s+689664\s+689664.+_dl_addr)")
636 ->Search(content));
637 ASSERT_TRUE(
638 RegEx::Create(R"(366116\s+0\s+297474\s+0\s+sleep\s+689664\s+689664.+__libc_start_main)")
639 ->Search(content));
Yabin Cui32b96272021-12-22 11:45:30 -0800640}
641
Yabin Cui648c3e42024-04-02 13:12:45 -0700642// @CddTest = 6.1/C-0-2
Yabin Cui5ea3bc12022-01-05 11:50:00 -0800643TEST_F(ReportCommandTest, exclude_include_pid_options) {
644 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--exclude-pid", "17441"});
645 ASSERT_TRUE(success);
646 ASSERT_TRUE(AllItemsWithString(lines, {"17443", "17444"}));
647 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "pid", "--include-pid", "17441"});
648 ASSERT_TRUE(success);
649 ASSERT_TRUE(AllItemsWithString(lines, {"17441"}));
650}
651
Yabin Cui648c3e42024-04-02 13:12:45 -0700652// @CddTest = 6.1/C-0-2
Yabin Cui5ea3bc12022-01-05 11:50:00 -0800653TEST_F(ReportCommandTest, exclude_include_tid_options) {
654 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS,
655 {"--sort", "tid", "--exclude-tid", "17441,17443,17444"});
656 ASSERT_TRUE(success);
657 ASSERT_TRUE(AllItemsWithString(lines, {"17445", "17446", "17447"}));
658 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS,
659 {"--sort", "tid", "--include-tid", "17441,17443,17444"});
660 ASSERT_TRUE(success);
661 ASSERT_TRUE(AllItemsWithString(lines, {"17441", "17443", "17444"}));
662}
663
Yabin Cui648c3e42024-04-02 13:12:45 -0700664// @CddTest = 6.1/C-0-2
Yabin Cui5ea3bc12022-01-05 11:50:00 -0800665TEST_F(ReportCommandTest, exclude_include_process_name_options) {
666 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--exclude-process-name", "t1"});
667 ASSERT_TRUE(success);
668 ASSERT_TRUE(AllItemsWithString(lines, {"simpleperf"}));
669 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--include-process-name", "t1"});
670 ASSERT_TRUE(success);
671 ASSERT_TRUE(AllItemsWithString(lines, {"t1"}));
672}
673
Yabin Cui648c3e42024-04-02 13:12:45 -0700674// @CddTest = 6.1/C-0-2
Yabin Cui5ea3bc12022-01-05 11:50:00 -0800675TEST_F(ReportCommandTest, exclude_include_thread_name_options) {
676 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--exclude-thread-name", "t1"});
677 ASSERT_TRUE(success);
678 ASSERT_TRUE(AllItemsWithString(lines, {"simpleperf"}));
679 Report(PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS, {"--sort", "comm", "--include-thread-name", "t1"});
680 ASSERT_TRUE(success);
681 ASSERT_TRUE(AllItemsWithString(lines, {"t1"}));
682}
683
Yabin Cui648c3e42024-04-02 13:12:45 -0700684// @CddTest = 6.1/C-0-2
Yabin Cuic4d9ead2022-01-06 15:41:31 -0800685TEST_F(ReportCommandTest, filter_file_option) {
686 std::string filter_data =
687 "GLOBAL_BEGIN 684943449406175\n"
688 "GLOBAL_END 684943449406176";
689 TemporaryFile tmpfile;
690 ASSERT_TRUE(android::base::WriteStringToFd(filter_data, tmpfile.fd));
691 Report("perf_display_bitmaps.data", {"--filter-file", tmpfile.path});
692 ASSERT_TRUE(success);
693 ASSERT_EQ(GetSampleCount(), 1);
694
695 // PERF_DATA uses clock perf, which doesn't match the default clock in filter data.
696 CapturedStderr capture;
697 ASSERT_FALSE(ReportCmd()->Run({"-i", GetTestData(PERF_DATA), "--filter-file", tmpfile.path}));
698 capture.Stop();
699 ASSERT_NE(capture.str().find("doesn't match clock used in time filter"), std::string::npos);
700}
701
Yabin Cui19e6b6d2016-03-10 11:49:57 -0800702#if defined(__linux__)
Yabin Cui003b2452016-09-29 15:32:45 -0700703#include "event_selection_set.h"
Yabin Cui6e51bef2016-02-23 21:41:03 -0800704
705static std::unique_ptr<Command> RecordCmd() {
706 return CreateCommandInstance("record");
Yabin Cui3c8c2132015-08-13 20:30:20 -0700707}
Yabin Cuib1a885b2016-02-14 19:18:02 -0800708
Yabin Cui648c3e42024-04-02 13:12:45 -0700709// @CddTest = 6.1/C-0-2
Yabin Cui6e51bef2016-02-23 21:41:03 -0800710TEST_F(ReportCommandTest, dwarf_callgraph) {
Yabin Cui8faa6152018-06-07 15:52:57 -0700711 TEST_REQUIRE_HW_COUNTER();
Yabin Cui64a9ecd2017-09-13 13:21:32 -0700712 OMIT_TEST_ON_NON_NATIVE_ABIS();
Yabin Cuid18c42e2017-07-12 14:50:07 -0700713 ASSERT_TRUE(IsDwarfCallChainSamplingSupported());
714 std::vector<std::unique_ptr<Workload>> workloads;
715 CreateProcesses(1, &workloads);
716 std::string pid = std::to_string(workloads[0]->GetPid());
717 TemporaryFile tmp_file;
Yabin Cui2412efb2025-01-24 14:40:42 -0800718 ASSERT_TRUE(RecordCmd()->Run(
719 {"-p", pid, "-g", "-o", tmp_file.path, "-e", "cpu-cycles:u", "sleep", SLEEP_SEC}));
Yabin Cuid18c42e2017-07-12 14:50:07 -0700720 ReportRaw(tmp_file.path, {"-g"});
721 ASSERT_TRUE(success);
Yabin Cui6e51bef2016-02-23 21:41:03 -0800722}
723
Yabin Cui648c3e42024-04-02 13:12:45 -0700724// @CddTest = 6.1/C-0-2
Yabin Cui8f680f62016-03-18 18:47:43 -0700725TEST_F(ReportCommandTest, report_dwarf_callgraph_of_nativelib_in_apk) {
Yabin Cui6e75e1b2018-02-06 13:42:16 -0800726 Report(NATIVELIB_IN_APK_PERF_DATA, {"-g"});
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +0200727 ASSERT_NE(content.find(GetUrlInApk(APK_FILE, NATIVELIB_IN_APK)), std::string::npos);
Yabin Cui6e75e1b2018-02-06 13:42:16 -0800728 ASSERT_NE(content.find("Func2"), std::string::npos);
729 ASSERT_NE(content.find("Func1"), std::string::npos);
730 ASSERT_NE(content.find("GlobalFunc"), std::string::npos);
Yabin Cui8f680f62016-03-18 18:47:43 -0700731}
732
Yabin Cui648c3e42024-04-02 13:12:45 -0700733// @CddTest = 6.1/C-0-2
Yabin Cuid3cb3b02017-07-24 14:59:46 -0700734TEST_F(ReportCommandTest, exclude_kernel_callchain) {
Yabin Cui2412efb2025-01-24 14:40:42 -0800735 TEST_REQUIRE_KERNEL_EVENTS();
Yabin Cui8faa6152018-06-07 15:52:57 -0700736 TEST_REQUIRE_HW_COUNTER();
Yabin Cuid3cb3b02017-07-24 14:59:46 -0700737 TEST_REQUIRE_HOST_ROOT();
Yabin Cui64a9ecd2017-09-13 13:21:32 -0700738 OMIT_TEST_ON_NON_NATIVE_ABIS();
Yabin Cuid3cb3b02017-07-24 14:59:46 -0700739 std::vector<std::unique_ptr<Workload>> workloads;
740 CreateProcesses(1, &workloads);
741 std::string pid = std::to_string(workloads[0]->GetPid());
742 TemporaryFile tmpfile;
Yabin Cuid180e312021-11-17 16:54:01 -0800743 ASSERT_TRUE(RecordCmd()->Run({"--trace-offcpu", "-e", "cpu-clock:u", "-p", pid, "--duration", "2",
744 "-o", tmpfile.path, "-g"}));
Yabin Cuid3cb3b02017-07-24 14:59:46 -0700745 ReportRaw(tmpfile.path, {"-g"});
746 ASSERT_TRUE(success);
747 ASSERT_EQ(content.find("[kernel.kallsyms]"), std::string::npos);
748}
749
Yabin Cui6e51bef2016-02-23 21:41:03 -0800750#endif