• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
19 #include "command.h"
20 #include "get_test_data.h"
21 #include "test_util.h"
22 
23 using namespace simpleperf;
24 
DumpCmd()25 static std::unique_ptr<Command> DumpCmd() {
26   return CreateCommandInstance("dump");
27 }
28 
TEST(cmd_dump,record_file_option)29 TEST(cmd_dump, record_file_option) {
30   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf.data")}));
31 }
32 
TEST(cmd_dump,input_option)33 TEST(cmd_dump, input_option) {
34   ASSERT_TRUE(DumpCmd()->Run({"-i", GetTestData("perf.data")}));
35 }
36 
TEST(cmd_dump,dump_data_generated_by_linux_perf)37 TEST(cmd_dump, dump_data_generated_by_linux_perf) {
38   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_GENERATED_BY_LINUX_PERF)}));
39 }
40 
TEST(cmd_dump,dump_callchain_records)41 TEST(cmd_dump, dump_callchain_records) {
42   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_CALLCHAIN_RECORD)}));
43 }
44 
TEST(cmd_dump,dump_callchain_of_sample_records)45 TEST(cmd_dump, dump_callchain_of_sample_records) {
46   CaptureStdout capture;
47   ASSERT_TRUE(capture.Start());
48   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_INTERPRETER_FRAMES)}));
49   std::string data = capture.Finish();
50   ASSERT_NE(data.find("[kernel.kallsyms][+ffffffc000086b4a]"), std::string::npos);
51   ASSERT_NE(data.find("__ioctl (/system/lib64/libc.so[+70b6c])"), std::string::npos);
52 }
53 
TEST(cmd_dump,dump_tracepoint_fields_of_sample_records)54 TEST(cmd_dump, dump_tracepoint_fields_of_sample_records) {
55   CaptureStdout capture;
56   ASSERT_TRUE(capture.Start());
57   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf_with_tracepoint_event.data")}));
58   std::string data = capture.Finish();
59   ASSERT_NE(data.find("prev_comm: sleep"), std::string::npos);
60 
61   // dump dynamic field of tracepoint events.
62   ASSERT_TRUE(capture.Start());
63   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf_with_tracepoint_event_dynamic_field.data")}));
64   data = capture.Finish();
65   ASSERT_NE(data.find("name: /sys/kernel/debug/tracing/events/kprobes/myopen/format"),
66             std::string::npos);
67 }
68 
TEST(cmd_dump,etm_data)69 TEST(cmd_dump, etm_data) {
70   CaptureStdout capture;
71   ASSERT_TRUE(capture.Start());
72   ASSERT_TRUE(DumpCmd()->Run({"--dump-etm", "raw,packet,element", "--symdir",
73                               GetTestDataDir() + "etm", GetTestData(PERF_DATA_ETM_TEST_LOOP)}));
74   std::string data = capture.Finish();
75   ASSERT_NE(data.find("record aux:"), std::string::npos);
76   ASSERT_NE(data.find("feature section for auxtrace:"), std::string::npos);
77   // Check if we can decode etm data into instruction range elements.
78   ASSERT_NE(data.find("OCSD_GEN_TRC_ELEM_INSTR_RANGE"), std::string::npos);
79 }
80