blob: e73c69a0184fb73421855b118a5ebcb29efd667f [file] [log] [blame]
Matt Spinler97f7abc2019-11-06 09:40:23 -06001/**
2 * Copyright © 2019 IBM Corporation
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 */
Matt Spinler90b4a0a2019-10-09 10:08:43 -050016#include "extensions/openpower-pels/mru.hpp"
17
18#include <gtest/gtest.h>
19
20using namespace openpower::pels;
21using namespace openpower::pels::src;
22
23TEST(MRUTest, TestConstructor)
24{
25 std::vector<uint8_t> data{
26 'M', 'R', 0x28, 0x04, // ID, size, flags
27 0x00, 0x00, 0x00, 0x00, // Reserved
28 0x00, 0x00, 0x00, 'H', // priority for MRU ID 0
29 0x01, 0x01, 0x01, 0x01, // MRU ID 0
30 0x00, 0x00, 0x00, 'M', // priority for MRU ID 1
31 0x02, 0x02, 0x02, 0x02, // MRU ID 1
32 0x00, 0x00, 0x00, 'L', // priority for MRU ID 2
33 0x03, 0x03, 0x03, 0x03, // MRU ID 2
34 0x00, 0x00, 0x00, 'H', // priority for MRU ID 3
35 0x04, 0x04, 0x04, 0x04, // MRU ID 3
36 };
37
38 Stream stream{data};
39
40 MRU mru{stream};
41
42 EXPECT_EQ(mru.flattenedSize(), data.size());
43 EXPECT_EQ(mru.mrus().size(), 4);
44
45 EXPECT_EQ(mru.mrus().at(0).priority, 'H');
46 EXPECT_EQ(mru.mrus().at(0).id, 0x01010101);
47 EXPECT_EQ(mru.mrus().at(1).priority, 'M');
48 EXPECT_EQ(mru.mrus().at(1).id, 0x02020202);
49 EXPECT_EQ(mru.mrus().at(2).priority, 'L');
50 EXPECT_EQ(mru.mrus().at(2).id, 0x03030303);
51 EXPECT_EQ(mru.mrus().at(3).priority, 'H');
52 EXPECT_EQ(mru.mrus().at(3).id, 0x04040404);
53
54 // Now flatten
55 std::vector<uint8_t> newData;
56 Stream newStream{newData};
57
58 mru.flatten(newStream);
59 EXPECT_EQ(data, newData);
60}
61
62TEST(MRUTest, TestBadData)
63{
64 // 4 MRUs expected, but only 1
65 std::vector<uint8_t> data{
66 'M', 'R', 0x28, 0x04, // ID, size, flags
67 0x00, 0x00, 0x00, 0x00, // Reserved
68 0x00, 0x00, 0x00, 'H', // priority 0
69 0x01, 0x01, 0x01, 0x01, // MRU ID 0
70 };
71
72 Stream stream{data};
73 EXPECT_THROW(MRU mru{stream}, std::out_of_range);
74}