blob: 19c54a26ee4bff8f4ca23c20e86f8c58dc771a93 [file] [log] [blame]
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05301#include <set>
2#include <algorithm>
3#include <gtest/gtest.h>
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +05304#include <sdbusplus/bus.hpp>
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05305#include "manager.hpp"
6#include "led-test-map.hpp"
Vishwanatha Subbannaed490732016-12-20 15:59:29 +05307using namespace phosphor::led;
8class LedTest : public ::testing::Test
9{
10 public:
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053011 sdbusplus::bus::bus bus;
12 LedTest() : bus(sdbusplus::bus::new_default())
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053013 {
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053014 // Nothing here
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053015 }
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053016 ~LedTest()
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053017 {
18 // Leaving upto auto cleanup.
19 }
20};
21
22/** @brief Assert Single LED to On */
23TEST_F(LedTest, assertSingleLedOn)
24{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053025 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053026 {
27 // Assert the LEDs.
28 Manager::group ledsAssert {};
29 Manager::group ledsDeAssert {};
30 Manager::group ledsUpdate {};
31
32 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
33 auto result = manager.setGroupState(group, true, ledsAssert,
34 ledsDeAssert, ledsUpdate);
35 EXPECT_EQ(true, result);
36
37 // Need just the ledsAssserted populated with these.
38 std::set<Layout::LedAction> refAssert = {
39 {"One",phosphor::led::Layout::On},
40 };
41 EXPECT_EQ(refAssert.size(), ledsAssert.size());
42 EXPECT_EQ(0, ledsDeAssert.size());
43 EXPECT_EQ(0, ledsUpdate.size());
44
45 // difference of refAssert and ledsAssert must be null.
46 Manager::group temp {};
47 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
48 refAssert.begin(), refAssert.end(),
49 std::inserter(temp, temp.begin()));
50 EXPECT_EQ(0, temp.size());
51 }
52}
53
54/** @brief Assert Single LED to Blink */
55TEST_F(LedTest, assertSingleLedBlink)
56{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053057 Manager manager(bus, singleLedBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053058 {
59 // Assert the LEDs.
60 Manager::group ledsAssert {};
61 Manager::group ledsDeAssert {};
62 Manager::group ledsUpdate {};
63
64 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
65 auto result = manager.setGroupState(group, true, ledsAssert,
66 ledsDeAssert, ledsUpdate);
67 EXPECT_EQ(true, result);
68
69 // Need just the ledsAssserted populated with these.
70 std::set<Layout::LedAction> refAssert = {
71 {"One",phosphor::led::Layout::Blink},
72 };
73 EXPECT_EQ(refAssert.size(), ledsAssert.size());
74 EXPECT_EQ(0, ledsDeAssert.size());
75 EXPECT_EQ(0, ledsUpdate.size());
76
77 // difference of refAssert and ledsAssert must be null.
78 Manager::group temp {};
79 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
80 refAssert.begin(), refAssert.end(),
81 std::inserter(temp, temp.begin()));
82 EXPECT_EQ(0, temp.size());
83 }
84}
85
86/** @brief Assert Single LED to On and Try Assert Again */
87TEST_F(LedTest, assertSingleLedOnAndreAssert)
88{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +053089 Manager manager(bus, singleLedOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +053090 {
91 // Assert the LEDs.
92 Manager::group ledsAssert {};
93 Manager::group ledsDeAssert {};
94 Manager::group ledsUpdate {};
95
96 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
97 auto result = manager.setGroupState(group, true, ledsAssert,
98 ledsDeAssert, ledsUpdate);
99 EXPECT_EQ(true, result);
100
101 // Need just the ledsAssserted populated with these.
102 std::set<Layout::LedAction> refAssert = {
103 {"One",phosphor::led::Layout::On},
104 };
105 EXPECT_EQ(refAssert.size(), ledsAssert.size());
106 EXPECT_EQ(0, ledsDeAssert.size());
107 EXPECT_EQ(0, ledsUpdate.size());
108
109 // difference of refAssert and ledsAssert must be null.
110 Manager::group temp {};
111 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.
118 Manager::group ledsAssert {};
119 Manager::group ledsDeAssert {};
120 Manager::group ledsUpdate {};
121
122 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed";
123 auto result = manager.setGroupState(group, true, ledsAssert,
124 ledsDeAssert, ledsUpdate);
125 EXPECT_EQ(true, result);
126
127 EXPECT_EQ(0, ledsAssert.size());
128 EXPECT_EQ(0, ledsDeAssert.size());
129 EXPECT_EQ(0, ledsUpdate.size());
130 }
131}
132
133/** @brief Assert Multiple LEDs to On */
134TEST_F(LedTest, assertMultipleLedOn)
135{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530136 Manager manager(bus, multipleLedsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530137 {
138 // Assert the LEDs.
139 Manager::group ledsAssert {};
140 Manager::group ledsDeAssert {};
141 Manager::group ledsUpdate {};
142
143 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
144 auto result = manager.setGroupState(group, true, ledsAssert,
145 ledsDeAssert, ledsUpdate);
146 EXPECT_EQ(true, result);
147
148 // Need just the ledsAssserted populated with these.
149 std::set<Layout::LedAction> refAssert = {
150 {"One",phosphor::led::Layout::On},
151 {"Two",phosphor::led::Layout::On},
152 {"Three",phosphor::led::Layout::On},
153 };
154 EXPECT_EQ(refAssert.size(), ledsAssert.size());
155 EXPECT_EQ(0, ledsDeAssert.size());
156 EXPECT_EQ(0, ledsUpdate.size());
157
158 // difference of refAssert and ledsAssert must be null.
159 Manager::group temp {};
160 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
161 refAssert.begin(), refAssert.end(),
162 std::inserter(temp, temp.begin()));
163 EXPECT_EQ(0, temp.size());
164 }
165}
166
167/** @brief Assert Multiple LEDs to Blink */
168TEST_F(LedTest, assertMultipleLedBlink)
169{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530170 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530171 {
172 // Assert the LEDs.
173 Manager::group ledsAssert {};
174 Manager::group ledsDeAssert {};
175 Manager::group ledsUpdate {};
176
177 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
178 auto result = manager.setGroupState(group, true, ledsAssert,
179 ledsDeAssert, ledsUpdate);
180 EXPECT_EQ(true, result);
181
182 // Need just the ledsAssserted populated with these.
183 std::set<Layout::LedAction> refAssert = {
184 {"One",phosphor::led::Layout::Blink},
185 {"Two",phosphor::led::Layout::Blink},
186 {"Three",phosphor::led::Layout::Blink},
187 };
188 EXPECT_EQ(refAssert.size(), ledsAssert.size());
189 EXPECT_EQ(0, ledsDeAssert.size());
190 EXPECT_EQ(0, ledsUpdate.size());
191
192 // difference of refAssert and ledsAssert must be null.
193 Manager::group temp {};
194 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
195 refAssert.begin(), refAssert.end(),
196 std::inserter(temp, temp.begin()));
197 EXPECT_EQ(0, temp.size());
198 }
199}
200
201/** @brief Assert Multiple LEDs to Blink, DeAssert */
202TEST_F(LedTest, assertMultipleLedBlinkAndDeAssert)
203{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530204 Manager manager(bus, multipleLedsBlink);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530205 {
206 // Assert the LEDs.
207 Manager::group ledsAssert {};
208 Manager::group ledsDeAssert {};
209 Manager::group ledsUpdate {};
210
211 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
212 auto result = manager.setGroupState(group, true, ledsAssert,
213 ledsDeAssert, ledsUpdate);
214 EXPECT_EQ(true, result);
215
216 // Need just the ledsAssserted populated with these.
217 std::set<Layout::LedAction> refAssert = {
218 {"One",phosphor::led::Layout::Blink},
219 {"Two",phosphor::led::Layout::Blink},
220 {"Three",phosphor::led::Layout::Blink},
221 };
222 EXPECT_EQ(refAssert.size(), ledsAssert.size());
223 EXPECT_EQ(0, ledsDeAssert.size());
224 EXPECT_EQ(0, ledsUpdate.size());
225
226 // difference of refAssert and ledsAssert must be null.
227 Manager::group temp {};
228 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
229 refAssert.begin(), refAssert.end(),
230 std::inserter(temp, temp.begin()));
231 EXPECT_EQ(0, temp.size());
232 }
233 {
234 // Assert the LEDs.
235 Manager::group ledsAssert {};
236 Manager::group ledsDeAssert {};
237 Manager::group ledsUpdate {};
238
239 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
240 auto result = manager.setGroupState(group, false, ledsAssert,
241 ledsDeAssert, ledsUpdate);
242 EXPECT_EQ(false, result);
243
244 // Need just the ledsAssserted populated with these.
245 std::set<Layout::LedAction> refDeAssert = {
246 {"One",phosphor::led::Layout::Blink},
247 {"Two",phosphor::led::Layout::Blink},
248 {"Three",phosphor::led::Layout::Blink},
249 };
250 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
251 EXPECT_EQ(0, ledsAssert.size());
252 EXPECT_EQ(0, ledsUpdate.size());
253
254 // difference of refDeAssert and ledsDeAssert must be null.
255 Manager::group temp {};
256 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.
269 Manager::group ledsAssert {};
270 Manager::group ledsDeAssert {};
271 Manager::group ledsUpdate {};
272
273 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
274 auto result = manager.setGroupState(group, true, ledsAssert,
275 ledsDeAssert, ledsUpdate);
276 EXPECT_EQ(true, result);
277
278 // Need just the ledsAssserted populated with these.
279 std::set<Layout::LedAction> refAssert = {
280 {"One",phosphor::led::Layout::Blink},
281 {"Two",phosphor::led::Layout::Blink},
282 {"Three",phosphor::led::Layout::Blink},
283 };
284 EXPECT_EQ(refAssert.size(), ledsAssert.size());
285 EXPECT_EQ(0, ledsDeAssert.size());
286 EXPECT_EQ(0, ledsUpdate.size());
287
288 // difference of refAssert and ledsAssert must be null.
289 Manager::group temp {};
290 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
291 refAssert.begin(), refAssert.end(),
292 std::inserter(temp, temp.begin()));
293 EXPECT_EQ(0, temp.size());
294 }
295 {
296 // DeAssert the LEDs.
297 Manager::group ledsAssert {};
298 Manager::group ledsDeAssert {};
299 Manager::group ledsUpdate {};
300
301 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
302 auto result = manager.setGroupState(group, false, ledsAssert,
303 ledsDeAssert, ledsUpdate);
304 EXPECT_EQ(false, result);
305
306 // Need just the ledsAssserted populated with these.
307 std::set<Layout::LedAction> refDeAssert = {
308 {"One",phosphor::led::Layout::Blink},
309 {"Two",phosphor::led::Layout::Blink},
310 {"Three",phosphor::led::Layout::Blink},
311 };
312 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
313 EXPECT_EQ(0, ledsAssert.size());
314 EXPECT_EQ(0, ledsUpdate.size());
315
316 // difference of refDeAssert and ledsDeAssert must be null.
317 Manager::group temp {};
318 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
319 refDeAssert.begin(), refDeAssert.end(),
320 std::inserter(temp, temp.begin()));
321 EXPECT_EQ(0, temp.size());
322 }
323 {
324 // DeAssert the LEDs.
325 Manager::group ledsAssert {};
326 Manager::group ledsDeAssert {};
327 Manager::group ledsUpdate {};
328
329 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds";
330 auto result = manager.setGroupState(group, false, ledsAssert,
331 ledsDeAssert, ledsUpdate);
332 EXPECT_EQ(false, result);
333 EXPECT_EQ(0, ledsDeAssert.size());
334 EXPECT_EQ(0, ledsAssert.size());
335 EXPECT_EQ(0, ledsUpdate.size());
336 }
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.
345 Manager::group ledsAssert {};
346 Manager::group ledsDeAssert {};
347 Manager::group ledsUpdate {};
348
349 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsMix";
350 auto result = manager.setGroupState(group, true, ledsAssert,
351 ledsDeAssert, ledsUpdate);
352 EXPECT_EQ(true, result);
353
354 // Need just the ledsAssserted populated with these.
355 std::set<Layout::LedAction> refAssert = {
356 {"One",phosphor::led::Layout::Blink},
357 {"Two",phosphor::led::Layout::On},
358 {"Three",phosphor::led::Layout::Blink},
359 {"Four",phosphor::led::Layout::On},
360 {"Five",phosphor::led::Layout::On},
361 };
362 EXPECT_EQ(refAssert.size(), ledsAssert.size());
363 EXPECT_EQ(0, ledsDeAssert.size());
364 EXPECT_EQ(0, ledsUpdate.size());
365
366 // difference of refAssert and ledsAssert must be null.
367 Manager::group temp {};
368 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
369 refAssert.begin(), refAssert.end(),
370 std::inserter(temp, temp.begin()));
371 EXPECT_EQ(0, temp.size());
372 }
373}
374
375/** @brief Assert 2 groups having distinct LEDs */
376TEST_F(LedTest, assertTwoGroupsOnWithDistinctLEDOn)
377{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530378 Manager manager(bus, twoGroupsWithDistinctLEDsOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530379 {
380 // Assert Set-A
381 Manager::group ledsAssert {};
382 Manager::group ledsDeAssert {};
383 Manager::group ledsUpdate {};
384
385 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
386 auto result = manager.setGroupState(group, true, ledsAssert,
387 ledsDeAssert, ledsUpdate);
388 EXPECT_EQ(true, result);
389
390 // Need just the ledsAssserted populated with these.
391 std::set<Layout::LedAction> refAssert = {
392 {"One",phosphor::led::Layout::On},
393 {"Two",phosphor::led::Layout::On},
394 {"Three",phosphor::led::Layout::On},
395 };
396 EXPECT_EQ(refAssert.size(), ledsAssert.size());
397 EXPECT_EQ(0, ledsDeAssert.size());
398 EXPECT_EQ(0, ledsUpdate.size());
399
400 // difference of refAssert and ledsAssert must be null.
401 Manager::group temp {};
402 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
403 refAssert.begin(), refAssert.end(),
404 std::inserter(temp, temp.begin()));
405 EXPECT_EQ(0, temp.size());
406 }
407 {
408 // Assert Set-B
409 Manager::group ledsAssert {};
410 Manager::group ledsDeAssert {};
411 Manager::group ledsUpdate {};
412
413 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
414 auto result = manager.setGroupState(group, true, ledsAssert,
415 ledsDeAssert, ledsUpdate);
416 EXPECT_EQ(true, result);
417
418 // Need just the ledsAssserted populated with these.
419 std::set<Layout::LedAction> refAssert = {
420 {"Four",phosphor::led::Layout::On},
421 {"Five",phosphor::led::Layout::On},
422 {"Six",phosphor::led::Layout::On},
423 };
424 EXPECT_EQ(refAssert.size(), ledsAssert.size());
425 EXPECT_EQ(0, ledsDeAssert.size());
426 EXPECT_EQ(0, ledsUpdate.size());
427
428 // difference of refAssert and ledsAssert must be null.
429 Manager::group temp {};
430 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
431 refAssert.begin(), refAssert.end(),
432 std::inserter(temp, temp.begin()));
433 EXPECT_EQ(0, temp.size());
434 }
435}
436
437/** @brief Assert 2 groups having one of the LEDs common */
438TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOn)
439{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530440 Manager manager(bus, twoGroupsWithOneComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530441 {
442 // Assert Set-A
443 Manager::group ledsAssert {};
444 Manager::group ledsDeAssert {};
445 Manager::group ledsUpdate {};
446
447 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
448 auto result = manager.setGroupState(group, true, ledsAssert,
449 ledsDeAssert, ledsUpdate);
450 EXPECT_EQ(true, result);
451
452 // Need just the ledsAssserted populated with these.
453 std::set<Layout::LedAction> refAssert = {
454 {"One",phosphor::led::Layout::On},
455 {"Two",phosphor::led::Layout::On},
456 {"Three",phosphor::led::Layout::On},
457 };
458 EXPECT_EQ(refAssert.size(), ledsAssert.size());
459 EXPECT_EQ(0, ledsDeAssert.size());
460 EXPECT_EQ(0, ledsUpdate.size());
461
462 // difference of refAssert and ledsAssert must be null.
463 Manager::group temp {};
464 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
465 refAssert.begin(), refAssert.end(),
466 std::inserter(temp, temp.begin()));
467 EXPECT_EQ(0, temp.size());
468 }
469 {
470 // Assert Set-B
471 Manager::group ledsAssert {};
472 Manager::group ledsDeAssert {};
473 Manager::group ledsUpdate {};
474
475 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
476 auto result = manager.setGroupState(group, true, ledsAssert,
477 ledsDeAssert, ledsUpdate);
478 EXPECT_EQ(true, result);
479
480 // Need just the ledsAssserted populated with these.
481 std::set<Layout::LedAction> refAssert = {
482 {"Four",phosphor::led::Layout::On},
483 {"Six",phosphor::led::Layout::On},
484 };
485 EXPECT_EQ(refAssert.size(), ledsAssert.size());
486 EXPECT_EQ(0, ledsDeAssert.size());
487 EXPECT_EQ(0, ledsUpdate.size());
488
489 // difference of refAssert and ledsAssert must be null.
490 Manager::group temp {};
491 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
498/** @brief Assert 2 groups having one of the LEDs common in different state */
499TEST_F(LedTest, assertTwoGroupsWithOneComonLEDInDifferentState)
500{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530501 Manager manager(bus, twoGroupsWithOneComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530502 {
503 // Assert Set-A
504 Manager::group ledsAssert {};
505 Manager::group ledsDeAssert {};
506 Manager::group ledsUpdate {};
507
508 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
509 auto result = manager.setGroupState(group, true, ledsAssert,
510 ledsDeAssert, ledsUpdate);
511 EXPECT_EQ(true, result);
512
513 // Need just the ledsAssserted populated with these.
514 std::set<Layout::LedAction> refAssert = {
515 {"One",phosphor::led::Layout::On},
516 {"Two",phosphor::led::Layout::On},
517 {"Three",phosphor::led::Layout::On},
518 };
519 EXPECT_EQ(refAssert.size(), ledsAssert.size());
520 EXPECT_EQ(0, ledsDeAssert.size());
521 EXPECT_EQ(0, ledsUpdate.size());
522
523 // difference of refAssert and ledsAssert must be null.
524 Manager::group temp {};
525 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
532 Manager::group ledsAssert {};
533 Manager::group ledsDeAssert {};
534 Manager::group ledsUpdate {};
535
536 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
537 auto result = manager.setGroupState(group, true, ledsAssert,
538 ledsDeAssert, ledsUpdate);
539 EXPECT_EQ(true, result);
540
541 // Need just the ledsAssserted populated with these.
542 std::set<Layout::LedAction> refAssert = {
543 {"Two",phosphor::led::Layout::Blink},
544 {"Four",phosphor::led::Layout::On},
545 {"Five",phosphor::led::Layout::On},
546 {"Six",phosphor::led::Layout::On},
547 };
548 EXPECT_EQ(refAssert.size(), ledsAssert.size());
549 EXPECT_EQ(0, ledsDeAssert.size());
550 EXPECT_EQ(0, ledsUpdate.size());
551
552 // difference of refAssert and ledsAssert must be null.
553 Manager::group temp {};
554 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
555 refAssert.begin(), refAssert.end(),
556 std::inserter(temp, temp.begin()));
557 EXPECT_EQ(0, temp.size());
558 }
559}
560
561/** @brief Assert 2 groups having multiple common LEDs in Same State */
562TEST_F(LedTest, assertTwoGroupsWithMultiplComonLEDOn)
563{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530564 Manager manager(bus, twoGroupsWithMultiplComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530565 {
566 // Assert Set-B
567 Manager::group ledsAssert {};
568 Manager::group ledsDeAssert {};
569 Manager::group ledsUpdate {};
570
571 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
572 auto result = manager.setGroupState(group, true, ledsAssert,
573 ledsDeAssert, ledsUpdate);
574 EXPECT_EQ(true, result);
575
576 // Need just the ledsAssserted populated with these.
577 std::set<Layout::LedAction> refAssert = {
578 {"Two",phosphor::led::Layout::On},
579 {"Six",phosphor::led::Layout::On},
580 {"Three",phosphor::led::Layout::On},
581 {"Seven",phosphor::led::Layout::On},
582 };
583 EXPECT_EQ(refAssert.size(), ledsAssert.size());
584 EXPECT_EQ(0, ledsDeAssert.size());
585 EXPECT_EQ(0, ledsUpdate.size());
586
587 // difference of refAssert and ledsAssert must be null.
588 Manager::group temp {};
589 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
590 refAssert.begin(), refAssert.end(),
591 std::inserter(temp, temp.begin()));
592 EXPECT_EQ(0, temp.size());
593 }
594 {
595 // Assert Set-A
596 Manager::group ledsAssert {};
597 Manager::group ledsDeAssert {};
598 Manager::group ledsUpdate {};
599
600 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
601 auto result = manager.setGroupState(group, true, ledsAssert,
602 ledsDeAssert, ledsUpdate);
603 EXPECT_EQ(true, result);
604
605 // Need just the ledsAssserted populated with these.
606 std::set<Layout::LedAction> refAssert = {
607 {"One",phosphor::led::Layout::On},
608 };
609 EXPECT_EQ(refAssert.size(), ledsAssert.size());
610 EXPECT_EQ(0, ledsDeAssert.size());
611 EXPECT_EQ(0, ledsUpdate.size());
612
613 // difference of refAssert and ledsAssert must be null.
614 Manager::group temp {};
615 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
616 refAssert.begin(), refAssert.end(),
617 std::inserter(temp, temp.begin()));
618 EXPECT_EQ(0, temp.size());
619 }
620}
621
622/** @brief Assert 2 groups having multiple LEDs common in different state */
623TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStates)
624{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530625 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530626 {
627 // Assert Set-A
628 Manager::group ledsAssert {};
629 Manager::group ledsDeAssert {};
630 Manager::group ledsUpdate {};
631
632 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
633 auto result = manager.setGroupState(group, true, ledsAssert,
634 ledsDeAssert, ledsUpdate);
635 EXPECT_EQ(true, result);
636
637 // Need just the ledsAssserted populated with these.
638 std::set<Layout::LedAction> refAssert = {
639 {"One",phosphor::led::Layout::On},
640 {"Two",phosphor::led::Layout::Blink},
641 {"Three",phosphor::led::Layout::On},
642 {"Four",phosphor::led::Layout::On},
643 };
644 EXPECT_EQ(refAssert.size(), ledsAssert.size());
645 EXPECT_EQ(0, ledsDeAssert.size());
646 EXPECT_EQ(0, ledsUpdate.size());
647
648 // difference of refAssert and ledsAssert must be null.
649 Manager::group temp {};
650 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
651 refAssert.begin(), refAssert.end(),
652 std::inserter(temp, temp.begin()));
653 EXPECT_EQ(0, temp.size());
654 }
655 {
656 // Assert Set-B
657 Manager::group ledsAssert {};
658 Manager::group ledsDeAssert {};
659 Manager::group ledsUpdate {};
660
661 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
662 auto result = manager.setGroupState(group, true, ledsAssert,
663 ledsDeAssert, ledsUpdate);
664 EXPECT_EQ(true, result);
665
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +0530666 // Need just the ledsAssserted populated with these.'Two' gets to Blink
667 // due to higher priority.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530668 std::set<Layout::LedAction> refAssert = {
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +0530669 {"Two",phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530670 {"Three",phosphor::led::Layout::Blink},
671 {"Five",phosphor::led::Layout::On},
672 {"Six",phosphor::led::Layout::On},
673 };
674 EXPECT_EQ(refAssert.size(), ledsAssert.size());
675 EXPECT_EQ(0, ledsDeAssert.size());
676 EXPECT_EQ(0, ledsUpdate.size());
677
678 // difference of refAssert and ledsAssert must be null.
679 Manager::group temp {};
680 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
681 refAssert.begin(), refAssert.end(),
682 std::inserter(temp, temp.begin()));
683 EXPECT_EQ(0, temp.size());
684 }
685}
686
687/** @brief Assert 2 groups having multiple LEDs common in Same State
688 * and then De-Assert One
689 */
690TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDAndDeAssertOne)
691{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530692 Manager manager(bus, twoGroupsWithMultiplComonLEDOn);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530693 {
694 // Assert Set-A
695 Manager::group ledsAssert {};
696 Manager::group ledsDeAssert {};
697 Manager::group ledsUpdate {};
698
699 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
700 auto result = manager.setGroupState(group, true, ledsAssert,
701 ledsDeAssert, ledsUpdate);
702 EXPECT_EQ(true, result);
703
704 // Need just the ledsAssserted populated with these.
705 std::set<Layout::LedAction> refAssert = {
706 {"One",phosphor::led::Layout::On},
707 {"Two",phosphor::led::Layout::On},
708 {"Three",phosphor::led::Layout::On},
709 };
710 EXPECT_EQ(refAssert.size(), ledsAssert.size());
711 EXPECT_EQ(0, ledsDeAssert.size());
712 EXPECT_EQ(0, ledsUpdate.size());
713
714 // difference of refAssert and ledsAssert must be null.
715 Manager::group temp {};
716 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
717 refAssert.begin(), refAssert.end(),
718 std::inserter(temp, temp.begin()));
719 EXPECT_EQ(0, temp.size());
720 }
721 {
722 // Assert Set-B
723 Manager::group ledsAssert {};
724 Manager::group ledsDeAssert {};
725 Manager::group ledsUpdate {};
726
727 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
728 auto result = manager.setGroupState(group, true, ledsAssert,
729 ledsDeAssert, ledsUpdate);
730 EXPECT_EQ(true, result);
731
732 // Need just the ledsAssserted populated with these.
733 std::set<Layout::LedAction> refAssert = {
734 {"Six",phosphor::led::Layout::On},
735 {"Seven",phosphor::led::Layout::On},
736 };
737 EXPECT_EQ(refAssert.size(), ledsAssert.size());
738 EXPECT_EQ(0, ledsDeAssert.size());
739 EXPECT_EQ(0, ledsUpdate.size());
740
741 // difference of refAssert and ledsAssert must be null.
742 Manager::group temp {};
743 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
744 refAssert.begin(), refAssert.end(),
745 std::inserter(temp, temp.begin()));
746 EXPECT_EQ(0, temp.size());
747 }
748 {
749 // DeAssert Set-A
750 Manager::group ledsAssert {};
751 Manager::group ledsDeAssert {};
752 Manager::group ledsUpdate {};
753
754 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
755 auto result = manager.setGroupState(group, false, ledsAssert,
756 ledsDeAssert, ledsUpdate);
757 EXPECT_EQ(false, result);
758
759 // Need just the ledsAssserted populated with these.
760 std::set<Layout::LedAction> refDeAssert = {
761 {"One",phosphor::led::Layout::On},
762 };
763 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
764 EXPECT_EQ(0, ledsAssert.size());
765 EXPECT_EQ(0, ledsUpdate.size());
766
767 // difference of refAssert and ledsAssert must be null.
768 Manager::group temp {};
769 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
770 refDeAssert.begin(), refDeAssert.end(),
771 std::inserter(temp, temp.begin()));
772 EXPECT_EQ(0, temp.size());
773 }
774}
775
776/** @brief Assert 2 groups having multiple LEDs common but in
777 * different state and De-Assert one*/
778TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateDeAssertOne)
779{
Vishwanatha Subbanna11ca8f92017-02-27 19:33:45 +0530780 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState);
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530781 {
782 // Assert Set-B
783 Manager::group ledsAssert {};
784 Manager::group ledsDeAssert {};
785 Manager::group ledsUpdate {};
786
787 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
788 auto result = manager.setGroupState(group, true, ledsAssert,
789 ledsDeAssert, ledsUpdate);
790 EXPECT_EQ(true, result);
791
792 // Need just the ledsAssserted populated with these.
793 std::set<Layout::LedAction> refAssert = {
794 {"Two",phosphor::led::Layout::On},
795 {"Three",phosphor::led::Layout::Blink},
796 {"Five",phosphor::led::Layout::On},
797 {"Six",phosphor::led::Layout::On},
798 };
799 EXPECT_EQ(refAssert.size(), ledsAssert.size());
800 EXPECT_EQ(0, ledsDeAssert.size());
801 EXPECT_EQ(0, ledsUpdate.size());
802
803 // difference of refAssert and ledsAssert must be null.
804 Manager::group temp {};
805 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
806 refAssert.begin(), refAssert.end(),
807 std::inserter(temp, temp.begin()));
808 EXPECT_EQ(0, temp.size());
809 }
810 {
811 // Assert Set-A
812 Manager::group ledsAssert {};
813 Manager::group ledsDeAssert {};
814 Manager::group ledsUpdate {};
815
816 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
817 auto result = manager.setGroupState(group, true, ledsAssert,
818 ledsDeAssert, ledsUpdate);
819 EXPECT_EQ(true, result);
820
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +0530821 // Need just the ledsAssserted populated with these. 'Three` remains at
822 // Blink due to increased priority.
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530823 std::set<Layout::LedAction> refAssert = {
824 {"One",phosphor::led::Layout::On},
825 {"Two",phosphor::led::Layout::Blink},
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +0530826 {"Three",phosphor::led::Layout::Blink},
Vishwanatha Subbannaed490732016-12-20 15:59:29 +0530827 {"Four",phosphor::led::Layout::On},
828 };
829 EXPECT_EQ(refAssert.size(), ledsAssert.size());
830 EXPECT_EQ(0, ledsDeAssert.size());
831 EXPECT_EQ(0, ledsUpdate.size());
832
833 // difference of refAssert and ledsAssert must be null.
834 Manager::group temp {};
835 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
836 refAssert.begin(), refAssert.end(),
837 std::inserter(temp, temp.begin()));
838 EXPECT_EQ(0, temp.size());
839 }
840 {
841 // DeAssert Set-A
842 Manager::group ledsAssert {};
843 Manager::group ledsDeAssert {};
844 Manager::group ledsUpdate {};
845
846 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
847 auto result = manager.setGroupState(group, false, ledsAssert,
848 ledsDeAssert, ledsUpdate);
849 EXPECT_EQ(false, result);
850
851 // Need just the ledsUpdated populated with these.
852 std::set<Layout::LedAction> refUpdate = {
853 {"Two",phosphor::led::Layout::On},
854 {"Three",phosphor::led::Layout::Blink},
855 };
856 EXPECT_EQ(refUpdate.size(), ledsUpdate.size());
857 EXPECT_EQ(0, ledsAssert.size());
858
859 // difference of refAssert and ledsAssert must be null.
860 Manager::group temp {};
861 std::set_difference(ledsUpdate.begin(), ledsUpdate.end(),
862 refUpdate.begin(), refUpdate.end(),
863 std::inserter(temp, temp.begin()));
864 EXPECT_EQ(0, temp.size());
865
866 // Need just the ledsDeAsserted populated with these.
867 std::set<Layout::LedAction> refDeAssert = {
868 {"One",phosphor::led::Layout::On},
869 {"Four",phosphor::led::Layout::On},
870 };
871 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
872
873 // difference of refAssert and ledsAssert must be null.
874 temp.clear();
875 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
876 refDeAssert.begin(), refDeAssert.end(),
877 std::inserter(temp, temp.begin()));
878 EXPECT_EQ(0, temp.size());
879 }
880}
Vishwanatha Subbannacd569d22017-05-03 12:46:14 +0530881
882/** @brief Assert 2 groups having multiple LEDs common but in
883 * different state and De-Assert one and make sure the
884 * state is changed back to Blink
885 */
886TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateDeAssertOneGetBlink)
887{
888 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentStateBlinkAgain);
889 {
890 // Assert Set-B
891 Manager::group ledsAssert {};
892 Manager::group ledsDeAssert {};
893 Manager::group ledsUpdate {};
894
895 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet";
896 auto result = manager.setGroupState(group, true, ledsAssert,
897 ledsDeAssert, ledsUpdate);
898 EXPECT_EQ(true, result);
899
900 // Need just the ledsAssserted populated with these.
901 std::set<Layout::LedAction> refAssert = {
902 {"Two",phosphor::led::Layout::Blink},
903 {"Three",phosphor::led::Layout::Blink},
904 {"Five",phosphor::led::Layout::On},
905 {"Six",phosphor::led::Layout::On},
906 };
907 EXPECT_EQ(refAssert.size(), ledsAssert.size());
908 EXPECT_EQ(0, ledsDeAssert.size());
909 EXPECT_EQ(0, ledsUpdate.size());
910
911 // difference of refAssert and ledsAssert must be null.
912 Manager::group temp {};
913 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
914 refAssert.begin(), refAssert.end(),
915 std::inserter(temp, temp.begin()));
916 EXPECT_EQ(0, temp.size());
917 }
918 {
919 // Assert Set-A
920 Manager::group ledsAssert {};
921 Manager::group ledsDeAssert {};
922 Manager::group ledsUpdate {};
923
924 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
925 auto result = manager.setGroupState(group, true, ledsAssert,
926 ledsDeAssert, ledsUpdate);
927 EXPECT_EQ(true, result);
928
929 // Need just the ledsAssserted populated with these. 'Three` remains at
930 // Blink due to increased priority. Two is already in asserted state and
931 // it wont be asserted again.
932 std::set<Layout::LedAction> refAssert = {
933 {"One",phosphor::led::Layout::On},
934 {"Three",phosphor::led::Layout::Blink},
935 {"Four",phosphor::led::Layout::On},
936 };
937 EXPECT_EQ(refAssert.size(), ledsAssert.size());
938 EXPECT_EQ(0, ledsDeAssert.size());
939 EXPECT_EQ(0, ledsUpdate.size());
940
941 // difference of refAssert and ledsAssert must be null.
942 Manager::group temp {};
943 std::set_difference(ledsAssert.begin(), ledsAssert.end(),
944 refAssert.begin(), refAssert.end(),
945 std::inserter(temp, temp.begin()));
946 EXPECT_EQ(0, temp.size());
947 }
948 {
949 // DeAssert Set-A
950 Manager::group ledsAssert {};
951 Manager::group ledsDeAssert {};
952 Manager::group ledsUpdate {};
953
954 auto group ="/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet";
955 auto result = manager.setGroupState(group, false, ledsAssert,
956 ledsDeAssert, ledsUpdate);
957 EXPECT_EQ(false, result);
958
959 // Need just the ledsUpdated populated with these.
960 std::set<Layout::LedAction> refUpdate = {
961 {"Three",phosphor::led::Layout::Blink},
962 };
963 EXPECT_EQ(refUpdate.size(), ledsUpdate.size());
964 EXPECT_EQ(0, ledsAssert.size());
965
966 // difference of refAssert and ledsAssert must be null.
967 Manager::group temp {};
968 std::set_difference(ledsUpdate.begin(), ledsUpdate.end(),
969 refUpdate.begin(), refUpdate.end(),
970 std::inserter(temp, temp.begin()));
971 EXPECT_EQ(0, temp.size());
972
973 // Need just the ledsDeAsserted populated with these.
974 std::set<Layout::LedAction> refDeAssert = {
975 {"One",phosphor::led::Layout::On},
976 {"Four",phosphor::led::Layout::On},
977 };
978 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size());
979
980 // difference of refAssert and ledsAssert must be null.
981 temp.clear();
982 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(),
983 refDeAssert.begin(), refDeAssert.end(),
984 std::inserter(temp, temp.begin()));
985 EXPECT_EQ(0, temp.size());
986 }
987}