hwmonio: Add injection point to test internal behavior

With the complexities of the various behaviors within the read() method
of HwmonIO, introduce an injection point for testing.  There is a
default available, and therefore this is a surgical change that only
impacts future tests.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I1ead56c7fe1a2f87ebf316488e68f435a41c9d19
diff --git a/hwmonio.hpp b/hwmonio.hpp
index b0b8617..ff18204 100644
--- a/hwmonio.hpp
+++ b/hwmonio.hpp
@@ -9,6 +9,28 @@
 static constexpr auto retries = 10;
 static constexpr auto delay = std::chrono::milliseconds{100};
 
+/** @class FileSystemInterface
+ *  @brief Abstract base class allowing testing of HwmonIO.
+ *
+ *  This is used to provide testing of behaviors within HwmonIO.
+ */
+class FileSystemInterface
+{
+  public:
+    virtual ~FileSystemInterface() = default;
+    virtual int64_t read(const std::string& path) const = 0;
+    virtual void write(const std::string& path, uint32_t value) const = 0;
+};
+
+class FileSystem : public FileSystemInterface
+{
+  public:
+    int64_t read(const std::string& path) const override;
+    void write(const std::string& path, uint32_t value) const override;
+};
+
+extern FileSystem fileSystemImpl;
+
 /** @class HwmonIOInterface
  *  @brief Abstract base class defining a HwmonIOInterface.
  *
@@ -56,7 +78,8 @@
      *  @param[in] path - hwmon instance root - eg:
      *      /sys/class/hwmon/hwmon<N>
      */
-    explicit HwmonIO(const std::string& path);
+    explicit HwmonIO(const std::string& path,
+                     const FileSystemInterface* intf = &fileSystemImpl);
 
     /** @brief Perform formatted hwmon sysfs read.
      *
@@ -108,6 +131,7 @@
 
   private:
     std::string _p;
+    const FileSystemInterface* _intf;
 };
 
 } // namespace hwmonio