1 #include "led-test-map.hpp" 2 #include "manager.hpp" 3 4 #include <sdbusplus/bus.hpp> 5 6 #include <algorithm> 7 #include <set> 8 9 #include <gtest/gtest.h> 10 using namespace phosphor::led; 11 class LedTest : public ::testing::Test 12 { 13 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 } 23 }; 24 25 /** @brief Assert Single LED to On */ 26 TEST_F(LedTest, assertSingleLedOn) 27 { 28 Manager manager(bus, singleLedOn); 29 { 30 // Assert the LEDs. 31 Manager::group ledsAssert{}; 32 Manager::group ledsDeAssert{}; 33 34 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed"; 35 auto result = 36 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 37 EXPECT_EQ(true, result); 38 39 // Need just the ledsAssserted populated with these. 40 std::set<Layout::LedAction> refAssert = { 41 {"One", phosphor::led::Layout::On, 0, 0, 42 phosphor::led::Layout::Blink}, 43 }; 44 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 45 EXPECT_EQ(0, ledsDeAssert.size()); 46 47 // difference of refAssert and ledsAssert must be null. 48 Manager::group temp{}; 49 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 */ 57 TEST_F(LedTest, assertSingleLedBlink) 58 { 59 Manager manager(bus, singleLedBlink); 60 { 61 // Assert the LEDs. 62 Manager::group ledsAssert{}; 63 Manager::group ledsDeAssert{}; 64 65 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed"; 66 auto result = 67 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 68 EXPECT_EQ(true, result); 69 70 // Need just the ledsAssserted populated with these. 71 std::set<Layout::LedAction> refAssert = { 72 {"One", phosphor::led::Layout::Blink, 0, 0, 73 phosphor::led::Layout::Blink}, 74 }; 75 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 76 EXPECT_EQ(0, ledsDeAssert.size()); 77 78 // difference of refAssert and ledsAssert must be null. 79 Manager::group temp{}; 80 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 */ 88 TEST_F(LedTest, assertSingleLedOnAndreAssert) 89 { 90 Manager manager(bus, singleLedOn); 91 { 92 // Assert the LEDs. 93 Manager::group ledsAssert{}; 94 Manager::group ledsDeAssert{}; 95 96 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed"; 97 auto result = 98 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 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, 0, 0, 104 phosphor::led::Layout::Blink}, 105 }; 106 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 107 EXPECT_EQ(0, ledsDeAssert.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 121 auto group = "/xyz/openbmc_project/ledmanager/groups/SingleLed"; 122 auto result = 123 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 124 EXPECT_EQ(true, result); 125 126 EXPECT_EQ(0, ledsAssert.size()); 127 EXPECT_EQ(0, ledsDeAssert.size()); 128 } 129 } 130 131 /** @brief Assert Multiple LEDs to On */ 132 TEST_F(LedTest, assertMultipleLedOn) 133 { 134 Manager manager(bus, multipleLedsOn); 135 { 136 // Assert the LEDs. 137 Manager::group ledsAssert{}; 138 Manager::group ledsDeAssert{}; 139 140 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds"; 141 auto result = 142 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 143 EXPECT_EQ(true, result); 144 145 // Need just the ledsAssserted populated with these. 146 std::set<Layout::LedAction> refAssert = { 147 {"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}, 151 }; 152 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 153 EXPECT_EQ(0, ledsDeAssert.size()); 154 155 // difference of refAssert and ledsAssert must be null. 156 Manager::group temp{}; 157 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 */ 165 TEST_F(LedTest, assertMultipleLedBlink) 166 { 167 Manager manager(bus, multipleLedsBlink); 168 { 169 // Assert the LEDs. 170 Manager::group ledsAssert{}; 171 Manager::group ledsDeAssert{}; 172 173 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds"; 174 auto result = 175 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 176 EXPECT_EQ(true, result); 177 178 // Need just the ledsAssserted populated with these. 179 std::set<Layout::LedAction> refAssert = { 180 {"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}, 186 }; 187 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 188 EXPECT_EQ(0, ledsDeAssert.size()); 189 190 // difference of refAssert and ledsAssert must be null. 191 Manager::group temp{}; 192 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 */ 200 TEST_F(LedTest, assertMultipleLedBlinkAndDeAssert) 201 { 202 Manager manager(bus, multipleLedsBlink); 203 { 204 // Assert the LEDs. 205 Manager::group ledsAssert{}; 206 Manager::group ledsDeAssert{}; 207 208 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds"; 209 auto result = 210 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 211 EXPECT_EQ(true, result); 212 213 // Need just the ledsAssserted populated with these. 214 std::set<Layout::LedAction> refAssert = { 215 {"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}, 221 }; 222 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 223 EXPECT_EQ(0, ledsDeAssert.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 237 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds"; 238 auto result = 239 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 240 EXPECT_EQ(false, result); 241 242 // Need just the ledsAssserted populated with these. 243 std::set<Layout::LedAction> refDeAssert = { 244 {"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}, 250 }; 251 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 252 EXPECT_EQ(0, ledsAssert.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 */ 264 TEST_F(LedTest, assertMultipleLedBlinkAndDeAssertTwice) 265 { 266 Manager manager(bus, multipleLedsBlink); 267 { 268 // Assert the LEDs. 269 Manager::group ledsAssert{}; 270 Manager::group ledsDeAssert{}; 271 272 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds"; 273 auto result = 274 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 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, 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}, 285 }; 286 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 287 EXPECT_EQ(0, ledsDeAssert.size()); 288 289 // difference of refAssert and ledsAssert must be null. 290 Manager::group temp{}; 291 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. 298 Manager::group ledsAssert{}; 299 Manager::group ledsDeAssert{}; 300 301 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds"; 302 auto result = 303 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 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, 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}, 314 }; 315 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 316 EXPECT_EQ(0, ledsAssert.size()); 317 318 // difference of refDeAssert and ledsDeAssert must be null. 319 Manager::group temp{}; 320 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. 327 Manager::group ledsAssert{}; 328 Manager::group ledsDeAssert{}; 329 330 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLeds"; 331 auto result = 332 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 333 EXPECT_EQ(false, result); 334 EXPECT_EQ(0, ledsDeAssert.size()); 335 EXPECT_EQ(0, ledsAssert.size()); 336 } 337 } 338 339 /** @brief Assert Multiple LEDs to mix of On and Blink */ 340 TEST_F(LedTest, assertMultipleLedOnAndBlink) 341 { 342 Manager manager(bus, multipleLedsOnAndBlink); 343 { 344 // Assert the LEDs. 345 Manager::group ledsAssert{}; 346 Manager::group ledsDeAssert{}; 347 348 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsMix"; 349 auto result = 350 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 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, 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}, 364 }; 365 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 366 EXPECT_EQ(0, ledsDeAssert.size()); 367 368 // difference of refAssert and ledsAssert must be null. 369 Manager::group temp{}; 370 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 */ 378 TEST_F(LedTest, assertTwoGroupsOnWithDistinctLEDOn) 379 { 380 Manager manager(bus, twoGroupsWithDistinctLEDsOn); 381 { 382 // Assert Set-A 383 Manager::group ledsAssert{}; 384 Manager::group ledsDeAssert{}; 385 386 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 387 auto result = 388 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 389 EXPECT_EQ(true, result); 390 391 // Need just the ledsAssserted populated with these. 392 std::set<Layout::LedAction> refAssert = { 393 {"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}, 398 }; 399 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 400 EXPECT_EQ(0, ledsDeAssert.size()); 401 402 // difference of refAssert and ledsAssert must be null. 403 Manager::group temp{}; 404 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 411 Manager::group ledsAssert{}; 412 Manager::group ledsDeAssert{}; 413 414 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 415 auto result = 416 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 417 EXPECT_EQ(true, result); 418 419 // Need just the ledsAssserted populated with these. 420 std::set<Layout::LedAction> refAssert = { 421 {"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}, 426 }; 427 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 428 EXPECT_EQ(0, ledsDeAssert.size()); 429 430 // difference of refAssert and ledsAssert must be null. 431 Manager::group temp{}; 432 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 */ 440 TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOn) 441 { 442 Manager manager(bus, twoGroupsWithOneComonLEDOn); 443 { 444 // Assert Set-A 445 Manager::group ledsAssert{}; 446 Manager::group ledsDeAssert{}; 447 448 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 449 auto result = 450 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 451 EXPECT_EQ(true, result); 452 453 // Need just the ledsAssserted populated with these. 454 std::set<Layout::LedAction> refAssert = { 455 {"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}, 459 }; 460 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 461 EXPECT_EQ(0, ledsDeAssert.size()); 462 463 // difference of refAssert and ledsAssert must be null. 464 Manager::group temp{}; 465 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 472 Manager::group ledsAssert{}; 473 Manager::group ledsDeAssert{}; 474 475 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 476 auto result = 477 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 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, 0, 0, 483 phosphor::led::Layout::On}, 484 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 485 }; 486 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 487 EXPECT_EQ(0, ledsDeAssert.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 but having Blink as 499 * priority and Deassert*/ 500 TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertB) 501 { 502 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority); 503 { 504 // Assert Set-A 505 Manager::group ledsAssert{}; 506 Manager::group ledsDeAssert{}; 507 508 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 509 auto result = 510 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 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, 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}, 519 }; 520 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 521 EXPECT_EQ(0, ledsDeAssert.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 535 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 536 auto result = 537 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 538 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 = { 543 {"Four", phosphor::led::Layout::On, 0, 0, 544 phosphor::led::Layout::On}, 545 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 546 }; 547 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 548 EXPECT_EQ(0, ledsDeAssert.size()); 549 550 // difference of refAssert and ledsAssert must be null. 551 Manager::group temp{}; 552 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 559 Manager::group ledsAssert{}; 560 Manager::group ledsDeAssert{}; 561 562 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 563 auto result = 564 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 565 EXPECT_EQ(false, result); 566 567 // Need just the ledsDeAssserted populated with these. 568 std::set<Layout::LedAction> refDeAssert = { 569 {"Four", phosphor::led::Layout::On, 0, 0, 570 phosphor::led::Layout::On}, 571 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 572 }; 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] 578 Manager::group temp{}; 579 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 */ 588 TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDBlinkPriorityAndDeAssertA) 589 { 590 Manager manager(bus, twoGroupsWithOneComonLEDOnOneLEDBlinkPriority); 591 { 592 // Assert Set-A 593 Manager::group ledsAssert{}; 594 Manager::group ledsDeAssert{}; 595 596 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 597 auto result = 598 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 599 EXPECT_EQ(true, result); 600 601 // Need just the ledsAssserted populated with these. 602 std::set<Layout::LedAction> refAssert = { 603 {"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}, 607 }; 608 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 609 EXPECT_EQ(0, ledsDeAssert.size()); 610 611 // difference of refAssert and ledsAssert must be null. 612 Manager::group temp{}; 613 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 } 618 { 619 // Assert Set-B 620 Manager::group ledsAssert{}; 621 Manager::group ledsDeAssert{}; 622 623 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 624 auto result = 625 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 626 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 = { 631 {"Four", phosphor::led::Layout::On, 0, 0, 632 phosphor::led::Layout::On}, 633 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 634 }; 635 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 636 EXPECT_EQ(0, ledsDeAssert.size()); 637 638 // difference of refAssert and ledsAssert must be null. 639 Manager::group temp{}; 640 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 647 Manager::group ledsAssert{}; 648 Manager::group ledsDeAssert{}; 649 650 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 651 auto result = 652 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 653 EXPECT_EQ(false, result); 654 655 // Need just the ledsDeAssserted populated with these. 656 std::set<Layout::LedAction> refDeAssert = { 657 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 658 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 659 }; 660 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 661 662 // difference of refDeAssert and ledsDeAssert must be null. 663 Manager::group temp{}; 664 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 = { 671 {"Three", phosphor::led::Layout::On, 0, 0, 672 phosphor::led::Layout::Blink}, 673 }; 674 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 675 676 // difference of refAssert and ledsAssert must be null. 677 Manager::group temp1{}; 678 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 */ 687 TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertA) 688 { 689 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority); 690 { 691 // Assert Set-A 692 Manager::group ledsAssert{}; 693 Manager::group ledsDeAssert{}; 694 695 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 696 auto result = 697 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 698 EXPECT_EQ(true, result); 699 700 // Need just the ledsAssserted populated with these. 701 std::set<Layout::LedAction> refAssert = { 702 {"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}, 706 }; 707 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 708 EXPECT_EQ(0, ledsDeAssert.size()); 709 710 // difference of refAssert and ledsAssert must be null. 711 Manager::group temp{}; 712 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 719 Manager::group ledsAssert{}; 720 Manager::group ledsDeAssert{}; 721 722 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 723 auto result = 724 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 725 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 = { 730 {"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}, 735 }; 736 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 737 EXPECT_EQ(0, ledsDeAssert.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 } 745 { 746 // De-Assert Set-A 747 Manager::group ledsAssert{}; 748 Manager::group ledsDeAssert{}; 749 750 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 751 auto result = 752 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 753 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 = { 758 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 759 {"Two", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 760 }; 761 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 762 EXPECT_EQ(0, ledsAssert.size()); 763 764 // difference of refDeAssert and ledsDeAssert must be null. 765 Manager::group temp{}; 766 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 */ 775 TEST_F(LedTest, asserttwoGroupsWithOneComonLEDOnOneLEDOnPriorityAndDeAssertB) 776 { 777 Manager manager(bus, twoGroupsWithOneComonLEDOnPriority); 778 { 779 // Assert Set-A 780 Manager::group ledsAssert{}; 781 Manager::group ledsDeAssert{}; 782 783 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 784 auto result = 785 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 786 EXPECT_EQ(true, result); 787 788 // Need just the ledsAssserted populated with these. 789 std::set<Layout::LedAction> refAssert = { 790 {"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}, 794 }; 795 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 796 EXPECT_EQ(0, ledsDeAssert.size()); 797 798 // difference of refAssert and ledsAssert must be null. 799 Manager::group temp{}; 800 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 807 Manager::group ledsAssert{}; 808 Manager::group ledsDeAssert{}; 809 810 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 811 auto result = 812 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 813 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 = { 818 {"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}, 823 }; 824 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 825 EXPECT_EQ(0, ledsDeAssert.size()); 826 827 // difference of refAssert and ledsAssert must be null. 828 Manager::group temp{}; 829 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 835 Manager::group ledsAssert{}; 836 Manager::group ledsDeAssert{}; 837 838 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 839 auto result = 840 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 841 EXPECT_EQ(false, result); 842 843 // Need just the ledsDeAssserted populated with these. 844 std::set<Layout::LedAction> refDeAssert = { 845 {"Four", phosphor::led::Layout::On, 0, 0, 846 phosphor::led::Layout::On}, 847 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 848 }; 849 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 850 851 // difference of refDeAssert and ledsDeAssert must be null. 852 Manager::group temp{}; 853 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 = { 861 {"Three", phosphor::led::Layout::Blink, 0, 0, 862 phosphor::led::Layout::On}, 863 }; 864 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 865 866 // difference of refAssert and ledsAssert must be null. 867 Manager::group temp1{}; 868 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 } 873 } 874 875 /** @brief Assert 2 groups having multiple common LEDs in Same State */ 876 TEST_F(LedTest, assertTwoGroupsWithMultiplComonLEDOnAndDeAssert) 877 { 878 Manager manager(bus, twoGroupsWithMultiplComonLEDOn); 879 { 880 // Assert Set-B 881 Manager::group ledsAssert{}; 882 Manager::group ledsDeAssert{}; 883 884 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 885 auto result = 886 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 887 EXPECT_EQ(true, result); 888 889 // Need just the ledsAssserted populated with these. 890 std::set<Layout::LedAction> refAssert = { 891 {"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}, 897 }; 898 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 899 EXPECT_EQ(0, ledsDeAssert.size()); 900 901 // difference of refAssert and ledsAssert must be null. 902 Manager::group temp{}; 903 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 910 Manager::group ledsAssert{}; 911 Manager::group ledsDeAssert{}; 912 913 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 914 auto result = 915 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 916 EXPECT_EQ(true, result); 917 918 // Need just the ledsAssserted populated with these. 919 std::set<Layout::LedAction> refAssert = { 920 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 921 }; 922 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 923 EXPECT_EQ(0, ledsDeAssert.size()); 924 925 // difference of refAssert and ledsAssert must be null. 926 Manager::group temp{}; 927 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 934 Manager::group ledsAssert{}; 935 Manager::group ledsDeAssert{}; 936 937 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 938 auto result = 939 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 940 EXPECT_EQ(false, result); 941 942 // Need just the ledsDeAssserted populated with these. 943 std::set<Layout::LedAction> refDeAssert = { 944 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 945 {"Seven", phosphor::led::Layout::On, 0, 0, 946 phosphor::led::Layout::On}, 947 }; 948 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 949 EXPECT_EQ(0, ledsAssert.size()); 950 951 // difference of refDeAssert and ledsDeAssert must be null. 952 Manager::group temp{}; 953 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(), 954 refDeAssert.begin(), refDeAssert.end(), 955 std::inserter(temp, temp.begin())); 956 EXPECT_EQ(0, temp.size()); 957 } 958 } 959 960 /** @brief Assert 2 groups having multiple LEDs common in different state */ 961 TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateBandA) 962 { 963 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState); 964 { 965 // Assert Set-B 966 Manager::group ledsAssert{}; 967 Manager::group ledsDeAssert{}; 968 969 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 970 auto result = 971 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 972 EXPECT_EQ(true, result); 973 974 // Need just the ledsAssserted populated with these. 975 std::set<Layout::LedAction> refAssert = { 976 {"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}, 982 }; 983 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 984 EXPECT_EQ(0, ledsDeAssert.size()); 985 986 // difference of refAssert and ledsAssert must be null. 987 Manager::group temp{}; 988 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 995 Manager::group ledsAssert{}; 996 Manager::group ledsDeAssert{}; 997 998 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 999 auto result = 1000 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1001 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 = { 1007 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 1008 {"Four", phosphor::led::Layout::On, 0, 0, 1009 phosphor::led::Layout::On}, 1010 }; 1011 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1012 EXPECT_EQ(0, ledsDeAssert.size()); 1013 1014 // difference of refAssert and ledsAssert must be null. 1015 Manager::group temp{}; 1016 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 */ 1024 TEST_F(LedTest, assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoB) 1025 { 1026 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState); 1027 { 1028 // Assert Set-A 1029 Manager::group ledsAssert{}; 1030 Manager::group ledsDeAssert{}; 1031 1032 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1033 auto result = 1034 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1035 EXPECT_EQ(true, result); 1036 1037 // Need just the ledsAssserted populated with these.'Two' gets to Blink 1038 // due to higher priority. 1039 std::set<Layout::LedAction> refAssert = { 1040 {"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}, 1047 }; 1048 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1049 EXPECT_EQ(0, ledsDeAssert.size()); 1050 1051 // difference of refAssert and ledsAssert must be null. 1052 Manager::group temp{}; 1053 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 1060 Manager::group ledsAssert{}; 1061 Manager::group ledsDeAssert{}; 1062 1063 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1064 auto result = 1065 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1066 EXPECT_EQ(true, result); 1067 1068 // Need just the ledsAssserted populated with these. 1069 // [Three] remains [Blink] from previous 1070 // [Two] moves to [On] from [Blink] due to [On] priority 1071 std::set<Layout::LedAction> refAssert = { 1072 {"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}, 1076 }; 1077 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1078 EXPECT_EQ(0, ledsDeAssert.size()); 1079 1080 // difference of refAssert and ledsAssert must be null. 1081 Manager::group temp{}; 1082 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 } 1087 } 1088 1089 /** @brief Assert 2 groups having multiple LEDs common in different state 1090 * DeAssert twice 1091 */ 1092 TEST_F(LedTest, 1093 assertTwoGroupsWithMultipleComonLEDInDifferentStateAtoBDeAssertTwice) 1094 { 1095 Manager manager(bus, twoGroupsWithMultipleComonLEDInDifferentState); 1096 { 1097 // Assert Set-A 1098 Manager::group ledsAssert{}; 1099 Manager::group ledsDeAssert{}; 1100 1101 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1102 auto result = 1103 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1104 EXPECT_EQ(true, result); 1105 1106 // Need just the ledsAssserted populated with these. 1107 std::set<Layout::LedAction> refAssert = { 1108 {"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}, 1115 }; 1116 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1117 EXPECT_EQ(0, ledsDeAssert.size()); 1118 1119 // difference of refAssert and ledsAssert must be null. 1120 Manager::group temp{}; 1121 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 { 1127 // Assert Set-B 1128 Manager::group ledsAssert{}; 1129 Manager::group ledsDeAssert{}; 1130 1131 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1132 auto result = 1133 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1134 EXPECT_EQ(true, result); 1135 1136 // Need just the ledsAssserted populated with these. 1137 // [Two] turns [On] due to priority 1138 // [Three] remains [Blink] 1139 std::set<Layout::LedAction> refAssert = { 1140 {"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}, 1144 }; 1145 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1146 EXPECT_EQ(0, ledsDeAssert.size()); 1147 1148 // difference of refAssert and ledsAssert must be null. 1149 Manager::group temp{}; 1150 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 { 1156 // DeAssert Set-B 1157 Manager::group ledsAssert{}; 1158 Manager::group ledsDeAssert{}; 1159 1160 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1161 auto result = 1162 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1163 EXPECT_EQ(false, result); 1164 1165 // Need just the ledsAssserted populated with these. 1166 std::set<Layout::LedAction> refDeAssert = { 1167 {"Five", phosphor::led::Layout::On, 0, 0, 1168 phosphor::led::Layout::On}, 1169 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 1170 }; 1171 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 1172 1173 // difference of refDeAssert and ledsDeAssert must be null. 1174 Manager::group temp{}; 1175 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 = { 1183 {"Two", phosphor::led::Layout::Blink, 0, 0, 1184 phosphor::led::Layout::On}, 1185 }; 1186 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1187 1188 // difference of refAssert and ledsAssert must be null. 1189 Manager::group temp1{}; 1190 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 { 1196 // DeAssert Set-A 1197 Manager::group ledsAssert{}; 1198 Manager::group ledsDeAssert{}; 1199 1200 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1201 auto result = 1202 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1203 EXPECT_EQ(false, result); 1204 1205 // Need just the ledsAssserted populated with these. 1206 std::set<Layout::LedAction> refDeAssert = { 1207 {"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}, 1214 }; 1215 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 1216 EXPECT_EQ(0, ledsAssert.size()); 1217 1218 // difference of refDeAssert and ledsDeAssert must be null. 1219 Manager::group temp{}; 1220 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 1227 Manager::group ledsAssert{}; 1228 Manager::group ledsDeAssert{}; 1229 1230 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1231 auto result = 1232 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1233 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 */ 1242 TEST_F(LedTest, 1243 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandB) 1244 { 1245 Manager manager(bus, 1246 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority); 1247 { 1248 // Assert Set-A 1249 Manager::group ledsAssert{}; 1250 Manager::group ledsDeAssert{}; 1251 1252 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1253 auto result = 1254 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1255 EXPECT_EQ(true, result); 1256 1257 // Need just the ledsAssserted populated with these. 1258 std::set<Layout::LedAction> refAssert = { 1259 {"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}, 1268 }; 1269 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1270 EXPECT_EQ(0, ledsDeAssert.size()); 1271 1272 // difference of refAssert and ledsAssert must be null. 1273 Manager::group temp{}; 1274 std::set_difference(ledsAssert.begin(), ledsAssert.end(), 1275 refAssert.begin(), refAssert.end(), 1276 std::inserter(temp, temp.begin())); 1277 EXPECT_EQ(0, temp.size()); 1278 } 1279 { 1280 // Assert Set-B 1281 Manager::group ledsAssert{}; 1282 Manager::group ledsDeAssert{}; 1283 1284 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1285 auto result = 1286 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1287 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 = { 1294 {"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}, 1298 }; 1299 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1300 EXPECT_EQ(0, ledsDeAssert.size()); 1301 1302 // difference of refAssert and ledsAssert must be null. 1303 Manager::group temp{}; 1304 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 1311 Manager::group ledsAssert{}; 1312 Manager::group ledsDeAssert{}; 1313 1314 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1315 auto result = 1316 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1317 EXPECT_EQ(false, result); 1318 1319 // Need just the ledsDeAsssert populated with these. 1320 std::set<Layout::LedAction> refDeAssert = { 1321 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 1322 {"Four", phosphor::led::Layout::On, 0, 0, 1323 phosphor::led::Layout::On}, 1324 }; 1325 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 1326 1327 // 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 = { 1332 {"Ten", phosphor::led::Layout::On, 0, 0, 1333 phosphor::led::Layout::Blink}, 1334 }; 1335 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1336 1337 // difference of refAssert and ledsAssert must be null. 1338 Manager::group temp{}; 1339 std::set_difference(ledsAssert.begin(), ledsAssert.end(), 1340 refAssert.begin(), refAssert.end(), 1341 std::inserter(temp, temp.begin())); 1342 EXPECT_EQ(0, temp.size()); 1343 } 1344 } 1345 1346 /** @brief Assert 2 groups having multiple LEDs common in different state and 1347 * mixed priority. DeAssert-B 1348 */ 1349 TEST_F( 1350 LedTest, 1351 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityAandBDeAssertB) 1352 { 1353 Manager manager(bus, 1354 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority); 1355 { 1356 // Assert Set-A 1357 Manager::group ledsAssert{}; 1358 Manager::group ledsDeAssert{}; 1359 1360 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1361 auto result = 1362 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1363 EXPECT_EQ(true, result); 1364 1365 // Need just the ledsAssserted populated with these. 1366 std::set<Layout::LedAction> refAssert = { 1367 {"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}, 1376 }; 1377 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1378 EXPECT_EQ(0, ledsDeAssert.size()); 1379 1380 // difference of refAssert and ledsAssert must be null. 1381 Manager::group temp{}; 1382 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 1389 Manager::group ledsAssert{}; 1390 Manager::group ledsDeAssert{}; 1391 1392 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1393 auto result = 1394 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1395 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 = { 1402 {"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}, 1406 }; 1407 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1408 EXPECT_EQ(0, ledsDeAssert.size()); 1409 1410 // difference of refAssert and ledsAssert must be null. 1411 Manager::group temp{}; 1412 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 1419 Manager::group ledsAssert{}; 1420 Manager::group ledsDeAssert{}; 1421 1422 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1423 auto result = 1424 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1425 EXPECT_EQ(false, result); 1426 1427 // Need just the ledsDeAsssert populated with these. 1428 std::set<Layout::LedAction> refDeAssert = { 1429 {"Five", phosphor::led::Layout::On, 0, 0, 1430 phosphor::led::Layout::On}, 1431 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 1432 }; 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 = { 1440 {"Two", phosphor::led::Layout::Blink, 0, 0, 1441 phosphor::led::Layout::On}, 1442 }; 1443 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1444 1445 // difference of refAssert and ledsAssert must be null. 1446 Manager::group temp{}; 1447 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 */ 1457 TEST_F(LedTest, 1458 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandA) 1459 { 1460 Manager manager(bus, 1461 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority); 1462 { 1463 // Assert Set-B 1464 Manager::group ledsAssert{}; 1465 Manager::group ledsDeAssert{}; 1466 1467 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1468 auto result = 1469 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1470 EXPECT_EQ(true, result); 1471 1472 // Need just the ledsAssserted populated with these. 1473 std::set<Layout::LedAction> refAssert = { 1474 {"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}, 1482 }; 1483 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1484 EXPECT_EQ(0, ledsDeAssert.size()); 1485 1486 // difference of refAssert and ledsAssert must be null. 1487 Manager::group temp{}; 1488 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 1495 Manager::group ledsAssert{}; 1496 Manager::group ledsDeAssert{}; 1497 1498 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1499 auto result = 1500 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1501 EXPECT_EQ(true, result); 1502 1503 // 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] 1507 std::set<Layout::LedAction> refAssert = { 1508 {"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}, 1513 }; 1514 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1515 EXPECT_EQ(0, ledsDeAssert.size()); 1516 1517 // difference of refAssert and ledsAssert must be null. 1518 Manager::group temp{}; 1519 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 */ 1529 TEST_F( 1530 LedTest, 1531 assertTwoGroupsWithMultipleComonLEDInDifferentStateDiffPriorityBandADeAssertA) 1532 { 1533 Manager manager(bus, 1534 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority); 1535 { 1536 // Assert Set-B 1537 Manager::group ledsAssert{}; 1538 Manager::group ledsDeAssert{}; 1539 1540 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1541 auto result = 1542 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1543 EXPECT_EQ(true, result); 1544 1545 // Need just the ledsAssserted populated with these. 1546 std::set<Layout::LedAction> refAssert = { 1547 {"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}, 1555 }; 1556 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1557 EXPECT_EQ(0, ledsDeAssert.size()); 1558 1559 // difference of refAssert and ledsAssert must be null. 1560 Manager::group temp{}; 1561 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 { 1567 // Assert Set-A 1568 Manager::group ledsAssert{}; 1569 Manager::group ledsDeAssert{}; 1570 1571 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1572 auto result = 1573 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1574 EXPECT_EQ(true, result); 1575 1576 // 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 = { 1581 {"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}, 1586 }; 1587 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1588 EXPECT_EQ(0, ledsDeAssert.size()); 1589 1590 // difference of refAssert and ledsAssert must be null. 1591 Manager::group temp{}; 1592 std::set_difference(ledsAssert.begin(), ledsAssert.end(), 1593 refAssert.begin(), refAssert.end(), 1594 std::inserter(temp, temp.begin())); 1595 EXPECT_EQ(0, temp.size()); 1596 } 1597 { 1598 // De-Assert Set-A 1599 Manager::group ledsAssert{}; 1600 Manager::group ledsDeAssert{}; 1601 1602 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1603 auto result = 1604 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1605 EXPECT_EQ(false, result); 1606 1607 // Need just the ledsAssserted populated with these. 1608 // [Ten] remains [Blink] due to priority. 1609 std::set<Layout::LedAction> refDeAssert = { 1610 {"One", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 1611 {"Four", phosphor::led::Layout::On, 0, 0, 1612 phosphor::led::Layout::On}, 1613 }; 1614 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 1615 1616 // 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 = { 1621 {"Ten", phosphor::led::Layout::On, 0, 0, 1622 phosphor::led::Layout::Blink}, 1623 }; 1624 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1625 1626 // difference of refAssert and ledsAssert must be null. 1627 Manager::group temp{}; 1628 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 */ 1638 TEST_F(LedTest, 1639 assertTwoGroupsWithMultipleComonLEDInDifferentStateOnBlinkPriorityBandA) 1640 { 1641 Manager manager(bus, 1642 twoGroupsWithMultipleComonLEDInDifferentStateDiffPriority); 1643 { 1644 // Assert Set-B 1645 Manager::group ledsAssert{}; 1646 Manager::group ledsDeAssert{}; 1647 1648 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1649 auto result = 1650 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1651 EXPECT_EQ(true, result); 1652 1653 // Need just the ledsAssserted populated with these. 1654 std::set<Layout::LedAction> refAssert = { 1655 {"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}, 1663 }; 1664 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1665 EXPECT_EQ(0, ledsDeAssert.size()); 1666 1667 // difference of refAssert and ledsAssert must be null. 1668 Manager::group temp{}; 1669 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 1676 Manager::group ledsAssert{}; 1677 Manager::group ledsDeAssert{}; 1678 1679 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1680 auto result = 1681 manager.setGroupState(group, true, ledsAssert, ledsDeAssert); 1682 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 = { 1689 {"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}, 1694 }; 1695 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1696 EXPECT_EQ(0, ledsDeAssert.size()); 1697 1698 // difference of refAssert and ledsAssert must be null. 1699 Manager::group temp{}; 1700 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 1707 Manager::group ledsAssert{}; 1708 Manager::group ledsDeAssert{}; 1709 1710 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1711 auto result = 1712 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1713 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 = { 1718 {"Five", phosphor::led::Layout::On, 0, 0, 1719 phosphor::led::Layout::On}, 1720 {"Six", phosphor::led::Layout::On, 0, 0, phosphor::led::Layout::On}, 1721 }; 1722 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 1723 1724 // difference of refDeAssert and ledsDeAssert must be null. 1725 Manager::group temp{}; 1726 std::set_difference(ledsDeAssert.begin(), ledsDeAssert.end(), 1727 refDeAssert.begin(), refDeAssert.end(), 1728 std::inserter(temp, temp.begin())); 1729 EXPECT_EQ(0, temp.size()); 1730 1731 // Need just the ledsAssert populated with these. 1732 // [Two] will move to [Blink] 1733 std::set<Layout::LedAction> refAssert = { 1734 {"Two", phosphor::led::Layout::Blink, 0, 0, 1735 phosphor::led::Layout::On}, 1736 }; 1737 EXPECT_EQ(refAssert.size(), ledsAssert.size()); 1738 1739 // difference of refAssert and ledsAssert must be null. 1740 Manager::group temp1{}; 1741 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 1748 Manager::group ledsAssert{}; 1749 Manager::group ledsDeAssert{}; 1750 1751 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsASet"; 1752 auto result = 1753 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1754 EXPECT_EQ(false, result); 1755 1756 // Need just the ledsAssserted populated with these. 1757 std::set<Layout::LedAction> refDeAssert = { 1758 {"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}, 1767 }; 1768 EXPECT_EQ(refDeAssert.size(), ledsDeAssert.size()); 1769 EXPECT_EQ(0, ledsAssert.size()); 1770 1771 // difference of refDeAssert and ledsDeAssert must be null. 1772 Manager::group temp{}; 1773 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 1780 Manager::group ledsAssert{}; 1781 Manager::group ledsDeAssert{}; 1782 1783 auto group = "/xyz/openbmc_project/ledmanager/groups/MultipleLedsBSet"; 1784 auto result = 1785 manager.setGroupState(group, false, ledsAssert, ledsDeAssert); 1786 EXPECT_EQ(false, result); 1787 EXPECT_EQ(0, ledsDeAssert.size()); 1788 EXPECT_EQ(0, ledsAssert.size()); 1789 } 1790 } 1791