regulators: Add Services& services to classes

Modify the configure() method in the System, Chassis, Device, and Rail
classes to have a new first parameter: Services& services.

Fix mock_services.hpp bug.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I6ef41de65d2c5b68c55edb42189ba9c0f2e436ed
diff --git a/phosphor-regulators/src/chassis.cpp b/phosphor-regulators/src/chassis.cpp
index 29ebb79..ebe446c 100644
--- a/phosphor-regulators/src/chassis.cpp
+++ b/phosphor-regulators/src/chassis.cpp
@@ -43,7 +43,7 @@
     }
 }
 
-void Chassis::configure(System& system)
+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));
@@ -51,7 +51,7 @@
     // Configure devices
     for (std::unique_ptr<Device>& device : devices)
     {
-        device->configure(system, *this);
+        device->configure(services, system, *this);
     }
 }
 
diff --git a/phosphor-regulators/src/chassis.hpp b/phosphor-regulators/src/chassis.hpp
index 4423926..3addd5e 100644
--- a/phosphor-regulators/src/chassis.hpp
+++ b/phosphor-regulators/src/chassis.hpp
@@ -17,6 +17,7 @@
 
 #include "device.hpp"
 #include "id_map.hpp"
+#include "services.hpp"
 
 #include <memory>
 #include <stdexcept>
@@ -95,9 +96,10 @@
      * This method should be called during the boot before regulators are
      * enabled.
      *
+     * @param services system services like error logging and the journal
      * @param system system that contains this chassis
      */
-    void configure(System& system);
+    void configure(Services& services, System& system);
 
     /**
      * Returns the devices within this chassis, if any.
diff --git a/phosphor-regulators/src/configuration.cpp b/phosphor-regulators/src/configuration.cpp
index 99245ca..8edc36c 100644
--- a/phosphor-regulators/src/configuration.cpp
+++ b/phosphor-regulators/src/configuration.cpp
@@ -30,19 +30,21 @@
 namespace phosphor::power::regulators
 {
 
-void Configuration::execute(System& system, Chassis& chassis, Device& device)
+void Configuration::execute(Services& services, System& system,
+                            Chassis& chassis, Device& device)
 {
-    execute(system, chassis, device, device.getID());
+    execute(services, system, chassis, device, device.getID());
 }
 
-void Configuration::execute(System& system, Chassis& chassis, Device& device,
-                            Rail& rail)
+void Configuration::execute(Services& services, System& system,
+                            Chassis& chassis, Device& device, Rail& rail)
 {
-    execute(system, chassis, device, rail.getID());
+    execute(services, system, chassis, device, rail.getID());
 }
 
-void Configuration::execute(System& system, Chassis& /*chassis*/,
-                            Device& device, const std::string& deviceOrRailID)
+void Configuration::execute(Services& /*services*/, System& system,
+                            Chassis& /*chassis*/, Device& device,
+                            const std::string& deviceOrRailID)
 {
     try
     {
diff --git a/phosphor-regulators/src/configuration.hpp b/phosphor-regulators/src/configuration.hpp
index 3534419..f0dd766 100644
--- a/phosphor-regulators/src/configuration.hpp
+++ b/phosphor-regulators/src/configuration.hpp
@@ -16,6 +16,7 @@
 #pragma once
 
 #include "action.hpp"
+#include "services.hpp"
 
 #include <memory>
 #include <optional>
@@ -82,11 +83,13 @@
      * This method should be called during the boot before regulators are
      * enabled.
      *
+     * @param services system services like error logging and the journal
      * @param system system that contains the chassis
      * @param chassis chassis that contains the device
      * @param device device to configure
      */
-    void execute(System& system, Chassis& chassis, Device& device);
+    void execute(Services& services, System& system, Chassis& chassis,
+                 Device& device);
 
     /**
      * Executes the actions to configure the specified rail.
@@ -94,12 +97,14 @@
      * This method should be called during the boot before regulators are
      * enabled.
      *
+     * @param services system services like error logging and the journal
      * @param system system that contains the chassis
      * @param chassis chassis that contains the device
      * @param device device that contains the rail
      * @param rail rail to configure
      */
-    void execute(System& system, Chassis& chassis, Device& device, Rail& rail);
+    void execute(Services& services, System& system, Chassis& chassis,
+                 Device& device, Rail& rail);
 
     /**
      * Returns the actions that configure the device/rail.
@@ -125,13 +130,14 @@
     /**
      * Executes the actions to configure a device or rail.
      *
+     * @param services system services like error logging and the journal
      * @param system system that contains the chassis
      * @param chassis chassis that contains the device
      * @param device device to configure or that contains rail to configure
      * @param deviceOrRailID ID of the device or rail to configure
      */
-    void execute(System& system, Chassis& chassis, Device& device,
-                 const std::string& deviceOrRailID);
+    void execute(Services& services, System& system, Chassis& chassis,
+                 Device& device, const std::string& deviceOrRailID);
 
     /**
      * Optional output voltage value.
diff --git a/phosphor-regulators/src/device.cpp b/phosphor-regulators/src/device.cpp
index fd07d71..f085afe 100644
--- a/phosphor-regulators/src/device.cpp
+++ b/phosphor-regulators/src/device.cpp
@@ -58,18 +58,18 @@
     }
 }
 
-void Device::configure(System& system, Chassis& chassis)
+void Device::configure(Services& services, System& system, Chassis& chassis)
 {
     // If configuration changes are defined for this device, apply them
     if (configuration)
     {
-        configuration->execute(system, chassis, *this);
+        configuration->execute(services, system, chassis, *this);
     }
 
     // Configure rails
     for (std::unique_ptr<Rail>& rail : rails)
     {
-        rail->configure(system, chassis, *this);
+        rail->configure(services, system, chassis, *this);
     }
 }
 
diff --git a/phosphor-regulators/src/device.hpp b/phosphor-regulators/src/device.hpp
index e18f6fa..cb3a3d9 100644
--- a/phosphor-regulators/src/device.hpp
+++ b/phosphor-regulators/src/device.hpp
@@ -20,6 +20,7 @@
 #include "id_map.hpp"
 #include "presence_detection.hpp"
 #include "rail.hpp"
+#include "services.hpp"
 
 #include <memory>
 #include <string>
@@ -104,10 +105,11 @@
      * This method should be called during the boot before regulators are
      * enabled.
      *
+     * @param services system services like error logging and the journal
      * @param system system that contains the chassis
      * @param chassis chassis that contains this device
      */
-    void configure(System& system, Chassis& chassis);
+    void configure(Services& services, System& system, Chassis& chassis);
 
     /**
      * Returns the configuration changes to apply to this device, if any.
diff --git a/phosphor-regulators/src/manager.cpp b/phosphor-regulators/src/manager.cpp
index fd8dd01..bb0e3a8 100644
--- a/phosphor-regulators/src/manager.cpp
+++ b/phosphor-regulators/src/manager.cpp
@@ -84,7 +84,7 @@
     if (system)
     {
         // Configure the regulator devices in the system
-        system->configure();
+        system->configure(services);
     }
     else
     {
diff --git a/phosphor-regulators/src/rail.cpp b/phosphor-regulators/src/rail.cpp
index 7d90e77..3739ef0 100644
--- a/phosphor-regulators/src/rail.cpp
+++ b/phosphor-regulators/src/rail.cpp
@@ -23,12 +23,13 @@
 namespace phosphor::power::regulators
 {
 
-void Rail::configure(System& system, Chassis& chassis, Device& device)
+void Rail::configure(Services& services, System& system, Chassis& chassis,
+                     Device& device)
 {
     // If configuration changes are defined for this rail, apply them
     if (configuration)
     {
-        configuration->execute(system, chassis, device, *this);
+        configuration->execute(services, system, chassis, device, *this);
     }
 }
 
diff --git a/phosphor-regulators/src/rail.hpp b/phosphor-regulators/src/rail.hpp
index 8340d07..9caafbe 100644
--- a/phosphor-regulators/src/rail.hpp
+++ b/phosphor-regulators/src/rail.hpp
@@ -17,6 +17,7 @@
 
 #include "configuration.hpp"
 #include "sensor_monitoring.hpp"
+#include "services.hpp"
 
 #include <memory>
 #include <string>
@@ -74,11 +75,13 @@
      * This method should be called during the boot before regulators are
      * enabled.
      *
+     * @param services system services like error logging and the journal
      * @param system system that contains the chassis
      * @param chassis chassis that contains the device
      * @param device device that contains this rail
      */
-    void configure(System& system, Chassis& chassis, Device& device);
+    void configure(Services& services, System& system, Chassis& chassis,
+                   Device& device);
 
     /**
      * Returns the configuration changes to apply to this rail, if any.
diff --git a/phosphor-regulators/src/system.cpp b/phosphor-regulators/src/system.cpp
index d3b599a..d6be768 100644
--- a/phosphor-regulators/src/system.cpp
+++ b/phosphor-regulators/src/system.cpp
@@ -43,12 +43,12 @@
     }
 }
 
-void System::configure()
+void System::configure(Services& services)
 {
     // Configure devices in each chassis
     for (std::unique_ptr<Chassis>& oneChassis : chassis)
     {
-        oneChassis->configure(*this);
+        oneChassis->configure(services, *this);
     }
 }
 
diff --git a/phosphor-regulators/src/system.hpp b/phosphor-regulators/src/system.hpp
index f678658..3ffeb5b 100644
--- a/phosphor-regulators/src/system.hpp
+++ b/phosphor-regulators/src/system.hpp
@@ -18,6 +18,7 @@
 #include "chassis.hpp"
 #include "id_map.hpp"
 #include "rule.hpp"
+#include "services.hpp"
 
 #include <memory>
 #include <utility>
@@ -69,8 +70,10 @@
      *
      * This method should be called during the boot before regulators are
      * enabled.
+     *
+     * @param services system services like error logging and the journal
      */
-    void configure();
+    void configure(Services& services);
 
     /**
      * Returns the chassis in the system.
diff --git a/phosphor-regulators/test/chassis_tests.cpp b/phosphor-regulators/test/chassis_tests.cpp
index eca6d97..481d71d 100644
--- a/phosphor-regulators/test/chassis_tests.cpp
+++ b/phosphor-regulators/test/chassis_tests.cpp
@@ -21,6 +21,7 @@
 #include "id_map.hpp"
 #include "journal.hpp"
 #include "mock_journal.hpp"
+#include "mock_services.hpp"
 #include "mocked_i2c_interface.hpp"
 #include "pmbus_read_sensor_action.hpp"
 #include "presence_detection.hpp"
@@ -180,6 +181,9 @@
 {
     // Test where no devices were specified in constructor
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create Chassis
         std::unique_ptr<Chassis> chassis = std::make_unique<Chassis>(1);
         Chassis* chassisPtr = chassis.get();
@@ -192,7 +196,7 @@
 
         // Call configure()
         journal::clear();
-        chassisPtr->configure(system);
+        chassisPtr->configure(services, system);
         EXPECT_EQ(journal::getDebugMessages().size(), 0);
         EXPECT_EQ(journal::getErrMessages().size(), 0);
         std::vector<std::string> expectedInfoMessages{"Configuring chassis 1"};
@@ -201,6 +205,9 @@
 
     // Test where devices were specified in constructor
     {
+        // Create mock services.
+        MockServices services{};
+
         std::vector<std::unique_ptr<Device>> devices{};
 
         // Create Device vdd0_reg
@@ -252,7 +259,7 @@
 
         // Call configure()
         journal::clear();
-        chassisPtr->configure(system);
+        chassisPtr->configure(services, system);
         std::vector<std::string> expectedDebugMessages{
             "Configuring vdd0_reg: volts=1.300000",
             "Configuring vdd1_reg: volts=1.200000"};
diff --git a/phosphor-regulators/test/configuration_tests.cpp b/phosphor-regulators/test/configuration_tests.cpp
index a7ba37f..93f1be8 100644
--- a/phosphor-regulators/test/configuration_tests.cpp
+++ b/phosphor-regulators/test/configuration_tests.cpp
@@ -22,6 +22,7 @@
 #include "journal.hpp"
 #include "mock_action.hpp"
 #include "mock_journal.hpp"
+#include "mock_services.hpp"
 #include "mocked_i2c_interface.hpp"
 #include "pmbus_utils.hpp"
 #include "pmbus_write_vout_command_action.hpp"
@@ -80,6 +81,9 @@
 {
     // Test where works: Volts value not specified
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
             std::make_unique<I2CWriteByteAction>(0x7C, 0x0A);
@@ -123,7 +127,7 @@
 
         // Execute Configuration
         journal::clear();
-        configurationPtr->execute(system, *chassisPtr, *devicePtr);
+        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);
@@ -131,6 +135,9 @@
 
     // Test where works: Volts value specified
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create PMBusWriteVoutCommandAction.  Do not specify a volts value
         // because it will get a value of 1.3V from the
         // ActionEnvironment/Configuration.  Specify a -8 exponent.
@@ -179,7 +186,7 @@
 
         // Execute Configuration
         journal::clear();
-        configurationPtr->execute(system, *chassisPtr, *devicePtr);
+        configurationPtr->execute(services, system, *chassisPtr, *devicePtr);
         std::vector<std::string> expectedDebugMessages{
             "Configuring vdd_reg: volts=1.300000"};
         EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
@@ -188,6 +195,9 @@
 
     // Test where fails
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
             std::make_unique<I2CWriteByteAction>(0x7C, 0x0A);
@@ -233,7 +243,7 @@
 
         // Execute Configuration
         journal::clear();
-        configurationPtr->execute(system, *chassisPtr, *devicePtr);
+        configurationPtr->execute(services, system, *chassisPtr, *devicePtr);
         std::vector<std::string> expectedDebugMessages{"Configuring vdd_reg"};
         EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
         std::vector<std::string> expectedErrMessages{
@@ -250,6 +260,9 @@
 {
     // Test where works: Volts value not specified
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
             std::make_unique<I2CWriteByteAction>(0x7C, 0x0A);
@@ -301,7 +314,8 @@
 
         // Execute Configuration
         journal::clear();
-        configurationPtr->execute(system, *chassisPtr, *devicePtr, *railPtr);
+        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);
@@ -309,6 +323,9 @@
 
     // Test where works: Volts value specified
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create PMBusWriteVoutCommandAction.  Do not specify a volts value
         // because it will get a value of 1.3V from the
         // ActionEnvironment/Configuration.  Specify a -8 exponent.
@@ -365,7 +382,8 @@
 
         // Execute Configuration
         journal::clear();
-        configurationPtr->execute(system, *chassisPtr, *devicePtr, *railPtr);
+        configurationPtr->execute(services, system, *chassisPtr, *devicePtr,
+                                  *railPtr);
         std::vector<std::string> expectedDebugMessages{
             "Configuring vio2: volts=1.300000"};
         EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
@@ -374,6 +392,9 @@
 
     // Test where fails
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create I2CWriteByteAction with register 0x7C and value 0x0A
         std::unique_ptr<I2CWriteByteAction> action =
             std::make_unique<I2CWriteByteAction>(0x7C, 0x0A);
@@ -427,7 +448,8 @@
 
         // Execute Configuration
         journal::clear();
-        configurationPtr->execute(system, *chassisPtr, *devicePtr, *railPtr);
+        configurationPtr->execute(services, system, *chassisPtr, *devicePtr,
+                                  *railPtr);
         std::vector<std::string> expectedDebugMessages{"Configuring vio2"};
         EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
         std::vector<std::string> expectedErrMessages{
diff --git a/phosphor-regulators/test/device_tests.cpp b/phosphor-regulators/test/device_tests.cpp
index e0efb35..47768e2 100644
--- a/phosphor-regulators/test/device_tests.cpp
+++ b/phosphor-regulators/test/device_tests.cpp
@@ -22,6 +22,7 @@
 #include "journal.hpp"
 #include "mock_action.hpp"
 #include "mock_journal.hpp"
+#include "mock_services.hpp"
 #include "mocked_i2c_interface.hpp"
 #include "pmbus_read_sensor_action.hpp"
 #include "presence_detection.hpp"
@@ -210,6 +211,9 @@
 {
     // Test where Configuration and Rails were not specified in constructor
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create Device
         std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
         std::unique_ptr<Device> device = std::make_unique<Device>(
@@ -232,13 +236,16 @@
 
         // Call configure().  Should do nothing.
         journal::clear();
-        devicePtr->configure(system, *chassisPtr);
+        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 Rail vdd0
@@ -309,7 +316,7 @@
         // Call configure().  For the Device and both Rails, should execute the
         // Configuration and log a debug message.
         journal::clear();
-        devicePtr->configure(system, *chassisPtr);
+        devicePtr->configure(services, system, *chassisPtr);
         std::vector<std::string> expectedDebugMessages{
             "Configuring reg1", "Configuring vdd0: volts=1.300000",
             "Configuring vio0: volts=3.200000"};
diff --git a/phosphor-regulators/test/mock_services.hpp b/phosphor-regulators/test/mock_services.hpp
index 58c565e..075768c 100644
--- a/phosphor-regulators/test/mock_services.hpp
+++ b/phosphor-regulators/test/mock_services.hpp
@@ -19,6 +19,7 @@
 #include "journal.hpp"
 #include "mock_error_logging.hpp"
 #include "mock_journal.hpp"
+#include "services.hpp"
 
 #include <sdbusplus/bus.hpp>
 
@@ -67,7 +68,7 @@
      *
      * @return mock error logging object
      */
-    virtual MockErrorLogging& getMockErrorLogging() override
+    virtual MockErrorLogging& getMockErrorLogging()
     {
         return errorLogging;
     }
@@ -79,7 +80,7 @@
      *
      * @return mock journal object
      */
-    virtual MockJournal& getMockJournal() override
+    virtual MockJournal& getMockJournal()
     {
         return journal;
     }
diff --git a/phosphor-regulators/test/rail_tests.cpp b/phosphor-regulators/test/rail_tests.cpp
index e3c1c6a..d8524dc 100644
--- a/phosphor-regulators/test/rail_tests.cpp
+++ b/phosphor-regulators/test/rail_tests.cpp
@@ -21,6 +21,7 @@
 #include "journal.hpp"
 #include "mock_action.hpp"
 #include "mock_journal.hpp"
+#include "mock_services.hpp"
 #include "mocked_i2c_interface.hpp"
 #include "pmbus_read_sensor_action.hpp"
 #include "presence_detection.hpp"
@@ -86,6 +87,9 @@
 {
     // Test where Configuration was not specified in constructor
     {
+        // Create mock services.
+        MockServices services{};
+
         // Create Rail
         std::unique_ptr<Rail> rail = std::make_unique<Rail>("vdd0");
         Rail* railPtr = rail.get();
@@ -118,13 +122,16 @@
 
         // Call configure().  Should do nothing.
         journal::clear();
-        railPtr->configure(system, *chassisPtr, *devicePtr);
+        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.
+        MockServices services{};
+
         // Create Configuration
         std::optional<double> volts{1.3};
         std::unique_ptr<MockAction> action = std::make_unique<MockAction>();
@@ -168,7 +175,7 @@
         // Call configure().  Should execute Configuration and log debug message
         // to journal.
         journal::clear();
-        railPtr->configure(system, *chassisPtr, *devicePtr);
+        railPtr->configure(services, system, *chassisPtr, *devicePtr);
         std::vector<std::string> expectedDebugMessages{
             "Configuring vddr1: volts=1.300000"};
         EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
diff --git a/phosphor-regulators/test/system_tests.cpp b/phosphor-regulators/test/system_tests.cpp
index b79e1ba..daa2084 100644
--- a/phosphor-regulators/test/system_tests.cpp
+++ b/phosphor-regulators/test/system_tests.cpp
@@ -18,6 +18,7 @@
 #include "id_map.hpp"
 #include "journal.hpp"
 #include "mock_journal.hpp"
+#include "mock_services.hpp"
 #include "mocked_i2c_interface.hpp"
 #include "pmbus_read_sensor_action.hpp"
 #include "rail.hpp"
@@ -90,6 +91,9 @@
 
 TEST(SystemTests, Configure)
 {
+    // Create mock services.
+    MockServices services{};
+
     // Specify an empty rules vector
     std::vector<std::unique_ptr<Rule>> rules{};
 
@@ -103,7 +107,7 @@
 
     // Call configure()
     journal::clear();
-    system.configure();
+    system.configure(services);
     EXPECT_EQ(journal::getDebugMessages().size(), 0);
     EXPECT_EQ(journal::getErrMessages().size(), 0);
     std::vector<std::string> expectedInfoMessages{"Configuring chassis 1",