bt_trace_class_create(): accept mandatory self component
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 10 Dec 2018 13:03:58 +0000 (08:03 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
This patch makes bt_trace_class_create() accept a mandatory self
component. The self component parameter is not used now, but it could be
in the future to control allocation (object pooling) and for
bookkeeping, as well as to have a system where a new trace class within
the graph can lead to notifying other components about it so they can
prepare associated data.

The `ctf` plugin is changed so that it does not require a trace class to
create packet indexes. This is required because the `trace-info` query
requires packet indexes to exist, but there's no self component in this
context to create a trace class.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
18 files changed:
include/babeltrace/trace-ir/trace-class.h
lib/trace-ir/trace-class.c
plugins/ctf/common/metadata/ast.h
plugins/ctf/common/metadata/decoder.c
plugins/ctf/common/metadata/decoder.h
plugins/ctf/common/metadata/visitor-generate-ir.c
plugins/ctf/common/msg-iter/msg-iter.c
plugins/ctf/common/msg-iter/msg-iter.h
plugins/ctf/fs-src/data-stream-file.c
plugins/ctf/fs-src/data-stream-file.h
plugins/ctf/fs-src/fs.c
plugins/ctf/fs-src/fs.h
plugins/ctf/fs-src/metadata.c
plugins/ctf/fs-src/metadata.h
plugins/ctf/fs-src/query.c
plugins/text/dmesg/dmesg.c
tests/lib/test_bt_message_iterator.c
tests/lib/test_trace_ir_ref.c

index 5cbabc0330ebc85fa6d5ad27952552221ededbe7..b253eb2ede8f89bd376a1d43d640f286b3c1d69e 100644 (file)
  * http://www.efficios.com/ctf
  */
 
-/* For bt_bool, bt_uuid, bt_trace_class, bt_stream_class, bt_field_class */
+/*
+ * For bt_bool, bt_uuid, bt_trace_class, bt_stream_class,
+ * bt_field_class, bt_self_component
+ */
 #include <babeltrace/types.h>
 
 /* For bt_trace_class_status */
@@ -39,7 +42,7 @@
 extern "C" {
 #endif
 
-extern bt_trace_class *bt_trace_class_create(void);
+extern bt_trace_class *bt_trace_class_create(bt_self_component *self_comp);
 
 extern void bt_trace_class_set_assigns_automatic_stream_class_id(
                bt_trace_class *trace_class, bt_bool value);
index b072bad8d160256cfd26981b8b320a350940036c..78a7161bb56c2c632521115364bcf8cfcf80ad00 100644 (file)
@@ -96,11 +96,12 @@ void free_packet_header_field(struct bt_field_wrapper *field_wrapper,
        bt_field_wrapper_destroy(field_wrapper);
 }
 
-struct bt_trace_class *bt_trace_class_create(void)
+struct bt_trace_class *bt_trace_class_create(bt_self_component *self_comp)
 {
        struct bt_trace_class *tc = NULL;
        int ret;
 
+       BT_ASSERT_PRE_NON_NULL(self_comp, "Self component");
        BT_LOGD_STR("Creating default trace class object.");
        tc = g_new0(struct bt_trace_class, 1);
        if (!tc) {
index ef40333bfc290bdca9a5269594b4b7ce24a0c8af..b7a097c8f83099f4d084884496b22859afdb5add 100644 (file)
@@ -318,6 +318,7 @@ const char *node_type(struct ctf_node *node);
 
 BT_HIDDEN
 struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
+               bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *config);
 
 void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor);
index af1e1eda2d0d6ad05c4fb716f1b3e57c1fcf5e05..b17caf1f998ffb3ebadb94f30d792069efccbf62 100644 (file)
@@ -348,6 +348,7 @@ int ctf_metadata_decoder_packetized_file_stream_to_buf(
 
 BT_HIDDEN
 struct ctf_metadata_decoder *ctf_metadata_decoder_create(
+               bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *config)
 {
        struct ctf_metadata_decoder *mdec =
@@ -372,7 +373,7 @@ struct ctf_metadata_decoder *ctf_metadata_decoder_create(
        }
 
        mdec->config = *config;
-       mdec->visitor = ctf_visitor_generate_ir_create(config);
+       mdec->visitor = ctf_visitor_generate_ir_create(self_comp, config);
        if (!mdec->visitor) {
                BT_LOGE("Failed to create a CTF IR metadata AST visitor: "
                        "mdec-addr=%p", mdec);
index 1edb548c7aaacf16609260df6b773bf5c63e2243..fac2f1d7ebaab4a964112f268bb6948786eadccd 100644 (file)
@@ -45,6 +45,7 @@ struct ctf_metadata_decoder_config {
  */
 BT_HIDDEN
 struct ctf_metadata_decoder *ctf_metadata_decoder_create(
+               bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *config);
 
 /*
index 71957e20a4051d0c320300fe4ccecf5ef7f26b69..e009b4437aa0a40ec170e514e3b98f0a9e8540f0 100644 (file)
@@ -570,7 +570,7 @@ end:
  * @returns    New visitor context, or NULL on error
  */
 static
-struct ctx *ctx_create(
+struct ctx *ctx_create(bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *decoder_config)
 {
        struct ctx *ctx = NULL;
@@ -583,10 +583,13 @@ struct ctx *ctx_create(
                goto error;
        }
 
-       ctx->trace_class = bt_trace_class_create();
-       if (!ctx->trace_class) {
-               BT_LOGE_STR("Cannot create empty trace class.");
-               goto error;
+       if (self_comp) {
+               ctx->trace_class = bt_trace_class_create(
+                       bt_self_component_source_as_self_component(self_comp));
+               if (!ctx->trace_class) {
+                       BT_LOGE_STR("Cannot create empty trace class.");
+                       goto error;
+               }
        }
 
        ctx->ctf_tc = ctf_trace_class_create();
@@ -4802,12 +4805,13 @@ end:
 
 BT_HIDDEN
 struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
+               bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *decoder_config)
 {
        struct ctx *ctx = NULL;
 
        /* Create visitor's context */
-       ctx = ctx_create(decoder_config);
+       ctx = ctx_create(self_comp, decoder_config);
        if (!ctx) {
                BT_LOGE_STR("Cannot create visitor's context.");
                goto error;
@@ -4836,8 +4840,11 @@ bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(
        struct ctx *ctx = (void *) visitor;
 
        BT_ASSERT(ctx);
-       BT_ASSERT(ctx->trace_class);
-       bt_trace_class_get_ref(ctx->trace_class);
+
+       if (ctx->trace_class) {
+               bt_trace_class_get_ref(ctx->trace_class);
+       }
+
        return ctx->trace_class;
 }
 
@@ -5042,11 +5049,19 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                goto end;
        }
 
-       /* Update "in IR" for field classes */
-       ret = ctf_trace_class_update_in_ir(ctx->ctf_tc);
-       if (ret) {
-               ret = -EINVAL;
-               goto end;
+       if (ctx->trace_class) {
+               /*
+                * Update "in IR" for field classes.
+                *
+                * If we have no IR trace class, then we'll have no way
+                * to create IR fields anyway, so we leave all the
+                * `in_ir` members false.
+                */
+               ret = ctf_trace_class_update_in_ir(ctx->ctf_tc);
+               if (ret) {
+                       ret = -EINVAL;
+                       goto end;
+               }
        }
 
        /* Update saved value indexes */
@@ -5063,11 +5078,13 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                goto end;
        }
 
-       /* Copy new CTF metadata -> new IR metadata */
-       ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc);
-       if (ret) {
-               ret = -EINVAL;
-               goto end;
+       if (ctx->trace_class) {
+               /* Copy new CTF metadata -> new IR metadata */
+               ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc);
+               if (ret) {
+                       ret = -EINVAL;
+                       goto end;
+               }
        }
 
 end:
index 8bed03784ce3503c25c61627066efda7c79219a3..7bd9192b0032d1f94a66800a031df537e73669ae 100644 (file)
@@ -120,6 +120,9 @@ struct bt_msg_iter {
        bool done_filling_string;
 
        /* Trace and classes */
+       /* True to set IR fields */
+       bool set_ir_fields;
+
        struct {
                struct ctf_trace_class *tc;
                struct ctf_stream_class *sc;
@@ -909,7 +912,7 @@ enum bt_msg_iter_status read_packet_context_begin_state(
                 * packet is created from a stream, and this API must be
                 * able to return the packet header and context fields
                 * without creating a stream
-                * (bt_msg_iter_borrow_packet_header_context_fields()).
+                * (read_packet_header_context_fields()).
                 */
                notit->packet_context_field =
                        bt_packet_context_field_create(
@@ -1946,7 +1949,11 @@ enum bt_bfcr_status bfcr_floating_point_cb(double value,
                "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
                "fc-type=%d, fc-in-ir=%d, value=%f",
                notit, notit->bfcr, fc, fc->type, fc->in_ir, value);
-       BT_ASSERT(fc->in_ir);
+
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
+
        field = borrow_next_field(notit);
        BT_ASSERT(field);
        BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
@@ -1954,6 +1961,8 @@ enum bt_bfcr_status bfcr_floating_point_cb(double value,
                  BT_FIELD_CLASS_TYPE_REAL);
        bt_field_real_set_value(field, value);
        stack_top(notit->stack)->index++;
+
+end:
        return status;
 }
 
@@ -1970,7 +1979,10 @@ enum bt_bfcr_status bfcr_string_begin_cb(
                "fc-type=%d, fc-in-ir=%d",
                notit, notit->bfcr, fc, fc->type, fc->in_ir);
 
-       BT_ASSERT(fc->in_ir);
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
+
        field = borrow_next_field(notit);
        BT_ASSERT(field);
        BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
@@ -1985,6 +1997,8 @@ enum bt_bfcr_status bfcr_string_begin_cb(
         * subsequent call to bfcr_string_end_cb().
         */
        stack_push(notit->stack, field);
+
+end:
        return BT_BFCR_STATUS_OK;
 }
 
@@ -2002,7 +2016,11 @@ enum bt_bfcr_status bfcr_string_cb(const char *value,
                "fc-type=%d, fc-in-ir=%d, string-length=%zu",
                notit, notit->bfcr, fc, fc->type, fc->in_ir,
                len);
-       BT_ASSERT(fc->in_ir);
+
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
+
        field = stack_top(notit->stack)->base;
        BT_ASSERT(field);
 
@@ -2030,13 +2048,18 @@ enum bt_bfcr_status bfcr_string_end_cb(
                "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
                "fc-type=%d, fc-in-ir=%d",
                notit, notit->bfcr, fc, fc->type, fc->in_ir);
-       BT_ASSERT(fc->in_ir);
+
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
 
        /* Pop string field */
        stack_pop(notit->stack);
 
        /* Go to next field */
        stack_top(notit->stack)->index++;
+
+end:
        return BT_BFCR_STATUS_OK;
 }
 
@@ -2633,11 +2656,9 @@ end:
        return status;
 }
 
-BT_HIDDEN
-enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
-               struct bt_msg_iter *notit,
-               bt_field **packet_header_field,
-               bt_field **packet_context_field)
+static
+enum bt_msg_iter_status read_packet_header_context_fields(
+               struct bt_msg_iter *notit)
 {
        int ret;
        enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
@@ -2646,7 +2667,7 @@ enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
 
        if (notit->state == STATE_EMIT_MSG_NEW_PACKET) {
                /* We're already there */
-               goto set_fields;
+               goto end;
        }
 
        while (true) {
@@ -2672,7 +2693,7 @@ enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
                         * Packet header and context fields are
                         * potentially decoded (or they don't exist).
                         */
-                       goto set_fields;
+                       goto end;
                case STATE_INIT:
                case STATE_EMIT_MSG_NEW_STREAM:
                case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
@@ -2694,22 +2715,13 @@ enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
                }
        }
 
-set_fields:
+end:
        ret = set_current_packet_content_sizes(notit);
        if (ret) {
                status = BT_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
-       if (packet_header_field) {
-               *packet_header_field = notit->dscopes.trace_packet_header;
-       }
-
-       if (packet_context_field) {
-               *packet_context_field = notit->dscopes.stream_packet_context;
-       }
-
-end:
        return status;
 }
 
@@ -2788,8 +2800,14 @@ enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
                struct bt_msg_iter *notit,
                struct bt_msg_iter_packet_properties *props)
 {
+       enum bt_msg_iter_status status;
+
        BT_ASSERT(notit);
        BT_ASSERT(props);
+       status = read_packet_header_context_fields(notit);
+       if (status != BT_MSG_ITER_STATUS_OK) {
+               goto end;
+       }
 
        props->exp_packet_total_size =
                (uint64_t) notit->cur_exp_packet_total_size;
@@ -2802,5 +2820,7 @@ enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
        props->snapshots.packets = notit->snapshots.packets;
        props->snapshots.beginning_clock = notit->snapshots.beginning_clock;
        props->snapshots.end_clock = notit->snapshots.end_clock;
-       return BT_MSG_ITER_STATUS_OK;
+
+end:
+       return status;
 }
index 89028bbb5ce7f55c57121ce04f1c1dd3a398566c..269d6b28ee9cd293bcde5377de5de9ecd20e393b 100644 (file)
@@ -290,24 +290,6 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                bt_self_message_iterator *msg_iter,
                bt_message **message);
 
-/**
- * Returns the first packet header and context fields. This function
- * never needs to call the `borrow_stream()` medium operation because
- * it does not create packet or event objects.
- *
- * @param msg_iter             CTF message iterator
- * @param packet_header_field  Packet header field (\c NULL if there's
- *                             no packet header field)
- * @param packet_context_field Packet context field (\c NULL if there's
- *                             no packet context field)
- * @returns                    One of #bt_msg_iter_status values
- */
-BT_HIDDEN
-enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
-               struct bt_msg_iter *notit,
-               bt_field **packet_header_field,
-               bt_field **packet_context_field);
-
 struct bt_msg_iter_packet_properties {
        uint64_t exp_packet_total_size;
        uint64_t exp_packet_content_size;
index 3c4b0bfe67710776a9524d6d5dc6325e72020d94..517bfec6ade205f1bc1b8f8dcf3ffa9f28ebdfa1 100644 (file)
@@ -324,17 +324,12 @@ struct ctf_fs_ds_index *build_index_from_idx_file(
 
        BT_LOGD("Building index from .idx file of stream file %s",
                        ds_file->file->path->str);
-
-       ret = bt_msg_iter_borrow_packet_header_context_fields(
-               ds_file->msg_iter, NULL, NULL);
+       ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter, &props);
        if (ret) {
-               BT_LOGD_STR("Cannot borrow first packet's header and context "
-                       "fields.");
+               BT_LOGD_STR("Cannot read first packet's header and context fields.");
                goto error;
        }
 
-       ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter, &props);
-       BT_ASSERT(ret == 0);
        sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc,
                props.stream_class_id);
        BT_ASSERT(sc);
@@ -550,8 +545,8 @@ struct ctf_fs_ds_index *build_index_from_stream_file(
                struct ctf_fs_ds_index_entry *entry;
                struct bt_msg_iter_packet_properties props;
 
-               iter_status = bt_msg_iter_borrow_packet_header_context_fields(
-                       ds_file->msg_iter, NULL, NULL);
+               iter_status = bt_msg_iter_get_packet_properties(
+                       ds_file->msg_iter, &props);
                if (iter_status != BT_MSG_ITER_STATUS_OK) {
                        if (iter_status == BT_MSG_ITER_STATUS_EOF) {
                                break;
@@ -559,10 +554,6 @@ struct ctf_fs_ds_index *build_index_from_stream_file(
                        goto error;
                }
 
-               ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter,
-                       &props);
-               BT_ASSERT(ret == 0);
-
                current_packet_offset =
                        bt_msg_iter_get_current_packet_offset(
                                ds_file->msg_iter);
@@ -739,40 +730,6 @@ bt_message_iterator_status ctf_fs_ds_file_next(
        return status;
 }
 
-BT_HIDDEN
-int ctf_fs_ds_file_borrow_packet_header_context_fields(
-               struct ctf_fs_ds_file *ds_file,
-               bt_field **packet_header_field,
-               bt_field **packet_context_field)
-{
-       enum bt_msg_iter_status msg_iter_status;
-       int ret = 0;
-
-       BT_ASSERT(ds_file);
-       msg_iter_status = bt_msg_iter_borrow_packet_header_context_fields(
-               ds_file->msg_iter, packet_header_field, packet_context_field);
-       switch (msg_iter_status) {
-       case BT_MSG_ITER_STATUS_EOF:
-       case BT_MSG_ITER_STATUS_OK:
-               break;
-       case BT_MSG_ITER_STATUS_AGAIN:
-               abort();
-       case BT_MSG_ITER_STATUS_INVAL:
-       case BT_MSG_ITER_STATUS_ERROR:
-       default:
-               goto error;
-               break;
-       }
-
-       goto end;
-
-error:
-       ret = -1;
-
-end:
-       return ret;
-}
-
 BT_HIDDEN
 void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index)
 {
index 0ccba27ae95e8c36d75ddd4e8adb61814a49b714..05c1dc342c6f2b5a22b7e0e25e8c95ebade69501 100644 (file)
@@ -132,12 +132,6 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(
                struct bt_msg_iter *msg_iter,
                bt_stream *stream, const char *path);
 
-BT_HIDDEN
-int ctf_fs_ds_file_borrow_packet_header_context_fields(
-               struct ctf_fs_ds_file *ds_file,
-               bt_field **packet_header_field,
-               bt_field **packet_context_field);
-
 BT_HIDDEN
 void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream);
 
index b6e2fb4ffc97c91a78e734259ebcc14524a1197a..daaae12e5a3a4ce1de501db31c5ce78362f15855 100644 (file)
@@ -640,16 +640,13 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace,
                goto error;
        }
 
-       ret = ctf_fs_ds_file_borrow_packet_header_context_fields(ds_file,
-               NULL, NULL);
+       ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter, &props);
        if (ret) {
                BT_LOGE("Cannot get stream file's first packet's header and context fields (`%s`).",
                        path);
                goto error;
        }
 
-       ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter, &props);
-       BT_ASSERT(ret == 0);
        sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc,
                props.stream_class_id);
        BT_ASSERT(sc);
@@ -843,6 +840,10 @@ int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
                ctf_fs_file_destroy(file);
        }
 
+       if (!ctf_fs_trace->trace) {
+               goto end;
+       }
+
        /*
         * At this point, DS file groupes are created, but their
         * associated stream objects do not exist yet. This is because
@@ -962,7 +963,8 @@ end:
 }
 
 BT_HIDDEN
-struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name,
+struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component_source *self_comp,
+               const char *path, const char *name,
                struct ctf_fs_metadata_config *metadata_config)
 {
        struct ctf_fs_trace *ctf_fs_trace;
@@ -995,20 +997,25 @@ struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name,
                goto error;
        }
 
-       ret = ctf_fs_metadata_set_trace_class(ctf_fs_trace, metadata_config);
+       ret = ctf_fs_metadata_set_trace_class(self_comp,
+               ctf_fs_trace, metadata_config);
        if (ret) {
                goto error;
        }
 
-       ctf_fs_trace->trace =
-               bt_trace_create(ctf_fs_trace->metadata->trace_class);
-       if (!ctf_fs_trace->trace) {
-               goto error;
+       if (ctf_fs_trace->metadata->trace_class) {
+               ctf_fs_trace->trace =
+                       bt_trace_create(ctf_fs_trace->metadata->trace_class);
+               if (!ctf_fs_trace->trace) {
+                       goto error;
+               }
        }
 
-       ret = set_trace_name(ctf_fs_trace->trace, name);
-       if (ret) {
-               goto error;
+       if (ctf_fs_trace->trace) {
+               ret = set_trace_name(ctf_fs_trace->trace, name);
+               if (ret) {
+                       goto error;
+               }
        }
 
        ret = create_ds_file_groups(ctf_fs_trace);
@@ -1021,7 +1028,9 @@ struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name,
         * trace needs. There won't be any more. Therefore it is safe to
         * make this trace static.
         */
-       (void) bt_trace_make_static(ctf_fs_trace->trace);
+       if (ctf_fs_trace->trace) {
+               (void) bt_trace_make_static(ctf_fs_trace->trace);
+       }
 
        goto end;
 
@@ -1213,7 +1222,8 @@ GList *ctf_fs_create_trace_names(GList *trace_paths, const char *base_path) {
 }
 
 static
-int create_ctf_fs_traces(struct ctf_fs_component *ctf_fs,
+int create_ctf_fs_traces(bt_self_component_source *self_comp,
+               struct ctf_fs_component *ctf_fs,
                const char *path_param)
 {
        struct ctf_fs_trace *ctf_fs_trace = NULL;
@@ -1254,8 +1264,9 @@ int create_ctf_fs_traces(struct ctf_fs_component *ctf_fs,
                GString *trace_path = tp_node->data;
                GString *trace_name = tn_node->data;
 
-               ctf_fs_trace = ctf_fs_trace_create(trace_path->str,
-                               trace_name->str, &ctf_fs->metadata_config);
+               ctf_fs_trace = ctf_fs_trace_create(self_comp,
+                               trace_path->str, trace_name->str,
+                               &ctf_fs->metadata_config);
                if (!ctf_fs_trace) {
                        BT_LOGE("Cannot create trace for `%s`.",
                                trace_path->str);
@@ -1366,7 +1377,7 @@ struct ctf_fs_component *ctf_fs_create(
                goto error;
        }
 
-       if (create_ctf_fs_traces(ctf_fs, path_param)) {
+       if (create_ctf_fs_traces(self_comp, ctf_fs, path_param)) {
                goto error;
        }
 
index 3f36387f495d0e0f25c26713071b38c6a088bd34..56fe4891931ceccfbda0879a0fe284b880457e43 100644 (file)
@@ -170,7 +170,8 @@ bt_query_status ctf_fs_query(
                const bt_value **result);
 
 BT_HIDDEN
-struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name,
+struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component_source *self_comp,
+               const char *path, const char *name,
                struct ctf_fs_metadata_config *config);
 
 BT_HIDDEN
index 7d480d1685acc7033dcb22f153ac5b4ff732a893..628033be2517162bf01b5a02e8f342e96f7be188 100644 (file)
@@ -86,7 +86,10 @@ end:
        return file;
 }
 
-int ctf_fs_metadata_set_trace_class(struct ctf_fs_trace *ctf_fs_trace,
+BT_HIDDEN
+int ctf_fs_metadata_set_trace_class(
+               bt_self_component_source *self_comp,
+               struct ctf_fs_trace *ctf_fs_trace,
                struct ctf_fs_metadata_config *config)
 {
        int ret = 0;
@@ -103,7 +106,7 @@ int ctf_fs_metadata_set_trace_class(struct ctf_fs_trace *ctf_fs_trace,
                goto end;
        }
 
-       ctf_fs_trace->metadata->decoder = ctf_metadata_decoder_create(
+       ctf_fs_trace->metadata->decoder = ctf_metadata_decoder_create(self_comp,
                config ? &decoder_config : NULL);
        if (!ctf_fs_trace->metadata->decoder) {
                BT_LOGE("Cannot create metadata decoder object");
@@ -121,7 +124,7 @@ int ctf_fs_metadata_set_trace_class(struct ctf_fs_trace *ctf_fs_trace,
        ctf_fs_trace->metadata->trace_class =
                ctf_metadata_decoder_get_ir_trace_class(
                        ctf_fs_trace->metadata->decoder);
-       BT_ASSERT(ctf_fs_trace->metadata->trace_class);
+       BT_ASSERT(!self_comp || ctf_fs_trace->metadata->trace_class);
        ctf_fs_trace->metadata->tc =
                ctf_metadata_decoder_borrow_ctf_trace_class(
                        ctf_fs_trace->metadata->decoder);
@@ -132,12 +135,14 @@ end:
        return ret;
 }
 
+BT_HIDDEN
 int ctf_fs_metadata_init(struct ctf_fs_metadata *metadata)
 {
        /* Nothing to initialize for the moment. */
        return 0;
 }
 
+BT_HIDDEN
 void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata)
 {
        if (metadata->text) {
index 6e936e407bddb26cb08fafe672b35472dedad835..4d0e2eccef03fb22f2f1fca7bf534a2ae74fbc58 100644 (file)
@@ -45,7 +45,8 @@ BT_HIDDEN
 void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata);
 
 BT_HIDDEN
-int ctf_fs_metadata_set_trace_class(struct ctf_fs_trace *ctf_fs_trace,
+int ctf_fs_metadata_set_trace_class(bt_self_component_source *self_comp,
+               struct ctf_fs_trace *ctf_fs_trace,
                struct ctf_fs_metadata_config *config);
 
 BT_HIDDEN
index bccb78aaf588e918b94587cfda23140f28b3e8e6..8dcc492ee8cdbfa6099d306cb94e2e0a7da2e2fb 100644 (file)
@@ -378,7 +378,7 @@ int populate_trace_info(const char *trace_path, const char *trace_name,
                goto end;
        }
 
-       trace = ctf_fs_trace_create(trace_path, trace_name, NULL);
+       trace = ctf_fs_trace_create(NULL, trace_path, trace_name, NULL);
        if (!trace) {
                BT_LOGE("Failed to create fs trace at \'%s\'", trace_path);
                ret = -1;
index 00cac4a346f062ad7141a1a39aa33ee6fb914ee3..4a7876d7053fc3680001b0ef66fdaecbb591516f 100644 (file)
@@ -68,6 +68,7 @@ struct dmesg_component {
                bt_bool no_timestamp;
        } params;
 
+       bt_self_component_source *self_comp;
        bt_trace_class *trace_class;
        bt_stream_class *stream_class;
        bt_event_class *event_class;
@@ -120,7 +121,9 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts)
        bt_field_class *fc = NULL;
        int ret = 0;
 
-       dmesg_comp->trace_class = bt_trace_class_create();
+       dmesg_comp->trace_class = bt_trace_class_create(
+               bt_self_component_source_as_self_component(
+                       dmesg_comp->self_comp));
        if (!dmesg_comp->trace_class) {
                BT_LOGE_STR("Cannot create an empty trace class object.");
                goto error;
@@ -379,6 +382,7 @@ bt_self_component_status dmesg_init(
                goto error;
        }
 
+       dmesg_comp->self_comp = self_comp;
        dmesg_comp->params.path = g_string_new(NULL);
        if (!dmesg_comp->params.path) {
                BT_LOGE_STR("Failed to allocate a GString.");
index 6738afdc966977937f2a142528c428e2771dfd0e..51a058eb8e468c3fcb7a37c611ca8b6d03872120 100644 (file)
@@ -239,18 +239,15 @@ bool compare_test_events(const struct test_event *expected_events)
 }
 
 static
-void init_static_data(void)
+void init_static_data(bt_self_component_source *self_comp)
 {
        bt_trace_class *trace_class;
        bt_trace *trace;
 
-       /* Test events */
-       test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event));
-       BT_ASSERT(test_events);
-
        /* Metadata, streams, and packets*/
-       trace_class = bt_trace_class_create();
-       BT_ASSERT(trace);
+       trace_class = bt_trace_class_create(
+               bt_self_component_source_as_self_component(self_comp));
+       BT_ASSERT(trace_class);
        src_stream_class = bt_stream_class_create(trace_class);
        BT_ASSERT(src_stream_class);
        src_event_class = bt_event_class_create(src_stream_class);
@@ -286,9 +283,6 @@ void init_static_data(void)
 static
 void fini_static_data(void)
 {
-       /* Test events */
-       g_array_free(test_events, TRUE);
-
        /* Metadata */
        bt_stream_class_put_ref(src_stream_class);
        bt_event_class_put_ref(src_event_class);
@@ -469,6 +463,7 @@ bt_self_component_status src_init(
 {
        int ret;
 
+       init_static_data(self_comp);
        ret = bt_self_component_source_add_output_port(
                self_comp, "out", NULL, NULL);
        BT_ASSERT(ret == 0);
@@ -721,9 +716,10 @@ void create_source_sink(bt_graph *graph,
        }
 }
 
+typedef void (*compare_func_t)(void);
+
 static
-void do_std_test(enum test test, const char *name,
-               const struct test_event *expected_test_events)
+void do_std_test(enum test test, const char *name, compare_func_t compare_func)
 {
        const bt_component_source *src_comp;
        const bt_component_sink *sink_comp;
@@ -760,18 +756,18 @@ void do_std_test(enum test test, const char *name,
                "graph finishes without any error");
 
        /* Compare the resulting test events */
-       if (expected_test_events) {
-               ok(compare_test_events(expected_test_events),
-                       "the produced sequence of test events is the expected one");
+       if (compare_func) {
+               compare_func();
        }
 
        bt_component_source_put_ref(src_comp);
        bt_component_sink_put_ref(sink_comp);
+       fini_static_data();
        BT_GRAPH_PUT_REF_AND_RESET(graph);
 }
 
 static
-void test_no_auto_msgs(void)
+void test_no_auto_msgs_compare(void)
 {
        const struct test_event expected_test_events[] = {
                { .type = TEST_EV_TYPE_MSG_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
@@ -794,33 +790,20 @@ void test_no_auto_msgs(void)
                { .type = TEST_EV_TYPE_SENTINEL, },
        };
 
+       ok(compare_test_events(expected_test_events),
+               "the produced sequence of test events is the expected one");
+}
+
+static
+void test_no_auto_msgs(void)
+{
        do_std_test(TEST_NO_AUTO_MSGS, "no automatic messages",
-               expected_test_events);
+               test_no_auto_msgs_compare);
 }
 
 static
 void test_output_port_message_iterator(void)
 {
-       const struct test_event expected_test_events[] = {
-               { .type = TEST_EV_TYPE_MSG_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
-               { .type = TEST_EV_TYPE_MSG_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
-               { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
-               { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
-               { .type = TEST_EV_TYPE_MSG_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, },
-               { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
-               { .type = TEST_EV_TYPE_MSG_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, },
-               { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, },
-               { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
-               { .type = TEST_EV_TYPE_MSG_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
-               { .type = TEST_EV_TYPE_MSG_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, },
-               { .type = TEST_EV_TYPE_MSG_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, },
-               { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, },
-               { .type = TEST_EV_TYPE_MSG_STREAM_END, .stream = src_stream2, .packet = NULL, },
-               { .type = TEST_EV_TYPE_MSG_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, },
-               { .type = TEST_EV_TYPE_MSG_STREAM_END, .stream = src_stream1, .packet = NULL, },
-               { .type = TEST_EV_TYPE_END, },
-               { .type = TEST_EV_TYPE_SENTINEL, },
-       };
        const bt_component_source *src_comp;
        bt_port_output_message_iterator *msg_iter;
        bt_message_iterator_status iter_status =
@@ -836,10 +819,9 @@ void test_output_port_message_iterator(void)
        create_source_sink(graph, &src_comp, NULL);
 
        /* Create message iterator on source's output port */
-       upstream_port = bt_component_source_borrow_output_port_by_name_const(src_comp,
-                                                                            "out");
-       msg_iter = bt_port_output_message_iterator_create(graph,
-               upstream_port);
+       upstream_port = bt_component_source_borrow_output_port_by_name_const(
+               src_comp, "out");
+       msg_iter = bt_port_output_message_iterator_create(graph, upstream_port);
        ok(msg_iter, "bt_private_output_port_message_iterator_create() succeeds");
 
        /* Consume the message iterator */
@@ -851,9 +833,33 @@ void test_output_port_message_iterator(void)
                "output port message iterator finishes without any error");
 
        /* Compare the resulting test events */
-       ok(compare_test_events(expected_test_events),
-               "the produced sequence of test events is the expected one");
+       {
+               const struct test_event expected_test_events[] = {
+                       { .type = TEST_EV_TYPE_MSG_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
+                       { .type = TEST_EV_TYPE_MSG_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
+                       { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+                       { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+                       { .type = TEST_EV_TYPE_MSG_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, },
+                       { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+                       { .type = TEST_EV_TYPE_MSG_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, },
+                       { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, },
+                       { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
+                       { .type = TEST_EV_TYPE_MSG_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
+                       { .type = TEST_EV_TYPE_MSG_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, },
+                       { .type = TEST_EV_TYPE_MSG_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, },
+                       { .type = TEST_EV_TYPE_MSG_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, },
+                       { .type = TEST_EV_TYPE_MSG_STREAM_END, .stream = src_stream2, .packet = NULL, },
+                       { .type = TEST_EV_TYPE_MSG_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, },
+                       { .type = TEST_EV_TYPE_MSG_STREAM_END, .stream = src_stream1, .packet = NULL, },
+                       { .type = TEST_EV_TYPE_END, },
+                       { .type = TEST_EV_TYPE_SENTINEL, },
+               };
+
+               ok(compare_test_events(expected_test_events),
+                       "the produced sequence of test events is the expected one");
+       }
 
+       fini_static_data();
        bt_component_source_put_ref(src_comp);
        BT_GRAPH_PUT_REF_AND_RESET(graph);
        bt_port_output_message_iterator_put_ref(msg_iter);
@@ -868,9 +874,10 @@ int main(int argc, char **argv)
        }
 
        plan_tests(NR_TESTS);
-       init_static_data();
+       test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event));
+       BT_ASSERT(test_events);
        test_no_auto_msgs();
        test_output_port_message_iterator();
-       fini_static_data();
+       g_array_free(test_events, TRUE);
        return exit_status();
 }
index 61c3de613e44587ed250a5caf4474a1bc247c120..71b833b4e901a301ea61516e6cec83da446f9a38 100644 (file)
@@ -294,11 +294,12 @@ static void set_trace_packet_header(bt_trace_class *trace_class)
        bt_field_class_put_ref(packet_header_type);
 }
 
-static bt_trace_class *create_tc1(void)
+static bt_trace_class *create_tc1(bt_self_component_source *self_comp)
 {
        bt_trace_class *tc1 = NULL;
 
-       tc1 = bt_trace_class_create();
+       tc1 = bt_trace_class_create(
+               bt_self_component_source_as_self_component(self_comp));
        BT_ASSERT(tc1);
        set_trace_packet_header(tc1);
        create_sc1(tc1);
@@ -322,7 +323,7 @@ static void init_weak_refs(bt_trace_class *tc,
        *ec3 = bt_stream_class_borrow_event_class_by_index(*sc2, 0);
 }
 
-static void test_example_scenario(void)
+static void test_example_scenario(bt_self_component_source *self_comp)
 {
        /*
         * Weak pointers to trace IR objects are to be used very
@@ -338,7 +339,7 @@ static void test_example_scenario(void)
        struct user user_a = { 0 }, user_b = { 0 }, user_c = { 0 };
 
        /* The only reference which exists at this point is on TC1. */
-       tc1 = create_tc1();
+       tc1 = create_tc1(self_comp);
        ok(tc1, "Initialize trace");
        BT_ASSERT(tc1);
        init_weak_refs(tc1, &weak_tc1, &weak_sc1, &weak_sc2, &weak_ec1,
@@ -465,6 +466,42 @@ static void test_example_scenario(void)
        BT_EVENT_CLASS_PUT_REF_AND_RESET(user_c.ec);
 }
 
+static
+bt_self_component_status src_init(
+       bt_self_component_source *self_comp,
+       const bt_value *params, void *init_method_data)
+{
+       test_example_scenario(self_comp);
+       return BT_SELF_COMPONENT_STATUS_OK;
+}
+
+static
+bt_self_message_iterator_status src_iter_next(
+               bt_self_message_iterator *self_iterator,
+               bt_message_array_const msgs, uint64_t capacity,
+               uint64_t *count)
+{
+       return BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
+}
+
+static void test_example_scenario_in_graph(void)
+{
+       bt_component_class_source *comp_cls;
+       bt_graph *graph;
+       int ret;
+
+       comp_cls = bt_component_class_source_create("src", src_iter_next);
+       BT_ASSERT(comp_cls);
+       ret = bt_component_class_source_set_init_method(comp_cls, src_init);
+       BT_ASSERT(ret == 0);
+       graph = bt_graph_create();
+       ret = bt_graph_add_source_component(graph, comp_cls, "src-comp",
+               NULL, NULL);
+       BT_ASSERT(ret == 0);
+       bt_graph_put_ref(graph);
+       bt_component_class_source_put_ref(comp_cls);
+}
+
 static void create_writer_user_full(struct writer_user *user)
 {
        gchar *trace_path;
@@ -604,7 +641,7 @@ int main(int argc, char **argv)
        /* Initialize tap harness before any tests */
        plan_tests(NR_TESTS);
 
-       test_example_scenario();
+       test_example_scenario_in_graph();
        test_put_order();
 
        return exit_status();
This page took 0.043181 seconds and 4 git commands to generate.