regulators: Add VPD service

The regulators application needs to obtain VPD (Vital Product Data)
keyword values.

Sometimes regulator configuration and monitoring varies depending on
hardware type or version.  VPD keyword values can provide this
information about the hardware.

Add a new class to obtain hardware VPD from the D-Bus
xyz.openbmc_project.Inventory.Decorator.Asset interface.

Also define an abstract base class and a mock implementation to
enable use of gmock in test cases related to VPD.

Tested:
* Verified VPD values were successfully obtained from D-Bus.
* Verified VPD values were cached.
* Tested where object path was invalid.
* Tested where keyword was invalid.
* Verified cached VPD values were cleared when machine powered on.
* For the complete test plan, see
  https://gist.github.com/smccarney/519a54353361e28b1d25f5783c15f471

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Id08e8bca8db6421d46669c495e8a9432e45a1fd6
diff --git a/phosphor-regulators/test/mock_services.hpp b/phosphor-regulators/test/mock_services.hpp
index 1ef7192..b121e13 100644
--- a/phosphor-regulators/test/mock_services.hpp
+++ b/phosphor-regulators/test/mock_services.hpp
@@ -20,8 +20,10 @@
 #include "mock_error_logging.hpp"
 #include "mock_journal.hpp"
 #include "mock_presence_service.hpp"
+#include "mock_vpd.hpp"
 #include "presence_service.hpp"
 #include "services.hpp"
+#include "vpd.hpp"
 
 #include <sdbusplus/bus.hpp>
 
@@ -68,6 +70,12 @@
         return presenceService;
     }
 
+    /** @copydoc Services::getVPD() */
+    virtual VPD& getVPD() override
+    {
+        return vpd;
+    }
+
     /**
      * Returns the MockErrorLogging object that implements the ErrorLogging
      * interface.
@@ -106,6 +114,18 @@
         return presenceService;
     }
 
+    /**
+     * Returns the MockVPD object that implements the VPD interface.
+     *
+     * This allows test cases to use the object in EXPECT_CALL() statements.
+     *
+     * @return mock VPD interface object
+     */
+    virtual MockVPD& getMockVPD()
+    {
+        return vpd;
+    }
+
   private:
     /**
      * D-Bus bus object.
@@ -126,6 +146,11 @@
      * Mock implementation of the PresenceService interface.
      */
     MockPresenceService presenceService{};
+
+    /**
+     * Mock implementation of the VPD interface.
+     */
+    MockVPD vpd{};
 };
 
 } // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/test/mock_vpd.hpp b/phosphor-regulators/test/mock_vpd.hpp
new file mode 100644
index 0000000..9b0d494
--- /dev/null
+++ b/phosphor-regulators/test/mock_vpd.hpp
@@ -0,0 +1,48 @@
+/**
+ * Copyright © 2021 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "vpd.hpp"
+
+#include <gmock/gmock.h>
+
+namespace phosphor::power::regulators
+{
+
+/**
+ * @class MockVPD
+ *
+ * Mock implementation of the VPD interface.
+ */
+class MockVPD : public VPD
+{
+  public:
+    // Specify which compiler-generated methods we want
+    MockVPD() = default;
+    MockVPD(const MockVPD&) = delete;
+    MockVPD(MockVPD&&) = delete;
+    MockVPD& operator=(const MockVPD&) = delete;
+    MockVPD& operator=(MockVPD&&) = delete;
+    virtual ~MockVPD() = default;
+
+    MOCK_METHOD(void, clearCache, (), (override));
+
+    MOCK_METHOD(std::string, getValue,
+                (const std::string& inventoryPath, const std::string& keyword),
+                (override));
+};
+
+} // namespace phosphor::power::regulators