Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 16 | #include "action.hpp" |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 17 | #include "chassis.hpp" |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 18 | #include "configuration.hpp" |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 19 | #include "device.hpp" |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 20 | #include "i2c_interface.hpp" |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 21 | #include "id_map.hpp" |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 22 | #include "mock_action.hpp" |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 23 | #include "mock_error_logging.hpp" |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 24 | #include "mock_journal.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 25 | #include "mock_sensors.hpp" |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 26 | #include "mock_services.hpp" |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 27 | #include "mocked_i2c_interface.hpp" |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 28 | #include "phase_fault_detection.hpp" |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 29 | #include "presence_detection.hpp" |
| 30 | #include "rail.hpp" |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 31 | #include "rule.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 32 | #include "sensor_monitoring.hpp" |
Shawn McCarney | 2f9e14f | 2021-04-29 02:45:18 -0500 | [diff] [blame] | 33 | #include "sensors.hpp" |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 34 | #include "system.hpp" |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 35 | #include "test_sdbus_error.hpp" |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 36 | #include "test_utils.hpp" |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 37 | |
| 38 | #include <memory> |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 39 | #include <optional> |
Shawn McCarney | 525e20c | 2020-04-14 11:05:39 -0500 | [diff] [blame] | 40 | #include <string> |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 41 | #include <utility> |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 42 | #include <vector> |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 43 | |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 44 | #include <gmock/gmock.h> |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 45 | #include <gtest/gtest.h> |
| 46 | |
| 47 | using namespace phosphor::power::regulators; |
Shawn McCarney | 8a3afd7 | 2020-03-12 14:28:44 -0500 | [diff] [blame] | 48 | using namespace phosphor::power::regulators::test_utils; |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 49 | |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 50 | using ::testing::A; |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 51 | using ::testing::Ref; |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 52 | using ::testing::Return; |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 53 | using ::testing::Throw; |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 54 | using ::testing::TypedEq; |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 55 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 56 | class DeviceTests : public ::testing::Test |
| 57 | { |
| 58 | public: |
| 59 | /** |
| 60 | * Constructor. |
| 61 | * |
| 62 | * Creates the Chassis and System objects needed for calling some Device |
| 63 | * methods. |
| 64 | */ |
| 65 | DeviceTests() : ::testing::Test{} |
| 66 | { |
| 67 | // Create Chassis |
| 68 | auto chassis = std::make_unique<Chassis>(1, chassisInvPath); |
| 69 | this->chassis = chassis.get(); |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 70 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 71 | // Create System |
| 72 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 73 | std::vector<std::unique_ptr<Chassis>> chassisVec{}; |
| 74 | chassisVec.emplace_back(std::move(chassis)); |
| 75 | this->system = |
| 76 | std::make_unique<System>(std::move(rules), std::move(chassisVec)); |
| 77 | } |
| 78 | |
| 79 | protected: |
| 80 | const std::string deviceInvPath{ |
| 81 | "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg2"}; |
| 82 | const std::string chassisInvPath{ |
| 83 | "/xyz/openbmc_project/inventory/system/chassis"}; |
| 84 | |
| 85 | // Note: This pointer does NOT need to be explicitly deleted. The Chassis |
| 86 | // object is owned by the System object and will be automatically deleted. |
| 87 | Chassis* chassis{nullptr}; |
| 88 | |
| 89 | std::unique_ptr<System> system{}; |
| 90 | }; |
| 91 | |
| 92 | TEST_F(DeviceTests, Constructor) |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 93 | { |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 94 | // Test where only required parameters are specified |
| 95 | { |
| 96 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 97 | i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 98 | Device device{"vdd_reg", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 99 | EXPECT_EQ(device.getID(), "vdd_reg"); |
| 100 | EXPECT_EQ(device.isRegulator(), true); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 101 | EXPECT_EQ(device.getFRU(), deviceInvPath); |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 102 | EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr); |
| 103 | EXPECT_EQ(device.getPresenceDetection(), nullptr); |
| 104 | EXPECT_EQ(device.getConfiguration(), nullptr); |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 105 | EXPECT_EQ(device.getPhaseFaultDetection(), nullptr); |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 106 | EXPECT_EQ(device.getRails().size(), 0); |
| 107 | } |
| 108 | |
| 109 | // Test where all parameters are specified |
| 110 | { |
| 111 | // Create I2CInterface |
| 112 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 113 | i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get(); |
| 114 | |
| 115 | // Create PresenceDetection |
| 116 | std::vector<std::unique_ptr<Action>> actions{}; |
| 117 | actions.push_back(std::make_unique<MockAction>()); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 118 | auto presenceDetection = |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 119 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 120 | |
| 121 | // Create Configuration |
| 122 | std::optional<double> volts{}; |
| 123 | actions.clear(); |
| 124 | actions.push_back(std::make_unique<MockAction>()); |
| 125 | actions.push_back(std::make_unique<MockAction>()); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 126 | auto configuration = |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 127 | std::make_unique<Configuration>(volts, std::move(actions)); |
| 128 | |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 129 | // Create PhaseFaultDetection |
| 130 | actions.clear(); |
| 131 | actions.push_back(std::make_unique<MockAction>()); |
| 132 | actions.push_back(std::make_unique<MockAction>()); |
| 133 | actions.push_back(std::make_unique<MockAction>()); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 134 | auto phaseFaultDetection = |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 135 | std::make_unique<PhaseFaultDetection>(std::move(actions)); |
| 136 | |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 137 | // Create vector of Rail objects |
| 138 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 139 | rails.push_back(std::make_unique<Rail>("vdd0")); |
| 140 | rails.push_back(std::make_unique<Rail>("vdd1")); |
| 141 | |
| 142 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 143 | Device device{"vdd_reg", |
| 144 | false, |
| 145 | deviceInvPath, |
| 146 | std::move(i2cInterface), |
| 147 | std::move(presenceDetection), |
| 148 | std::move(configuration), |
| 149 | std::move(phaseFaultDetection), |
| 150 | std::move(rails)}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 151 | EXPECT_EQ(device.getID(), "vdd_reg"); |
| 152 | EXPECT_EQ(device.isRegulator(), false); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 153 | EXPECT_EQ(device.getFRU(), deviceInvPath); |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 154 | EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr); |
| 155 | EXPECT_NE(device.getPresenceDetection(), nullptr); |
| 156 | EXPECT_EQ(device.getPresenceDetection()->getActions().size(), 1); |
| 157 | EXPECT_NE(device.getConfiguration(), nullptr); |
| 158 | EXPECT_EQ(device.getConfiguration()->getVolts().has_value(), false); |
| 159 | EXPECT_EQ(device.getConfiguration()->getActions().size(), 2); |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 160 | EXPECT_NE(device.getPhaseFaultDetection(), nullptr); |
| 161 | EXPECT_EQ(device.getPhaseFaultDetection()->getActions().size(), 3); |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 162 | EXPECT_EQ(device.getRails().size(), 2); |
| 163 | } |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 164 | } |
| 165 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 166 | TEST_F(DeviceTests, AddToIDMap) |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 167 | { |
| 168 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 169 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 170 | std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{}; |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 171 | |
| 172 | // Create vector of Rail objects |
| 173 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 174 | rails.push_back(std::make_unique<Rail>("vdd0")); |
| 175 | rails.push_back(std::make_unique<Rail>("vdd1")); |
| 176 | |
| 177 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 178 | Device device{"vdd_reg", |
| 179 | false, |
| 180 | deviceInvPath, |
| 181 | std::move(createI2CInterface()), |
| 182 | std::move(presenceDetection), |
| 183 | std::move(configuration), |
| 184 | std::move(phaseFaultDetection), |
| 185 | std::move(rails)}; |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 186 | |
| 187 | // Add Device and Rail objects to an IDMap |
| 188 | IDMap idMap{}; |
| 189 | device.addToIDMap(idMap); |
| 190 | |
| 191 | // Verify Device is in the IDMap |
| 192 | EXPECT_NO_THROW(idMap.getDevice("vdd_reg")); |
| 193 | EXPECT_THROW(idMap.getDevice("vio_reg"), std::invalid_argument); |
| 194 | |
| 195 | // Verify all Rails are in the IDMap |
| 196 | EXPECT_NO_THROW(idMap.getRail("vdd0")); |
| 197 | EXPECT_NO_THROW(idMap.getRail("vdd1")); |
| 198 | EXPECT_THROW(idMap.getRail("vdd2"), std::invalid_argument); |
| 199 | } |
| 200 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 201 | TEST_F(DeviceTests, ClearCache) |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 202 | { |
| 203 | // Test where Device does not contain a PresenceDetection object |
| 204 | try |
| 205 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 206 | Device device{"vdd_reg", false, deviceInvPath, |
| 207 | std::move(createI2CInterface())}; |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 208 | device.clearCache(); |
| 209 | } |
| 210 | catch (...) |
| 211 | { |
| 212 | ADD_FAILURE() << "Should not have caught exception."; |
| 213 | } |
| 214 | |
| 215 | // Test where Device contains a PresenceDetection object |
| 216 | { |
| 217 | // Create PresenceDetection |
| 218 | std::vector<std::unique_ptr<Action>> actions{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 219 | auto presenceDetection = |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 220 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 221 | PresenceDetection* presenceDetectionPtr = presenceDetection.get(); |
| 222 | |
| 223 | // Create Device |
| 224 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 225 | Device device{"reg2", true, deviceInvPath, std::move(i2cInterface), |
| 226 | std::move(presenceDetection)}; |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 227 | |
| 228 | // Cache presence value in PresenceDetection |
| 229 | MockServices services{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 230 | presenceDetectionPtr->execute(services, *system, *chassis, device); |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 231 | EXPECT_TRUE(presenceDetectionPtr->getCachedPresence().has_value()); |
| 232 | |
| 233 | // Clear cached data in Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 234 | device.clearCache(); |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 235 | |
| 236 | // Verify presence value no longer cached in PresenceDetection |
| 237 | EXPECT_FALSE(presenceDetectionPtr->getCachedPresence().has_value()); |
| 238 | } |
| 239 | } |
| 240 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 241 | TEST_F(DeviceTests, ClearErrorHistory) |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 242 | { |
| 243 | // Create SensorMonitoring. Will fail with a DBus exception. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 244 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 245 | EXPECT_CALL(*action, execute) |
| 246 | .WillRepeatedly(Throw(TestSDBusError{"Unable to set sensor value"})); |
| 247 | std::vector<std::unique_ptr<Action>> actions{}; |
| 248 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 249 | auto sensorMonitoring = |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 250 | std::make_unique<SensorMonitoring>(std::move(actions)); |
| 251 | |
| 252 | // Create Rail |
| 253 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 254 | auto rail = std::make_unique<Rail>("vddr1", std::move(configuration), |
| 255 | std::move(sensorMonitoring)); |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 256 | |
| 257 | // Create Device that contains Rail |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 258 | auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>(); |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 259 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 260 | std::unique_ptr<Configuration> deviceConfiguration{}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 261 | std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{}; |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 262 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 263 | rails.emplace_back(std::move(rail)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 264 | Device device{"reg2", |
| 265 | true, |
| 266 | deviceInvPath, |
| 267 | std::move(i2cInterface), |
| 268 | std::move(presenceDetection), |
| 269 | std::move(deviceConfiguration), |
| 270 | std::move(phaseFaultDetection), |
| 271 | std::move(rails)}; |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 272 | |
| 273 | // Create mock services |
| 274 | MockServices services{}; |
| 275 | |
| 276 | // Expect Sensors service to be called 5+5=10 times |
| 277 | MockSensors& sensors = services.getMockSensors(); |
| 278 | EXPECT_CALL(sensors, startRail).Times(10); |
| 279 | EXPECT_CALL(sensors, setValue).Times(0); |
| 280 | EXPECT_CALL(sensors, endRail).Times(10); |
| 281 | |
| 282 | // Expect Journal service to be called 3+3=6 times to log error messages |
| 283 | MockJournal& journal = services.getMockJournal(); |
| 284 | EXPECT_CALL(journal, logError(A<const std::vector<std::string>&>())) |
| 285 | .Times(6); |
| 286 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(6); |
| 287 | |
| 288 | // Expect ErrorLogging service to be called 1+1=2 times to log a DBus error |
| 289 | MockErrorLogging& errorLogging = services.getMockErrorLogging(); |
| 290 | EXPECT_CALL(errorLogging, logDBusError).Times(2); |
| 291 | |
| 292 | // Monitor sensors 5 times. Should fail every time, write to journal 3 |
| 293 | // times, and log one error. |
| 294 | for (int i = 1; i <= 5; ++i) |
| 295 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 296 | device.monitorSensors(services, *system, *chassis); |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | // Clear error history |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 300 | device.clearErrorHistory(); |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 301 | |
| 302 | // Monitor sensors 5 times again. Should fail every time, write to journal |
| 303 | // 3 times, and log one error. |
| 304 | for (int i = 1; i <= 5; ++i) |
| 305 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 306 | device.monitorSensors(services, *system, *chassis); |
Shawn McCarney | 371e244 | 2021-05-14 14:18:07 -0500 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 310 | TEST_F(DeviceTests, Close) |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 311 | { |
| 312 | // Test where works: I2C interface is not open |
| 313 | { |
| 314 | // Create mock I2CInterface |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 315 | auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>(); |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 316 | EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(false)); |
| 317 | EXPECT_CALL(*i2cInterface, close).Times(0); |
| 318 | |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 319 | // Create mock services. No logError should occur. |
| 320 | MockServices services{}; |
| 321 | MockJournal& journal = services.getMockJournal(); |
| 322 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0); |
| 323 | EXPECT_CALL(journal, logError(A<const std::vector<std::string>&>())) |
| 324 | .Times(0); |
| 325 | |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 326 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 327 | Device device{"vdd_reg", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 328 | |
| 329 | // Close Device |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 330 | device.close(services); |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | // Test where works: I2C interface is open |
| 334 | { |
| 335 | // Create mock I2CInterface |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 336 | auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>(); |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 337 | EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true)); |
| 338 | EXPECT_CALL(*i2cInterface, close).Times(1); |
| 339 | |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 340 | // Create mock services. No logError should occur. |
| 341 | MockServices services{}; |
| 342 | MockJournal& journal = services.getMockJournal(); |
| 343 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0); |
| 344 | EXPECT_CALL(journal, logError(A<const std::vector<std::string>&>())) |
| 345 | .Times(0); |
| 346 | |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 347 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 348 | Device device{"vdd_reg", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 349 | |
| 350 | // Close Device |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 351 | device.close(services); |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | // Test where fails: closing I2C interface fails |
| 355 | { |
| 356 | // Create mock I2CInterface |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 357 | auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>(); |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 358 | EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true)); |
| 359 | EXPECT_CALL(*i2cInterface, close) |
| 360 | .Times(1) |
| 361 | .WillOnce(Throw( |
| 362 | i2c::I2CException{"Failed to close", "/dev/i2c-1", 0x70})); |
| 363 | |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 364 | // Create mock services. Expect logError() and logI2CError() to be |
| 365 | // called. |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 366 | MockServices services{}; |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 367 | MockErrorLogging& errorLogging = services.getMockErrorLogging(); |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 368 | MockJournal& journal = services.getMockJournal(); |
| 369 | std::vector<std::string> expectedErrMessagesException{ |
| 370 | "I2CException: Failed to close: bus /dev/i2c-1, addr 0x70"}; |
| 371 | EXPECT_CALL(journal, logError("Unable to close device vdd_reg")) |
| 372 | .Times(1); |
| 373 | EXPECT_CALL(journal, logError(expectedErrMessagesException)).Times(1); |
Shawn McCarney | 81a2f90 | 2021-03-23 21:41:34 -0500 | [diff] [blame] | 374 | EXPECT_CALL(errorLogging, |
| 375 | logI2CError(Entry::Level::Notice, Ref(journal), |
| 376 | "/dev/i2c-1", 0x70, 0)) |
| 377 | .Times(1); |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 378 | |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 379 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 380 | Device device{"vdd_reg", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 381 | |
| 382 | // Close Device |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 383 | device.close(services); |
Shawn McCarney | b4d18a4 | 2020-06-02 10:27:05 -0500 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 387 | TEST_F(DeviceTests, Configure) |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 388 | { |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 389 | // Test where device is not present |
| 390 | { |
| 391 | // Create mock services. No logging should occur. |
| 392 | MockServices services{}; |
| 393 | MockJournal& journal = services.getMockJournal(); |
| 394 | EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0); |
| 395 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0); |
| 396 | |
| 397 | // Create PresenceDetection. Indicates device is not present. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 398 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 399 | { |
| 400 | auto action = std::make_unique<MockAction>(); |
| 401 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(false)); |
| 402 | std::vector<std::unique_ptr<Action>> actions{}; |
| 403 | actions.emplace_back(std::move(action)); |
| 404 | presenceDetection = |
| 405 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 406 | } |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 407 | |
| 408 | // Create Configuration. Action inside it should not be executed. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 409 | std::unique_ptr<Configuration> configuration{}; |
| 410 | { |
| 411 | std::optional<double> volts{}; |
| 412 | auto action = std::make_unique<MockAction>(); |
| 413 | EXPECT_CALL(*action, execute).Times(0); |
| 414 | std::vector<std::unique_ptr<Action>> actions{}; |
| 415 | actions.emplace_back(std::move(action)); |
| 416 | configuration = |
| 417 | std::make_unique<Configuration>(volts, std::move(actions)); |
| 418 | } |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 419 | |
| 420 | // Create Device |
| 421 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 422 | Device device{"reg2", |
| 423 | true, |
| 424 | deviceInvPath, |
| 425 | std::move(i2cInterface), |
| 426 | std::move(presenceDetection), |
| 427 | std::move(configuration)}; |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 428 | |
| 429 | // Call configure(). Should do nothing. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 430 | device.configure(services, *system, *chassis); |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 431 | } |
| 432 | |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 433 | // Test where Configuration and Rails were not specified in constructor |
| 434 | { |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 435 | // Create mock services. No logging should occur. |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 436 | MockServices services{}; |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 437 | MockJournal& journal = services.getMockJournal(); |
| 438 | EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0); |
| 439 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0); |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 440 | |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 441 | // Create Device |
| 442 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 443 | Device device{"reg2", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 444 | |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 445 | // Call configure(). |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 446 | device.configure(services, *system, *chassis); |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | // Test where Configuration and Rails were specified in constructor |
| 450 | { |
| 451 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 452 | |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 453 | // Create mock services. Expect logDebug() to be called. |
| 454 | // For the Device and both Rails, should execute the Configuration |
| 455 | // and log a debug message. |
| 456 | MockServices services{}; |
| 457 | MockJournal& journal = services.getMockJournal(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 458 | EXPECT_CALL(journal, logDebug("Configuring reg2")).Times(1); |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 459 | EXPECT_CALL(journal, logDebug("Configuring vdd0: volts=1.300000")) |
| 460 | .Times(1); |
| 461 | EXPECT_CALL(journal, logDebug("Configuring vio0: volts=3.200000")) |
| 462 | .Times(1); |
| 463 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0); |
| 464 | |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 465 | // Create Rail vdd0 |
| 466 | { |
| 467 | // Create Configuration for Rail |
| 468 | std::optional<double> volts{1.3}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 469 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 470 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 471 | std::vector<std::unique_ptr<Action>> actions{}; |
| 472 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 473 | auto configuration = |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 474 | std::make_unique<Configuration>(volts, std::move(actions)); |
| 475 | |
| 476 | // Create Rail |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 477 | auto rail = |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 478 | std::make_unique<Rail>("vdd0", std::move(configuration)); |
| 479 | rails.emplace_back(std::move(rail)); |
| 480 | } |
| 481 | |
| 482 | // Create Rail vio0 |
| 483 | { |
| 484 | // Create Configuration for Rail |
| 485 | std::optional<double> volts{3.2}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 486 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 487 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 488 | std::vector<std::unique_ptr<Action>> actions{}; |
| 489 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 490 | auto configuration = |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 491 | std::make_unique<Configuration>(volts, std::move(actions)); |
| 492 | |
| 493 | // Create Rail |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 494 | auto rail = |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 495 | std::make_unique<Rail>("vio0", std::move(configuration)); |
| 496 | rails.emplace_back(std::move(rail)); |
| 497 | } |
| 498 | |
| 499 | // Create Configuration for Device |
| 500 | std::optional<double> volts{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 501 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 502 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 503 | std::vector<std::unique_ptr<Action>> actions{}; |
| 504 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 505 | auto configuration = |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 506 | std::make_unique<Configuration>(volts, std::move(actions)); |
| 507 | |
| 508 | // Create Device |
| 509 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 510 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 511 | std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 512 | Device device{"reg2", |
| 513 | true, |
| 514 | deviceInvPath, |
| 515 | std::move(i2cInterface), |
| 516 | std::move(presenceDetection), |
| 517 | std::move(configuration), |
| 518 | std::move(phaseFaultDetection), |
| 519 | std::move(rails)}; |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 520 | |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 521 | // Call configure(). |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 522 | device.configure(services, *system, *chassis); |
Shawn McCarney | eb7bec4 | 2020-04-14 09:38:15 -0500 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 526 | TEST_F(DeviceTests, GetConfiguration) |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 527 | { |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 528 | // Test where Configuration was not specified in constructor |
| 529 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 530 | Device device{"vdd_reg", true, deviceInvPath, |
| 531 | std::move(createI2CInterface())}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 532 | EXPECT_EQ(device.getConfiguration(), nullptr); |
| 533 | } |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 534 | |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 535 | // Test where Configuration was specified in constructor |
| 536 | { |
| 537 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 538 | |
| 539 | // Create Configuration |
| 540 | std::optional<double> volts{3.2}; |
| 541 | std::vector<std::unique_ptr<Action>> actions{}; |
| 542 | actions.push_back(std::make_unique<MockAction>()); |
| 543 | actions.push_back(std::make_unique<MockAction>()); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 544 | auto configuration = |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 545 | std::make_unique<Configuration>(volts, std::move(actions)); |
| 546 | |
| 547 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 548 | Device device{"vdd_reg", |
| 549 | true, |
| 550 | deviceInvPath, |
| 551 | std::move(createI2CInterface()), |
| 552 | std::move(presenceDetection), |
| 553 | std::move(configuration)}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 554 | EXPECT_NE(device.getConfiguration(), nullptr); |
| 555 | EXPECT_EQ(device.getConfiguration()->getVolts().has_value(), true); |
| 556 | EXPECT_EQ(device.getConfiguration()->getVolts().value(), 3.2); |
| 557 | EXPECT_EQ(device.getConfiguration()->getActions().size(), 2); |
| 558 | } |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 559 | } |
| 560 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 561 | TEST_F(DeviceTests, GetFRU) |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 562 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 563 | Device device{"vdd_reg", true, deviceInvPath, |
| 564 | std::move(createI2CInterface())}; |
| 565 | EXPECT_EQ(device.getFRU(), deviceInvPath); |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 566 | } |
| 567 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 568 | TEST_F(DeviceTests, GetI2CInterface) |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 569 | { |
| 570 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 571 | i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 572 | Device device{"vdd_reg", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | afb7fc3 | 2019-12-11 19:42:03 -0600 | [diff] [blame] | 573 | EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr); |
Shawn McCarney | a2461b3 | 2019-10-24 18:53:01 -0500 | [diff] [blame] | 574 | } |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 575 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 576 | TEST_F(DeviceTests, GetID) |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 577 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 578 | Device device{"vdd_reg", false, deviceInvPath, |
| 579 | std::move(createI2CInterface())}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 580 | EXPECT_EQ(device.getID(), "vdd_reg"); |
| 581 | } |
| 582 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 583 | TEST_F(DeviceTests, GetPhaseFaultDetection) |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 584 | { |
| 585 | // Test where PhaseFaultDetection was not specified in constructor |
| 586 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 587 | Device device{"vdd_reg", true, deviceInvPath, |
| 588 | std::move(createI2CInterface())}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 589 | EXPECT_EQ(device.getPhaseFaultDetection(), nullptr); |
| 590 | } |
| 591 | |
| 592 | // Test where PhaseFaultDetection was specified in constructor |
| 593 | { |
| 594 | // Create PhaseFaultDetection |
| 595 | std::vector<std::unique_ptr<Action>> actions{}; |
| 596 | actions.push_back(std::make_unique<MockAction>()); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 597 | auto phaseFaultDetection = |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 598 | std::make_unique<PhaseFaultDetection>(std::move(actions)); |
| 599 | |
| 600 | // Create Device |
| 601 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 602 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 603 | Device device{"vdd_reg", |
| 604 | false, |
| 605 | deviceInvPath, |
| 606 | std::move(createI2CInterface()), |
| 607 | std::move(presenceDetection), |
| 608 | std::move(configuration), |
| 609 | std::move(phaseFaultDetection)}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 610 | EXPECT_NE(device.getPhaseFaultDetection(), nullptr); |
| 611 | EXPECT_EQ(device.getPhaseFaultDetection()->getActions().size(), 1); |
| 612 | } |
| 613 | } |
| 614 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 615 | TEST_F(DeviceTests, GetPresenceDetection) |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 616 | { |
| 617 | // Test where PresenceDetection was not specified in constructor |
| 618 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 619 | Device device{"vdd_reg", true, deviceInvPath, |
| 620 | std::move(createI2CInterface())}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 621 | EXPECT_EQ(device.getPresenceDetection(), nullptr); |
| 622 | } |
| 623 | |
| 624 | // Test where PresenceDetection was specified in constructor |
| 625 | { |
| 626 | // Create PresenceDetection |
| 627 | std::vector<std::unique_ptr<Action>> actions{}; |
| 628 | actions.push_back(std::make_unique<MockAction>()); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 629 | auto presenceDetection = |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 630 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 631 | |
| 632 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 633 | Device device{"vdd_reg", false, deviceInvPath, |
| 634 | std::move(createI2CInterface()), |
| 635 | std::move(presenceDetection)}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 636 | EXPECT_NE(device.getPresenceDetection(), nullptr); |
| 637 | EXPECT_EQ(device.getPresenceDetection()->getActions().size(), 1); |
| 638 | } |
| 639 | } |
| 640 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 641 | TEST_F(DeviceTests, GetRails) |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 642 | { |
| 643 | // Test where no rails were specified in constructor |
| 644 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 645 | Device device{"vdd_reg", true, deviceInvPath, |
| 646 | std::move(createI2CInterface())}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 647 | EXPECT_EQ(device.getRails().size(), 0); |
| 648 | } |
| 649 | |
| 650 | // Test where rails were specified in constructor |
| 651 | { |
| 652 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 653 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 654 | std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 655 | |
| 656 | // Create vector of Rail objects |
| 657 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 658 | rails.push_back(std::make_unique<Rail>("vdd0")); |
| 659 | rails.push_back(std::make_unique<Rail>("vdd1")); |
| 660 | |
| 661 | // Create Device |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 662 | Device device{"vdd_reg", |
| 663 | false, |
| 664 | deviceInvPath, |
| 665 | std::move(createI2CInterface()), |
| 666 | std::move(presenceDetection), |
| 667 | std::move(configuration), |
| 668 | std::move(phaseFaultDetection), |
| 669 | std::move(rails)}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 670 | EXPECT_EQ(device.getRails().size(), 2); |
| 671 | EXPECT_EQ(device.getRails()[0]->getID(), "vdd0"); |
| 672 | EXPECT_EQ(device.getRails()[1]->getID(), "vdd1"); |
| 673 | } |
| 674 | } |
| 675 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 676 | TEST_F(DeviceTests, IsPresent) |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 677 | { |
| 678 | // Test where PresenceDetection not specified in constructor |
| 679 | { |
| 680 | // Create Device |
| 681 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 682 | Device device{"reg2", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 683 | |
| 684 | // Create MockServices |
| 685 | MockServices services{}; |
| 686 | |
| 687 | // Since no PresenceDetection defined, isPresent() should return true |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 688 | EXPECT_TRUE(device.isPresent(services, *system, *chassis)); |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | // Test where PresenceDetection was specified in constructor: Is present |
| 692 | { |
| 693 | // Create PresenceDetection. Indicates device is present. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 694 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 695 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 696 | std::vector<std::unique_ptr<Action>> actions{}; |
| 697 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 698 | auto presenceDetection = |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 699 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 700 | |
| 701 | // Create Device |
| 702 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 703 | Device device{"reg2", true, deviceInvPath, std::move(i2cInterface), |
| 704 | std::move(presenceDetection)}; |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 705 | |
| 706 | // Create MockServices |
| 707 | MockServices services{}; |
| 708 | |
| 709 | // PresenceDetection::execute() and isPresent() should return true |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 710 | EXPECT_TRUE(device.isPresent(services, *system, *chassis)); |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | // Test where PresenceDetection was specified in constructor: Is not present |
| 714 | { |
| 715 | // Create PresenceDetection. Indicates device is not present. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 716 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 717 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(false)); |
| 718 | std::vector<std::unique_ptr<Action>> actions{}; |
| 719 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 720 | auto presenceDetection = |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 721 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 722 | |
| 723 | // Create Device |
| 724 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 725 | Device device{"reg2", true, deviceInvPath, std::move(i2cInterface), |
| 726 | std::move(presenceDetection)}; |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 727 | |
| 728 | // Create MockServices |
| 729 | MockServices services{}; |
| 730 | |
| 731 | // PresenceDetection::execute() and isPresent() should return false |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 732 | EXPECT_FALSE(device.isPresent(services, *system, *chassis)); |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 736 | TEST_F(DeviceTests, IsRegulator) |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 737 | { |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 738 | Device device{"vdd_reg", false, deviceInvPath, |
| 739 | std::move(createI2CInterface())}; |
Shawn McCarney | 0b1a0e7 | 2020-03-11 18:01:44 -0500 | [diff] [blame] | 740 | EXPECT_EQ(device.isRegulator(), false); |
| 741 | } |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 742 | |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 743 | TEST_F(DeviceTests, MonitorSensors) |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 744 | { |
Shawn McCarney | 48033bf | 2021-01-27 17:56:49 -0600 | [diff] [blame] | 745 | // Test where device is not present |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 746 | { |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 747 | // Create mock services. No Sensors methods should be called. |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 748 | MockServices services{}; |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 749 | MockSensors& sensors = services.getMockSensors(); |
| 750 | EXPECT_CALL(sensors, startRail).Times(0); |
| 751 | EXPECT_CALL(sensors, setValue).Times(0); |
| 752 | EXPECT_CALL(sensors, endRail).Times(0); |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 753 | |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 754 | // Create SensorMonitoring. Action inside it should not be executed. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 755 | std::unique_ptr<SensorMonitoring> sensorMonitoring{}; |
| 756 | { |
| 757 | auto action = std::make_unique<MockAction>(); |
| 758 | EXPECT_CALL(*action, execute).Times(0); |
| 759 | std::vector<std::unique_ptr<Action>> actions{}; |
| 760 | actions.emplace_back(std::move(action)); |
| 761 | sensorMonitoring = |
| 762 | std::make_unique<SensorMonitoring>(std::move(actions)); |
| 763 | } |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 764 | |
| 765 | // Create Rail |
| 766 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 767 | auto rail = std::make_unique<Rail>("vddr1", std::move(configuration), |
| 768 | std::move(sensorMonitoring)); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 769 | |
| 770 | // Create PresenceDetection. Indicates device is not present. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 771 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 772 | { |
| 773 | auto action = std::make_unique<MockAction>(); |
| 774 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(false)); |
| 775 | std::vector<std::unique_ptr<Action>> actions{}; |
| 776 | actions.emplace_back(std::move(action)); |
| 777 | presenceDetection = |
| 778 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 779 | } |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 780 | |
| 781 | // Create Device |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 782 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 783 | std::unique_ptr<Configuration> deviceConfiguration{}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 784 | std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{}; |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 785 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 786 | rails.emplace_back(std::move(rail)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 787 | Device device{"reg2", |
| 788 | true, |
| 789 | deviceInvPath, |
| 790 | std::move(i2cInterface), |
| 791 | std::move(presenceDetection), |
| 792 | std::move(deviceConfiguration), |
| 793 | std::move(phaseFaultDetection), |
| 794 | std::move(rails)}; |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 795 | |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 796 | // Call monitorSensors(). Should do nothing. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 797 | device.monitorSensors(services, *system, *chassis); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | // Test where Rails were not specified in constructor |
| 801 | { |
| 802 | // Create mock services. No Sensors methods should be called. |
| 803 | MockServices services{}; |
| 804 | MockSensors& sensors = services.getMockSensors(); |
| 805 | EXPECT_CALL(sensors, startRail).Times(0); |
| 806 | EXPECT_CALL(sensors, setValue).Times(0); |
| 807 | EXPECT_CALL(sensors, endRail).Times(0); |
| 808 | |
| 809 | // Create Device |
| 810 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 811 | Device device{"reg2", true, deviceInvPath, std::move(i2cInterface)}; |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 812 | |
| 813 | // Call monitorSensors(). Should do nothing. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 814 | device.monitorSensors(services, *system, *chassis); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | // Test where Rails were specified in constructor |
| 818 | { |
| 819 | // Create mock services. Set Sensors service expectations. |
| 820 | MockServices services{}; |
| 821 | MockSensors& sensors = services.getMockSensors(); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 822 | EXPECT_CALL(sensors, startRail("vdd0", deviceInvPath, chassisInvPath)) |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 823 | .Times(1); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 824 | EXPECT_CALL(sensors, startRail("vio0", deviceInvPath, chassisInvPath)) |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 825 | .Times(1); |
| 826 | EXPECT_CALL(sensors, setValue).Times(0); |
| 827 | EXPECT_CALL(sensors, endRail(false)).Times(2); |
| 828 | |
| 829 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 830 | |
| 831 | // Create Rail vdd0 |
| 832 | { |
| 833 | // Create SensorMonitoring for Rail |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 834 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 835 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 836 | std::vector<std::unique_ptr<Action>> actions{}; |
| 837 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 838 | auto sensorMonitoring = |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 839 | std::make_unique<SensorMonitoring>(std::move(actions)); |
| 840 | |
| 841 | // Create Rail |
| 842 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 843 | auto rail = std::make_unique<Rail>("vdd0", std::move(configuration), |
| 844 | std::move(sensorMonitoring)); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 845 | rails.emplace_back(std::move(rail)); |
| 846 | } |
| 847 | |
| 848 | // Create Rail vio0 |
| 849 | { |
| 850 | // Create SensorMonitoring for Rail |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 851 | auto action = std::make_unique<MockAction>(); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 852 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 853 | std::vector<std::unique_ptr<Action>> actions{}; |
| 854 | actions.emplace_back(std::move(action)); |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 855 | auto sensorMonitoring = |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 856 | std::make_unique<SensorMonitoring>(std::move(actions)); |
| 857 | |
| 858 | // Create Rail |
| 859 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 860 | auto rail = std::make_unique<Rail>("vio0", std::move(configuration), |
| 861 | std::move(sensorMonitoring)); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 862 | rails.emplace_back(std::move(rail)); |
| 863 | } |
| 864 | |
| 865 | // Create Device that contains Rails |
| 866 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 867 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 868 | std::unique_ptr<Configuration> configuration{}; |
Shawn McCarney | 3225259 | 2021-09-08 15:29:36 -0500 | [diff] [blame] | 869 | std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{}; |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 870 | Device device{"reg2", |
| 871 | true, |
| 872 | deviceInvPath, |
| 873 | std::move(i2cInterface), |
| 874 | std::move(presenceDetection), |
| 875 | std::move(configuration), |
| 876 | std::move(phaseFaultDetection), |
| 877 | std::move(rails)}; |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 878 | |
| 879 | // Call monitorSensors(). Should monitor sensors in both rails. |
Shawn McCarney | 2874e90 | 2021-09-09 10:03:59 -0500 | [diff] [blame^] | 880 | device.monitorSensors(services, *system, *chassis); |
Bob King | 8e1cd0b | 2020-07-08 13:30:27 +0800 | [diff] [blame] | 881 | } |
| 882 | } |