PEL: Support creator supplied power fault flag

User can supply POWER_THERMAL_CRITICAL_FAULT=TRUE as part
of AdditionalData entry in the event log to set the power
fault bit in PEL

Tested: I ran unit test using docker. Also tested manually
by setting D-bus event log

Change-Id: Ifa03f091a7d1efcc67f181c2be1cc0a6240891e1
Signed-off-by: Vijay Lobo <vijaylobo@gmail.com>
diff --git a/extensions/openpower-pels/README.md b/extensions/openpower-pels/README.md
index 3fdb43a..1aba263 100644
--- a/extensions/openpower-pels/README.md
+++ b/extensions/openpower-pels/README.md
@@ -34,6 +34,17 @@
 The code will assign its own error log ID to this PEL, and also update the
 commit timestamp field to the current time.
 
+#### POWER_THERMAL_CRITICAL_FAULT
+
+This keyword is used to set the power fault bit in PEL. The syntax is:
+```
+POWER_THERMAL_CRITICAL_FAULT=<FLAG>
+e.g.
+POWER_THERMAL_CRITICAL_FAULT=TRUE
+```
+
+Note that TRUE is the only value supported.
+
 #### ESEL
 
 This keyword's data contains a full PEL in string format.  This is how hostboot
diff --git a/extensions/openpower-pels/src.cpp b/extensions/openpower-pels/src.cpp
index 9257036..398cfaa 100644
--- a/extensions/openpower-pels/src.cpp
+++ b/extensions/openpower-pels/src.cpp
@@ -291,7 +291,10 @@
     _version = srcVersion;
 
     _flags = 0;
-    if (regEntry.src.powerFault.value_or(false))
+
+    auto item = additionalData.getValue("POWER_THERMAL_CRITICAL_FAULT");
+    if ((regEntry.src.powerFault.value_or(false)) ||
+        (item.value_or("") == "TRUE"))
     {
         _flags |= powerFaultEvent;
     }
diff --git a/test/openpower-pels/src_test.cpp b/test/openpower-pels/src_test.cpp
index 301faac..32facd4 100644
--- a/test/openpower-pels/src_test.cpp
+++ b/test/openpower-pels/src_test.cpp
@@ -252,6 +252,29 @@
     EXPECT_FALSE(newSRC.callouts());
 }
 
+// Create an SRC to test POWER_THERMAL_CRITICAL_FAULT set to TRUE
+// sets the power fault bit in SRC
+TEST_F(SRCTest, PowerFaultTest)
+{
+    message::Entry entry;
+    entry.src.type = 0xBD;
+    entry.src.reasonCode = 0xABCD;
+    entry.subsystem = 0x42;
+    entry.src.powerFault = false;
+
+    // Values for the SRC words pointed to above
+    std::vector<std::string> adData{"POWER_THERMAL_CRITICAL_FAULT=TRUE",
+                                    "TEST2=12345678", "TEST3=0XDEF", "TEST4=Z"};
+    AdditionalData ad{adData};
+    NiceMock<MockDataInterface> dataIface;
+
+    SRC src{entry, ad, dataIface};
+
+    EXPECT_TRUE(src.valid());
+    EXPECT_TRUE(src.isPowerFaultEvent());
+    EXPECT_EQ(src.size(), baseSRCSize);
+}
+
 // Test when the CCIN string isn't a 4 character number
 TEST_F(SRCTest, BadCCINTest)
 {