2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
19 #include "event_attr.h"
20 #include "event_type.h"
22 #include "record_equal_test.h"
24 class RecordTest : public ::testing::Test {
26 virtual void SetUp() {
27 const EventType* event_type = EventTypeFactory::FindEventTypeByName("cpu-cycles");
28 ASSERT_TRUE(event_type != nullptr);
29 event_attr = CreateDefaultPerfEventAttr(*event_type);
32 template <class RecordType>
33 void CheckRecordMatchBinary(const RecordType& record);
35 perf_event_attr event_attr;
38 template <class RecordType>
39 void RecordTest::CheckRecordMatchBinary(const RecordType& record) {
40 std::vector<char> binary = record.BinaryFormat();
41 std::unique_ptr<const Record> record_p =
42 ReadRecordFromBuffer(event_attr, reinterpret_cast<const perf_event_header*>(binary.data()));
43 ASSERT_TRUE(record_p != nullptr);
44 CheckRecordEqual(record, *record_p);
47 TEST_F(RecordTest, MmapRecordMatchBinary) {
49 CreateMmapRecord(event_attr, true, 1, 2, 0x1000, 0x2000, 0x3000, "MmapRecord");
50 CheckRecordMatchBinary(record);
53 TEST_F(RecordTest, CommRecordMatchBinary) {
54 CommRecord record = CreateCommRecord(event_attr, 1, 2, "CommRecord");
55 CheckRecordMatchBinary(record);