blob: 530dfd5db29806c34deccfcbdc0db3b9cee0156c [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 Spinler89fa0822019-07-17 13:54:30 -050016#include "extensions/openpower-pels/manager.hpp"
17#include "log_manager.hpp"
Matt Spinlere6b48f12020-04-02 09:51:39 -050018#include "mocks.hpp"
Matt Spinler89fa0822019-07-17 13:54:30 -050019#include "pel_utils.hpp"
20
21#include <fstream>
22#include <regex>
Matt Spinlere6b48f12020-04-02 09:51:39 -050023#include <sdbusplus/test/sdbus_mock.hpp>
Matt Spinlera34ab722019-12-16 10:39:32 -060024#include <xyz/openbmc_project/Common/error.hpp>
Matt Spinler89fa0822019-07-17 13:54:30 -050025
26#include <gtest/gtest.h>
27
28using namespace openpower::pels;
29namespace fs = std::filesystem;
30
Matt Spinlere6b48f12020-04-02 09:51:39 -050031using ::testing::NiceMock;
32
Matt Spinler05c2c6c2019-12-18 14:02:09 -060033class TestLogger
34{
35 public:
36 void log(const std::string& name, phosphor::logging::Entry::Level level,
37 const EventLogger::ADMap& additionalData)
38 {
39 errName = name;
40 errLevel = level;
41 ad = additionalData;
42 }
43
44 std::string errName;
45 phosphor::logging::Entry::Level errLevel;
46 EventLogger::ADMap ad;
47};
48
Matt Spinler89fa0822019-07-17 13:54:30 -050049class ManagerTest : public CleanPELFiles
50{
Matt Spinler6b1a5c82020-01-07 08:48:53 -060051 public:
Matt Spinlere6b48f12020-04-02 09:51:39 -050052 ManagerTest() :
53 bus(sdbusplus::get_mocked_new(&sdbusInterface)),
54 logManager(bus, "logging_path")
Matt Spinler6b1a5c82020-01-07 08:48:53 -060055 {
56 sd_event_default(&sdEvent);
Matt Spinler6b1a5c82020-01-07 08:48:53 -060057 }
58
59 ~ManagerTest()
60 {
61 sd_event_unref(sdEvent);
62 }
63
Matt Spinlere6b48f12020-04-02 09:51:39 -050064 NiceMock<sdbusplus::SdBusMock> sdbusInterface;
65 sdbusplus::bus::bus bus;
Matt Spinler6b1a5c82020-01-07 08:48:53 -060066 phosphor::logging::internal::Manager logManager;
67 sd_event* sdEvent;
Matt Spinler05c2c6c2019-12-18 14:02:09 -060068 TestLogger logger;
Matt Spinler89fa0822019-07-17 13:54:30 -050069};
70
71fs::path makeTempDir()
72{
73 char path[] = "/tmp/tempnameXXXXXX";
74 std::filesystem::path dir = mkdtemp(path);
75 return dir;
76}
77
Matt Spinler67456c22019-10-21 12:22:49 -050078std::optional<fs::path> findAnyPELInRepo()
79{
80 // PELs are named <timestamp>_<ID>
81 std::regex expr{"\\d+_\\d+"};
82
83 for (auto& f : fs::directory_iterator(getPELRepoPath() / "logs"))
84 {
85 if (std::regex_search(f.path().string(), expr))
86 {
87 return f.path();
88 }
89 }
90 return std::nullopt;
91}
92
Matt Spinler89fa0822019-07-17 13:54:30 -050093// Test that using the RAWPEL=<file> with the Manager::create() call gets
94// a PEL saved in the repository.
95TEST_F(ManagerTest, TestCreateWithPEL)
96{
Matt Spinlerc8705e22019-09-11 12:36:07 -050097 std::unique_ptr<DataInterfaceBase> dataIface =
Matt Spinlere6b48f12020-04-02 09:51:39 -050098 std::make_unique<MockDataInterface>();
Matt Spinler89fa0822019-07-17 13:54:30 -050099
Matt Spinler05c2c6c2019-12-18 14:02:09 -0600100 openpower::pels::Manager manager{
101 logManager, std::move(dataIface),
102 std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
103 std::placeholders::_2, std::placeholders::_3)};
Matt Spinler89fa0822019-07-17 13:54:30 -0500104
105 // Create a PEL, write it to a file, and pass that filename into
106 // the create function.
Matt Spinler42828bd2019-10-11 10:39:30 -0500107 auto data = pelDataFactory(TestPELType::pelSimple);
Matt Spinler89fa0822019-07-17 13:54:30 -0500108
109 fs::path pelFilename = makeTempDir() / "rawpel";
110 std::ofstream pelFile{pelFilename};
Matt Spinler42828bd2019-10-11 10:39:30 -0500111 pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
Matt Spinler89fa0822019-07-17 13:54:30 -0500112 pelFile.close();
113
114 std::string adItem = "RAWPEL=" + pelFilename.string();
115 std::vector<std::string> additionalData{adItem};
116 std::vector<std::string> associations;
117
Matt Spinler367144c2019-09-19 15:33:52 -0500118 manager.create("error message", 42, 0,
119 phosphor::logging::Entry::Level::Error, additionalData,
Matt Spinler89fa0822019-07-17 13:54:30 -0500120 associations);
121
Matt Spinler67456c22019-10-21 12:22:49 -0500122 // Find the file in the PEL repository directory
123 auto pelPathInRepo = findAnyPELInRepo();
Matt Spinler89fa0822019-07-17 13:54:30 -0500124
Matt Spinler67456c22019-10-21 12:22:49 -0500125 EXPECT_TRUE(pelPathInRepo);
Matt Spinler89fa0822019-07-17 13:54:30 -0500126
Matt Spinler475e5742019-07-18 16:09:49 -0500127 // Now remove it based on its OpenBMC event log ID
128 manager.erase(42);
129
Matt Spinler67456c22019-10-21 12:22:49 -0500130 pelPathInRepo = findAnyPELInRepo();
Matt Spinler475e5742019-07-18 16:09:49 -0500131
Matt Spinler67456c22019-10-21 12:22:49 -0500132 EXPECT_FALSE(pelPathInRepo);
Matt Spinler475e5742019-07-18 16:09:49 -0500133
Matt Spinler89fa0822019-07-17 13:54:30 -0500134 fs::remove_all(pelFilename.parent_path());
135}
Matt Spinler67456c22019-10-21 12:22:49 -0500136
Matt Spinlere95fd012020-01-07 12:53:16 -0600137TEST_F(ManagerTest, TestCreateWithInvalidPEL)
138{
139 std::unique_ptr<DataInterfaceBase> dataIface =
Matt Spinlere6b48f12020-04-02 09:51:39 -0500140 std::make_unique<MockDataInterface>();
Matt Spinlere95fd012020-01-07 12:53:16 -0600141
142 openpower::pels::Manager manager{
143 logManager, std::move(dataIface),
144 std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
145 std::placeholders::_2, std::placeholders::_3)};
146
147 // Create a PEL, write it to a file, and pass that filename into
148 // the create function.
149 auto data = pelDataFactory(TestPELType::pelSimple);
150
151 // Truncate it to make it invalid.
152 data.resize(200);
153
154 fs::path pelFilename = makeTempDir() / "rawpel";
155 std::ofstream pelFile{pelFilename};
156 pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
157 pelFile.close();
158
159 std::string adItem = "RAWPEL=" + pelFilename.string();
160 std::vector<std::string> additionalData{adItem};
161 std::vector<std::string> associations;
162
163 manager.create("error message", 42, 0,
164 phosphor::logging::Entry::Level::Error, additionalData,
165 associations);
166
167 // Run the event loop to log the bad PEL event
168 sdeventplus::Event e{sdEvent};
169 e.run(std::chrono::milliseconds(1));
170
171 PEL invalidPEL{data};
172 EXPECT_EQ(logger.errName, "org.open_power.Logging.Error.BadHostPEL");
173 EXPECT_EQ(logger.errLevel, phosphor::logging::Entry::Level::Error);
174 EXPECT_EQ(std::stoi(logger.ad["PLID"], nullptr, 16), invalidPEL.plid());
175 EXPECT_EQ(logger.ad["OBMC_LOG_ID"], "42");
176 EXPECT_EQ(logger.ad["SRC"], (*invalidPEL.primarySRC())->asciiString());
177 EXPECT_EQ(logger.ad["PEL_SIZE"], std::to_string(data.size()));
178
179 fs::remove_all(pelFilename.parent_path());
180}
181
Matt Spinler67456c22019-10-21 12:22:49 -0500182// Test that the message registry can be used to build a PEL.
183TEST_F(ManagerTest, TestCreateWithMessageRegistry)
184{
185 const auto registry = R"(
186{
187 "PELs":
188 [
189 {
190 "Name": "xyz.openbmc_project.Error.Test",
191 "Subsystem": "power_supply",
192 "ActionFlags": ["service_action", "report"],
193 "SRC":
194 {
195 "ReasonCode": "0x2030"
Harisuddin Mohamed Isa0f717e12020-01-15 20:05:33 +0800196 },
197 "Documentation":
198 {
199 "Description": "A PGOOD Fault",
200 "Message": "PS had a PGOOD Fault"
Matt Spinler67456c22019-10-21 12:22:49 -0500201 }
202 }
203 ]
204}
205)";
206
Matt Spinlerd4ffb652019-11-12 14:16:14 -0600207 auto path = getMessageRegistryPath();
208 fs::create_directories(path);
209 path /= "message_registry.json";
210
Matt Spinler67456c22019-10-21 12:22:49 -0500211 std::ofstream registryFile{path};
212 registryFile << registry;
213 registryFile.close();
214
Matt Spinler67456c22019-10-21 12:22:49 -0500215 std::unique_ptr<DataInterfaceBase> dataIface =
Matt Spinlere6b48f12020-04-02 09:51:39 -0500216 std::make_unique<MockDataInterface>();
Matt Spinler67456c22019-10-21 12:22:49 -0500217
Matt Spinler05c2c6c2019-12-18 14:02:09 -0600218 openpower::pels::Manager manager{
219 logManager, std::move(dataIface),
220 std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
221 std::placeholders::_2, std::placeholders::_3)};
Matt Spinler67456c22019-10-21 12:22:49 -0500222
223 std::vector<std::string> additionalData;
224 std::vector<std::string> associations;
225
226 // Create the event log to create the PEL from.
227 manager.create("xyz.openbmc_project.Error.Test", 33, 0,
228 phosphor::logging::Entry::Level::Error, additionalData,
229 associations);
230
231 // Ensure a PEL was created in the repository
232 auto pelFile = findAnyPELInRepo();
233 ASSERT_TRUE(pelFile);
234
235 auto data = readPELFile(*pelFile);
236 PEL pel(*data);
237
238 // Spot check it. Other testcases cover the details.
239 EXPECT_TRUE(pel.valid());
240 EXPECT_EQ(pel.obmcLogID(), 33);
241 EXPECT_EQ(pel.primarySRC().value()->asciiString(),
242 "BD612030 ");
243
244 // Remove it
245 manager.erase(33);
246 pelFile = findAnyPELInRepo();
247 EXPECT_FALSE(pelFile);
248
249 // Create an event log that can't be found in the registry.
250 manager.create("xyz.openbmc_project.Error.Foo", 33, 0,
251 phosphor::logging::Entry::Level::Error, additionalData,
252 associations);
253
254 // Currently, no PEL should be created. Eventually, a 'missing registry
255 // entry' PEL will be there.
256 pelFile = findAnyPELInRepo();
257 EXPECT_FALSE(pelFile);
258}
Matt Spinlera34ab722019-12-16 10:39:32 -0600259
260TEST_F(ManagerTest, TestDBusMethods)
261{
Matt Spinlera34ab722019-12-16 10:39:32 -0600262 std::unique_ptr<DataInterfaceBase> dataIface =
Matt Spinlere6b48f12020-04-02 09:51:39 -0500263 std::make_unique<MockDataInterface>();
Matt Spinlera34ab722019-12-16 10:39:32 -0600264
Matt Spinler05c2c6c2019-12-18 14:02:09 -0600265 Manager manager{logManager, std::move(dataIface),
266 std::bind(std::mem_fn(&TestLogger::log), &logger,
267 std::placeholders::_1, std::placeholders::_2,
268 std::placeholders::_3)};
Matt Spinlera34ab722019-12-16 10:39:32 -0600269
270 // Create a PEL, write it to a file, and pass that filename into
271 // the create function so there's one in the repo.
272 auto data = pelDataFactory(TestPELType::pelSimple);
273
274 fs::path pelFilename = makeTempDir() / "rawpel";
275 std::ofstream pelFile{pelFilename};
276 pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
277 pelFile.close();
278
279 std::string adItem = "RAWPEL=" + pelFilename.string();
280 std::vector<std::string> additionalData{adItem};
281 std::vector<std::string> associations;
282
283 manager.create("error message", 42, 0,
284 phosphor::logging::Entry::Level::Error, additionalData,
285 associations);
286
287 // getPELFromOBMCID
288 auto newData = manager.getPELFromOBMCID(42);
289 EXPECT_EQ(newData.size(), data.size());
290
291 // Read the PEL to get the ID for later
292 PEL pel{newData};
293 auto id = pel.id();
294
295 EXPECT_THROW(
296 manager.getPELFromOBMCID(id + 1),
297 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
298
299 // getPEL
300 auto unixfd = manager.getPEL(id);
301
302 // Get the size
303 struct stat s;
304 int r = fstat(unixfd, &s);
305 ASSERT_EQ(r, 0);
306 auto size = s.st_size;
307
308 // Open the FD and check the contents
309 FILE* fp = fdopen(unixfd, "r");
310 ASSERT_NE(fp, nullptr);
311
312 std::vector<uint8_t> fdData;
313 fdData.resize(size);
314 r = fread(fdData.data(), 1, size, fp);
315 EXPECT_EQ(r, size);
316
317 EXPECT_EQ(newData, fdData);
318
319 fclose(fp);
320
Matt Spinler05c2c6c2019-12-18 14:02:09 -0600321 // Run the event loop to close the FD
322 sdeventplus::Event e{sdEvent};
323 e.run(std::chrono::milliseconds(1));
324
Matt Spinlera34ab722019-12-16 10:39:32 -0600325 EXPECT_THROW(
326 manager.getPEL(id + 1),
327 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
328
329 // hostAck
330 manager.hostAck(id);
331
332 EXPECT_THROW(
333 manager.hostAck(id + 1),
334 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
335
336 // hostReject
337 manager.hostReject(id, Manager::RejectionReason::BadPEL);
Matt Spinler05c2c6c2019-12-18 14:02:09 -0600338
339 // Run the event loop to log the bad PEL event
340 e.run(std::chrono::milliseconds(1));
341
342 EXPECT_EQ(logger.errName, "org.open_power.Logging.Error.SentBadPELToHost");
343 EXPECT_EQ(id, std::stoi(logger.ad["BAD_ID"], nullptr, 16));
344
Matt Spinlera34ab722019-12-16 10:39:32 -0600345 manager.hostReject(id, Manager::RejectionReason::HostFull);
346
347 EXPECT_THROW(
348 manager.hostReject(id + 1, Manager::RejectionReason::BadPEL),
349 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
350
351 fs::remove_all(pelFilename.parent_path());
352}
Matt Spinler19e72902020-01-24 11:05:20 -0600353
354// An ESEL from the wild
355const std::string esel{
356 "00 00 df 00 00 00 00 20 00 04 12 01 6f aa 00 00 "
357 "50 48 00 30 01 00 33 00 00 00 00 07 5c 69 cc 0d 00 00 00 07 5c d5 50 db "
358 "42 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 90 00 00 4e 90 00 00 4e "
359 "55 48 00 18 01 00 09 00 8a 03 40 00 00 00 00 00 ff ff 00 00 00 00 00 00 "
360 "50 53 00 50 01 01 00 00 02 00 00 09 33 2d 00 48 00 00 00 e0 00 00 10 00 "
361 "00 00 00 00 00 20 00 00 00 0c 00 02 00 00 00 fa 00 00 0c e4 00 00 00 12 "
362 "42 43 38 41 33 33 32 44 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
363 "20 20 20 20 20 20 20 20 55 44 00 1c 01 06 01 00 02 54 41 4b 00 00 00 06 "
364 "00 00 00 55 00 01 f9 20 00 00 00 00 55 44 00 24 01 06 01 00 01 54 41 4b "
365 "00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 23 01 00 02 00 05 00 00 "
366 "55 44 00 0c 01 0b 01 00 0f 01 00 00 55 44 00 10 01 04 01 00 0f 9f de 6a "
367 "00 01 00 00 55 44 00 7c 00 0c 01 00 00 13 0c 02 00 fa 0c e4 16 00 01 2c "
368 "0c 1c 16 00 00 fa 0a f0 14 00 00 fa 0b b8 14 00 00 be 09 60 12 00 01 2c "
369 "0d 7a 12 00 00 fa 0c 4e 10 00 00 fa 0c e4 10 00 00 be 0a 8c 16 00 01 2c "
370 "0c 1c 16 00 01 09 09 f6 16 00 00 fa 09 f6 14 00 00 fa 0b b8 14 00 00 fa "
371 "0a f0 14 00 00 be 08 ca 12 00 01 2c 0c e4 12 00 00 fa 0b 54 10 00 00 fa "
372 "0c 2d 10 00 00 be 08 ca 55 44 00 58 01 03 01 00 00 00 00 00 00 05 31 64 "
373 "00 00 00 00 00 05 0d d4 00 00 00 00 40 5f 06 e0 00 00 00 00 40 5d d2 00 "
374 "00 00 00 00 40 57 d3 d0 00 00 00 00 40 58 f6 a0 00 00 00 00 40 54 c9 34 "
375 "00 00 00 00 40 55 9a 10 00 00 00 00 40 4c 0a 80 00 00 00 00 00 00 27 14 "
376 "55 44 01 84 01 01 01 00 48 6f 73 74 62 6f 6f 74 20 42 75 69 6c 64 20 49 "
377 "44 3a 20 68 6f 73 74 62 6f 6f 74 2d 66 65 63 37 34 64 66 2d 70 30 61 38 "
378 "37 64 63 34 2f 68 62 69 63 6f 72 65 2e 62 69 6e 00 49 42 4d 2d 77 69 74 "
379 "68 65 72 73 70 6f 6f 6e 2d 4f 50 39 2d 76 32 2e 34 2d 39 2e 32 33 34 0a "
380 "09 6f 70 2d 62 75 69 6c 64 2d 38 32 66 34 63 66 30 0a 09 62 75 69 6c 64 "
381 "72 6f 6f 74 2d 32 30 31 39 2e 30 35 2e 32 2d 31 30 2d 67 38 39 35 39 31 "
382 "31 34 0a 09 73 6b 69 62 6f 6f 74 2d 76 36 2e 35 2d 31 38 2d 67 34 37 30 "
383 "66 66 62 35 66 32 39 64 37 0a 09 68 6f 73 74 62 6f 6f 74 2d 66 65 63 37 "
384 "34 64 66 2d 70 30 61 38 37 64 63 34 0a 09 6f 63 63 2d 65 34 35 39 37 61 "
385 "62 0a 09 6c 69 6e 75 78 2d 35 2e 32 2e 31 37 2d 6f 70 65 6e 70 6f 77 65 "
386 "72 31 2d 70 64 64 63 63 30 33 33 0a 09 70 65 74 69 74 62 6f 6f 74 2d 76 "
387 "31 2e 31 30 2e 34 0a 09 6d 61 63 68 69 6e 65 2d 78 6d 6c 2d 63 36 32 32 "
388 "63 62 35 2d 70 37 65 63 61 62 33 64 0a 09 68 6f 73 74 62 6f 6f 74 2d 62 "
389 "69 6e 61 72 69 65 73 2d 36 36 65 39 61 36 30 0a 09 63 61 70 70 2d 75 63 "
390 "6f 64 65 2d 70 39 2d 64 64 32 2d 76 34 0a 09 73 62 65 2d 36 30 33 33 30 "
391 "65 30 0a 09 68 63 6f 64 65 2d 68 77 30 39 32 31 31 39 61 2e 6f 70 6d 73 "
392 "74 0a 00 00 55 44 00 70 01 04 01 00 0f 9f de 6a 00 05 00 00 07 5f 1d f4 "
393 "30 32 43 59 34 37 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
394 "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
395 "0b ac 54 02 59 41 31 39 33 34 36 39 37 30 35 38 00 00 00 00 00 00 05 22 "
396 "a1 58 01 8a 00 58 40 20 17 18 4d 2c 00 00 00 fc 01 a1 00 00 55 44 00 14 "
397 "01 08 01 00 00 00 00 01 00 00 00 5a 00 00 00 05 55 44 03 fc 01 15 31 00 "
398 "01 28 00 42 46 41 50 49 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 f4 "
399 "00 00 00 00 00 00 03 f4 00 00 00 0b 00 00 00 00 00 00 00 3d 2c 9b c2 84 "
400 "00 00 01 e4 00 48 43 4f fb ed 70 b1 00 00 02 01 00 00 00 00 00 00 00 09 "
401 "00 00 00 00 00 11 bd 20 00 00 00 00 00 01 f8 80 00 00 00 00 00 00 00 01 "
402 "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 00 00 00 00 00 00 01 2c "
403 "00 00 00 00 00 00 07 d0 00 00 00 00 00 00 0c 1c 00 00 00 64 00 00 00 3d "
404 "2c 9b d1 11 00 00 01 e4 00 48 43 4f fb ed 70 b1 00 00 02 01 00 00 00 00 "
405 "00 00 00 0a 00 00 00 00 00 13 b5 a0 00 00 00 00 00 01 f8 80 00 00 00 00 "
406 "00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 "
407 "00 00 00 be 00 00 00 00 00 00 07 d0 00 00 00 00 00 00 0a 8c 00 00 00 64 "
408 "00 00 00 3d 2c 9b df 98 00 00 01 e4 00 48 43 4f fb ed 70 b1 00 00 02 01 "
409 "00 00 00 00 00 00 00 0b 00 00 00 00 00 15 ae 20 00 00 00 00 00 01 f8 80 "
410 "00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 "
411 "00 00 00 00 00 00 00 fa 00 00 00 00 00 00 07 d0 00 00 00 00 00 00 0c e4 "
412 "00 00 00 64 00 00 00 3d 2c 9b ea b7 00 00 01 e4 00 48 43 4f fb ed 70 b1 "
413 "00 00 02 01 00 00 00 00 00 00 00 0c 00 00 00 00 00 17 a6 a0 00 00 00 00 "
414 "00 01 f8 80 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 "
415 "00 00 00 12 00 00 00 00 00 00 00 fa 00 00 00 00 00 00 07 d0 00 00 00 00 "
416 "00 00 0c 4e 00 00 00 64 00 00 00 3d 2c 9b f6 27 00 00 01 e4 00 48 43 4f "
417 "fb ed 70 b1 00 00 02 01 00 00 00 00 00 00 00 0d 00 00 00 00 00 19 9f 20 "
418 "00 00 00 00 00 01 f8 80 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 "
419 "00 00 00 00 00 00 00 12 00 00 00 00 00 00 01 2c 00 00 00 00 00 00 07 d0 "
420 "00 00 00 00 00 00 0d 7a 00 00 00 64 00 00 00 3d 2c 9c 05 75 00 00 01 e4 "
421 "00 48 43 4f fb ed 70 b1 00 00 02 01 00 00 00 00 00 00 00 0e 00 00 00 00 "
422 "00 1b 97 a0 00 00 00 00 00 01 f8 80 00 00 00 00 00 00 00 01 00 00 00 00 "
423 "00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 be 00 00 00 00 "
424 "00 00 07 d0 00 00 00 00 00 00 09 60 00 00 00 64 00 00 00 3d 2c 9c 11 29 "
425 "00 00 01 e4 00 48 43 4f fb ed 70 b1 00 00 02 01 00 00 00 00 00 00 00 0f "
426 "00 00 00 00 00 1d 90 20 00 00 00 00 00 01 f8 80 00 00 00 00 00 00 00 01 "
427 "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 fa "
428 "00 00 00 00 00 00 07 d0 00 00 00 00 00 00 0b b8 00 00 00 64 00 00 00 3d "
429 "2c 9c 1c 45 00 00 01 e4 00 48 43 4f fb ed 70 b1 00 00 02 01 00 00 00 00 "
430 "00 00 00 10 00 00 00 00 00 1f 88 a0 00 00 00 00 00 01 f8 80 00 00 00 00 "
431 "00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 00 00 00 00 "
432 "00 00 00 fa 00 00 00 00 00 00 07 d0 00 00 00 00 00 00 0a f0 00 00 00 64 "
433 "00 00 00 3d 2c 9c 2b 14 00 00 01 e4 00 48 43 4f fb ed 70 b1 00 00 02 01 "
434 "00 00 00 00 00 00 00 11 00 00 00 00 00 21 81 20 00 00 00 00 00 01 f8 80 "
435 "00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 "
436 "00 00 00 00 00 00 01 2c 00 00 00 00 00 00 07 d0 00 00 00 00 00 00 0c 1c "
437 "00 00 00 64 00 00 00 3d 2d 6d 8f 9e 00 00 01 e4 00 00 43 4f 52 d7 9c 36 "
438 "00 00 04 73 00 00 00 1c 00 00 00 3d 2d 6d 99 ac 00 00 01 e4 00 10 43 4f "
439 "3f f2 02 3d 00 00 05 58 00 00 00 00 02 00 00 01 00 00 00 00 00 00 00 40 "
440 "00 00 00 2c 55 44 00 30 01 15 31 00 01 28 00 42 46 41 50 49 5f 44 42 47 "
441 "00 00 00 00 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00 28 00 00 00 00 "
442 "00 00 00 00 55 44 01 74 01 15 31 00 01 28 00 42 46 41 50 49 5f 49 00 00 "
443 "00 00 00 00 00 00 00 00 00 00 01 6c 00 00 00 00 00 00 01 6c 00 00 00 0b "
444 "00 00 00 00 00 00 00 3c 0d 52 18 5e 00 00 01 e4 00 08 43 4f 46 79 94 13 "
445 "00 00 0a 5b 00 00 00 00 00 00 2c 00 00 00 00 24 00 00 00 3c 0d 6b 26 6c "
446 "00 00 01 e4 00 00 43 4f 4e 9b 18 74 00 00 01 03 00 00 00 1c 00 00 00 3c "
447 "12 b9 2d 13 00 00 01 e4 00 00 43 4f ea 31 ed d4 00 00 05 c4 00 00 00 1c "
448 "00 00 00 3c 13 02 73 53 00 00 01 e4 00 00 43 4f ea 31 ed d4 00 00 05 c4 "
449 "00 00 00 1c 00 00 00 3c 13 04 7c 94 00 00 01 e4 00 00 43 4f ea 31 ed d4 "
450 "00 00 05 c4 00 00 00 1c 00 00 00 3c 13 06 ad e1 00 00 01 e4 00 00 43 4f "
451 "ea 31 ed d4 00 00 05 c4 00 00 00 1c 00 00 00 3c 13 07 3f 77 00 00 01 e4 "
452 "00 00 43 4f 5e 4a 55 32 00 00 10 f2 00 00 00 1c 00 00 00 3c 13 07 4e e4 "
453 "00 00 01 e4 00 00 43 4f 5e 4a 55 32 00 00 0d 68 00 00 00 1c 00 00 00 3c "
454 "13 36 79 18 00 00 01 e4 00 00 43 4f ea 31 ed d4 00 00 05 c4 00 00 00 1c "
455 "00 00 00 3d 2c 9c 36 70 00 00 01 e4 00 00 43 4f 23 45 90 97 00 00 02 47 "
456 "00 00 00 1c 00 00 00 3d 2d 6d a3 ed 00 00 01 e4 00 08 43 4f 74 3a 5b 1a "
457 "00 00 04 cc 00 00 00 00 02 00 00 01 00 00 00 24 55 44 00 30 01 15 31 00 "
458 "01 28 00 42 53 43 41 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 "
459 "00 00 00 00 00 00 00 28 00 00 00 00 00 00 00 00"};
460
461TEST_F(ManagerTest, TestESELToRawData)
462{
463 auto data = Manager::eselToRawData(esel);
464
465 EXPECT_EQ(data.size(), 2464);
466
467 PEL pel{data};
468 EXPECT_TRUE(pel.valid());
469}
470
471TEST_F(ManagerTest, TestCreateWithESEL)
472{
473 std::unique_ptr<DataInterfaceBase> dataIface =
Matt Spinlere6b48f12020-04-02 09:51:39 -0500474 std::make_unique<MockDataInterface>();
Matt Spinler19e72902020-01-24 11:05:20 -0600475
476 openpower::pels::Manager manager{
477 logManager, std::move(dataIface),
478 std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
479 std::placeholders::_2, std::placeholders::_3)};
480
481 {
482 std::string adItem = "ESEL=" + esel;
483 std::vector<std::string> additionalData{adItem};
484 std::vector<std::string> associations;
485
486 manager.create("error message", 37, 0,
487 phosphor::logging::Entry::Level::Error, additionalData,
488 associations);
489
490 auto data = manager.getPELFromOBMCID(37);
491 PEL pel{data};
492 EXPECT_TRUE(pel.valid());
493 }
494
495 // Now an invalid one
496 {
497 std::string adItem = "ESEL=" + esel;
498
499 // Crop it
500 adItem.resize(adItem.size() - 300);
501
502 std::vector<std::string> additionalData{adItem};
503 std::vector<std::string> associations;
504
505 manager.create("error message", 38, 0,
506 phosphor::logging::Entry::Level::Error, additionalData,
507 associations);
508
509 EXPECT_THROW(
510 manager.getPELFromOBMCID(38),
511 sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument);
512
513 // Run the event loop to log the bad PEL event
514 sdeventplus::Event e{sdEvent};
515 e.run(std::chrono::milliseconds(1));
516
517 EXPECT_EQ(logger.errName, "org.open_power.Logging.Error.BadHostPEL");
518 EXPECT_EQ(logger.errLevel, phosphor::logging::Entry::Level::Error);
519 }
520}