hwmonio:: Add Interface base class and tests

Enable injecting hwmonio::HwmonIO mocks for testing.

Tested: Ran on quanta-q71l and saw all sensors exported to dbus as
expected with the expected values.

Change-Id: I35912bf2a733932d9e1e774ff53b0114ae16560b
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/hwmonio.hpp b/hwmonio.hpp
index 619d6ad..d49f4db 100644
--- a/hwmonio.hpp
+++ b/hwmonio.hpp
@@ -8,6 +8,35 @@
 static constexpr auto retries = 10;
 static constexpr auto delay = std::chrono::milliseconds{100};
 
+/** @class HwmonIOInterface
+ *  @brief Abstract base class defining a HwmonIOInterface.
+ *
+ *  This is initially to provide easier testing through injection,
+ *  however, could in theory support non-sysfs handling of hwmon IO.
+ */
+class HwmonIOInterface
+{
+    public:
+        virtual ~HwmonIOInterface() = default;
+
+        virtual int64_t read(
+                const std::string& type,
+                const std::string& id,
+                const std::string& sensor,
+                size_t retries,
+                std::chrono::milliseconds delay) const = 0;
+
+        virtual void write(
+                uint32_t val,
+                const std::string& type,
+                const std::string& id,
+                const std::string& sensor,
+                size_t retries,
+                std::chrono::milliseconds delay) const = 0;
+
+        virtual std::string path() const = 0;
+};
+
 /** @class HwmonIO
  *  @brief Convenience wrappers for HWMON sysfs attribute IO.
  *
@@ -17,7 +46,7 @@
  *  cannot always be terminated externally before we try to
  *  do an io.
  */
-class HwmonIO
+class HwmonIO : public HwmonIOInterface
 {
     public:
         HwmonIO() = delete;
@@ -57,7 +86,7 @@
                 const std::string& id,
                 const std::string& sensor,
                 size_t retries,
-                std::chrono::milliseconds delay) const;
+                std::chrono::milliseconds delay) const override;
 
         /** @brief Perform formatted hwmon sysfs write.
          *
@@ -81,14 +110,14 @@
                 const std::string& id,
                 const std::string& sensor,
                 size_t retries,
-                std::chrono::milliseconds delay) const;
+                std::chrono::milliseconds delay) const override;
 
 
         /** @brief Hwmon instance path access.
          *
          *  @return path - The hwmon instance path.
          */
-        std::string path() const;
+        std::string path() const override;
 
     private:
         std::string p;