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,dump_data_generated_by_linux_perf)33 TEST(cmd_dump, dump_data_generated_by_linux_perf) {
34 ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_GENERATED_BY_LINUX_PERF)}));
35 }
36
TEST(cmd_dump,dump_callchain_records)37 TEST(cmd_dump, dump_callchain_records) {
38 ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_CALLCHAIN_RECORD)}));
39 }
40
TEST(cmd_dump,dump_callchain_of_sample_records)41 TEST(cmd_dump, dump_callchain_of_sample_records) {
42 CaptureStdout capture;
43 ASSERT_TRUE(capture.Start());
44 ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_INTERPRETER_FRAMES)}));
45 std::string data = capture.Finish();
46 ASSERT_NE(data.find("[kernel.kallsyms][+ffffffc000086b4a]"), std::string::npos);
47 ASSERT_NE(data.find("__ioctl (/system/lib64/libc.so[+70b6c])"), std::string::npos);
48 }
49
TEST(cmd_dump,dump_tracepoint_fields_of_sample_records)50 TEST(cmd_dump, dump_tracepoint_fields_of_sample_records) {
51 CaptureStdout capture;
52 ASSERT_TRUE(capture.Start());
53 ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf_with_tracepoint_event.data")}));
54 std::string data = capture.Finish();
55 ASSERT_NE(data.find("prev_comm: sleep"), std::string::npos);
56 }
57
TEST(cmd_dump,etm_data)58 TEST(cmd_dump, etm_data) {
59 CaptureStdout capture;
60 ASSERT_TRUE(capture.Start());
61 ASSERT_TRUE(DumpCmd()->Run({"--dump-etm", "raw,packet,element", "--symdir",
62 GetTestDataDir() + "etm", GetTestData(PERF_DATA_ETM_TEST_LOOP)}));
63 std::string data = capture.Finish();
64 ASSERT_NE(data.find("record aux:"), std::string::npos);
65 ASSERT_NE(data.find("feature section for auxtrace:"), std::string::npos);
66 // Check if we can decode etm data into instruction range elements.
67 ASSERT_NE(data.find("OCSD_GEN_TRC_ELEM_INSTR_RANGE"), std::string::npos);
68 }
69