regulators: Add monitorSensors support to System
Implemented the monitorSensors() method in the System class. This method
reads the sensors for the voltage rails produced by the system.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: Ied2248c362708aa77c1efd31abff0cf023211a7e
diff --git a/phosphor-regulators/src/system.cpp b/phosphor-regulators/src/system.cpp
index 29dad5e..d3b599a 100644
--- a/phosphor-regulators/src/system.cpp
+++ b/phosphor-regulators/src/system.cpp
@@ -52,4 +52,13 @@
}
}
+void System::monitorSensors()
+{
+ // Monitor sensors in each chassis
+ for (std::unique_ptr<Chassis>& oneChassis : chassis)
+ {
+ oneChassis->monitorSensors(*this);
+ }
+}
+
} // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/src/system.hpp b/phosphor-regulators/src/system.hpp
index 46c3d7c..f678658 100644
--- a/phosphor-regulators/src/system.hpp
+++ b/phosphor-regulators/src/system.hpp
@@ -105,6 +105,14 @@
return rules;
}
+ /**
+ * Monitors the sensors for the voltage rails produced by this system, if
+ * any.
+ *
+ * This method should be called once per second.
+ */
+ void monitorSensors();
+
private:
/**
* Builds the IDMap for the system.
diff --git a/phosphor-regulators/test/system_tests.cpp b/phosphor-regulators/test/system_tests.cpp
index dfc22a0..b79e1ba 100644
--- a/phosphor-regulators/test/system_tests.cpp
+++ b/phosphor-regulators/test/system_tests.cpp
@@ -18,6 +18,8 @@
#include "id_map.hpp"
#include "journal.hpp"
#include "mock_journal.hpp"
+#include "mocked_i2c_interface.hpp"
+#include "pmbus_read_sensor_action.hpp"
#include "rail.hpp"
#include "rule.hpp"
#include "system.hpp"
@@ -29,11 +31,16 @@
#include <utility>
#include <vector>
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace phosphor::power::regulators;
using namespace phosphor::power::regulators::test_utils;
+using ::testing::A;
+using ::testing::Return;
+using ::testing::TypedEq;
+
TEST(SystemTests, Constructor)
{
// Create Rules
@@ -187,3 +194,62 @@
EXPECT_EQ(system.getRules()[0]->getID(), "set_voltage_rule");
EXPECT_EQ(system.getRules()[1]->getID(), "read_sensors_rule");
}
+
+TEST(SystemTests, MonitorSensors)
+{
+ // Create PMBusReadSensorAction
+ pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
+ uint8_t command = 0x8C;
+ pmbus_utils::SensorDataFormat format{
+ pmbus_utils::SensorDataFormat::linear_11};
+ std::optional<int8_t> exponent{};
+ std::unique_ptr<PMBusReadSensorAction> action =
+ std::make_unique<PMBusReadSensorAction>(type, command, format,
+ exponent);
+
+ // Create mock I2CInterface. A two-byte read should occur.
+ std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
+ std::make_unique<i2c::MockedI2CInterface>();
+ EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
+ EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x8C), A<uint16_t&>()))
+ .Times(1);
+
+ // Create SensorMonitoring
+ std::vector<std::unique_ptr<Action>> actions{};
+ actions.emplace_back(std::move(action));
+ std::unique_ptr<SensorMonitoring> sensorMonitoring =
+ std::make_unique<SensorMonitoring>(std::move(actions));
+
+ // Create Rail
+ std::vector<std::unique_ptr<Rail>> rails{};
+ std::unique_ptr<Configuration> configuration{};
+ std::unique_ptr<Rail> rail = std::make_unique<Rail>(
+ "vdd0", std::move(configuration), std::move(sensorMonitoring));
+ rails.emplace_back(std::move(rail));
+
+ // Create Device
+ std::unique_ptr<PresenceDetection> presenceDetection{};
+ std::unique_ptr<Configuration> deviceConfiguration{};
+ std::unique_ptr<Device> device = std::make_unique<Device>(
+ "reg1", true, "/system/chassis/motherboard/reg1",
+ std::move(i2cInterface), std::move(presenceDetection),
+ std::move(deviceConfiguration), std::move(rails));
+
+ // Create Chassis
+ std::vector<std::unique_ptr<Device>> devices{};
+ devices.emplace_back(std::move(device));
+ std::unique_ptr<Chassis> chassis =
+ std::make_unique<Chassis>(1, std::move(devices));
+
+ // Create System that contains Chassis
+ std::vector<std::unique_ptr<Rule>> rules{};
+ std::vector<std::unique_ptr<Chassis>> chassisVec{};
+ chassisVec.emplace_back(std::move(chassis));
+ System system{std::move(rules), std::move(chassisVec)};
+
+ // Call monitorSensors()
+ journal::clear();
+ system.monitorSensors();
+ EXPECT_EQ(journal::getDebugMessages().size(), 0);
+ EXPECT_EQ(journal::getErrMessages().size(), 0);
+}