blob: d9e9a4bd03205daacfb90832721f167c129c4503 [file] [log] [blame]
Yabin Cui5beebc82015-05-04 20:27:57 -07001/*
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 "event_attr.h"
20#include "event_type.h"
21#include "record.h"
22#include "record_equal_test.h"
23
24class RecordTest : public ::testing::Test {
25 protected:
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);
30 }
31
32 template <class RecordType>
33 void CheckRecordMatchBinary(const RecordType& record);
34
35 perf_event_attr event_attr;
36};
37
38template <class RecordType>
39void 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);
45}
46
47TEST_F(RecordTest, MmapRecordMatchBinary) {
48 MmapRecord record =
49 CreateMmapRecord(event_attr, true, 1, 2, 0x1000, 0x2000, 0x3000, "MmapRecord");
50 CheckRecordMatchBinary(record);
51}
52
53TEST_F(RecordTest, CommRecordMatchBinary) {
54 CommRecord record = CreateCommRecord(event_attr, 1, 2, "CommRecord");
55 CheckRecordMatchBinary(record);
56}