Export the part number and serial number

This commit exposes the eMMC's part name and serial number over the
appropriate D-Bus interface, so that it can be exposed over Redfish in
bmcweb.

Tested:
$ busctl introspect xyz.openbmc_project.eStoraged \
  /xyz/openbmc_project/inventory/storage/mmcblk0
  ...
  xyz.openbmc_project.Inventory.Decorator.Asset    interface -         -                                        -
.PartNumber                                      property  s         "ABCDEF"                                 emits-change
.SerialNumber                                    property  s         "123456abcd"                             emits-change
  ...
$ wget -qO- http://localhost:80/redfish/v1/Chassis/DC_SCM/Drives/mmcblk0
{
  "@odata.id": "/redfish/v1/Chassis/DC_SCM/Drives/mmcblk0",
  "@odata.type": "#Drive.v1_7_0.Drive",
  "CapacityBytes": 15634268160,
  "Id": "mmcblk0",
  "Links": {
    "Chassis": {
      "@odata.id": "/redfish/v1/Chassis/DC_SCM"
    }
  },
  "Name": "Name",
  "PartNumber": "ABCDEF",
  "PhysicalLocation": {
    "PartLocation": {
      "LocationType": "Embedded"
    }
  },
  "SerialNumber": "123456abcd",
  "Status": {
    "State": "Enabled"
  }
}

Signed-off-by: John Wedig <johnwedig@google.com>
Change-Id: I1d17f08b99907620b5f2c73fdaeacc84950ce64e
diff --git a/src/test/util_test.cpp b/src/test/util_test.cpp
index 9059d76..5f16068 100644
--- a/src/test/util_test.cpp
+++ b/src/test/util_test.cpp
@@ -13,6 +13,8 @@
 namespace estoraged_test
 {
 using estoraged::util::findPredictedMediaLifeLeftPercent;
+using estoraged::util::getPartNumber;
+using estoraged::util::getSerialNumber;
 
 TEST(utilTest, passFindPredictedMediaLife)
 {
@@ -24,6 +26,7 @@
     testFile << "0x07 0x04";
     testFile.close();
     EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 40);
+    EXPECT_TRUE(std::filesystem::remove(testFileName));
 }
 
 TEST(utilTest, estimatesSame)
@@ -38,6 +41,7 @@
     testFile.close();
 
     EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 70);
+    EXPECT_TRUE(std::filesystem::remove(testFileName));
 }
 
 TEST(utilTest, estimatesNotAvailable)
@@ -51,6 +55,49 @@
     testFile.close();
 
     EXPECT_EQ(findPredictedMediaLifeLeftPercent(prefixName), 255);
+    EXPECT_TRUE(std::filesystem::remove(testFileName));
+}
+
+TEST(utilTest, getPartNumberFail)
+{
+    std::string prefixName = ".";
+    std::string testFileName = prefixName + "/name";
+    /* The part name file won't exist for this test. */
+    EXPECT_EQ(getPartNumber(prefixName), "unknown");
+}
+
+TEST(utilTest, getPartNumberPass)
+{
+    std::string prefixName = ".";
+    std::string testFileName = prefixName + "/name";
+    std::ofstream testFile;
+    testFile.open(testFileName,
+                  std::ios::out | std::ios::binary | std::ios::trunc);
+    testFile << "ABCD1234";
+    testFile.close();
+    EXPECT_EQ(getPartNumber(prefixName), "ABCD1234");
+    EXPECT_TRUE(std::filesystem::remove(testFileName));
+}
+
+TEST(utilTest, getSerialNumberFail)
+{
+    std::string prefixName = ".";
+    std::string testFileName = prefixName + "/serial";
+    /* The serial number file won't exist for this test. */
+    EXPECT_EQ(getSerialNumber(prefixName), "unknown");
+}
+
+TEST(utilTest, getSerialNumberPass)
+{
+    std::string prefixName = ".";
+    std::string testFileName = prefixName + "/serial";
+    std::ofstream testFile;
+    testFile.open(testFileName,
+                  std::ios::out | std::ios::binary | std::ios::trunc);
+    testFile << "0x12345678";
+    testFile.close();
+    EXPECT_EQ(getSerialNumber(prefixName), "0x12345678");
+    EXPECT_TRUE(std::filesystem::remove(testFileName));
 }
 
 /* Test case where we successfully find the device file. */