blob: 53127bb18be7b8a4c455eed94af5c4adab8d3221 [file] [log] [blame]
Shawn McCarneyc3991f12020-04-05 13:16:06 -05001/**
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 McCarney17bac892021-05-08 07:55:52 -050016#include "action.hpp"
Shawn McCarneyc3991f12020-04-05 13:16:06 -050017#include "chassis.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050018#include "configuration.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050019#include "device.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050020#include "i2c_interface.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050021#include "id_map.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050022#include "mock_action.hpp"
Shawn McCarney23b0d0d2021-05-14 15:27:59 -050023#include "mock_error_logging.hpp"
Shawn McCarney2af52892020-04-14 11:54:45 -050024#include "mock_journal.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050025#include "mock_sensors.hpp"
Bob King23243f82020-07-29 10:38:57 +080026#include "mock_services.hpp"
Bob King8e2294d2020-07-14 17:41:31 +080027#include "mocked_i2c_interface.hpp"
Shawn McCarney32252592021-09-08 15:29:36 -050028#include "phase_fault_detection.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050029#include "presence_detection.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050030#include "rail.hpp"
Shawn McCarneyc3991f12020-04-05 13:16:06 -050031#include "rule.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050032#include "sensor_monitoring.hpp"
Shawn McCarney2f9e14f2021-04-29 02:45:18 -050033#include "sensors.hpp"
Bob King5cfe5102020-07-30 16:26:18 +080034#include "services.hpp"
Shawn McCarneyc3991f12020-04-05 13:16:06 -050035#include "system.hpp"
Shawn McCarney23b0d0d2021-05-14 15:27:59 -050036#include "test_sdbus_error.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050037#include "test_utils.hpp"
Shawn McCarneyc3991f12020-04-05 13:16:06 -050038
39#include <memory>
Shawn McCarneydb0b8332020-04-06 14:13:04 -050040#include <stdexcept>
Shawn McCarney2af52892020-04-14 11:54:45 -050041#include <string>
Shawn McCarneyc3991f12020-04-05 13:16:06 -050042#include <utility>
43#include <vector>
44
Bob King8e2294d2020-07-14 17:41:31 +080045#include <gmock/gmock.h>
Shawn McCarneyc3991f12020-04-05 13:16:06 -050046#include <gtest/gtest.h>
47
48using namespace phosphor::power::regulators;
Shawn McCarneydb0b8332020-04-06 14:13:04 -050049using namespace phosphor::power::regulators::test_utils;
Shawn McCarneyc3991f12020-04-05 13:16:06 -050050
Bob King8e2294d2020-07-14 17:41:31 +080051using ::testing::A;
52using ::testing::Return;
Shawn McCarney23b0d0d2021-05-14 15:27:59 -050053using ::testing::Throw;
Bob King8e2294d2020-07-14 17:41:31 +080054using ::testing::TypedEq;
55
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050056static const std::string chassisInvPath{
57 "/xyz/openbmc_project/inventory/system/chassis"};
58
Shawn McCarneyc3991f12020-04-05 13:16:06 -050059TEST(SystemTests, Constructor)
60{
61 // Create Rules
62 std::vector<std::unique_ptr<Rule>> rules{};
Shawn McCarneydb0b8332020-04-06 14:13:04 -050063 rules.emplace_back(createRule("set_voltage_rule"));
Shawn McCarneyc3991f12020-04-05 13:16:06 -050064
65 // Create Chassis
66 std::vector<std::unique_ptr<Chassis>> chassis{};
Shawn McCarneydb0b8332020-04-06 14:13:04 -050067 std::vector<std::unique_ptr<Device>> devices{};
68 devices.emplace_back(createDevice("reg1", {"rail1"}));
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050069 chassis.emplace_back(
70 std::make_unique<Chassis>(1, chassisInvPath, std::move(devices)));
Shawn McCarneyc3991f12020-04-05 13:16:06 -050071
72 // Create System
73 System system{std::move(rules), std::move(chassis)};
74 EXPECT_EQ(system.getChassis().size(), 1);
75 EXPECT_EQ(system.getChassis()[0]->getNumber(), 1);
Shawn McCarneydb0b8332020-04-06 14:13:04 -050076 EXPECT_NO_THROW(system.getIDMap().getRule("set_voltage_rule"));
77 EXPECT_NO_THROW(system.getIDMap().getDevice("reg1"));
78 EXPECT_NO_THROW(system.getIDMap().getRail("rail1"));
79 EXPECT_THROW(system.getIDMap().getRail("rail2"), std::invalid_argument);
Shawn McCarneyc3991f12020-04-05 13:16:06 -050080 EXPECT_EQ(system.getRules().size(), 1);
81 EXPECT_EQ(system.getRules()[0]->getID(), "set_voltage_rule");
82}
83
Shawn McCarney9bd94d32021-01-25 19:40:42 -060084TEST(SystemTests, ClearCache)
85{
86 // Create PresenceDetection
87 std::vector<std::unique_ptr<Action>> actions{};
Shawn McCarneya3fecef2021-09-09 23:15:35 -050088 auto presenceDetection =
Shawn McCarney9bd94d32021-01-25 19:40:42 -060089 std::make_unique<PresenceDetection>(std::move(actions));
90 PresenceDetection* presenceDetectionPtr = presenceDetection.get();
91
92 // Create Device that contains PresenceDetection
Shawn McCarneya3fecef2021-09-09 23:15:35 -050093 auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>();
94 auto device = std::make_unique<Device>(
Shawn McCarney9bd94d32021-01-25 19:40:42 -060095 "reg1", true,
96 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
97 std::move(i2cInterface), std::move(presenceDetection));
98 Device* devicePtr = device.get();
99
100 // Create Chassis that contains Device
101 std::vector<std::unique_ptr<Device>> devices{};
102 devices.emplace_back(std::move(device));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500103 auto chassis =
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500104 std::make_unique<Chassis>(1, chassisInvPath, std::move(devices));
Shawn McCarney9bd94d32021-01-25 19:40:42 -0600105 Chassis* chassisPtr = chassis.get();
106
107 // Create System that contains Chassis
108 std::vector<std::unique_ptr<Rule>> rules{};
109 std::vector<std::unique_ptr<Chassis>> chassisVec{};
110 chassisVec.emplace_back(std::move(chassis));
111 System system{std::move(rules), std::move(chassisVec)};
112
113 // Cache presence value in PresenceDetection
114 MockServices services{};
115 presenceDetectionPtr->execute(services, system, *chassisPtr, *devicePtr);
116 EXPECT_TRUE(presenceDetectionPtr->getCachedPresence().has_value());
117
118 // Clear cached data in System
119 system.clearCache();
120
121 // Verify presence value no longer cached in PresenceDetection
122 EXPECT_FALSE(presenceDetectionPtr->getCachedPresence().has_value());
123}
124
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500125TEST(SystemTests, ClearErrorHistory)
126{
127 // Create SensorMonitoring. Will fail with a DBus exception.
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500128 auto action = std::make_unique<MockAction>();
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500129 EXPECT_CALL(*action, execute)
130 .WillRepeatedly(Throw(TestSDBusError{"Unable to set sensor value"}));
131 std::vector<std::unique_ptr<Action>> actions{};
132 actions.emplace_back(std::move(action));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500133 auto sensorMonitoring =
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500134 std::make_unique<SensorMonitoring>(std::move(actions));
135
136 // Create Rail
137 std::unique_ptr<Configuration> configuration{};
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500138 auto rail = std::make_unique<Rail>("vddr1", std::move(configuration),
139 std::move(sensorMonitoring));
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500140
141 // Create Device that contains Rail
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500142 auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>();
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500143 std::unique_ptr<PresenceDetection> presenceDetection{};
144 std::unique_ptr<Configuration> deviceConfiguration{};
Shawn McCarney32252592021-09-08 15:29:36 -0500145 std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{};
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500146 std::vector<std::unique_ptr<Rail>> rails{};
147 rails.emplace_back(std::move(rail));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500148 auto device = std::make_unique<Device>(
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500149 "reg1", true,
150 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
151 std::move(i2cInterface), std::move(presenceDetection),
Shawn McCarney32252592021-09-08 15:29:36 -0500152 std::move(deviceConfiguration), std::move(phaseFaultDetection),
153 std::move(rails));
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500154
155 // Create Chassis that contains Device
156 std::vector<std::unique_ptr<Device>> devices{};
157 devices.emplace_back(std::move(device));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500158 auto chassis =
Shawn McCarney23b0d0d2021-05-14 15:27:59 -0500159 std::make_unique<Chassis>(1, chassisInvPath, std::move(devices));
160
161 // Create System that contains Chassis
162 std::vector<std::unique_ptr<Rule>> rules{};
163 std::vector<std::unique_ptr<Chassis>> chassisVec{};
164 chassisVec.emplace_back(std::move(chassis));
165 System system{std::move(rules), std::move(chassisVec)};
166
167 // Create mock services
168 MockServices services{};
169
170 // Expect Sensors service to be called 5+5=10 times
171 MockSensors& sensors = services.getMockSensors();
172 EXPECT_CALL(sensors, startRail).Times(10);
173 EXPECT_CALL(sensors, setValue).Times(0);
174 EXPECT_CALL(sensors, endRail).Times(10);
175
176 // Expect Journal service to be called 3+3=6 times to log error messages
177 MockJournal& journal = services.getMockJournal();
178 EXPECT_CALL(journal, logError(A<const std::vector<std::string>&>()))
179 .Times(6);
180 EXPECT_CALL(journal, logError(A<const std::string&>())).Times(6);
181
182 // Expect ErrorLogging service to be called 1+1=2 times to log a DBus error
183 MockErrorLogging& errorLogging = services.getMockErrorLogging();
184 EXPECT_CALL(errorLogging, logDBusError).Times(2);
185
186 // Monitor sensors 5 times. Should fail every time, write to journal 3
187 // times, and log one error.
188 for (int i = 1; i <= 5; ++i)
189 {
190 system.monitorSensors(services);
191 }
192
193 // Clear error history
194 system.clearErrorHistory();
195
196 // Monitor sensors 5 times again. Should fail every time, write to journal
197 // 3 times, and log one error.
198 for (int i = 1; i <= 5; ++i)
199 {
200 system.monitorSensors(services);
201 }
202}
203
Shawn McCarney5b19ea52020-06-02 18:52:56 -0500204TEST(SystemTests, CloseDevices)
205{
206 // Specify an empty rules vector
207 std::vector<std::unique_ptr<Rule>> rules{};
208
Bob Kingd692d6d2020-09-14 13:42:57 +0800209 // Create mock services. Expect logDebug() to be called.
210 MockServices services{};
211 MockJournal& journal = services.getMockJournal();
212 EXPECT_CALL(journal, logDebug("Closing devices in chassis 1")).Times(1);
213 EXPECT_CALL(journal, logDebug("Closing devices in chassis 3")).Times(1);
214 EXPECT_CALL(journal, logInfo(A<const std::string&>())).Times(0);
215 EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
216
Shawn McCarney5b19ea52020-06-02 18:52:56 -0500217 // Create Chassis
218 std::vector<std::unique_ptr<Chassis>> chassis{};
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500219 chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1'));
220 chassis.emplace_back(std::make_unique<Chassis>(3, chassisInvPath + '3'));
Shawn McCarney5b19ea52020-06-02 18:52:56 -0500221
222 // Create System
223 System system{std::move(rules), std::move(chassis)};
224
225 // Call closeDevices()
Bob Kingd692d6d2020-09-14 13:42:57 +0800226 system.closeDevices(services);
Shawn McCarney5b19ea52020-06-02 18:52:56 -0500227}
228
Shawn McCarney2af52892020-04-14 11:54:45 -0500229TEST(SystemTests, Configure)
230{
Bob King5cfe5102020-07-30 16:26:18 +0800231 // Create mock services. Expect logInfo() to be called.
Bob King23243f82020-07-29 10:38:57 +0800232 MockServices services{};
Bob King5cfe5102020-07-30 16:26:18 +0800233 MockJournal& journal = services.getMockJournal();
234 EXPECT_CALL(journal, logInfo("Configuring chassis 1")).Times(1);
235 EXPECT_CALL(journal, logInfo("Configuring chassis 3")).Times(1);
236 EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0);
237 EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
Bob King23243f82020-07-29 10:38:57 +0800238
Shawn McCarney2af52892020-04-14 11:54:45 -0500239 // Specify an empty rules vector
240 std::vector<std::unique_ptr<Rule>> rules{};
241
242 // Create Chassis
243 std::vector<std::unique_ptr<Chassis>> chassis{};
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500244 chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1'));
245 chassis.emplace_back(std::make_unique<Chassis>(3, chassisInvPath + '3'));
Shawn McCarney2af52892020-04-14 11:54:45 -0500246
247 // Create System
248 System system{std::move(rules), std::move(chassis)};
249
250 // Call configure()
Bob King23243f82020-07-29 10:38:57 +0800251 system.configure(services);
Shawn McCarney2af52892020-04-14 11:54:45 -0500252}
253
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500254TEST(SystemTests, GetChassis)
255{
256 // Specify an empty rules vector
257 std::vector<std::unique_ptr<Rule>> rules{};
258
259 // Create Chassis
260 std::vector<std::unique_ptr<Chassis>> chassis{};
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500261 chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1'));
262 chassis.emplace_back(std::make_unique<Chassis>(3, chassisInvPath + '3'));
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500263
264 // Create System
265 System system{std::move(rules), std::move(chassis)};
266 EXPECT_EQ(system.getChassis().size(), 2);
267 EXPECT_EQ(system.getChassis()[0]->getNumber(), 1);
268 EXPECT_EQ(system.getChassis()[1]->getNumber(), 3);
269}
270
271TEST(SystemTests, GetIDMap)
272{
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500273 // Create Rules
274 std::vector<std::unique_ptr<Rule>> rules{};
275 rules.emplace_back(createRule("set_voltage_rule"));
276 rules.emplace_back(createRule("read_sensors_rule"));
277
278 // Create Chassis
279 std::vector<std::unique_ptr<Chassis>> chassis{};
280 {
281 // Chassis 1
282 std::vector<std::unique_ptr<Device>> devices{};
283 devices.emplace_back(createDevice("reg1", {"rail1"}));
284 devices.emplace_back(createDevice("reg2", {"rail2a", "rail2b"}));
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500285 chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath + '1',
286 std::move(devices)));
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500287 }
288 {
289 // Chassis 2
290 std::vector<std::unique_ptr<Device>> devices{};
291 devices.emplace_back(createDevice("reg3", {"rail3a", "rail3b"}));
292 devices.emplace_back(createDevice("reg4"));
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500293 chassis.emplace_back(std::make_unique<Chassis>(2, chassisInvPath + '2',
294 std::move(devices)));
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500295 }
296
297 // Create System
298 System system{std::move(rules), std::move(chassis)};
299 const IDMap& idMap = system.getIDMap();
300
301 // Verify all Rules are in the IDMap
302 EXPECT_NO_THROW(idMap.getRule("set_voltage_rule"));
303 EXPECT_NO_THROW(idMap.getRule("read_sensors_rule"));
304 EXPECT_THROW(idMap.getRule("set_voltage_rule2"), std::invalid_argument);
305
306 // Verify all Devices are in the IDMap
307 EXPECT_NO_THROW(idMap.getDevice("reg1"));
308 EXPECT_NO_THROW(idMap.getDevice("reg2"));
309 EXPECT_NO_THROW(idMap.getDevice("reg3"));
310 EXPECT_NO_THROW(idMap.getDevice("reg4"));
311 EXPECT_THROW(idMap.getDevice("reg5"), std::invalid_argument);
312
313 // Verify all Rails are in the IDMap
314 EXPECT_NO_THROW(idMap.getRail("rail1"));
315 EXPECT_NO_THROW(idMap.getRail("rail2a"));
316 EXPECT_NO_THROW(idMap.getRail("rail2b"));
317 EXPECT_NO_THROW(idMap.getRail("rail3a"));
318 EXPECT_NO_THROW(idMap.getRail("rail3b"));
319 EXPECT_THROW(idMap.getRail("rail4"), std::invalid_argument);
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500320}
321
322TEST(SystemTests, GetRules)
323{
324 // Create Rules
325 std::vector<std::unique_ptr<Rule>> rules{};
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500326 rules.emplace_back(createRule("set_voltage_rule"));
327 rules.emplace_back(createRule("read_sensors_rule"));
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500328
329 // Create Chassis
330 std::vector<std::unique_ptr<Chassis>> chassis{};
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500331 chassis.emplace_back(std::make_unique<Chassis>(1, chassisInvPath));
Shawn McCarneyc3991f12020-04-05 13:16:06 -0500332
333 // Create System
334 System system{std::move(rules), std::move(chassis)};
335 EXPECT_EQ(system.getRules().size(), 2);
336 EXPECT_EQ(system.getRules()[0]->getID(), "set_voltage_rule");
337 EXPECT_EQ(system.getRules()[1]->getID(), "read_sensors_rule");
338}
Bob King8e2294d2020-07-14 17:41:31 +0800339
340TEST(SystemTests, MonitorSensors)
341{
Shawn McCarney17bac892021-05-08 07:55:52 -0500342 // Create mock services. Set Sensors service expectations.
Bob King8a552922020-08-05 17:02:31 +0800343 MockServices services{};
Shawn McCarney17bac892021-05-08 07:55:52 -0500344 MockSensors& sensors = services.getMockSensors();
345 EXPECT_CALL(sensors, startRail("c1_vdd0",
346 "/xyz/openbmc_project/inventory/system/"
347 "chassis1/motherboard/vdd0_reg",
348 chassisInvPath + '1'))
Bob King8e2294d2020-07-14 17:41:31 +0800349 .Times(1);
Shawn McCarney17bac892021-05-08 07:55:52 -0500350 EXPECT_CALL(sensors, startRail("c2_vdd0",
351 "/xyz/openbmc_project/inventory/system/"
352 "chassis2/motherboard/vdd0_reg",
353 chassisInvPath + '2'))
354 .Times(1);
355 EXPECT_CALL(sensors, setValue).Times(0);
356 EXPECT_CALL(sensors, endRail(false)).Times(2);
Bob King8e2294d2020-07-14 17:41:31 +0800357
Shawn McCarney17bac892021-05-08 07:55:52 -0500358 std::vector<std::unique_ptr<Chassis>> chassisVec{};
Bob King8e2294d2020-07-14 17:41:31 +0800359
Shawn McCarney17bac892021-05-08 07:55:52 -0500360 // Create Chassis 1
361 {
362 // Create SensorMonitoring for Rail
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500363 auto action = std::make_unique<MockAction>();
Shawn McCarney17bac892021-05-08 07:55:52 -0500364 EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true));
365 std::vector<std::unique_ptr<Action>> actions{};
366 actions.emplace_back(std::move(action));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500367 auto sensorMonitoring =
Shawn McCarney17bac892021-05-08 07:55:52 -0500368 std::make_unique<SensorMonitoring>(std::move(actions));
Bob King8e2294d2020-07-14 17:41:31 +0800369
Shawn McCarney17bac892021-05-08 07:55:52 -0500370 // Create Rail
371 std::unique_ptr<Configuration> configuration{};
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500372 auto rail = std::make_unique<Rail>("c1_vdd0", std::move(configuration),
373 std::move(sensorMonitoring));
Bob King8e2294d2020-07-14 17:41:31 +0800374
Shawn McCarney17bac892021-05-08 07:55:52 -0500375 // Create Device
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500376 auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>();
Shawn McCarney17bac892021-05-08 07:55:52 -0500377 std::unique_ptr<PresenceDetection> presenceDetection{};
378 std::unique_ptr<Configuration> deviceConfiguration{};
Shawn McCarney32252592021-09-08 15:29:36 -0500379 std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{};
Shawn McCarney17bac892021-05-08 07:55:52 -0500380 std::vector<std::unique_ptr<Rail>> rails{};
381 rails.emplace_back(std::move(rail));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500382 auto device = std::make_unique<Device>(
Shawn McCarney17bac892021-05-08 07:55:52 -0500383 "c1_vdd0_reg", true,
384 "/xyz/openbmc_project/inventory/system/chassis1/motherboard/"
385 "vdd0_reg",
386 std::move(i2cInterface), std::move(presenceDetection),
Shawn McCarney32252592021-09-08 15:29:36 -0500387 std::move(deviceConfiguration), std::move(phaseFaultDetection),
388 std::move(rails));
Shawn McCarney17bac892021-05-08 07:55:52 -0500389
390 // Create Chassis
391 std::vector<std::unique_ptr<Device>> devices{};
392 devices.emplace_back(std::move(device));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500393 auto chassis = std::make_unique<Chassis>(1, chassisInvPath + '1',
394 std::move(devices));
Shawn McCarney17bac892021-05-08 07:55:52 -0500395 chassisVec.emplace_back(std::move(chassis));
396 }
397
398 // Create Chassis 2
399 {
400 // Create SensorMonitoring for Rail
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500401 auto action = std::make_unique<MockAction>();
Shawn McCarney17bac892021-05-08 07:55:52 -0500402 EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true));
403 std::vector<std::unique_ptr<Action>> actions{};
404 actions.emplace_back(std::move(action));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500405 auto sensorMonitoring =
Shawn McCarney17bac892021-05-08 07:55:52 -0500406 std::make_unique<SensorMonitoring>(std::move(actions));
407
408 // Create Rail
409 std::unique_ptr<Configuration> configuration{};
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500410 auto rail = std::make_unique<Rail>("c2_vdd0", std::move(configuration),
411 std::move(sensorMonitoring));
Shawn McCarney17bac892021-05-08 07:55:52 -0500412
413 // Create Device
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500414 auto i2cInterface = std::make_unique<i2c::MockedI2CInterface>();
Shawn McCarney17bac892021-05-08 07:55:52 -0500415 std::unique_ptr<PresenceDetection> presenceDetection{};
416 std::unique_ptr<Configuration> deviceConfiguration{};
Shawn McCarney32252592021-09-08 15:29:36 -0500417 std::unique_ptr<PhaseFaultDetection> phaseFaultDetection{};
Shawn McCarney17bac892021-05-08 07:55:52 -0500418 std::vector<std::unique_ptr<Rail>> rails{};
419 rails.emplace_back(std::move(rail));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500420 auto device = std::make_unique<Device>(
Shawn McCarney17bac892021-05-08 07:55:52 -0500421 "c2_vdd0_reg", true,
422 "/xyz/openbmc_project/inventory/system/chassis2/motherboard/"
423 "vdd0_reg",
424 std::move(i2cInterface), std::move(presenceDetection),
Shawn McCarney32252592021-09-08 15:29:36 -0500425 std::move(deviceConfiguration), std::move(phaseFaultDetection),
426 std::move(rails));
Shawn McCarney17bac892021-05-08 07:55:52 -0500427
428 // Create Chassis
429 std::vector<std::unique_ptr<Device>> devices{};
430 devices.emplace_back(std::move(device));
Shawn McCarneya3fecef2021-09-09 23:15:35 -0500431 auto chassis = std::make_unique<Chassis>(2, chassisInvPath + '2',
432 std::move(devices));
Shawn McCarney17bac892021-05-08 07:55:52 -0500433 chassisVec.emplace_back(std::move(chassis));
434 }
Bob King8e2294d2020-07-14 17:41:31 +0800435
436 // Create System that contains Chassis
437 std::vector<std::unique_ptr<Rule>> rules{};
Bob King8e2294d2020-07-14 17:41:31 +0800438 System system{std::move(rules), std::move(chassisVec)};
439
440 // Call monitorSensors()
Bob King8a552922020-08-05 17:02:31 +0800441 system.monitorSensors(services);
Bob King8e2294d2020-07-14 17:41:31 +0800442}