blob: f7c9150f764df14756ef57162e0f99cb54a4d955 [file] [log] [blame]
Matt Spinlerd3335df2019-07-10 11:04:21 -05001#include "pel_utils.hpp"
2
3#include "extensions/openpower-pels/private_header.hpp"
Matt Spinler03c1d912019-07-10 14:12:15 -05004#include "extensions/openpower-pels/user_header.hpp"
Matt Spinlerd3335df2019-07-10 11:04:21 -05005
6#include <fstream>
7
8#include <gtest/gtest.h>
9
10namespace fs = std::filesystem;
11using namespace openpower::pels;
12
Matt Spinlercb6b0592019-07-16 15:58:51 -050013std::filesystem::path CleanLogID::pelIDFile{};
Matt Spinler89fa0822019-07-17 13:54:30 -050014std::filesystem::path CleanPELFiles::pelIDFile{};
15std::filesystem::path CleanPELFiles::repoPath{};
Matt Spinler367144c2019-09-19 15:33:52 -050016std::filesystem::path CleanPELFiles::registryPath{};
Matt Spinlercb6b0592019-07-16 15:58:51 -050017
Matt Spinlerd3335df2019-07-10 11:04:21 -050018constexpr uint8_t simplePEL[] = {
19 // private header section header
20 0x50, 0x48, // ID 'PH'
21 0x00, 0x30, // Size
22 0x01, 0x02, // version, subtype
23 0x03, 0x04, // comp ID
24
25 // private header
26 0x20, 0x30, 0x05, 0x09, 0x11, 0x1E, 0x1, 0x63, // create timestamp
27 0x20, 0x31, 0x06, 0x0F, 0x09, 0x22, 0x3A, 0x00, // commit timestamp
28 0xAA, // creatorID
29 0x00, // logtype
30 0x00, // reserved
31 0x02, // section count
32 0x90, 0x91, 0x92, 0x93, // OpenBMC log ID
33 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, // creator version
34 0x50, 0x51, 0x52, 0x53, // plid
Matt Spinler03c1d912019-07-10 14:12:15 -050035 0x80, 0x81, 0x82, 0x83, // id
Matt Spinlerd3335df2019-07-10 11:04:21 -050036
Matt Spinler03c1d912019-07-10 14:12:15 -050037 // user header section header
38 0x55, 0x48, // ID 'UH'
39 0x00, 0x18, // Size
40 0x01, 0x0A, // version, subtype
41 0x0B, 0x0C, // comp ID
42
43 // user header
44 0x10, 0x04, // subsystem, scope
45 0x20, 0x00, // severity, type
46 0x00, 0x00, 0x00, 0x00, // reserved
47 0x03, 0x04, // problem domain, vector
48 0x80, 0xC0, // action flags
49 0x00, 0x00, 0x00, 0x00 // reserved
50
51 // Add more as the code supports more
Matt Spinlerd3335df2019-07-10 11:04:21 -050052};
53
Matt Spinler6c9662c2019-10-09 11:27:20 -050054std::vector<uint8_t> srcFRUIdentityCallout{
55 'I', 'D', 0x1C, 0x1D, // type, size, flags
56 '1', '2', '3', '4', // PN
57 '5', '6', '7', 0x00, 'A', 'A', 'A', 'A', // CCIN
58 '1', '2', '3', '4', '5', '6', '7', '8', // SN
59 '9', 'A', 'B', 'C'};
60
61std::vector<uint8_t> srcPCEIdentityCallout{
62 'P', 'E', 0x24, 0x00, // type, size, flags
63 'T', 'T', 'T', 'T', '-', 'M', 'M', 'M', // MTM
64 '1', '2', '3', '4', '5', '6', '7', // SN
65 '8', '9', 'A', 'B', 'C', 'P', 'C', 'E', // Name + null padded
66 'N', 'A', 'M', 'E', '1', '2', 0x00, 0x00, 0x00};
67
68std::vector<uint8_t> srcMRUCallout{
69 'M', 'R', 0x28, 0x04, // ID, size, flags
70 0x00, 0x00, 0x00, 0x00, // Reserved
71 0x00, 0x00, 0x00, 'H', // priority 0
72 0x01, 0x01, 0x01, 0x01, // MRU ID 0
73 0x00, 0x00, 0x00, 'M', // priority 1
74 0x02, 0x02, 0x02, 0x02, // MRU ID 1
75 0x00, 0x00, 0x00, 'L', // priority 2
76 0x03, 0x03, 0x03, 0x03, // MRU ID 2
77 0x00, 0x00, 0x00, 'H', // priority 3
78 0x04, 0x04, 0x04, 0x04, // MRU ID 3
79};
80
Matt Spinlerd3335df2019-07-10 11:04:21 -050081std::unique_ptr<std::vector<uint8_t>> pelDataFactory(TestPelType type)
82{
83 std::unique_ptr<std::vector<uint8_t>> data;
84 switch (type)
85 {
86 case TestPelType::pelSimple:
87 data = std::make_unique<std::vector<uint8_t>>(
88 simplePEL, simplePEL + sizeof(simplePEL));
89 break;
90 case TestPelType::privateHeaderSimple:
91 data = std::make_unique<std::vector<uint8_t>>(
92 simplePEL, simplePEL + PrivateHeader::flattenedSize());
93 break;
Matt Spinler03c1d912019-07-10 14:12:15 -050094 case TestPelType::userHeaderSimple:
95 data = std::make_unique<std::vector<uint8_t>>(
96 simplePEL + PrivateHeader::flattenedSize(),
97 simplePEL + PrivateHeader::flattenedSize() +
98 UserHeader::flattenedSize());
99 break;
Matt Spinlerd3335df2019-07-10 11:04:21 -0500100 }
101 return data;
102}
103
Matt Spinler6c9662c2019-10-09 11:27:20 -0500104std::vector<uint8_t> srcDataFactory(TestSRCType type)
105{
106 switch (type)
107 {
108 case TestSRCType::fruIdentityStructure:
109 return srcFRUIdentityCallout;
110
111 case TestSRCType::pceIdentityStructure:
112 return srcPCEIdentityCallout;
113
114 case TestSRCType::mruStructure:
115 return srcMRUCallout;
Matt Spinler32f13c92019-10-09 12:48:25 -0500116
117 case TestSRCType::calloutStructureA:
118 {
119 // Add just the FRU identity substructure to the base structure
120 std::vector<uint8_t> data{
121 0xFF, 0x28, 'H', 4, // size, flags, priority, LC length
122 'U', '4', '2', 0x00 // LC
123 };
124
125 data.insert(data.end(), srcFRUIdentityCallout.begin(),
126 srcFRUIdentityCallout.end());
127
128 // The final size
129 data[0] = data.size();
130 return data;
131 }
132 case TestSRCType::calloutStructureB:
133 {
134 // Add all 3 substructures to the base structure
135
136 std::vector<uint8_t> data{
137 0xFF, 0x2F, 'L', 8, // size, flags, priority, LC length
138 'U', '1', '2', '-', 'P', '1', 0x00, 0x00 // LC
139 };
140 data.insert(data.end(), srcFRUIdentityCallout.begin(),
141 srcFRUIdentityCallout.end());
142 data.insert(data.end(), srcPCEIdentityCallout.begin(),
143 srcPCEIdentityCallout.end());
144 data.insert(data.end(), srcMRUCallout.begin(), srcMRUCallout.end());
145
146 // The final size
147 data[0] = data.size();
148 return data;
149 }
Matt Spinler6c9662c2019-10-09 11:27:20 -0500150 }
151 return {};
152}
153
Matt Spinlerd3335df2019-07-10 11:04:21 -0500154std::unique_ptr<std::vector<uint8_t>> readPELFile(const fs::path& path)
155{
156 std::ifstream file{path};
157
158 auto pel = std::make_unique<std::vector<uint8_t>>(
159 std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
160 return pel;
161}