Skip to content

Commit e594063

Browse files
extension: use map in create extension
Adjust the Create extension to use a map for metadata instead of vector. Tested: Unit tests updated and passing. Signed-off-by: Patrick Williams <[email protected]> Change-Id: I9bd62b8dcc8b18a61958ed64de98b52a48333637
1 parent 64a9eaa commit e594063

11 files changed

+117
-114
lines changed

extensions.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace logging
1717
*/
1818
using StartupFunction = std::function<void(internal::Manager&)>;
1919

20-
using AdditionalDataArg = std::vector<std::string>;
20+
using AdditionalDataArg = std::map<std::string, std::string>;
2121
using AssociationEndpointsArg = std::vector<std::string>;
2222
using FFDCArg = FFDCEntries;
2323

extensions/openpower-pels/additional_data.hpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,9 @@ class AdditionalData
3838
* @param[in] ad - the AdditionalData property vector with
3939
* entries of "KEY=VALUE"
4040
*/
41-
explicit AdditionalData(const std::vector<std::string>& ad)
42-
{
43-
for (auto& item : ad)
44-
{
45-
auto pos = item.find_first_of('=');
46-
if (pos == std::string::npos || pos == 0)
47-
{
48-
continue;
49-
}
50-
51-
_data[item.substr(0, pos)] = std::move(item.substr(pos + 1));
52-
}
53-
}
41+
explicit AdditionalData(const std::map<std::string, std::string>& ad) :
42+
_data(ad)
43+
{}
5444

5545
/**
5646
* @brief Returns the value of the AdditionalData item for the

extensions/openpower-pels/manager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Manager::~Manager()
7373

7474
void Manager::create(const std::string& message, uint32_t obmcLogID,
7575
uint64_t timestamp, Entry::Level severity,
76-
const std::vector<std::string>& additionalData,
76+
const std::map<std::string, std::string>& additionalData,
7777
const std::vector<std::string>& associations,
7878
const FFDCEntries& ffdc)
7979
{
@@ -361,7 +361,7 @@ PelFFDC Manager::convertToPelFFDC(const FFDCEntries& ffdc)
361361
void Manager::createPEL(
362362
const std::string& message, uint32_t obmcLogID, uint64_t timestamp,
363363
phosphor::logging::Entry::Level severity,
364-
const std::vector<std::string>& additionalData,
364+
const std::map<std::string, std::string>& additionalData,
365365
const std::vector<std::string>& /*associations*/, const FFDCEntries& ffdc)
366366
{
367367
auto entry = _registry.lookup(message, rg::LookupType::name);

extensions/openpower-pels/manager.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class Manager : public PELInterface
113113
*/
114114
void create(const std::string& message, uint32_t obmcLogID,
115115
uint64_t timestamp, phosphor::logging::Entry::Level severity,
116-
const std::vector<std::string>& additionalData,
116+
const std::map<std::string, std::string>& additionalData,
117117
const std::vector<std::string>& associations,
118118
const phosphor::logging::FFDCEntries& ffdc =
119119
phosphor::logging::FFDCEntries{});
@@ -319,7 +319,7 @@ class Manager : public PELInterface
319319
*/
320320
void createPEL(const std::string& message, uint32_t obmcLogID,
321321
uint64_t timestamp, phosphor::logging::Entry::Level severity,
322-
const std::vector<std::string>& additionalData,
322+
const std::map<std::string, std::string>& additionalData,
323323
const std::vector<std::string>& associations,
324324
const phosphor::logging::FFDCEntries& ffdc);
325325

log_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ void Manager::doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc)
452452
try
453453
{
454454
create(entry.message(), entry.id(), entry.timestamp(),
455-
entry.severity(), entry.additionalData(), assocs, ffdc);
455+
entry.severity(), entry.additionalData2(), assocs, ffdc);
456456
}
457457
catch (const std::exception& e)
458458
{

test/openpower-pels/additional_data_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ using namespace openpower::pels;
2121

2222
TEST(AdditionalDataTest, GetKeywords)
2323
{
24-
std::vector<std::string> data{"KEY1=VALUE1", "KEY2=VALUE2",
25-
"KEY3=", "HELLOWORLD", "=VALUE5"};
24+
std::map<std::string, std::string> data{
25+
{"KEY1", "VALUE1"}, {"KEY2", "VALUE2"}, {"KEY3", ""}};
2626
AdditionalData ad{data};
2727

2828
EXPECT_TRUE(ad.getValue("KEY1"));

test/openpower-pels/pel_manager_test.cpp

+37-37
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ TEST_F(ManagerTest, TestCreateWithPEL)
155155
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
156156
pelFile.close();
157157

158-
std::string adItem = "RAWPEL=" + pelFilename.string();
159-
std::vector<std::string> additionalData{adItem};
158+
std::map<std::string, std::string> additionalData{
159+
{"RAWPEL", pelFilename.string()}};
160160
std::vector<std::string> associations;
161161

162162
manager.create("error message", 42, 0,
@@ -201,8 +201,8 @@ TEST_F(ManagerTest, TestCreateWithInvalidPEL)
201201
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
202202
pelFile.close();
203203

204-
std::string adItem = "RAWPEL=" + pelFilename.string();
205-
std::vector<std::string> additionalData{adItem};
204+
std::map<std::string, std::string> additionalData{
205+
{"RAWPEL", pelFilename.string()}};
206206
std::vector<std::string> associations;
207207

208208
manager.create("error message", 42, 0,
@@ -291,7 +291,7 @@ TEST_F(ManagerTest, TestCreateWithMessageRegistry)
291291
std::placeholders::_2, std::placeholders::_3),
292292
std::move(journal)};
293293

294-
std::vector<std::string> additionalData{"FOO=BAR"};
294+
std::map<std::string, std::string> additionalData{{"FOO", "BAR"}};
295295
std::vector<std::string> associations;
296296

297297
// Create the event log to create the PEL from.
@@ -408,8 +408,8 @@ TEST_F(ManagerTest, TestDBusMethods)
408408
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
409409
pelFile.close();
410410

411-
std::string adItem = "RAWPEL=" + pelFilename.string();
412-
std::vector<std::string> additionalData{adItem};
411+
std::map<std::string, std::string> additionalData{
412+
{"RAWPEL", pelFilename.string()}};
413413
std::vector<std::string> associations;
414414

415415
manager.create("error message", 42, 0,
@@ -624,8 +624,7 @@ TEST_F(ManagerTest, TestCreateWithESEL)
624624
std::move(journal)};
625625

626626
{
627-
std::string adItem = "ESEL=" + esel;
628-
std::vector<std::string> additionalData{adItem};
627+
std::map<std::string, std::string> additionalData{{"ESEL", esel}};
629628
std::vector<std::string> associations;
630629

631630
manager.create("error message", 37, 0,
@@ -639,12 +638,12 @@ TEST_F(ManagerTest, TestCreateWithESEL)
639638

640639
// Now an invalid one
641640
{
642-
std::string adItem = "ESEL=" + esel;
641+
std::string adItem = esel;
643642

644643
// Crop it
645644
adItem.resize(adItem.size() - 300);
646645

647-
std::vector<std::string> additionalData{adItem};
646+
std::map<std::string, std::string> additionalData{{"ESEL", adItem}};
648647
std::vector<std::string> associations;
649648

650649
manager.create("error message", 38, 0,
@@ -680,11 +679,11 @@ TEST_F(ManagerTest, TestPruning)
680679
std::placeholders::_2, std::placeholders::_3),
681680
std::move(journal)};
682681

683-
// Create 25 1000B (4096B on disk each, which is what is used for pruning)
684-
// BMC non-informational PELs in the 100KB repository. After the 24th one,
685-
// the repo will be 96% full and a prune should be triggered to remove all
686-
// but 7 to get under 30% full. Then when the 25th is added there will be
687-
// 8 left.
682+
// Create 25 1000B (4096B on disk each, which is what is used for
683+
// pruning) BMC non-informational PELs in the 100KB repository. After
684+
// the 24th one, the repo will be 96% full and a prune should be
685+
// triggered to remove all but 7 to get under 30% full. Then when the
686+
// 25th is added there will be 8 left.
688687

689688
auto dir = makeTempDir();
690689
for (int i = 1; i <= 25; i++)
@@ -696,8 +695,8 @@ TEST_F(ManagerTest, TestPruning)
696695
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
697696
pelFile.close();
698697

699-
std::string adItem = "RAWPEL=" + pelFilename.string();
700-
std::vector<std::string> additionalData{adItem};
698+
std::map<std::string, std::string> additionalData{
699+
{"RAWPEL", pelFilename.string()}};
701700
std::vector<std::string> associations;
702701

703702
manager.create("error message", 42, 0,
@@ -759,8 +758,8 @@ TEST_F(ManagerTest, TestPELManualDelete)
759758
auto dir = makeTempDir();
760759
fs::path pelFilename = dir / "rawpel";
761760

762-
std::string adItem = "RAWPEL=" + pelFilename.string();
763-
std::vector<std::string> additionalData{adItem};
761+
std::map<std::string, std::string> additionalData{
762+
{"RAWPEL", pelFilename.string()}};
764763
std::vector<std::string> associations;
765764

766765
// Add 20 PELs, they will get incrementing IDs like
@@ -836,8 +835,8 @@ TEST_F(ManagerTest, TestPELManualDeleteAll)
836835
auto dir = makeTempDir();
837836
fs::path pelFilename = dir / "rawpel";
838837

839-
std::string adItem = "RAWPEL=" + pelFilename.string();
840-
std::vector<std::string> additionalData{adItem};
838+
std::map<std::string, std::string> additionalData{
839+
{"RAWPEL", pelFilename.string()}};
841840
std::vector<std::string> associations;
842841

843842
// Add 200 PELs, they will get incrementing IDs like
@@ -922,8 +921,8 @@ TEST_F(ManagerTest, TestServiceIndicators)
922921
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
923922
pelFile.close();
924923

925-
std::string adItem = "RAWPEL=" + pelFilename.string();
926-
std::vector<std::string> additionalData{adItem};
924+
std::map<std::string, std::string> additionalData{
925+
{"RAWPEL", pelFilename.string()}};
927926
std::vector<std::string> associations;
928927

929928
manager.create("error message", 42, 0,
@@ -991,7 +990,7 @@ TEST_F(ManagerTest, TestServiceIndicators)
991990
registryFile << registry;
992991
registryFile.close();
993992

994-
std::vector<std::string> additionalData;
993+
std::map<std::string, std::string> additionalData;
995994
std::vector<std::string> associations;
996995

997996
manager.create("xyz.openbmc_project.Error.Test", 42, 0,
@@ -1027,8 +1026,8 @@ TEST_F(ManagerTest, TestDuplicatePEL)
10271026
pelFile.write(reinterpret_cast<const char*>(data.data()), data.size());
10281027
pelFile.close();
10291028

1030-
std::string adItem = "RAWPEL=" + pelFilename.string();
1031-
std::vector<std::string> additionalData{adItem};
1029+
std::map<std::string, std::string> additionalData{
1030+
{"RAWPEL", pelFilename.string()}};
10321031
std::vector<std::string> associations;
10331032

10341033
manager.create("error message", 42, 0,
@@ -1052,7 +1051,8 @@ TEST_F(ManagerTest, TestDuplicatePEL)
10521051
EXPECT_EQ(count, 1);
10531052
}
10541053

1055-
// Test termination bit set for pel with critical system termination severity
1054+
// Test termination bit set for pel with critical system termination
1055+
// severity
10561056
TEST_F(ManagerTest, TestTerminateBitWithPELSevCriticalSysTerminate)
10571057
{
10581058
const auto registry = R"(
@@ -1097,7 +1097,7 @@ TEST_F(ManagerTest, TestTerminateBitWithPELSevCriticalSysTerminate)
10971097
std::placeholders::_2, std::placeholders::_3),
10981098
std::move(journal)};
10991099

1100-
std::vector<std::string> additionalData{"FOO=BAR"};
1100+
std::map<std::string, std::string> additionalData{{"FOO", "BAR"}};
11011101
std::vector<std::string> associations;
11021102

11031103
// Create the event log to create the PEL from.
@@ -1200,7 +1200,7 @@ TEST_F(ManagerTest, TestFruPlug)
12001200
std::placeholders::_2, std::placeholders::_3),
12011201
std::move(journal)};
12021202

1203-
std::vector<std::string> additionalData;
1203+
std::map<std::string, std::string> additionalData;
12041204
std::vector<std::string> associations;
12051205

12061206
auto checkDeconfigured = [](bool deconfigured) {
@@ -1346,7 +1346,7 @@ TEST_F(ManagerTest, TestPELDeleteWithoutHWIsolation)
13461346
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
13471347
std::placeholders::_2, std::placeholders::_3),
13481348
std::move(journal)};
1349-
std::vector<std::string> additionalData;
1349+
std::map<std::string, std::string> additionalData;
13501350
std::vector<std::string> associations;
13511351

13521352
// Check when there's no PEL with given id.
@@ -1363,8 +1363,8 @@ TEST_F(ManagerTest, TestPELDeleteWithoutHWIsolation)
13631363
{
13641364
// Verify that the guard flag is false.
13651365
EXPECT_FALSE(pel_unguarded.getGuardFlag());
1366-
// Check that `isDeleteProhibited` returns false when the guard flag is
1367-
// false.
1366+
// Check that `isDeleteProhibited` returns false when the guard flag
1367+
// is false.
13681368
EXPECT_FALSE(manager.isDeleteProhibited(42));
13691369
}
13701370
manager.erase(42);
@@ -1449,7 +1449,7 @@ TEST_F(ManagerTest, TestPELDeleteWithHWIsolation)
14491449
std::bind(std::mem_fn(&TestLogger::log), &logger, std::placeholders::_1,
14501450
std::placeholders::_2, std::placeholders::_3),
14511451
std::move(journal)};
1452-
std::vector<std::string> additionalData;
1452+
std::map<std::string, std::string> additionalData;
14531453
std::vector<std::string> associations;
14541454

14551455
int fd = createHWIsolatedCalloutFile();
@@ -1468,9 +1468,9 @@ TEST_F(ManagerTest, TestPELDeleteWithHWIsolation)
14681468
auto data = readPELFile(*pelFile);
14691469
PEL pel(*data);
14701470
EXPECT_TRUE(pel.valid());
1471-
// Test case where the guard flag is set to true and the hardware isolation
1472-
// guard is associated, which should result in `isDeleteProhibited`
1473-
// returning true as expected.
1471+
// Test case where the guard flag is set to true and the hardware
1472+
// isolation guard is associated, which should result in
1473+
// `isDeleteProhibited` returning true as expected.
14741474
EXPECT_TRUE(pel.getGuardFlag());
14751475
EXPECT_TRUE(manager.isDeleteProhibited(42));
14761476
manager.erase(42);

0 commit comments

Comments
 (0)