blob: 47768e29b3ab32e737562758e1dfd813e12638c5 [file] [log] [blame]
Shawn McCarneya2461b32019-10-24 18:53:01 -05001/**
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 McCarney0b1a0e72020-03-11 18:01:44 -050016#include "action.hpp"
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050017#include "chassis.hpp"
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050018#include "configuration.hpp"
Shawn McCarneya2461b32019-10-24 18:53:01 -050019#include "device.hpp"
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060020#include "i2c_interface.hpp"
Shawn McCarneydb0b8332020-04-06 14:13:04 -050021#include "id_map.hpp"
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050022#include "journal.hpp"
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050023#include "mock_action.hpp"
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050024#include "mock_journal.hpp"
Bob King23243f82020-07-29 10:38:57 +080025#include "mock_services.hpp"
Shawn McCarneyb4d18a42020-06-02 10:27:05 -050026#include "mocked_i2c_interface.hpp"
Bob King8e1cd0b2020-07-08 13:30:27 +080027#include "pmbus_read_sensor_action.hpp"
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050028#include "presence_detection.hpp"
29#include "rail.hpp"
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050030#include "rule.hpp"
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050031#include "system.hpp"
Shawn McCarney8a3afd72020-03-12 14:28:44 -050032#include "test_utils.hpp"
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060033
34#include <memory>
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050035#include <optional>
Shawn McCarney525e20c2020-04-14 11:05:39 -050036#include <string>
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060037#include <utility>
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050038#include <vector>
Shawn McCarneya2461b32019-10-24 18:53:01 -050039
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050040#include <gmock/gmock.h>
Shawn McCarneya2461b32019-10-24 18:53:01 -050041#include <gtest/gtest.h>
42
43using namespace phosphor::power::regulators;
Shawn McCarney8a3afd72020-03-12 14:28:44 -050044using namespace phosphor::power::regulators::test_utils;
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060045
Bob King8e1cd0b2020-07-08 13:30:27 +080046using ::testing::A;
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050047using ::testing::Return;
Shawn McCarneyb4d18a42020-06-02 10:27:05 -050048using ::testing::Throw;
Bob King8e1cd0b2020-07-08 13:30:27 +080049using ::testing::TypedEq;
Shawn McCarneyeb7bec42020-04-14 09:38:15 -050050
Shawn McCarneya2461b32019-10-24 18:53:01 -050051TEST(DeviceTests, Constructor)
52{
Shawn McCarney0b1a0e72020-03-11 18:01:44 -050053 // Test where only required parameters are specified
54 {
55 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
56 i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get();
57 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
58 std::move(i2cInterface)};
59 EXPECT_EQ(device.getID(), "vdd_reg");
60 EXPECT_EQ(device.isRegulator(), true);
61 EXPECT_EQ(device.getFRU(), "/system/chassis/motherboard/reg2");
62 EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr);
63 EXPECT_EQ(device.getPresenceDetection(), nullptr);
64 EXPECT_EQ(device.getConfiguration(), nullptr);
65 EXPECT_EQ(device.getRails().size(), 0);
66 }
67
68 // Test where all parameters are specified
69 {
70 // Create I2CInterface
71 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
72 i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get();
73
74 // Create PresenceDetection
75 std::vector<std::unique_ptr<Action>> actions{};
76 actions.push_back(std::make_unique<MockAction>());
77 std::unique_ptr<PresenceDetection> presenceDetection =
78 std::make_unique<PresenceDetection>(std::move(actions));
79
80 // Create Configuration
81 std::optional<double> volts{};
82 actions.clear();
83 actions.push_back(std::make_unique<MockAction>());
84 actions.push_back(std::make_unique<MockAction>());
85 std::unique_ptr<Configuration> configuration =
86 std::make_unique<Configuration>(volts, std::move(actions));
87
88 // Create vector of Rail objects
89 std::vector<std::unique_ptr<Rail>> rails{};
90 rails.push_back(std::make_unique<Rail>("vdd0"));
91 rails.push_back(std::make_unique<Rail>("vdd1"));
92
93 // Create Device
94 Device device{"vdd_reg",
95 false,
96 "/system/chassis/motherboard/reg1",
97 std::move(i2cInterface),
98 std::move(presenceDetection),
99 std::move(configuration),
100 std::move(rails)};
101 EXPECT_EQ(device.getID(), "vdd_reg");
102 EXPECT_EQ(device.isRegulator(), false);
103 EXPECT_EQ(device.getFRU(), "/system/chassis/motherboard/reg1");
104 EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr);
105 EXPECT_NE(device.getPresenceDetection(), nullptr);
106 EXPECT_EQ(device.getPresenceDetection()->getActions().size(), 1);
107 EXPECT_NE(device.getConfiguration(), nullptr);
108 EXPECT_EQ(device.getConfiguration()->getVolts().has_value(), false);
109 EXPECT_EQ(device.getConfiguration()->getActions().size(), 2);
110 EXPECT_EQ(device.getRails().size(), 2);
111 }
Shawn McCarneya2461b32019-10-24 18:53:01 -0500112}
113
Shawn McCarneydb0b8332020-04-06 14:13:04 -0500114TEST(DeviceTests, AddToIDMap)
115{
116 std::unique_ptr<PresenceDetection> presenceDetection{};
117 std::unique_ptr<Configuration> configuration{};
118
119 // Create vector of Rail objects
120 std::vector<std::unique_ptr<Rail>> rails{};
121 rails.push_back(std::make_unique<Rail>("vdd0"));
122 rails.push_back(std::make_unique<Rail>("vdd1"));
123
124 // Create Device
125 Device device{"vdd_reg",
126 false,
127 "/system/chassis/motherboard/reg2",
128 std::move(createI2CInterface()),
129 std::move(presenceDetection),
130 std::move(configuration),
131 std::move(rails)};
132
133 // Add Device and Rail objects to an IDMap
134 IDMap idMap{};
135 device.addToIDMap(idMap);
136
137 // Verify Device is in the IDMap
138 EXPECT_NO_THROW(idMap.getDevice("vdd_reg"));
139 EXPECT_THROW(idMap.getDevice("vio_reg"), std::invalid_argument);
140
141 // Verify all Rails are in the IDMap
142 EXPECT_NO_THROW(idMap.getRail("vdd0"));
143 EXPECT_NO_THROW(idMap.getRail("vdd1"));
144 EXPECT_THROW(idMap.getRail("vdd2"), std::invalid_argument);
145}
146
Shawn McCarneyb4d18a42020-06-02 10:27:05 -0500147TEST(DeviceTests, Close)
148{
149 // Test where works: I2C interface is not open
150 {
151 // Create mock I2CInterface
152 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
153 std::make_unique<i2c::MockedI2CInterface>();
154 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(false));
155 EXPECT_CALL(*i2cInterface, close).Times(0);
156
157 // Create Device
158 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
159 std::move(i2cInterface)};
160
161 // Close Device
162 journal::clear();
163 device.close();
164 EXPECT_EQ(journal::getErrMessages().size(), 0);
165 }
166
167 // Test where works: I2C interface is open
168 {
169 // Create mock I2CInterface
170 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
171 std::make_unique<i2c::MockedI2CInterface>();
172 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
173 EXPECT_CALL(*i2cInterface, close).Times(1);
174
175 // Create Device
176 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
177 std::move(i2cInterface)};
178
179 // Close Device
180 journal::clear();
181 device.close();
182 EXPECT_EQ(journal::getErrMessages().size(), 0);
183 }
184
185 // Test where fails: closing I2C interface fails
186 {
187 // Create mock I2CInterface
188 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
189 std::make_unique<i2c::MockedI2CInterface>();
190 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
191 EXPECT_CALL(*i2cInterface, close)
192 .Times(1)
193 .WillOnce(Throw(
194 i2c::I2CException{"Failed to close", "/dev/i2c-1", 0x70}));
195
196 // Create Device
197 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
198 std::move(i2cInterface)};
199
200 // Close Device
201 journal::clear();
202 device.close();
203 std::vector<std::string> expectedErrMessages{
204 "I2CException: Failed to close: bus /dev/i2c-1, addr 0x70",
205 "Unable to close device vdd_reg"};
206 EXPECT_EQ(journal::getErrMessages(), expectedErrMessages);
207 }
208}
209
Shawn McCarneyeb7bec42020-04-14 09:38:15 -0500210TEST(DeviceTests, Configure)
211{
212 // Test where Configuration and Rails were not specified in constructor
213 {
Bob King23243f82020-07-29 10:38:57 +0800214 // Create mock services.
215 MockServices services{};
216
Shawn McCarneyeb7bec42020-04-14 09:38:15 -0500217 // Create Device
218 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
219 std::unique_ptr<Device> device = std::make_unique<Device>(
220 "reg1", true, "/system/chassis/motherboard/reg1",
221 std::move(i2cInterface));
222 Device* devicePtr = device.get();
223
224 // Create Chassis that contains Device
225 std::vector<std::unique_ptr<Device>> devices{};
226 devices.emplace_back(std::move(device));
227 std::unique_ptr<Chassis> chassis =
228 std::make_unique<Chassis>(1, std::move(devices));
229 Chassis* chassisPtr = chassis.get();
230
231 // Create System that contains Chassis
232 std::vector<std::unique_ptr<Rule>> rules{};
233 std::vector<std::unique_ptr<Chassis>> chassisVec{};
234 chassisVec.emplace_back(std::move(chassis));
235 System system{std::move(rules), std::move(chassisVec)};
236
237 // Call configure(). Should do nothing.
238 journal::clear();
Bob King23243f82020-07-29 10:38:57 +0800239 devicePtr->configure(services, system, *chassisPtr);
Shawn McCarneyeb7bec42020-04-14 09:38:15 -0500240 EXPECT_EQ(journal::getDebugMessages().size(), 0);
241 EXPECT_EQ(journal::getErrMessages().size(), 0);
242 }
243
244 // Test where Configuration and Rails were specified in constructor
245 {
Bob King23243f82020-07-29 10:38:57 +0800246 // Create mock services.
247 MockServices services{};
248
Shawn McCarneyeb7bec42020-04-14 09:38:15 -0500249 std::vector<std::unique_ptr<Rail>> rails{};
250
251 // Create Rail vdd0
252 {
253 // Create Configuration for Rail
254 std::optional<double> volts{1.3};
255 std::unique_ptr<MockAction> action = std::make_unique<MockAction>();
256 EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true));
257 std::vector<std::unique_ptr<Action>> actions{};
258 actions.emplace_back(std::move(action));
259 std::unique_ptr<Configuration> configuration =
260 std::make_unique<Configuration>(volts, std::move(actions));
261
262 // Create Rail
263 std::unique_ptr<Rail> rail =
264 std::make_unique<Rail>("vdd0", std::move(configuration));
265 rails.emplace_back(std::move(rail));
266 }
267
268 // Create Rail vio0
269 {
270 // Create Configuration for Rail
271 std::optional<double> volts{3.2};
272 std::unique_ptr<MockAction> action = std::make_unique<MockAction>();
273 EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true));
274 std::vector<std::unique_ptr<Action>> actions{};
275 actions.emplace_back(std::move(action));
276 std::unique_ptr<Configuration> configuration =
277 std::make_unique<Configuration>(volts, std::move(actions));
278
279 // Create Rail
280 std::unique_ptr<Rail> rail =
281 std::make_unique<Rail>("vio0", std::move(configuration));
282 rails.emplace_back(std::move(rail));
283 }
284
285 // Create Configuration for Device
286 std::optional<double> volts{};
287 std::unique_ptr<MockAction> action = std::make_unique<MockAction>();
288 EXPECT_CALL(*action, execute).Times(1).WillOnce(Return(true));
289 std::vector<std::unique_ptr<Action>> actions{};
290 actions.emplace_back(std::move(action));
291 std::unique_ptr<Configuration> configuration =
292 std::make_unique<Configuration>(volts, std::move(actions));
293
294 // Create Device
295 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
296 std::unique_ptr<PresenceDetection> presenceDetection{};
297 std::unique_ptr<Device> device = std::make_unique<Device>(
298 "reg1", true, "/system/chassis/motherboard/reg1",
299 std::move(i2cInterface), std::move(presenceDetection),
300 std::move(configuration), std::move(rails));
301 Device* devicePtr = device.get();
302
303 // Create Chassis that contains Device
304 std::vector<std::unique_ptr<Device>> devices{};
305 devices.emplace_back(std::move(device));
306 std::unique_ptr<Chassis> chassis =
307 std::make_unique<Chassis>(1, std::move(devices));
308 Chassis* chassisPtr = chassis.get();
309
310 // Create System that contains Chassis
311 std::vector<std::unique_ptr<Rule>> rules{};
312 std::vector<std::unique_ptr<Chassis>> chassisVec{};
313 chassisVec.emplace_back(std::move(chassis));
314 System system{std::move(rules), std::move(chassisVec)};
315
316 // Call configure(). For the Device and both Rails, should execute the
317 // Configuration and log a debug message.
318 journal::clear();
Bob King23243f82020-07-29 10:38:57 +0800319 devicePtr->configure(services, system, *chassisPtr);
Shawn McCarneyeb7bec42020-04-14 09:38:15 -0500320 std::vector<std::string> expectedDebugMessages{
Shawn McCarney525e20c2020-04-14 11:05:39 -0500321 "Configuring reg1", "Configuring vdd0: volts=1.300000",
322 "Configuring vio0: volts=3.200000"};
Shawn McCarneyeb7bec42020-04-14 09:38:15 -0500323 EXPECT_EQ(journal::getDebugMessages(), expectedDebugMessages);
324 EXPECT_EQ(journal::getErrMessages().size(), 0);
325 }
326}
327
Shawn McCarney0b1a0e72020-03-11 18:01:44 -0500328TEST(DeviceTests, GetConfiguration)
Shawn McCarneya2461b32019-10-24 18:53:01 -0500329{
Shawn McCarney0b1a0e72020-03-11 18:01:44 -0500330 // Test where Configuration was not specified in constructor
331 {
332 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
333 std::move(createI2CInterface())};
334 EXPECT_EQ(device.getConfiguration(), nullptr);
335 }
Shawn McCarneyafb7fc32019-12-11 19:42:03 -0600336
Shawn McCarney0b1a0e72020-03-11 18:01:44 -0500337 // Test where Configuration was specified in constructor
338 {
339 std::unique_ptr<PresenceDetection> presenceDetection{};
340
341 // Create Configuration
342 std::optional<double> volts{3.2};
343 std::vector<std::unique_ptr<Action>> actions{};
344 actions.push_back(std::make_unique<MockAction>());
345 actions.push_back(std::make_unique<MockAction>());
346 std::unique_ptr<Configuration> configuration =
347 std::make_unique<Configuration>(volts, std::move(actions));
348
349 // Create Device
350 Device device{"vdd_reg",
351 true,
352 "/system/chassis/motherboard/reg2",
353 std::move(createI2CInterface()),
354 std::move(presenceDetection),
355 std::move(configuration)};
356 EXPECT_NE(device.getConfiguration(), nullptr);
357 EXPECT_EQ(device.getConfiguration()->getVolts().has_value(), true);
358 EXPECT_EQ(device.getConfiguration()->getVolts().value(), 3.2);
359 EXPECT_EQ(device.getConfiguration()->getActions().size(), 2);
360 }
Shawn McCarneyafb7fc32019-12-11 19:42:03 -0600361}
362
363TEST(DeviceTests, GetFRU)
364{
365 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
366 std::move(createI2CInterface())};
367 EXPECT_EQ(device.getFRU(), "/system/chassis/motherboard/reg2");
368}
369
370TEST(DeviceTests, GetI2CInterface)
371{
372 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
373 i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get();
374 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
375 std::move(i2cInterface)};
376 EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr);
Shawn McCarneya2461b32019-10-24 18:53:01 -0500377}
Shawn McCarney0b1a0e72020-03-11 18:01:44 -0500378
379TEST(DeviceTests, GetID)
380{
381 Device device{"vdd_reg", false, "/system/chassis/motherboard/reg2",
382 std::move(createI2CInterface())};
383 EXPECT_EQ(device.getID(), "vdd_reg");
384}
385
386TEST(DeviceTests, GetPresenceDetection)
387{
388 // Test where PresenceDetection was not specified in constructor
389 {
390 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
391 std::move(createI2CInterface())};
392 EXPECT_EQ(device.getPresenceDetection(), nullptr);
393 }
394
395 // Test where PresenceDetection was specified in constructor
396 {
397 // Create PresenceDetection
398 std::vector<std::unique_ptr<Action>> actions{};
399 actions.push_back(std::make_unique<MockAction>());
400 std::unique_ptr<PresenceDetection> presenceDetection =
401 std::make_unique<PresenceDetection>(std::move(actions));
402
403 // Create Device
404 Device device{"vdd_reg", false, "/system/chassis/motherboard/reg2",
405 std::move(createI2CInterface()),
406 std::move(presenceDetection)};
407 EXPECT_NE(device.getPresenceDetection(), nullptr);
408 EXPECT_EQ(device.getPresenceDetection()->getActions().size(), 1);
409 }
410}
411
412TEST(DeviceTests, GetRails)
413{
414 // Test where no rails were specified in constructor
415 {
416 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
417 std::move(createI2CInterface())};
418 EXPECT_EQ(device.getRails().size(), 0);
419 }
420
421 // Test where rails were specified in constructor
422 {
423 std::unique_ptr<PresenceDetection> presenceDetection{};
424 std::unique_ptr<Configuration> configuration{};
425
426 // Create vector of Rail objects
427 std::vector<std::unique_ptr<Rail>> rails{};
428 rails.push_back(std::make_unique<Rail>("vdd0"));
429 rails.push_back(std::make_unique<Rail>("vdd1"));
430
431 // Create Device
432 Device device{"vdd_reg",
433 false,
434 "/system/chassis/motherboard/reg2",
435 std::move(createI2CInterface()),
436 std::move(presenceDetection),
437 std::move(configuration),
438 std::move(rails)};
439 EXPECT_EQ(device.getRails().size(), 2);
440 EXPECT_EQ(device.getRails()[0]->getID(), "vdd0");
441 EXPECT_EQ(device.getRails()[1]->getID(), "vdd1");
442 }
443}
444
445TEST(DeviceTests, IsRegulator)
446{
447 Device device{"vdd_reg", false, "/system/chassis/motherboard/reg2",
448 std::move(createI2CInterface())};
449 EXPECT_EQ(device.isRegulator(), false);
450}
Bob King8e1cd0b2020-07-08 13:30:27 +0800451
452TEST(DeviceTests, MonitorSensors)
453{
454 // Test where Rails were not specified in constructor
455 {
456 // Create mock I2CInterface. A two-byte read should NOT occur.
457 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
458 std::make_unique<i2c::MockedI2CInterface>();
459 EXPECT_CALL(*i2cInterface, read(A<uint8_t>(), A<uint16_t&>())).Times(0);
460
461 // Create Device
462 std::unique_ptr<Device> device = std::make_unique<Device>(
463 "reg1", true, "/system/chassis/motherboard/reg1",
464 std::move(i2cInterface));
465 Device* devicePtr = device.get();
466
467 // Create Chassis that contains Device
468 std::vector<std::unique_ptr<Device>> devices{};
469 devices.emplace_back(std::move(device));
470 std::unique_ptr<Chassis> chassis =
471 std::make_unique<Chassis>(1, std::move(devices));
472 Chassis* chassisPtr = chassis.get();
473
474 // Create System that contains Chassis
475 std::vector<std::unique_ptr<Rule>> rules{};
476 std::vector<std::unique_ptr<Chassis>> chassisVec{};
477 chassisVec.emplace_back(std::move(chassis));
478 System system{std::move(rules), std::move(chassisVec)};
479
480 // Call monitorSensors(). Should do nothing.
481 journal::clear();
482 devicePtr->monitorSensors(system, *chassisPtr);
483 EXPECT_EQ(journal::getDebugMessages().size(), 0);
484 EXPECT_EQ(journal::getErrMessages().size(), 0);
485 }
486
487 // Test where Rails were specified in constructor
488 {
489 std::vector<std::unique_ptr<Rail>> rails{};
490
491 // Create PMBusReadSensorAction
492 pmbus_utils::SensorValueType type{pmbus_utils::SensorValueType::iout};
493 uint8_t command = 0x8C;
494 pmbus_utils::SensorDataFormat format{
495 pmbus_utils::SensorDataFormat::linear_11};
496 std::optional<int8_t> exponent{};
497 std::unique_ptr<PMBusReadSensorAction> action =
498 std::make_unique<PMBusReadSensorAction>(type, command, format,
499 exponent);
500
501 // Create mock I2CInterface. A two-byte read should occur.
502 std::unique_ptr<i2c::MockedI2CInterface> i2cInterface =
503 std::make_unique<i2c::MockedI2CInterface>();
504 EXPECT_CALL(*i2cInterface, isOpen).Times(1).WillOnce(Return(true));
505 EXPECT_CALL(*i2cInterface, read(TypedEq<uint8_t>(0x8C), A<uint16_t&>()))
506 .Times(1);
507
508 // Create SensorMonitoring
509 std::vector<std::unique_ptr<Action>> actions{};
510 actions.emplace_back(std::move(action));
511 std::unique_ptr<SensorMonitoring> sensorMonitoring =
512 std::make_unique<SensorMonitoring>(std::move(actions));
513
514 // Create Rail
515 std::unique_ptr<Configuration> configuration{};
516 std::unique_ptr<Rail> rail = std::make_unique<Rail>(
517 "vdd0", std::move(configuration), std::move(sensorMonitoring));
518 rails.emplace_back(std::move(rail));
519
520 // Create Device
521 std::unique_ptr<PresenceDetection> presenceDetection{};
522 std::unique_ptr<Configuration> deviceConfiguration{};
523 std::unique_ptr<Device> device = std::make_unique<Device>(
524 "reg1", true, "/system/chassis/motherboard/reg1",
525 std::move(i2cInterface), std::move(presenceDetection),
526 std::move(deviceConfiguration), std::move(rails));
527 Device* devicePtr = device.get();
528
529 // Create Chassis that contains Device
530 std::vector<std::unique_ptr<Device>> devices{};
531 devices.emplace_back(std::move(device));
532 std::unique_ptr<Chassis> chassis =
533 std::make_unique<Chassis>(1, std::move(devices));
534 Chassis* chassisPtr = chassis.get();
535
536 // Create System that contains Chassis
537 std::vector<std::unique_ptr<Rule>> rules{};
538 std::vector<std::unique_ptr<Chassis>> chassisVec{};
539 chassisVec.emplace_back(std::move(chassis));
540 System system{std::move(rules), std::move(chassisVec)};
541
542 // Call monitorSensors().
543 journal::clear();
544 devicePtr->monitorSensors(system, *chassisPtr);
545 EXPECT_EQ(journal::getDebugMessages().size(), 0);
546 EXPECT_EQ(journal::getErrMessages().size(), 0);
547 }
548}