PEL: FRU identity SRC substructure

This substructure is part of the callout subsection in the SRC
section of a PEL, and contains information about the FRU (Field
Replaceable Unit) being called out.

This includes:
* The specific type of FRU (see the flags field definitions)
* The FRU part number
* The FRU CCIN value (CCIN = a keyword in VPD).
* The FRU serial number

Instead of just calling out a FRU, this structure can instead be used to
call out a maintenance procedure, which is a string that is used as
a key into the service documentation that maps to a procedure to fix
the problem.

This commit only adds support for creating an object from a flattened PEL,
such as one that comes down from the host.  A future commit will handle
creating it from scratch for BMC errors.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ic2b9489abea48084116bf2f450bd293c2d655979
diff --git a/test/openpower-pels/fru_identity_test.cpp b/test/openpower-pels/fru_identity_test.cpp
new file mode 100644
index 0000000..e985b80
--- /dev/null
+++ b/test/openpower-pels/fru_identity_test.cpp
@@ -0,0 +1,74 @@
+#include "extensions/openpower-pels/fru_identity.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace openpower::pels;
+using namespace openpower::pels::src;
+
+// Unflatten a FRUIdentity that is a HW FRU callout
+TEST(FRUIdentityTest, TestHardwareFRU)
+{
+    // Has PN, SN, CCIN
+    std::vector<uint8_t> data{'I', 'D', 0x1C, 0x1D, // type, size, flags
+                              '1', '2', '3',  '4',  // PN
+                              '5', '6', '7',  0x00, 'A', 'A', 'A', 'A', // CCIN
+                              '1', '2', '3',  '4',  '5', '6', '7', '8', // SN
+                              '9', 'A', 'B',  'C'};
+
+    Stream stream{data};
+
+    FRUIdentity fru{stream};
+
+    EXPECT_EQ(fru.failingComponentType(), FRUIdentity::hardwareFRU);
+    EXPECT_EQ(fru.flattenedSize(), data.size());
+
+    EXPECT_EQ(fru.getPN().value(), "1234567");
+    EXPECT_EQ(fru.getCCIN().value(), "AAAA");
+    EXPECT_EQ(fru.getSN().value(), "123456789ABC");
+    EXPECT_FALSE(fru.getMaintProc());
+
+    // Flatten
+    std::vector<uint8_t> newData;
+    Stream newStream{newData};
+    fru.flatten(newStream);
+    EXPECT_EQ(data, newData);
+}
+
+// Unflatten a FRUIdentity that is a Maintenance Procedure callout
+TEST(FRUIdentityTest, TestMaintProcedure)
+{
+    // Only contains the maintenance procedure
+    std::vector<uint8_t> data{
+        0x49, 0x44, 0x0C, 0x42,                     // type, size, flags
+        '1',  '2',  '3',  '4',  '5', '6', '7', 0x00 // Procedure
+    };
+
+    Stream stream{data};
+
+    FRUIdentity fru{stream};
+
+    EXPECT_EQ(fru.failingComponentType(), FRUIdentity::maintenanceProc);
+    EXPECT_EQ(fru.flattenedSize(), data.size());
+
+    EXPECT_EQ(fru.getMaintProc().value(), "1234567");
+    EXPECT_FALSE(fru.getPN());
+    EXPECT_FALSE(fru.getCCIN());
+    EXPECT_FALSE(fru.getSN());
+
+    // Flatten
+    std::vector<uint8_t> newData;
+    Stream newStream{newData};
+    fru.flatten(newStream);
+    EXPECT_EQ(data, newData);
+}
+
+// Try to unflatten garbage data
+TEST(FRUIdentityTest, BadDataTest)
+{
+    std::vector<uint8_t> data{0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+                              0xFF, 0xFF, 0xFF, 0xFF};
+
+    Stream stream{data};
+
+    EXPECT_THROW(FRUIdentity fru{stream}, std::out_of_range);
+}