summaryrefslogtreecommitdiffstats
path: root/sdevent/test/iotest.cpp
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-06-15 15:16:18 -0400
committerPatrick Williams <patrick@stwcx.xyz>2017-08-02 20:18:18 +0000
commita51f8fe0747374fe13c3ac0ab09d3e5b612ed194 (patch)
tree1bd4408f95d22c198e9fe3cf23b3fe80335bb388 /sdevent/test/iotest.cpp
parente2c65d43ef41289271c3a504e1e9852b2249e290 (diff)
downloadphosphor-fan-presence-a51f8fe0747374fe13c3ac0ab09d3e5b612ed194.tar.gz
phosphor-fan-presence-a51f8fe0747374fe13c3ac0ab09d3e5b612ed194.zip
Add iotest for sdevent io wrapper
Change-Id: I5f3054720e9c48248351c398b58f98f499799a0a Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'sdevent/test/iotest.cpp')
-rw-r--r--sdevent/test/iotest.cpp42
1 files changed, 42 insertions, 0 deletions
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);
+}
OpenPOWER on IntegriCloud