blob: def281c050256d4dcf93770fde2f777e398f6594 [file] [log] [blame]
Shawn McCarney8a3afd72020-03-12 14:28:44 -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 McCarney525e20c2020-04-14 11:05:39 -050016#include "action.hpp"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050017#include "chassis.hpp"
Shawn McCarney525e20c2020-04-14 11:05:39 -050018#include "configuration.hpp"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050019#include "device.hpp"
20#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 McCarney525e20c2020-04-14 11:05:39 -050023#include "mock_journal.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050024#include "mock_sensors.hpp"
Bob King23243f82020-07-29 10:38:57 +080025#include "mock_services.hpp"
Shawn McCarney050531f2020-06-02 14:17:12 -050026#include "mocked_i2c_interface.hpp"
Shawn McCarney525e20c2020-04-14 11:05:39 -050027#include "presence_detection.hpp"
28#include "rail.hpp"
29#include "rule.hpp"
Shawn McCarney17bac892021-05-08 07:55:52 -050030#include "sensor_monitoring.hpp"
Shawn McCarney2f9e14f2021-04-29 02:45:18 -050031#include "sensors.hpp"
Shawn McCarney525e20c2020-04-14 11:05:39 -050032#include "system.hpp"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050033#include "test_utils.hpp"
34
35#include <memory>
36#include <stdexcept>
Shawn McCarney525e20c2020-04-14 11:05:39 -050037#include <string>
Shawn McCarney8a3afd72020-03-12 14:28:44 -050038#include <utility>
39#include <vector>
40
Bob Kinga2c81a62020-07-08 13:31:16 +080041#include <gmock/gmock.h>
Shawn McCarney8a3afd72020-03-12 14:28:44 -050042#include <gtest/gtest.h>
43
44using namespace phosphor::power::regulators;
45using namespace phosphor::power::regulators::test_utils;
46
Bob Kinga2c81a62020-07-08 13:31:16 +080047using ::testing::A;
Shawn McCarney050531f2020-06-02 14:17:12 -050048using ::testing::Return;
Bob Kinga2c81a62020-07-08 13:31:16 +080049using ::testing::TypedEq;
Shawn McCarney050531f2020-06-02 14:17:12 -050050
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050051// Default chassis inventory path
52static const std::string defaultInventoryPath{
53 "/xyz/openbmc_project/inventory/system/chassis"};
54
Shawn McCarney8a3afd72020-03-12 14:28:44 -050055TEST(ChassisTests, Constructor)
56{
57 // Test where works: Only required parameters are specified
58 {
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050059 Chassis chassis{2, defaultInventoryPath};
Shawn McCarney8a3afd72020-03-12 14:28:44 -050060 EXPECT_EQ(chassis.getNumber(), 2);
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050061 EXPECT_EQ(chassis.getInventoryPath(), defaultInventoryPath);
Shawn McCarney8a3afd72020-03-12 14:28:44 -050062 EXPECT_EQ(chassis.getDevices().size(), 0);
63 }
64
65 // Test where works: All parameters are specified
66 {
67 // Create vector of Device objects
68 std::vector<std::unique_ptr<Device>> devices{};
Shawn McCarneydb0b8332020-04-06 14:13:04 -050069 devices.emplace_back(createDevice("vdd_reg1"));
70 devices.emplace_back(createDevice("vdd_reg2"));
Shawn McCarney8a3afd72020-03-12 14:28:44 -050071
72 // Create Chassis
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050073 Chassis chassis{1, defaultInventoryPath, std::move(devices)};
Shawn McCarney8a3afd72020-03-12 14:28:44 -050074 EXPECT_EQ(chassis.getNumber(), 1);
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050075 EXPECT_EQ(chassis.getInventoryPath(), defaultInventoryPath);
Shawn McCarney8a3afd72020-03-12 14:28:44 -050076 EXPECT_EQ(chassis.getDevices().size(), 2);
77 }
78
79 // Test where fails: Invalid chassis number < 1
80 try
81 {
Shawn McCarneycb3f6a62021-04-30 10:54:30 -050082 Chassis chassis{0, defaultInventoryPath};
Shawn McCarney8a3afd72020-03-12 14:28:44 -050083 ADD_FAILURE() << "Should not have reached this line.";
84 }
85 catch (const std::invalid_argument& e)
86 {
87 EXPECT_STREQ(e.what(), "Invalid chassis number: 0");
88 }
89 catch (...)
90 {
91 ADD_FAILURE() << "Should not have caught exception.";
92 }
93}
94
Shawn McCarneydb0b8332020-04-06 14:13:04 -050095TEST(ChassisTests, AddToIDMap)
96{
97 // Create vector of Device objects
98 std::vector<std::unique_ptr<Device>> devices{};
99 devices.emplace_back(createDevice("reg1", {"rail1"}));
100 devices.emplace_back(createDevice("reg2", {"rail2a", "rail2b"}));
101 devices.emplace_back(createDevice("reg3"));
102
103 // Create Chassis
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500104 Chassis chassis{1, defaultInventoryPath, std::move(devices)};
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500105
106 // Add Device and Rail objects within the Chassis to an IDMap
107 IDMap idMap{};
108 chassis.addToIDMap(idMap);
109
110 // Verify all Devices are in the IDMap
111 EXPECT_NO_THROW(idMap.getDevice("reg1"));
112 EXPECT_NO_THROW(idMap.getDevice("reg2"));
113 EXPECT_NO_THROW(idMap.getDevice("reg3"));
114 EXPECT_THROW(idMap.getDevice("reg4"), std::invalid_argument);
115
116 // Verify all Rails are in the IDMap
117 EXPECT_NO_THROW(idMap.getRail("rail1"));
118 EXPECT_NO_THROW(idMap.getRail("rail2a"));
119 EXPECT_NO_THROW(idMap.getRail("rail2b"));
120 EXPECT_THROW(idMap.getRail("rail3"), std::invalid_argument);
121}
122
Shawn McCarney9bd94d32021-01-25 19:40:42 -0600123TEST(ChassisTests, ClearCache)
124{
125 // Create PresenceDetection
126 std::vector<std::unique_ptr<Action>> actions{};
127 std::unique_ptr<PresenceDetection> presenceDetection =
128 std::make_unique<PresenceDetection>(std::move(actions));
129 PresenceDetection* presenceDetectionPtr = presenceDetection.get();
130
131 // Create Device that contains PresenceDetection
132 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
133 std::unique_ptr<Device> device = std::make_unique<Device>(
134 "reg1", true,
135 "/xyz/openbmc_project/inventory/system/chassis/motherboard/reg1",
136 std::move(i2cInterface), std::move(presenceDetection));
137 Device* devicePtr = device.get();
138
139 // Create Chassis that contains Device
140 std::vector<std::unique_ptr<Device>> devices{};
141 devices.emplace_back(std::move(device));
142 std::unique_ptr<Chassis> chassis =
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500143 std::make_unique<Chassis>(1, defaultInventoryPath, std::move(devices));
Shawn McCarney9bd94d32021-01-25 19:40:42 -0600144 Chassis* chassisPtr = chassis.get();
145
146 // Create System that contains Chassis
147 std::vector<std::unique_ptr<Rule>> rules{};
148 std::vector<std::unique_ptr<Chassis>> chassisVec{};
149 chassisVec.emplace_back(std::move(chassis));
150 System system{std::move(rules), std::move(chassisVec)};
151
152 // Cache presence value in PresenceDetection
153 MockServices services{};
154 presenceDetectionPtr->execute(services, system, *chassisPtr, *devicePtr);
155 EXPECT_TRUE(presenceDetectionPtr->getCachedPresence().has_value());
156
157 // Clear cached data in Chassis
158 chassisPtr->clearCache();
159
160 // Verify presence value no longer cached in PresenceDetection
161 EXPECT_FALSE(presenceDetectionPtr->getCachedPresence().has_value());
162}
163
Shawn McCarney050531f2020-06-02 14:17:12 -0500164TEST(ChassisTests, CloseDevices)
165{
166 // Test where no devices were specified in constructor
167 {
Bob Kingd692d6d2020-09-14 13:42:57 +0800168 // Create mock services. Expect logDebug() to be called.
169 MockServices services{};
170 MockJournal& journal = services.getMockJournal();
171 EXPECT_CALL(journal, logDebug("Closing devices in chassis 2")).Times(1);
172
Shawn McCarney050531f2020-06-02 14:17:12 -0500173 // Create Chassis
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500174 Chassis chassis{2, defaultInventoryPath};
Shawn McCarney050531f2020-06-02 14:17:12 -0500175
176 // Call closeDevices()
Bob Kingd692d6d2020-09-14 13:42:57 +0800177 chassis.closeDevices(services);
Shawn McCarney050531f2020-06-02 14:17:12 -0500178 }
179
180 // Test where devices were specified in constructor
181 {
182 std::vector<std::unique_ptr<Device>> devices{};
183
Bob Kingd692d6d2020-09-14 13:42:57 +0800184 // Create mock services. Expect logDebug() to be called.
185 MockServices services{};
186 MockJournal& journal = services.getMockJournal();
187 EXPECT_CALL(journal, logDebug("Closing devices in chassis 1")).Times(1);
188
Shawn McCarney050531f2020-06-02 14:17:12 -0500189 // Create Device vdd0_reg
190 {
191 // Create mock I2CInterface: isOpen() and close() should be called
192 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
193 std::make_unique<i2c::MockedI2CInterface>();
194 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
195 EXPECT_CALL(*i2cInterface, close).Times(1);
196
197 // Create Device
Bob Kinga76898f2020-10-13 15:08:33 +0800198 std::unique_ptr<Device> device =
199 std::make_unique<Device>("vdd0_reg", true,
200 "/xyz/openbmc_project/inventory/"
201 "system/chassis/motherboard/vdd0_reg",
202 std::move(i2cInterface));
Shawn McCarney050531f2020-06-02 14:17:12 -0500203 devices.emplace_back(std::move(device));
204 }
205
206 // Create Device vdd1_reg
207 {
208 // Create mock I2CInterface: isOpen() and close() should be called
209 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
210 std::make_unique<i2c::MockedI2CInterface>();
211 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
212 EXPECT_CALL(*i2cInterface, close).Times(1);
213
214 // Create Device
Bob Kinga76898f2020-10-13 15:08:33 +0800215 std::unique_ptr<Device> device =
216 std::make_unique<Device>("vdd1_reg", true,
217 "/xyz/openbmc_project/inventory/"
218 "system/chassis/motherboard/vdd1_reg",
219 std::move(i2cInterface));
Shawn McCarney050531f2020-06-02 14:17:12 -0500220 devices.emplace_back(std::move(device));
221 }
222
223 // Create Chassis
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500224 Chassis chassis{1, defaultInventoryPath, std::move(devices)};
Shawn McCarney050531f2020-06-02 14:17:12 -0500225
226 // Call closeDevices()
Bob Kingd692d6d2020-09-14 13:42:57 +0800227 chassis.closeDevices(services);
Shawn McCarney050531f2020-06-02 14:17:12 -0500228 }
229}
230
Shawn McCarney525e20c2020-04-14 11:05:39 -0500231TEST(ChassisTests, Configure)
232{
233 // Test where no devices were specified in constructor
234 {
Bob King5cfe5102020-07-30 16:26:18 +0800235 // Create mock services. Expect logInfo() to be called.
Bob King23243f82020-07-29 10:38:57 +0800236 MockServices services{};
Bob King5cfe5102020-07-30 16:26:18 +0800237 MockJournal& journal = services.getMockJournal();
238 EXPECT_CALL(journal, logInfo("Configuring chassis 1")).Times(1);
239 EXPECT_CALL(journal, logDebug(A<const std::string&>())).Times(0);
240 EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
Bob King23243f82020-07-29 10:38:57 +0800241
Shawn McCarney525e20c2020-04-14 11:05:39 -0500242 // Create Chassis
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500243 std::unique_ptr<Chassis> chassis =
244 std::make_unique<Chassis>(1, defaultInventoryPath);
Shawn McCarney525e20c2020-04-14 11:05:39 -0500245 Chassis* chassisPtr = chassis.get();
246
247 // Create System that contains Chassis
248 std::vector<std::unique_ptr<Rule>> rules{};
249 std::vector<std::unique_ptr<Chassis>> chassisVec{};
250 chassisVec.emplace_back(std::move(chassis));
251 System system{std::move(rules), std::move(chassisVec)};
252
253 // Call configure()
Bob King23243f82020-07-29 10:38:57 +0800254 chassisPtr->configure(services, system);
Shawn McCarney525e20c2020-04-14 11:05:39 -0500255 }
256
257 // Test where devices were specified in constructor
258 {
259 std::vector<std::unique_ptr<Device>> devices{};
260
Bob King5cfe5102020-07-30 16:26:18 +0800261 // Create mock services. Expect logInfo() and logDebug() to be called.
262 MockServices services{};
263 MockJournal& journal = services.getMockJournal();
264 EXPECT_CALL(journal, logInfo("Configuring chassis 2")).Times(1);
265 EXPECT_CALL(journal, logDebug("Configuring vdd0_reg: volts=1.300000"))
266 .Times(1);
267 EXPECT_CALL(journal, logDebug("Configuring vdd1_reg: volts=1.200000"))
268 .Times(1);
269 EXPECT_CALL(journal, logError(A<const std::string&>())).Times(0);
270
Shawn McCarney525e20c2020-04-14 11:05:39 -0500271 // Create Device vdd0_reg
272 {
273 // Create Configuration
274 std::vector<std::unique_ptr<Action>> actions{};
275 std::unique_ptr<Configuration> configuration =
276 std::make_unique<Configuration>(1.3, std::move(actions));
277
278 // Create Device
279 std::unique_ptr<i2c::I2CInterface> i2cInterface =
280 createI2CInterface();
281 std::unique_ptr<PresenceDetection> presenceDetection{};
282 std::unique_ptr<Device> device = std::make_unique<Device>(
Bob Kinga76898f2020-10-13 15:08:33 +0800283 "vdd0_reg", true,
284 "/xyz/openbmc_project/inventory/system/chassis/motherboard/"
285 "vdd0_reg",
Shawn McCarney525e20c2020-04-14 11:05:39 -0500286 std::move(i2cInterface), std::move(presenceDetection),
287 std::move(configuration));
288 devices.emplace_back(std::move(device));
289 }
290
291 // Create Device vdd1_reg
292 {
293 // Create Configuration
294 std::vector<std::unique_ptr<Action>> actions{};
295 std::unique_ptr<Configuration> configuration =
296 std::make_unique<Configuration>(1.2, std::move(actions));
297
298 // Create Device
299 std::unique_ptr<i2c::I2CInterface> i2cInterface =
300 createI2CInterface();
301 std::unique_ptr<PresenceDetection> presenceDetection{};
302 std::unique_ptr<Device> device = std::make_unique<Device>(
Bob Kinga76898f2020-10-13 15:08:33 +0800303 "vdd1_reg", true,
304 "/xyz/openbmc_project/inventory/system/chassis/motherboard/"
305 "vdd1_reg",
Shawn McCarney525e20c2020-04-14 11:05:39 -0500306 std::move(i2cInterface), std::move(presenceDetection),
307 std::move(configuration));
308 devices.emplace_back(std::move(device));
309 }
310
311 // Create Chassis
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500312 std::unique_ptr<Chassis> chassis = std::make_unique<Chassis>(
313 2, defaultInventoryPath, std::move(devices));
Shawn McCarney525e20c2020-04-14 11:05:39 -0500314 Chassis* chassisPtr = chassis.get();
315
316 // Create System that contains Chassis
317 std::vector<std::unique_ptr<Rule>> rules{};
318 std::vector<std::unique_ptr<Chassis>> chassisVec{};
319 chassisVec.emplace_back(std::move(chassis));
320 System system{std::move(rules), std::move(chassisVec)};
321
322 // Call configure()
Bob King23243f82020-07-29 10:38:57 +0800323 chassisPtr->configure(services, system);
Shawn McCarney525e20c2020-04-14 11:05:39 -0500324 }
325}
326
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500327TEST(ChassisTests, GetDevices)
328{
329 // Test where no devices were specified in constructor
330 {
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500331 Chassis chassis{2, defaultInventoryPath};
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500332 EXPECT_EQ(chassis.getDevices().size(), 0);
333 }
334
335 // Test where devices were specified in constructor
336 {
337 // Create vector of Device objects
338 std::vector<std::unique_ptr<Device>> devices{};
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500339 devices.emplace_back(createDevice("vdd_reg1"));
340 devices.emplace_back(createDevice("vdd_reg2"));
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500341
342 // Create Chassis
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500343 Chassis chassis{1, defaultInventoryPath, std::move(devices)};
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500344 EXPECT_EQ(chassis.getDevices().size(), 2);
345 EXPECT_EQ(chassis.getDevices()[0]->getID(), "vdd_reg1");
346 EXPECT_EQ(chassis.getDevices()[1]->getID(), "vdd_reg2");
347 }
348}
349
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500350TEST(ChassisTests, GetInventoryPath)
351{
352 Chassis chassis{3, defaultInventoryPath};
353 EXPECT_EQ(chassis.getInventoryPath(), defaultInventoryPath);
354}
355
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500356TEST(ChassisTests, GetNumber)
357{
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500358 Chassis chassis{3, defaultInventoryPath};
Shawn McCarney8a3afd72020-03-12 14:28:44 -0500359 EXPECT_EQ(chassis.getNumber(), 3);
360}
Bob Kinga2c81a62020-07-08 13:31:16 +0800361
362TEST(ChassisTests, MonitorSensors)
363{
364 // Test where no devices were specified in constructor
365 {
Shawn McCarney17bac892021-05-08 07:55:52 -0500366 // Create mock services. No Sensors methods should be called.
Bob King8a552922020-08-05 17:02:31 +0800367 MockServices services{};
Shawn McCarney17bac892021-05-08 07:55:52 -0500368 MockSensors& sensors = services.getMockSensors();
369 EXPECT_CALL(sensors, startRail).Times(0);
370 EXPECT_CALL(sensors, setValue).Times(0);
371 EXPECT_CALL(sensors, endRail).Times(0);
Bob King8a552922020-08-05 17:02:31 +0800372
Bob Kinga2c81a62020-07-08 13:31:16 +0800373 // Create Chassis
Shawn McCarney17bac892021-05-08 07:55:52 -0500374 std::unique_ptr<Chassis> chassis =
375 std::make_unique<Chassis>(1, defaultInventoryPath);
Bob Kinga2c81a62020-07-08 13:31:16 +0800376 Chassis* chassisPtr = chassis.get();
377
378 // Create System that contains Chassis
379 std::vector<std::unique_ptr<Rule>> rules{};
380 std::vector<std::unique_ptr<Chassis>> chassisVec{};
381 chassisVec.emplace_back(std::move(chassis));
382 System system{std::move(rules), std::move(chassisVec)};
383
384 // Call monitorSensors(). Should do nothing.
Bob King8a552922020-08-05 17:02:31 +0800385 chassisPtr->monitorSensors(services, system);
Bob Kinga2c81a62020-07-08 13:31:16 +0800386 }
387
388 // Test where devices were specified in constructor
389 {
Shawn McCarney17bac892021-05-08 07:55:52 -0500390 // Create mock services. Set Sensors service expectations.
Bob King8a552922020-08-05 17:02:31 +0800391 MockServices services{};
Shawn McCarney17bac892021-05-08 07:55:52 -0500392 MockSensors& sensors = services.getMockSensors();
393 EXPECT_CALL(sensors, startRail("vdd0",
394 "/xyz/openbmc_project/inventory/system/"
395 "chassis/motherboard/vdd0_reg",
396 defaultInventoryPath))
397 .Times(1);
398 EXPECT_CALL(sensors, startRail("vdd1",
399 "/xyz/openbmc_project/inventory/system/"
400 "chassis/motherboard/vdd1_reg",
401 defaultInventoryPath))
402 .Times(1);
403 EXPECT_CALL(sensors, setValue).Times(0);
404 EXPECT_CALL(sensors, endRail(false)).Times(2);
Bob King8a552922020-08-05 17:02:31 +0800405
Bob Kinga2c81a62020-07-08 13:31:16 +0800406 std::vector<std::unique_ptr<Device>> devices{};
407
Shawn McCarney17bac892021-05-08 07:55:52 -0500408 // Create Device vdd0_reg
409 {
410 // Create SensorMonitoring for Rail
411 std::unique_ptr<MockAction> action = std::make_unique<MockAction>();
412 EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true));
413 std::vector<std::unique_ptr<Action>> actions{};
414 actions.emplace_back(std::move(action));
415 std::unique_ptr<SensorMonitoring> sensorMonitoring =
416 std::make_unique<SensorMonitoring>(std::move(actions));
Bob Kinga2c81a62020-07-08 13:31:16 +0800417
Shawn McCarney17bac892021-05-08 07:55:52 -0500418 // Create Rail
419 std::unique_ptr<Configuration> configuration{};
420 std::unique_ptr<Rail> rail = std::make_unique<Rail>(
421 "vdd0", std::move(configuration), std::move(sensorMonitoring));
Bob Kinga2c81a62020-07-08 13:31:16 +0800422
Shawn McCarney17bac892021-05-08 07:55:52 -0500423 // Create Device
424 std::unique_ptr<i2c::I2CInterface> i2cInterface =
425 createI2CInterface();
426 std::unique_ptr<PresenceDetection> presenceDetection{};
427 std::unique_ptr<Configuration> deviceConfiguration{};
428 std::vector<std::unique_ptr<Rail>> rails{};
429 rails.emplace_back(std::move(rail));
430 std::unique_ptr<Device> device = std::make_unique<Device>(
431 "vdd0_reg", true,
432 "/xyz/openbmc_project/inventory/system/chassis/motherboard/"
433 "vdd0_reg",
434 std::move(i2cInterface), std::move(presenceDetection),
435 std::move(deviceConfiguration), std::move(rails));
436 devices.emplace_back(std::move(device));
437 }
Bob Kinga2c81a62020-07-08 13:31:16 +0800438
Shawn McCarney17bac892021-05-08 07:55:52 -0500439 // Create Device vdd1_reg
440 {
441 // Create SensorMonitoring for Rail
442 std::unique_ptr<MockAction> action = std::make_unique<MockAction>();
443 EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true));
444 std::vector<std::unique_ptr<Action>> actions{};
445 actions.emplace_back(std::move(action));
446 std::unique_ptr<SensorMonitoring> sensorMonitoring =
447 std::make_unique<SensorMonitoring>(std::move(actions));
Bob Kinga2c81a62020-07-08 13:31:16 +0800448
Shawn McCarney17bac892021-05-08 07:55:52 -0500449 // Create Rail
450 std::unique_ptr<Configuration> configuration{};
451 std::unique_ptr<Rail> rail = std::make_unique<Rail>(
452 "vdd1", std::move(configuration), std::move(sensorMonitoring));
Bob Kinga2c81a62020-07-08 13:31:16 +0800453
Shawn McCarney17bac892021-05-08 07:55:52 -0500454 // Create Device
455 std::unique_ptr<i2c::I2CInterface> i2cInterface =
456 createI2CInterface();
457 std::unique_ptr<PresenceDetection> presenceDetection{};
458 std::unique_ptr<Configuration> deviceConfiguration{};
459 std::vector<std::unique_ptr<Rail>> rails{};
460 rails.emplace_back(std::move(rail));
461 std::unique_ptr<Device> device = std::make_unique<Device>(
462 "vdd1_reg", true,
463 "/xyz/openbmc_project/inventory/system/chassis/motherboard/"
464 "vdd1_reg",
465 std::move(i2cInterface), std::move(presenceDetection),
466 std::move(deviceConfiguration), std::move(rails));
467 devices.emplace_back(std::move(device));
468 }
469
470 // Create Chassis that contains Devices
Shawn McCarneycb3f6a62021-04-30 10:54:30 -0500471 std::unique_ptr<Chassis> chassis = std::make_unique<Chassis>(
Shawn McCarney17bac892021-05-08 07:55:52 -0500472 2, defaultInventoryPath, std::move(devices));
Bob Kinga2c81a62020-07-08 13:31:16 +0800473 Chassis* chassisPtr = chassis.get();
474
475 // Create System that contains Chassis
476 std::vector<std::unique_ptr<Rule>> rules{};
477 std::vector<std::unique_ptr<Chassis>> chassisVec{};
478 chassisVec.emplace_back(std::move(chassis));
479 System system{std::move(rules), std::move(chassisVec)};
480
481 // Call monitorSensors()
Bob King8a552922020-08-05 17:02:31 +0800482 chassisPtr->monitorSensors(services, system);
Bob Kinga2c81a62020-07-08 13:31:16 +0800483 }
484}