PEL: Support user supplied flag to indicate a fatal/terminating

User can supply SEVERITY_DETAIL=SYSTEM_TERM as part
of AdditionalData entry in the event log to set the
severity level in User Header of PEL

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

Change-Id: I9205c084c32576734c2b5b4c79c273f8defde9d4
Signed-off-by: Vijay Lobo <vijaylobo@gmail.com>
diff --git a/test/openpower-pels/user_header_test.cpp b/test/openpower-pels/user_header_test.cpp
index b7b6583..9c38ec1 100644
--- a/test/openpower-pels/user_header_test.cpp
+++ b/test/openpower-pels/user_header_test.cpp
@@ -112,8 +112,9 @@
         regEntry.eventScope = 2;
 
         MockDataInterface dataIface;
+        AdditionalData ad;
 
-        UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error,
+        UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad,
                       dataIface);
 
         ASSERT_TRUE(uh.valid());
@@ -138,7 +139,7 @@
             // then set them to 0xFFFF.
             regEntry.actionFlags = std::nullopt;
 
-            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error,
+            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad,
                           dataIface);
             EXPECT_EQ(uh.actionFlags(), 0xFFFF);
         }
@@ -152,6 +153,8 @@
         regEntry.subsystem = 5;
         regEntry.severity = {{"", 0x20}, {"systemB", 0x10}, {"systemA", 0x00}};
 
+        AdditionalData ad;
+
         MockDataInterface dataIface;
         std::vector<std::string> names1{"systemA"};
         std::vector<std::string> names2{"systemB"};
@@ -163,21 +166,21 @@
             .WillOnce(Return(names3));
 
         {
-            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error,
+            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad,
                           dataIface);
 
             EXPECT_EQ(uh.severity(), 0x00);
         }
 
         {
-            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error,
+            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad,
                           dataIface);
 
             EXPECT_EQ(uh.severity(), 0x10);
         }
 
         {
-            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error,
+            UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad,
                           dataIface);
 
             EXPECT_EQ(uh.severity(), 0x20);
@@ -200,11 +203,58 @@
     // Leave off severity
 
     MockDataInterface dataIface;
+    AdditionalData ad;
 
-    UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, dataIface);
+    UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad,
+                  dataIface);
     ASSERT_EQ(uh.severity(), 0x40);
 }
 
+// Test that the critical severity comes from the event log if not
+// in the message registry
+TEST(UserHeaderTest, UseEventLogSevCritTest)
+{
+    using namespace openpower::pels::message;
+    Entry regEntry;
+
+    regEntry.name = "test";
+    regEntry.subsystem = 5;
+    regEntry.actionFlags = 0xC000;
+    regEntry.eventType = 1;
+    regEntry.eventScope = 2;
+    // Leave off severity
+
+    MockDataInterface dataIface;
+    AdditionalData ad;
+
+    UserHeader uh(regEntry, phosphor::logging::Entry::Level::Critical, ad,
+                  dataIface);
+    ASSERT_EQ(uh.severity(), 0x50);
+}
+
+// Test that the critical severity comes from the event log if not
+// in the message registry and termination condition is set
+TEST(UserHeaderTest, UseEventLogSevCritTermTest)
+{
+    using namespace openpower::pels::message;
+    Entry regEntry;
+
+    regEntry.name = "test";
+    regEntry.subsystem = 5;
+    regEntry.actionFlags = 0xC000;
+    regEntry.eventType = 1;
+    regEntry.eventScope = 2;
+    // Leave off severity
+
+    MockDataInterface dataIface;
+    std::vector<std::string> adData{"SEVERITY_DETAIL=SYSTEM_TERM"};
+    AdditionalData ad{adData};
+
+    UserHeader uh(regEntry, phosphor::logging::Entry::Level::Critical, ad,
+                  dataIface);
+    ASSERT_EQ(uh.severity(), 0x51);
+}
+
 // Test that the optional event type & scope fields work
 TEST(UserHeaderTest, DefaultEventTypeScopeTest)
 {
@@ -217,8 +267,10 @@
     regEntry.actionFlags = 0xC000;
 
     MockDataInterface dataIface;
+    AdditionalData ad;
 
-    UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, dataIface);
+    UserHeader uh(regEntry, phosphor::logging::Entry::Level::Error, ad,
+                  dataIface);
 
     ASSERT_EQ(uh.eventType(), 0);
     ASSERT_EQ(uh.scope(), 0x03);