Add iotest for sdevent io wrapper

Change-Id: I5f3054720e9c48248351c398b58f98f499799a0a
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/sdevent/test/iotest.cpp b/sdevent/test/iotest.cpp
new file mode 100644
index 0000000..015f87b
--- /dev/null
+++ b/sdevent/test/iotest.cpp
@@ -0,0 +1,42 @@
+#include <gtest/gtest.h>
+#include <thread>
+#include <unistd.h>
+#include "sdevent/event.hpp"
+#include "sdevent/io.hpp"
+
+TEST(IoTest, TestIo)
+{
+    // Validate an sd event io callback can be
+    // constructed, added to an event loop, and
+    // that the callback is invoked.
+
+    auto loop = sdevent::event::newDefault();
+    auto expected = 100;
+    volatile auto actual = 0;
+
+    std::array<int, 2> fds;
+    auto rc = pipe(fds.data());
+    ASSERT_EQ(rc, 0);
+
+    auto t = std::thread([&loop](){loop.loop();});
+
+    sdevent::event::io::IO io(
+        loop,
+        fds.data()[0],
+        [&fds, &actual, &loop](auto& s)
+        {
+            auto tmp = 0;
+            auto rc = read(fds.data()[0], &tmp, sizeof(tmp));
+            ASSERT_GT(rc, 0);
+            actual = tmp;
+            loop.exit();
+        });
+
+    rc = write(fds.data()[1], &expected, sizeof(expected));
+    ASSERT_GT(rc, 0);
+    t.join();
+    close(fds.data()[0]);
+    close(fds.data()[1]);
+
+    ASSERT_EQ(expected, actual);
+}