Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame^] | 1 | #include "group.hpp" |
| 2 | #include "ledlayout.hpp" |
| 3 | #include "manager.hpp" |
| 4 | #include "test-group-priority.hpp" |
| 5 | |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | |
| 8 | #include <algorithm> |
| 9 | #include <set> |
| 10 | |
| 11 | #include <gtest/gtest.h> |
| 12 | |
| 13 | using namespace phosphor::led; |
| 14 | |
| 15 | using Action = phosphor::led::Layout::Action; |
| 16 | |
| 17 | // systemLedMap is generated code |
| 18 | // static const phosphor::led::GroupMap systemLedMap = {}; |
| 19 | |
| 20 | const std::string basePath = "/xyz/openbmc_project/led/groups/"; |
| 21 | |
| 22 | TEST(YamlGroupPriorityTest, assertYAMLLedOn) |
| 23 | { |
| 24 | const std::string groupPath = basePath + "group1"; |
| 25 | EXPECT_EQ(systemLedMap.contains(groupPath), true); |
| 26 | |
| 27 | phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath); |
| 28 | |
| 29 | EXPECT_EQ(group.priority, 0); |
| 30 | EXPECT_EQ(group.actionSet.size(), 1); |
| 31 | |
| 32 | for (auto& led : group.actionSet) |
| 33 | { |
| 34 | EXPECT_EQ(led.name, "led1"); |
| 35 | EXPECT_EQ(led.action, Action::On); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | TEST(YamlGroupPriorityTest, assertYAMLLedOff) |
| 40 | { |
| 41 | const std::string groupPath = basePath + "group2"; |
| 42 | EXPECT_EQ(systemLedMap.contains(groupPath), true); |
| 43 | |
| 44 | phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath); |
| 45 | |
| 46 | EXPECT_EQ(group.priority, 0); |
| 47 | EXPECT_EQ(group.actionSet.size(), 1); |
| 48 | |
| 49 | for (auto& led : group.actionSet) |
| 50 | { |
| 51 | EXPECT_EQ(led.name, "led1"); |
| 52 | EXPECT_EQ(led.action, Action::Off); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | TEST(YamlGroupPriorityTest, assertYAMLLedBlink) |
| 57 | { |
| 58 | const std::string groupPath = basePath + "group3"; |
| 59 | EXPECT_EQ(systemLedMap.contains(groupPath), true); |
| 60 | |
| 61 | phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath); |
| 62 | |
| 63 | EXPECT_EQ(group.priority, 0); |
| 64 | EXPECT_EQ(group.actionSet.size(), 1); |
| 65 | |
| 66 | for (auto& led : group.actionSet) |
| 67 | { |
| 68 | EXPECT_EQ(led.name, "led1"); |
| 69 | EXPECT_EQ(led.action, Action::Blink); |
| 70 | EXPECT_EQ(led.dutyOn, 50); |
| 71 | EXPECT_EQ(led.period, 1000); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | TEST(YamlGroupPriorityTest, assertYAMLGroupPriority) |
| 76 | { |
| 77 | const std::string groupPath = basePath + "group4"; |
| 78 | EXPECT_EQ(systemLedMap.contains(groupPath), true); |
| 79 | |
| 80 | phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath); |
| 81 | |
| 82 | EXPECT_EQ(group.priority, 2); |
| 83 | EXPECT_EQ(group.actionSet.size(), 2); |
| 84 | |
| 85 | int found = 0; |
| 86 | for (auto& led : group.actionSet) |
| 87 | { |
| 88 | if (led.name == "led1") |
| 89 | { |
| 90 | EXPECT_EQ(led.action, Action::On); |
| 91 | found++; |
| 92 | } |
| 93 | if (led.name == "led2") |
| 94 | { |
| 95 | EXPECT_EQ(led.action, Action::Off); |
| 96 | found++; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | EXPECT_EQ(found, group.actionSet.size()); |
| 101 | } |