blob: 0a78c9473b6a40a09cf78e291f5fab01aa822003 [file] [log] [blame]
Matt Spinler6c9662c2019-10-09 11:27:20 -05001#include "extensions/openpower-pels/callout.hpp"
2#include "pel_utils.hpp"
3
4#include <gtest/gtest.h>
5
6using namespace openpower::pels;
7using namespace openpower::pels::src;
8
9// Unflatten the callout section with all three substructures
10TEST(CalloutTest, TestUnflattenAllSubstructures)
11{
12 // The base data.
13 std::vector<uint8_t> data{
14 0xFF, 0x2F, 'H', 8, // size, flags, priority, LC length
15 'U', '1', '2', '-', 'P', '1', 0x00, 0x00 // LC
16 };
17
18 auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);
19 auto pceIdentity = srcDataFactory(TestSRCType::pceIdentityStructure);
20 auto mrus = srcDataFactory(TestSRCType::mruStructure);
21
22 // Add all 3 substructures
23 data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());
24 data.insert(data.end(), pceIdentity.begin(), pceIdentity.end());
25 data.insert(data.end(), mrus.begin(), mrus.end());
26
27 // The final size
28 data[0] = data.size();
29
30 Stream stream{data};
31 Callout callout{stream};
32
33 EXPECT_EQ(callout.flattenedSize(), data.size());
34 EXPECT_EQ(callout.priority(), 'H');
35 EXPECT_EQ(callout.locationCode(), "U12-P1");
36
37 // Spot check the 3 substructures
38 EXPECT_TRUE(callout.fruIdentity());
39 EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC");
40
41 EXPECT_TRUE(callout.pceIdentity());
42 EXPECT_EQ(callout.pceIdentity()->enclosureName(), "PCENAME12");
43
44 EXPECT_TRUE(callout.mru());
45 EXPECT_EQ(callout.mru()->mrus().size(), 4);
46 EXPECT_EQ(callout.mru()->mrus().at(3).id, 0x04040404);
47
48 // Now flatten
49 std::vector<uint8_t> newData;
50 Stream newStream{newData};
51
52 callout.flatten(newStream);
53 EXPECT_EQ(data, newData);
54}
55
56TEST(CalloutTest, TestUnflattenOneSubstructure)
57{
58 std::vector<uint8_t> data{
59 0xFF, 0x28, 'H', 0x08, // size, flags, priority, LC length
60 'U', '1', '2', '-', 'P', '1', 0x00, 0x00 // LC
61 };
62
63 auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);
64
65 data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());
66
67 // The final size
68 data[0] = data.size();
69
70 Stream stream{data};
71 Callout callout{stream};
72
73 EXPECT_EQ(callout.flattenedSize(), data.size());
74
75 // Spot check the substructure
76 EXPECT_TRUE(callout.fruIdentity());
77 EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC");
78
79 // Not present
80 EXPECT_FALSE(callout.pceIdentity());
81 EXPECT_FALSE(callout.mru());
82
83 // Now flatten
84 std::vector<uint8_t> newData;
85 Stream newStream{newData};
86
87 callout.flatten(newStream);
88 EXPECT_EQ(data, newData);
89}
90
91TEST(CalloutTest, TestUnflattenTwoSubstructures)
92{
93 std::vector<uint8_t> data{
94 0xFF, 0x2B, 'H', 0x08, // size, flags, priority, LC length
95 'U', '1', '2', '-', 'P', '1', 0x00, 0x00 // LC
96 };
97
98 auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);
99 auto pceIdentity = srcDataFactory(TestSRCType::pceIdentityStructure);
100
101 data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());
102 data.insert(data.end(), pceIdentity.begin(), pceIdentity.end());
103
104 // The final size
105 data[0] = data.size();
106
107 Stream stream{data};
108 Callout callout{stream};
109
110 EXPECT_EQ(callout.flattenedSize(), data.size());
111
112 // Spot check the 2 substructures
113 EXPECT_TRUE(callout.fruIdentity());
114 EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC");
115
116 EXPECT_TRUE(callout.pceIdentity());
117 EXPECT_EQ(callout.pceIdentity()->enclosureName(), "PCENAME12");
118
119 // Not present
120 EXPECT_FALSE(callout.mru());
121
122 // Now flatten
123 std::vector<uint8_t> newData;
124 Stream newStream{newData};
125
126 callout.flatten(newStream);
127 EXPECT_EQ(data, newData);
128}
129
130TEST(CalloutTest, TestNoLocationCode)
131{
132 std::vector<uint8_t> data{
133 0xFF, 0x2B, 'H', 0x00 // size, flags, priority, LC length
134 };
135
136 auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);
137 data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());
138
139 // The final size
140 data[0] = data.size();
141
142 Stream stream{data};
143 Callout callout{stream};
144
145 EXPECT_TRUE(callout.locationCode().empty());
146}