Add I2C interface to Device class
Add an I2C interface to the phosphor-regulators C++ Device class.
Use the I2CInterface class from the tools/i2c directory of this
repository.
Also add the other required properties of the JSON "device" object to
the C++ Device class.
The JSON "device" object is in the phosphor-regulators config file. For
more information, see phosphor-regulators/docs/config_file/device.md.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: Idc780b1a11372d6597762cfb6540fa44f1cfb64e
diff --git a/phosphor-regulators/test/id_map_tests.cpp b/phosphor-regulators/test/id_map_tests.cpp
index ffa6c15..d3053d7 100644
--- a/phosphor-regulators/test/id_map_tests.cpp
+++ b/phosphor-regulators/test/id_map_tests.cpp
@@ -14,7 +14,9 @@
* limitations under the License.
*/
#include "device.hpp"
+#include "i2c_interface.hpp"
#include "id_map.hpp"
+#include "mocked_i2c_interface.hpp"
#include "rail.hpp"
#include "rule.hpp"
@@ -22,6 +24,7 @@
#include <memory>
#include <stdexcept>
#include <string>
+#include <utility>
#include <vector>
#include <gtest/gtest.h>
@@ -33,8 +36,11 @@
IDMap idMap{};
// Create device
+ std::unique_ptr<i2c::I2CInterface> i2cInterface =
+ i2c::create(1, 0x70, i2c::I2CInterface::InitialState::CLOSED);
std::string id{"vio_reg"};
- Device device{id};
+ Device device{id, true, "/system/chassis/motherboard/vio_reg",
+ std::move(i2cInterface)};
// Verify device is not initially in map
EXPECT_THROW(idMap.getDevice(id), std::invalid_argument);
@@ -123,9 +129,14 @@
{
IDMap idMap{};
- // Add a device to the map
+ // Create device
+ std::unique_ptr<i2c::I2CInterface> i2cInterface =
+ i2c::create(1, 0x70, i2c::I2CInterface::InitialState::CLOSED);
std::string id{"vio_reg"};
- Device device{id};
+ Device device{id, true, "/system/chassis/motherboard/vio_reg",
+ std::move(i2cInterface)};
+
+ // Add a device to the map
idMap.addDevice(device);
// Test where ID found in map