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 
DumpCmd()23 static std::unique_ptr<Command> DumpCmd() {
24   return CreateCommandInstance("dump");
25 }
26 
TEST(cmd_dump,record_file_option)27 TEST(cmd_dump, record_file_option) {
28   ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf.data")}));
29 }
30 
TEST(cmd_dump,dump_data_generated_by_linux_perf)31 TEST(cmd_dump, dump_data_generated_by_linux_perf) {
32   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_GENERATED_BY_LINUX_PERF)}));
33 }
34 
TEST(cmd_dump,dump_callchain_records)35 TEST(cmd_dump, dump_callchain_records) {
36   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_CALLCHAIN_RECORD)}));
37 }
38 
TEST(cmd_dump,dump_callchain_of_sample_records)39 TEST(cmd_dump, dump_callchain_of_sample_records) {
40   CaptureStdout capture;
41   ASSERT_TRUE(capture.Start());
42   ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_INTERPRETER_FRAMES)}));
43   std::string data = capture.Finish();
44   ASSERT_NE(data.find("[kernel.kallsyms][+ffffffc000086b4a]"), std::string::npos);
45   ASSERT_NE(data.find("__ioctl (/system/lib64/libc.so[+70b6c])"), std::string::npos);
46 }
47 
TEST(cmd_dump,etm_data)48 TEST(cmd_dump, etm_data) {
49   CaptureStdout capture;
50   ASSERT_TRUE(capture.Start());
51   ASSERT_TRUE(DumpCmd()->Run({"--dump-etm", "raw,packet,element", "--symdir",
52                               GetTestDataDir() + "etm", GetTestData(PERF_DATA_ETM_TEST_LOOP)}));
53   std::string data = capture.Finish();
54   ASSERT_NE(data.find("record aux:"), std::string::npos);
55   ASSERT_NE(data.find("feature section for auxtrace:"), std::string::npos);
56   // Check if we can decode etm data into instruction range elements.
57   ASSERT_NE(data.find("OCSD_GEN_TRC_ELEM_INSTR_RANGE"), std::string::npos);
58 }
59