summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-10-24 13:03:46 -0500
committerMatt Spinler <spinler@us.ibm.com>2019-11-04 16:18:24 -0600
commitafa857c70ad78fd91f50871005d8a2ef8bf6a59b (patch)
tree647f23105318408ae36b95742bb0d95e88698554 /test
parentaa659477fa398f255c5a87207224d59aea15aa34 (diff)
downloadphosphor-logging-afa857c70ad78fd91f50871005d8a2ef8bf6a59b.tar.gz
phosphor-logging-afa857c70ad78fd91f50871005d8a2ef8bf6a59b.zip
PEL: Save AdditionalData in a UserData section
Save the contents of the AdditionalData OpenBMC event log property as JSON in a UserData PEL section. For example, if the AdditionalData property, which is an array of strings, looks like: ["KEY1=VALUE1", "KEY=VALUE2"] Then the data stored as ASCII text in the UserData section is: {"KEY1":"VALUE1","KEY2":"VALUE2"} If one of the keys is "ESEL", then that entry is removed from the UserData output as that contains a full raw PEL from the host sent down as ASCII text. Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: Ia6ffabb39fdb4315ec2152744414e44f7d2ec4aa
Diffstat (limited to 'test')
-rw-r--r--test/openpower-pels/additional_data_test.cpp7
-rw-r--r--test/openpower-pels/pel_test.cpp29
2 files changed, 36 insertions, 0 deletions
diff --git a/test/openpower-pels/additional_data_test.cpp b/test/openpower-pels/additional_data_test.cpp
index 2be06c4..1bf4af7 100644
--- a/test/openpower-pels/additional_data_test.cpp
+++ b/test/openpower-pels/additional_data_test.cpp
@@ -24,4 +24,11 @@ TEST(AdditionalDataTest, GetKeywords)
EXPECT_FALSE(ad.getValue("HELLOWORLD"));
EXPECT_FALSE(ad.getValue("VALUE5"));
+
+ auto json = ad.toJSON();
+ std::string expected = R"({"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":""})";
+ EXPECT_EQ(json.dump(), expected);
+
+ ad.remove("KEY1");
+ EXPECT_FALSE(ad.getValue("KEY1"));
}
diff --git a/test/openpower-pels/pel_test.cpp b/test/openpower-pels/pel_test.cpp
index b0c6528..6494c52 100644
--- a/test/openpower-pels/pel_test.cpp
+++ b/test/openpower-pels/pel_test.cpp
@@ -231,3 +231,32 @@ TEST_F(PELTest, InvalidGenericTest)
EXPECT_TRUE(foundGeneric);
}
+
+// Create a UserData section out of AdditionalData
+TEST_F(PELTest, MakeUDSectionTest)
+{
+ std::vector<std::string> ad{"KEY1=VALUE1", "KEY2=VALUE2", "KEY3=VALUE3",
+ "ESEL=TEST"};
+ AdditionalData additionalData{ad};
+
+ auto ud = util::makeADUserDataSection(additionalData);
+
+ 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);
+
+ const auto& d = ud->data();
+
+ std::string jsonString{d.begin(), d.end()};
+ std::string expected =
+ R"({"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":"VALUE3"})";
+ EXPECT_EQ(jsonString, expected);
+
+ // Ensure we can read this as JSON
+ auto newJSON = nlohmann::json::parse(jsonString);
+ EXPECT_EQ(newJSON["KEY1"], "VALUE1");
+ EXPECT_EQ(newJSON["KEY2"], "VALUE2");
+ EXPECT_EQ(newJSON["KEY3"], "VALUE3");
+} \ No newline at end of file
OpenPOWER on IntegriCloud