X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Fassert-cond.h;h=4868c48c07fd3738912b8a1d6afaf3c02a698b86;hb=HEAD;hp=411f1364b786deb14805bd2c7a542164597b8bce;hpb=1778c2a4134647150b199b2b57130817144446b0;p=babeltrace.git diff --git a/src/lib/assert-cond.h b/src/lib/assert-cond.h index 411f1364..f73cfb97 100644 --- a/src/lib/assert-cond.h +++ b/src/lib/assert-cond.h @@ -5,10 +5,13 @@ * Copyright (c) 2018-2020 Philippe Proulx */ -#ifndef BABELTRACE_ASSERT_COND_INTERNAL_H -#define BABELTRACE_ASSERT_COND_INTERNAL_H +#ifndef BABELTRACE_LIB_ASSERT_COND_H +#define BABELTRACE_LIB_ASSERT_COND_H #include "assert-cond-base.h" +#include "trace-ir/trace-class.h" /* IWYU pragma: keep */ + +#include /* * Asserts that a given variable `_obj` named `_obj_name` (capitalized) @@ -17,7 +20,7 @@ */ #define BT_ASSERT_PRE_NON_NULL_FROM_FUNC(_func, _obj_id, _obj, _obj_name) \ BT_ASSERT_PRE_FROM_FUNC(_func, "not-null:" _obj_id, (_obj), \ - "%s is NULL: ", _obj_name) + "%s is NULL.", _obj_name) #define BT_ASSERT_PRE_NON_NULL(_obj_id, _obj, _obj_name) \ BT_ASSERT_PRE_NON_NULL_FROM_FUNC(__func__, _obj_id, (_obj), _obj_name) @@ -356,6 +359,15 @@ #define _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_ID(_fc_id) \ "is-variant-field-class-with-selector:" _fc_id +#define _BT_ASSERT_PRE_FC_IS_BLOB_ID(_fc_id) \ + "is-blob-field-class:" _fc_id + +#define _BT_ASSERT_PRE_FC_IS_BLOB_COND(_fc) \ + bt_field_class_type_is((_fc)->type, BT_FIELD_CLASS_TYPE_BLOB) + +#define _BT_ASSERT_PRE_FC_IS_BLOB_FMT(_name) \ + _name " is not a BLOB field class: %![fc-]+F" + #define _BT_ASSERT_PRE_FC_HAS_TYPE_COND(_fc, _type) \ (((const struct bt_field_class *) (_fc))->type == (_type)) @@ -434,6 +446,12 @@ _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc), \ _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc)) +#define BT_ASSERT_PRE_FC_IS_BLOB(_fc_id, _fc, _name) \ + BT_ASSERT_PRE( \ + _BT_ASSERT_PRE_FC_IS_BLOB_ID(_fc_id), \ + _BT_ASSERT_PRE_FC_IS_BLOB_COND(_fc), \ + _BT_ASSERT_PRE_FC_IS_BLOB_FMT(_name), (_fc)) + #define BT_ASSERT_PRE_FC_HAS_TYPE_FROM_FUNC(_func, _fc_id, _fc, _type_id, _type, _name) \ BT_ASSERT_PRE_FROM_FUNC(_func, \ _BT_ASSERT_PRE_FC_HAS_TYPE_ID(_fc_id, _type_id), \ @@ -532,6 +550,13 @@ BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_FC_ID, (_fc), \ _BT_ASSERT_PRE_FC_NAME) +#define _BT_ASSERT_PRE_SELECTOR_FC_NAME "Selector field class" +#define _BT_ASSERT_PRE_SELECTOR_FC_ID "selector-field-class" + +#define BT_ASSERT_PRE_SELECTOR_FC_NON_NULL(_fc) \ + BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_SELECTOR_FC_ID, (_fc), \ + _BT_ASSERT_PRE_SELECTOR_FC_NAME) + #define BT_ASSERT_PRE_DEV_FC_NON_NULL(_fc) \ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_FC_ID, (_fc), \ _BT_ASSERT_PRE_FC_NAME) @@ -558,6 +583,31 @@ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_VAR_FC_OPT_ID, (_fc), \ _BT_ASSERT_PRE_VAR_FC_OPT_NAME) +/* Field location */ +#define _BT_ASSERT_PRE_FL_NAME "Field location" +#define _BT_ASSERT_PRE_FL_ID "field-location" + +/* Asserts that `_fl` is non-NULL */ +#define BT_ASSERT_PRE_FL_NON_NULL(_fl) \ + BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_FL_ID, (_fl), \ + _BT_ASSERT_PRE_FL_NAME) + +#define _BT_ASSERT_PRE_SELECTOR_FL_NAME "Selector field location" +#define _BT_ASSERT_PRE_SELECTOR_FL_ID "selector-field-location" + +/* Asserts that `_fl` is non-NULL */ +#define BT_ASSERT_PRE_SELECTOR_FL_NON_NULL(_fl) \ + BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_SELECTOR_FL_ID, (_fl), \ + _BT_ASSERT_PRE_SELECTOR_FL_NAME) + +#define _BT_ASSERT_PRE_LENGTH_FL_NAME "Length field location" +#define _BT_ASSERT_PRE_LENGTH_FL_ID "length-field-location" + +/* Asserts that `_fl` is non-NULL */ +#define BT_ASSERT_PRE_LENGTH_FL_NON_NULL(_fl) \ + BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_LENGTH_FL_ID, (_fl), \ + _BT_ASSERT_PRE_LENGTH_FL_NAME) + #define _BT_ASSERT_PRE_FP_NAME "Field path" #define _BT_ASSERT_PRE_FP_ID "field-path" @@ -569,13 +619,17 @@ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_FP_ID, (_fp), \ _BT_ASSERT_PRE_FP_NAME) -#define BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(_field_id, _field, _cls_type_id, _cls_type, _name) \ - BT_ASSERT_PRE_DEV("is-" _cls_type_id ":" _field_id, \ +#define BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(_func, _field_id, _field, _cls_type_id, _cls_type, _name) \ + BT_ASSERT_PRE_DEV_FROM_FUNC(_func, "is-" _cls_type_id ":" _field_id, \ ((const struct bt_field *) (_field))->class->type == (_cls_type), \ _name " has the wrong class type: expected-class-type=%s, " \ "%![field-]+f", \ bt_common_field_class_type_string(_cls_type), (_field)) +#define BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(_field_id, _field, _cls_type_id, _cls_type, _name) \ + BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE_FROM_FUNC(__func__, \ + _field_id, (_field), _cls_type_id, _cls_type, _name) + #define BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(_field_id, _field, _name) \ BT_ASSERT_PRE_DEV( \ "is-unsigned-integer-field:" _field_id, \ @@ -592,14 +646,18 @@ _name " is not a signed integer field: %![field-]+f", \ (_field)) -#define BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(_field_id, _field, _name) \ - BT_ASSERT_PRE_DEV( \ +#define BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY_FROM_FUNC(_func, _field_id, _field, _name) \ + BT_ASSERT_PRE_DEV_FROM_FUNC(_func, \ "is-array-field:" _field_id, \ ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \ ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD || \ ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD, \ _name " is not an array field: %![field-]+f", (_field)) +#define BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY(_field_id, _field, _name) \ + BT_ASSERT_PRE_DEV_FIELD_IS_ARRAY_FROM_FUNC(__func__, _field_id, \ + (_field), _name) + #define BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(_field_id, _field, _name) \ BT_ASSERT_PRE_DEV( \ "is-dynamic-array-field:" _field_id, \ @@ -624,6 +682,18 @@ ((const struct bt_field *) (_field))->class->type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, \ _name " is not a variant field: %![field-]+f", (_field)) +#define BT_ASSERT_PRE_DEV_FIELD_IS_BLOB(_field_id, _field, _name) \ + BT_ASSERT_PRE_DEV( \ + "is-blob-field:" _field_id, \ + bt_field_class_type_is(_field->class->type, BT_FIELD_CLASS_TYPE_BLOB), \ + _name "is not a BLOB field: %![field-]+f", (_field)) + +#define BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_BLOB(_field_id, _field, _name) \ + BT_ASSERT_PRE_DEV( \ + "is-dynamic-blob-field:" _field_id, \ + bt_field_class_type_is(_field->class->type, BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB), \ + _name "is not a dynamic BLOB field: %![field-]+f", (_field)) + #define BT_ASSERT_PRE_DEV_FIELD_IS_SET(_field_id, _field) \ BT_ASSERT_PRE_DEV("is-field-set:" _field_id, \ bt_field_is_set(_field), \ @@ -636,6 +706,11 @@ BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_FIELD_ID, (_field), \ _BT_ASSERT_PRE_FIELD_NAME) +#define BT_ASSERT_PRE_DEV_FIELD_NON_NULL_FROM_FUNC(_func, _field) \ + BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(_func, \ + _BT_ASSERT_PRE_FIELD_ID, (_field), \ + _BT_ASSERT_PRE_FIELD_NAME) + #define BT_ASSERT_PRE_DEV_FIELD_NON_NULL(_field) \ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_FIELD_ID, (_field), \ _BT_ASSERT_PRE_FIELD_NAME) @@ -817,14 +892,14 @@ _BT_ASSERT_PRE_MSG_HAS_TYPE_ID(_msg_id, _type_id), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_COND((_msg), (_type)), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_FMT, \ - bt_message_type_string(_type), (_msg)) + bt_common_message_type_string(_type), (_msg)) #define BT_ASSERT_PRE_DEV_MSG_HAS_TYPE(_msg_id, _msg, _type_id, _type) \ BT_ASSERT_PRE_DEV( \ _BT_ASSERT_PRE_MSG_HAS_TYPE_ID(_msg_id, _type_id), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_COND((_msg), (_type)), \ _BT_ASSERT_PRE_MSG_HAS_TYPE_FMT, \ - bt_message_type_string(_type), (_msg)) + bt_common_message_type_string(_type), (_msg)) #define _BT_ASSERT_PRE_MSG_NAME "Message" #define _BT_ASSERT_PRE_MSG_ID "message" @@ -931,6 +1006,115 @@ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_GRAPH_ID, (_graph), \ _BT_ASSERT_PRE_GRAPH_NAME) +#define _BT_ASSERT_PRE_MIP_VERSION_VALID_ID "mip-version-is-valid" + +/* Asserts that the MIP version `_mip_version` is equal to `_val`. */ +#define BT_ASSERT_PRE_MIP_VERSION_EQ(_mip_version, _val) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_MIP_VERSION_VALID_ID, \ + _mip_version == _val, \ + "MIP version is not equal to %" PRIu64, _val) + +/* Asserts that the MIP version `_mip_version` is equal to `_val`. */ +#define BT_ASSERT_PRE_DEV_MIP_VERSION_EQ(_mip_version, _val) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_MIP_VERSION_VALID_ID, \ + _mip_version == _val, \ + "MIP version is not equal to %" PRIu64, _val) + +/* + * Asserts that the given MIP version `_mip_version` is greater than or equal + * to `_val`. + */ +#define BT_ASSERT_PRE_MIP_VERSION_GE(_mip_version, _val) \ + BT_ASSERT_PRE(_BT_ASSERT_PRE_MIP_VERSION_VALID_ID, \ + _mip_version >= _val, \ + "MIP version is less than %" PRIu64, _val) + +/* + * Asserts that the given MIP version `_mip_version` is greater than or equal + * to `_val`. + */ +#define BT_ASSERT_PRE_DEV_MIP_VERSION_GE(_mip_version, _val) \ + BT_ASSERT_PRE_DEV(_BT_ASSERT_PRE_MIP_VERSION_VALID_ID, \ + _mip_version >= _val, \ + "MIP version is less than %" PRIu64, _val) + +/* + * Asserts that the effective MIP version for `_clock_class` is equal to `_val`. + */ +#define BT_ASSERT_PRE_CC_MIP_VERSION_EQ(_clock_class, _val) \ + BT_ASSERT_PRE_MIP_VERSION_EQ((_clock_class)->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_clock_class` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_CC_MIP_VERSION_GE(_clock_class, _val) \ + BT_ASSERT_PRE_MIP_VERSION_GE((_clock_class)->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_trace_class` is equal to `_val`. + */ +#define BT_ASSERT_PRE_TC_MIP_VERSION_EQ(_trace_class, _val) \ + BT_ASSERT_PRE_MIP_VERSION_EQ((_trace_class)->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_trace_class` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_TC_MIP_VERSION_GE(_trace_class, _val) \ + BT_ASSERT_PRE_MIP_VERSION_GE((_trace_class)->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_trace` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_TRACE_MIP_VERSION_GE(_trace, _val) \ + BT_ASSERT_PRE_MIP_VERSION_GE((_trace)->class->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_stream_class` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_SC_MIP_VERSION_GE(_stream_class, _val) \ + BT_ASSERT_PRE_TC_MIP_VERSION_GE( \ + bt_stream_class_borrow_trace_class_inline(_stream_class), \ + _val) + +/* + * Asserts that the effective MIP version for `_event_class` is greater than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_EC_MIP_VERSION_GE(_event_class, _val) \ + BT_ASSERT_PRE_SC_MIP_VERSION_GE( \ + bt_event_class_borrow_stream_class_inline(_event_class), \ + _val) + +/* + * Asserts that the effective MIP version for `_field_class` is equal to `_val`. + */ +#define BT_ASSERT_PRE_FC_MIP_VERSION_EQ(_field_class, _val) \ + BT_ASSERT_PRE_MIP_VERSION_EQ((_field_class)->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_field_class` is equal to `_val`. + */ +#define BT_ASSERT_PRE_DEV_FC_MIP_VERSION_EQ(_field_class, _val) \ + BT_ASSERT_PRE_DEV_MIP_VERSION_EQ((_field_class)->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_field_class` is greator than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_FC_MIP_VERSION_GE(_field_class, _val) \ + BT_ASSERT_PRE_MIP_VERSION_GE((_field_class)->mip_version, _val) + +/* + * Asserts that the effective MIP version for `_field_class` is greator than or + * equal to `_val`. + */ +#define BT_ASSERT_PRE_DEV_FC_MIP_VERSION_GE(_field_class, _val) \ + BT_ASSERT_PRE_DEV_MIP_VERSION_GE((_field_class)->mip_version, _val) + #define _BT_ASSERT_PRE_INTR_NAME "Interrupter" #define _BT_ASSERT_PRE_INTR_ID "interrupter" @@ -1218,6 +1402,13 @@ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_NAME_ID, (_name), \ _BT_ASSERT_PRE_NAME_NAME) +#define _BT_ASSERT_PRE_NAMESPACE_NAME "Namespace" +#define _BT_ASSERT_PRE_NAMESPACE_ID "namespace" + +#define BT_ASSERT_PRE_NAMESPACE_NON_NULL(_namespace) \ + BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_NAMESPACE_ID, (_namespace), \ + _BT_ASSERT_PRE_NAMESPACE_NAME) + #define _BT_ASSERT_PRE_DESCR_NAME "Description" #define _BT_ASSERT_PRE_DESCR_ID "description" @@ -1240,6 +1431,13 @@ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_UUID_ID, (_uuid), \ _BT_ASSERT_PRE_UUID_NAME) +#define _BT_ASSERT_PRE_UID_NAME "Unique identifier" +#define _BT_ASSERT_PRE_UID_ID "uid" + +#define BT_ASSERT_PRE_UID_NON_NULL(_uid) \ + BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_UID_ID, (_uid), \ + _BT_ASSERT_PRE_UID_NAME) + #define _BT_ASSERT_PRE_KEY_NAME "Key" #define _BT_ASSERT_PRE_KEY_ID "key" @@ -1255,4 +1453,4 @@ BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_KEY_ID, (_key), \ _BT_ASSERT_PRE_KEY_NAME) -#endif /* BABELTRACE_ASSERT_COND_INTERNAL_H */ +#endif /* BABELTRACE_LIB_ASSERT_COND_H */