From b97bfff73e44e53571f8a00b80ec947496930d7b Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Thu, 25 May 2017 22:14:54 -0400 Subject: Add testcase for conditions Change-Id: I94059c0be78d5b97e7e0e11c78d4a164a98a483e Signed-off-by: Brad Bishop --- src/test/.gitignore | 2 + src/test/Makefile.am | 25 ++++++++ src/test/conditiongentest.cpp | 54 ++++++++++++++++ src/test/templates/conditiongentest.mako.hpp | 12 ++++ src/test/yaml/conditiongentest/test.yaml | 95 ++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+) create mode 100644 src/test/conditiongentest.cpp create mode 100644 src/test/templates/conditiongentest.mako.hpp create mode 100644 src/test/yaml/conditiongentest/test.yaml (limited to 'src/test') diff --git a/src/test/.gitignore b/src/test/.gitignore index 55db6d7..9c938e1 100644 --- a/src/test/.gitignore +++ b/src/test/.gitignore @@ -11,3 +11,5 @@ /callbackgentest /callbackgroupgentest.hpp /callbackgroupgentest +/conditiongentest.hpp +/conditiongentest diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 893f264..324eec7 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -154,3 +154,28 @@ callbackgroupgentest.hpp: $(CALLBACKGROUP_TEST_GEN_DEPS) -d yaml/callbackgroupgentest \ -o $(builddir)/$@ \ generate-cpp + +check_PROGRAMS += conditiongentest +conditiongentest_SOURCES = \ + conditiongentest.cpp +conditiongentest_CXXFLAGS = \ + $(gtest_cflags) +conditiongentest_LDFLAGS = \ + $(OESDK_TESTCASE_FLAGS) +conditiongentest_LDADD = \ + ${gtest_ldadd} + +BUILT_SOURCES += conditiongentest.hpp +CLEANFILES += conditiongentest.hpp + +CONDITION_TEST_GEN_DEPS = \ + templates/conditiongentest.mako.hpp \ + yaml/conditiongentest + +conditiongentest.hpp: $(CONDITION_TEST_GEN_DEPS) + $(AM_V_GEN) $(PYTHON) $(PDMGEN) \ + -t conditiongentest.mako.hpp \ + -p "${TEMPLATESEARCH}" \ + -d yaml/conditiongentest \ + -o $(builddir)/$@ \ + generate-cpp diff --git a/src/test/conditiongentest.cpp b/src/test/conditiongentest.cpp new file mode 100644 index 0000000..76ea608 --- /dev/null +++ b/src/test/conditiongentest.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include "data_types.hpp" + +using namespace phosphor::dbus::monitoring; + +#include "conditiongentest.hpp" + +const std::array, 2> expectedGroups = +{ + { + {0}, + {1}, + } +}; + +const std::array expectedCallbacks = +{ + 0, + 0, + 1, + 1, +}; + +TEST(ConditionGenTest, GroupsSameSize) +{ + ASSERT_EQ(sizeof(expectedGroups), sizeof(groups)); +} + +TEST(ConditionGenTest, CallbacksSameSize) +{ + ASSERT_EQ(sizeof(expectedGroups), sizeof(groups)); +} + +TEST(ConditionGenTest, GroupsSameContent) +{ + size_t i; + for (i = 0; i < expectedGroups.size(); ++i) + { + ASSERT_EQ(groups[i], + expectedGroups[i]); + } +} + +TEST(ConditionGenTest, CallbacksSameContent) +{ + size_t i; + for (i = 0; i < expectedCallbacks.size(); ++i) + { + ASSERT_EQ(callbacks[i], + expectedCallbacks[i]); + } +} diff --git a/src/test/templates/conditiongentest.mako.hpp b/src/test/templates/conditiongentest.mako.hpp new file mode 100644 index 0000000..d3267bb --- /dev/null +++ b/src/test/templates/conditiongentest.mako.hpp @@ -0,0 +1,12 @@ +const std::array, ${len(callbackgroups)}> groups = {{ +% for g in callbackgroups: + {${', '.join([str(x) for x in g.members])}}, +% endfor +}}; + +<% graphs = [ x for x in callbacks if hasattr(x, 'graph')] %>\ +const std::array callbacks = { +% for g in graphs: + ${g.graph}, +% endfor +}; diff --git a/src/test/yaml/conditiongentest/test.yaml b/src/test/yaml/conditiongentest/test.yaml new file mode 100644 index 0000000..0444d55 --- /dev/null +++ b/src/test/yaml/conditiongentest/test.yaml @@ -0,0 +1,95 @@ +# Validate condition callback rendering. + +- 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 count condition 1 + class: condition + condition: count + paths: test path group 1 + properties: test property group 1 + callback: test journal callback 1 + countop: '>=' + countbound: 3 + op: '>=' + bound: 115 + +- name: test count condition 2 + class: condition + condition: count + paths: test path group 1 + properties: test property group 1 + callback: test journal callback 1 + countop: '>=' + countbound: 3 + op: '>=' + bound: 115 + +- 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 count condition 3 + class: condition + condition: count + paths: test path group 1 + properties: test property group 1 + callback: test journal callback 2 + countop: '>=' + countbound: 3 + op: '>=' + bound: 115 + +- name: test count condition 4 + class: condition + condition: count + paths: test path group 1 + properties: test property group 1 + callback: test journal callback 2 + countop: '>=' + countbound: 3 + op: '>=' + bound: 115 + +- 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! -- cgit v1.2.1