Skip to content

Commit

Permalink
Add custom range base enums for api and object_type (#2112)
Browse files Browse the repository at this point in the history
Also include metadata test for validation
  • Loading branch information
kcudnik authored Nov 22, 2024
1 parent 4820582 commit 5f75d99
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
5 changes: 5 additions & 0 deletions inc/sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions inc/saitypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
55 changes: 47 additions & 8 deletions meta/test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ sub CreateCustomRangeTest
WriteTest "}";
}

sub CreateCustomRangeAll
sub CreateCustomRangeAllTest
{
DefineTestName "custom_range_all_test";

Expand All @@ -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$/;
}
Expand All @@ -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";
Expand Down Expand Up @@ -742,7 +779,9 @@ sub CreateTests

CreateStructUnionSizeCheckTest();

CreateCustomRangeAll();
CreateCustomRangeAllTest();

CreateCustomRangeBaseTest();

CreateExtensionRangeTest();

Expand Down

0 comments on commit 5f75d99

Please sign in to comment.