@@ -210,15 +210,28 @@ void check_all_enums_values()
210210
211211 if (value != last + 1 )
212212 {
213- flags = true;
214-
215- if (is_flag_enum (emd ))
213+ if (value == CUSTOM_ATTR_RANGE_START )
216214 {
217- /* flags, ok */
215+ /*
216+ * Object contains custom attributes in custom range, they
217+ * still needs to be increasing by 1 but since those are
218+ * not flags, attribute value can't be used as array index.
219+ */
220+
221+ META_ENUM_LOG_WARN (emd , "contains custom range attibutes" );
218222 }
219223 else
220224 {
221- META_ENUM_ASSERT_FAIL (emd , "values are not increasing by 1: last: %d current: %d, should be marked as @flags?" , last , value );
225+ flags = true;
226+
227+ if (is_flag_enum (emd ))
228+ {
229+ /* flags, ok */
230+ }
231+ else
232+ {
233+ META_ENUM_ASSERT_FAIL (emd , "values are not increasing by 1: last: %d current: %d, should be marked as @flags?" , last , value );
234+ }
222235 }
223236 }
224237
@@ -3528,6 +3541,8 @@ void check_object_infos()
35283541
35293542 bool has_extensions_attrs = false;
35303543
3544+ bool has_custom_range_attrs = false;
3545+
35313546 for (; meta [index ] != NULL ; ++ index )
35323547 {
35333548 const sai_attr_metadata_t * am = meta [index ];
@@ -3537,13 +3552,26 @@ void check_object_infos()
35373552
35383553 if (last + 1 != (int )am -> attrid )
35393554 {
3540- if (is_flag_enum ( info -> enummetadata ) )
3555+ if (am -> attrid == CUSTOM_ATTR_RANGE_START )
35413556 {
3542- /* flags, ok */
3557+ /*
3558+ * Object contains custom attributes in custom range, they
3559+ * still needs to be increasing by 1 but since those are
3560+ * not flags, attribute value can't be used as array index.
3561+ */
3562+
3563+ has_custom_range_attrs = true;
35433564 }
35443565 else
35453566 {
3546- META_MD_ASSERT_FAIL (am , "attr id is not increasing by 1: prev %d, curr %d" , last , am -> attrid );
3567+ if (is_flag_enum (info -> enummetadata ))
3568+ {
3569+ /* flags, ok */
3570+ }
3571+ else
3572+ {
3573+ META_MD_ASSERT_FAIL (am , "attr id is not increasing by 1: prev %d, curr %d" , last , am -> attrid );
3574+ }
35473575 }
35483576 }
35493577
@@ -3591,6 +3619,10 @@ void check_object_infos()
35913619 {
35923620 /* ok, extension attribute */
35933621 }
3622+ else if (has_custom_range_attrs )
3623+ {
3624+ /* ok, custom range attributes */
3625+ }
35943626 else
35953627 {
35963628 META_ENUM_ASSERT_FAIL (info -> enummetadata , "end of attributes don't match attr count on %s" ,
@@ -3825,8 +3857,8 @@ void check_attr_sorted_by_id_name()
38253857
38263858 const char * last = "AAA" ;
38273859
3828- META_ASSERT_TRUE (sai_metadata_attr_sorted_by_id_name_count > 800 ,
3829- "there should be at least 800 attributes in total" );
3860+ META_ASSERT_TRUE (sai_metadata_attr_sorted_by_id_name_count > 1700 ,
3861+ "there should be at least 1700 attributes in total" );
38303862
38313863 for (; i < sai_metadata_attr_sorted_by_id_name_count ; ++ i )
38323864 {
@@ -4147,7 +4179,7 @@ void check_mixed_object_list_types()
41474179 * be supported.
41484180 */
41494181
4150- META_ASSERT_TRUE (sai_metadata_attr_sorted_by_id_name_count > 800 , "there should be at least 800 attributes in total" );
4182+ META_ASSERT_TRUE (sai_metadata_attr_sorted_by_id_name_count > 1700 , "there should be at least 1700 attributes in total" );
41514183
41524184 size_t idx = 0 ;
41534185
@@ -5150,17 +5182,165 @@ void check_get_attr_metadata()
51505182 while (mda [idx ])
51515183 {
51525184 const sai_attr_metadata_t * m = mda [idx ++ ];
5185+ const sai_attr_metadata_t * md = sai_metadata_get_attr_metadata (ot , m -> attrid );
5186+
5187+ META_ASSERT_NOT_NULL (md );
5188+ META_ASSERT_TRUE (m == md , "different attribute found, fatal" );
5189+
5190+ count ++ ;
5191+ }
5192+ }
5193+
5194+ META_ASSERT_TRUE (count > 1700 , "expected at least 1700 attributes" );
5195+ }
51535196
5197+ void check_get_attr_metadata_custom_range ()
5198+ {
5199+ META_LOG_ENTER ();
5200+
5201+ /*
5202+ * This function will check, if attributes which are marked as no flags,
5203+ * will have values equal to attribute index in metadata array even if
5204+ * attribute is extension attribute, and custom range attributes will be
5205+ * ignored.
5206+ *
5207+ * This will make sure that we can use attr id as index in arrays except
5208+ * custom attributes.
5209+ */
5210+
5211+ size_t count = 0 ;
5212+
5213+ size_t ot = 0 ;
5214+
5215+ for (; ot < SAI_OBJECT_TYPE_EXTENSIONS_MAX ; ++ ot )
5216+ {
5217+ const sai_object_type_info_t * oti = sai_metadata_get_object_type_info (ot );
5218+
5219+ if (oti == NULL )
5220+ continue ;
5221+
5222+ const sai_attr_metadata_t * const * mda = sai_metadata_attr_by_object_type [ot ];
5223+
5224+ if (oti -> enummetadata -> containsflags )
5225+ {
5226+ int idx = 0 ;
5227+
5228+ while (mda [idx ])
5229+ {
5230+ const sai_attr_metadata_t * m = mda [idx ++ ];
5231+
5232+ const sai_attr_metadata_t * md = sai_metadata_get_attr_metadata (ot , m -> attrid );
5233+
5234+ META_ASSERT_NOT_NULL (md );
5235+ META_ASSERT_TRUE (m == md , "different attribute found, fatal" );
5236+
5237+ count ++ ;
5238+ }
5239+
5240+ continue ;
5241+ }
5242+
5243+ /* no flags attributes */
5244+
5245+ META_ASSERT_TRUE (oti -> attridend <= oti -> attrmetadatalength , "attridend must be less or equal to total number of attributes" );
5246+
5247+ uint32_t idx = 0 ;
5248+
5249+ while (mda [idx ])
5250+ {
5251+ const sai_attr_metadata_t * m = mda [idx ];
51545252 const sai_attr_metadata_t * md = sai_metadata_get_attr_metadata (ot , m -> attrid );
51555253
51565254 META_ASSERT_NOT_NULL (md );
51575255 META_ASSERT_TRUE (m == md , "different attribute found, fatal" );
51585256
5257+ if (oti -> attridend == oti -> attrmetadatalength || idx < oti -> attridend )
5258+ {
5259+ META_ASSERT_TRUE (md -> attrid == idx , "%s, attrid (%u) must be equal to index (%u)" , md -> attridname , md -> attrid , idx );
5260+ }
5261+ else /* extensions or custom attributes */
5262+ {
5263+ if (md -> attrid < CUSTOM_ATTR_RANGE_START )
5264+ {
5265+ META_ASSERT_TRUE (md -> attrid == idx , "extenstion attribute %s, attrid (%u) must be equal to index (%u)" , md -> attridname , md -> attrid , idx );
5266+ }
5267+ else
5268+ {
5269+ /* custom range attributes will not follow index increase */
5270+ }
5271+ }
5272+
5273+ idx ++ ;
51595274 count ++ ;
51605275 }
51615276 }
51625277
5163- META_ASSERT_TRUE (count > 600 , "expected at least 600 attributes" );
5278+ META_ASSERT_TRUE (count > 1700 , "expected at least 1700 attributes, got %zu" , count );
5279+ }
5280+
5281+ void check_attr_get_outside_range ()
5282+ {
5283+ META_LOG_ENTER ();
5284+
5285+ int ot = -10 ;
5286+
5287+ for (; ot < (int )(SAI_OBJECT_TYPE_EXTENSIONS_MAX + 10 ); ++ ot )
5288+ {
5289+ const sai_object_type_info_t * oti = sai_metadata_get_object_type_info (ot );
5290+
5291+ if (oti == NULL )
5292+ continue ;
5293+
5294+ int idx = -10 ;
5295+
5296+ for (; idx < (int )(oti -> attrmetadatalength + 10 ); idx ++ )
5297+ {
5298+ const sai_attr_metadata_t * md = sai_metadata_get_attr_metadata (ot , (sai_attr_id_t )idx );
5299+
5300+ if (md == NULL )
5301+ continue ;
5302+
5303+ if ((int )md -> attrid != idx )
5304+ {
5305+ META_MD_ASSERT_FAIL (md , "attr %u expected to be %u" , md -> attrid , idx );
5306+ }
5307+ }
5308+ }
5309+ }
5310+
5311+ void check_custom_range_attributes ()
5312+ {
5313+ META_LOG_ENTER ();
5314+
5315+ /* Checks whether attribute is correctly marked as custom */
5316+
5317+ size_t ot = 0 ;
5318+
5319+ for (; ot < SAI_OBJECT_TYPE_EXTENSIONS_MAX ; ++ ot )
5320+ {
5321+ const sai_attr_metadata_t * const * mda = sai_metadata_attr_by_object_type [ot ];
5322+
5323+ int idx = 0 ;
5324+
5325+ while (mda [idx ])
5326+ {
5327+ const sai_attr_metadata_t * m = mda [idx ++ ];
5328+ const sai_attr_metadata_t * md = sai_metadata_get_attr_metadata (ot , m -> attrid );
5329+
5330+ META_ASSERT_NOT_NULL (md );
5331+
5332+ if (md -> attrid >= CUSTOM_ATTR_RANGE_START )
5333+ {
5334+ META_ASSERT_TRUE (md -> iscustom , "expected to be marked as custom attribute, %s" , md -> attridname );
5335+ }
5336+ else
5337+ {
5338+ META_ASSERT_FALSE (md -> iscustom , "expected to be NOT marked as custom attribute, %s" , md -> attridname );
5339+ }
5340+ }
5341+ }
5342+
5343+ /*sai_metadata_get_attr_metadata */
51645344}
51655345
51665346void check_acl_user_defined_field ()
@@ -5224,7 +5404,7 @@ void check_defines()
52245404 */
52255405
52265406 META_ASSERT_TRUE (SAI_METADATA_SWITCH_NOTIFY_ATTR_COUNT == sai_metadata_switch_notify_attr_count , "notify define must be equal" );
5227- META_ASSERT_TRUE (SAI_METADATA_SWITCH_NOTIFY_ATTR_COUNT > 3 , "there must be at least 3 notifications defined" );
5407+ META_ASSERT_TRUE (SAI_METADATA_SWITCH_NOTIFY_ATTR_COUNT >= 15 , "there must be at least 15 notifications defined" );
52285408}
52295409
52305410void check_object_type_attributes ()
@@ -5433,7 +5613,18 @@ void check_enum_flags_type_none(
54335613
54345614 if (value != last + 1 )
54355615 {
5436- META_ENUM_ASSERT_FAIL (emd , "values are not increasing by 1: last: %d current: %d, should be marked as @flags?" , last , value );
5616+ if (value == CUSTOM_ATTR_RANGE_START )
5617+ {
5618+ /*
5619+ * Object contains custom attributes in custom range, they
5620+ * still needs to be increasing by 1 but since those are
5621+ * not flags, attribute value can't be used as array index.
5622+ */
5623+ }
5624+ else
5625+ {
5626+ META_ENUM_ASSERT_FAIL (emd , "values are not increasing by 1: last: %d current: %d, should be marked as @flags?" , last , value );
5627+ }
54375628 }
54385629
54395630 last = value ;
@@ -5742,6 +5933,7 @@ int main(int argc, char **argv)
57425933 check_backward_comparibility_defines ();
57435934 check_graph_connected ();
57445935 check_get_attr_metadata ();
5936+ check_get_attr_metadata_custom_range ();
57455937 check_acl_user_defined_field ();
57465938 check_label_size ();
57475939 check_switch_notify_list ();
@@ -5757,6 +5949,8 @@ int main(int argc, char **argv)
57575949 check_struct_and_union_size ();
57585950 check_declare_entry_macro ();
57595951 check_json_type_size ();
5952+ check_custom_range_attributes ();
5953+ check_attr_get_outside_range ();
57605954
57615955 SAI_META_LOG_DEBUG ("log test" );
57625956
0 commit comments