regulators: Implement log_phase_fault action

Implement the new log_phase_fault action in the JSON configuration file.

Create gtests to test the new class.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I53130b029967d0a0d7b7fdd9b12f69035b9f085e
diff --git a/phosphor-regulators/test/actions/log_phase_fault_action_tests.cpp b/phosphor-regulators/test/actions/log_phase_fault_action_tests.cpp
new file mode 100644
index 0000000..74cf11a
--- /dev/null
+++ b/phosphor-regulators/test/actions/log_phase_fault_action_tests.cpp
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+#include "action_environment.hpp"
+#include "id_map.hpp"
+#include "log_phase_fault_action.hpp"
+#include "mock_services.hpp"
+#include "phase_fault.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::power::regulators;
+
+TEST(LogPhaseFaultActionTests, Constructor)
+{
+    LogPhaseFaultAction action{PhaseFaultType::n};
+    EXPECT_EQ(action.getType(), PhaseFaultType::n);
+}
+
+TEST(LogPhaseFaultActionTests, Execute)
+{
+    // Test with "n" phase fault type
+    {
+        IDMap idMap{};
+        MockServices services{};
+        ActionEnvironment env{idMap, "", services};
+        EXPECT_EQ(env.getPhaseFaults().size(), 0);
+
+        LogPhaseFaultAction action{PhaseFaultType::n};
+        EXPECT_EQ(action.execute(env), true);
+
+        EXPECT_EQ(env.getPhaseFaults().size(), 1);
+        EXPECT_EQ(env.getPhaseFaults().count(PhaseFaultType::n), 1);
+    }
+
+    // Test with "n+1" phase fault type
+    {
+        IDMap idMap{};
+        MockServices services{};
+        ActionEnvironment env{idMap, "", services};
+        EXPECT_EQ(env.getPhaseFaults().size(), 0);
+
+        LogPhaseFaultAction action{PhaseFaultType::n_plus_1};
+        EXPECT_EQ(action.execute(env), true);
+
+        EXPECT_EQ(env.getPhaseFaults().size(), 1);
+        EXPECT_EQ(env.getPhaseFaults().count(PhaseFaultType::n_plus_1), 1);
+    }
+}
+
+TEST(LogPhaseFaultActionTests, GetType)
+{
+    LogPhaseFaultAction action{PhaseFaultType::n_plus_1};
+    EXPECT_EQ(action.getType(), PhaseFaultType::n_plus_1);
+}
+
+TEST(LogPhaseFaultActionTests, ToString)
+{
+    LogPhaseFaultAction action{PhaseFaultType::n_plus_1};
+    EXPECT_EQ(action.toString(), "log_phase_fault: { type: n+1 }");
+}
diff --git a/phosphor-regulators/test/meson.build b/phosphor-regulators/test/meson.build
index 897e540..57200a4 100644
--- a/phosphor-regulators/test/meson.build
+++ b/phosphor-regulators/test/meson.build
@@ -40,6 +40,7 @@
     'actions/i2c_write_byte_action_tests.cpp',
     'actions/i2c_write_bytes_action_tests.cpp',
     'actions/if_action_tests.cpp',
+    'actions/log_phase_fault_action_tests.cpp',
     'actions/not_action_tests.cpp',
     'actions/or_action_tests.cpp',
     'actions/pmbus_read_sensor_action_tests.cpp',