test: unit test parse_led.py
Providing a test for parse_led.py since it was refactored.
Testing that various keys in the yaml are available in the cpp literal.
Change-Id: I94d03eb2a4d2bd3129971c4acbe75edd74449ed4
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/config/test-group-priority.yaml b/test/config/test-group-priority.yaml
new file mode 100644
index 0000000..ca5005f
--- /dev/null
+++ b/test/config/test-group-priority.yaml
@@ -0,0 +1,17 @@
+group1:
+ led1:
+ Action: "On"
+group2:
+ led1:
+ Action: "Off"
+group3:
+ led1:
+ Action: "Blink"
+ DutyOn: 50
+ Period: 1000
+group4:
+ Priority: 2
+ led1:
+ Action: "On"
+ led2:
+ Action: "Off"
diff --git a/test/config/test-led-priority.yaml b/test/config/test-led-priority.yaml
new file mode 100644
index 0000000..4dc755a
--- /dev/null
+++ b/test/config/test-led-priority.yaml
@@ -0,0 +1,22 @@
+group1:
+ led1:
+ Action: "On"
+ Priority: "On"
+group2:
+ led2:
+ Action: "Off"
+ Priority: "Off"
+group3:
+ led3:
+ Action: "Blink"
+ Priority: "Blink"
+group4:
+ led1:
+ Action: "Off"
+ Priority: "On"
+ led2:
+ Action: "On"
+ Priority: "Off"
+ led3:
+ Action: "On"
+ Priority: "Blink"
diff --git a/test/meson.build b/test/meson.build
index ae1b8e6..010f7f4 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -19,15 +19,37 @@
endif
endif
+test_yamls = [
+ 'test-group-priority',
+ 'test-led-priority'
+]
+
test_sources = [
'../manager/manager.cpp',
- '../utils.cpp'
+ '../utils.cpp',
]
+foreach yaml : test_yamls
+ gen_hpp = custom_target(
+ yaml + '.hpp',
+ command : [
+ prog_python,
+ meson.project_source_root() + '/scripts/parse_led.py',
+ '--filename', meson.project_source_root() + '/test/config/' + yaml + '.yaml',
+ '-o', meson.current_build_dir(),
+ '--output-filename', yaml + '.hpp'
+ ],
+ output : yaml + '.hpp')
+
+ test_sources += [ gen_hpp ]
+endforeach
+
tests = [
'utest.cpp',
'utest-led-json.cpp',
'utest-group-priority.cpp',
+ 'utest-led-yaml-group-priority.cpp',
+ 'utest-led-yaml-led-priority.cpp',
]
if get_option('persistent-led-asserted').allowed()
test_sources += [
diff --git a/test/utest-led-yaml-group-priority.cpp b/test/utest-led-yaml-group-priority.cpp
new file mode 100644
index 0000000..e48a199
--- /dev/null
+++ b/test/utest-led-yaml-group-priority.cpp
@@ -0,0 +1,101 @@
+#include "group.hpp"
+#include "ledlayout.hpp"
+#include "manager.hpp"
+#include "test-group-priority.hpp"
+
+#include <sdbusplus/bus.hpp>
+
+#include <algorithm>
+#include <set>
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::led;
+
+using Action = phosphor::led::Layout::Action;
+
+// systemLedMap is generated code
+// static const phosphor::led::GroupMap systemLedMap = {};
+
+const std::string basePath = "/xyz/openbmc_project/led/groups/";
+
+TEST(YamlGroupPriorityTest, assertYAMLLedOn)
+{
+ const std::string groupPath = basePath + "group1";
+ EXPECT_EQ(systemLedMap.contains(groupPath), true);
+
+ phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath);
+
+ EXPECT_EQ(group.priority, 0);
+ EXPECT_EQ(group.actionSet.size(), 1);
+
+ for (auto& led : group.actionSet)
+ {
+ EXPECT_EQ(led.name, "led1");
+ EXPECT_EQ(led.action, Action::On);
+ }
+}
+
+TEST(YamlGroupPriorityTest, assertYAMLLedOff)
+{
+ const std::string groupPath = basePath + "group2";
+ EXPECT_EQ(systemLedMap.contains(groupPath), true);
+
+ phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath);
+
+ EXPECT_EQ(group.priority, 0);
+ EXPECT_EQ(group.actionSet.size(), 1);
+
+ for (auto& led : group.actionSet)
+ {
+ EXPECT_EQ(led.name, "led1");
+ EXPECT_EQ(led.action, Action::Off);
+ }
+}
+
+TEST(YamlGroupPriorityTest, assertYAMLLedBlink)
+{
+ const std::string groupPath = basePath + "group3";
+ EXPECT_EQ(systemLedMap.contains(groupPath), true);
+
+ phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath);
+
+ EXPECT_EQ(group.priority, 0);
+ EXPECT_EQ(group.actionSet.size(), 1);
+
+ for (auto& led : group.actionSet)
+ {
+ EXPECT_EQ(led.name, "led1");
+ EXPECT_EQ(led.action, Action::Blink);
+ EXPECT_EQ(led.dutyOn, 50);
+ EXPECT_EQ(led.period, 1000);
+ }
+}
+
+TEST(YamlGroupPriorityTest, assertYAMLGroupPriority)
+{
+ const std::string groupPath = basePath + "group4";
+ EXPECT_EQ(systemLedMap.contains(groupPath), true);
+
+ phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath);
+
+ EXPECT_EQ(group.priority, 2);
+ EXPECT_EQ(group.actionSet.size(), 2);
+
+ int found = 0;
+ for (auto& led : group.actionSet)
+ {
+ if (led.name == "led1")
+ {
+ EXPECT_EQ(led.action, Action::On);
+ found++;
+ }
+ if (led.name == "led2")
+ {
+ EXPECT_EQ(led.action, Action::Off);
+ found++;
+ }
+ }
+
+ EXPECT_EQ(found, group.actionSet.size());
+}
diff --git a/test/utest-led-yaml-led-priority.cpp b/test/utest-led-yaml-led-priority.cpp
new file mode 100644
index 0000000..4cee0f0
--- /dev/null
+++ b/test/utest-led-yaml-led-priority.cpp
@@ -0,0 +1,74 @@
+#include "group.hpp"
+#include "ledlayout.hpp"
+#include "manager.hpp"
+#include "test-led-priority.hpp"
+
+#include <sdbusplus/bus.hpp>
+
+#include <algorithm>
+#include <set>
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::led;
+
+using Action = phosphor::led::Layout::Action;
+
+// systemLedMap is generated code
+// static const phosphor::led::GroupMap systemLedMap = {};
+
+const std::string basePath = "/xyz/openbmc_project/led/groups/";
+
+TEST(YamlLedPriorityTest, assertPriorityOn)
+{
+ const std::string groupPath = basePath + "group1";
+ EXPECT_EQ(systemLedMap.contains(groupPath), true);
+
+ phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath);
+
+ EXPECT_EQ(group.priority, 0);
+ EXPECT_EQ(group.actionSet.size(), 1);
+
+ for (auto& led : group.actionSet)
+ {
+ EXPECT_EQ(led.name, "led1");
+ EXPECT_EQ(led.action, Action::On);
+ EXPECT_EQ(led.priority, Action::On);
+ }
+}
+
+TEST(YamlLedPriorityTest, assertPriorityOff)
+{
+ const std::string groupPath = basePath + "group2";
+ EXPECT_EQ(systemLedMap.contains(groupPath), true);
+
+ phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath);
+
+ EXPECT_EQ(group.priority, 0);
+ EXPECT_EQ(group.actionSet.size(), 1);
+
+ for (auto& led : group.actionSet)
+ {
+ EXPECT_EQ(led.name, "led2");
+ EXPECT_EQ(led.action, Action::Off);
+ EXPECT_EQ(led.priority, Action::Off);
+ }
+}
+
+TEST(YamlLedPriorityTest, assertPriorityBlink)
+{
+ const std::string groupPath = basePath + "group3";
+ EXPECT_EQ(systemLedMap.contains(groupPath), true);
+
+ phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath);
+
+ EXPECT_EQ(group.priority, 0);
+ EXPECT_EQ(group.actionSet.size(), 1);
+
+ for (auto& led : group.actionSet)
+ {
+ EXPECT_EQ(led.name, "led3");
+ EXPECT_EQ(led.action, Action::Blink);
+ EXPECT_EQ(led.priority, Action::Blink);
+ }
+}