From 6955d48858150ba9e63a4dd36ef1f206af473bec Mon Sep 17 00:00:00 2001 From: Prince George Date: Wed, 6 Nov 2024 20:11:33 +0000 Subject: [PATCH] Fix build error Signed-off-by: Prince George --- orchagent/portsorch.cpp | 5 +- tests/mock_tests/portsorch_ut.cpp | 113 ++++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 33 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index 1602c5a377..2ce9b31b6f 100644 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -8081,6 +8081,7 @@ void PortsOrch::doTask(NotificationConsumer &consumer) for (uint32_t i = 0; i < count; i++) { + Port port; sai_object_id_t id = portoperstatus[i].port_id; sai_port_oper_status_t status = portoperstatus[i].port_state; sai_port_error_status_t port_oper_err = portoperstatus[i].port_error_status; @@ -8089,10 +8090,6 @@ void PortsOrch::doTask(NotificationConsumer &consumer) "oper_error_status:0x%" PRIx32, id, status, port_oper_err); - //port_oper_err = static_cast(SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT | SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT); - - Port port; - if (!getPort(id, port)) { SWSS_LOG_NOTICE("Got port state change for port id 0x%" PRIx64 " which does not exist, possibly outdated event", id); diff --git a/tests/mock_tests/portsorch_ut.cpp b/tests/mock_tests/portsorch_ut.cpp index a511b81972..0d698b8451 100644 --- a/tests/mock_tests/portsorch_ut.cpp +++ b/tests/mock_tests/portsorch_ut.cpp @@ -710,23 +710,39 @@ namespace portsorch_test Port port; gPortsOrch->getPort("Ethernet0", port); ASSERT_TRUE(port.m_oper_status != SAI_PORT_OPER_STATUS_UP); - ASSERT_TRUE(port.m_oper_error_status == SAI_PORT_ERROR_STATUS_CLEAR); + ASSERT_TRUE(port.m_flap_count == 0); auto exec = static_cast(gPortsOrch->getExecutor("PORT_STATUS_NOTIFICATIONS")); auto consumer = exec->getNotificationConsumer(); std::vector errors = { - SAI_PORT_ERROR_STATUS_CLEAR, SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT, - SAI_PORT_ERROR_STATUS_CLEAR, SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT, - SAI_PORT_ERROR_STATUS_CLEAR, - SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT | SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT + static_cast( + SAI_PORT_ERROR_STATUS_FEC_SYNC_LOSS | + SAI_PORT_ERROR_STATUS_MAC_LOCAL_FAULT), + static_cast( + SAI_PORT_ERROR_STATUS_FEC_LOSS_ALIGNMENT_MARKER | + SAI_PORT_ERROR_STATUS_HIGH_SER | + SAI_PORT_ERROR_STATUS_HIGH_BER | + SAI_PORT_ERROR_STATUS_CRC_RATE), + SAI_PORT_ERROR_STATUS_DATA_UNIT_CRC_ERROR, + static_cast( + SAI_PORT_ERROR_STATUS_FEC_SYNC_LOSS | + SAI_PORT_ERROR_STATUS_DATA_UNIT_SIZE | + SAI_PORT_ERROR_STATUS_DATA_UNIT_MISALIGNMENT_ERROR), + static_cast( + SAI_PORT_ERROR_STATUS_CODE_GROUP_ERROR | + SAI_PORT_ERROR_STATUS_SIGNAL_LOCAL_ERROR | + SAI_PORT_ERROR_STATUS_NO_RX_REACHABILITY), + static_cast( + SAI_PORT_ERROR_STATUS_FEC_SYNC_LOSS | + SAI_PORT_ERROR_STATUS_MAC_REMOTE_FAULT) }; // mock a redis reply for notification, it notifies that Ehernet0 is going to up - for (uint32_t count=0; count < 6; count++) { - sai_port_oper_status_t oper_status = (count % 2 == 0) ? SAI_PORT_OPER_STATUS_UP : SAI_PORT_OPER_STATUS_DOWN; + for (uint32_t count=0; count < errors.size(); count++) { + sai_port_oper_status_t oper_status = SAI_PORT_OPER_STATUS_DOWN; mockReply = (redisReply *)calloc(sizeof(redisReply), 1); mockReply->type = REDIS_REPLY_ARRAY; mockReply->elements = 3; // REDIS_PUBLISH_MESSAGE_ELEMNTS @@ -734,7 +750,8 @@ namespace portsorch_test mockReply->element[2] = (redisReply *)calloc(sizeof(redisReply), 1); mockReply->element[2]->type = REDIS_REPLY_STRING; sai_port_oper_status_notification_t port_oper_status; - port_oper_status.port_error_status = errors[count] + memset(&port_oper_status, 0, sizeof(port_oper_status)); + port_oper_status.port_error_status = errors[count]; port_oper_status.port_state = oper_status; port_oper_status.port_id = port.m_port_id; std::string data = sai_serialize_port_oper_status_ntf(1, &port_oper_status); @@ -749,33 +766,71 @@ namespace portsorch_test consumer->readData(); gPortsOrch->doTask(*consumer); mockReply = nullptr; - gPortsOrch->getPort("Ethernet0", port); - ASSERT_TRUE(port.m_oper_status == oper_status); - if (port.m_oper_status == SAI_PORT_OPER_STATUS_UP) + gPortsOrch->updatePortErrorStatus(port, errors[count]); + ASSERT_TRUE(port.m_oper_error_status == errors[count]); + } + + std::vector values; + portTableOpErrState.get("Ethernet0", values); + + for (auto &valueTuple : values) + { + if (fvField(valueTuple) == "mac_local_fault_count") { - ASSERT_TRUE(port.m_oper_error_status == SAI_PORT_ERROR_STATUS_CLEAR); + ASSERT_TRUE(fvValue(valueTuple) == "2"); } - else + else if (fvField(valueTuple) == "mac_remote_fault_count") { - ASSERT_TRUE(port.m_oper_error_status == errors[count]); + ASSERT_TRUE(fvValue(valueTuple) == "2"); } - std::vector values; - statePortTable.get("Ethernet0", values); - for (auto &valueTuple : values) + else if (fvField(valueTuple) == "oper_error_status") { - if (fvField(valueTuple) == "mac_local_fault_count") - { - ASSERT_TRUE(fvValue(valueTuple) == 3); - } - else if (fvField(valueTuple) == "mac_remote_fault_count") - { - ASSERT_TRUE(fvValue(valueTuple) == 2); - } - else if (fvField(valueTuple) == "oper_error_status") - { - ASSERT_TRUE(fvValue(valueTuple) == 0x3); - } + ASSERT_TRUE(fvValue(valueTuple) == "3"); + } + else if (fvField(valueTuple) == "fec_sync_loss_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "3"); + } + else if (fvField(valueTuple) == "fec_alignment_loss_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "high_ser_error_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "high ber_error_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "crc_rate_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "data_unit_crc_error_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "data_unit_size_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "data_unit_misalignment_error_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "code_group_error_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "signal_local_error_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); + } + else if (fvField(valueTuple) == "no_rx_reachability_count") + { + ASSERT_TRUE(fvValue(valueTuple) == "1"); } }