summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2020-01-22 14:55:07 -0600
committerMatt Spinler <spinler@us.ibm.com>2020-01-31 15:00:11 +0000
commit4dcd3f46599a8c702fca4b13e4370a0ec7f66ffd (patch)
tree618aebb1ccb9b5231f9c1e8d6c74658005ec6b68 /test
parentc7c3e40249fcba41b4c6b15676fc1054e6ce1049 (diff)
downloadphosphor-logging-4dcd3f46599a8c702fca4b13e4370a0ec7f66ffd.tar.gz
phosphor-logging-4dcd3f46599a8c702fca4b13e4370a0ec7f66ffd.zip
PEL: Save process name in a UserData section
When creating a new PEL, add a UserData section that contains various pieces of system information that will be saved in every error log. In this first commit, just save the process name of the creator, provided they passed in the '_PID' AdditionalData item containing their PID. Future commits will add other items like certain D-Bus properties. Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: I7139b4056e494277ff3388bfa8a00002c9c89dc1
Diffstat (limited to 'test')
-rw-r--r--test/openpower-pels/pel_test.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/test/openpower-pels/pel_test.cpp b/test/openpower-pels/pel_test.cpp
index 995f780..1a5f81f 100644
--- a/test/openpower-pels/pel_test.cpp
+++ b/test/openpower-pels/pel_test.cpp
@@ -136,7 +136,8 @@ TEST_F(PELTest, CreateFromRegistryTest)
regEntry.src.type = 0xBD;
regEntry.src.reasonCode = 0x1234;
- AdditionalData ad;
+ std::vector<std::string> data{"KEY1=VALUE1"};
+ AdditionalData ad{data};
MockDataInterface dataIface;
PEL pel{regEntry, 42, timestamp, phosphor::logging::Entry::Level::Error, ad,
@@ -148,6 +149,34 @@ TEST_F(PELTest, CreateFromRegistryTest)
EXPECT_EQ(pel.primarySRC().value()->asciiString(),
"BD051234 ");
+
+ // Check that certain optional sections have been created
+ size_t mtmsCount = 0;
+ size_t euhCount = 0;
+ size_t udCount = 0;
+
+ for (const auto& section : pel.optionalSections())
+ {
+ if (section->header().id ==
+ static_cast<uint16_t>(SectionID::failingMTMS))
+ {
+ mtmsCount++;
+ }
+ else if (section->header().id ==
+ static_cast<uint16_t>(SectionID::extendedUserHeader))
+ {
+ euhCount++;
+ }
+ else if (section->header().id ==
+ static_cast<uint16_t>(SectionID::userData))
+ {
+ udCount++;
+ }
+ }
+
+ EXPECT_EQ(mtmsCount, 1);
+ EXPECT_EQ(euhCount, 1);
+ EXPECT_EQ(udCount, 2); // AD section and sysInfo section
}
// Test that we'll create Generic optional sections for sections that
@@ -282,3 +311,30 @@ TEST_F(PELTest, MakeUDSectionTest)
EXPECT_EQ(newJSON["KEY2"], "VALUE2");
EXPECT_EQ(newJSON["KEY3"], "VALUE3");
}
+
+// Create the UserData section that contains system info
+TEST_F(PELTest, MakeSysInfoSectionTest)
+{
+ MockDataInterface dataIface;
+
+ std::string pid = "_PID=" + std::to_string(getpid());
+ std::vector<std::string> ad{pid};
+ AdditionalData additionalData{ad};
+
+ auto ud = util::makeSysInfoUserDataSection(additionalData, dataIface);
+
+ EXPECT_TRUE(ud->valid());
+ EXPECT_EQ(ud->header().id, 0x5544);
+ EXPECT_EQ(ud->header().version, 0x01);
+ EXPECT_EQ(ud->header().subType, 0x01);
+ EXPECT_EQ(ud->header().componentID, 0x2000);
+
+ // Pull out the JSON data and check it.
+ const auto& d = ud->data();
+ std::string jsonString{d.begin(), d.end()};
+ auto json = nlohmann::json::parse(jsonString);
+
+ // Ensure the 'Process Name' entry contains 'pel_test'
+ auto name = json["Process Name"].get<std::string>();
+ EXPECT_NE(name.find("pel_test"), std::string::npos);
+}
OpenPOWER on IntegriCloud