Yabin Cui | 9759e1b | 2015-04-28 15:54:13 -0700 | [diff] [blame] | 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 | |
Yabin Cui | 7d59bb4 | 2015-05-04 20:27:57 -0700 | [diff] [blame] | 19 | #include "command.h" |
Yabin Cui | be7ec66 | 2016-03-02 13:56:28 -0800 | [diff] [blame] | 20 | #include "get_test_data.h" |
Yabin Cui | 92c4cb1 | 2018-04-18 19:32:06 -0700 | [diff] [blame] | 21 | #include "test_util.h" |
Yabin Cui | 9759e1b | 2015-04-28 15:54:13 -0700 | [diff] [blame] | 22 | |
Yabin Cui | acbdb24 | 2020-07-07 15:56:34 -0700 | [diff] [blame] | 23 | using namespace simpleperf; |
| 24 | |
Yabin Cui | be7ec66 | 2016-03-02 13:56:28 -0800 | [diff] [blame] | 25 | static std::unique_ptr<Command> DumpCmd() { |
| 26 | return CreateCommandInstance("dump"); |
Yabin Cui | 9759e1b | 2015-04-28 15:54:13 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 29 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | be7ec66 | 2016-03-02 13:56:28 -0800 | [diff] [blame] | 30 | TEST(cmd_dump, record_file_option) { |
| 31 | ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf.data")})); |
Yabin Cui | 9759e1b | 2015-04-28 15:54:13 -0700 | [diff] [blame] | 32 | } |
Yabin Cui | eafa718 | 2016-08-30 13:13:17 -0700 | [diff] [blame] | 33 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 34 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | f3f2e32 | 2020-10-26 15:02:21 -0700 | [diff] [blame] | 35 | TEST(cmd_dump, input_option) { |
| 36 | ASSERT_TRUE(DumpCmd()->Run({"-i", GetTestData("perf.data")})); |
| 37 | } |
| 38 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 39 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | eafa718 | 2016-08-30 13:13:17 -0700 | [diff] [blame] | 40 | TEST(cmd_dump, dump_data_generated_by_linux_perf) { |
| 41 | ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_GENERATED_BY_LINUX_PERF)})); |
| 42 | } |
Yabin Cui | 81a9d33 | 2017-12-10 13:09:07 -0800 | [diff] [blame] | 43 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 44 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | 81a9d33 | 2017-12-10 13:09:07 -0800 | [diff] [blame] | 45 | TEST(cmd_dump, dump_callchain_records) { |
| 46 | ASSERT_TRUE(DumpCmd()->Run({GetTestData(PERF_DATA_WITH_CALLCHAIN_RECORD)})); |
| 47 | } |
Yabin Cui | 92c4cb1 | 2018-04-18 19:32:06 -0700 | [diff] [blame] | 48 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 49 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | 92c4cb1 | 2018-04-18 19:32:06 -0700 | [diff] [blame] | 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 | } |
Yabin Cui | 7ee5d6d | 2019-08-02 11:35:38 -0700 | [diff] [blame] | 58 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 59 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | 97de9a0 | 2020-06-29 11:56:37 -0700 | [diff] [blame] | 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); |
Yabin Cui | 15dd5f7 | 2020-08-24 14:21:55 -0700 | [diff] [blame] | 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); |
Yabin Cui | 97de9a0 | 2020-06-29 11:56:37 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 75 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | 7ee5d6d | 2019-08-02 11:35:38 -0700 | [diff] [blame] | 76 | TEST(cmd_dump, etm_data) { |
| 77 | CaptureStdout capture; |
| 78 | ASSERT_TRUE(capture.Start()); |
Yabin Cui | fc9da9b | 2019-08-08 18:15:14 -0700 | [diff] [blame] | 79 | ASSERT_TRUE(DumpCmd()->Run({"--dump-etm", "raw,packet,element", "--symdir", |
| 80 | GetTestDataDir() + "etm", GetTestData(PERF_DATA_ETM_TEST_LOOP)})); |
Yabin Cui | 7ee5d6d | 2019-08-02 11:35:38 -0700 | [diff] [blame] | 81 | std::string data = capture.Finish(); |
| 82 | ASSERT_NE(data.find("record aux:"), std::string::npos); |
Yabin Cui | 7ee5d6d | 2019-08-02 11:35:38 -0700 | [diff] [blame] | 83 | ASSERT_NE(data.find("feature section for auxtrace:"), std::string::npos); |
Yabin Cui | fc9da9b | 2019-08-08 18:15:14 -0700 | [diff] [blame] | 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); |
Yabin Cui | 7ee5d6d | 2019-08-02 11:35:38 -0700 | [diff] [blame] | 86 | } |
Yabin Cui | 078e0c4 | 2021-07-13 14:18:06 -0700 | [diff] [blame] | 87 | |
Yabin Cui | 648c3e4 | 2024-04-02 13:12:45 -0700 | [diff] [blame] | 88 | // @CddTest = 6.1/C-0-2 |
Yabin Cui | 078e0c4 | 2021-07-13 14:18:06 -0700 | [diff] [blame] | 89 | TEST(cmd_dump, dump_arm_regs_recorded_in_arm64) { |
| 90 | ASSERT_TRUE(DumpCmd()->Run({GetTestData("perf_with_arm_regs.data")})); |
| 91 | } |
Yabin Cui | d344a99 | 2024-09-11 14:20:07 -0700 | [diff] [blame] | 92 | |
| 93 | // @CddTest = 6.1/C-0-2 |
| 94 | TEST(cmd_dump, dump_feature_option) { |
| 95 | ASSERT_TRUE( |
| 96 | DumpCmd()->Run({"--dump-feature", "meta_info", GetTestData("perf_display_bitmaps.data")})); |
| 97 | } |