From 3ce5c484aa9d25927b106f9bd3f819ec861176ad Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Thu, 25 May 2017 21:31:58 -0400 Subject: Add testcase for callbacks Change-Id: Iff1ddb9c18b5384d05a4d2dbfba95ade8cc1783c Signed-off-by: Brad Bishop --- src/test/.gitignore | 2 + src/test/Makefile.am | 25 ++++++++++++ src/test/callbackgentest.cpp | 35 ++++++++++++++++ src/test/templates/callbackgentest.mako.hpp | 17 ++++++++ src/test/yaml/callbackgentest/one.yaml | 62 +++++++++++++++++++++++++++++ src/test/yaml/callbackgentest/two.yaml | 27 +++++++++++++ 6 files changed, 168 insertions(+) create mode 100644 src/test/callbackgentest.cpp create mode 100644 src/test/templates/callbackgentest.mako.hpp create mode 100644 src/test/yaml/callbackgentest/one.yaml create mode 100644 src/test/yaml/callbackgentest/two.yaml (limited to 'src/test') diff --git a/src/test/.gitignore b/src/test/.gitignore index c3c7a0c..9c5e674 100644 --- a/src/test/.gitignore +++ b/src/test/.gitignore @@ -7,3 +7,5 @@ /propertywatchtest /propertywatchgentest.hpp /propertywatchgentest +/callbackgentest.hpp +/callbackgentest diff --git a/src/test/Makefile.am b/src/test/Makefile.am index fe66203..f4e2e46 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -104,3 +104,28 @@ propertywatchtest_LDADD = \ ${gtest_ldadd} \ ${SDBUSPLUS_LIBS} \ $(builddir)/../propertywatch.o + +check_PROGRAMS += callbackgentest +callbackgentest_SOURCES = \ + callbackgentest.cpp +callbackgentest_CXXFLAGS = \ + $(gtest_cflags) +callbackgentest_LDFLAGS = \ + $(OESDK_TESTCASE_FLAGS) +callbackgentest_LDADD = \ + ${gtest_ldadd} + +BUILT_SOURCES += callbackgentest.hpp +CLEANFILES += callbackgentest.hpp + +CALLBACK_TEST_GEN_DEPS = \ + templates/callbackgentest.mako.hpp \ + yaml/callbackgentest + +callbackgentest.hpp: $(CALLBACK_TEST_GEN_DEPS) + $(AM_V_GEN) $(PYTHON) $(PDMGEN) \ + -t callbackgentest.mako.hpp \ + -p "${TEMPLATESEARCH}" \ + -d yaml/callbackgentest \ + -o $(builddir)/$@ \ + generate-cpp diff --git a/src/test/callbackgentest.cpp b/src/test/callbackgentest.cpp new file mode 100644 index 0000000..77fe60a --- /dev/null +++ b/src/test/callbackgentest.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include "data_types.hpp" + +using namespace phosphor::dbus::monitoring; + +using Index = std::map, size_t>; + +#include "callbackgentest.hpp" + +const std::array, 4> expectedCallbacks = +{ + { + std::tuple{"int32_t", 0}, + std::tuple{"int32_t", 0}, + std::tuple{"std::string", 1}, + std::tuple{"std::string", 2}, + } +}; + +TEST(CallbackGenTest, CallbacksSameSize) +{ + ASSERT_EQ(sizeof(expectedCallbacks), sizeof(callbacks)); +} + +TEST(CallbackGenTest, CallbacksSameContent) +{ + size_t i; + for (i = 0; i < expectedCallbacks.size(); ++i) + { + ASSERT_EQ(callbacks[i], + expectedCallbacks[i]); + } +} diff --git a/src/test/templates/callbackgentest.mako.hpp b/src/test/templates/callbackgentest.mako.hpp new file mode 100644 index 0000000..f387c23 --- /dev/null +++ b/src/test/templates/callbackgentest.mako.hpp @@ -0,0 +1,17 @@ +auto storageCount = ${len(instances)}; + +const std::array indicies = {{ +% for g in instancegroups: + { + % for i in g.members: + {Index::key_type{${i[0]}, ${i[2]}, ${i[3]}}, ${i[5]}}, + % endfor + }, +% endfor +}}; + +const std::array, ${len(callbacks)}> callbacks = {{ +% for c in callbacks: + std::tuple{"${c.datatype}", ${c.instances}}, +% endfor +}}; diff --git a/src/test/yaml/callbackgentest/one.yaml b/src/test/yaml/callbackgentest/one.yaml new file mode 100644 index 0000000..e94b262 --- /dev/null +++ b/src/test/yaml/callbackgentest/one.yaml @@ -0,0 +1,62 @@ +# Validate two callbacks that share an index +# and a single callback with its own index. +# +# Expecting three callbacks pointing at two indicies. + +- name: test path group 1 + class: group + group: path + members: + - meta: path + path: /xyz/openbmc_project/testing/inst4 + +- name: test path group 2 + class: group + group: path + members: + - meta: path + path: /xyz/openbmc_project/testing/inst4 + - meta: path + path: /xyz/openbmc_project/testing/inst6 + +- name: test property group 1 + class: group + group: property + type: int32 + members: + - interface: xyz.openbmc_project.Sensor.Iface1 + meta: property + property: Value + +- name: test property group 2 + class: group + group: property + type: string + members: + - interface: xyz.openbmc_project.Sensor.Iface3 + meta: property + property: Value2 + +- name: test journal callback 1 + class: callback + callback: journal + paths: test path group 1 + properties: test property group 1 + severity: INFO + message: Hello world from PDM! + +- name: test journal callback 2 + class: callback + callback: journal + paths: test path group 1 + properties: test property group 1 + severity: INFO + message: Hello world from PDM! + +- name: test journal callback 3 + class: callback + callback: journal + paths: test path group 2 + properties: test property group 2 + severity: INFO + message: Hello world from PDM! diff --git a/src/test/yaml/callbackgentest/two.yaml b/src/test/yaml/callbackgentest/two.yaml new file mode 100644 index 0000000..6037f43 --- /dev/null +++ b/src/test/yaml/callbackgentest/two.yaml @@ -0,0 +1,27 @@ +# Validate the same callback name works in differnt config files. + +- name: test path group 1 + class: group + group: path + members: + - meta: path + path: /xyz/openbmc_project/testing/inst4 + - meta: path + path: /xyz/openbmc_project/testing/inst6 + +- name: test property group 1 + class: group + group: property + type: string + members: + - interface: xyz.openbmc_project.Sensor.Iface3 + meta: property + property: Value2 + +- name: test journal callback 1 + class: callback + callback: journal + paths: test path group 1 + properties: test property group 1 + severity: INFO + message: Hello world from PDM! -- cgit v1.2.1