regulators: Add phase_fault_detection to parser

Enhance the JSON configuration file parser to support the new
phase_fault_detection object.

Add gtest test cases to exercise new code.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I5b987054ef35c8b27d7d984e5e9ec9b4488bf944
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index 6527b5f..430d490 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -759,6 +759,38 @@
     return std::make_unique<OrAction>(std::move(actions));
 }
 
+std::unique_ptr<PhaseFaultDetection>
+    parsePhaseFaultDetection(const json& element)
+{
+    verifyIsObject(element);
+    unsigned int propertyCount{0};
+
+    // Optional comments property; value not stored
+    if (element.contains("comments"))
+    {
+        ++propertyCount;
+    }
+
+    // Optional device_id property
+    std::string deviceID{};
+    auto deviceIDIt = element.find("device_id");
+    if (deviceIDIt != element.end())
+    {
+        deviceID = parseString(*deviceIDIt);
+        ++propertyCount;
+    }
+
+    // Required rule_id or actions property
+    std::vector<std::unique_ptr<Action>> actions{};
+    actions = parseRuleIDOrActionsProperty(element);
+    ++propertyCount;
+
+    // Verify no invalid properties exist
+    verifyPropertyCount(element, propertyCount);
+
+    return std::make_unique<PhaseFaultDetection>(std::move(actions), deviceID);
+}
+
 PhaseFaultType parsePhaseFaultType(const json& element)
 {
     std::string value = parseString(element);
diff --git a/phosphor-regulators/src/config_file_parser.hpp b/phosphor-regulators/src/config_file_parser.hpp
index 63c8bf8..05c5b60 100644
--- a/phosphor-regulators/src/config_file_parser.hpp
+++ b/phosphor-regulators/src/config_file_parser.hpp
@@ -35,6 +35,7 @@
 #include "not_action.hpp"
 #include "or_action.hpp"
 #include "phase_fault.hpp"
+#include "phase_fault_detection.hpp"
 #include "pmbus_read_sensor_action.hpp"
 #include "pmbus_write_vout_command_action.hpp"
 #include "presence_detection.hpp"
@@ -256,7 +257,7 @@
     parseCompareVPD(const nlohmann::json& element);
 
 /**
- * Parses a JSON element containing a configuration.
+ * Parses a JSON element containing a configuration object.
  *
  * Returns the corresponding C++ Configuration object.
  *
@@ -554,6 +555,19 @@
 std::unique_ptr<OrAction> parseOr(const nlohmann::json& element);
 
 /**
+ * Parses a JSON element containing a phase_fault_detection object.
+ *
+ * Returns the corresponding C++ PhaseFaultDetection object.
+ *
+ * Throws an exception if parsing fails.
+ *
+ * @param element JSON element
+ * @return PhaseFaultDetection object
+ */
+std::unique_ptr<PhaseFaultDetection>
+    parsePhaseFaultDetection(const nlohmann::json& element);
+
+/**
  * Parses a JSON element containing a PhaseFaultType expressed as a string.
  *
  * Returns the corresponding PhaseFaultType enum value.
@@ -592,7 +606,7 @@
     parsePMBusWriteVoutCommand(const nlohmann::json& element);
 
 /**
- * Parses a JSON element containing a presence detection operation.
+ * Parses a JSON element containing a presence_detection object.
  *
  * Returns the corresponding C++ PresenceDetection object.
  *
@@ -713,7 +727,7 @@
     parseSensorDataFormat(const nlohmann::json& element);
 
 /**
- * Parses a JSON element containing a sensor monitoring operation.
+ * Parses a JSON element containing a sensor_monitoring object.
  *
  * Returns the corresponding C++ SensorMonitoring object.
  *