Skip to content

Commit e85c87a

Browse files
Add check for empty m_priority_group_ids in initializePriorityGroupsBulk
1 parent 3ccfa62 commit e85c87a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

orchagent/portsorch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6467,6 +6467,10 @@ void PortsOrch::initializePriorityGroupsBulk(std::vector<Port>& ports)
64676467
for (size_t idx = 0; idx < portCount; idx++)
64686468
{
64696469
const auto& port = ports[idx];
6470+
if (port.m_priority_group_ids.size() == 0)
6471+
{
6472+
continue;
6473+
}
64706474
const auto status = bulker.statuses[idx];
64716475

64726476
if (status != SAI_STATUS_SUCCESS)

tests/mock_tests/portsorch_ut.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3860,6 +3860,36 @@ namespace portsorch_test
38603860
ASSERT_FALSE(bridgePortCalledBeforeLagMember); // bridge port created on lag before lag member was created
38613861
}
38623862

3863+
// Mock variables for zero priority groups test
3864+
bool mock_zero_priority_groups = false;
3865+
sai_object_id_t mock_zero_pg_port_id = 0;
3866+
3867+
sai_status_t _ut_stub_sai_get_port_attribute_zero_pg(
3868+
_In_ sai_object_id_t port_id,
3869+
_In_ uint32_t attr_count,
3870+
_Inout_ sai_attribute_t *attr_list)
3871+
{
3872+
if (attr_list != nullptr &&
3873+
mock_zero_priority_groups &&
3874+
port_id == mock_zero_pg_port_id &&
3875+
attr_count == 1 &&
3876+
attr_list[0].id == SAI_PORT_ATTR_NUMBER_OF_INGRESS_PRIORITY_GROUPS)
3877+
{
3878+
attr_list[0].value.u32 = 0; // Return 0 priority groups
3879+
return SAI_STATUS_SUCCESS;
3880+
}
3881+
return pold_sai_port_api->get_port_attribute(port_id, attr_count, attr_list);
3882+
}
3883+
3884+
void _hook_sai_port_api_zero_pg()
3885+
{
3886+
ut_sai_port_api = *sai_port_api;
3887+
pold_sai_port_api = sai_port_api;
3888+
ut_sai_port_api.get_port_attribute = _ut_stub_sai_get_port_attribute_zero_pg;
3889+
ut_sai_port_api.set_port_attribute = _ut_stub_sai_set_port_attribute;
3890+
sai_port_api = &ut_sai_port_api;
3891+
}
3892+
38633893
struct PostPortInitTests : PortsOrchTest
38643894
{
38653895
};
@@ -3907,5 +3937,36 @@ namespace portsorch_test
39073937
// Now the field "max_priority_groups" is set
39083938
stateDbSet = stateTable.hget("Ethernet0", "max_priority_groups", value);
39093939
ASSERT_TRUE(stateDbSet);
3940+
3941+
// Test case for port with zero priority groups
3942+
Port port_with_zero_pg;
3943+
Port port_with_normal_pg;
3944+
3945+
ASSERT_TRUE(gPortsOrch->getPort("Ethernet4", port_with_zero_pg));
3946+
ASSERT_TRUE(gPortsOrch->getPort("Ethernet8", port_with_normal_pg));
3947+
3948+
// Clear the priority group IDs to simulate fresh ports
3949+
port_with_zero_pg.m_priority_group_ids.clear();
3950+
port_with_normal_pg.m_priority_group_ids.clear();
3951+
3952+
// Hook SAI API to return 0 priority groups for Ethernet4 only
3953+
mock_zero_pg_port_id = port_with_zero_pg.m_port_id;
3954+
mock_zero_priority_groups = true;
3955+
_hook_sai_port_api_zero_pg();
3956+
3957+
// Create a vector with both ports to test mixed scenario and initialize in bulk
3958+
std::vector<Port> test_ports = {port_with_zero_pg, port_with_normal_pg};
3959+
ASSERT_NO_THROW(gPortsOrch->initializePriorityGroupsBulk(test_ports));
3960+
3961+
// Verify that the port with zero priority groups has empty m_priority_group_ids
3962+
ASSERT_EQ(test_ports[0].m_priority_group_ids.size(), 0);
3963+
3964+
// Verify that the port with normal priority groups has non-empty m_priority_group_ids
3965+
ASSERT_GT(test_ports[1].m_priority_group_ids.size(), 0);
3966+
3967+
// Cleanup: unhook SAI API and reset mock variables
3968+
_unhook_sai_port_api();
3969+
mock_zero_priority_groups = false;
3970+
mock_zero_pg_port_id = 0;
39103971
}
39113972
}

0 commit comments

Comments
 (0)