PEL: Add function to get PEL size

Add a size() function to the PEL class that adds up the size fields
in the header of every PEL section.

This required a fix to some testcases where the size field was wrong in
a header.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I0d70deae116cd3835f2c0ab34e13811da471fb14
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index 262865f..d1c9620 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -153,6 +153,28 @@
     return pelData;
 }
 
+size_t PEL::size() const
+{
+    size_t size = 0;
+
+    if (_ph)
+    {
+        size += _ph->header().size;
+    }
+
+    if (_uh)
+    {
+        size += _uh->header().size;
+    }
+
+    for (const auto& section : _optionalSections)
+    {
+        size += section->header().size;
+    }
+
+    return size;
+}
+
 std::optional<SRC*> PEL::primarySRC() const
 {
     auto src = std::find_if(
diff --git a/extensions/openpower-pels/pel.hpp b/extensions/openpower-pels/pel.hpp
index ccbef91..c3c9f5a 100644
--- a/extensions/openpower-pels/pel.hpp
+++ b/extensions/openpower-pels/pel.hpp
@@ -198,6 +198,13 @@
     std::vector<uint8_t> data() const;
 
     /**
+     * @brief Returns the size of the PEL
+     *
+     * @return size_t The PEL size in bytes
+     */
+    size_t size() const;
+
+    /**
      * @brief Says if the PEL is valid (the sections are all valid)
      *
      * @return bool - if the PEL is valid
diff --git a/test/openpower-pels/pel_test.cpp b/test/openpower-pels/pel_test.cpp
index afab5ca..995f780 100644
--- a/test/openpower-pels/pel_test.cpp
+++ b/test/openpower-pels/pel_test.cpp
@@ -34,7 +34,6 @@
 TEST_F(PELTest, FlattenTest)
 {
     auto data = pelDataFactory(TestPELType::pelSimple);
-    auto origData = data;
     auto pel = std::make_unique<PEL>(data);
 
     // Check a few fields
@@ -46,7 +45,8 @@
 
     // Test that data in == data out
     auto flattenedData = pel->data();
-    ASSERT_EQ(origData, flattenedData);
+    EXPECT_EQ(data, flattenedData);
+    EXPECT_EQ(flattenedData.size(), pel->size());
 }
 
 TEST_F(PELTest, CommitTimeTest)
@@ -58,12 +58,12 @@
     pel->setCommitTime();
     auto newTime = pel->commitTime();
 
-    ASSERT_NE(origTime, newTime);
+    EXPECT_NE(origTime, newTime);
 
     // Make a new PEL and check new value is still there
     auto newData = pel->data();
     auto newPel = std::make_unique<PEL>(newData);
-    ASSERT_EQ(newTime, newPel->commitTime());
+    EXPECT_EQ(newTime, newPel->commitTime());
 }
 
 TEST_F(PELTest, AssignIDTest)
@@ -75,12 +75,12 @@
     pel->assignID();
     auto newID = pel->id();
 
-    ASSERT_NE(origID, newID);
+    EXPECT_NE(origID, newID);
 
     // Make a new PEL and check new value is still there
     auto newData = pel->data();
     auto newPel = std::make_unique<PEL>(newData);
-    ASSERT_EQ(newID, newPel->id());
+    EXPECT_EQ(newID, newPel->id());
 }
 
 TEST_F(PELTest, WithLogIDTest)
diff --git a/test/openpower-pels/pel_utils.cpp b/test/openpower-pels/pel_utils.cpp
index 18095a1..4560b2f 100644
--- a/test/openpower-pels/pel_utils.cpp
+++ b/test/openpower-pels/pel_utils.cpp
@@ -66,7 +66,7 @@
 const std::vector<uint8_t> srcSectionNoCallouts{
 
     // Header
-    'P', 'S', 0x00, 0x80, 0x01, 0x01, 0x02, 0x02,
+    'P', 'S', 0x00, 0x50, 0x01, 0x01, 0x02, 0x02,
 
     0x02, 0x00, 0x00, // version, flags, reserved
     0x09, 0x00, 0x00, // hex word count, reserved2B
diff --git a/test/openpower-pels/real_pel_test.cpp b/test/openpower-pels/real_pel_test.cpp
index 1846239..a170812 100644
--- a/test/openpower-pels/real_pel_test.cpp
+++ b/test/openpower-pels/real_pel_test.cpp
@@ -548,6 +548,7 @@
     // Check that the flat data is correct
     auto flat = pel.data();
     EXPECT_EQ(realPELData, flat);
+    EXPECT_EQ(realPELData.size(), pel.size());
 
     // Check that the code can extract an object for every section.
     //(The PrivateHeader and UserHeader account for the + 2 below.)
diff --git a/test/openpower-pels/src_test.cpp b/test/openpower-pels/src_test.cpp
index 2749c37..c1b5116 100644
--- a/test/openpower-pels/src_test.cpp
+++ b/test/openpower-pels/src_test.cpp
@@ -30,7 +30,7 @@
     EXPECT_TRUE(src.valid());
 
     EXPECT_EQ(src.header().id, 0x5053);
-    EXPECT_EQ(src.header().size, 0x80);
+    EXPECT_EQ(src.header().size, 0x50);
     EXPECT_EQ(src.header().version, 0x01);
     EXPECT_EQ(src.header().subType, 0x01);
     EXPECT_EQ(src.header().componentID, 0x0202);