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 namespace simpleperf {
18
CheckMmapRecordDataEqual(const MmapRecord & r1,const MmapRecord & r2)19 static void CheckMmapRecordDataEqual(const MmapRecord& r1, const MmapRecord& r2) {
20 ASSERT_EQ(0, memcmp(r1.data, r2.data, sizeof(*r1.data)));
21 ASSERT_STREQ(r1.filename, r2.filename);
22 }
23
CheckCommRecordDataEqual(const CommRecord & r1,const CommRecord & r2)24 static void CheckCommRecordDataEqual(const CommRecord& r1, const CommRecord& r2) {
25 ASSERT_EQ(0, memcmp(r1.data, r2.data, sizeof(*r1.data)));
26 ASSERT_STREQ(r1.comm, r2.comm);
27 }
28
CheckBuildIdRecordDataEqual(const BuildIdRecord & r1,const BuildIdRecord & r2)29 static void CheckBuildIdRecordDataEqual(const BuildIdRecord& r1, const BuildIdRecord& r2) {
30 ASSERT_EQ(r1.pid, r2.pid);
31 ASSERT_EQ(r1.build_id, r2.build_id);
32 ASSERT_STREQ(r1.filename, r2.filename);
33 }
34
CheckSampleRecordDataEqual(const SampleRecord & r1,const SampleRecord & r2)35 static void CheckSampleRecordDataEqual(const SampleRecord& r1, const SampleRecord& r2) {
36 ASSERT_EQ(r1.sample_type, r2.sample_type);
37 if (r1.sample_type & PERF_SAMPLE_IP) {
38 EXPECT_EQ(r1.ip_data.ip, r2.ip_data.ip);
39 }
40 if (r1.sample_type & PERF_SAMPLE_TID) {
41 EXPECT_EQ(r1.tid_data.pid, r2.tid_data.pid);
42 EXPECT_EQ(r1.tid_data.tid, r2.tid_data.tid);
43 }
44 if (r1.sample_type & PERF_SAMPLE_TIME) {
45 EXPECT_EQ(r1.time_data.time, r2.time_data.time);
46 }
47 if (r1.sample_type & PERF_SAMPLE_ID) {
48 EXPECT_EQ(r1.id_data.id, r2.id_data.id);
49 }
50 if (r1.sample_type & PERF_SAMPLE_CPU) {
51 EXPECT_EQ(r1.cpu_data.cpu, r2.cpu_data.cpu);
52 }
53 if (r1.sample_type & PERF_SAMPLE_PERIOD) {
54 EXPECT_EQ(r1.period_data.period, r2.period_data.period);
55 }
56 if (r1.sample_type & PERF_SAMPLE_CALLCHAIN) {
57 ASSERT_EQ(r1.callchain_data.ip_nr, r2.callchain_data.ip_nr);
58 for (size_t i = 0; i < r1.callchain_data.ip_nr; ++i) {
59 EXPECT_EQ(r1.callchain_data.ips[i], r2.callchain_data.ips[i]);
60 }
61 }
62 if (r1.sample_type & PERF_SAMPLE_REGS_USER) {
63 ASSERT_EQ(r1.regs_user_data.abi, r2.regs_user_data.abi);
64 if (r1.regs_user_data.abi != 0) {
65 ASSERT_EQ(r1.regs_user_data.reg_mask, r2.regs_user_data.reg_mask);
66 ASSERT_EQ(0, memcmp(r1.regs_user_data.regs, r2.regs_user_data.regs,
67 r1.regs_user_data.reg_nr * sizeof(uint64_t)));
68 }
69 }
70 if (r1.sample_type & PERF_SAMPLE_STACK_USER) {
71 ASSERT_EQ(r1.stack_user_data.size, r2.stack_user_data.size);
72 if (r1.stack_user_data.size > 0) {
73 ASSERT_EQ(r1.stack_user_data.dyn_size, r2.stack_user_data.dyn_size);
74 ASSERT_EQ(0,
75 memcmp(r1.stack_user_data.data, r2.stack_user_data.data, r1.stack_user_data.size));
76 }
77 }
78 }
79
CheckRecordEqual(const Record & r1,const Record & r2)80 static void CheckRecordEqual(const Record& r1, const Record& r2) {
81 ASSERT_EQ(r1.type(), r2.type());
82 ASSERT_EQ(r1.misc(), r2.misc());
83 ASSERT_EQ(r1.size(), r2.size());
84 if (r1.type() == PERF_RECORD_SAMPLE) {
85 CheckSampleRecordDataEqual(static_cast<const SampleRecord&>(r1),
86 static_cast<const SampleRecord&>(r2));
87 return;
88 }
89 ASSERT_EQ(0, memcmp(&r1.sample_id, &r2.sample_id, sizeof(r1.sample_id)));
90 if (r1.type() == PERF_RECORD_MMAP) {
91 CheckMmapRecordDataEqual(static_cast<const MmapRecord&>(r1),
92 static_cast<const MmapRecord&>(r2));
93 } else if (r1.type() == PERF_RECORD_COMM) {
94 CheckCommRecordDataEqual(static_cast<const CommRecord&>(r1),
95 static_cast<const CommRecord&>(r2));
96 } else if (r1.type() == PERF_RECORD_BUILD_ID) {
97 CheckBuildIdRecordDataEqual(static_cast<const BuildIdRecord&>(r1),
98 static_cast<const BuildIdRecord&>(r2));
99 }
100 }
101
102 } // namespace simpleperf
103