blob: 75961860f4358d7f15fa3b5ffe6cfd771552a89b [file] [log] [blame]
Matt Spinlerf9bae182019-10-09 13:37:38 -05001#include "extensions/openpower-pels/src.hpp"
2#include "pel_utils.hpp"
3
4#include <gtest/gtest.h>
5
6using namespace openpower::pels;
7
8TEST(SRCTest, UnflattenFlattenTestNoCallouts)
9{
Matt Spinler42828bd2019-10-11 10:39:30 -050010 auto data = pelDataFactory(TestPELType::primarySRCSection);
Matt Spinlerf9bae182019-10-09 13:37:38 -050011
12 Stream stream{data};
13 SRC src{stream};
14
15 EXPECT_TRUE(src.valid());
16
17 EXPECT_EQ(src.header().id, 0x5053);
18 EXPECT_EQ(src.header().size, 0x80);
19 EXPECT_EQ(src.header().version, 0x01);
20 EXPECT_EQ(src.header().subType, 0x01);
21 EXPECT_EQ(src.header().componentID, 0x0202);
22
23 EXPECT_EQ(src.version(), 0x02);
24 EXPECT_EQ(src.flags(), 0x00);
25 EXPECT_EQ(src.hexWordCount(), 9);
26 EXPECT_EQ(src.size(), 0x48);
27
28 const auto& hexwords = src.hexwordData();
29 EXPECT_EQ(0x02020202, hexwords[0]);
30 EXPECT_EQ(0x03030303, hexwords[1]);
31 EXPECT_EQ(0x04040404, hexwords[2]);
32 EXPECT_EQ(0x05050505, hexwords[3]);
33 EXPECT_EQ(0x06060606, hexwords[4]);
34 EXPECT_EQ(0x07070707, hexwords[5]);
35 EXPECT_EQ(0x08080808, hexwords[6]);
36 EXPECT_EQ(0x09090909, hexwords[7]);
37
38 EXPECT_EQ(src.asciiString(), "BD8D5678 ");
39 EXPECT_FALSE(src.callouts());
40
41 // Flatten
42 std::vector<uint8_t> newData;
43 Stream newStream{newData};
44
45 src.flatten(newStream);
46 EXPECT_EQ(data, newData);
47}
48
49TEST(SRCTest, UnflattenFlattenTest2Callouts)
50{
Matt Spinler42828bd2019-10-11 10:39:30 -050051 auto data = pelDataFactory(TestPELType::primarySRCSection2Callouts);
Matt Spinlerf9bae182019-10-09 13:37:38 -050052
53 Stream stream{data};
54 SRC src{stream};
55
56 EXPECT_TRUE(src.valid());
57
58 // Spot check the SRC fields, but they're the same as above
59 EXPECT_EQ(src.asciiString(), "BD8D5678 ");
60
61 // There should be 2 callouts
62 const auto& calloutsSection = src.callouts();
63 ASSERT_TRUE(calloutsSection);
64 const auto& callouts = calloutsSection->callouts();
65 EXPECT_EQ(callouts.size(), 2);
66
67 // spot check that each callout has the right substructures
68 EXPECT_TRUE(callouts.front()->fruIdentity());
69 EXPECT_FALSE(callouts.front()->pceIdentity());
70 EXPECT_FALSE(callouts.front()->mru());
71
72 EXPECT_TRUE(callouts.back()->fruIdentity());
73 EXPECT_TRUE(callouts.back()->pceIdentity());
74 EXPECT_TRUE(callouts.back()->mru());
75
76 // Flatten
77 std::vector<uint8_t> newData;
78 Stream newStream{newData};
79
80 src.flatten(newStream);
81 EXPECT_EQ(data, newData);
82}