Skip to content

Commit

Permalink
Fix LED Tests for multi-port platforms
Browse files Browse the repository at this point in the history
Summary:
For platforms with multiple ports on the same transceiver, we will have multiple LEDs per transceiver.

This fixes the test. Should work for single LED/port chassis too.

Reviewed By: birdsoup

Differential Revision: D64092477

fbshipit-source-id: 4489b82f8b1d83a390721a280bc6942f2fbc4158
  • Loading branch information
Mohammed Al-Sanabani authored and facebook-github-bot committed Oct 10, 2024
1 parent 36df6f5 commit 6be78d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
55 changes: 36 additions & 19 deletions fboss/led_service/hw_test/LedServiceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,21 @@ TEST_F(LedServiceTest, checkForceLed) {
}
}

void LedServiceTest::checkLedColor(PortID port, enum led::LedColor color) {
void LedServiceTest::checkLedColor(
PortID port,
enum led::LedColor color,
int testNum) {
auto portName = platformMap_->getPortNameByPortId(port);
CHECK(portName.has_value());
auto currentColor = ledManager_->getCurrentLedColor(port);
auto ledState = ledManager_->getPortLedState(portName.value());
EXPECT_EQ(currentColor, color)
<< "LED color should be " << enumToName<led::LedColor>(color)
<< " for port " << portName.value();
<< " for port " << portName.value() << " but current color is "
<< enumToName<led::LedColor>(currentColor) << " for test " << testNum;
EXPECT_EQ(ledState.currentLedState()->ledColor().value(), color)
<< "LED state should be " << enumToName<led::LedColor>(color)
<< " for port " << portName.value();
<< " for port " << portName.value() << " for test " << testNum;
// If the flags is specified, add a delay to enable seeing the LED change
sleep(FLAGS_visual_delay_sec);
}
Expand All @@ -151,11 +155,15 @@ TEST_F(LedServiceTest, checkLedColorChange) {
std::sort(transceivers.begin(), transceivers.end());

for (auto tcvr : transceivers) {
XLOG(INFO) << "Testing transceiver " << tcvr;
auto swPorts = platformMap_->getSwPortListFromTransceiverId(tcvr);
for (auto& swPort : swPorts) {
// Do the first update from FSDB to LedService. LED set to inactive.
auto maxSpeed = platformMap_->getPortMaxSpeed(swPort);
auto profile = platformMap_->getProfileIDBySpeed(swPort, maxSpeed);
XLOG(INFO) << "Testing SW Port " << swPort << " with speed "
<< enumToName<cfg::PortSpeed>(maxSpeed) << " and profile "
<< enumToName<cfg::PortProfileID>(profile);
LedManager::LedSwitchStateUpdate ledUpdate = {
static_cast<short>(swPort),
"",
Expand All @@ -170,83 +178,92 @@ TEST_F(LedServiceTest, checkLedColorChange) {
auto swPortName = platformMap_->getPortNameByPortId(swPort);
CHECK(swPortName.has_value());

int testNum = 0;
// 1- Verify Default creation with operational state = false that the
// LED color is off.
checkLedColor(swPort, led::LedColor::OFF);
checkLedColor(swPort, led::LedColor::OFF, ++testNum);

// 2- Set the operational state to true, verify that the LED color
// is not off anymore. Platform determines its own on color.
updateMap[swPort].operState = true;
ledManager_->updateLedStatus(updateMap);
auto colorBefore = ledManager_->getCurrentLedColor(swPort);
auto ledState = ledManager_->getPortLedState(swPortName.value());
EXPECT_NE(colorBefore, led::LedColor::OFF);
EXPECT_EQ(ledState.currentLedState()->ledColor().value(), colorBefore);
checkLedColor(swPort, colorBefore, ++testNum);

// If the flags is specified, add a delay before forcing LED off
// to enable seeing the LED change
// to enable visual test for the LED change
sleep(FLAGS_visual_delay_sec);

// 3- Force LED to be off. The LED color should be off.
ledManager_->setExternalLedState(
swPort, PortLedExternalState::EXTERNAL_FORCE_OFF);
checkLedColor(swPort, led::LedColor::OFF);
checkLedColor(swPort, led::LedColor::OFF, ++testNum);

// 4- Unforce LED Off. LED should go back to the previous color.
ledManager_->setExternalLedState(swPort, PortLedExternalState::NONE);
checkLedColor(swPort, colorBefore);
checkLedColor(swPort, colorBefore, ++testNum);

// 5- Force LED to be on. The LED color should not be off.
// Each platform determines its own on color.
ledManager_->setExternalLedState(
swPort, PortLedExternalState::EXTERNAL_FORCE_ON);
auto onLedColorExpected = ledManager_->forcedOnColor();
checkLedColor(swPort, onLedColorExpected);
checkLedColor(swPort, onLedColorExpected, ++testNum);

// 6- Unforce LED On. LED should go back to the previous color.
ledManager_->setExternalLedState(swPort, PortLedExternalState::NONE);
checkLedColor(swPort, colorBefore);
checkLedColor(swPort, colorBefore, ++testNum);

// 7- Set the cabling error, expect yellow LED.
updateMap[swPort].ledExternalState = PortLedExternalState::CABLING_ERROR;
ledManager_->updateLedStatus(updateMap);
checkLedColor(swPort, led::LedColor::YELLOW);
checkLedColor(swPort, led::LedColor::YELLOW, ++testNum);

// 8- Remove the cabling error, check the LED color goes back
updateMap[swPort].ledExternalState = PortLedExternalState::NONE;
ledManager_->updateLedStatus(updateMap);
checkLedColor(swPort, colorBefore);
checkLedColor(swPort, colorBefore, ++testNum);

// 9- Set the cabling error, force LED ON, check the LED color is on, and
// not yellow.
updateMap[swPort].ledExternalState = PortLedExternalState::CABLING_ERROR;
ledManager_->updateLedStatus(updateMap);
ledManager_->setExternalLedState(
swPort, PortLedExternalState::EXTERNAL_FORCE_ON);
checkLedColor(swPort, onLedColorExpected);
checkLedColor(swPort, onLedColorExpected, ++testNum);

// 10 - Remove force on, LED should go back to cabling error.
ledManager_->setExternalLedState(swPort, PortLedExternalState::NONE);
checkLedColor(swPort, led::LedColor::YELLOW);
checkLedColor(swPort, led::LedColor::YELLOW, ++testNum);

// 11- Force LED Off.
ledManager_->setExternalLedState(
swPort, PortLedExternalState::EXTERNAL_FORCE_OFF);
checkLedColor(swPort, led::LedColor::OFF);
checkLedColor(swPort, led::LedColor::OFF, ++testNum);

// 12 - Remove force off, LED should go back to cabling error.
ledManager_->setExternalLedState(swPort, PortLedExternalState::NONE);
checkLedColor(swPort, led::LedColor::YELLOW);
checkLedColor(swPort, led::LedColor::YELLOW, ++testNum);

// 13 - Remove Cabling Error, LED should go back to original color.
updateMap[swPort].ledExternalState = PortLedExternalState::NONE;
ledManager_->updateLedStatus(updateMap);
checkLedColor(swPort, colorBefore);
checkLedColor(swPort, colorBefore, ++testNum);

// 14 - Force LED Off.
ledManager_->setExternalLedState(
swPort, PortLedExternalState::EXTERNAL_FORCE_OFF);
checkLedColor(swPort, led::LedColor::OFF);
checkLedColor(swPort, led::LedColor::OFF, ++testNum);

// 15 - Remove Force Off. LED should be in original color.
ledManager_->setExternalLedState(swPort, PortLedExternalState::NONE);
checkLedColor(swPort, colorBefore, ++testNum);

// 16 - set Operational state off. Expect LED to be off.
updateMap[swPort].operState = false;
ledManager_->updateLedStatus(updateMap);
checkLedColor(swPort, led::LedColor::OFF, ++testNum);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fboss/led_service/hw_test/LedServiceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LedServiceTest : public ::testing::Test {
void SetUp() override;
void TearDown() override;
// Check the LED color.
void checkLedColor(PortID port, led::LedColor color);
void checkLedColor(PortID port, led::LedColor color, int testNum);

facebook::fboss::LedManager* ledManager_ = nullptr;
const facebook::fboss::PlatformMapping* platformMap_ = nullptr;
Expand Down

0 comments on commit 6be78d8

Please sign in to comment.