PEL: Print SRC section into JSON

For BMC created errors, look up the reason code in
the message registry for error description and also
meaning of data stored in hexwords 6-9 (if any).

Added registry message field in peltool list output.

"Primary SRC": {
    "Section Version":          "1",
    "Sub-section type":         "1",
    "Created by":               "0x1000",
    "SRC Version":              "0x02",
    "SRC Format":               "0x55",
    "Power Control Net Fault":  "False",
    "Error Details": {
        "Message":              "PS 0x64 had a PGOOD Fault",
        "PS_NUM":               "0x64"
    },
    "Valid Word Count":         "0x09",
    "Reference Code":           "BD8D1001",
    "Hex Word 2":               "00000055",
    "Hex Word 3":               "00000010",
    "Hex Word 4":               "00000000",
    "Hex Word 5":               "00000000",
    "Hex Word 6":               "00000064",
    "Hex Word 7":               "00000000",
    "Hex Word 8":               "00000000",
    "Hex Word 9":               "00000000"
}

"Primary SRC": {
    "Section Version":          "1",
    "Sub-section type":         "0",
    "Created by":               "0x4552",
    "SRC Version":              "0x02",
    "SRC Format":               "0x2008000",
    "Power Control Net Fault":  "False",
    "Valid Word Count":         "0x04",
    "Reference Code":           "B2001020",
    "Hex Word 2":               "02008000",
    "Hex Word 3":               "00000000",
    "Hex Word 4":               "00000012",
    "Callout Section": {
        "Callout Count":        "1",
        "Callouts": [{
            "FRU Type":         "Symbolic FRU",
            "Priority":         "Medium Priority",
            "Part Number":      "NEXTLVL"
        }]
    }
}

Testing: Manually run peltool and verified out. All unit tests passed.
Signed-off-by: Harisuddin Mohamed Isa <harisuddin@gmail.com>
Change-Id: I124627ba785413ebda02305b7d9f95431922e714
diff --git a/test/openpower-pels/registry_test.cpp b/test/openpower-pels/registry_test.cpp
index c193c3f..2944ce0 100644
--- a/test/openpower-pels/registry_test.cpp
+++ b/test/openpower-pels/registry_test.cpp
@@ -35,6 +35,12 @@
             "SRC":
             {
                 "ReasonCode": "0x2030"
+            },
+
+            "Documentation":
+            {
+                "Description": "A PGOOD Fault",
+                "Message": "PS had a PGOOD Fault"
             }
         },
 
@@ -66,6 +72,20 @@
                         "AdditionalDataPropSource": "VOLTAGE"
                     }
                 }
+            },
+
+            "Documentation":
+            {
+                "Description": "A PGOOD Fault",
+                "Message": "PS %1 had a PGOOD Fault",
+                "MessageArgSources":
+                [
+                    "SRCWord6"
+                ],
+                "Notes": [
+                    "In the UserData section there is a JSON",
+                    "dump that provides debug information."
+                ]
             }
         }
     ]
@@ -104,7 +124,7 @@
     auto path = RegistryTest::writeData(registryData);
     Registry registry{path};
 
-    auto entry = registry.lookup("foo");
+    auto entry = registry.lookup("foo", LookupType::name);
     EXPECT_FALSE(entry);
 }
 
@@ -113,7 +133,8 @@
     auto path = RegistryTest::writeData(registryData);
     Registry registry{path};
 
-    auto entry = registry.lookup("xyz.openbmc_project.Power.OverVoltage");
+    auto entry = registry.lookup("xyz.openbmc_project.Power.OverVoltage",
+                                 LookupType::name);
     ASSERT_TRUE(entry);
     EXPECT_EQ(entry->name, "xyz.openbmc_project.Power.OverVoltage");
     EXPECT_EQ(entry->subsystem, 0x62);
@@ -147,6 +168,17 @@
     EXPECT_NE(std::find((*sid).begin(), (*sid).end(), 5), (*sid).end());
     EXPECT_NE(std::find((*sid).begin(), (*sid).end(), 6), (*sid).end());
     EXPECT_NE(std::find((*sid).begin(), (*sid).end(), 7), (*sid).end());
+
+    EXPECT_EQ(entry->doc.description, "A PGOOD Fault");
+    EXPECT_EQ(entry->doc.message, "PS %1 had a PGOOD Fault");
+    auto& hexwordSource = entry->doc.messageArgSources;
+    EXPECT_TRUE(hexwordSource);
+    EXPECT_EQ((*hexwordSource).size(), 1);
+    EXPECT_EQ((*hexwordSource).front(), "SRCWord6");
+
+    entry = registry.lookup("0x2333", LookupType::reasonCode);
+    ASSERT_TRUE(entry);
+    EXPECT_EQ(entry->name, "xyz.openbmc_project.Power.OverVoltage");
 }
 
 // Check the entry that mostly uses defaults
@@ -155,7 +187,8 @@
     auto path = RegistryTest::writeData(registryData);
     Registry registry{path};
 
-    auto entry = registry.lookup("xyz.openbmc_project.Power.Fault");
+    auto entry =
+        registry.lookup("xyz.openbmc_project.Power.Fault", LookupType::name);
     ASSERT_TRUE(entry);
     EXPECT_EQ(entry->name, "xyz.openbmc_project.Power.Fault");
     EXPECT_EQ(entry->subsystem, 0x61);
@@ -180,7 +213,7 @@
 
     Registry registry{path};
 
-    EXPECT_FALSE(registry.lookup("foo"));
+    EXPECT_FALSE(registry.lookup("foo", LookupType::name));
 }
 
 // Test the helper functions the use the pel_values data.