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