.gitignore: add some missing files
[babeltrace.git] / src / lib / assert-cond.h
index 2c89d8926734761e089057b16ac185fa7198dbf9..f73cfb97ebd5592a4506d287607ba014e9feebd4 100644 (file)
@@ -5,10 +5,13 @@
  * Copyright (c) 2018-2020 Philippe Proulx <pproulx@efficios.com>
  */
 
  * Copyright (c) 2018-2020 Philippe Proulx <pproulx@efficios.com>
  */
 
-#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 "assert-cond-base.h"
+#include "trace-ir/trace-class.h" /* IWYU pragma: keep */
+
+#include <inttypes.h>
 
 /*
  * Asserts that a given variable `_obj` named `_obj_name` (capitalized)
 
 /*
  * Asserts that a given variable `_obj` named `_obj_name` (capitalized)
 #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_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))
 
 #define _BT_ASSERT_PRE_FC_HAS_TYPE_COND(_fc, _type)                    \
        (((const struct bt_field_class *) (_fc))->type == (_type))
 
                _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_COND(_fc),        \
                _BT_ASSERT_PRE_FC_IS_VARIANT_WITH_SEL_FMT(_name), (_fc))
 
                _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),                \
 #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),                \
        BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_FC_ID, (_fc),             \
                _BT_ASSERT_PRE_FC_NAME)
 
        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)
 #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)
        BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_VAR_FC_OPT_ID, (_fc), \
                _BT_ASSERT_PRE_VAR_FC_OPT_NAME)
 
        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"
 
 #define _BT_ASSERT_PRE_FP_NAME "Field path"
 #define _BT_ASSERT_PRE_FP_ID   "field-path"
 
        BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_FP_ID, (_fp),         \
                _BT_ASSERT_PRE_FP_NAME)
 
        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))
 
                ((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,                 \
 #define BT_ASSERT_PRE_DEV_FIELD_IS_UNSIGNED_INT(_field_id, _field, _name) \
        BT_ASSERT_PRE_DEV(                                              \
                "is-unsigned-integer-field:" _field_id,                 \
                _name " is not a signed integer field: %![field-]+f",   \
                (_field))
 
                _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))
 
                "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,                    \
 #define BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(_field_id, _field, _name) \
        BT_ASSERT_PRE_DEV(                                              \
                "is-dynamic-array-field:" _field_id,                    \
                ((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))
 
                ((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),                                \
 #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),                                \
        BT_ASSERT_PRE_NON_NULL(_BT_ASSERT_PRE_FIELD_ID, (_field),       \
                _BT_ASSERT_PRE_FIELD_NAME)
 
        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)
 #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)
        BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_GRAPH_ID, (_graph),   \
                _BT_ASSERT_PRE_GRAPH_NAME)
 
        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"
 
 #define _BT_ASSERT_PRE_INTR_NAME       "Interrupter"
 #define _BT_ASSERT_PRE_INTR_ID         "interrupter"
 
        BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_NAME_ID, (_name),     \
                _BT_ASSERT_PRE_NAME_NAME)
 
        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"
 
 #define _BT_ASSERT_PRE_DESCR_NAME      "Description"
 #define _BT_ASSERT_PRE_DESCR_ID                "description"
 
        BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_UUID_ID, (_uuid),     \
                _BT_ASSERT_PRE_UUID_NAME)
 
        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"
 
 #define _BT_ASSERT_PRE_KEY_NAME        "Key"
 #define _BT_ASSERT_PRE_KEY_ID  "key"
 
        BT_ASSERT_PRE_DEV_NON_NULL(_BT_ASSERT_PRE_KEY_ID, (_key),       \
                _BT_ASSERT_PRE_KEY_NAME)
 
        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 */
This page took 0.036817 seconds and 4 git commands to generate.