From 2ccadf4b09bdf9c24fe51d6faf79f72fd5c8eb70 Mon Sep 17 00:00:00 2001 From: dgsudharsan Date: Mon, 25 Mar 2024 21:10:51 +0000 Subject: [PATCH] Refactoring code and adding more coverage --- orchagent/portsorch.cpp | 8 ++------ tests/mock_tests/portsorch_ut.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index f528f8a74d..a910e19c71 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -7739,7 +7739,7 @@ void PortsOrch::refreshPortStatus() updateDbPortOperSpeed(port, 0); } sai_port_fec_mode_t fec_mode; - string fec_str; + string fec_str = "N/A"; if (oper_fec_sup && getPortOperFec(port, fec_mode)) { if (!m_portHlpr.fecToStr(fec_str, fec_mode)) @@ -7748,12 +7748,8 @@ void PortsOrch::refreshPortStatus() static_cast(fec_mode), port.m_alias.c_str()); fec_str = "N/A"; } - updateDbPortOperFec(port,fec_str); - } - else - { - updateDbPortOperFec(port, "N/A"); } + updateDbPortOperFec(port,fec_str); } } } diff --git a/tests/mock_tests/portsorch_ut.cpp b/tests/mock_tests/portsorch_ut.cpp index 696d862ce1..ccdbfcc365 100644 --- a/tests/mock_tests/portsorch_ut.cpp +++ b/tests/mock_tests/portsorch_ut.cpp @@ -1301,6 +1301,20 @@ namespace portsorch_test } } ASSERT_TRUE(fec_found == true); + + /*Mock an invalid fec mode with high value*/ + _sai_port_fec_mode = 100; + gPortsOrch->refreshPortStatus(); + statePortTable.get("Ethernet0", values); + fec_found = false; + for (auto &valueTuple : values) + { + if (fvField(valueTuple) == "fec") + { + fec_found = true; + ASSERT_TRUE(fvValue(valueTuple) == "N/A"); + } + } mock_port_fec_modes = old_mock_port_fec_modes; _unhook_sai_port_api(); }