summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHarisuddin Mohamed Isa <harisuddin@gmail.com>2020-02-06 14:25:57 +0800
committerMatt Spinler <spinler@us.ibm.com>2020-02-07 14:39:10 +0000
commit6fd0c1e70c1f63c44ffa69308569b1be144451ce (patch)
treed323c85356bc3f8845355b95ea22b9fdf4bb47dd /test
parentc32e5516d2aee1a4069574f915f0946e56ff8427 (diff)
downloadphosphor-logging-6fd0c1e70c1f63c44ffa69308569b1be144451ce.tar.gz
phosphor-logging-6fd0c1e70c1f63c44ffa69308569b1be144451ce.zip
PEL: Add SRC::getErrorDetails() unit test
Tests the registry message string placeholder substitution Signed-off-by: Harisuddin Mohamed Isa <harisuddin@gmail.com> Change-Id: If89609a911403a76bd6044f81e0f464e38aec8f2
Diffstat (limited to 'test')
-rw-r--r--test/openpower-pels/src_test.cpp105
1 files changed, 102 insertions, 3 deletions
diff --git a/test/openpower-pels/src_test.cpp b/test/openpower-pels/src_test.cpp
index c1b5116..b966344 100644
--- a/test/openpower-pels/src_test.cpp
+++ b/test/openpower-pels/src_test.cpp
@@ -16,11 +16,89 @@
#include "extensions/openpower-pels/src.hpp"
#include "pel_utils.hpp"
+#include <fstream>
+
#include <gtest/gtest.h>
using namespace openpower::pels;
+namespace fs = std::filesystem;
+
+const auto testRegistry = R"(
+{
+"PELs":
+[
+ {
+ "Name": "xyz.openbmc_project.Error.Test",
+ "Subsystem": "bmc_firmware",
+ "SRC":
+ {
+ "ReasonCode": "0xABCD",
+ "Words6To9":
+ {
+ "6":
+ {
+ "Description": "Component ID",
+ "AdditionalDataPropSource": "COMPID"
+ },
+ "7":
+ {
+ "Description": "Failure count",
+ "AdditionalDataPropSource": "FREQUENCY"
+ },
+ "8":
+ {
+ "Description": "Time period",
+ "AdditionalDataPropSource": "DURATION"
+ },
+ "9":
+ {
+ "Description": "Error code",
+ "AdditionalDataPropSource": "ERRORCODE"
+ }
+ }
+ },
+ "Documentation":
+ {
+ "Description": "A Component Fault",
+ "Message": "Comp %1 failed %2 times over %3 secs with ErrorCode %4",
+ "MessageArgSources":
+ [
+ "SRCWord6", "SRCWord7", "SRCWord8", "SRCWord9"
+ ]
+ }
+ }
+]
+}
+)";
-TEST(SRCTest, UnflattenFlattenTestNoCallouts)
+class SRCTest : public ::testing::Test
+{
+ protected:
+ static void SetUpTestCase()
+ {
+ char path[] = "/tmp/srctestXXXXXX";
+ regDir = mkdtemp(path);
+ }
+
+ static void TearDownTestCase()
+ {
+ fs::remove_all(regDir);
+ }
+
+ static std::string writeData(const char* data)
+ {
+ fs::path path = regDir / "registry.json";
+ std::ofstream stream{path};
+ stream << data;
+ return path;
+ }
+
+ static fs::path regDir;
+};
+
+fs::path SRCTest::regDir{};
+
+TEST_F(SRCTest, UnflattenFlattenTestNoCallouts)
{
auto data = pelDataFactory(TestPELType::primarySRCSection);
@@ -61,7 +139,7 @@ TEST(SRCTest, UnflattenFlattenTestNoCallouts)
EXPECT_EQ(data, newData);
}
-TEST(SRCTest, UnflattenFlattenTest2Callouts)
+TEST_F(SRCTest, UnflattenFlattenTest2Callouts)
{
auto data = pelDataFactory(TestPELType::primarySRCSection2Callouts);
@@ -98,7 +176,7 @@ TEST(SRCTest, UnflattenFlattenTest2Callouts)
}
// Create an SRC from the message registry
-TEST(SRCTest, CreateTestNoCallouts)
+TEST_F(SRCTest, CreateTestNoCallouts)
{
message::Entry entry;
entry.src.type = 0xBD;
@@ -160,3 +238,24 @@ TEST(SRCTest, CreateTestNoCallouts)
EXPECT_EQ(newSRC.asciiString(), src.asciiString());
EXPECT_FALSE(newSRC.callouts());
}
+
+// Test the getErrorDetails function
+TEST_F(SRCTest, MessageSubstitutionTest)
+{
+ auto path = SRCTest::writeData(testRegistry);
+ message::Registry registry{path};
+ auto entry = registry.lookup("0xABCD", message::LookupType::reasonCode);
+
+ std::vector<std::string> adData{"COMPID=0x1", "FREQUENCY=0x4",
+ "DURATION=30", "ERRORCODE=0x01ABCDEF"};
+ AdditionalData ad{adData};
+
+ SRC src{*entry, ad};
+ EXPECT_TRUE(src.valid());
+
+ auto errorDetails = src.getErrorDetails(registry, DetailLevel::message);
+ ASSERT_TRUE(errorDetails);
+ EXPECT_EQ(
+ errorDetails.value(),
+ "Comp 0x1 failed 0x4 times over 0x1E secs with ErrorCode 0x1ABCDEF");
+}
OpenPOWER on IntegriCloud