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 
29 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,record_file_option)30 TEST(cmd_dump, record_file_option) {
31   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf.data")}));
32 }
33 
34 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,input_option)35 TEST(cmd_dump, input_option) {
36   ASSERT_TRUE(DumpCmd()->Run({"-i", GetTestData("perf.data")}));
37 }
38 
39 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,dump_data_generated_by_linux_perf)40 TEST(cmd_dump, dump_data_generated_by_linux_perf) {
41   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_GENERATED_BY_LINUX_PERF)}));
42 }
43 
44 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,dump_callchain_records)45 TEST(cmd_dump, dump_callchain_records) {
46   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_CALLCHAIN_RECORD)}));
47 }
48 
49 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,dump_callchain_of_sample_records)50 TEST(cmd_dump, dump_callchain_of_sample_records) {
51   CaptureStdout capture;
52   ASSERT_TRUE(capture.Start());
53   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_INTERPRETER_FRAMES)}));
54   std::string data = capture.Finish();
55   ASSERT_NE(data.find("[kernel.kallsyms][+ffffffc000086b4a]"), std::string::npos);
56   ASSERT_NE(data.find("__ioctl (/system/lib64/libc.so[+70b6c])"), std::string::npos);
57 }
58 
59 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,dump_tracepoint_fields_of_sample_records)60 TEST(cmd_dump, dump_tracepoint_fields_of_sample_records) {
61   CaptureStdout capture;
62   ASSERT_TRUE(capture.Start());
63   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf_with_tracepoint_event.data")}));
64   std::string data = capture.Finish();
65   ASSERT_NE(data.find("prev_comm: sleep"), std::string::npos);
66 
67   // dump dynamic field of tracepoint events.
68   ASSERT_TRUE(capture.Start());
69   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf_with_tracepoint_event_dynamic_field.data")}));
70   data = capture.Finish();
71   ASSERT_NE(data.find("name: /sys/kernel/debug/tracing/events/kprobes/myopen/format"),
72             std::string::npos);
73 }
74 
75 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,etm_data)76 TEST(cmd_dump, etm_data) {
77   CaptureStdout capture;
78   ASSERT_TRUE(capture.Start());
79   ASSERT_TRUE(DumpCmd()->Run({"--dump-etm", "raw,packet,element", "--symdir",
80                               GetTestDataDir() + "etm", GetTestData(PERF_DATA_ETM_TEST_LOOP)}));
81   std::string data = capture.Finish();
82   ASSERT_NE(data.find("record aux:"), std::string::npos);
83   ASSERT_NE(data.find("feature section for auxtrace:"), std::string::npos);
84   // Check if we can decode etm data into instruction range elements.
85   ASSERT_NE(data.find("OCSD_GEN_TRC_ELEM_INSTR_RANGE"), std::string::npos);
86 }
87 
88 // @CddTest = 6.1/C-0-2
TEST(cmd_dump,dump_arm_regs_recorded_in_arm64)89 TEST(cmd_dump, dump_arm_regs_recorded_in_arm64) {
90   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf_with_arm_regs.data")}));
91 }
92