peltool: Print the Words6To9 'Description' field

Include the 'Description' field from the Words6To9 registry entry when printing
SRC error details.

Changed from this:

"Error Details": {
    "Message":              "There was a failure when reading a sensor device",
    "CALLOUT_ERRNO":        "0x5"
}

to this:

"Error Details": {
    "Message":              "There was a failure when reading a sensor device",
    "CALLOUT_ERRNO": [
                            "0x5",
                            "errno of the failure"
    ]
}

Signed-off-by: Harisuddin Mohamed Isa <harisuddin@gmail.com>
Change-Id: Icc107b0516062eb891f14f3ff3f3cffd316c6d77
diff --git a/extensions/openpower-pels/registry.cpp b/extensions/openpower-pels/registry.cpp
index c8f10d7..755e829 100644
--- a/extensions/openpower-pels/registry.cpp
+++ b/extensions/openpower-pels/registry.cpp
@@ -15,6 +15,7 @@
  */
 #include "registry.hpp"
 
+#include "json_utils.hpp"
 #include "pel_types.hpp"
 #include "pel_values.hpp"
 
@@ -220,8 +221,9 @@
         }
 
         auto attributes = word.value();
-        std::string adPropName = attributes["AdditionalDataPropSource"];
-        hexwordFields[wordNum] = std::move(adPropName);
+        std::tuple<std::string, std::string> adPropSourceDesc(
+            attributes["AdditionalDataPropSource"], attributes["Description"]);
+        hexwordFields[wordNum] = std::move(adPropSourceDesc);
     }
 
     if (!hexwordFields.empty())
diff --git a/extensions/openpower-pels/registry.hpp b/extensions/openpower-pels/registry.hpp
index 7a13b58..180090c 100644
--- a/extensions/openpower-pels/registry.hpp
+++ b/extensions/openpower-pels/registry.hpp
@@ -99,10 +99,13 @@
      *        SRC hexwords.
      *
      * For example, if the AdditionalData event log property contained
-     * "CHIPNUM=42" and this map contained {6, CHIPNUM}, then the code
-     * would put 42 into SRC hexword 6.
+     * "CHIPNUM=42" and this map contained {6, {"CHIPNUM", "DESC"}}, then the
+     * code would put 42 into SRC hexword 6.
+     *
+     * AdditionalDataField specifies two fields from the SRC entry in the
+     * message registry: "AdditionalDataPropSource" and "Description"
      */
-    using AdditionalDataField = std::string;
+    using AdditionalDataField = std::tuple<std::string, std::string>;
     std::optional<std::map<WordNum, AdditionalDataField>> hexwordADFields;
 
     SRC() : type(0), reasonCode(0)
diff --git a/extensions/openpower-pels/src.cpp b/extensions/openpower-pels/src.cpp
index 643adec..5f6f121 100644
--- a/extensions/openpower-pels/src.cpp
+++ b/extensions/openpower-pels/src.cpp
@@ -342,8 +342,8 @@
         return;
     }
 
-    // Save the AdditionalData value corresponding to the
-    // adName key in _hexData[wordNum].
+    // Save the AdditionalData value corresponding to the first element of
+    // adName tuple into _hexData[wordNum].
     for (const auto& [wordNum, adName] : *regEntry.src.hexwordADFields)
     {
         // Can only set words 6 - 9
@@ -355,7 +355,7 @@
             continue;
         }
 
-        auto value = ad.getValue(adName);
+        auto value = ad.getValue(std::get<0>(adName));
         if (value)
         {
             _hexData[getWordIndexFromWordNum(wordNum)] =
@@ -363,8 +363,8 @@
         }
         else
         {
-            std::string msg =
-                "Source for user data SRC word not found: " + adName;
+            std::string msg = "Source for user data SRC word not found: " +
+                              std::get<0>(adName);
             addDebugData(msg);
         }
     }
@@ -454,15 +454,17 @@
             }
             if (entry->src.hexwordADFields)
             {
-                std::map<size_t, std::string> adFields =
-                    entry->src.hexwordADFields.value();
+                std::map<size_t, std::tuple<std::string, std::string>>
+                    adFields = entry->src.hexwordADFields.value();
                 for (const auto& hexwordMap : adFields)
                 {
-                    jsonInsert(errorOut, hexwordMap.second,
-                               getNumberString("0x%X",
-                                               _hexData[getWordIndexFromWordNum(
-                                                   hexwordMap.first)]),
-                               2);
+                    std::vector<std::string> valueDescr;
+                    valueDescr.push_back(getNumberString(
+                        "0x%X",
+                        _hexData[getWordIndexFromWordNum(hexwordMap.first)]));
+                    valueDescr.push_back(std::get<1>(hexwordMap.second));
+                    jsonInsertArray(errorOut, std::get<0>(hexwordMap.second),
+                                    valueDescr, 2);
                 }
             }
             errorOut.erase(errorOut.size() - 2);
diff --git a/test/openpower-pels/Makefile.include b/test/openpower-pels/Makefile.include
index a098ad9..d250b77 100644
--- a/test/openpower-pels/Makefile.include
+++ b/test/openpower-pels/Makefile.include
@@ -183,7 +183,8 @@
 	$(test_ldadd) \
 	$(pel_test_utils_ldadd) \
 	$(top_builddir)/extensions/openpower-pels/registry.o \
-	$(top_builddir)/extensions/openpower-pels/pel_values.o
+	$(top_builddir)/extensions/openpower-pels/pel_values.o \
+	$(top_builddir)/extensions/openpower-pels/json_utils.o
 registry_test_LDFLAGS = $(test_ldflags)
 
 severity_test_SOURCES = %reldir%/severity_test.cpp
diff --git a/test/openpower-pels/registry_test.cpp b/test/openpower-pels/registry_test.cpp
index 08eefc4..2b5e482 100644
--- a/test/openpower-pels/registry_test.cpp
+++ b/test/openpower-pels/registry_test.cpp
@@ -76,13 +76,13 @@
                 {
                     "6":
                     {
-                        "description": "Failing unit number",
+                        "Description": "Failing unit number",
                         "AdditionalDataPropSource": "PS_NUM"
                     },
 
                     "7":
                     {
-                        "description": "bad voltage",
+                        "Description": "bad voltage",
                         "AdditionalDataPropSource": "VOLTAGE"
                     }
                 }
@@ -180,11 +180,11 @@
 
     auto word = (*hexwords).find(6);
     EXPECT_NE(word, (*hexwords).end());
-    EXPECT_EQ(word->second, "PS_NUM");
+    EXPECT_EQ(std::get<0>(word->second), "PS_NUM");
 
     word = (*hexwords).find(7);
     EXPECT_NE(word, (*hexwords).end());
-    EXPECT_EQ(word->second, "VOLTAGE");
+    EXPECT_EQ(std::get<0>(word->second), "VOLTAGE");
 
     auto& sid = entry->src.symptomID;
     EXPECT_TRUE(sid);
@@ -296,6 +296,7 @@
       {
         "8":
         {
+            "Description": "TEST",
             "AdditionalDataPropSource": "TEST"
         }
       }
@@ -311,6 +312,7 @@
       {
         "R":
         {
+            "Description": "TEST",
             "AdditionalDataPropSource": "TEST"
         }
       }
diff --git a/test/openpower-pels/src_test.cpp b/test/openpower-pels/src_test.cpp
index 671bd54..301faac 100644
--- a/test/openpower-pels/src_test.cpp
+++ b/test/openpower-pels/src_test.cpp
@@ -190,11 +190,12 @@
     entry.src.reasonCode = 0xABCD;
     entry.subsystem = 0x42;
     entry.src.powerFault = true;
-    entry.src.hexwordADFields = {{5, "TEST1"}, // Not a user defined word
-                                 {6, "TEST1"},
-                                 {7, "TEST2"},
-                                 {8, "TEST3"},
-                                 {9, "TEST4"}};
+    entry.src.hexwordADFields = {
+        {5, {"TEST1", "DESCR1"}}, // Not a user defined word
+        {6, {"TEST1", "DESCR1"}},
+        {7, {"TEST2", "DESCR2"}},
+        {8, {"TEST3", "DESCR3"}},
+        {9, {"TEST4", "DESCR4"}}};
 
     // Values for the SRC words pointed to above
     std::vector<std::string> adData{"TEST1=0x12345678", "TEST2=12345678",
@@ -315,7 +316,6 @@
         errorDetails.value(),
         "Comp 0x1 failed 0x4 times over 0x1E secs with ErrorCode 0x1ABCDEF");
 }
-
 // Test that an inventory path callout string is
 // converted into the appropriate FRU callout.
 TEST_F(SRCTest, InventoryCalloutTest)
@@ -1300,4 +1300,4 @@
 
     EXPECT_EQ(callout->locationCode(), "UTMS-P1");
     EXPECT_EQ(callout->priority(), 'M');
-}
\ No newline at end of file
+}