blob: 787b345a56dc7f218e5641699268c6c20b19e388 [file] [log] [blame]
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301#include "led-test-map.hpp"
Patrick Venture91ac8d32018-11-01 17:03:22 -07002#include "manager.hpp"
3
Patrick Venture91ac8d32018-11-01 17:03:22 -07004#include <sdbusplus/bus.hpp>
George Liua6c18f82020-06-22 10:50:04 +08005
6#include <algorithm>
Patrick Venture91ac8d32018-11-01 17:03:22 -07007#include <set>
8
9#include <gtest/gtest.h>
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053010using namespace phosphor::led;
11class LedTest : public ::testing::Test
12{
Patrick Venture91ac8d32018-11-01 17:03:22 -070013 public:
14 sdbusplus::bus::bus bus;
15 LedTest() : bus(sdbusplus::bus::new_default())
16 {
17 // Nothing here
18 }
19 ~LedTest()
20 {
21 // Leaving up to auto cleanup.
22 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053023};
24
25/** @brief Assert Single LED to On */
26TEST_F(LedTest, assertSingleLedOn)
27{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053028 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053029 {
30 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070031 Manager::group ledsAssert{};
32 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053033
34 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070035 auto result =
36 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053037 EXPECT_EQ(true, result);
38
39 // Need just the ledsAssserted populated with these.
40 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -070041 {"One", phosphor::led::Layout::On, 0, 0,
42 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053043 };
44 EXPECT_EQ(refAssert.size(), ledsAssert.size());
45 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053046
47 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -070048 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053049 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
50 refAssert.begin(), refAssert.end(),
51 std::inserter(temp, temp.begin()));
52 EXPECT_EQ(0, temp.size());
53 }
54}
55
56/** @brief Assert Single LED to Blink */
57TEST_F(LedTest, assertSingleLedBlink)
58{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053059 Manager manager(bus, singleLedBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053060 {
61 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070062 Manager::group ledsAssert{};
63 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053064
65 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070066 auto result =
67 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053068 EXPECT_EQ(true, result);
69
70 // Need just the ledsAssserted populated with these.
71 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -070072 {"One", phosphor::led::Layout::Blink, 0, 0,
73 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053074 };
75 EXPECT_EQ(refAssert.size(), ledsAssert.size());
76 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053077
78 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -070079 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053080 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
81 refAssert.begin(), refAssert.end(),
82 std::inserter(temp, temp.begin()));
83 EXPECT_EQ(0, temp.size());
84 }
85}
86
87/** @brief Assert Single LED to On and Try Assert Again */
88TEST_F(LedTest, assertSingleLedOnAndreAssert)
89{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053090 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053091 {
92 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -070093 Manager::group ledsAssert{};
94 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053095
96 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -070097 auto result =
98 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053099 EXPECT_EQ(true, result);
100
101 // Need just the ledsAssserted populated with these.
102 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700103 {"One", phosphor::led::Layout::On, 0, 0,
104 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530105 };
106 EXPECT_EQ(refAssert.size(), ledsAssert.size());
107 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530108
109 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700110 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530111 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
112 refAssert.begin(), refAssert.end(),
113 std::inserter(temp, temp.begin()));
114 EXPECT_EQ(0, temp.size());
115 }
116 {
117 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700118 Manager::group ledsAssert{};
119 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530120
121 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700122 auto result =
123 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530124 EXPECT_EQ(true, result);
125
126 EXPECT_EQ(0, ledsAssert.size());
127 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530128 }
129}
130
131/** @brief Assert Multiple LEDs to On */
132TEST_F(LedTest, assertMultipleLedOn)
133{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530134 Manager manager(bus, multipleLedsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530135 {
136 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700137 Manager::group ledsAssert{};
138 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530139
140 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700141 auto result =
142 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530143 EXPECT_EQ(true, result);
144
145 // Need just the ledsAssserted populated with these.
146 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700147 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
148 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
149 {"Three", phosphor::led::Layout::On, 0, 0,
150 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530151 };
152 EXPECT_EQ(refAssert.size(), ledsAssert.size());
153 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530154
155 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700156 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530157 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
158 refAssert.begin(), refAssert.end(),
159 std::inserter(temp, temp.begin()));
160 EXPECT_EQ(0, temp.size());
161 }
162}
163
164/** @brief Assert Multiple LEDs to Blink */
165TEST_F(LedTest, assertMultipleLedBlink)
166{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530167 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530168 {
169 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700170 Manager::group ledsAssert{};
171 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530172
173 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700174 auto result =
175 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530176 EXPECT_EQ(true, result);
177
178 // Need just the ledsAssserted populated with these.
179 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700180 {"One", phosphor::led::Layout::Blink, 0, 0,
181 phosphor::led::Layout::Blink},
182 {"Two", phosphor::led::Layout::Blink, 0, 0,
183 phosphor::led::Layout::Blink},
184 {"Three", phosphor::led::Layout::Blink, 0, 0,
185 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530186 };
187 EXPECT_EQ(refAssert.size(), ledsAssert.size());
188 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530189
190 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700191 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530192 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
193 refAssert.begin(), refAssert.end(),
194 std::inserter(temp, temp.begin()));
195 EXPECT_EQ(0, temp.size());
196 }
197}
198
199/** @brief Assert Multiple LEDs to Blink, DeAssert */
200TEST_F(LedTest, assertMultipleLedBlinkAndDeAssert)
201{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530202 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530203 {
204 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700205 Manager::group ledsAssert{};
206 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530207
208 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700209 auto result =
210 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530211 EXPECT_EQ(true, result);
212
213 // Need just the ledsAssserted populated with these.
214 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700215 {"One", phosphor::led::Layout::Blink, 0, 0,
216 phosphor::led::Layout::Blink},
217 {"Two", phosphor::led::Layout::Blink, 0, 0,
218 phosphor::led::Layout::Blink},
219 {"Three", phosphor::led::Layout::Blink, 0, 0,
220 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530221 };
222 EXPECT_EQ(refAssert.size(), ledsAssert.size());
223 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530224
225 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700226 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530227 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
228 refAssert.begin(), refAssert.end(),
229 std::inserter(temp, temp.begin()));
230 EXPECT_EQ(0, temp.size());
231 }
232 {
233 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700234 Manager::group ledsAssert{};
235 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530236
237 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700238 auto result =
239 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530240 EXPECT_EQ(false, result);
241
242 // Need just the ledsAssserted populated with these.
243 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700244 {"One", phosphor::led::Layout::Blink, 0, 0,
245 phosphor::led::Layout::Blink},
246 {"Two", phosphor::led::Layout::Blink, 0, 0,
247 phosphor::led::Layout::Blink},
248 {"Three", phosphor::led::Layout::Blink, 0, 0,
249 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530250 };
251 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
252 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530253
254 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700255 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530256 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
257 refDeAssert.begin(), refDeAssert.end(),
258 std::inserter(temp, temp.begin()));
259 EXPECT_EQ(0, temp.size());
260 }
261}
262
263/** @brief Assert Multiple LEDs to Blink, DeAssert Twice */
264TEST_F(LedTest, assertMultipleLedBlinkAndDeAssertTwice)
265{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530266 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530267 {
268 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700269 Manager::group ledsAssert{};
270 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530271
272 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700273 auto result =
274 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530275 EXPECT_EQ(true, result);
276
277 // Need just the ledsAssserted populated with these.
278 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700279 {"One", phosphor::led::Layout::Blink, 0, 0,
280 phosphor::led::Layout::Blink},
281 {"Two", phosphor::led::Layout::Blink, 0, 0,
282 phosphor::led::Layout::Blink},
283 {"Three", phosphor::led::Layout::Blink, 0, 0,
284 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530285 };
286 EXPECT_EQ(refAssert.size(), ledsAssert.size());
287 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530288
289 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700290 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530291 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
292 refAssert.begin(), refAssert.end(),
293 std::inserter(temp, temp.begin()));
294 EXPECT_EQ(0, temp.size());
295 }
296 {
297 // DeAssert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700298 Manager::group ledsAssert{};
299 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530300
301 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700302 auto result =
303 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530304 EXPECT_EQ(false, result);
305
306 // Need just the ledsAssserted populated with these.
307 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700308 {"One", phosphor::led::Layout::Blink, 0, 0,
309 phosphor::led::Layout::Blink},
310 {"Two", phosphor::led::Layout::Blink, 0, 0,
311 phosphor::led::Layout::Blink},
312 {"Three", phosphor::led::Layout::Blink, 0, 0,
313 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530314 };
315 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
316 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530317
318 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700319 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530320 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
321 refDeAssert.begin(), refDeAssert.end(),
322 std::inserter(temp, temp.begin()));
323 EXPECT_EQ(0, temp.size());
324 }
325 {
326 // DeAssert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700327 Manager::group ledsAssert{};
328 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530329
330 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700331 auto result =
332 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530333 EXPECT_EQ(false, result);
334 EXPECT_EQ(0, ledsDeAssert.size());
335 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530336 }
337}
338
339/** @brief Assert Multiple LEDs to mix of On and Blink */
340TEST_F(LedTest, assertMultipleLedOnAndBlink)
341{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530342 Manager manager(bus, multipleLedsOnAndBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530343 {
344 // Assert the LEDs.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700345 Manager::group ledsAssert{};
346 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530347
348 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsMix";
Patrick Venture91ac8d32018-11-01 17:03:22 -0700349 auto result =
350 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530351 EXPECT_EQ(true, result);
352
353 // Need just the ledsAssserted populated with these.
354 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700355 {"One", phosphor::led::Layout::Blink, 0, 0,
356 phosphor::led::Layout::Blink},
357 {"Two", phosphor::led::Layout::On, 0, phosphor::led::Layout::Blink},
358 {"Three", phosphor::led::Layout::Blink, 0,
359 phosphor::led::Layout::On},
360 {"Four", phosphor::led::Layout::On, 0,
361 phosphor::led::Layout::Blink},
362 {"Five", phosphor::led::Layout::On, 0,
363 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530364 };
365 EXPECT_EQ(refAssert.size(), ledsAssert.size());
366 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530367
368 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700369 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530370 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
371 refAssert.begin(), refAssert.end(),
372 std::inserter(temp, temp.begin()));
373 EXPECT_EQ(0, temp.size());
374 }
375}
376
377/** @brief Assert 2 groups having distinct LEDs */
378TEST_F(LedTest, assertTwoGroupsOnWithDistinctLEDOn)
379{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530380 Manager manager(bus, twoGroupsWithDistinctLEDsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530381 {
382 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700383 Manager::group ledsAssert{};
384 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530385
Patrick Venture91ac8d32018-11-01 17:03:22 -0700386 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
387 auto result =
388 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530389 EXPECT_EQ(true, result);
390
391 // Need just the ledsAssserted populated with these.
392 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700393 {"One", phosphor::led::Layout::On, 0, 0,
394 phosphor::led::Layout::Blink},
395 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
396 {"Three", phosphor::led::Layout::On, 0, 0,
397 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530398 };
399 EXPECT_EQ(refAssert.size(), ledsAssert.size());
400 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530401
402 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700403 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530404 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
405 refAssert.begin(), refAssert.end(),
406 std::inserter(temp, temp.begin()));
407 EXPECT_EQ(0, temp.size());
408 }
409 {
410 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700411 Manager::group ledsAssert{};
412 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530413
Patrick Venture91ac8d32018-11-01 17:03:22 -0700414 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
415 auto result =
416 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530417 EXPECT_EQ(true, result);
418
419 // Need just the ledsAssserted populated with these.
420 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700421 {"Four", phosphor::led::Layout::On, 0, 0,
422 phosphor::led::Layout::Blink},
423 {"Five", phosphor::led::Layout::On, 0, 0,
424 phosphor::led::Layout::Blink},
425 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530426 };
427 EXPECT_EQ(refAssert.size(), ledsAssert.size());
428 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530429
430 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700431 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530432 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
433 refAssert.begin(), refAssert.end(),
434 std::inserter(temp, temp.begin()));
435 EXPECT_EQ(0, temp.size());
436 }
437}
438
439/** @brief Assert 2 groups having one of the LEDs common */
440TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOn)
441{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530442 Manager manager(bus, twoGroupsWithOneComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530443 {
444 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700445 Manager::group ledsAssert{};
446 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530447
Patrick Venture91ac8d32018-11-01 17:03:22 -0700448 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
449 auto result =
450 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530451 EXPECT_EQ(true, result);
452
453 // Need just the ledsAssserted populated with these.
454 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700455 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
456 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
457 {"Three", phosphor::led::Layout::On, 0, 0,
458 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530459 };
460 EXPECT_EQ(refAssert.size(), ledsAssert.size());
461 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530462
463 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700464 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530465 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
466 refAssert.begin(), refAssert.end(),
467 std::inserter(temp, temp.begin()));
468 EXPECT_EQ(0, temp.size());
469 }
470 {
471 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700472 Manager::group ledsAssert{};
473 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530474
Patrick Venture91ac8d32018-11-01 17:03:22 -0700475 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
476 auto result =
477 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530478 EXPECT_EQ(true, result);
479
480 // Need just the ledsAssserted populated with these.
481 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700482 {"Four", phosphor::led::Layout::On, 0, 0,
483 phosphor::led::Layout::On},
484 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530485 };
486 EXPECT_EQ(refAssert.size(), ledsAssert.size());
487 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530488
489 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700490 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530491 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
492 refAssert.begin(), refAssert.end(),
493 std::inserter(temp, temp.begin()));
494 EXPECT_EQ(0, temp.size());
495 }
496}
497
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530498/** @brief Assert 2 groups having one of the LEDs common but having Blink as
499 * priority and Deassert*/
500TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertB)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530501{
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530502 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530503 {
504 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700505 Manager::group ledsAssert{};
506 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530507
Patrick Venture91ac8d32018-11-01 17:03:22 -0700508 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
509 auto result =
510 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530511 EXPECT_EQ(true, result);
512
513 // Need just the ledsAssserted populated with these.
514 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700515 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
516 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
517 {"Three", phosphor::led::Layout::Blink, 0, 0,
518 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530519 };
520 EXPECT_EQ(refAssert.size(), ledsAssert.size());
521 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530522
523 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700524 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530525 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
526 refAssert.begin(), refAssert.end(),
527 std::inserter(temp, temp.begin()));
528 EXPECT_EQ(0, temp.size());
529 }
530 {
531 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700532 Manager::group ledsAssert{};
533 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530534
Patrick Venture91ac8d32018-11-01 17:03:22 -0700535 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
536 auto result =
537 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530538 EXPECT_EQ(true, result);
539
540 // Need just the ledsAssserted populated with these.
541 // Does not action on [Three] since priority is [Blink]
542 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700543 {"Four", phosphor::led::Layout::On, 0, 0,
544 phosphor::led::Layout::On},
545 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530546 };
547 EXPECT_EQ(refAssert.size(), ledsAssert.size());
548 EXPECT_EQ(0, ledsDeAssert.size());
549
550 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700551 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530552 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
553 refAssert.begin(), refAssert.end(),
554 std::inserter(temp, temp.begin()));
555 EXPECT_EQ(0, temp.size());
556 }
557 {
558 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700559 Manager::group ledsAssert{};
560 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530561
Patrick Venture91ac8d32018-11-01 17:03:22 -0700562 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
563 auto result =
564 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530565 EXPECT_EQ(false, result);
566
567 // Need just the ledsDeAssserted populated with these.
568 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700569 {"Four", phosphor::led::Layout::On, 0, 0,
570 phosphor::led::Layout::On},
571 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530572 };
573 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
574 EXPECT_EQ(0, ledsAssert.size());
575
576 // difference of refDeAssert and ledsDeAssert must be null.
577 // [Three] is not touched since its already [Blink]
Patrick Venture91ac8d32018-11-01 17:03:22 -0700578 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530579 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
580 refDeAssert.begin(), refDeAssert.end(),
581 std::inserter(temp, temp.begin()));
582 EXPECT_EQ(0, temp.size());
583 }
584}
585
586/** @brief Assert 2 groups having one of the LEDs common but having Blink as
587 * priority and Deassert A */
588TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertA)
589{
590 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority);
591 {
592 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700593 Manager::group ledsAssert{};
594 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530595
Patrick Venture91ac8d32018-11-01 17:03:22 -0700596 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
597 auto result =
598 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530599 EXPECT_EQ(true, result);
600
601 // Need just the ledsAssserted populated with these.
602 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700603 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
604 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
605 {"Three", phosphor::led::Layout::Blink, 0, 0,
606 phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530607 };
608 EXPECT_EQ(refAssert.size(), ledsAssert.size());
609 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530610
611 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700612 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530613 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
614 refAssert.begin(), refAssert.end(),
615 std::inserter(temp, temp.begin()));
616 EXPECT_EQ(0, temp.size());
617 }
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530618 {
619 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700620 Manager::group ledsAssert{};
621 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530622
Patrick Venture91ac8d32018-11-01 17:03:22 -0700623 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
624 auto result =
625 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530626 EXPECT_EQ(true, result);
627
628 // Need just the ledsAssserted populated with these.
629 // [Three] does not get actioned since it has Blink priority
630 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700631 {"Four", phosphor::led::Layout::On, 0, 0,
632 phosphor::led::Layout::On},
633 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530634 };
635 EXPECT_EQ(refAssert.size(), ledsAssert.size());
636 EXPECT_EQ(0, ledsDeAssert.size());
637
638 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700639 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530640 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
641 refAssert.begin(), refAssert.end(),
642 std::inserter(temp, temp.begin()));
643 EXPECT_EQ(0, temp.size());
644 }
645 {
646 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700647 Manager::group ledsAssert{};
648 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530649
Patrick Venture91ac8d32018-11-01 17:03:22 -0700650 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
651 auto result =
652 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530653 EXPECT_EQ(false, result);
654
655 // Need just the ledsDeAssserted populated with these.
656 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700657 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
658 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530659 };
660 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
661
662 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700663 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530664 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
665 refDeAssert.begin(), refDeAssert.end(),
666 std::inserter(temp, temp.begin()));
667 EXPECT_EQ(0, temp.size());
668
669 // Need just the ledsAssert populated with these.
670 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700671 {"Three", phosphor::led::Layout::On, 0, 0,
672 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530673 };
674 EXPECT_EQ(refAssert.size(), ledsAssert.size());
675
676 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700677 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530678 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
679 refAssert.begin(), refAssert.end(),
680 std::inserter(temp1, temp1.begin()));
681 EXPECT_EQ(0, temp1.size());
682 }
683}
684
685/** @brief Assert 2 groups having one of the LEDs common but having ON as
686 * priority And Deassert A */
687TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertA)
688{
689 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority);
690 {
691 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700692 Manager::group ledsAssert{};
693 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530694
Patrick Venture91ac8d32018-11-01 17:03:22 -0700695 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
696 auto result =
697 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530698 EXPECT_EQ(true, result);
699
700 // Need just the ledsAssserted populated with these.
701 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700702 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
703 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
704 {"Three", phosphor::led::Layout::Blink, 0, 0,
705 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530706 };
707 EXPECT_EQ(refAssert.size(), ledsAssert.size());
708 EXPECT_EQ(0, ledsDeAssert.size());
709
710 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700711 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530712 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
713 refAssert.begin(), refAssert.end(),
714 std::inserter(temp, temp.begin()));
715 EXPECT_EQ(0, temp.size());
716 }
717 {
718 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700719 Manager::group ledsAssert{};
720 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530721
Patrick Venture91ac8d32018-11-01 17:03:22 -0700722 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
723 auto result =
724 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530725 EXPECT_EQ(true, result);
726
727 // Need just the ledsAssserted populated with these.
728 // Three is set to ON due to ON priority.
729 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700730 {"Three", phosphor::led::Layout::On, 0, 0,
731 phosphor::led::Layout::On},
732 {"Four", phosphor::led::Layout::On, 0, 0,
733 phosphor::led::Layout::On},
734 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530735 };
736 EXPECT_EQ(refAssert.size(), ledsAssert.size());
737 EXPECT_EQ(0, ledsDeAssert.size());
738
739 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700740 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530741 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
742 refAssert.begin(), refAssert.end(),
743 std::inserter(temp, temp.begin()));
744 }
745 {
746 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700747 Manager::group ledsAssert{};
748 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530749
Patrick Venture91ac8d32018-11-01 17:03:22 -0700750 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
751 auto result =
752 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530753 EXPECT_EQ(false, result);
754
755 // Need just the ledsDeAssserted populated with these.
756 // [Three] stays in [On] since [B] has it [On]
757 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700758 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
759 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530760 };
761 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
762 EXPECT_EQ(0, ledsAssert.size());
763
764 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700765 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530766 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
767 refDeAssert.begin(), refDeAssert.end(),
768 std::inserter(temp, temp.begin()));
769 EXPECT_EQ(0, temp.size());
770 }
771}
772
773/** @brief Assert 2 groups having one of the LEDs common but having ON as
774 * priority And Deassert B */
775TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertB)
776{
777 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority);
778 {
779 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700780 Manager::group ledsAssert{};
781 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530782
Patrick Venture91ac8d32018-11-01 17:03:22 -0700783 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
784 auto result =
785 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530786 EXPECT_EQ(true, result);
787
788 // Need just the ledsAssserted populated with these.
789 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700790 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
791 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
792 {"Three", phosphor::led::Layout::Blink, 0, 0,
793 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530794 };
795 EXPECT_EQ(refAssert.size(), ledsAssert.size());
796 EXPECT_EQ(0, ledsDeAssert.size());
797
798 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700799 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530800 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
801 refAssert.begin(), refAssert.end(),
802 std::inserter(temp, temp.begin()));
803 EXPECT_EQ(0, temp.size());
804 }
805 {
806 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700807 Manager::group ledsAssert{};
808 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530809
Patrick Venture91ac8d32018-11-01 17:03:22 -0700810 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
811 auto result =
812 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530813 EXPECT_EQ(true, result);
814
815 // Need just the ledsAssserted populated with these.
816 // Three is set to ON due to ON priority.
817 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700818 {"Three", phosphor::led::Layout::On, 0, 0,
819 phosphor::led::Layout::On},
820 {"Four", phosphor::led::Layout::On, 0, 0,
821 phosphor::led::Layout::On},
822 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530823 };
824 EXPECT_EQ(refAssert.size(), ledsAssert.size());
825 EXPECT_EQ(0, ledsDeAssert.size());
826
827 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700828 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530829 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
830 refAssert.begin(), refAssert.end(),
831 std::inserter(temp, temp.begin()));
832 }
833 {
834 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700835 Manager::group ledsAssert{};
836 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530837
Patrick Venture91ac8d32018-11-01 17:03:22 -0700838 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
839 auto result =
840 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530841 EXPECT_EQ(false, result);
842
843 // Need just the ledsDeAssserted populated with these.
844 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700845 {"Four", phosphor::led::Layout::On, 0, 0,
846 phosphor::led::Layout::On},
847 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530848 };
849 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
850
851 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700852 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530853 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
854 refDeAssert.begin(), refDeAssert.end(),
855 std::inserter(temp, temp.begin()));
856 EXPECT_EQ(0, temp.size());
857
858 // Need just the ledsAssert populated with these.
859 // Since [Three] stood [On], need to go back to [Blink]
860 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700861 {"Three", phosphor::led::Layout::Blink, 0, 0,
862 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530863 };
864 EXPECT_EQ(refAssert.size(), ledsAssert.size());
865
866 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700867 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530868 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
869 refAssert.begin(), refAssert.end(),
870 std::inserter(temp, temp.begin()));
871 EXPECT_EQ(0, temp.size());
872 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530873}
874
875/** @brief Assert 2 groups having multiple common LEDs in Same State */
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530876TEST_F(LedTest, assertTwoGroupsWithMultiplComonLEDOnAndDeAssert)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530877{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530878 Manager manager(bus, twoGroupsWithMultiplComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530879 {
880 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700881 Manager::group ledsAssert{};
882 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530883
Patrick Venture91ac8d32018-11-01 17:03:22 -0700884 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
885 auto result =
886 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530887 EXPECT_EQ(true, result);
888
889 // Need just the ledsAssserted populated with these.
890 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700891 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
892 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
893 {"Three", phosphor::led::Layout::On, 0, 0,
894 phosphor::led::Layout::On},
895 {"Seven", phosphor::led::Layout::On, 0, 0,
896 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530897 };
898 EXPECT_EQ(refAssert.size(), ledsAssert.size());
899 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530900
901 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700902 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530903 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
904 refAssert.begin(), refAssert.end(),
905 std::inserter(temp, temp.begin()));
906 EXPECT_EQ(0, temp.size());
907 }
908 {
909 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700910 Manager::group ledsAssert{};
911 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530912
Patrick Venture91ac8d32018-11-01 17:03:22 -0700913 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
914 auto result =
915 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530916 EXPECT_EQ(true, result);
917
918 // Need just the ledsAssserted populated with these.
919 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700920 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530921 };
922 EXPECT_EQ(refAssert.size(), ledsAssert.size());
923 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530924
925 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700926 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530927 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
928 refAssert.begin(), refAssert.end(),
929 std::inserter(temp, temp.begin()));
930 EXPECT_EQ(0, temp.size());
931 }
932 {
933 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700934 Manager::group ledsAssert{};
935 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530936
Patrick Venture91ac8d32018-11-01 17:03:22 -0700937 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
938 auto result =
939 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530940 EXPECT_EQ(false, result);
941
942 // Need just the ledsDeAssserted populated with these.
943 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700944 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
945 {"Seven", phosphor::led::Layout::On, 0, 0,
946 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530947 };
948 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
949 EXPECT_EQ(0, ledsAssert.size());
950
951 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700952 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530953 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
954 refDeAssert.begin(), refDeAssert.end(),
955 std::inserter(temp, temp.begin()));
956 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530957 }
958}
959
960/** @brief Assert 2 groups having multiple LEDs common in different state */
961TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateBandA)
962{
963 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
964 {
965 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -0700966 Manager::group ledsAssert{};
967 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530968
Patrick Venture91ac8d32018-11-01 17:03:22 -0700969 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
970 auto result =
971 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530972 EXPECT_EQ(true, result);
973
974 // Need just the ledsAssserted populated with these.
975 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -0700976 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
977 {"Three", phosphor::led::Layout::Blink, 0, 0,
978 phosphor::led::Layout::On},
979 {"Five", phosphor::led::Layout::On, 0, 0,
980 phosphor::led::Layout::On},
981 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530982 };
983 EXPECT_EQ(refAssert.size(), ledsAssert.size());
984 EXPECT_EQ(0, ledsDeAssert.size());
985
986 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -0700987 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530988 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
989 refAssert.begin(), refAssert.end(),
990 std::inserter(temp, temp.begin()));
991 EXPECT_EQ(0, temp.size());
992 }
993 {
994 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -0700995 Manager::group ledsAssert{};
996 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +0530997
Patrick Venture91ac8d32018-11-01 17:03:22 -0700998 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
999 auto result =
1000 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301001 EXPECT_EQ(true, result);
1002
1003 // Need just the ledsAssserted populated with these
1004 // [Two] remains [On] due to higher priority.
1005 // [Three] remains [Blink]
1006 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001007 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1008 {"Four", phosphor::led::Layout::On, 0, 0,
1009 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301010 };
1011 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1012 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301013
1014 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001015 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301016 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1017 refAssert.begin(), refAssert.end(),
1018 std::inserter(temp, temp.begin()));
1019 EXPECT_EQ(0, temp.size());
1020 }
1021}
1022
1023/** @brief Assert 2 groups having multiple LEDs common in different state */
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301024TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoB)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301025{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05301026 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301027 {
1028 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001029 Manager::group ledsAssert{};
1030 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301031
Patrick Venture91ac8d32018-11-01 17:03:22 -07001032 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1033 auto result =
1034 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301035 EXPECT_EQ(true, result);
1036
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301037 // Need just the ledsAssserted populated with these.'Two' gets to Blink
1038 // due to higher priority.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301039 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001040 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1041 {"Two", phosphor::led::Layout::Blink, 0, 0,
1042 phosphor::led::Layout::On},
1043 {"Three", phosphor::led::Layout::Blink, 0, 0,
1044 phosphor::led::Layout::On},
1045 {"Four", phosphor::led::Layout::On, 0, 0,
1046 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301047 };
1048 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1049 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301050
1051 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001052 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301053 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1054 refAssert.begin(), refAssert.end(),
1055 std::inserter(temp, temp.begin()));
1056 EXPECT_EQ(0, temp.size());
1057 }
1058 {
1059 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001060 Manager::group ledsAssert{};
1061 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301062
Patrick Venture91ac8d32018-11-01 17:03:22 -07001063 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1064 auto result =
1065 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301066 EXPECT_EQ(true, result);
1067
1068 // Need just the ledsAssserted populated with these.
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301069 // [Three] remains [Blink] from previous
1070 // [Two] moves to [On] from [Blink] due to [On] priority
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301071 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001072 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1073 {"Five", phosphor::led::Layout::On, 0, 0,
1074 phosphor::led::Layout::On},
1075 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301076 };
1077 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1078 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301079
1080 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001081 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301082 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1083 refAssert.begin(), refAssert.end(),
1084 std::inserter(temp, temp.begin()));
1085 EXPECT_EQ(0, temp.size());
1086 }
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301087}
1088
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301089/** @brief Assert 2 groups having multiple LEDs common in different state
1090 * DeAssert twice
1091 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001092TEST_F(LedTest,
1093 assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoBDeAssertTwice)
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301094{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05301095 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301096 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301097 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001098 Manager::group ledsAssert{};
1099 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301100
Patrick Venture91ac8d32018-11-01 17:03:22 -07001101 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1102 auto result =
1103 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301104 EXPECT_EQ(true, result);
1105
1106 // Need just the ledsAssserted populated with these.
1107 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001108 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1109 {"Two", phosphor::led::Layout::Blink, 0, 0,
1110 phosphor::led::Layout::On},
1111 {"Three", phosphor::led::Layout::Blink, 0, 0,
1112 phosphor::led::Layout::On},
1113 {"Four", phosphor::led::Layout::On, 0, 0,
1114 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301115 };
1116 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1117 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301118
1119 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001120 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301121 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1122 refAssert.begin(), refAssert.end(),
1123 std::inserter(temp, temp.begin()));
1124 EXPECT_EQ(0, temp.size());
1125 }
1126 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301127 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001128 Manager::group ledsAssert{};
1129 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301130
Patrick Venture91ac8d32018-11-01 17:03:22 -07001131 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1132 auto result =
1133 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301134 EXPECT_EQ(true, result);
1135
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301136 // Need just the ledsAssserted populated with these.
1137 // [Two] turns [On] due to priority
1138 // [Three] remains [Blink]
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301139 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001140 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1141 {"Five", phosphor::led::Layout::On, 0, 0,
1142 phosphor::led::Layout::On},
1143 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301144 };
1145 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1146 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301147
1148 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001149 Manager::group temp{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301150 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1151 refAssert.begin(), refAssert.end(),
1152 std::inserter(temp, temp.begin()));
1153 EXPECT_EQ(0, temp.size());
1154 }
1155 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301156 // DeAssert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001157 Manager::group ledsAssert{};
1158 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301159
Patrick Venture91ac8d32018-11-01 17:03:22 -07001160 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1161 auto result =
1162 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301163 EXPECT_EQ(false, result);
1164
1165 // Need just the ledsAssserted populated with these.
1166 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001167 {"Five", phosphor::led::Layout::On, 0, 0,
1168 phosphor::led::Layout::On},
1169 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301170 };
1171 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1172
1173 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001174 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301175 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1176 refDeAssert.begin(), refDeAssert.end(),
1177 std::inserter(temp, temp.begin()));
1178 EXPECT_EQ(0, temp.size());
1179
1180 // Need just the ledsAssert populated with these.
1181 // [Two] will go back to [Blink] from [On]
1182 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001183 {"Two", phosphor::led::Layout::Blink, 0, 0,
1184 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301185 };
1186 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1187
1188 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001189 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301190 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1191 refAssert.begin(), refAssert.end(),
1192 std::inserter(temp1, temp1.begin()));
1193 EXPECT_EQ(0, temp1.size());
1194 }
1195 {
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301196 // DeAssert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001197 Manager::group ledsAssert{};
1198 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301199
Patrick Venture91ac8d32018-11-01 17:03:22 -07001200 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1201 auto result =
1202 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301203 EXPECT_EQ(false, result);
1204
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301205 // Need just the ledsAssserted populated with these.
1206 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001207 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1208 {"Two", phosphor::led::Layout::Blink, 0, 0,
1209 phosphor::led::Layout::On},
1210 {"Three", phosphor::led::Layout::Blink, 0, 0,
1211 phosphor::led::Layout::On},
1212 {"Four", phosphor::led::Layout::On, 0, 0,
1213 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301214 };
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301215 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301216 EXPECT_EQ(0, ledsAssert.size());
1217
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301218 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001219 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301220 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1221 refDeAssert.begin(), refDeAssert.end(),
1222 std::inserter(temp, temp.begin()));
1223 EXPECT_EQ(0, temp.size());
1224 }
1225 {
1226 // DeAssert Set-A again and make sure we get all empty
Patrick Venture91ac8d32018-11-01 17:03:22 -07001227 Manager::group ledsAssert{};
1228 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301229
Patrick Venture91ac8d32018-11-01 17:03:22 -07001230 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1231 auto result =
1232 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301233 EXPECT_EQ(false, result);
1234 EXPECT_EQ(0, ledsDeAssert.size());
1235 EXPECT_EQ(0, ledsAssert.size());
1236 }
1237}
1238
1239/** @brief Assert 2 groups having multiple LEDs common in different state and
1240 * mixed priority. DeAssert-A
1241 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001242TEST_F(LedTest,
1243 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandB)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301244{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001245 Manager manager(bus,
1246 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301247 {
1248 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001249 Manager::group ledsAssert{};
1250 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301251
Patrick Venture91ac8d32018-11-01 17:03:22 -07001252 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1253 auto result =
1254 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301255 EXPECT_EQ(true, result);
1256
1257 // Need just the ledsAssserted populated with these.
1258 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001259 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1260 {"Two", phosphor::led::Layout::Blink, 0, 0,
1261 phosphor::led::Layout::On},
1262 {"Three", phosphor::led::Layout::On, 0, 0,
1263 phosphor::led::Layout::Blink},
1264 {"Four", phosphor::led::Layout::On, 0, 0,
1265 phosphor::led::Layout::On},
1266 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1267 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301268 };
1269 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1270 EXPECT_EQ(0, ledsDeAssert.size());
1271
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301272 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001273 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301274 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1275 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301276 std::inserter(temp, temp.begin()));
1277 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301278 }
1279 {
1280 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001281 Manager::group ledsAssert{};
1282 Manager::group ledsDeAssert{};
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301283
Patrick Venture91ac8d32018-11-01 17:03:22 -07001284 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1285 auto result =
1286 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301287 EXPECT_EQ(true, result);
1288
1289 // Need just the ledsAssserted populated with these.
1290 // [Two] gets to [ON] due to higher priority.
1291 // [Three] remains on since it never was in [Blink] before
1292 // [Ten] remains [Blink] due to priority: [Blink]
1293 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001294 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1295 {"Five", phosphor::led::Layout::On, 0, 0,
1296 phosphor::led::Layout::On},
1297 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301298 };
1299 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1300 EXPECT_EQ(0, ledsDeAssert.size());
1301
1302 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001303 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301304 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1305 refAssert.begin(), refAssert.end(),
1306 std::inserter(temp, temp.begin()));
1307 EXPECT_EQ(0, temp.size());
1308 }
1309 {
1310 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001311 Manager::group ledsAssert{};
1312 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301313
Patrick Venture91ac8d32018-11-01 17:03:22 -07001314 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1315 auto result =
1316 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301317 EXPECT_EQ(false, result);
1318
1319 // Need just the ledsDeAsssert populated with these.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301320 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001321 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1322 {"Four", phosphor::led::Layout::On, 0, 0,
1323 phosphor::led::Layout::On},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301324 };
1325 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1326
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301327 // Need just the ledsAsssert populated with these.
1328 // [Ten] Moves to [On] since there is no prior [Blink]
1329 // [Three] remains [On] since it never changed state.
1330 // [Two] remains [On] since it did not go back
1331 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001332 {"Ten", phosphor::led::Layout::On, 0, 0,
1333 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301334 };
1335 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1336
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301337 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001338 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301339 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1340 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301341 std::inserter(temp, temp.begin()));
1342 EXPECT_EQ(0, temp.size());
1343 }
1344}
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301345
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301346/** @brief Assert 2 groups having multiple LEDs common in different state and
1347 * mixed priority. DeAssert-B
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301348 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001349TEST_F(
1350 LedTest,
1351 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandBDeAssertB)
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301352{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001353 Manager manager(bus,
1354 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301355 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301356 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001357 Manager::group ledsAssert{};
1358 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301359
Patrick Venture91ac8d32018-11-01 17:03:22 -07001360 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1361 auto result =
1362 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301363 EXPECT_EQ(true, result);
1364
1365 // Need just the ledsAssserted populated with these.
1366 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001367 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1368 {"Two", phosphor::led::Layout::Blink, 0, 0,
1369 phosphor::led::Layout::On},
1370 {"Three", phosphor::led::Layout::On, 0, 0,
1371 phosphor::led::Layout::Blink},
1372 {"Four", phosphor::led::Layout::On, 0, 0,
1373 phosphor::led::Layout::On},
1374 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1375 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301376 };
1377 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1378 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301379
1380 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001381 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301382 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1383 refAssert.begin(), refAssert.end(),
1384 std::inserter(temp, temp.begin()));
1385 EXPECT_EQ(0, temp.size());
1386 }
1387 {
1388 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001389 Manager::group ledsAssert{};
1390 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301391
Patrick Venture91ac8d32018-11-01 17:03:22 -07001392 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1393 auto result =
1394 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301395 EXPECT_EQ(true, result);
1396
1397 // Need just the ledsAssserted populated with these.
1398 // [Two] gets to [ON] due to higher priority.
1399 // [Three] remains on since it never was in [Blink] before
1400 // [Ten] remains [Blink] due to priority: [Blink]
1401 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001402 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1403 {"Five", phosphor::led::Layout::On, 0, 0,
1404 phosphor::led::Layout::On},
1405 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301406 };
1407 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1408 EXPECT_EQ(0, ledsDeAssert.size());
1409
1410 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001411 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301412 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1413 refAssert.begin(), refAssert.end(),
1414 std::inserter(temp, temp.begin()));
1415 EXPECT_EQ(0, temp.size());
1416 }
1417 {
1418 // De-Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001419 Manager::group ledsAssert{};
1420 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301421
Patrick Venture91ac8d32018-11-01 17:03:22 -07001422 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1423 auto result =
1424 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301425 EXPECT_EQ(false, result);
1426
1427 // Need just the ledsDeAsssert populated with these.
1428 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001429 {"Five", phosphor::led::Layout::On, 0, 0,
1430 phosphor::led::Layout::On},
1431 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301432 };
1433 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1434
1435 // Need just the ledsAsssert populated with these.
1436 // [Ten] remains [Blink] since it did not move to [On]
1437 // [Three] remains [On] since it never changed state.
1438 // [Two] moves to [Blink] since there is no prior [On]
1439 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001440 {"Two", phosphor::led::Layout::Blink, 0, 0,
1441 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301442 };
1443 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1444
1445 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001446 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301447 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1448 refAssert.begin(), refAssert.end(),
1449 std::inserter(temp, temp.begin()));
1450 EXPECT_EQ(0, temp.size());
1451 }
1452}
1453
1454/** @brief Assert 2 groups having multiple LEDs common in different state and
1455 * mixed priority.
1456 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001457TEST_F(LedTest,
1458 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301459{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001460 Manager manager(bus,
1461 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301462 {
1463 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001464 Manager::group ledsAssert{};
1465 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301466
Patrick Venture91ac8d32018-11-01 17:03:22 -07001467 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1468 auto result =
1469 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301470 EXPECT_EQ(true, result);
1471
1472 // Need just the ledsAssserted populated with these.
1473 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001474 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1475 {"Three", phosphor::led::Layout::On, 0, 0,
1476 phosphor::led::Layout::Blink},
1477 {"Five", phosphor::led::Layout::On, 0, 0,
1478 phosphor::led::Layout::On},
1479 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1480 {"Ten", phosphor::led::Layout::On, 0, 0,
1481 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301482 };
1483 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1484 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301485
1486 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001487 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301488 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1489 refAssert.begin(), refAssert.end(),
1490 std::inserter(temp, temp.begin()));
1491 EXPECT_EQ(0, temp.size());
1492 }
1493 {
1494 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001495 Manager::group ledsAssert{};
1496 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301497
Patrick Venture91ac8d32018-11-01 17:03:22 -07001498 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1499 auto result =
1500 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301501 EXPECT_EQ(true, result);
1502
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301503 // Need just the ledsAssserted populated with these.
1504 // [Two] remains [ON] due to higher priority.
1505 // [Three] remains on since it never was in [Blink] before
1506 // [Ten] moves to [Blink] due to priority: [Blink]
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301507 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001508 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1509 {"Four", phosphor::led::Layout::On, 0, 0,
1510 phosphor::led::Layout::On},
1511 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1512 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301513 };
1514 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1515 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301516
1517 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001518 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301519 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1520 refAssert.begin(), refAssert.end(),
1521 std::inserter(temp, temp.begin()));
1522 EXPECT_EQ(0, temp.size());
1523 }
1524}
1525
1526/** @brief Assert 2 groups having multiple LEDs common in different state and
1527 * mixed priority and De-Assert-A
1528 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001529TEST_F(
1530 LedTest,
1531 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandADeAssertA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301532{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001533 Manager manager(bus,
1534 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301535 {
1536 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001537 Manager::group ledsAssert{};
1538 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301539
Patrick Venture91ac8d32018-11-01 17:03:22 -07001540 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1541 auto result =
1542 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301543 EXPECT_EQ(true, result);
1544
1545 // Need just the ledsAssserted populated with these.
1546 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001547 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1548 {"Three", phosphor::led::Layout::On, 0, 0,
1549 phosphor::led::Layout::Blink},
1550 {"Five", phosphor::led::Layout::On, 0, 0,
1551 phosphor::led::Layout::On},
1552 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1553 {"Ten", phosphor::led::Layout::On, 0, 0,
1554 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301555 };
1556 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1557 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301558
1559 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001560 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301561 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1562 refAssert.begin(), refAssert.end(),
1563 std::inserter(temp, temp.begin()));
1564 EXPECT_EQ(0, temp.size());
1565 }
1566 {
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301567 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001568 Manager::group ledsAssert{};
1569 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301570
Patrick Venture91ac8d32018-11-01 17:03:22 -07001571 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1572 auto result =
1573 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301574 EXPECT_EQ(true, result);
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301575
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301576 // Need just the ledsAssserted populated with these.
1577 // [Two] remains [ON] due to higher priority.
1578 // [Three] remains on since it never was in [Blink] before
1579 // [Ten] moves to [Blink] due to priority: [Blink]
1580 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001581 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1582 {"Four", phosphor::led::Layout::On, 0, 0,
1583 phosphor::led::Layout::On},
1584 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1585 phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301586 };
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301587 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1588 EXPECT_EQ(0, ledsDeAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301589
1590 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001591 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301592 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1593 refAssert.begin(), refAssert.end(),
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301594 std::inserter(temp, temp.begin()));
1595 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301596 }
1597 {
1598 // De-Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001599 Manager::group ledsAssert{};
1600 Manager::group ledsDeAssert{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301601
Patrick Venture91ac8d32018-11-01 17:03:22 -07001602 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1603 auto result =
1604 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301605 EXPECT_EQ(false, result);
1606
1607 // Need just the ledsAssserted populated with these.
1608 // [Ten] remains [Blink] due to priority.
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301609 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001610 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1611 {"Four", phosphor::led::Layout::On, 0, 0,
1612 phosphor::led::Layout::On},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301613 };
1614 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1615
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301616 // Need just the ledsAssserted populated with these.
1617 // [Two] remains [ON] due to higher priority.
1618 // [Three] remains [On] since it never was in [Blink] before
1619 // [Ten] moves to [On] due to priority: [Blink]
1620 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001621 {"Ten", phosphor::led::Layout::On, 0, 0,
1622 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301623 };
1624 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1625
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301626 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001627 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301628 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1629 refAssert.begin(), refAssert.end(),
1630 std::inserter(temp, temp.begin()));
1631 EXPECT_EQ(0, temp.size());
1632 }
1633}
1634
1635/** @brief Assert 2 groups having multiple LEDs common in different state and
1636 * mixed priority and then DeAssert twice.
1637 */
Patrick Venture91ac8d32018-11-01 17:03:22 -07001638TEST_F(LedTest,
1639 assertTwoGroupsWithMultipleComonLEDInDifferentStateOnBlinkPriorityBandA)
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301640{
Patrick Venture91ac8d32018-11-01 17:03:22 -07001641 Manager manager(bus,
1642 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301643 {
1644 // Assert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001645 Manager::group ledsAssert{};
1646 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301647
Patrick Venture91ac8d32018-11-01 17:03:22 -07001648 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1649 auto result =
1650 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301651 EXPECT_EQ(true, result);
1652
1653 // Need just the ledsAssserted populated with these.
1654 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001655 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1656 {"Three", phosphor::led::Layout::On, 0, 0,
1657 phosphor::led::Layout::Blink},
1658 {"Five", phosphor::led::Layout::On, 0, 0,
1659 phosphor::led::Layout::On},
1660 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1661 {"Ten", phosphor::led::Layout::On, 0, 0,
1662 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301663 };
1664 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1665 EXPECT_EQ(0, ledsDeAssert.size());
1666
1667 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001668 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301669 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1670 refAssert.begin(), refAssert.end(),
1671 std::inserter(temp, temp.begin()));
1672 EXPECT_EQ(0, temp.size());
1673 }
1674 {
1675 // Assert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001676 Manager::group ledsAssert{};
1677 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301678
Patrick Venture91ac8d32018-11-01 17:03:22 -07001679 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1680 auto result =
1681 manager.setGroupState(group, true, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301682 EXPECT_EQ(true, result);
1683
1684 // Need just the ledsAssserted populated with these.
1685 // [Two] remains [ON] due to higher priority.
1686 // [Three] remains on since it never was in [Blink] before
1687 // [Ten] moves to [Blink] due to priority: [Blink]
1688 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001689 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1690 {"Four", phosphor::led::Layout::On, 0, 0,
1691 phosphor::led::Layout::On},
1692 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1693 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301694 };
1695 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1696 EXPECT_EQ(0, ledsDeAssert.size());
1697
1698 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001699 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301700 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1701 refAssert.begin(), refAssert.end(),
1702 std::inserter(temp, temp.begin()));
1703 EXPECT_EQ(0, temp.size());
1704 }
1705 {
1706 // DeAssert Set-B
Patrick Venture91ac8d32018-11-01 17:03:22 -07001707 Manager::group ledsAssert{};
1708 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301709
Patrick Venture91ac8d32018-11-01 17:03:22 -07001710 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1711 auto result =
1712 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301713 EXPECT_EQ(false, result);
1714
1715 // Need just the ledsAssserted populated with these.
1716 // [Ten] remains [Blink] due to priority.
1717 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001718 {"Five", phosphor::led::Layout::On, 0, 0,
1719 phosphor::led::Layout::On},
1720 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301721 };
1722 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1723
1724 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001725 Manager::group temp{};
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301726 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1727 refDeAssert.begin(), refDeAssert.end(),
1728 std::inserter(temp, temp.begin()));
1729 EXPECT_EQ(0, temp.size());
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301730
1731 // Need just the ledsAssert populated with these.
1732 // [Two] will move to [Blink]
1733 std::set<Layout::LedAction> refAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001734 {"Two", phosphor::led::Layout::Blink, 0, 0,
1735 phosphor::led::Layout::On},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301736 };
1737 EXPECT_EQ(refAssert.size(), ledsAssert.size());
1738
1739 // difference of refAssert and ledsAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001740 Manager::group temp1{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301741 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
1742 refAssert.begin(), refAssert.end(),
1743 std::inserter(temp1, temp1.begin()));
1744 EXPECT_EQ(0, temp1.size());
1745 }
1746 {
1747 // DeAssert Set-A
Patrick Venture91ac8d32018-11-01 17:03:22 -07001748 Manager::group ledsAssert{};
1749 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301750
Patrick Venture91ac8d32018-11-01 17:03:22 -07001751 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
1752 auto result =
1753 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301754 EXPECT_EQ(false, result);
1755
1756 // Need just the ledsAssserted populated with these.
1757 std::set<Layout::LedAction> refDeAssert = {
Patrick Venture91ac8d32018-11-01 17:03:22 -07001758 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On},
1759 {"Two", phosphor::led::Layout::Blink, 0, 0,
1760 phosphor::led::Layout::On},
1761 {"Three", phosphor::led::Layout::On, 0, 0,
1762 phosphor::led::Layout::Blink},
1763 {"Four", phosphor::led::Layout::On, 0, 0,
1764 phosphor::led::Layout::On},
1765 {"Ten", phosphor::led::Layout::Blink, 0, 0,
1766 phosphor::led::Layout::Blink},
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301767 };
1768 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
1769 EXPECT_EQ(0, ledsAssert.size());
1770
1771 // difference of refDeAssert and ledsDeAssert must be null.
Patrick Venture91ac8d32018-11-01 17:03:22 -07001772 Manager::group temp{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301773 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
1774 refDeAssert.begin(), refDeAssert.end(),
1775 std::inserter(temp, temp.begin()));
1776 EXPECT_EQ(0, temp.size());
1777 }
1778 {
1779 // DeAssert Set-B again and make sure we get all empty
Patrick Venture91ac8d32018-11-01 17:03:22 -07001780 Manager::group ledsAssert{};
1781 Manager::group ledsDeAssert{};
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301782
Patrick Venture91ac8d32018-11-01 17:03:22 -07001783 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
1784 auto result =
1785 manager.setGroupState(group, false, ledsAssert, ledsDeAssert);
Vishwanatha Subbanna4b000d82017-05-03 18:44:16 +05301786 EXPECT_EQ(false, result);
1787 EXPECT_EQ(0, ledsDeAssert.size());
1788 EXPECT_EQ(0, ledsAssert.size());
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +05301789 }
1790}