From: Philippe Proulx Date: Mon, 29 May 2017 19:27:23 +0000 (-0400) Subject: Fix: test_ctf_ir_ref.c: create valid SC PC/EH and trace packet header X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=da1cc6719ff24cfad103122ca91bf1e0fb56d9dd;p=deliverable%2Fbabeltrace.git Fix: test_ctf_ir_ref.c: create valid SC PC/EH and trace packet header Since CTF IR is more strict regarding the semantics of trace packet header, stream class packet context and event header field types, this test fails because the default packet context field type of a stream class which is not created for a CTF writer object contains `timestamp_begin` and `timestamp_end` fields which are not mapped to a clock class. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/tests/lib/test_ctf_ir_ref.c b/tests/lib/test_ctf_ir_ref.c index 5ffb069a4..60a8b5533 100644 --- a/tests/lib/test_ctf_ir_ref.c +++ b/tests/lib/test_ctf_ir_ref.c @@ -210,18 +210,62 @@ error: goto end;; } +static void set_stream_class_field_types( + struct bt_ctf_stream_class *stream_class) +{ + struct bt_ctf_field_type *packet_context_type; + struct bt_ctf_field_type *event_header_type; + struct bt_ctf_field_type *ft; + int ret; + + packet_context_type = bt_ctf_field_type_structure_create(); + assert(packet_context_type); + ft = bt_ctf_field_type_integer_create(32); + assert(ft); + ret = bt_ctf_field_type_structure_add_field(packet_context_type, + ft, "packet_size"); + assert(ret == 0); + bt_put(ft); + ft = bt_ctf_field_type_integer_create(32); + assert(ft); + ret = bt_ctf_field_type_structure_add_field(packet_context_type, + ft, "content_size"); + assert(ret == 0); + bt_put(ft); + + event_header_type = bt_ctf_field_type_structure_create(); + assert(event_header_type); + ft = bt_ctf_field_type_integer_create(32); + assert(ft); + ret = bt_ctf_field_type_structure_add_field(event_header_type, + ft, "id"); + assert(ret == 0); + bt_put(ft); + + ret = bt_ctf_stream_class_set_packet_context_type(stream_class, + packet_context_type); + assert(ret == 0); + ret = bt_ctf_stream_class_set_event_header_type(stream_class, + event_header_type); + assert(ret == 0); + + bt_put(packet_context_type); + bt_put(event_header_type); +} + static struct bt_ctf_stream_class *create_sc1(void) { int ret; struct bt_ctf_event_class *ec1 = NULL, *ec2 = NULL; struct bt_ctf_stream_class *sc1 = NULL, *ret_stream = NULL; - sc1 = bt_ctf_stream_class_create("sc1"); + sc1 = bt_ctf_stream_class_create_empty("sc1"); if (!sc1) { diag("Failed to create Stream Class"); goto error; } + set_stream_class_field_types(sc1); ec1 = create_complex_event("ec1"); if (!ec1) { diag("Failed to create complex event EC1"); @@ -266,12 +310,13 @@ static struct bt_ctf_stream_class *create_sc2(void) struct bt_ctf_event_class *ec3 = NULL; struct bt_ctf_stream_class *sc2 = NULL, *ret_stream = NULL; - sc2 = bt_ctf_stream_class_create("sc2"); + sc2 = bt_ctf_stream_class_create_empty("sc2"); if (!sc2) { diag("Failed to create Stream Class"); goto error; } + set_stream_class_field_types(sc2); ec3 = create_simple_event("ec3"); if (!ec3) { diag("Failed to create simple event EC3"); @@ -294,6 +339,28 @@ error: goto end; } +static void set_trace_packet_header(struct bt_ctf_trace *trace) +{ + struct bt_ctf_field_type *packet_header_type; + struct bt_ctf_field_type *ft; + int ret; + + packet_header_type = bt_ctf_field_type_structure_create(); + assert(packet_header_type); + ft = bt_ctf_field_type_integer_create(32); + assert(ft); + ret = bt_ctf_field_type_structure_add_field(packet_header_type, + ft, "stream_id"); + assert(ret == 0); + bt_put(ft); + + ret = bt_ctf_trace_set_packet_header_type(trace, + packet_header_type); + assert(ret == 0); + + bt_put(packet_header_type); +} + static struct bt_ctf_trace *create_tc1(void) { int ret; @@ -306,6 +373,7 @@ static struct bt_ctf_trace *create_tc1(void) goto error; } + set_trace_packet_header(tc1); ret = bt_ctf_trace_set_native_byte_order(tc1, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); assert(ret == 0);