From b604480a43a25d0645b944fb16c1268d36782d36 Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Sun, 7 May 2017 23:14:57 -0400 Subject: Add testcases for path and path group support Change-Id: I296de0e0cb30e0e25f6677a06bd04fe15c2fd015 Signed-off-by: Brad Bishop --- src/test/.gitignore | 2 + src/test/Makefile.am | 25 ++++++ src/test/pathgentest.cpp | 144 ++++++++++++++++++++++++++++++++ src/test/templates/pathgentest.mako.hpp | 28 +++++++ src/test/yaml/pathgentest/groupone.yaml | 28 +++++++ src/test/yaml/pathgentest/grouptwo.yaml | 30 +++++++ 6 files changed, 257 insertions(+) create mode 100644 src/test/pathgentest.cpp create mode 100644 src/test/templates/pathgentest.mako.hpp create mode 100644 src/test/yaml/pathgentest/groupone.yaml create mode 100644 src/test/yaml/pathgentest/grouptwo.yaml (limited to 'src/test') diff --git a/src/test/.gitignore b/src/test/.gitignore index 7e563b8..c1bc7de 100644 --- a/src/test/.gitignore +++ b/src/test/.gitignore @@ -1,2 +1,4 @@ *.log *.trs +/pathgentest +/pathgentest.hpp diff --git a/src/test/Makefile.am b/src/test/Makefile.am index c44bffa..02772e7 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -11,3 +11,28 @@ BUILT_SOURCES = CLEANFILES = TESTS = $(check_PROGRAMS) + +check_PROGRAMS += pathgentest +pathgentest_SOURCES = \ + pathgentest.cpp +pathgentest_CXXFLAGS = \ + $(gtest_cflags) +pathgentest_LDFLAGS = \ + $(OESDK_TESTCASE_FLAGS) +pathgentest_LDADD = \ + ${gtest_ldadd} + +BUILT_SOURCES += pathgentest.hpp +CLEANFILES += pathgentest.hpp + +PATH_TEST_GEN_DEPS = \ + templates/pathgentest.mako.hpp \ + yaml/pathgentest + +pathgentest.hpp: $(PDMGEN) $(PATH_TEST_GEN_DEPS) + $(AM_V_GEN) $(PYTHON) $(PDMGEN) \ + -t pathgentest.mako.hpp \ + -p "${TEMPLATESEARCH}" \ + -d yaml/pathgentest \ + -o $(builddir)/$@ \ + generate-cpp diff --git a/src/test/pathgentest.cpp b/src/test/pathgentest.cpp new file mode 100644 index 0000000..2199182 --- /dev/null +++ b/src/test/pathgentest.cpp @@ -0,0 +1,144 @@ +#include +#include +#include +#include "data_types.hpp" + +using namespace std::string_literals; +using namespace phosphor::dbus::monitoring; +using PathMeta = TupleOfRefs; + +#include "pathgentest.hpp" + +const std::array expectedMeta = +{ + "path1"s, + "path3"s, + "path2"s, +}; + +const std::array expectedPaths = +{ + "/xyz/openbmc_project/testing/inst1"s, + "/xyz/openbmc_project/testing/inst2"s, + "/xyz/openbmc_project/testing/inst3"s, + "/xyz/openbmc_project/testing/inst4"s, + "/xyz/openbmc_project/testing/inst5"s, + "/xyz/openbmc_project/testing/inst6"s, +}; + +const std::array expectedPathMeta = +{ + { + PathMeta{ paths[0], meta[0] }, + PathMeta{ paths[1], meta[0] }, + PathMeta{ paths[2], meta[0] }, + PathMeta{ paths[3], meta[0] }, + PathMeta{ paths[0], meta[1] }, + PathMeta{ paths[1], meta[1] }, + PathMeta{ paths[2], meta[1] }, + PathMeta{ paths[3], meta[1] }, + PathMeta{ paths[4], meta[0] }, + PathMeta{ paths[5], meta[0] }, + PathMeta{ paths[3], meta[2] }, + PathMeta{ paths[2], meta[2] }, + PathMeta{ paths[1], meta[2] }, + PathMeta{ paths[0], meta[2] }, + } +}; + +const std::array, 4> expectedGroups = +{ + { + { + paths[0], + paths[1], + paths[2], + paths[3], + }, + { + paths[0], + paths[1], + paths[2], + paths[3], + }, + { + paths[0], + paths[1], + paths[4], + paths[5], + }, + { + paths[3], + paths[2], + paths[1], + paths[0], + }, + } +}; + +TEST(PathGenTest, MetaSameSize) +{ + ASSERT_EQ(sizeof(expectedMeta), sizeof(meta)); +} + +TEST(PathGenTest, PathsSameSize) +{ + ASSERT_EQ(sizeof(expectedPaths), sizeof(paths)); +} + +TEST(PathGenTest, PathMetaSameSize) +{ + ASSERT_EQ(sizeof(expectedPathMeta), sizeof(pathMeta)); +} + +TEST(PathGenTest, GroupsSameSize) +{ + ASSERT_EQ(sizeof(expectedGroups), sizeof(groups)); +} + +TEST(PathGenTest, MetaSameContent) +{ + size_t i; + for (i = 0; i < expectedMeta.size(); ++i) + { + ASSERT_EQ(meta[i], expectedMeta[i]); + } +} + +TEST(PathGenTest, PathsSameContent) +{ + size_t i; + for (i = 0; i < expectedPaths.size(); ++i) + { + ASSERT_EQ(paths[i], expectedPaths[i]); + } +} + +TEST(PathGenTest, PathMetaSameContent) +{ + size_t i; + for (i = 0; i < expectedPathMeta.size(); ++i) + { + const auto& path = std::get<0>(pathMeta[i]).get(); + const auto& expPath = std::get<0>(expectedPathMeta[i]).get(); + const auto& meta = std::get<1>(pathMeta[i]).get(); + const auto& expMeta = std::get<1>(expectedPathMeta[i]).get(); + + ASSERT_EQ(path, expPath); + ASSERT_EQ(meta, expMeta); + } +} + +TEST(PathGenTest, GroupsSameContent) +{ + size_t i; + for (i = 0; i < expectedGroups.size(); ++i) + { + size_t j; + for (j = 0; j < groups[i].size(); ++j) + { + ASSERT_EQ(groups[i][j].get(), expectedGroups[i][j].get()); + + } + } +} diff --git a/src/test/templates/pathgentest.mako.hpp b/src/test/templates/pathgentest.mako.hpp new file mode 100644 index 0000000..b217c56 --- /dev/null +++ b/src/test/templates/pathgentest.mako.hpp @@ -0,0 +1,28 @@ +const std::array meta = { +% for m in meta: + "${m.name}"s, +% endfor +}; + +const std::array paths = { +% for p in paths: + "${p.name}"s, +% endfor +}; + +const std::array pathMeta = {{ +% for p in pathmeta: + PathMeta{ paths[${p.path}], meta[${p.meta}] }, +% endfor +}}; + +const std::array, ${len(pathgroups)}> groups = {{ +% for g in pathgroups: + // ${g.name} + { + % for p in g.members: + paths[${p[0]}], + % endfor + }, +% endfor +}}; diff --git a/src/test/yaml/pathgentest/groupone.yaml b/src/test/yaml/pathgentest/groupone.yaml new file mode 100644 index 0000000..a4d5b57 --- /dev/null +++ b/src/test/yaml/pathgentest/groupone.yaml @@ -0,0 +1,28 @@ +# Validate paths are not duplicated when +# they exist in multiple groups. + +- name: test path group + class: group + group: path + members: + - meta: path1 + path: /xyz/openbmc_project/testing/inst1 + - meta: path1 + path: /xyz/openbmc_project/testing/inst2 + - meta: path1 + path: /xyz/openbmc_project/testing/inst3 + - meta: path1 + path: /xyz/openbmc_project/testing/inst4 + +- name: test path group 2 + class: group + group: path + members: + - meta: path3 + path: /xyz/openbmc_project/testing/inst1 + - meta: path3 + path: /xyz/openbmc_project/testing/inst2 + - meta: path3 + path: /xyz/openbmc_project/testing/inst3 + - meta: path3 + path: /xyz/openbmc_project/testing/inst4 diff --git a/src/test/yaml/pathgentest/grouptwo.yaml b/src/test/yaml/pathgentest/grouptwo.yaml new file mode 100644 index 0000000..911211e --- /dev/null +++ b/src/test/yaml/pathgentest/grouptwo.yaml @@ -0,0 +1,30 @@ +# Validate paths are not duplicated when +# they exist in multiple groups, and +# validate the same name can be used +# in different config files. + +- name: test path group + class: group + group: path + members: + - meta: path1 + path: /xyz/openbmc_project/testing/inst1 + - meta: path1 + path: /xyz/openbmc_project/testing/inst2 + - meta: path1 + path: /xyz/openbmc_project/testing/inst5 + - meta: path1 + path: /xyz/openbmc_project/testing/inst6 + +- name: test path group 2 + class: group + group: path + members: + - meta: path2 + path: /xyz/openbmc_project/testing/inst4 + - meta: path2 + path: /xyz/openbmc_project/testing/inst3 + - meta: path2 + path: /xyz/openbmc_project/testing/inst2 + - meta: path2 + path: /xyz/openbmc_project/testing/inst1 -- cgit v1.2.1