lib: make precondition failure messages more clear on message creation
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 6 Jun 2019 21:39:37 +0000 (17:39 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 7 Jun 2019 22:51:09 +0000 (18:51 -0400)
Suggested-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: If1486d9bbb3fad02235ce14f53a974e57283fc1b
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1390
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
lib/graph/message/discarded-items.c
lib/graph/message/packet.c

index 5f7108f829db3633b14b5a1a54ac2dd8422916c8..36bdc3689d330f4da709d496fcb24bd1e0462abc 100644 (file)
@@ -70,7 +70,7 @@ struct bt_message *create_discarded_items_message(
        struct bt_message_discarded_items *message;
        struct bt_stream_class *stream_class;
        bool has_support;
-       bool has_default_clock_snapshots;
+       bool need_cs;
 
        BT_ASSERT_PRE_NON_NULL(self_msg_iter, "Message iterator");
        BT_ASSERT_PRE_NON_NULL(stream, "Stream");
@@ -79,22 +79,28 @@ struct bt_message *create_discarded_items_message(
 
        if (type == BT_MESSAGE_TYPE_DISCARDED_EVENTS) {
                has_support = stream_class->supports_discarded_events;
-               has_default_clock_snapshots =
-                       stream_class->discarded_events_have_default_clock_snapshots;
+               need_cs = stream_class->discarded_events_have_default_clock_snapshots;
        } else {
                has_support = stream_class->supports_discarded_packets;
-               has_default_clock_snapshots =
-                       stream_class->discarded_packets_have_default_clock_snapshots;
+               need_cs = stream_class->discarded_packets_have_default_clock_snapshots;
        }
 
        BT_ASSERT_PRE(has_support,
                "Stream class does not support discarded events or packets: "
                "type=%s, %![stream-]+s, %![sc-]+S",
                bt_message_type_string(type), stream, stream_class);
-       BT_ASSERT_PRE((with_cs && has_default_clock_snapshots) ||
-               (!with_cs && !has_default_clock_snapshots),
+       BT_ASSERT_PRE(need_cs ? with_cs : true,
                "Unexpected stream class configuration when creating "
-               "a discarded events or packets message: "
+               "a discarded events or discarded packets message: "
+               "default clock snapshots are needed, but none was provided: "
+               "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
+               "cs-begin-val=%" PRIu64 ", cs-end-val=%" PRIu64,
+               bt_message_type_string(type), stream, stream_class,
+               with_cs, beginning_raw_value, end_raw_value);
+       BT_ASSERT_PRE(!need_cs ? !with_cs : true,
+               "Unexpected stream class configuration when creating "
+               "a discarded events or discarded packets message: "
+               "no default clock snapshots are needed, but two were provided: "
                "type=%s, %![stream-]+s, %![sc-]+S, with-cs=%d, "
                "cs-begin-val=%" PRIu64 ", cs-end-val=%" PRIu64,
                bt_message_type_string(type), stream, stream_class,
index abaa7c7f6e37a744a94ff1bdc14e2f66089a4253..9ed9a0c47f2eb3054553feb4402dab82f0d6d504 100644 (file)
@@ -87,7 +87,7 @@ struct bt_message *create_packet_message(
        struct bt_message_packet *message = NULL;
        struct bt_stream *stream;
        struct bt_stream_class *stream_class;
-       bool packet_has_default_clock_snapshot;
+       bool need_cs;
 
        BT_ASSERT(msg_iter);
        BT_ASSERT_PRE_NON_NULL(packet, "Packet");
@@ -97,21 +97,26 @@ struct bt_message *create_packet_message(
        BT_ASSERT(stream_class);
 
        if (pool == &msg_iter->graph->packet_begin_msg_pool) {
-               packet_has_default_clock_snapshot =
-                       stream_class->packets_have_beginning_default_clock_snapshot;
+               need_cs = stream_class->packets_have_beginning_default_clock_snapshot;
        } else {
-               packet_has_default_clock_snapshot =
-                       stream_class->packets_have_end_default_clock_snapshot;
+               need_cs = stream_class->packets_have_end_default_clock_snapshot;
        }
 
        /*
         * `packet_has_default_clock_snapshot` implies that the stream
         * class has a default clock class (precondition).
         */
-       BT_ASSERT_PRE((with_cs && packet_has_default_clock_snapshot) ||
-               (!with_cs && !packet_has_default_clock_snapshot),
+       BT_ASSERT_PRE(need_cs ? with_cs : true,
                "Unexpected stream class configuration when creating "
-               "a packet beginning or end message: ",
+               "a packet beginning or end message: "
+               "a default clock snapshot is needed, but none was provided: "
+               "%![stream-]+s, %![sc-]+S, with-cs=%d, "
+               "cs-val=%" PRIu64,
+               stream, stream_class, with_cs, raw_value);
+       BT_ASSERT_PRE(!need_cs ? !with_cs : true,
+               "Unexpected stream class configuration when creating "
+               "a packet beginning or end message: "
+               "no default clock snapshot is needed, but one was provided: "
                "%![stream-]+s, %![sc-]+S, with-cs=%d, "
                "cs-val=%" PRIu64,
                stream, stream_class, with_cs, raw_value);
This page took 0.02658 seconds and 4 git commands to generate.