Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 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 | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 16 | #include "action.hpp" |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 17 | #include "chassis.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 18 | #include "configuration.hpp" |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 19 | #include "device.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [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 | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 22 | #include "mock_action.hpp" |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 23 | #include "mock_journal.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 24 | #include "mock_sensors.hpp" |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 25 | #include "mock_services.hpp" |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 26 | #include "mocked_i2c_interface.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 27 | #include "presence_detection.hpp" |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 28 | #include "rail.hpp" |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 29 | #include "rule.hpp" |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 30 | #include "sensor_monitoring.hpp" |
Shawn McCarney | 2f9e14f | 2021-04-29 02:45:18 -0500 | [diff] [blame] | 31 | #include "sensors.hpp" |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 32 | #include "services.hpp" |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 33 | #include "system.hpp" |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 34 | #include "test_utils.hpp" |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 35 | |
| 36 | #include <memory> |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 37 | #include <stdexcept> |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 38 | #include <string> |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 39 | #include <utility> |
| 40 | #include <vector> |
| 41 | |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 42 | #include <gmock/gmock.h> |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 43 | #include <gtest/gtest.h> |
| 44 | |
| 45 | using namespace phosphor::power::regulators; |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 46 | using namespace phosphor::power::regulators::test_utils; |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 47 | |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 48 | using ::testing::A; |
| 49 | using ::testing::Return; |
| 50 | using ::testing::TypedEq; |
| 51 | |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 52 | static const std::string chassisInvPath{ |
| 53 | "/xyz/openbmc_project/inventory/system/chassis"}; |
| 54 | |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 55 | TEST(SystemTests, Constructor) |
| 56 | { |
| 57 | // Create Rules |
| 58 | std::vector<std::unique_ptr<Rule>> rules{}; |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 59 | rules.emplace_back(createRule("set_voltage_rule")); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 60 | |
| 61 | // Create Chassis |
| 62 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 63 | std::vector<std::unique_ptr<Device>> devices{}; |
| 64 | devices.emplace_back(createDevice("reg1", {"rail1"})); |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 65 | chassis.emplace_back( |
| 66 | std::make_unique<Chassis>(1, chassisInvPath, std::move(devices))); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 67 | |
| 68 | // Create System |
| 69 | System system{std::move(rules), std::move(chassis)}; |
| 70 | EXPECT_EQ(system.getChassis().size(), 1); |
| 71 | EXPECT_EQ(system.getChassis()[0]->getNumber(), 1); |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 72 | EXPECT_NO_THROW(system.getIDMap().getRule("set_voltage_rule")); |
| 73 | EXPECT_NO_THROW(system.getIDMap().getDevice("reg1")); |
| 74 | EXPECT_NO_THROW(system.getIDMap().getRail("rail1")); |
| 75 | EXPECT_THROW(system.getIDMap().getRail("rail2"), std::invalid_argument); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 76 | EXPECT_EQ(system.getRules().size(), 1); |
| 77 | EXPECT_EQ(system.getRules()[0]->getID(), "set_voltage_rule"); |
| 78 | } |
| 79 | |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 80 | TEST(SystemTests, ClearCache) |
| 81 | { |
| 82 | // Create PresenceDetection |
| 83 | std::vector<std::unique_ptr<Action>> actions{}; |
| 84 | std::unique_ptr<PresenceDetection> presenceDetection = |
| 85 | std::make_unique<PresenceDetection>(std::move(actions)); |
| 86 | PresenceDetection* presenceDetectionPtr = presenceDetection.get(); |
| 87 | |
| 88 | // Create Device that contains PresenceDetection |
| 89 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 90 | std::unique_ptr<Device> device = std::make_unique<Device>( |
| 91 | "reg1", true, |
| 92 | "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1", |
| 93 | std::move(i2cInterface), std::move(presenceDetection)); |
| 94 | Device* devicePtr = device.get(); |
| 95 | |
| 96 | // Create Chassis that contains Device |
| 97 | std::vector<std::unique_ptr<Device>> devices{}; |
| 98 | devices.emplace_back(std::move(device)); |
| 99 | std::unique_ptr<Chassis> chassis = |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 100 | std::make_unique<Chassis>(1, chassisInvPath, std::move(devices)); |
Shawn McCarney | 9bd94d3 | 2021-01-25 19:40:42 -0600 | [diff] [blame] | 101 | Chassis* chassisPtr = chassis.get(); |
| 102 | |
| 103 | // Create System that contains Chassis |
| 104 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 105 | std::vector<std::unique_ptr<Chassis>> chassisVec{}; |
| 106 | chassisVec.emplace_back(std::move(chassis)); |
| 107 | System system{std::move(rules), std::move(chassisVec)}; |
| 108 | |
| 109 | // Cache presence value in PresenceDetection |
| 110 | MockServices services{}; |
| 111 | presenceDetectionPtr->execute(services, system, *chassisPtr, *devicePtr); |
| 112 | EXPECT_TRUE(presenceDetectionPtr->getCachedPresence().has_value()); |
| 113 | |
| 114 | // Clear cached data in System |
| 115 | system.clearCache(); |
| 116 | |
| 117 | // Verify presence value no longer cached in PresenceDetection |
| 118 | EXPECT_FALSE(presenceDetectionPtr->getCachedPresence().has_value()); |
| 119 | } |
| 120 | |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 121 | TEST(SystemTests, CloseDevices) |
| 122 | { |
| 123 | // Specify an empty rules vector |
| 124 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 125 | |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 126 | // Create mock services. Expect logDebug() to be called. |
| 127 | MockServices services{}; |
| 128 | MockJournal& journal = services.getMockJournal(); |
| 129 | EXPECT_CALL(journal, logDebug("Closing devices in chassis 1")).Times(1); |
| 130 | EXPECT_CALL(journal, logDebug("Closing devices in chassis 3")).Times(1); |
| 131 | EXPECT_CALL(journal, logInfo(A<const std::string&>())).Times(0); |
| 132 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0); |
| 133 | |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 134 | // Create Chassis |
| 135 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 136 | chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1')); |
| 137 | chassis.emplace_back(std::make_unique<Chassis>(3, chassisInvPath + '3')); |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 138 | |
| 139 | // Create System |
| 140 | System system{std::move(rules), std::move(chassis)}; |
| 141 | |
| 142 | // Call closeDevices() |
Bob King | d692d6d | 2020-09-14 13:42:57 +0800 | [diff] [blame] | 143 | system.closeDevices(services); |
Shawn McCarney | 5b19ea5 | 2020-06-02 18:52:56 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 146 | TEST(SystemTests, Configure) |
| 147 | { |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 148 | // Create mock services. Expect logInfo() to be called. |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 149 | MockServices services{}; |
Bob King | 5cfe510 | 2020-07-30 16:26:18 +0800 | [diff] [blame] | 150 | MockJournal& journal = services.getMockJournal(); |
| 151 | EXPECT_CALL(journal, logInfo("Configuring chassis 1")).Times(1); |
| 152 | EXPECT_CALL(journal, logInfo("Configuring chassis 3")).Times(1); |
| 153 | EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0); |
| 154 | EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0); |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 155 | |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 156 | // Specify an empty rules vector |
| 157 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 158 | |
| 159 | // Create Chassis |
| 160 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 161 | chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1')); |
| 162 | chassis.emplace_back(std::make_unique<Chassis>(3, chassisInvPath + '3')); |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 163 | |
| 164 | // Create System |
| 165 | System system{std::move(rules), std::move(chassis)}; |
| 166 | |
| 167 | // Call configure() |
Bob King | 23243f8 | 2020-07-29 10:38:57 +0800 | [diff] [blame] | 168 | system.configure(services); |
Shawn McCarney | 2af5289 | 2020-04-14 11:54:45 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 171 | TEST(SystemTests, GetChassis) |
| 172 | { |
| 173 | // Specify an empty rules vector |
| 174 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 175 | |
| 176 | // Create Chassis |
| 177 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 178 | chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1')); |
| 179 | chassis.emplace_back(std::make_unique<Chassis>(3, chassisInvPath + '3')); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 180 | |
| 181 | // Create System |
| 182 | System system{std::move(rules), std::move(chassis)}; |
| 183 | EXPECT_EQ(system.getChassis().size(), 2); |
| 184 | EXPECT_EQ(system.getChassis()[0]->getNumber(), 1); |
| 185 | EXPECT_EQ(system.getChassis()[1]->getNumber(), 3); |
| 186 | } |
| 187 | |
| 188 | TEST(SystemTests, GetIDMap) |
| 189 | { |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 190 | // Create Rules |
| 191 | std::vector<std::unique_ptr<Rule>> rules{}; |
| 192 | rules.emplace_back(createRule("set_voltage_rule")); |
| 193 | rules.emplace_back(createRule("read_sensors_rule")); |
| 194 | |
| 195 | // Create Chassis |
| 196 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
| 197 | { |
| 198 | // Chassis 1 |
| 199 | std::vector<std::unique_ptr<Device>> devices{}; |
| 200 | devices.emplace_back(createDevice("reg1", {"rail1"})); |
| 201 | devices.emplace_back(createDevice("reg2", {"rail2a", "rail2b"})); |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 202 | chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1', |
| 203 | std::move(devices))); |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 204 | } |
| 205 | { |
| 206 | // Chassis 2 |
| 207 | std::vector<std::unique_ptr<Device>> devices{}; |
| 208 | devices.emplace_back(createDevice("reg3", {"rail3a", "rail3b"})); |
| 209 | devices.emplace_back(createDevice("reg4")); |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 210 | chassis.emplace_back(std::make_unique<Chassis>(2, chassisInvPath + '2', |
| 211 | std::move(devices))); |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | // Create System |
| 215 | System system{std::move(rules), std::move(chassis)}; |
| 216 | const IDMap& idMap = system.getIDMap(); |
| 217 | |
| 218 | // Verify all Rules are in the IDMap |
| 219 | EXPECT_NO_THROW(idMap.getRule("set_voltage_rule")); |
| 220 | EXPECT_NO_THROW(idMap.getRule("read_sensors_rule")); |
| 221 | EXPECT_THROW(idMap.getRule("set_voltage_rule2"), std::invalid_argument); |
| 222 | |
| 223 | // Verify all Devices are in the IDMap |
| 224 | EXPECT_NO_THROW(idMap.getDevice("reg1")); |
| 225 | EXPECT_NO_THROW(idMap.getDevice("reg2")); |
| 226 | EXPECT_NO_THROW(idMap.getDevice("reg3")); |
| 227 | EXPECT_NO_THROW(idMap.getDevice("reg4")); |
| 228 | EXPECT_THROW(idMap.getDevice("reg5"), std::invalid_argument); |
| 229 | |
| 230 | // Verify all Rails are in the IDMap |
| 231 | EXPECT_NO_THROW(idMap.getRail("rail1")); |
| 232 | EXPECT_NO_THROW(idMap.getRail("rail2a")); |
| 233 | EXPECT_NO_THROW(idMap.getRail("rail2b")); |
| 234 | EXPECT_NO_THROW(idMap.getRail("rail3a")); |
| 235 | EXPECT_NO_THROW(idMap.getRail("rail3b")); |
| 236 | EXPECT_THROW(idMap.getRail("rail4"), std::invalid_argument); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | TEST(SystemTests, GetRules) |
| 240 | { |
| 241 | // Create Rules |
| 242 | std::vector<std::unique_ptr<Rule>> rules{}; |
Shawn McCarney | db0b833 | 2020-04-06 14:13:04 -0500 | [diff] [blame] | 243 | rules.emplace_back(createRule("set_voltage_rule")); |
| 244 | rules.emplace_back(createRule("read_sensors_rule")); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 245 | |
| 246 | // Create Chassis |
| 247 | std::vector<std::unique_ptr<Chassis>> chassis{}; |
Shawn McCarney | cb3f6a6 | 2021-04-30 10:54:30 -0500 | [diff] [blame] | 248 | chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath)); |
Shawn McCarney | c3991f1 | 2020-04-05 13:16:06 -0500 | [diff] [blame] | 249 | |
| 250 | // Create System |
| 251 | System system{std::move(rules), std::move(chassis)}; |
| 252 | EXPECT_EQ(system.getRules().size(), 2); |
| 253 | EXPECT_EQ(system.getRules()[0]->getID(), "set_voltage_rule"); |
| 254 | EXPECT_EQ(system.getRules()[1]->getID(), "read_sensors_rule"); |
| 255 | } |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 256 | |
| 257 | TEST(SystemTests, MonitorSensors) |
| 258 | { |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 259 | // Create mock services. Set Sensors service expectations. |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 260 | MockServices services{}; |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 261 | MockSensors& sensors = services.getMockSensors(); |
| 262 | EXPECT_CALL(sensors, startRail("c1_vdd0", |
| 263 | "/xyz/openbmc_project/inventory/system/" |
| 264 | "chassis1/motherboard/vdd0_reg", |
| 265 | chassisInvPath + '1')) |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 266 | .Times(1); |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 267 | EXPECT_CALL(sensors, startRail("c2_vdd0", |
| 268 | "/xyz/openbmc_project/inventory/system/" |
| 269 | "chassis2/motherboard/vdd0_reg", |
| 270 | chassisInvPath + '2')) |
| 271 | .Times(1); |
| 272 | EXPECT_CALL(sensors, setValue).Times(0); |
| 273 | EXPECT_CALL(sensors, endRail(false)).Times(2); |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 274 | |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 275 | std::vector<std::unique_ptr<Chassis>> chassisVec{}; |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 276 | |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 277 | // Create Chassis 1 |
| 278 | { |
| 279 | // Create SensorMonitoring for Rail |
| 280 | std::unique_ptr<MockAction> action = std::make_unique<MockAction>(); |
| 281 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 282 | std::vector<std::unique_ptr<Action>> actions{}; |
| 283 | actions.emplace_back(std::move(action)); |
| 284 | std::unique_ptr<SensorMonitoring> sensorMonitoring = |
| 285 | std::make_unique<SensorMonitoring>(std::move(actions)); |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 286 | |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 287 | // Create Rail |
| 288 | std::unique_ptr<Configuration> configuration{}; |
| 289 | std::unique_ptr<Rail> rail = std::make_unique<Rail>( |
| 290 | "c1_vdd0", std::move(configuration), std::move(sensorMonitoring)); |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 291 | |
Shawn McCarney | 17bac89 | 2021-05-08 07:55:52 -0500 | [diff] [blame] | 292 | // Create Device |
| 293 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 294 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 295 | std::unique_ptr<Configuration> deviceConfiguration{}; |
| 296 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 297 | rails.emplace_back(std::move(rail)); |
| 298 | std::unique_ptr<Device> device = std::make_unique<Device>( |
| 299 | "c1_vdd0_reg", true, |
| 300 | "/xyz/openbmc_project/inventory/system/chassis1/motherboard/" |
| 301 | "vdd0_reg", |
| 302 | std::move(i2cInterface), std::move(presenceDetection), |
| 303 | std::move(deviceConfiguration), std::move(rails)); |
| 304 | |
| 305 | // Create Chassis |
| 306 | std::vector<std::unique_ptr<Device>> devices{}; |
| 307 | devices.emplace_back(std::move(device)); |
| 308 | std::unique_ptr<Chassis> chassis = std::make_unique<Chassis>( |
| 309 | 1, chassisInvPath + '1', std::move(devices)); |
| 310 | chassisVec.emplace_back(std::move(chassis)); |
| 311 | } |
| 312 | |
| 313 | // Create Chassis 2 |
| 314 | { |
| 315 | // Create SensorMonitoring for Rail |
| 316 | std::unique_ptr<MockAction> action = std::make_unique<MockAction>(); |
| 317 | EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true)); |
| 318 | std::vector<std::unique_ptr<Action>> actions{}; |
| 319 | actions.emplace_back(std::move(action)); |
| 320 | std::unique_ptr<SensorMonitoring> sensorMonitoring = |
| 321 | std::make_unique<SensorMonitoring>(std::move(actions)); |
| 322 | |
| 323 | // Create Rail |
| 324 | std::unique_ptr<Configuration> configuration{}; |
| 325 | std::unique_ptr<Rail> rail = std::make_unique<Rail>( |
| 326 | "c2_vdd0", std::move(configuration), std::move(sensorMonitoring)); |
| 327 | |
| 328 | // Create Device |
| 329 | std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface(); |
| 330 | std::unique_ptr<PresenceDetection> presenceDetection{}; |
| 331 | std::unique_ptr<Configuration> deviceConfiguration{}; |
| 332 | std::vector<std::unique_ptr<Rail>> rails{}; |
| 333 | rails.emplace_back(std::move(rail)); |
| 334 | std::unique_ptr<Device> device = std::make_unique<Device>( |
| 335 | "c2_vdd0_reg", true, |
| 336 | "/xyz/openbmc_project/inventory/system/chassis2/motherboard/" |
| 337 | "vdd0_reg", |
| 338 | std::move(i2cInterface), std::move(presenceDetection), |
| 339 | std::move(deviceConfiguration), std::move(rails)); |
| 340 | |
| 341 | // Create Chassis |
| 342 | std::vector<std::unique_ptr<Device>> devices{}; |
| 343 | devices.emplace_back(std::move(device)); |
| 344 | std::unique_ptr<Chassis> chassis = std::make_unique<Chassis>( |
| 345 | 2, chassisInvPath + '2', std::move(devices)); |
| 346 | chassisVec.emplace_back(std::move(chassis)); |
| 347 | } |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 348 | |
| 349 | // Create System that contains Chassis |
| 350 | std::vector<std::unique_ptr<Rule>> rules{}; |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 351 | System system{std::move(rules), std::move(chassisVec)}; |
| 352 | |
| 353 | // Call monitorSensors() |
Bob King | 8a55292 | 2020-08-05 17:02:31 +0800 | [diff] [blame] | 354 | system.monitorSensors(services); |
Bob King | 8e2294d | 2020-07-14 17:41:31 +0800 | [diff] [blame] | 355 | } |