From d9761eb3700f5a6c68e4c0739ba718eb73ac649a Mon Sep 17 00:00:00 2001 From: Ravi Vantipalli Date: Wed, 14 Aug 2024 08:23:18 -0700 Subject: [PATCH] DLB: SaiArsProfileManager unit tests Summary: ARS profile manager unit tests Reviewed By: srikrishnagopu Differential Revision: D61067669 fbshipit-source-id: 2221bbc97e9b09786f85fae92ea7df6b41a6afb6 --- cmake/AgentHwSaiSwitchTest.cmake | 1 + .../switch/tests/ArsProfileManagerTest.cpp | 109 ++++++++++++++++++ fboss/agent/hw/sai/switch/tests/BUCK | 7 ++ 3 files changed, 117 insertions(+) create mode 100644 fboss/agent/hw/sai/switch/tests/ArsProfileManagerTest.cpp diff --git a/cmake/AgentHwSaiSwitchTest.cmake b/cmake/AgentHwSaiSwitchTest.cmake index 44fcc2e26fa4e..f38495282a922 100644 --- a/cmake/AgentHwSaiSwitchTest.cmake +++ b/cmake/AgentHwSaiSwitchTest.cmake @@ -9,6 +9,7 @@ add_executable(switch_test fboss/agent/hw/sai/switch/tests/AclTableGroupManagerTest.cpp fboss/agent/hw/sai/switch/tests/AclTableManagerTest.cpp fboss/agent/hw/sai/switch/tests/ArsManagerTest.cpp + fboss/agent/hw/sai/switch/tests/ArsProfileManagerTest.cpp fboss/agent/hw/sai/switch/tests/BridgeManagerTest.cpp fboss/agent/hw/sai/switch/tests/FdbManagerTest.cpp fboss/agent/hw/sai/switch/tests/InSegEntryManagerTest.cpp diff --git a/fboss/agent/hw/sai/switch/tests/ArsProfileManagerTest.cpp b/fboss/agent/hw/sai/switch/tests/ArsProfileManagerTest.cpp new file mode 100644 index 0000000000000..c5b690e6e3a03 --- /dev/null +++ b/fboss/agent/hw/sai/switch/tests/ArsProfileManagerTest.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2004-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + */ +#include "fboss/agent/hw/sai/switch/SaiArsProfileManager.h" +#include "fboss/agent/hw/sai/switch/tests/ManagerTestBase.h" +#include "fboss/agent/types.h" + +#include + +using namespace facebook::fboss; + +class ArsProfileManagerTest : public ManagerTestBase {}; + +TEST_F(ArsProfileManagerTest, testArsProfileManager) { + std::shared_ptr oldFsc = + std::make_shared(); + oldFsc->setDynamicSampleRate(1000000); + oldFsc->setDynamicEgressLoadExponent(2); + oldFsc->setDynamicQueueExponent(3); + oldFsc->setDynamicPhysicalQueueExponent(4); + oldFsc->setDynamicEgressMinThresholdBytes(10000); + oldFsc->setDynamicEgressMaxThresholdBytes(20000); + oldFsc->setDynamicQueueMinThresholdBytes(30000); + oldFsc->setDynamicQueueMaxThresholdBytes(40000); + // verify ars profile object creation + saiManagerTable->arsProfileManager().addArsProfile(oldFsc); + auto arsProfileHandle = + saiManagerTable->arsProfileManager().getArsProfileHandle(); + auto arsProfileSaiId = arsProfileHandle->arsProfile->adapterKey(); + auto samplingRate = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::SamplingInterval{}); + EXPECT_EQ(samplingRate, 1000000); + auto portLoadPastWeight = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::PortLoadPastWeight{}); + EXPECT_EQ(portLoadPastWeight, 2); + auto portLoadFutureWeight = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::PortLoadFutureWeight{}); + EXPECT_EQ(portLoadFutureWeight, 3); + auto portLoadExponent = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::PortLoadExponent{}); + EXPECT_EQ(portLoadExponent, 4); + auto loadPastMinVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadPastMinVal{}); + EXPECT_EQ(loadPastMinVal, 10000); + auto loadPastMaxVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadPastMaxVal{}); + EXPECT_EQ(loadPastMaxVal, 20000); + auto loadFutureMinVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadFutureMinVal{}); + EXPECT_EQ(loadFutureMinVal, 30000); + auto loadFutureMaxVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadFutureMaxVal{}); + EXPECT_EQ(loadFutureMaxVal, 40000); + auto loadCurrentMinVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadCurrentMinVal{}); + EXPECT_EQ(loadCurrentMinVal, 15000); + auto loadCurrentMaxVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadCurrentMaxVal{}); + EXPECT_EQ(loadCurrentMaxVal, 20000); + + std::shared_ptr newFsc = + std::make_shared(); + newFsc->setDynamicSampleRate(2000000); + newFsc->setDynamicEgressLoadExponent(4); + newFsc->setDynamicQueueExponent(6); + newFsc->setDynamicPhysicalQueueExponent(8); + newFsc->setDynamicEgressMinThresholdBytes(20000); + newFsc->setDynamicEgressMaxThresholdBytes(40000); + newFsc->setDynamicQueueMinThresholdBytes(60000); + newFsc->setDynamicQueueMaxThresholdBytes(80000); + // verify ars profile config change + saiManagerTable->arsProfileManager().changeArsProfile(oldFsc, newFsc); + samplingRate = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::SamplingInterval{}); + EXPECT_EQ(samplingRate, 2000000); + portLoadPastWeight = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::PortLoadPastWeight{}); + EXPECT_EQ(portLoadPastWeight, 4); + portLoadFutureWeight = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::PortLoadFutureWeight{}); + EXPECT_EQ(portLoadFutureWeight, 6); + portLoadExponent = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::PortLoadExponent{}); + EXPECT_EQ(portLoadExponent, 8); + loadPastMinVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadPastMinVal{}); + EXPECT_EQ(loadPastMinVal, 20000); + loadPastMaxVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadPastMaxVal{}); + EXPECT_EQ(loadPastMaxVal, 40000); + loadFutureMinVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadFutureMinVal{}); + EXPECT_EQ(loadFutureMinVal, 60000); + loadFutureMaxVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadFutureMaxVal{}); + EXPECT_EQ(loadFutureMaxVal, 80000); + loadCurrentMinVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadCurrentMinVal{}); + EXPECT_EQ(loadCurrentMinVal, 30000); + loadCurrentMaxVal = saiApiTable->arsProfileApi().getAttribute( + arsProfileSaiId, SaiArsProfileTraits::Attributes::LoadCurrentMaxVal{}); + EXPECT_EQ(loadCurrentMaxVal, 40000); +} diff --git a/fboss/agent/hw/sai/switch/tests/BUCK b/fboss/agent/hw/sai/switch/tests/BUCK index 50d41758493c1..6683e80441237 100644 --- a/fboss/agent/hw/sai/switch/tests/BUCK +++ b/fboss/agent/hw/sai/switch/tests/BUCK @@ -40,6 +40,13 @@ switch_manager_unittest( ], ) +switch_manager_unittest( + name = "ars_profile_manager_test", + srcs = [ + "ArsProfileManagerTest.cpp", + ], +) + switch_manager_unittest( name = "fdb_manager_test", srcs = [