ir: make sure you can't add a SC to a trace with a native BO
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 3 Apr 2017 22:32:01 +0000 (18:32 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:40 +0000 (12:57 -0400)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/ctf-ir/trace.c
tests/lib/test_bt_ctf_field_type_validation.c
tests/lib/test_ctf_ir_ref.c
tests/lib/test_ir_visit.c

index 5229338106bc4c37b1c489582a9c87a89e2baa0b..1b239fa3f457f1c3f5dbb30e72791bbb6bcfe153 100644 (file)
@@ -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. */
index 27c188146cbebfa2cfa3dfe266cf4d0e73d6762a..065d367b696d796c4ee81cafb515206b60cf9d0c 100644 (file)
@@ -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");
index 3726b44bd604f37a0fc45f7c984cfde2a326c145..f6a8253fdc5362c9b36e8ce1a017c780b787923b 100644 (file)
@@ -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) {
index 6209079f60597939d979beb84fd1fecb8a67c3c6..68534812af130e9d7b56b0988b687c2db08e1629 100644 (file)
@@ -27,6 +27,7 @@
 #include <babeltrace/ctf-ir/visitor.h>
 #include <stdlib.h>
 #include <string.h>
+#include <assert.h>
 
 #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;
This page took 0.027092 seconds and 4 git commands to generate.