regulators: Add PhaseFaultDetection to Device

Add a PhaseFaultDetection data member to the Device class.  This is the
first step in enabling phase fault detection for Device objects.

Create and modify gtest test cases to exercise new code.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Icc771eda5c79ace854acb1d7c395b82b34213996
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 430d490..619a8b6 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -394,6 +394,20 @@
         ++propertyCount;
     }
 
+    // Optional phase_fault_detection property
+    std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{};
+    auto phaseFaultDetectionIt = element.find("phase_fault_detection");
+    if (phaseFaultDetectionIt != element.end())
+    {
+        if (!isRegulator)
+        {
+            throw std::invalid_argument{"Invalid phase_fault_detection "
+                                        "property when is_regulator is false"};
+        }
+        phaseFaultDetection = parsePhaseFaultDetection(*phaseFaultDetectionIt);
+        ++propertyCount;
+    }
+
     // Optional rails property
     std::vector<std::unique_ptr<Rail>> rails{};
     auto railsIt = element.find("rails");
@@ -411,10 +425,10 @@
     // Verify no invalid properties exist
     verifyPropertyCount(element, propertyCount);
 
-    return std::make_unique<Device>(id, isRegulator, fru,
-                                    std::move(i2cInterface),
-                                    std::move(presenceDetection),
-                                    std::move(configuration), std::move(rails));
+    return std::make_unique<Device>(
+        id, isRegulator, fru, std::move(i2cInterface),
+        std::move(presenceDetection), std::move(configuration),
+        std::move(phaseFaultDetection), std::move(rails));
 }
 
 std::vector<std::unique_ptr<Device>> parseDeviceArray(const json& element)
diff --git a/phosphor-regulators/src/device.hpp b/phosphor-regulators/src/device.hpp
index 4937567..a8f35b6 100644
--- a/phosphor-regulators/src/device.hpp
+++ b/phosphor-regulators/src/device.hpp
@@ -18,6 +18,7 @@
 #include "configuration.hpp"
 #include "i2c_interface.hpp"
 #include "id_map.hpp"
+#include "phase_fault_detection.hpp"
 #include "presence_detection.hpp"
 #include "rail.hpp"
 #include "services.hpp"
@@ -60,6 +61,7 @@
      * @param presenceDetection presence detection for this device, if any
      * @param configuration configuration changes to apply to this device, if
      *                      any
+     * @param phaseFaultDetection phase fault detection for this device, if any
      * @param rails voltage rails produced by this device, if any
      */
     explicit Device(
@@ -67,13 +69,16 @@
         std::unique_ptr<i2c::I2CInterface> i2cInterface,
         std::unique_ptr<PresenceDetection> presenceDetection = nullptr,
         std::unique_ptr<Configuration> configuration = nullptr,
+        std::unique_ptr<PhaseFaultDetection> phaseFaultDetection = nullptr,
         std::vector<std::unique_ptr<Rail>> rails =
             std::vector<std::unique_ptr<Rail>>{}) :
         id{id},
         isRegulatorDevice{isRegulator}, fru{fru},
         i2cInterface{std::move(i2cInterface)}, presenceDetection{std::move(
                                                    presenceDetection)},
-        configuration{std::move(configuration)}, rails{std::move(rails)}
+        configuration{std::move(configuration)},
+        phaseFaultDetection{std::move(phaseFaultDetection)}, rails{std::move(
+                                                                 rails)}
     {
     }
 
@@ -173,6 +178,17 @@
     }
 
     /**
+     * Returns the phase fault detection for this device, if any.
+     *
+     * @return Pointer to PhaseFaultDetection object.  Will equal nullptr if no
+     *         phase fault detection is defined for this device.
+     */
+    const std::unique_ptr<PhaseFaultDetection>& getPhaseFaultDetection() const
+    {
+        return phaseFaultDetection;
+    }
+
+    /**
      * Returns the presence detection for this device, if any.
      *
      * @return Pointer to PresenceDetection object.  Will equal nullptr if no
@@ -271,6 +287,12 @@
     std::unique_ptr<Configuration> configuration{};
 
     /**
+     * Phase fault detection for this device, if any.  Set to nullptr if no
+     * phase fault detection is defined for this device.
+     */
+    std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{};
+
+    /**
      * Voltage rails produced by this device, if any.  Vector is empty if no
      * voltage rails are defined for this device.
      */