Skip to content

Commit

Permalink
[meta] Add support for ignored attribute names (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Apr 13, 2021
1 parent 875fec7 commit 575ea81
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
10 changes: 10 additions & 0 deletions meta/parse.pl
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ sub ProcessEnumSection
{
LogInfo "Ignoring $enumvaluename";

my $initializer = $ev->{initializer}[0];

if ($initializer =~ /^= (SAI_\w+)$/)
{
}
else
{
LogWarning "Enum $enumvaluename is ignored, but initializer is '$initializer' not in form '= SAI_\\w+'";
}

# process ignore attributes

if (not defined $SAI_ENUMS{$enumtypename}{ignoreval})
Expand Down
43 changes: 43 additions & 0 deletions meta/saimetadatautils.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,49 @@ const sai_attr_metadata_t* sai_metadata_get_attr_metadata_by_attr_id_name(
return NULL;
}

const sai_attr_metadata_t* sai_metadata_get_ignored_attr_metadata_by_attr_id_name(
_In_ const char *attr_id_name)
{
if (attr_id_name == NULL)
{
return NULL;
}

sai_object_type_t ot;

/*
* Since we don't have list of ignored attributes, enumerate all objects
* and attribute enums to find ignored values.
*/

for (ot = SAI_OBJECT_TYPE_NULL; ot < SAI_OBJECT_TYPE_EXTENSIONS_MAX; ot++)
{
const sai_object_type_info_t* oti = sai_metadata_get_object_type_info(ot);

if (oti == NULL)
continue;

const sai_enum_metadata_t* em = oti->enummetadata;

if (em->ignorevaluesnames)
{
size_t i;

for (i = 0; em->ignorevaluesnames[i] != NULL; i++)
{
if (strcmp(attr_id_name, em->ignorevaluesnames[i]) == 0)
{
const char* name = sai_metadata_get_enum_value_name(em, em->ignorevalues[i]);

return sai_metadata_get_attr_metadata_by_attr_id_name(name);
}
}
}
}

return NULL;
}

const char* sai_metadata_get_enum_value_name(
_In_ const sai_enum_metadata_t* metadata,
_In_ int value)
Expand Down
10 changes: 10 additions & 0 deletions meta/saimetadatautils.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ extern const sai_attr_metadata_t* sai_metadata_get_attr_metadata(
extern const sai_attr_metadata_t* sai_metadata_get_attr_metadata_by_attr_id_name(
_In_ const char *attr_id_name);

/**
* @brief Gets ignored attribute metadata based on attribute id name
*
* @param[in] attr_id_name Attribute id name
*
* @return Pointer to object metadata or NULL in case of failure
*/
extern const sai_attr_metadata_t* sai_metadata_get_ignored_attr_metadata_by_attr_id_name(
_In_ const char *attr_id_name);

/**
* @brief Gets string representation of enum value
*
Expand Down
18 changes: 18 additions & 0 deletions meta/saisanitycheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -4701,6 +4701,23 @@ void check_all_object_infos()
META_ASSERT_TRUE((size_t)SAI_OBJECT_TYPE_EXTENSIONS_MAX == (size_t)SAI_OBJECT_TYPE_EXTENSIONS_RANGE_END, "must be equal");
}

void check_ignored_attributes()
{
META_LOG_ENTER();

META_ASSERT_NULL(sai_metadata_get_attr_metadata_by_attr_id_name("SAI_BUFFER_PROFILE_ATTR_BUFFER_SIZE"));

const sai_attr_metadata_t* meta = sai_metadata_get_ignored_attr_metadata_by_attr_id_name("SAI_BUFFER_PROFILE_ATTR_BUFFER_SIZE");

if (meta == NULL)
{
META_ASSERT_FAIL("Failed to find ignored attribute SAI_BUFFER_PROFILE_ATTR_BUFFER_SIZE");
}

META_ASSERT_TRUE(strcmp(meta->attridname, "SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE") == 0,
"expected attribute was SAI_BUFFER_PROFILE_ATTR_RESERVED_BUFFER_SIZE");
}

int main(int argc, char **argv)
{
debug = (argc > 1);
Expand Down Expand Up @@ -4739,6 +4756,7 @@ int main(int argc, char **argv)
check_switch_pointers_list();
check_defines();
check_all_object_infos();
check_ignored_attributes();

SAI_META_LOG_DEBUG("log test");

Expand Down

0 comments on commit 575ea81

Please sign in to comment.