From: Philippe Proulx Date: Mon, 3 Apr 2017 22:32:01 +0000 (-0400) Subject: ir: make sure you can't add a SC to a trace with a native BO X-Git-Tag: v2.0.0-pre1~391 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=d490fcbefb2a6069918ab3fa02e204754b57fc6d;p=babeltrace.git ir: make sure you can't add a SC to a trace with a native BO When you create a trace object with bt_ctf_trace_create(), its native byte order is set to BT_CTF_BYTE_ORDER_NATIVE, which essentially means "unset". Before freezing the trace (which only happens in bt_ctf_trace_add_stream_class()), make sure that the trace's native byte order is a real byte order, not still BT_CTF_BYTE_ORDER_NATIVE (unset). Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/lib/ctf-ir/trace.c b/lib/ctf-ir/trace.c index 52293381..1b239fa3 100644 --- a/lib/ctf-ir/trace.c +++ b/lib/ctf-ir/trace.c @@ -465,6 +465,15 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, goto end; } + /* + * At the end of this function we freeze the trace, so its + * native byte order must NOT be BT_CTF_BYTE_ORDER_NATIVE. + */ + if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE) { + ret = -1; + goto end; + } + current_parent_trace = bt_ctf_stream_class_get_trace(stream_class); if (current_parent_trace) { /* Stream class is already associated to a trace, abort. */ diff --git a/tests/lib/test_bt_ctf_field_type_validation.c b/tests/lib/test_bt_ctf_field_type_validation.c index 27c18814..065d367b 100644 --- a/tests/lib/test_bt_ctf_field_type_validation.c +++ b/tests/lib/test_bt_ctf_field_type_validation.c @@ -2069,6 +2069,9 @@ void test_pass(void) trace = bt_ctf_trace_create(); assert(trace); + ret = bt_ctf_trace_set_native_byte_order(trace, + BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); + assert(ret == 0); sc = bt_ctf_stream_class_create("nice_piece_of_stream_class"); assert(sc); ec = bt_ctf_event_class_create("oh_what_an_event_class"); diff --git a/tests/lib/test_ctf_ir_ref.c b/tests/lib/test_ctf_ir_ref.c index 3726b44b..f6a8253f 100644 --- a/tests/lib/test_ctf_ir_ref.c +++ b/tests/lib/test_ctf_ir_ref.c @@ -306,6 +306,9 @@ static struct bt_ctf_trace *create_tc1(void) goto error; } + ret = bt_ctf_trace_set_native_byte_order(tc1, + BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); + assert(ret == 0); sc1 = create_sc1(); ok(sc1, "Create SC1"); if (!sc1) { diff --git a/tests/lib/test_ir_visit.c b/tests/lib/test_ir_visit.c index 6209079f..68534812 100644 --- a/tests/lib/test_ir_visit.c +++ b/tests/lib/test_ir_visit.c @@ -27,6 +27,7 @@ #include #include #include +#include #define NR_TESTS 13 @@ -104,6 +105,9 @@ struct bt_ctf_trace *init_trace(void) goto end; } + ret = bt_ctf_trace_set_native_byte_order(trace, + BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); + assert(ret == 0); ret = bt_ctf_stream_class_add_event_class(sc1, ec1); if (ret) { goto error;