@@ -6462,6 +6462,126 @@ void check_object_type_index()
64626462 }
64636463}
64646464
6465+ static int get_status_attr_category (
6466+ _In_ sai_status_t status )
6467+ {
6468+ int category = 0 ;
6469+ int matches = 0 ;
6470+
6471+ if (SAI_STATUS_IS_INVALID_ATTRIBUTE (status ))
6472+ {
6473+ category = 1 ;
6474+ matches ++ ;
6475+ }
6476+
6477+ if (SAI_STATUS_IS_INVALID_ATTR_VALUE (status ))
6478+ {
6479+ category = 2 ;
6480+ matches ++ ;
6481+ }
6482+
6483+ if (SAI_STATUS_IS_ATTR_NOT_IMPLEMENTED (status ))
6484+ {
6485+ category = 3 ;
6486+ matches ++ ;
6487+ }
6488+
6489+ if (SAI_STATUS_IS_UNKNOWN_ATTRIBUTE (status ))
6490+ {
6491+ category = 4 ;
6492+ matches ++ ;
6493+ }
6494+
6495+ if (SAI_STATUS_IS_ATTR_NOT_SUPPORTED (status ))
6496+ {
6497+ category = 5 ;
6498+ matches ++ ;
6499+ }
6500+
6501+ /* a valid attribute-range code must match exactly one helper */
6502+
6503+ return (matches == 1 ) ? category : 0 ;
6504+ }
6505+
6506+ void check_status_attr_ranges ()
6507+ {
6508+ META_LOG_ENTER ();
6509+
6510+ const sai_status_t base0 [] = {
6511+ SAI_STATUS_INVALID_ATTRIBUTE_0 ,
6512+ SAI_STATUS_INVALID_ATTR_VALUE_0 ,
6513+ SAI_STATUS_ATTR_NOT_IMPLEMENTED_0 ,
6514+ SAI_STATUS_UNKNOWN_ATTRIBUTE_0 ,
6515+ SAI_STATUS_ATTR_NOT_SUPPORTED_0 ,
6516+ };
6517+
6518+ const sai_status_t basemax [] = {
6519+ SAI_STATUS_INVALID_ATTRIBUTE_MAX ,
6520+ SAI_STATUS_INVALID_ATTR_VALUE_MAX ,
6521+ SAI_STATUS_ATTR_NOT_IMPLEMENTED_MAX ,
6522+ SAI_STATUS_UNKNOWN_ATTRIBUTE_MAX ,
6523+ SAI_STATUS_ATTR_NOT_SUPPORTED_MAX ,
6524+ };
6525+
6526+ /* positive magnitude of each *_0 base (0x10000 .. 0x50000) */
6527+ const int magnitude [] = { 0x10000 , 0x20000 , 0x30000 , 0x40000 , 0x50000 };
6528+
6529+ /* attribute indices to cover, including _0 and the _MAX boundary */
6530+ const int indices [] = { 0 , 1 , 2 , 17 , 0xFFFE , 0xFFFF };
6531+
6532+ size_t r ;
6533+ size_t k ;
6534+
6535+ /* codes that are not attribute-range errors must not match any helper */
6536+ META_ASSERT_TRUE (get_status_attr_category (SAI_STATUS_SUCCESS ) == 0 ,
6537+ "SAI_STATUS_SUCCESS must not match any attribute range" );
6538+ META_ASSERT_TRUE (get_status_attr_category (SAI_STATUS_FAILURE ) == 0 ,
6539+ "SAI_STATUS_FAILURE must not match any attribute range" );
6540+ META_ASSERT_TRUE (get_status_attr_category (SAI_STATUS_NOT_EXECUTED ) == 0 ,
6541+ "SAI_STATUS_NOT_EXECUTED must not match any attribute range" );
6542+ META_ASSERT_TRUE (get_status_attr_category ((sai_status_t )1 ) == 0 ,
6543+ "value 1 must not match any attribute range" );
6544+ META_ASSERT_TRUE (get_status_attr_category ((sai_status_t )- 1 ) == 0 ,
6545+ "value -1 must not match any attribute range" );
6546+
6547+ for (r = 0 ; r < sizeof (base0 ) / sizeof (base0 [0 ]); r ++ )
6548+ {
6549+ int category = (int )(r + 1 );
6550+
6551+ /* _MAX must be the last (index 0xFFFF) code of the range */
6552+ META_ASSERT_TRUE (basemax [r ] == SAI_STATUS_CODE (magnitude [r ] + 0xFFFF ),
6553+ "range %d: _MAX must equal SAI_STATUS_CODE(base + 0xFFFF)" , category );
6554+
6555+ for (k = 0 ; k < sizeof (indices ) / sizeof (indices [0 ]); k ++ )
6556+ {
6557+ int index = indices [k ];
6558+
6559+ /* the indexed code must be built as base_0 + SAI_STATUS_CODE(index) */
6560+ sai_status_t status = base0 [r ] + SAI_STATUS_CODE (index );
6561+
6562+ META_ASSERT_TRUE (status == SAI_STATUS_CODE (magnitude [r ] + index ),
6563+ "range %d: base_0 + SAI_STATUS_CODE(%d) has wrong value" , category , index );
6564+
6565+ /* it must classify into its own range and no other */
6566+ META_ASSERT_TRUE (get_status_attr_category (status ) == category ,
6567+ "range %d: indexed status (index %d) classified into wrong/ambiguous range" ,
6568+ category , index );
6569+
6570+ /* the encoded attribute index must round-trip */
6571+ META_ASSERT_TRUE ((SAI_STATUS_CODE (status ) & 0xFFFF ) == index ,
6572+ "range %d: decoded attribute index != %d" , category , index );
6573+ }
6574+
6575+ /* the code just below _0 must not classify into this range */
6576+ META_ASSERT_TRUE (get_status_attr_category (SAI_STATUS_CODE (magnitude [r ] - 1 )) != category ,
6577+ "range %d: code below _0 must not match this range" , category );
6578+
6579+ /* the code just above _MAX must not classify into this range */
6580+ META_ASSERT_TRUE (get_status_attr_category (SAI_STATUS_CODE (magnitude [r ] + 0x10000 )) != category ,
6581+ "range %d: code above _MAX must not match this range" , category );
6582+ }
6583+ }
6584+
64656585int main (int argc , char * * argv )
64666586{
64676587 debug = (argc > 1 );
@@ -6472,6 +6592,7 @@ int main(int argc, char **argv)
64726592 check_all_enums_values ();
64736593 check_enums_ignore_values ();
64746594 check_sai_status ();
6595+ check_status_attr_ranges ();
64756596 check_object_type_index ();
64766597 check_object_type ();
64776598 check_attr_by_object_type ();
0 commit comments