blob: 38e80f9a85744e00a8a62bc82dca87dfa242e2e3 [file] [log] [blame]
Matt Spinler90b4a0a2019-10-09 10:08:43 -05001#include "extensions/openpower-pels/mru.hpp"
2
3#include <gtest/gtest.h>
4
5using namespace openpower::pels;
6using namespace openpower::pels::src;
7
8TEST(MRUTest, TestConstructor)
9{
10 std::vector<uint8_t> data{
11 'M', 'R', 0x28, 0x04, // ID, size, flags
12 0x00, 0x00, 0x00, 0x00, // Reserved
13 0x00, 0x00, 0x00, 'H', // priority for MRU ID 0
14 0x01, 0x01, 0x01, 0x01, // MRU ID 0
15 0x00, 0x00, 0x00, 'M', // priority for MRU ID 1
16 0x02, 0x02, 0x02, 0x02, // MRU ID 1
17 0x00, 0x00, 0x00, 'L', // priority for MRU ID 2
18 0x03, 0x03, 0x03, 0x03, // MRU ID 2
19 0x00, 0x00, 0x00, 'H', // priority for MRU ID 3
20 0x04, 0x04, 0x04, 0x04, // MRU ID 3
21 };
22
23 Stream stream{data};
24
25 MRU mru{stream};
26
27 EXPECT_EQ(mru.flattenedSize(), data.size());
28 EXPECT_EQ(mru.mrus().size(), 4);
29
30 EXPECT_EQ(mru.mrus().at(0).priority, 'H');
31 EXPECT_EQ(mru.mrus().at(0).id, 0x01010101);
32 EXPECT_EQ(mru.mrus().at(1).priority, 'M');
33 EXPECT_EQ(mru.mrus().at(1).id, 0x02020202);
34 EXPECT_EQ(mru.mrus().at(2).priority, 'L');
35 EXPECT_EQ(mru.mrus().at(2).id, 0x03030303);
36 EXPECT_EQ(mru.mrus().at(3).priority, 'H');
37 EXPECT_EQ(mru.mrus().at(3).id, 0x04040404);
38
39 // Now flatten
40 std::vector<uint8_t> newData;
41 Stream newStream{newData};
42
43 mru.flatten(newStream);
44 EXPECT_EQ(data, newData);
45}
46
47TEST(MRUTest, TestBadData)
48{
49 // 4 MRUs expected, but only 1
50 std::vector<uint8_t> data{
51 'M', 'R', 0x28, 0x04, // ID, size, flags
52 0x00, 0x00, 0x00, 0x00, // Reserved
53 0x00, 0x00, 0x00, 'H', // priority 0
54 0x01, 0x01, 0x01, 0x01, // MRU ID 0
55 };
56
57 Stream stream{data};
58 EXPECT_THROW(MRU mru{stream}, std::out_of_range);
59}