regulators: Modify Configuration to use Journal

Modify Configuration::execute() to log messages using
the new Journal interface.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: If7dee12ca064147386fc076223474f004281d7ec
diff --git a/phosphor-regulators/src/chassis.cpp b/phosphor-regulators/src/chassis.cpp
index ebe446c..4a016e6 100644
--- a/phosphor-regulators/src/chassis.cpp
+++ b/phosphor-regulators/src/chassis.cpp
@@ -46,7 +46,8 @@
 void Chassis::configure(Services& services, System& system)
 {
     // Log info message in journal; important for verifying success of boot
-    journal::logInfo("Configuring chassis " + std::to_string(number));
+    services.getJournal().logInfo("Configuring chassis " +
+                                  std::to_string(number));
 
     // Configure devices
     for (std::unique_ptr<Device>& device : devices)
diff --git a/phosphor-regulators/src/configuration.cpp b/phosphor-regulators/src/configuration.cpp
index 8edc36c..81b2c17 100644
--- a/phosphor-regulators/src/configuration.cpp
+++ b/phosphor-regulators/src/configuration.cpp
@@ -21,7 +21,6 @@
 #include "chassis.hpp"
 #include "device.hpp"
 #include "exception_utils.hpp"
-#include "journal.hpp"
 #include "rail.hpp"
 #include "system.hpp"
 
@@ -42,7 +41,7 @@
     execute(services, system, chassis, device, rail.getID());
 }
 
-void Configuration::execute(Services& /*services*/, System& system,
+void Configuration::execute(Services& services, System& system,
                             Chassis& /*chassis*/, Device& device,
                             const std::string& deviceOrRailID)
 {
@@ -54,7 +53,7 @@
         {
             message += ": volts=" + std::to_string(volts.value());
         }
-        journal::logDebug(message);
+        services.getJournal().logDebug(message);
 
         // Create ActionEnvironment
         ActionEnvironment environment{system.getIDMap(), device.getID()};
@@ -69,8 +68,8 @@
     catch (const std::exception& e)
     {
         // Log error messages in journal
-        exception_utils::log(e);
-        journal::logErr("Unable to configure " + deviceOrRailID);
+        services.getJournal().logError(exception_utils::getMessages(e));
+        services.getJournal().logError("Unable to configure " + deviceOrRailID);
 
         // TODO: Create error log entry
     }
diff --git a/phosphor-regulators/test/chassis_tests.cpp b/phosphor-regulators/test/chassis_tests.cpp
index 481d71d..639dc33 100644
--- a/phosphor-regulators/test/chassis_tests.cpp
+++ b/phosphor-regulators/test/chassis_tests.cpp
@@ -181,8 +181,12 @@
 {
     // Test where no devices were specified in constructor
     {
-        // Create mock services.
+        // Create mock services.  Expect logInfo() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logInfo("Configuring chassis 1")).Times(1);
+        EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create Chassis
         std::unique_ptr<Chassis> chassis = std::make_unique<Chassis>(1);
@@ -195,21 +199,23 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Call configure()
-        journal::clear();
         chassisPtr->configure(services, system);
-        EXPECT_EQ(journal::getDebugMessages().size(), 0);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
-        std::vector<std::string> expectedInfoMessages{"Configuring chassis 1"};
-        EXPECT_EQ(journal::getInfoMessages(), expectedInfoMessages);
     }
 
     // Test where devices were specified in constructor
     {
-        // Create mock services.
-        MockServices services{};
-
         std::vector<std::unique_ptr<Device>> devices{};
 
+        // Create mock services.  Expect logInfo() and logDebug() to be called.
+        MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logInfo("Configuring chassis 2")).Times(1);
+        EXPECT_CALL(journal, logDebug("Configuring vdd0_reg: volts=1.300000"))
+            .Times(1);
+        EXPECT_CALL(journal, logDebug("Configuring vdd1_reg: volts=1.200000"))
+            .Times(1);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
+
         // Create Device vdd0_reg
         {
             // Create Configuration
@@ -258,15 +264,7 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Call configure()
-        journal::clear();
         chassisPtr->configure(services, system);
-        std::vector<std::string> expectedDebugMessages{
-            "Configuring vdd0_reg: volts=1.300000",
-            "Configuring vdd1_reg: volts=1.200000"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
-        std::vector<std::string> expectedInfoMessages{"Configuring chassis 2"};
-        EXPECT_EQ(journal::getInfoMessages(), expectedInfoMessages);
     }
 }
 
diff --git a/phosphor-regulators/test/configuration_tests.cpp b/phosphor-regulators/test/configuration_tests.cpp
index 93f1be8..260b638 100644
--- a/phosphor-regulators/test/configuration_tests.cpp
+++ b/phosphor-regulators/test/configuration_tests.cpp
@@ -19,7 +19,6 @@
 #include "device.hpp"
 #include "i2c_interface.hpp"
 #include "i2c_write_byte_action.hpp"
-#include "journal.hpp"
 #include "mock_action.hpp"
 #include "mock_journal.hpp"
 #include "mock_services.hpp"
@@ -43,6 +42,7 @@
 using namespace phosphor::power::regulators;
 using namespace phosphor::power::regulators::pmbus_utils;
 
+using ::testing::A;
 using ::testing::Return;
 using ::testing::Throw;
 using ::testing::TypedEq;
@@ -76,13 +76,16 @@
     }
 }
 
-// Test for execute(System&, Chassis&, Device&)
+// Test for execute(Services&, System&, Chassis&, Device&)
 TEST(ConfigurationTests, ExecuteForDevice)
 {
     // Test where works: Volts value not specified
     {
-        // Create mock services.
+        // Create mock services.  Expect logDebug() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug("Configuring vdd_reg")).Times(1);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
@@ -126,17 +129,17 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Execute Configuration
-        journal::clear();
         configurationPtr->execute(services, system, *chassisPtr, *devicePtr);
-        std::vector<std::string> expectedDebugMessages{"Configuring vdd_reg"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 
     // Test where works: Volts value specified
     {
-        // Create mock services.
+        // Create mock services.  Expect logDebug() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug("Configuring vdd_reg: volts=1.300000"))
+            .Times(1);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create PMBusWriteVoutCommandAction.  Do not specify a volts value
         // because it will get a value of 1.3V from the
@@ -185,18 +188,21 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Execute Configuration
-        journal::clear();
         configurationPtr->execute(services, system, *chassisPtr, *devicePtr);
-        std::vector<std::string> expectedDebugMessages{
-            "Configuring vdd_reg: volts=1.300000"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 
     // Test where fails
     {
-        // Create mock services.
+        // Create mock services.  Expect logDebug() and logError() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        std::vector<std::string> expectedErrMessagesException{
+            "I2CException: Failed to write byte: bus /dev/i2c-1, addr 0x70",
+            "ActionError: i2c_write_byte: { register: 0x7C, value: 0xA, mask: "
+            "0xFF }"};
+        EXPECT_CALL(journal, logDebug("Configuring vdd_reg")).Times(1);
+        EXPECT_CALL(journal, logError(expectedErrMessagesException)).Times(1);
+        EXPECT_CALL(journal, logError("Unable to configure vdd_reg")).Times(1);
 
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
@@ -242,26 +248,20 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Execute Configuration
-        journal::clear();
         configurationPtr->execute(services, system, *chassisPtr, *devicePtr);
-        std::vector<std::string> expectedDebugMessages{"Configuring vdd_reg"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        std::vector<std::string> expectedErrMessages{
-            "I2CException: Failed to write byte: bus /dev/i2c-1, addr 0x70",
-            "ActionError: i2c_write_byte: { register: 0x7C, value: 0xA, mask: "
-            "0xFF }",
-            "Unable to configure vdd_reg"};
-        EXPECT_EQ(journal::getErrMessages(), expectedErrMessages);
     }
 }
 
-// Test for execute(System&, Chassis&, Device&, Rail&)
+// Test for execute(Services&, System&, Chassis&, Device&, Rail&)
 TEST(ConfigurationTests, ExecuteForRail)
 {
     // Test where works: Volts value not specified
     {
-        // Create mock services.
+        // Create mock services.  Expect logDebug() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug("Configuring vio2")).Times(1);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
@@ -313,18 +313,18 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Execute Configuration
-        journal::clear();
         configurationPtr->execute(services, system, *chassisPtr, *devicePtr,
                                   *railPtr);
-        std::vector<std::string> expectedDebugMessages{"Configuring vio2"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 
     // Test where works: Volts value specified
     {
-        // Create mock services.
+        // Create mock services.  Expect logDebug() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug("Configuring vio2: volts=1.300000"))
+            .Times(1);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create PMBusWriteVoutCommandAction.  Do not specify a volts value
         // because it will get a value of 1.3V from the
@@ -381,19 +381,22 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Execute Configuration
-        journal::clear();
         configurationPtr->execute(services, system, *chassisPtr, *devicePtr,
                                   *railPtr);
-        std::vector<std::string> expectedDebugMessages{
-            "Configuring vio2: volts=1.300000"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 
     // Test where fails
     {
-        // Create mock services.
+        // Create mock services.  Expect logDebug() and logError() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        std::vector<std::string> expectedErrMessagesException{
+            "I2CException: Failed to write byte: bus /dev/i2c-1, addr 0x70",
+            "ActionError: i2c_write_byte: { register: 0x7C, value: 0xA, mask: "
+            "0xFF }"};
+        EXPECT_CALL(journal, logDebug("Configuring vio2")).Times(1);
+        EXPECT_CALL(journal, logError(expectedErrMessagesException)).Times(1);
+        EXPECT_CALL(journal, logError("Unable to configure vio2")).Times(1);
 
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
@@ -447,17 +450,8 @@
         System system{std::move(rules), std::move(chassisVec)};
 
         // Execute Configuration
-        journal::clear();
         configurationPtr->execute(services, system, *chassisPtr, *devicePtr,
                                   *railPtr);
-        std::vector<std::string> expectedDebugMessages{"Configuring vio2"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        std::vector<std::string> expectedErrMessages{
-            "I2CException: Failed to write byte: bus /dev/i2c-1, addr 0x70",
-            "ActionError: i2c_write_byte: { register: 0x7C, value: 0xA, mask: "
-            "0xFF }",
-            "Unable to configure vio2"};
-        EXPECT_EQ(journal::getErrMessages(), expectedErrMessages);
     }
 }
 
diff --git a/phosphor-regulators/test/device_tests.cpp b/phosphor-regulators/test/device_tests.cpp
index 47768e2..690a510 100644
--- a/phosphor-regulators/test/device_tests.cpp
+++ b/phosphor-regulators/test/device_tests.cpp
@@ -211,8 +211,11 @@
 {
     // Test where Configuration and Rails were not specified in constructor
     {
-        // Create mock services.
+        // Create mock services.  No logging should occur.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create Device
         std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
@@ -234,20 +237,26 @@
         chassisVec.emplace_back(std::move(chassis));
         System system{std::move(rules), std::move(chassisVec)};
 
-        // Call configure().  Should do nothing.
-        journal::clear();
+        // Call configure().
         devicePtr->configure(services, system, *chassisPtr);
-        EXPECT_EQ(journal::getDebugMessages().size(), 0);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 
     // Test where Configuration and Rails were specified in constructor
     {
-        // Create mock services.
-        MockServices services{};
-
         std::vector<std::unique_ptr<Rail>> rails{};
 
+        // Create mock services.  Expect logDebug() to be called.
+        // For the Device and both Rails, should execute the Configuration
+        // and log a debug message.
+        MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug("Configuring reg1")).Times(1);
+        EXPECT_CALL(journal, logDebug("Configuring vdd0: volts=1.300000"))
+            .Times(1);
+        EXPECT_CALL(journal, logDebug("Configuring vio0: volts=3.200000"))
+            .Times(1);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
+
         // Create Rail vdd0
         {
             // Create Configuration for Rail
@@ -313,15 +322,8 @@
         chassisVec.emplace_back(std::move(chassis));
         System system{std::move(rules), std::move(chassisVec)};
 
-        // Call configure().  For the Device and both Rails, should execute the
-        // Configuration and log a debug message.
-        journal::clear();
+        // Call configure().
         devicePtr->configure(services, system, *chassisPtr);
-        std::vector<std::string> expectedDebugMessages{
-            "Configuring reg1", "Configuring vdd0: volts=1.300000",
-            "Configuring vio0: volts=3.200000"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 }
 
diff --git a/phosphor-regulators/test/rail_tests.cpp b/phosphor-regulators/test/rail_tests.cpp
index d8524dc..190e48e 100644
--- a/phosphor-regulators/test/rail_tests.cpp
+++ b/phosphor-regulators/test/rail_tests.cpp
@@ -87,8 +87,11 @@
 {
     // Test where Configuration was not specified in constructor
     {
-        // Create mock services.
+        // Create mock services.  No logging should occur.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create Rail
         std::unique_ptr<Rail> rail = std::make_unique<Rail>("vdd0");
@@ -120,17 +123,18 @@
         chassisVec.emplace_back(std::move(chassis));
         System system{std::move(rules), std::move(chassisVec)};
 
-        // Call configure().  Should do nothing.
-        journal::clear();
+        // Call configure().
         railPtr->configure(services, system, *chassisPtr, *devicePtr);
-        EXPECT_EQ(journal::getDebugMessages().size(), 0);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 
     // Test where Configuration was specified in constructor
     {
-        // Create mock services.
+        // Create mock services.  Expect logDebug() to be called.
         MockServices services{};
+        MockJournal& journal = services.getMockJournal();
+        EXPECT_CALL(journal, logDebug("Configuring vddr1: volts=1.300000"))
+            .Times(1);
+        EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
         // Create Configuration
         std::optional<double> volts{1.3};
@@ -172,14 +176,8 @@
         chassisVec.emplace_back(std::move(chassis));
         System system{std::move(rules), std::move(chassisVec)};
 
-        // Call configure().  Should execute Configuration and log debug message
-        // to journal.
-        journal::clear();
+        // Call configure().
         railPtr->configure(services, system, *chassisPtr, *devicePtr);
-        std::vector<std::string> expectedDebugMessages{
-            "Configuring vddr1: volts=1.300000"};
-        EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
-        EXPECT_EQ(journal::getErrMessages().size(), 0);
     }
 }
 
diff --git a/phosphor-regulators/test/system_tests.cpp b/phosphor-regulators/test/system_tests.cpp
index daa2084..7adc5d8 100644
--- a/phosphor-regulators/test/system_tests.cpp
+++ b/phosphor-regulators/test/system_tests.cpp
@@ -23,6 +23,7 @@
 #include "pmbus_read_sensor_action.hpp"
 #include "rail.hpp"
 #include "rule.hpp"
+#include "services.hpp"
 #include "system.hpp"
 #include "test_utils.hpp"
 
@@ -91,8 +92,13 @@
 
 TEST(SystemTests, Configure)
 {
-    // Create mock services.
+    // Create mock services.  Expect logInfo() to be called.
     MockServices services{};
+    MockJournal& journal = services.getMockJournal();
+    EXPECT_CALL(journal, logInfo("Configuring chassis 1")).Times(1);
+    EXPECT_CALL(journal, logInfo("Configuring chassis 3")).Times(1);
+    EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0);
+    EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
 
     // Specify an empty rules vector
     std::vector<std::unique_ptr<Rule>> rules{};
@@ -106,13 +112,7 @@
     System system{std::move(rules), std::move(chassis)};
 
     // Call configure()
-    journal::clear();
     system.configure(services);
-    EXPECT_EQ(journal::getDebugMessages().size(), 0);
-    EXPECT_EQ(journal::getErrMessages().size(), 0);
-    std::vector<std::string> expectedInfoMessages{"Configuring chassis 1",
-                                                  "Configuring chassis 3"};
-    EXPECT_EQ(journal::getInfoMessages(), expectedInfoMessages);
 }
 
 TEST(SystemTests, GetChassis)