@@ -791,9 +791,6 @@ TEST(FlexCounter, bulkChunksize)
791791 * 3. Verify whether values of all counter IDs of all objects have been generated
792792 * 4. Verify whether the bulk chunk size is correct
793793 */
794- sai->mock_getStatsExt = [&](sai_object_type_t , sai_object_id_t , uint32_t number_of_counters, const sai_stat_id_t *, sai_stats_mode_t , uint64_t *counters) {
795- return SAI_STATUS_SUCCESS;
796- };
797794 sai->mock_getStats = [&](sai_object_type_t , sai_object_id_t , uint32_t number_of_counters, const sai_stat_id_t *, uint64_t *counters) {
798795 return SAI_STATUS_SUCCESS;
799796 };
@@ -841,10 +838,31 @@ TEST(FlexCounter, bulkChunksize)
841838 }
842839 };
843840
841+ std::map<sai_stat_id_t , uint64_t > bulkUnsupportedCounters;
842+ // <oid, <counter id, counter value>>
843+ std::map<std::string, std::map<std::string, std::string>> bulkUnsupportedCounterExpectedValues;
844+ sai->mock_getStatsExt = [&](sai_object_type_t , sai_object_id_t oid, uint32_t number_of_counters, const sai_stat_id_t *counter_ids, sai_stats_mode_t , uint64_t *counters) {
845+ for (auto i = 0u ; i < number_of_counters; i++)
846+ {
847+ if (bulkUnsupportedCounters.find (counter_ids[i]) != bulkUnsupportedCounters.end ())
848+ {
849+ counters[i] = bulkUnsupportedCounters[counter_ids[i]] * (uint64_t )oid;
850+ if (counterValuesMap.find (oid) == counterValuesMap.end ())
851+ {
852+ counterValuesMap[oid] = {};
853+ }
854+ counterValuesMap[oid][counter_ids[i]] = counters[i];
855+ }
856+ }
857+ return SAI_STATUS_SUCCESS;
858+ };
859+
844860 std::vector<std::vector<sai_stat_id_t >> counterRecord;
845861 std::vector<std::vector<uint64_t >> valueRecord;
846862 sai_uint64_t counterSeed = 0 ;
847- uint32_t expectedInitObjectCount;
863+ // non zero unifiedBulkChunkSize indicates all counter IDs share the same bulk chunk size
864+ uint32_t unifiedBulkChunkSize = 0 ;
865+ int32_t initialCheckCount;
848866 sai->mock_bulkGetStats = [&](sai_object_id_t ,
849867 sai_object_type_t ,
850868 uint32_t object_count,
@@ -858,10 +876,18 @@ TEST(FlexCounter, bulkChunksize)
858876 EXPECT_TRUE (mode == SAI_STATS_MODE_BULK_READ);
859877 std::vector<sai_stat_id_t > record;
860878 std::vector<uint64_t > value;
861- if (number_of_counters >= 5 && object_count == expectedInitObjectCount )
879+ if (initialCheckCount-- > 0 )
862880 {
863881 allObjectIds.insert (toOid (object_keys[0 ].key .object_id ));
864882 // This call is to check whether bulk counter polling is supported during initialization
883+ if (!bulkUnsupportedCounters.empty ())
884+ {
885+ // Simulate counters that are not supported being polled in bulk mode
886+ if (bulkUnsupportedCounters.find (counter_ids[0 ]) != bulkUnsupportedCounters.end ())
887+ {
888+ return SAI_STATUS_FAILURE;
889+ }
890+ }
865891 return SAI_STATUS_SUCCESS;
866892 }
867893 for (uint32_t i = 0 ; i < object_count; i++)
@@ -925,7 +951,7 @@ TEST(FlexCounter, bulkChunksize)
925951 allObjectIds.erase (key);
926952 };
927953
928- expectedInitObjectCount = 1 ;
954+ initialCheckCount = 6 ;
929955 testAddRemoveCounter (
930956 6 ,
931957 SAI_OBJECT_TYPE_PORT,
@@ -940,6 +966,7 @@ TEST(FlexCounter, bulkChunksize)
940966 " SAI_PORT_STAT_IF_OUT_QLEN:0;SAI_PORT_STAT_IF_IN_FEC:2" );
941967 EXPECT_TRUE (allObjectIds.empty ());
942968
969+ initialCheckCount = 6 ;
943970 testAddRemoveCounter (
944971 6 ,
945972 SAI_OBJECT_TYPE_PORT,
@@ -956,7 +983,27 @@ TEST(FlexCounter, bulkChunksize)
956983 PORT_PLUGIN_FIELD);
957984 EXPECT_TRUE (allObjectIds.empty ());
958985
959- expectedInitObjectCount = 6 ;
986+ unifiedBulkChunkSize = 3 ;
987+ initialCheckCount = 6 ;
988+ testAddRemoveCounter (
989+ 6 ,
990+ SAI_OBJECT_TYPE_PORT,
991+ PORT_COUNTER_ID_LIST,
992+ {" SAI_PORT_STAT_IF_IN_OCTETS" , " SAI_PORT_STAT_IF_IN_UCAST_PKTS" , " SAI_PORT_STAT_IF_OUT_QLEN" , " SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES" , " SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES" },
993+ {},
994+ counterVerifyFunc,
995+ false ,
996+ STATS_MODE_READ,
997+ false ,
998+ " 3" ,
999+ " SAI_PORT_STAT_IF_OUT_QLEN:0;SAI_PORT_STAT_IF_IN_FEC:2" ,
1000+ true ,
1001+ " " ,
1002+ true );
1003+ EXPECT_TRUE (allObjectIds.empty ());
1004+ unifiedBulkChunkSize = 0 ;
1005+
1006+ initialCheckCount = 3 ;
9601007 testAddRemoveCounter (
9611008 6 ,
9621009 SAI_OBJECT_TYPE_PORT,
@@ -971,6 +1018,33 @@ TEST(FlexCounter, bulkChunksize)
9711018 " SAI_PORT_STAT_IF_OUT_QLEN:0;SAI_PORT_STAT_IF_IN_FEC:2" );
9721019 EXPECT_TRUE (allObjectIds.empty ());
9731020
1021+ initialCheckCount = 3 ;
1022+ testAddRemoveCounter (
1023+ 6 ,
1024+ SAI_OBJECT_TYPE_PORT,
1025+ PORT_COUNTER_ID_LIST,
1026+ {" SAI_PORT_STAT_IF_IN_OCTETS" , " SAI_PORT_STAT_IF_IN_UCAST_PKTS" , " SAI_PORT_STAT_IF_OUT_QLEN" , " SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES" , " SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES" },
1027+ {},
1028+ counterVerifyFunc,
1029+ false ,
1030+ STATS_MODE_READ,
1031+ true ,
1032+ " 3" ,
1033+ " SAI_PORT_STAT_IF_OUT_QLEN:0;SAI_PORT_STAT_IF_IN_FEC:2" ,
1034+ false ,
1035+ PORT_PLUGIN_FIELD);
1036+ EXPECT_TRUE (allObjectIds.empty ());
1037+
1038+ initialCheckCount = 3 ; // check bulk for 3 prefixes
1039+ initialCheckCount += 6 ; // for bulk unsupported counter prefix, check bulk again for each objects
1040+ bulkUnsupportedCounters = {
1041+ {SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES, 3 },
1042+ {SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES, 5 }
1043+ };
1044+ std::set<std::string> bulkUnsupportedCounterNames = {
1045+ " SAI_PORT_STAT_IF_IN_FEC_CORRECTABLE_FRAMES" ,
1046+ " SAI_PORT_STAT_IF_IN_FEC_NOT_CORRECTABLE_FRAMES"
1047+ };
9741048 testAddRemoveCounter (
9751049 6 ,
9761050 SAI_OBJECT_TYPE_PORT,
0 commit comments