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/Makefile.include b/test/openpower-pels/Makefile.include
index d9a6375..f824030 100644
--- a/test/openpower-pels/Makefile.include
+++ b/test/openpower-pels/Makefile.include
@@ -5,6 +5,7 @@
 	ascii_string_test \
 	bcd_time_test \
 	failing_mtms_test \
+	fru_identity_test \
 	generic_section_test \
 	log_id_test \
 	mtms_test \
@@ -199,3 +200,11 @@
 	$(test_ldadd) \
 	$(top_builddir)/extensions/openpower-pels/ascii_string.o
 ascii_string_test_LDFLAGS = $(test_ldflags)
+
+fru_identity_test_SOURCES = %reldir%/fru_identity_test.cpp
+fru_identity_test_CPPFLAGS = $(test_cppflags)
+fru_identity_test_CXXFLAGS = $(test_cxxflags)
+fru_identity_test_LDADD = \
+	$(test_ldadd) \
+	$(top_builddir)/extensions/openpower-pels/fru_identity.o
+fru_identity_test_LDFLAGS = $(test_ldflags)
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);
+}