summaryrefslogtreecommitdiffstats
path: root/sdevent
diff options
context:
space:
mode:
Diffstat (limited to 'sdevent')
-rw-r--r--sdevent/test/.gitignore1
-rw-r--r--sdevent/test/Makefile.am18
-rw-r--r--sdevent/test/iotest.cpp42
3 files changed, 61 insertions, 0 deletions
diff --git a/sdevent/test/.gitignore b/sdevent/test/.gitignore
index e69de29..014ec3f 100644
--- a/sdevent/test/.gitignore
+++ b/sdevent/test/.gitignore
@@ -0,0 +1 @@
+iotest
diff --git a/sdevent/test/Makefile.am b/sdevent/test/Makefile.am
index 56c3ab3..39790de 100644
--- a/sdevent/test/Makefile.am
+++ b/sdevent/test/Makefile.am
@@ -5,3 +5,21 @@ gtest_ldadd = -lgtest -lgtest_main -lgmock $(PTHREAD_LIBS)
check_PROGRAMS =
TESTS = $(check_PROGRAMS)
+
+check_PROGRAMS += iotest
+iotest_SOURCES = \
+ iotest.cpp
+iotest_CXXFLAGS = \
+ $(gtest_cflags) \
+ $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \
+ $(PHOSPHOR_LOGGING_CFLAGS) \
+ $(SDBUSPLUS_CFLAGS) \
+ $(SYSTEMD_CFLAGS)
+iotest_LDFLAGS = \
+ $(OESDK_TESTCASE_FLAGS)
+iotest_LDADD = \
+ $(gtest_ldadd) \
+ $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
+ $(PHOSPHOR_LOGGING_LIBS) \
+ $(SDBUSPLUS_LIBS) \
+ $(SYSTEMD_LIBS)
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