From: Philippe Proulx Date: Tue, 2 May 2017 19:19:34 +0000 (-0400) Subject: Make bt_ctf_event_class_create() create an empty context FT X-Git-Tag: v2.0.0-pre1~320 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=53a1cae7cefe4497f219c13971bfb85218c6d559;p=babeltrace.git Make bt_ctf_event_class_create() create an empty context FT This is in line with bt_ctf_trace_create() and bt_ctf_stream_class_create_empty(). You can get the empty context FT with bt_ctf_event_class_get_context_type() after creation and add fields to it. Update tests accordingly. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/ctf-ir/event-class.h b/include/babeltrace/ctf-ir/event-class.h index 5052f70f..fec7aa87 100644 --- a/include/babeltrace/ctf-ir/event-class.h +++ b/include/babeltrace/ctf-ir/event-class.h @@ -121,9 +121,11 @@ struct bt_ctf_stream_class; /** @brief Creates a default CTF IR event class named \p name­. -The event class is created \em without an event context -\link ctfirfieldtypes field type\endlink and with an empty event -payload field type. +On success, the context and payload field types are empty structure +field types. You can modify those default field types after the +event class is created with +bt_ctf_event_class_set_context_type() and +bt_ctf_event_class_set_payload_type(). Upon creation, the event class's ID is not set. You can set it to a specific value with bt_ctf_event_class_set_id(). If it diff --git a/lib/ctf-ir/event-class.c b/lib/ctf-ir/event-class.c index e37331f0..8dc4619d 100644 --- a/lib/ctf-ir/event-class.c +++ b/lib/ctf-ir/event-class.c @@ -66,6 +66,11 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) goto error; } + event_class->context = bt_ctf_field_type_structure_create(); + if (!event_class->context) { + goto error; + } + event_class->attributes = bt_ctf_attributes_create(); if (!event_class->attributes) { goto error; diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 0d2b5839..80e49ca4 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -61,7 +61,7 @@ #define DEFAULT_CLOCK_TIME 0 #define DEFAULT_CLOCK_VALUE 0 -#define NR_TESTS 614 +#define NR_TESTS 612 static int64_t current_time = 42; @@ -371,8 +371,6 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, "Add event specific context field"); ok(bt_ctf_event_class_get_context_type(NULL) == NULL, "bt_ctf_event_class_get_context_type handles NULL correctly"); - ok(bt_ctf_event_class_get_context_type(simple_event_class) == NULL, - "bt_ctf_event_class_get_context_type returns NULL when no event context type is set"); ok(bt_ctf_event_class_set_context_type(NULL, event_context_type) < 0, "bt_ctf_event_class_set_context_type handles a NULL event class correctly"); @@ -3313,9 +3311,6 @@ int main(int argc, char **argv) /* Define a stream event context containing a my_integer field. */ ok(bt_ctf_stream_class_get_event_context_type(NULL) == NULL, "bt_ctf_stream_class_get_event_context_type handles NULL correctly"); - ok(bt_ctf_stream_class_get_event_context_type( - stream_class) == NULL, - "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set."); stream_event_context_type = bt_ctf_field_type_structure_create(); bt_ctf_field_type_structure_add_field(stream_event_context_type, integer_type, "common_event_context");