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 | |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 29 | EXPECT_EQ(group.priority, 1); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 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); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 36 | EXPECT_EQ(led.priority, std::nullopt); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| 40 | TEST(YamlGroupPriorityTest, assertYAMLLedOff) |
| 41 | { |
| 42 | const std::string groupPath = basePath + "group2"; |
| 43 | EXPECT_EQ(systemLedMap.contains(groupPath), true); |
| 44 | |
| 45 | phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath); |
| 46 | |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 47 | EXPECT_EQ(group.priority, 2); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 48 | EXPECT_EQ(group.actionSet.size(), 1); |
| 49 | |
| 50 | for (auto& led : group.actionSet) |
| 51 | { |
| 52 | EXPECT_EQ(led.name, "led1"); |
| 53 | EXPECT_EQ(led.action, Action::Off); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 54 | EXPECT_EQ(led.priority, std::nullopt); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | TEST(YamlGroupPriorityTest, assertYAMLLedBlink) |
| 59 | { |
| 60 | const std::string groupPath = basePath + "group3"; |
| 61 | EXPECT_EQ(systemLedMap.contains(groupPath), true); |
| 62 | |
| 63 | phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath); |
| 64 | |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 65 | EXPECT_EQ(group.priority, 3); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 66 | EXPECT_EQ(group.actionSet.size(), 1); |
| 67 | |
| 68 | for (auto& led : group.actionSet) |
| 69 | { |
| 70 | EXPECT_EQ(led.name, "led1"); |
| 71 | EXPECT_EQ(led.action, Action::Blink); |
| 72 | EXPECT_EQ(led.dutyOn, 50); |
| 73 | EXPECT_EQ(led.period, 1000); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 74 | EXPECT_EQ(led.priority, std::nullopt); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | TEST(YamlGroupPriorityTest, assertYAMLGroupPriority) |
| 79 | { |
| 80 | const std::string groupPath = basePath + "group4"; |
| 81 | EXPECT_EQ(systemLedMap.contains(groupPath), true); |
| 82 | |
| 83 | phosphor::led::Layout::GroupLayout group = systemLedMap.at(groupPath); |
| 84 | |
| 85 | EXPECT_EQ(group.priority, 2); |
| 86 | EXPECT_EQ(group.actionSet.size(), 2); |
| 87 | |
| 88 | int found = 0; |
| 89 | for (auto& led : group.actionSet) |
| 90 | { |
| 91 | if (led.name == "led1") |
| 92 | { |
| 93 | EXPECT_EQ(led.action, Action::On); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 94 | EXPECT_EQ(led.priority, std::nullopt); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 95 | found++; |
| 96 | } |
| 97 | if (led.name == "led2") |
| 98 | { |
| 99 | EXPECT_EQ(led.action, Action::Off); |
Alexander Hansen | 638d148 | 2024-08-21 17:39:57 +0200 | [diff] [blame] | 100 | EXPECT_EQ(led.priority, std::nullopt); |
Alexander Hansen | eb1f46a | 2024-07-30 16:09:07 +0200 | [diff] [blame] | 101 | found++; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | EXPECT_EQ(found, group.actionSet.size()); |
| 106 | } |