From 5fc9b155af6fce8badd1efdee0019ea29373cb80 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Fri, 22 Nov 2024 13:59:10 +0100 Subject: [PATCH] Add custom range base enums for api and object_type Also include metadata test for validation --- inc/sai.h | 5 +++++ inc/saitypes.h | 5 +++++ meta/test.pm | 55 ++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/inc/sai.h b/inc/sai.h index 4a802b4f9..9938b5a68 100644 --- a/inc/sai.h +++ b/inc/sai.h @@ -153,6 +153,11 @@ typedef enum _sai_api_t SAI_API_PREFIX_COMPRESSION = 53, /**< sai_prefix_compression_api_t */ SAI_API_MAX, /**< total number of APIs */ + /** + * @brief Custom range base + */ + SAI_API_CUSTOM_RANGE_BASE = 0x10000000, + /** * @brief Extensions range base */ diff --git a/inc/saitypes.h b/inc/saitypes.h index b65be6bdb..a9a977bb1 100644 --- a/inc/saitypes.h +++ b/inc/saitypes.h @@ -305,6 +305,11 @@ typedef enum _sai_object_type_t /** Must remain in last position */ SAI_OBJECT_TYPE_MAX, + /** + * @brief Custom range base + */ + SAI_OBJECT_TYPE_CUSTOM_RANGE_BASE = 0x10000000, + SAI_OBJECT_TYPE_EXTENSIONS_RANGE_BASE = 0x20000000, } sai_object_type_t; diff --git a/meta/test.pm b/meta/test.pm index c3b7a1820..7d3309a76 100644 --- a/meta/test.pm +++ b/meta/test.pm @@ -149,7 +149,7 @@ sub CreateCustomRangeTest WriteTest "}"; } -sub CreateCustomRangeAll +sub CreateCustomRangeAllTest { DefineTestName "custom_range_all_test"; @@ -166,12 +166,6 @@ sub CreateCustomRangeAll for my $enum (@all) { - # extepions and will be removed - next if $enum eq "SAI_API_CUSTOM_RANGE_START"; - next if $enum eq "SAI_API_CUSTOM_RANGE_END"; - next if $enum eq "SAI_OBJECT_TYPE_CUSTOM_RANGE_START"; - next if $enum eq "SAI_OBJECT_TYPE_CUSTOM_RANGE_END"; - WriteTest " TEST_ASSERT_TRUE($enum == 0x10000000, \"invalid custom range start for $enum\");" if $enum =~ /_START$/; WriteTest " TEST_ASSERT_TRUE($enum < 0x20000000, \"invalid custom range end for $enum\");" if $enum =~ /_END$/; } @@ -180,6 +174,49 @@ sub CreateCustomRangeAll WriteTest "}"; } +sub CreateCustomRangeBaseTest +{ + DefineTestName "custom_range_base_test"; + + WriteTest "{"; + + for my $key (sort keys %main::SAI_ENUMS) + { + next if not defined $main::SAI_ENUMS{$key}{ranges}; + + my @ranges = @{ $main::SAI_ENUMS{$key}{ranges} }; + + next if scalar @ranges == 0; + + for my $range (@ranges) + { + next if $range eq "SAI_HOSTIF_USER_DEFINED_TRAP_TYPE_CUSTOM_RANGE_BASE"; # TODO exception, to be remove + + my $prefix = uc $1 if $key =~ /(sai_\w+)_t$/; + + if ($range eq "${prefix}_CUSTOM_RANGE_BASE") + { + WriteTest " TEST_ASSERT_TRUE_EXT($range == 0x10000000, \"invalid custom range base for $range = 0x%x\", $range);" ; + next; + } + + if ($range eq "${prefix}_EXTENSIONS_RANGE_BASE") + { + WriteTest " TEST_ASSERT_TRUE_EXT($range == 0x20000000, \"invalid extensions range base for $range: = 0x%x\", $range);" ; + next; + } + + LogInfo "Skipping range base $range"; + + # currently any other range should be less than custom + + WriteTest " TEST_ASSERT_TRUE_EXT($range < 0x10000000 , \"invalid extensions range base for $range = 0x%x\", $range);" ; + } + } + + WriteTest "}"; +} + sub CreateEnumSizeCheckTest { DefineTestName "enum_size_check_test"; @@ -742,7 +779,9 @@ sub CreateTests CreateStructUnionSizeCheckTest(); - CreateCustomRangeAll(); + CreateCustomRangeAllTest(); + + CreateCustomRangeBaseTest(); CreateExtensionRangeTest();