diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-06-15 15:16:18 -0400 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-02 20:18:18 +0000 |
commit | a51f8fe0747374fe13c3ac0ab09d3e5b612ed194 (patch) | |
tree | 1bd4408f95d22c198e9fe3cf23b3fe80335bb388 /sdevent | |
parent | e2c65d43ef41289271c3a504e1e9852b2249e290 (diff) | |
download | phosphor-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')
-rw-r--r-- | sdevent/test/.gitignore | 1 | ||||
-rw-r--r-- | sdevent/test/Makefile.am | 18 | ||||
-rw-r--r-- | sdevent/test/iotest.cpp | 42 |
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); +} |