psu-ng: Updates to get VPD data to inventory

Add in code to retrieve the VPD data and populate that data to the D-Bus
inventory properties.

Use the PMBus utilities to retrieve the model (CCIN for IBM power
supplies), part number, serial number, and firmware version information
from the sysfs "files" provided via the device driver.

Only build in IBM VPD data collection and reporting if meson ran with
-Dibm-vpd=true.

Tested:
    Copied SDK build of phospor-psu-monitor with -Dibm-vpd=true to
    Rainier hardware system, verified inventory properties updated/added.

Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: I61688b154ead570e9d9390342596bf7d840f4dce
diff --git a/phosphor-power-supply/test/power_supply_tests.cpp b/phosphor-power-supply/test/power_supply_tests.cpp
index 5eb4b3e..55dc2a7 100644
--- a/phosphor-power-supply/test/power_supply_tests.cpp
+++ b/phosphor-power-supply/test/power_supply_tests.cpp
@@ -46,14 +46,40 @@
      * @param[in] i2caddr - The 16-bit I2C address of the power supply
      */
     auto bus = sdbusplus::bus::new_default();
-    EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath))).Times(1);
-    auto psu = std::make_unique<PowerSupply>(bus, PSUInventoryPath, 3, "0068");
 
-    EXPECT_EQ(psu->isPresent(), false);
-    EXPECT_EQ(psu->isFaulted(), false);
-    EXPECT_EQ(psu->hasInputFault(), false);
-    EXPECT_EQ(psu->hasMFRFault(), false);
-    EXPECT_EQ(psu->hasVINUVFault(), false);
+    // Try where inventory path is empty, constructor should fail.
+    try
+    {
+        auto psu = std::make_unique<PowerSupply>(bus, "", 3, "0068");
+        ADD_FAILURE() << "Should not have reached this line.";
+    }
+    catch (const std::invalid_argument& e)
+    {
+        EXPECT_STREQ(e.what(), "Invalid empty inventoryPath");
+    }
+    catch (...)
+    {
+        ADD_FAILURE() << "Should not have caught exception.";
+    }
+
+    // Test with valid arguments
+    try
+    {
+        EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath)))
+            .Times(1);
+        auto psu =
+            std::make_unique<PowerSupply>(bus, PSUInventoryPath, 3, "0068");
+
+        EXPECT_EQ(psu->isPresent(), false);
+        EXPECT_EQ(psu->isFaulted(), false);
+        EXPECT_EQ(psu->hasInputFault(), false);
+        EXPECT_EQ(psu->hasMFRFault(), false);
+        EXPECT_EQ(psu->hasVINUVFault(), false);
+    }
+    catch (...)
+    {
+        ADD_FAILURE() << "Should not have caught exception.";
+    }
 }
 
 TEST_F(PowerSupplyTests, Analyze)
@@ -225,12 +251,47 @@
 TEST_F(PowerSupplyTests, UpdateInventory)
 {
     auto bus = sdbusplus::bus::new_default();
-    EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath)))
-        .Times(1)
-        .WillOnce(Return(true)); // present
-    PowerSupply psu{bus, PSUInventoryPath, 3, "0068"};
-    psu.updateInventory();
-    // TODO: Checks / Story #921
+
+    try
+    {
+        EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath)))
+            .Times(1)
+            .WillOnce(Return(false)); // missing
+        PowerSupply psu{bus, PSUInventoryPath, 3, "0068"};
+        MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
+        // If it is not present, I should not be trying to read a string
+        EXPECT_CALL(mockPMBus, readString(_, _)).Times(0);
+        psu.updateInventory();
+    }
+    catch (...)
+    {
+        ADD_FAILURE() << "Should not have caught exception.";
+    }
+
+    try
+    {
+        EXPECT_CALL(mockedUtil, getPresence(_, StrEq(PSUInventoryPath)))
+            .Times(1)
+            .WillOnce(Return(true)); // present
+        PowerSupply psu{bus, PSUInventoryPath, 13, "0069"};
+        MockedPMBus& mockPMBus = static_cast<MockedPMBus&>(psu.getPMBus());
+        EXPECT_CALL(mockPMBus, readString(_, _)).WillRepeatedly(Return(""));
+        psu.updateInventory();
+
+        EXPECT_CALL(mockPMBus, readString(_, _))
+            .WillOnce(Return("CCIN"))
+            .WillOnce(Return("PN3456"))
+            .WillOnce(Return("FN3456"))
+            .WillOnce(Return("HEADER"))
+            .WillOnce(Return("SN3456"))
+            .WillOnce(Return("FW3456"));
+        psu.updateInventory();
+        // TODO: D-Bus mocking to verify values stored on D-Bus (???)
+    }
+    catch (...)
+    {
+        ADD_FAILURE() << "Should not have caught exception.";
+    }
 }
 
 TEST_F(PowerSupplyTests, IsPresent)