@@ -1002,7 +1002,7 @@ namespace flexcounter_test
10021002 );
10031003
10041004 using namespace mock_orch_test ;
1005- class EniStatFlexCounterTest : public MockOrchTest
1005+ class StandaloneFCTest : public MockOrchTest
10061006 {
10071007 virtual void PostSetUp () {
10081008 _hook_sai_switch_api ();
@@ -1013,7 +1013,7 @@ namespace flexcounter_test
10131013 }
10141014 };
10151015
1016- TEST_F (EniStatFlexCounterTest, TestStatusUpdate )
1016+ TEST_F (StandaloneFCTest, TestEniStatusUpdate )
10171017 {
10181018 /* Add a mock ENI */
10191019 EniEntry tmp_entry;
@@ -1029,4 +1029,72 @@ namespace flexcounter_test
10291029 m_DashOrch->handleFCStatusUpdate (false );
10301030 ASSERT_FALSE (checkFlexCounter (ENI_STAT_COUNTER_FLEX_COUNTER_GROUP, tmp_entry.eni_id , ENI_COUNTER_ID_LIST));
10311031 }
1032+
1033+ TEST_F (StandaloneFCTest, TestCaching)
1034+ {
1035+ mockFlexCounterOperationCallCount = 0 ;
1036+
1037+ /* Disable traditional FC since caching is only used for FC config through SAIREDIS channel */
1038+ gTraditionalFlexCounter = false ;
1039+ FlexCounterTaggedCachedManager<void > port_stat_manager (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, 1000 , false );
1040+
1041+ // Create two port OIDs
1042+ sai_object_id_t port1_oid = 0x100000000000d ;
1043+ sai_object_id_t port2_oid = 0x100000000000e ;
1044+ sai_object_id_t port3_oid = 0x100000000000f ;
1045+ sai_object_id_t port4_oid = 0x1000000000010 ;
1046+ // Different counter stats for each port
1047+ std::unordered_set<string> type1_stats = {
1048+ " SAI_PORT_STAT_IF_IN_OCTETS" ,
1049+ " SAI_PORT_STAT_IF_IN_ERRORS"
1050+ };
1051+ std::unordered_set<string> type2_stats = {
1052+ " SAI_PORT_STAT_IF_OUT_OCTETS" ,
1053+ " SAI_PORT_STAT_IF_OUT_ERRORS"
1054+ };
1055+
1056+ // Set counter IDs for both ports
1057+ port_stat_manager.setCounterIdList (port1_oid, CounterType::PORT, type1_stats);
1058+ port_stat_manager.setCounterIdList (port2_oid, CounterType::PORT, type1_stats);
1059+ port_stat_manager.setCounterIdList (port3_oid, CounterType::PORT, type2_stats);
1060+ port_stat_manager.setCounterIdList (port4_oid, CounterType::PORT, type1_stats);
1061+
1062+ // Flush the counters
1063+ port_stat_manager.flush ();
1064+
1065+ /* SAIREDIS channel should have been called thrice, once for port1&port2,port3,port4 */
1066+ ASSERT_EQ (mockFlexCounterOperationCallCount, 3 );
1067+
1068+ ASSERT_TRUE (checkFlexCounter (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, port1_oid,
1069+ {
1070+ {PORT_COUNTER_ID_LIST,
1071+ " SAI_PORT_STAT_IF_IN_OCTETS,"
1072+ " SAI_PORT_STAT_IF_IN_ERRORS"
1073+ }
1074+ }));
1075+
1076+ ASSERT_TRUE (checkFlexCounter (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, port2_oid,
1077+ {
1078+ {PORT_COUNTER_ID_LIST,
1079+ " SAI_PORT_STAT_IF_IN_OCTETS,"
1080+ " SAI_PORT_STAT_IF_IN_ERRORS"
1081+ }
1082+ }));
1083+
1084+ ASSERT_TRUE (checkFlexCounter (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, port3_oid,
1085+ {
1086+ {PORT_COUNTER_ID_LIST,
1087+ " SAI_PORT_STAT_IF_OUT_OCTETS,"
1088+ " SAI_PORT_STAT_IF_OUT_ERRORS"
1089+ }
1090+ }));
1091+
1092+ ASSERT_TRUE (checkFlexCounter (PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, port4_oid,
1093+ {
1094+ {PORT_COUNTER_ID_LIST,
1095+ " SAI_PORT_STAT_IF_IN_OCTETS,"
1096+ " SAI_PORT_STAT_IF_IN_ERRORS"
1097+ }
1098+ }));
1099+ }
10321100}
0 commit comments