regulators: Add Sensors service

Define the abstract base class Sensors.  This class represents a service
that maintains a list of voltage regulator sensors.

This service makes the voltage regulator sensors available to other BMC
applications.  For example, the Redfish support obtains sensor data from
this service.

Each voltage rail in the system may provide multiple types of sensor
data, such as temperature, output voltage, and output current.  A sensor
tracks one of these data types for a voltage rail.

Also define a concrete subclass MockSensors used for test cases.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I0b1c28161bad899c6dd75f87b7ee8e891c8781af
diff --git a/phosphor-regulators/test/meson.build b/phosphor-regulators/test/meson.build
index 0fd55de..3f16812 100644
--- a/phosphor-regulators/test/meson.build
+++ b/phosphor-regulators/test/meson.build
@@ -20,6 +20,7 @@
     'rail_tests.cpp',
     'rule_tests.cpp',
     'sensor_monitoring_tests.cpp',
+    'sensors_tests.cpp',
     'system_tests.cpp',
     'temporary_file_tests.cpp',
     'write_verification_error_tests.cpp',
diff --git a/phosphor-regulators/test/mock_sensors.hpp b/phosphor-regulators/test/mock_sensors.hpp
new file mode 100644
index 0000000..0973d7c
--- /dev/null
+++ b/phosphor-regulators/test/mock_sensors.hpp
@@ -0,0 +1,66 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include "sensors.hpp"
+#include "services.hpp"
+
+#include <string>
+
+#include <gmock/gmock.h>
+
+namespace phosphor::power::regulators
+{
+
+/**
+ * @class MockSensors
+ *
+ * Mock implementation of the Sensors interface.
+ */
+class MockSensors : public Sensors
+{
+  public:
+    // Specify which compiler-generated methods we want
+    MockSensors() = default;
+    MockSensors(const MockSensors&) = delete;
+    MockSensors(MockSensors&&) = delete;
+    MockSensors& operator=(const MockSensors&) = delete;
+    MockSensors& operator=(MockSensors&&) = delete;
+    virtual ~MockSensors() = default;
+
+    MOCK_METHOD(void, enable, (Services & services), (override));
+
+    MOCK_METHOD(void, endCycle, (Services & services), (override));
+
+    MOCK_METHOD(void, endRail, (bool errorOccurred, Services& services),
+                (override));
+
+    MOCK_METHOD(void, disable, (Services & services), (override));
+
+    MOCK_METHOD(void, setValue,
+                (SensorType type, double value, Services& services),
+                (override));
+
+    MOCK_METHOD(void, startCycle, (Services & services), (override));
+
+    MOCK_METHOD(void, startRail,
+                (const std::string& rail,
+                 const std::string& deviceInventoryPath,
+                 const std::string& chassisInventoryPath, Services& services),
+                (override));
+};
+
+} // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/test/sensors_tests.cpp b/phosphor-regulators/test/sensors_tests.cpp
new file mode 100644
index 0000000..764bc07
--- /dev/null
+++ b/phosphor-regulators/test/sensors_tests.cpp
@@ -0,0 +1,34 @@
+/**
+ * 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 "sensors.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::power::regulators;
+using namespace phosphor::power::regulators::sensors;
+
+TEST(SensorsTests, ToString)
+{
+    EXPECT_EQ(toString(SensorType::iout), "iout");
+    EXPECT_EQ(toString(SensorType::iout_peak), "iout_peak");
+    EXPECT_EQ(toString(SensorType::iout_valley), "iout_valley");
+    EXPECT_EQ(toString(SensorType::pout), "pout");
+    EXPECT_EQ(toString(SensorType::temperature), "temperature");
+    EXPECT_EQ(toString(SensorType::temperature_peak), "temperature_peak");
+    EXPECT_EQ(toString(SensorType::vout), "vout");
+    EXPECT_EQ(toString(SensorType::vout_peak), "vout_peak");
+    EXPECT_EQ(toString(SensorType::vout_valley), "vout_valley");
+}