blob: 38f8196a1b99c5a0e6edfebfd164525c9d338eef [file] [log] [blame]
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301#include <set>
2#include <algorithm>
3#include <gtest/gtest.h>
4#include "manager.hpp"
5#include "led-test-map.hpp"
6
7using namespace phosphor::led;
8class LedTest : public ::testing::Test
9{
10 public:
11 virtual void SetUp()
12 {
13 // Not having a need at the moment but for future.
14 }
15 virtual void TearDown()
16 {
17 // Leaving upto auto cleanup.
18 }
19};
20
21/** @brief Assert Single LED to On */
22TEST_F(LedTest, assertSingleLedOn)
23{
24 Manager manager(singleLedOn);
25 {
26 // Assert the LEDs.
27 Manager::group ledsAssert {};
28 Manager::group ledsDeAssert {};
29 Manager::group ledsUpdate {};
30
31 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
32 auto result = manager.setGroupState(group, true, ledsAssert,
33 ledsDeAssert, ledsUpdate);
34 EXPECT_EQ(true, result);
35
36 // Need just the ledsAssserted populated with these.
37 std::set<Layout::LedAction> refAssert = {
38 {"One",phosphor::led::Layout::On},
39 };
40 EXPECT_EQ(refAssert.size(), ledsAssert.size());
41 EXPECT_EQ(0, ledsDeAssert.size());
42 EXPECT_EQ(0, ledsUpdate.size());
43
44 // difference of refAssert and ledsAssert must be null.
45 Manager::group temp {};
46 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
47 refAssert.begin(), refAssert.end(),
48 std::inserter(temp, temp.begin()));
49 EXPECT_EQ(0, temp.size());
50 }
51}
52
53/** @brief Assert Single LED to Blink */
54TEST_F(LedTest, assertSingleLedBlink)
55{
56 Manager manager(singleLedBlink);
57 {
58 // Assert the LEDs.
59 Manager::group ledsAssert {};
60 Manager::group ledsDeAssert {};
61 Manager::group ledsUpdate {};
62
63 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
64 auto result = manager.setGroupState(group, true, ledsAssert,
65 ledsDeAssert, ledsUpdate);
66 EXPECT_EQ(true, result);
67
68 // Need just the ledsAssserted populated with these.
69 std::set<Layout::LedAction> refAssert = {
70 {"One",phosphor::led::Layout::Blink},
71 };
72 EXPECT_EQ(refAssert.size(), ledsAssert.size());
73 EXPECT_EQ(0, ledsDeAssert.size());
74 EXPECT_EQ(0, ledsUpdate.size());
75
76 // difference of refAssert and ledsAssert must be null.
77 Manager::group temp {};
78 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
79 refAssert.begin(), refAssert.end(),
80 std::inserter(temp, temp.begin()));
81 EXPECT_EQ(0, temp.size());
82 }
83}
84
85/** @brief Assert Single LED to On and Try Assert Again */
86TEST_F(LedTest, assertSingleLedOnAndreAssert)
87{
88 Manager manager(singleLedOn);
89 {
90 // Assert the LEDs.
91 Manager::group ledsAssert {};
92 Manager::group ledsDeAssert {};
93 Manager::group ledsUpdate {};
94
95 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
96 auto result = manager.setGroupState(group, true, ledsAssert,
97 ledsDeAssert, ledsUpdate);
98 EXPECT_EQ(true, result);
99
100 // Need just the ledsAssserted populated with these.
101 std::set<Layout::LedAction> refAssert = {
102 {"One",phosphor::led::Layout::On},
103 };
104 EXPECT_EQ(refAssert.size(), ledsAssert.size());
105 EXPECT_EQ(0, ledsDeAssert.size());
106 EXPECT_EQ(0, ledsUpdate.size());
107
108 // difference of refAssert and ledsAssert must be null.
109 Manager::group temp {};
110 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
111 refAssert.begin(), refAssert.end(),
112 std::inserter(temp, temp.begin()));
113 EXPECT_EQ(0, temp.size());
114 }
115 {
116 // Assert the LEDs.
117 Manager::group ledsAssert {};
118 Manager::group ledsDeAssert {};
119 Manager::group ledsUpdate {};
120
121 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
122 auto result = manager.setGroupState(group, true, ledsAssert,
123 ledsDeAssert, ledsUpdate);
124 EXPECT_EQ(true, result);
125
126 EXPECT_EQ(0, ledsAssert.size());
127 EXPECT_EQ(0, ledsDeAssert.size());
128 EXPECT_EQ(0, ledsUpdate.size());
129 }
130}
131
132/** @brief Assert Multiple LEDs to On */
133TEST_F(LedTest, assertMultipleLedOn)
134{
135 Manager manager(multipleLedsOn);
136 {
137 // Assert the LEDs.
138 Manager::group ledsAssert {};
139 Manager::group ledsDeAssert {};
140 Manager::group ledsUpdate {};
141
142 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
143 auto result = manager.setGroupState(group, true, ledsAssert,
144 ledsDeAssert, ledsUpdate);
145 EXPECT_EQ(true, result);
146
147 // Need just the ledsAssserted populated with these.
148 std::set<Layout::LedAction> refAssert = {
149 {"One",phosphor::led::Layout::On},
150 {"Two",phosphor::led::Layout::On},
151 {"Three",phosphor::led::Layout::On},
152 };
153 EXPECT_EQ(refAssert.size(), ledsAssert.size());
154 EXPECT_EQ(0, ledsDeAssert.size());
155 EXPECT_EQ(0, ledsUpdate.size());
156
157 // difference of refAssert and ledsAssert must be null.
158 Manager::group temp {};
159 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
160 refAssert.begin(), refAssert.end(),
161 std::inserter(temp, temp.begin()));
162 EXPECT_EQ(0, temp.size());
163 }
164}
165
166/** @brief Assert Multiple LEDs to Blink */
167TEST_F(LedTest, assertMultipleLedBlink)
168{
169 Manager manager(multipleLedsBlink);
170 {
171 // Assert the LEDs.
172 Manager::group ledsAssert {};
173 Manager::group ledsDeAssert {};
174 Manager::group ledsUpdate {};
175
176 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
177 auto result = manager.setGroupState(group, true, ledsAssert,
178 ledsDeAssert, ledsUpdate);
179 EXPECT_EQ(true, result);
180
181 // Need just the ledsAssserted populated with these.
182 std::set<Layout::LedAction> refAssert = {
183 {"One",phosphor::led::Layout::Blink},
184 {"Two",phosphor::led::Layout::Blink},
185 {"Three",phosphor::led::Layout::Blink},
186 };
187 EXPECT_EQ(refAssert.size(), ledsAssert.size());
188 EXPECT_EQ(0, ledsDeAssert.size());
189 EXPECT_EQ(0, ledsUpdate.size());
190
191 // difference of refAssert and ledsAssert must be null.
192 Manager::group temp {};
193 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
194 refAssert.begin(), refAssert.end(),
195 std::inserter(temp, temp.begin()));
196 EXPECT_EQ(0, temp.size());
197 }
198}
199
200/** @brief Assert Multiple LEDs to Blink, DeAssert */
201TEST_F(LedTest, assertMultipleLedBlinkAndDeAssert)
202{
203 Manager manager(multipleLedsBlink);
204 {
205 // Assert the LEDs.
206 Manager::group ledsAssert {};
207 Manager::group ledsDeAssert {};
208 Manager::group ledsUpdate {};
209
210 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
211 auto result = manager.setGroupState(group, true, ledsAssert,
212 ledsDeAssert, ledsUpdate);
213 EXPECT_EQ(true, result);
214
215 // Need just the ledsAssserted populated with these.
216 std::set<Layout::LedAction> refAssert = {
217 {"One",phosphor::led::Layout::Blink},
218 {"Two",phosphor::led::Layout::Blink},
219 {"Three",phosphor::led::Layout::Blink},
220 };
221 EXPECT_EQ(refAssert.size(), ledsAssert.size());
222 EXPECT_EQ(0, ledsDeAssert.size());
223 EXPECT_EQ(0, ledsUpdate.size());
224
225 // difference of refAssert and ledsAssert must be null.
226 Manager::group temp {};
227 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.
234 Manager::group ledsAssert {};
235 Manager::group ledsDeAssert {};
236 Manager::group ledsUpdate {};
237
238 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
239 auto result = manager.setGroupState(group, false, ledsAssert,
240 ledsDeAssert, ledsUpdate);
241 EXPECT_EQ(false, result);
242
243 // Need just the ledsAssserted populated with these.
244 std::set<Layout::LedAction> refDeAssert = {
245 {"One",phosphor::led::Layout::Blink},
246 {"Two",phosphor::led::Layout::Blink},
247 {"Three",phosphor::led::Layout::Blink},
248 };
249 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
250 EXPECT_EQ(0, ledsAssert.size());
251 EXPECT_EQ(0, ledsUpdate.size());
252
253 // difference of refDeAssert and ledsDeAssert must be null.
254 Manager::group temp {};
255 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
256 refDeAssert.begin(), refDeAssert.end(),
257 std::inserter(temp, temp.begin()));
258 EXPECT_EQ(0, temp.size());
259 }
260}
261
262/** @brief Assert Multiple LEDs to Blink, DeAssert Twice */
263TEST_F(LedTest, assertMultipleLedBlinkAndDeAssertTwice)
264{
265 Manager manager(multipleLedsBlink);
266 {
267 // Assert the LEDs.
268 Manager::group ledsAssert {};
269 Manager::group ledsDeAssert {};
270 Manager::group ledsUpdate {};
271
272 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
273 auto result = manager.setGroupState(group, true, ledsAssert,
274 ledsDeAssert, ledsUpdate);
275 EXPECT_EQ(true, result);
276
277 // Need just the ledsAssserted populated with these.
278 std::set<Layout::LedAction> refAssert = {
279 {"One",phosphor::led::Layout::Blink},
280 {"Two",phosphor::led::Layout::Blink},
281 {"Three",phosphor::led::Layout::Blink},
282 };
283 EXPECT_EQ(refAssert.size(), ledsAssert.size());
284 EXPECT_EQ(0, ledsDeAssert.size());
285 EXPECT_EQ(0, ledsUpdate.size());
286
287 // difference of refAssert and ledsAssert must be null.
288 Manager::group temp {};
289 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
290 refAssert.begin(), refAssert.end(),
291 std::inserter(temp, temp.begin()));
292 EXPECT_EQ(0, temp.size());
293 }
294 {
295 // DeAssert the LEDs.
296 Manager::group ledsAssert {};
297 Manager::group ledsDeAssert {};
298 Manager::group ledsUpdate {};
299
300 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
301 auto result = manager.setGroupState(group, false, ledsAssert,
302 ledsDeAssert, ledsUpdate);
303 EXPECT_EQ(false, result);
304
305 // Need just the ledsAssserted populated with these.
306 std::set<Layout::LedAction> refDeAssert = {
307 {"One",phosphor::led::Layout::Blink},
308 {"Two",phosphor::led::Layout::Blink},
309 {"Three",phosphor::led::Layout::Blink},
310 };
311 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
312 EXPECT_EQ(0, ledsAssert.size());
313 EXPECT_EQ(0, ledsUpdate.size());
314
315 // difference of refDeAssert and ledsDeAssert must be null.
316 Manager::group temp {};
317 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
318 refDeAssert.begin(), refDeAssert.end(),
319 std::inserter(temp, temp.begin()));
320 EXPECT_EQ(0, temp.size());
321 }
322 {
323 // DeAssert the LEDs.
324 Manager::group ledsAssert {};
325 Manager::group ledsDeAssert {};
326 Manager::group ledsUpdate {};
327
328 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
329 auto result = manager.setGroupState(group, false, ledsAssert,
330 ledsDeAssert, ledsUpdate);
331 EXPECT_EQ(false, result);
332 EXPECT_EQ(0, ledsDeAssert.size());
333 EXPECT_EQ(0, ledsAssert.size());
334 EXPECT_EQ(0, ledsUpdate.size());
335 }
336}
337
338/** @brief Assert Multiple LEDs to mix of On and Blink */
339TEST_F(LedTest, assertMultipleLedOnAndBlink)
340{
341 Manager manager(multipleLedsOnAndBlink);
342 {
343 // Assert the LEDs.
344 Manager::group ledsAssert {};
345 Manager::group ledsDeAssert {};
346 Manager::group ledsUpdate {};
347
348 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsMix";
349 auto result = manager.setGroupState(group, true, ledsAssert,
350 ledsDeAssert, ledsUpdate);
351 EXPECT_EQ(true, result);
352
353 // Need just the ledsAssserted populated with these.
354 std::set<Layout::LedAction> refAssert = {
355 {"One",phosphor::led::Layout::Blink},
356 {"Two",phosphor::led::Layout::On},
357 {"Three",phosphor::led::Layout::Blink},
358 {"Four",phosphor::led::Layout::On},
359 {"Five",phosphor::led::Layout::On},
360 };
361 EXPECT_EQ(refAssert.size(), ledsAssert.size());
362 EXPECT_EQ(0, ledsDeAssert.size());
363 EXPECT_EQ(0, ledsUpdate.size());
364
365 // difference of refAssert and ledsAssert must be null.
366 Manager::group temp {};
367 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
368 refAssert.begin(), refAssert.end(),
369 std::inserter(temp, temp.begin()));
370 EXPECT_EQ(0, temp.size());
371 }
372}
373
374/** @brief Assert 2 groups having distinct LEDs */
375TEST_F(LedTest, assertTwoGroupsOnWithDistinctLEDOn)
376{
377 Manager manager(twoGroupsWithDistinctLEDsOn);
378 {
379 // Assert Set-A
380 Manager::group ledsAssert {};
381 Manager::group ledsDeAssert {};
382 Manager::group ledsUpdate {};
383
384 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
385 auto result = manager.setGroupState(group, true, ledsAssert,
386 ledsDeAssert, ledsUpdate);
387 EXPECT_EQ(true, result);
388
389 // Need just the ledsAssserted populated with these.
390 std::set<Layout::LedAction> refAssert = {
391 {"One",phosphor::led::Layout::On},
392 {"Two",phosphor::led::Layout::On},
393 {"Three",phosphor::led::Layout::On},
394 };
395 EXPECT_EQ(refAssert.size(), ledsAssert.size());
396 EXPECT_EQ(0, ledsDeAssert.size());
397 EXPECT_EQ(0, ledsUpdate.size());
398
399 // difference of refAssert and ledsAssert must be null.
400 Manager::group temp {};
401 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
402 refAssert.begin(), refAssert.end(),
403 std::inserter(temp, temp.begin()));
404 EXPECT_EQ(0, temp.size());
405 }
406 {
407 // Assert Set-B
408 Manager::group ledsAssert {};
409 Manager::group ledsDeAssert {};
410 Manager::group ledsUpdate {};
411
412 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
413 auto result = manager.setGroupState(group, true, ledsAssert,
414 ledsDeAssert, ledsUpdate);
415 EXPECT_EQ(true, result);
416
417 // Need just the ledsAssserted populated with these.
418 std::set<Layout::LedAction> refAssert = {
419 {"Four",phosphor::led::Layout::On},
420 {"Five",phosphor::led::Layout::On},
421 {"Six",phosphor::led::Layout::On},
422 };
423 EXPECT_EQ(refAssert.size(), ledsAssert.size());
424 EXPECT_EQ(0, ledsDeAssert.size());
425 EXPECT_EQ(0, ledsUpdate.size());
426
427 // difference of refAssert and ledsAssert must be null.
428 Manager::group temp {};
429 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
430 refAssert.begin(), refAssert.end(),
431 std::inserter(temp, temp.begin()));
432 EXPECT_EQ(0, temp.size());
433 }
434}
435
436/** @brief Assert 2 groups having one of the LEDs common */
437TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOn)
438{
439 Manager manager(twoGroupsWithOneComonLEDOn);
440 {
441 // Assert Set-A
442 Manager::group ledsAssert {};
443 Manager::group ledsDeAssert {};
444 Manager::group ledsUpdate {};
445
446 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
447 auto result = manager.setGroupState(group, true, ledsAssert,
448 ledsDeAssert, ledsUpdate);
449 EXPECT_EQ(true, result);
450
451 // Need just the ledsAssserted populated with these.
452 std::set<Layout::LedAction> refAssert = {
453 {"One",phosphor::led::Layout::On},
454 {"Two",phosphor::led::Layout::On},
455 {"Three",phosphor::led::Layout::On},
456 };
457 EXPECT_EQ(refAssert.size(), ledsAssert.size());
458 EXPECT_EQ(0, ledsDeAssert.size());
459 EXPECT_EQ(0, ledsUpdate.size());
460
461 // difference of refAssert and ledsAssert must be null.
462 Manager::group temp {};
463 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
464 refAssert.begin(), refAssert.end(),
465 std::inserter(temp, temp.begin()));
466 EXPECT_EQ(0, temp.size());
467 }
468 {
469 // Assert Set-B
470 Manager::group ledsAssert {};
471 Manager::group ledsDeAssert {};
472 Manager::group ledsUpdate {};
473
474 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
475 auto result = manager.setGroupState(group, true, ledsAssert,
476 ledsDeAssert, ledsUpdate);
477 EXPECT_EQ(true, result);
478
479 // Need just the ledsAssserted populated with these.
480 std::set<Layout::LedAction> refAssert = {
481 {"Four",phosphor::led::Layout::On},
482 {"Six",phosphor::led::Layout::On},
483 };
484 EXPECT_EQ(refAssert.size(), ledsAssert.size());
485 EXPECT_EQ(0, ledsDeAssert.size());
486 EXPECT_EQ(0, ledsUpdate.size());
487
488 // difference of refAssert and ledsAssert must be null.
489 Manager::group temp {};
490 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
491 refAssert.begin(), refAssert.end(),
492 std::inserter(temp, temp.begin()));
493 EXPECT_EQ(0, temp.size());
494 }
495}
496
497/** @brief Assert 2 groups having one of the LEDs common in different state */
498TEST_F(LedTest, assertTwoGroupsWithOneComonLEDInDifferentState)
499{
500 Manager manager(twoGroupsWithOneComonLEDInDifferentState);
501 {
502 // Assert Set-A
503 Manager::group ledsAssert {};
504 Manager::group ledsDeAssert {};
505 Manager::group ledsUpdate {};
506
507 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
508 auto result = manager.setGroupState(group, true, ledsAssert,
509 ledsDeAssert, ledsUpdate);
510 EXPECT_EQ(true, result);
511
512 // Need just the ledsAssserted populated with these.
513 std::set<Layout::LedAction> refAssert = {
514 {"One",phosphor::led::Layout::On},
515 {"Two",phosphor::led::Layout::On},
516 {"Three",phosphor::led::Layout::On},
517 };
518 EXPECT_EQ(refAssert.size(), ledsAssert.size());
519 EXPECT_EQ(0, ledsDeAssert.size());
520 EXPECT_EQ(0, ledsUpdate.size());
521
522 // difference of refAssert and ledsAssert must be null.
523 Manager::group temp {};
524 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
525 refAssert.begin(), refAssert.end(),
526 std::inserter(temp, temp.begin()));
527 EXPECT_EQ(0, temp.size());
528 }
529 {
530 // Assert Set-B
531 Manager::group ledsAssert {};
532 Manager::group ledsDeAssert {};
533 Manager::group ledsUpdate {};
534
535 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
536 auto result = manager.setGroupState(group, true, ledsAssert,
537 ledsDeAssert, ledsUpdate);
538 EXPECT_EQ(true, result);
539
540 // Need just the ledsAssserted populated with these.
541 std::set<Layout::LedAction> refAssert = {
542 {"Two",phosphor::led::Layout::Blink},
543 {"Four",phosphor::led::Layout::On},
544 {"Five",phosphor::led::Layout::On},
545 {"Six",phosphor::led::Layout::On},
546 };
547 EXPECT_EQ(refAssert.size(), ledsAssert.size());
548 EXPECT_EQ(0, ledsDeAssert.size());
549 EXPECT_EQ(0, ledsUpdate.size());
550
551 // difference of refAssert and ledsAssert must be null.
552 Manager::group temp {};
553 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
554 refAssert.begin(), refAssert.end(),
555 std::inserter(temp, temp.begin()));
556 EXPECT_EQ(0, temp.size());
557 }
558}
559
560/** @brief Assert 2 groups having multiple common LEDs in Same State */
561TEST_F(LedTest, assertTwoGroupsWithMultiplComonLEDOn)
562{
563 Manager manager(twoGroupsWithMultiplComonLEDOn);
564 {
565 // Assert Set-B
566 Manager::group ledsAssert {};
567 Manager::group ledsDeAssert {};
568 Manager::group ledsUpdate {};
569
570 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
571 auto result = manager.setGroupState(group, true, ledsAssert,
572 ledsDeAssert, ledsUpdate);
573 EXPECT_EQ(true, result);
574
575 // Need just the ledsAssserted populated with these.
576 std::set<Layout::LedAction> refAssert = {
577 {"Two",phosphor::led::Layout::On},
578 {"Six",phosphor::led::Layout::On},
579 {"Three",phosphor::led::Layout::On},
580 {"Seven",phosphor::led::Layout::On},
581 };
582 EXPECT_EQ(refAssert.size(), ledsAssert.size());
583 EXPECT_EQ(0, ledsDeAssert.size());
584 EXPECT_EQ(0, ledsUpdate.size());
585
586 // difference of refAssert and ledsAssert must be null.
587 Manager::group temp {};
588 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
589 refAssert.begin(), refAssert.end(),
590 std::inserter(temp, temp.begin()));
591 EXPECT_EQ(0, temp.size());
592 }
593 {
594 // Assert Set-A
595 Manager::group ledsAssert {};
596 Manager::group ledsDeAssert {};
597 Manager::group ledsUpdate {};
598
599 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
600 auto result = manager.setGroupState(group, true, ledsAssert,
601 ledsDeAssert, ledsUpdate);
602 EXPECT_EQ(true, result);
603
604 // Need just the ledsAssserted populated with these.
605 std::set<Layout::LedAction> refAssert = {
606 {"One",phosphor::led::Layout::On},
607 };
608 EXPECT_EQ(refAssert.size(), ledsAssert.size());
609 EXPECT_EQ(0, ledsDeAssert.size());
610 EXPECT_EQ(0, ledsUpdate.size());
611
612 // difference of refAssert and ledsAssert must be null.
613 Manager::group temp {};
614 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
615 refAssert.begin(), refAssert.end(),
616 std::inserter(temp, temp.begin()));
617 EXPECT_EQ(0, temp.size());
618 }
619}
620
621/** @brief Assert 2 groups having multiple LEDs common in different state */
622TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStates)
623{
624 Manager manager(twoGroupsWithMultipleComonLEDInDifferentState);
625 {
626 // Assert Set-A
627 Manager::group ledsAssert {};
628 Manager::group ledsDeAssert {};
629 Manager::group ledsUpdate {};
630
631 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
632 auto result = manager.setGroupState(group, true, ledsAssert,
633 ledsDeAssert, ledsUpdate);
634 EXPECT_EQ(true, result);
635
636 // Need just the ledsAssserted populated with these.
637 std::set<Layout::LedAction> refAssert = {
638 {"One",phosphor::led::Layout::On},
639 {"Two",phosphor::led::Layout::Blink},
640 {"Three",phosphor::led::Layout::On},
641 {"Four",phosphor::led::Layout::On},
642 };
643 EXPECT_EQ(refAssert.size(), ledsAssert.size());
644 EXPECT_EQ(0, ledsDeAssert.size());
645 EXPECT_EQ(0, ledsUpdate.size());
646
647 // difference of refAssert and ledsAssert must be null.
648 Manager::group temp {};
649 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
650 refAssert.begin(), refAssert.end(),
651 std::inserter(temp, temp.begin()));
652 EXPECT_EQ(0, temp.size());
653 }
654 {
655 // Assert Set-B
656 Manager::group ledsAssert {};
657 Manager::group ledsDeAssert {};
658 Manager::group ledsUpdate {};
659
660 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
661 auto result = manager.setGroupState(group, true, ledsAssert,
662 ledsDeAssert, ledsUpdate);
663 EXPECT_EQ(true, result);
664
665 // Need just the ledsAssserted populated with these.
666 std::set<Layout::LedAction> refAssert = {
667 {"Two",phosphor::led::Layout::On},
668 {"Three",phosphor::led::Layout::Blink},
669 {"Five",phosphor::led::Layout::On},
670 {"Six",phosphor::led::Layout::On},
671 };
672 EXPECT_EQ(refAssert.size(), ledsAssert.size());
673 EXPECT_EQ(0, ledsDeAssert.size());
674 EXPECT_EQ(0, ledsUpdate.size());
675
676 // difference of refAssert and ledsAssert must be null.
677 Manager::group temp {};
678 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
679 refAssert.begin(), refAssert.end(),
680 std::inserter(temp, temp.begin()));
681 EXPECT_EQ(0, temp.size());
682 }
683}
684
685/** @brief Assert 2 groups having multiple LEDs common in Same State
686 * and then De-Assert One
687 */
688TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDAndDeAssertOne)
689{
690 Manager manager(twoGroupsWithMultiplComonLEDOn);
691 {
692 // Assert Set-A
693 Manager::group ledsAssert {};
694 Manager::group ledsDeAssert {};
695 Manager::group ledsUpdate {};
696
697 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
698 auto result = manager.setGroupState(group, true, ledsAssert,
699 ledsDeAssert, ledsUpdate);
700 EXPECT_EQ(true, result);
701
702 // Need just the ledsAssserted populated with these.
703 std::set<Layout::LedAction> refAssert = {
704 {"One",phosphor::led::Layout::On},
705 {"Two",phosphor::led::Layout::On},
706 {"Three",phosphor::led::Layout::On},
707 };
708 EXPECT_EQ(refAssert.size(), ledsAssert.size());
709 EXPECT_EQ(0, ledsDeAssert.size());
710 EXPECT_EQ(0, ledsUpdate.size());
711
712 // difference of refAssert and ledsAssert must be null.
713 Manager::group temp {};
714 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
715 refAssert.begin(), refAssert.end(),
716 std::inserter(temp, temp.begin()));
717 EXPECT_EQ(0, temp.size());
718 }
719 {
720 // Assert Set-B
721 Manager::group ledsAssert {};
722 Manager::group ledsDeAssert {};
723 Manager::group ledsUpdate {};
724
725 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
726 auto result = manager.setGroupState(group, true, ledsAssert,
727 ledsDeAssert, ledsUpdate);
728 EXPECT_EQ(true, result);
729
730 // Need just the ledsAssserted populated with these.
731 std::set<Layout::LedAction> refAssert = {
732 {"Six",phosphor::led::Layout::On},
733 {"Seven",phosphor::led::Layout::On},
734 };
735 EXPECT_EQ(refAssert.size(), ledsAssert.size());
736 EXPECT_EQ(0, ledsDeAssert.size());
737 EXPECT_EQ(0, ledsUpdate.size());
738
739 // difference of refAssert and ledsAssert must be null.
740 Manager::group temp {};
741 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
742 refAssert.begin(), refAssert.end(),
743 std::inserter(temp, temp.begin()));
744 EXPECT_EQ(0, temp.size());
745 }
746 {
747 // DeAssert Set-A
748 Manager::group ledsAssert {};
749 Manager::group ledsDeAssert {};
750 Manager::group ledsUpdate {};
751
752 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
753 auto result = manager.setGroupState(group, false, ledsAssert,
754 ledsDeAssert, ledsUpdate);
755 EXPECT_EQ(false, result);
756
757 // Need just the ledsAssserted populated with these.
758 std::set<Layout::LedAction> refDeAssert = {
759 {"One",phosphor::led::Layout::On},
760 };
761 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
762 EXPECT_EQ(0, ledsAssert.size());
763 EXPECT_EQ(0, ledsUpdate.size());
764
765 // difference of refAssert and ledsAssert must be null.
766 Manager::group temp {};
767 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
768 refDeAssert.begin(), refDeAssert.end(),
769 std::inserter(temp, temp.begin()));
770 EXPECT_EQ(0, temp.size());
771 }
772}
773
774/** @brief Assert 2 groups having multiple LEDs common but in
775 * different state and De-Assert one*/
776TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateDeAssertOne)
777{
778 Manager manager(twoGroupsWithMultipleComonLEDInDifferentState);
779 {
780 // Assert Set-B
781 Manager::group ledsAssert {};
782 Manager::group ledsDeAssert {};
783 Manager::group ledsUpdate {};
784
785 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
786 auto result = manager.setGroupState(group, true, ledsAssert,
787 ledsDeAssert, ledsUpdate);
788 EXPECT_EQ(true, result);
789
790 // Need just the ledsAssserted populated with these.
791 std::set<Layout::LedAction> refAssert = {
792 {"Two",phosphor::led::Layout::On},
793 {"Three",phosphor::led::Layout::Blink},
794 {"Five",phosphor::led::Layout::On},
795 {"Six",phosphor::led::Layout::On},
796 };
797 EXPECT_EQ(refAssert.size(), ledsAssert.size());
798 EXPECT_EQ(0, ledsDeAssert.size());
799 EXPECT_EQ(0, ledsUpdate.size());
800
801 // difference of refAssert and ledsAssert must be null.
802 Manager::group temp {};
803 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
804 refAssert.begin(), refAssert.end(),
805 std::inserter(temp, temp.begin()));
806 EXPECT_EQ(0, temp.size());
807 }
808 {
809 // Assert Set-A
810 Manager::group ledsAssert {};
811 Manager::group ledsDeAssert {};
812 Manager::group ledsUpdate {};
813
814 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
815 auto result = manager.setGroupState(group, true, ledsAssert,
816 ledsDeAssert, ledsUpdate);
817 EXPECT_EQ(true, result);
818
819 // Need just the ledsAssserted populated with these.
820 std::set<Layout::LedAction> refAssert = {
821 {"One",phosphor::led::Layout::On},
822 {"Two",phosphor::led::Layout::Blink},
823 {"Three",phosphor::led::Layout::On},
824 {"Four",phosphor::led::Layout::On},
825 };
826 EXPECT_EQ(refAssert.size(), ledsAssert.size());
827 EXPECT_EQ(0, ledsDeAssert.size());
828 EXPECT_EQ(0, ledsUpdate.size());
829
830 // difference of refAssert and ledsAssert must be null.
831 Manager::group temp {};
832 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
833 refAssert.begin(), refAssert.end(),
834 std::inserter(temp, temp.begin()));
835 EXPECT_EQ(0, temp.size());
836 }
837 {
838 // DeAssert Set-A
839 Manager::group ledsAssert {};
840 Manager::group ledsDeAssert {};
841 Manager::group ledsUpdate {};
842
843 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
844 auto result = manager.setGroupState(group, false, ledsAssert,
845 ledsDeAssert, ledsUpdate);
846 EXPECT_EQ(false, result);
847
848 // Need just the ledsUpdated populated with these.
849 std::set<Layout::LedAction> refUpdate = {
850 {"Two",phosphor::led::Layout::On},
851 {"Three",phosphor::led::Layout::Blink},
852 };
853 EXPECT_EQ(refUpdate.size(), ledsUpdate.size());
854 EXPECT_EQ(0, ledsAssert.size());
855
856 // difference of refAssert and ledsAssert must be null.
857 Manager::group temp {};
858 std::set_difference(ledsUpdate.begin(), ledsUpdate.end(),
859 refUpdate.begin(), refUpdate.end(),
860 std::inserter(temp, temp.begin()));
861 EXPECT_EQ(0, temp.size());
862
863 // Need just the ledsDeAsserted populated with these.
864 std::set<Layout::LedAction> refDeAssert = {
865 {"One",phosphor::led::Layout::On},
866 {"Four",phosphor::led::Layout::On},
867 };
868 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
869
870 // difference of refAssert and ledsAssert must be null.
871 temp.clear();
872 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
873 refDeAssert.begin(), refDeAssert.end(),
874 std::inserter(temp, temp.begin()));
875 EXPECT_EQ(0, temp.size());
876 }
877}