Create PMBusBase class to allow for mocking
Derive the PMBus class from a new PMBusBase class to allow for the use
of Google Mock for unit testing. Create an interface to PMBusBase in the
phosphor-power-supply code.
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
Change-Id: I6dd8d8a64bdece0d82478450ec83f1aefcae4c75
diff --git a/pmbus.cpp b/pmbus.cpp
index 5c16624..d8b1804 100644
--- a/pmbus.cpp
+++ b/pmbus.cpp
@@ -336,5 +336,21 @@
}
}
+std::unique_ptr<PMBusBase> PMBus::createPMBus(std::uint8_t bus,
+ const std::string& address)
+{
+ const std::string physpath = {"/sys/bus/i2c/devices/" +
+ std::to_string(bus) + "-" + address};
+ auto interface = std::make_unique<PMBus>(physpath);
+
+ return interface;
+}
+
+std::unique_ptr<PMBusBase> createPMBus(std::uint8_t bus,
+ const std::string& address)
+{
+ return PMBus::createPMBus(bus, address);
+}
+
} // namespace pmbus
} // namespace phosphor