void check_object_infos()

in meta/saisanitycheck.c [3563:3692]


void check_object_infos()
{
    META_LOG_ENTER();

    size_t i = 1;

    META_ASSERT_NULL(sai_metadata_all_object_type_infos[0]);

    for (; sai_metadata_all_object_type_infos[i] != NULL; ++i)
    {
        const sai_object_type_info_t* info = sai_metadata_all_object_type_infos[i];

        META_ASSERT_NOT_NULL(info->enummetadata);

        META_ASSERT_NOT_NULL(info->objecttypename);

        META_LOG_DEBUG("processing object type: %s", sai_metadata_get_object_type_name(info->objecttype));

        META_ASSERT_TRUE(info->attridstart == 0, "attribute enum start should be zero");
        META_ASSERT_TRUE(info->attridend > 0, "attribute enum end must be > 0");

        const sai_attr_metadata_t* const* const meta = info->attrmetadata;

        META_ASSERT_NOT_NULL(meta);

        size_t index = 0;

        int last = -1;

        /* check all listed attributes under this object type */

        bool has_extensions_attrs = false;

        bool has_custom_range_attrs = false;

        for (; meta[index] != NULL; ++index)
        {
            const sai_attr_metadata_t* am = meta[index];

            META_ASSERT_TRUE((int)am->attrid >= 0, "attribute must be non negative");
            META_ASSERT_TRUE(last < (int)am->attrid, "attributes are not increasing");

            if (last + 1 != (int)am->attrid)
            {
                if (am->attrid == 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.
                     */

                    has_custom_range_attrs = true;
                }
                else if (am->attrid == EXTENSION_RANGE_START)
                {
                    has_extensions_attrs = true;
                }
                else
                {
                    if (is_flag_enum(info->enummetadata))
                    {
                        /* flags, ok */
                    }
                    else
                    {
                        META_MD_ASSERT_FAIL(am, "attr id is not increasing by 1: prev %d, curr %d", last, am->attrid);
                    }
                }
            }

            if (am->isextensionattr)
            {
                has_extensions_attrs = true;
            }

            last = (int)am->attrid;

            if (am->attrid >= info->attridstart &&
                    am->attrid < info->attridend)
            {
                continue;
            }

            if (am->attrid >= CUSTOM_ATTR_RANGE_START)
            {
                /*
                 * Attribute ID is in custom range, so it will not be in
                 * regular start .. end range.
                 */

                continue;
            }

            if (am->attrid >= info->attridend && am->isextensionattr)
            {
                /* extensions attribute id can be beyond attr id end range */
                continue;
            }

            META_MD_ASSERT_FAIL(am, "attr is is not in start .. end range");
        }

        META_ASSERT_NOT_NULL(info->enummetadata);

        if (index != info->attridend)
        {
            if (is_flag_enum(info->enummetadata))
            {
                /* ok, flags */
            }
            else if (has_extensions_attrs)
            {
                /* ok, extension attribute */
            }
            else if (has_custom_range_attrs)
            {
                /* ok, custom range attributes */
            }
            else
            {
                META_ENUM_ASSERT_FAIL(info->enummetadata, "end of attributes don't match attr count on %s",
                        sai_metadata_get_object_type_name(info->objecttype));
            }
        }
    }

    /* guard */
    META_ASSERT_NULL(sai_metadata_all_object_type_infos[i]);
}