From e5576bf2a145117c583c3ad05fec3a08aa90993d Mon Sep 17 00:00:00 2001 From: Marri Devender Rao Date: Mon, 16 Apr 2018 05:56:11 -0500 Subject: Add unit test for watches created on object paths Verify the watches created for the object path being watched for 'interfaces added' signal. Resolves openbmc/openbmc#3003 Change-Id: I88a3adbbe91fcbe5bdf606d2f460d4d0c6d9c1a2 Signed-off-by: Marri Devender Rao --- src/test/Makefile.am | 25 +++++++++++++++++++++++++ src/test/interfaceaddtest.cpp | 28 ++++++++++++++++++++++++++++ src/test/templates/interfaceaddtest.mako.hpp | 11 +++++++++++ src/test/yaml/interfaceaddtest/one.yaml | 22 ++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/test/interfaceaddtest.cpp create mode 100644 src/test/templates/interfaceaddtest.mako.hpp create mode 100644 src/test/yaml/interfaceaddtest/one.yaml diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 8f3cd02..d09e678 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -201,3 +201,28 @@ callbacktest_LDADD = \ $(builddir)/../event_manager.o \ $(builddir)/../event_serialize.o \ -lstdc++fs + +check_PROGRAMS += interfaceaddtest +interfaceaddtest_SOURCES = \ + interfaceaddtest.cpp +interfaceaddtest_CXXFLAGS = \ + $(gtest_cflags) +interfaceaddtest_LDFLAGS = \ + $(OESDK_TESTCASE_FLAGS) +interfaceaddtest_LDADD = \ + ${gtest_ldadd} + +BUILT_SOURCES += interfaceaddtest.hpp +CLEANFILES += interfaceaddtest.hpp + +INTERFACEADD_TEST_GEN_DEPS = \ + templates/interfaceaddtest.mako.hpp \ + yaml/interfaceaddtest + +interfaceaddtest.hpp: $(PDMGEN) $(INTERFACEADD_TEST_GEN_DEPS) + $(AM_V_GEN) $(PYTHON) $(PDMGEN) \ + -t interfaceaddtest.mako.hpp \ + -p "${TEMPLATESEARCH}" \ + -d ${srcdir}/yaml/interfaceaddtest \ + -o $(builddir)/$@ \ + generate-cpp diff --git a/src/test/interfaceaddtest.cpp b/src/test/interfaceaddtest.cpp new file mode 100644 index 0000000..d80f437 --- /dev/null +++ b/src/test/interfaceaddtest.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include "pathwatchimpl.hpp" +#include "event.hpp" + +using namespace std::string_literals; +using namespace phosphor::dbus::monitoring; + +#include "interfaceaddtest.hpp" + +const std::array expectedPaths = { + "/xyz/openbmc_project/testing/inst1"s, +}; + +const std::array expectedWatches = { + "/xyz/openbmc_project/testing/inst1"s, +}; + +TEST(InterfaceAddTest, PathsSameSize) +{ + ASSERT_EQ(sizeof(expectedPaths), sizeof(paths)); +} + +TEST(InterfaceAddTest, WatchSameSize) +{ + ASSERT_EQ(expectedWatches.size(), pathwatches.size()); +} \ No newline at end of file diff --git a/src/test/templates/interfaceaddtest.mako.hpp b/src/test/templates/interfaceaddtest.mako.hpp new file mode 100644 index 0000000..3b0609a --- /dev/null +++ b/src/test/templates/interfaceaddtest.mako.hpp @@ -0,0 +1,11 @@ +const std::array paths = { +% for p in paths: + "${p.name}"s, +% endfor +}; + +const std::array pathwatches = {{ +% for w in pathwatches: + paths[${w.pathinstances}], +% endfor +}}; diff --git a/src/test/yaml/interfaceaddtest/one.yaml b/src/test/yaml/interfaceaddtest/one.yaml new file mode 100644 index 0000000..f84389e --- /dev/null +++ b/src/test/yaml/interfaceaddtest/one.yaml @@ -0,0 +1,22 @@ +# Validate number of watches created for the object path +# +# Expecting one watch created for the object path +- name: errorlog path group + class: group + group: path + members: + - meta: PATH + path: /xyz/openbmc_project/testing/inst1 + +- name: pathwatch errorlog + description: > + class: pathwatch + pathwatch: path + paths: errorlog path group + pathcallback: create errorlog event + +- name: create errorlog event + class: pathcallback + pathcallback: eventpath + paths: errorlog path group + eventType: ErrorNotification -- cgit v1.2.1