1 /*
2 * Copyright (C) 2016 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
19 #include <android-base/file.h>
20 #include <android-base/test_utils.h>
21
22 #include "command.h"
23 #include "get_test_data.h"
24
ReportSampleCmd()25 static std::unique_ptr<Command> ReportSampleCmd() {
26 return CreateCommandInstance("report-sample");
27 }
28
TEST(cmd_report_sample,text)29 TEST(cmd_report_sample, text) {
30 ASSERT_TRUE(
31 ReportSampleCmd()->Run({"-i", GetTestData(PERF_DATA_WITH_SYMBOLS)}));
32 }
33
TEST(cmd_report_sample,output_option)34 TEST(cmd_report_sample, output_option) {
35 TemporaryFile tmpfile;
36 ASSERT_TRUE(ReportSampleCmd()->Run(
37 {"-i", GetTestData(PERF_DATA_WITH_SYMBOLS), "-o", tmpfile.path}));
38 }
39
TEST(cmd_report_sample,show_callchain_option)40 TEST(cmd_report_sample, show_callchain_option) {
41 TemporaryFile tmpfile;
42 ASSERT_TRUE(ReportSampleCmd()->Run({"-i", GetTestData(CALLGRAPH_FP_PERF_DATA),
43 "-o", tmpfile.path, "--show-callchain"}));
44 }
45
TEST(cmd_report_sample,protobuf_option)46 TEST(cmd_report_sample, protobuf_option) {
47 TemporaryFile tmpfile;
48 TemporaryFile tmpfile2;
49 ASSERT_TRUE(ReportSampleCmd()->Run({"-i", GetTestData(PERF_DATA_WITH_SYMBOLS),
50 "-o", tmpfile.path, "--protobuf"}));
51 ASSERT_TRUE(ReportSampleCmd()->Run(
52 {"--dump-protobuf-report", tmpfile.path, "-o", tmpfile2.path}));
53 std::string data;
54 ASSERT_TRUE(android::base::ReadFileToString(tmpfile2.path, &data));
55 ASSERT_NE(data.find("file:"), std::string::npos);
56 }
57