blob: abeda0b5397678964dc34e115ebd8c15e69a8acc [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();
Matt Spinlerbd716f02019-10-15 10:54:11 -050029 EXPECT_EQ(0x02020255, hexwords[0]);
30 EXPECT_EQ(0x03030310, hexwords[1]);
Matt Spinlerf9bae182019-10-09 13:37:38 -050031 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());
Matt Spinlerbd716f02019-10-15 10:54:11 -050057 EXPECT_EQ(src.flags(), 0x01); // Additional sections within the SRC.
Matt Spinlerf9bae182019-10-09 13:37:38 -050058
59 // Spot check the SRC fields, but they're the same as above
60 EXPECT_EQ(src.asciiString(), "BD8D5678 ");
61
62 // There should be 2 callouts
63 const auto& calloutsSection = src.callouts();
64 ASSERT_TRUE(calloutsSection);
65 const auto& callouts = calloutsSection->callouts();
66 EXPECT_EQ(callouts.size(), 2);
67
68 // spot check that each callout has the right substructures
69 EXPECT_TRUE(callouts.front()->fruIdentity());
70 EXPECT_FALSE(callouts.front()->pceIdentity());
71 EXPECT_FALSE(callouts.front()->mru());
72
73 EXPECT_TRUE(callouts.back()->fruIdentity());
74 EXPECT_TRUE(callouts.back()->pceIdentity());
75 EXPECT_TRUE(callouts.back()->mru());
76
77 // Flatten
78 std::vector<uint8_t> newData;
79 Stream newStream{newData};
80
81 src.flatten(newStream);
82 EXPECT_EQ(data, newData);
83}
Matt Spinlerbd716f02019-10-15 10:54:11 -050084
85// Create an SRC from the message registry
86TEST(SRCTest, CreateTestNoCallouts)
87{
88 message::Entry entry;
89 entry.src.type = 0xBD;
90 entry.src.reasonCode = 0xABCD;
91 entry.subsystem = 0x42;
92 entry.src.powerFault = true;
93 entry.src.hexwordADFields = {{5, "TEST1"}, // Not a user defined word
94 {6, "TEST1"},
95 {7, "TEST2"},
96 {8, "TEST3"},
97 {9, "TEST4"}};
98
99 // Values for the SRC words pointed to above
100 std::vector<std::string> adData{"TEST1=0x12345678", "TEST2=12345678",
101 "TEST3=0XDEF", "TEST4=Z"};
102 AdditionalData ad{adData};
103 SRC src{entry, ad};
104
105 EXPECT_TRUE(src.valid());
106 EXPECT_TRUE(src.isPowerFaultEvent());
107 EXPECT_EQ(src.size(), baseSRCSize);
108
109 const auto& hexwords = src.hexwordData();
110
111 // The spec always refers to SRC words 2 - 9, and as the hexwordData()
112 // array index starts at 0 use the math in the [] below to make it easier
113 // to tell what is being accessed.
114 EXPECT_EQ(hexwords[2 - 2] & 0xF0000000, 0); // Partition dump status
115 EXPECT_EQ(hexwords[2 - 2] & 0x00F00000, 0); // Partition boot type
116 EXPECT_EQ(hexwords[2 - 2] & 0x000000FF, 0x55); // SRC format
117 EXPECT_EQ(hexwords[3 - 2] & 0x000000FF, 0x10); // BMC position
118
119 // Validate more fields here as the code starts filling them in.
120
121 // Ensure hex word 5 wasn't allowed to be set to TEST1's contents
122 EXPECT_EQ(hexwords[5 - 2], 0);
123
124 // The user defined hex word fields specifed in the additional data.
125 EXPECT_EQ(hexwords[6 - 2], 0x12345678); // TEST1
126 EXPECT_EQ(hexwords[7 - 2], 12345678); // TEST2
127 EXPECT_EQ(hexwords[8 - 2], 0xdef); // TEST3
128 EXPECT_EQ(hexwords[9 - 2], 0); // TEST4, but can't convert a 'Z'
129
130 EXPECT_EQ(src.asciiString(), "BD42ABCD ");
131
132 // No callouts
133 EXPECT_FALSE(src.callouts());
134
135 // May as well spot check the flatten/unflatten
136 std::vector<uint8_t> data;
137 Stream stream{data};
138 src.flatten(stream);
139
140 stream.offset(0);
141 SRC newSRC{stream};
142
143 EXPECT_TRUE(newSRC.valid());
144 EXPECT_EQ(newSRC.isPowerFaultEvent(), src.isPowerFaultEvent());
145 EXPECT_EQ(newSRC.asciiString(), src.asciiString());
146 EXPECT_FALSE(newSRC.callouts());
147}