PEL: Misc pel_manager_test improvements
Simplify 2 things in pel_manager_test.cpp:
1. Add a 'Using Level' statement for the error log severity so
the namespace doesn't have to be used in each instance.
2. Use std::bind_front so std::placeholders doesn't need to be used
for the function args.
Change-Id: Id02a0d052f9c5e0979ad0199b01a82e2119c9b45
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
index 51c327e..b93e58c 100644
--- a/test/openpower-pels/pel_manager_test.cpp
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -21,10 +21,12 @@
using ::testing::Return;
using json = nlohmann::json;
+using Level = phosphor::logging::Entry::Level;
+
class TestLogger
{
public:
- void log(const std::string& name, phosphor::logging::Entry::Level level,
+ void log(const std::string& name, Level level,
const EventLogger::ADMap& additionalData)
{
errName = name;
@@ -33,7 +35,7 @@
}
std::string errName;
- phosphor::logging::Entry::Level errLevel;
+ Level errLevel;
EventLogger::ADMap ad;
};
@@ -128,11 +130,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
// Create a PEL, write it to a file, and pass that filename into
// the create function.
@@ -147,8 +147,7 @@
{"RAWPEL", pelFilename.string()}};
std::vector<std::string> associations;
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
// Find the file in the PEL repository directory
@@ -171,11 +170,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
// Create a PEL, write it to a file, and pass that filename into
// the create function.
@@ -193,8 +190,7 @@
{"RAWPEL", pelFilename.string()}};
std::vector<std::string> associations;
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
// Run the event loop to log the bad PEL event
@@ -203,7 +199,7 @@
PEL invalidPEL{data};
EXPECT_EQ(logger.errName, "org.open_power.Logging.Error.BadHostPEL");
- EXPECT_EQ(logger.errLevel, phosphor::logging::Entry::Level::Error);
+ EXPECT_EQ(logger.errLevel, Level::Error);
EXPECT_EQ(std::stoi(logger.ad["PLID"], nullptr, 16), invalidPEL.plid());
EXPECT_EQ(logger.ad["OBMC_LOG_ID"], "42");
EXPECT_EQ(logger.ad["SRC"], (*invalidPEL.primarySRC())->asciiString());
@@ -273,19 +269,16 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
std::map<std::string, std::string> additionalData{{"FOO", "BAR"}};
std::vector<std::string> associations;
// Create the event log to create the PEL from.
- manager.create("xyz.openbmc_project.Error.Test", 33, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations);
+ manager.create("xyz.openbmc_project.Error.Test", 33, 0, Level::Error,
+ additionalData, associations);
// Ensure a PEL was created in the repository
auto pelFile = findAnyPELInRepo();
@@ -316,9 +309,8 @@
// Create an event log that can't be found in the registry.
// In this case, xyz.openbmc_project.Logging.Error.Default will
// be used as the key instead to find a registry match.
- manager.create("xyz.openbmc_project.Error.Foo", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations);
+ manager.create("xyz.openbmc_project.Error.Foo", 42, 0, Level::Error,
+ additionalData, associations);
// Ensure a PEL was still created in the repository
pelFile = findAnyPELInRepo();
@@ -381,11 +373,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
// Create a PEL, write it to a file, and pass that filename into
// the create function so there's one in the repo.
@@ -400,8 +390,7 @@
{"RAWPEL", pelFilename.string()}};
std::vector<std::string> associations;
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
// getPELFromOBMCID
@@ -605,18 +594,15 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
{
std::map<std::string, std::string> additionalData{{"ESEL", esel}};
std::vector<std::string> associations;
- manager.create("error message", 37, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 37, 0, Level::Error, additionalData,
associations);
auto data = manager.getPELFromOBMCID(37);
@@ -634,8 +620,7 @@
std::map<std::string, std::string> additionalData{{"ESEL", adItem}};
std::vector<std::string> associations;
- manager.create("error message", 38, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 38, 0, Level::Error, additionalData,
associations);
EXPECT_THROW(
@@ -647,7 +632,7 @@
e.run(std::chrono::milliseconds(1));
EXPECT_EQ(logger.errName, "org.open_power.Logging.Error.BadHostPEL");
- EXPECT_EQ(logger.errLevel, phosphor::logging::Entry::Level::Error);
+ EXPECT_EQ(logger.errLevel, Level::Error);
}
}
@@ -661,11 +646,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
// Create 25 1000B (4096B on disk each, which is what is used for
// pruning) BMC non-informational PELs in the 100KB repository. After
@@ -687,8 +670,7 @@
{"RAWPEL", pelFilename.string()}};
std::vector<std::string> associations;
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
// Simulate the code getting back to the event loop
@@ -736,11 +718,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
auto data = pelDataFactory(TestPELType::pelSimple);
auto dir = makeTempDir();
@@ -758,8 +738,7 @@
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
pelFile.close();
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
// Sanity check this ID is really there so we can test
@@ -813,11 +792,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
auto data = pelDataFactory(TestPELType::pelSimple);
auto dir = makeTempDir();
@@ -835,8 +812,7 @@
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
pelFile.close();
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
// Sanity check this ID is really there so we can test
@@ -885,11 +861,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
// Add a PEL with a callout as if hostboot added it
{
@@ -913,8 +887,7 @@
{"RAWPEL", pelFilename.string()}};
std::vector<std::string> associations;
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
}
@@ -981,9 +954,8 @@
std::map<std::string, std::string> additionalData;
std::vector<std::string> associations;
- manager.create("xyz.openbmc_project.Error.Test", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations);
+ manager.create("xyz.openbmc_project.Error.Test", 42, 0, Level::Error,
+ additionalData, associations);
}
}
@@ -998,11 +970,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
for (int i = 0; i < 2; i++)
{
@@ -1018,8 +988,7 @@
{"RAWPEL", pelFilename.string()}};
std::vector<std::string> associations;
- manager.create("error message", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
+ manager.create("error message", 42, 0, Level::Error, additionalData,
associations);
e.run(std::chrono::milliseconds(1));
@@ -1079,19 +1048,16 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
std::map<std::string, std::string> additionalData{{"FOO", "BAR"}};
std::vector<std::string> associations;
// Create the event log to create the PEL from.
- manager.create("xyz.openbmc_project.Error.Test", 33, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations);
+ manager.create("xyz.openbmc_project.Error.Test", 33, 0, Level::Error,
+ additionalData, associations);
// Ensure a PEL was created in the repository
auto pelData = findAnyPELInRepo();
@@ -1182,11 +1148,9 @@
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
std::map<std::string, std::string> additionalData;
std::vector<std::string> associations;
@@ -1204,9 +1168,8 @@
deconfigured);
};
- manager.create("xyz.openbmc_project.Fan.Error.Fault", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations);
+ manager.create("xyz.openbmc_project.Fan.Error.Fault", 42, 0, Level::Error,
+ additionalData, associations);
checkDeconfigured(true);
// Replace A3 so PEL deconfigured flag should be set to false
@@ -1217,9 +1180,8 @@
// Create it again and replace a FRU not in the callout list.
// Deconfig flag should stay on.
- manager.create("xyz.openbmc_project.Fan.Error.Fault", 43, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations);
+ manager.create("xyz.openbmc_project.Fan.Error.Fault", 43, 0, Level::Error,
+ additionalData, associations);
checkDeconfigured(true);
mockIface->fruPresent("U1234-A4");
checkDeconfigured(true);
@@ -1329,11 +1291,9 @@
.WillRepeatedly(Return(std::vector<std::string>{}));
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
std::map<std::string, std::string> additionalData;
std::vector<std::string> associations;
@@ -1342,9 +1302,8 @@
EXPECT_FALSE(manager.isDeleteProhibited(42));
}
// creating without ffdcEntries
- manager.create("xyz.openbmc_project.Error.Test", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations);
+ manager.create("xyz.openbmc_project.Error.Test", 42, 0, Level::Error,
+ additionalData, associations);
auto pelFile = findAnyPELInRepo();
auto data = readPELFile(*pelFile);
PEL pel_unguarded(*data);
@@ -1364,9 +1323,8 @@
uint8_t version = 0x01;
phosphor::logging::FFDCEntries ffdcEntries;
appendFFDCEntry(fd, subTypeJson, version, ffdcEntries);
- manager.create("xyz.openbmc_project.Error.Test", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations, ffdcEntries);
+ manager.create("xyz.openbmc_project.Error.Test", 42, 0, Level::Error,
+ additionalData, associations, ffdcEntries);
close(fd);
std::filesystem::remove(calloutFile);
@@ -1433,11 +1391,9 @@
"/xyz/openbmc_project/hardware_isolation/entry/1"}));
std::unique_ptr<JournalBase> journal = std::make_unique<MockJournal>();
- openpower::pels::Manager manager{
- logManager, std::move(dataIface),
- std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3),
- std::move(journal)};
+ Manager manager{logManager, std::move(dataIface),
+ std::bind_front(&TestLogger::log, &logger),
+ std::move(journal)};
std::map<std::string, std::string> additionalData;
std::vector<std::string> associations;
@@ -1447,9 +1403,8 @@
uint8_t version = 0x01;
phosphor::logging::FFDCEntries ffdcEntries;
appendFFDCEntry(fd, subTypeJson, version, ffdcEntries);
- manager.create("xyz.openbmc_project.Error.Test", 42, 0,
- phosphor::logging::Entry::Level::Error, additionalData,
- associations, ffdcEntries);
+ manager.create("xyz.openbmc_project.Error.Test", 42, 0, Level::Error,
+ additionalData, associations, ffdcEntries);
close(fd);
std::filesystem::remove(calloutFile);