in meta/saisanitycheck.c [163:274]
void check_all_enums_values()
{
META_LOG_ENTER();
size_t i = 0;
for (; i < sai_metadata_all_enums_count; ++i)
{
const sai_enum_metadata_t* emd = sai_metadata_all_enums[i];
META_LOG_DEBUG("enum: %s", emd->name);
bool flags = false;
size_t j = 0;
int last = -1;
if (strcmp(emd->name, "sai_status_t") == 0)
{
/* status values are negative */
continue;
}
for (; j < emd->valuescount; ++j)
{
META_LOG_DEBUG(" value: %s", emd->valuesnames[j]);
int value = emd->values[j];
META_ASSERT_FALSE(value < 0, "enum values are negative");
META_ASSERT_TRUE(last < value, "enum values are not increasing");
if (j == 0)
{
if (value != 0)
{
flags = true;
if (is_flag_enum(emd))
{
/* ok, flags not need zero enum */
}
else
{
META_ENUM_ASSERT_FAIL(emd, "first enum should start with zero");
}
}
}
if (value != last + 1)
{
if (value == CUSTOM_ATTR_RANGE_START)
{
/*
* Object contains custom attributes in custom range, they
* still needs to be increasing by 1 but since those are
* not flags, attribute value can't be used as array index.
*/
META_ENUM_LOG_WARN(emd, "contains custom range attributes");
}
else if (value == EXTENSION_RANGE_START)
{
/*
* Object contains extensions attributes, they still needs
* to be increasing by 1 but since those are not flags,
* attribute value can't be used as array index.
*/
META_ENUM_LOG_WARN(emd, "contains extensions range attributes");
}
else
{
flags = true;
if (is_flag_enum(emd))
{
/* flags, ok */
}
else
{
META_ENUM_ASSERT_FAIL(emd, "values are not increasing by 1: last: %d current: %d, should be marked as @flags?", last, value);
}
}
}
last = emd->values[j];
if (value >= CUSTOM_ATTR_RANGE_START && value < EXTENSION_RANGE_START)
{
/* value is in custom range */
}
else if (value >= EXTENSION_RANGE_START)
{
/* value is in extensions range */
}
else
{
META_ASSERT_TRUE(value < 0x10000, "enum value is too big, range?");
}
}
META_ASSERT_TRUE(emd->values[j] == -1, "missing guard at the end of enum");
if (emd->valuescount > 0 && flags != emd->containsflags)
{
META_ENUM_ASSERT_FAIL(emd, "enum flags: %d but declared as %d", flags, emd->containsflags);
}
}
}