lib/graph/iterator: don't reset clock expectation when seeking beginning
[babeltrace.git] / src / lib / graph / iterator.c
index 760affc7ddcae8dfe501883f87598478f2955d5e..1cb1e6a074f19af053650d58acdbe049987eda8b 100644 (file)
@@ -65,7 +65,7 @@
                (_iter)->state == BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, \
                "Message iterator is in the wrong state: %!+i", (_iter))
 
-#ifdef BT_DEV_MODE
+BT_IF_DEV_MODE(
 struct per_stream_state
 {
        bt_packet *cur_packet;
@@ -73,7 +73,7 @@ struct per_stream_state
        /* Bit mask of expected message types. */
        guint expected_msg_types;
 };
-#endif
+)
 
 static void
 clear_per_stream_state (struct bt_message_iterator *iterator)
@@ -160,9 +160,7 @@ void bt_message_iterator_destroy(struct bt_object *obj)
                iterator->msgs = NULL;
        }
 
-#ifdef BT_DEV_MODE
-       g_hash_table_destroy(iterator->per_stream_state);
-#endif
+       BT_IF_DEV_MODE(g_hash_table_destroy(iterator->per_stream_state));
 
        g_free(iterator);
 }
@@ -371,14 +369,12 @@ int create_self_component_input_port_message_iterator(
        g_ptr_array_set_size(iterator->msgs, MSG_BATCH_SIZE);
        iterator->last_ns_from_origin = INT64_MIN;
 
-#ifdef BT_DEV_MODE
        /* The per-stream state is only used for dev assertions right now. */
-       iterator->per_stream_state = g_hash_table_new_full(
+       BT_IF_DEV_MODE(iterator->per_stream_state = g_hash_table_new_full(
                g_direct_hash,
                g_direct_equal,
                NULL,
-               g_free);
-#endif
+               g_free));
 
        iterator->auto_seek.msgs = g_queue_new();
        if (!iterator->auto_seek.msgs) {
@@ -667,164 +663,142 @@ end:
        return result;
 }
 
+#define NEXT_METHOD_NAME       "bt_message_iterator_class_next_method"
+
+#ifdef BT_DEV_MODE
+
 /*
  * When a new stream begins, verify that the clock class tied to this
  * stream is compatible with what we've seen before.
  */
 
-BT_ASSERT_COND_DEV_FUNC
 static
-bool clock_classes_are_compatible_one(struct bt_message_iterator *iterator,
+void assert_post_dev_clock_classes_are_compatible_one(
+               struct bt_message_iterator *iterator,
                const struct bt_message *msg)
 {
-       enum bt_message_type message_type = bt_message_get_type(msg);
-       bool result;
+       const struct bt_clock_class *clock_class = NULL;
+       bt_uuid clock_class_uuid = NULL;
 
-       if (message_type == BT_MESSAGE_TYPE_STREAM_BEGINNING) {
-               const struct bt_message_stream *stream_msg = (struct bt_message_stream *) msg;
-               const struct bt_clock_class *clock_class = stream_msg->stream->class->default_clock_class;
-               bt_uuid clock_class_uuid = NULL;
+       switch (bt_message_get_type(msg)) {
+       case BT_MESSAGE_TYPE_STREAM_BEGINNING:
+       {
+               const struct bt_message_stream *stream_msg =
+                       (struct bt_message_stream *) msg;
 
-               if (clock_class) {
-                       clock_class_uuid = bt_clock_class_get_uuid(clock_class);
-               }
+               clock_class = stream_msg->stream->class->default_clock_class;
+               break;
+       }
+       case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
+       {
+               const struct bt_message_message_iterator_inactivity *mii_msg =
+                       (struct bt_message_message_iterator_inactivity *) msg;
 
-               switch (iterator->clock_expectation.type) {
-               case CLOCK_EXPECTATION_UNSET:
-                       /*
-                        * This is the first time we see a message with a clock
-                        * snapshot: record the properties of that clock, against
-                        * which we'll compare the clock properties of the following
-                        * messages.
-                        */
+               clock_class = mii_msg->cs->clock_class;
+               break;
+       }
+       default:
+               return;
+       }
 
-                       if (!clock_class) {
-                               iterator->clock_expectation.type = CLOCK_EXPECTATION_NONE;
-                       } else if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
-                               iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_UNIX;
-                       } else if (clock_class_uuid) {
-                               iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_UUID;
-                               bt_uuid_copy(iterator->clock_expectation.uuid, clock_class_uuid);
-                       } else {
-                               iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID;
-                               iterator->clock_expectation.clock_class = clock_class;
-                               bt_clock_class_get_ref(iterator->clock_expectation.clock_class);
-                       }
-                       break;
+       if (clock_class) {
+               clock_class_uuid = bt_clock_class_get_uuid(clock_class);
+       }
 
-               case CLOCK_EXPECTATION_NONE:
-                       if (clock_class) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting no clock class, got one: %![cc-]+K",
-                                       clock_class);
-                               result = false;
-                               goto end;
-                       }
+       switch (iterator->clock_expectation.type) {
+       case CLOCK_EXPECTATION_UNSET:
+               /*
+                * This is the first time we see a message with a clock
+                * snapshot: record the properties of that clock, against
+                * which we'll compare the clock properties of the following
+                * messages.
+                */
 
-                       break;
+               if (!clock_class) {
+                       iterator->clock_expectation.type = CLOCK_EXPECTATION_NONE;
+               } else if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
+                       iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_UNIX;
+               } else if (clock_class_uuid) {
+                       iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_UUID;
+                       bt_uuid_copy(iterator->clock_expectation.uuid, clock_class_uuid);
+               } else {
+                       iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID;
+                       iterator->clock_expectation.clock_class = clock_class;
+                       bt_clock_class_get_ref(iterator->clock_expectation.clock_class);
+               }
+               break;
 
-               case CLOCK_EXPECTATION_ORIGIN_UNIX:
-                       if (!clock_class) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting a clock class, got none.");
-                               result = false;
-                               goto end;
-                       }
+       case CLOCK_EXPECTATION_NONE:
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "stream-class-has-no-clock-class", !clock_class,
+                       "Expecting no clock class, got one: %![cc-]+K",
+                       clock_class);
+               break;
 
-                       if (!bt_clock_class_origin_is_unix_epoch(clock_class)) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting a clock class with Unix epoch origin: %![cc-]+K",
-                                       clock_class);
-                               result = false;
-                               goto end;
-                       }
-                       break;
+       case CLOCK_EXPECTATION_ORIGIN_UNIX:
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "stream-class-has-clock-class-with-unix-epoch-origin", clock_class,
+                       "Expecting a clock class with Unix epoch origin, got none.");
 
-               case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID:
-                       if (!clock_class) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting a clock class, got none.");
-                               result = false;
-                               goto end;
-                       }
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "clock-class-has-unix-epoch-origin",
+                       bt_clock_class_origin_is_unix_epoch(clock_class),
+                       "Expecting a clock class with Unix epoch origin: %![cc-]+K",
+                       clock_class);
+               break;
 
-                       if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting a clock class without Unix epoch origin: %![cc-]+K",
-                                       clock_class);
-                               result = false;
-                               goto end;
-                       }
+       case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID:
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "stream-class-has-clock-class-with-uuid", clock_class,
+                       "Expecting a clock class with UUID, got none.");
 
-                       if (!clock_class_uuid) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting a clock class with UUID: %![cc-]+K",
-                                       clock_class);
-                               result = false;
-                               goto end;
-                       }
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "clock-class-has-non-unix-epoch-origin",
+                       !bt_clock_class_origin_is_unix_epoch(clock_class),
+                       "Expecting a clock class without Unix epoch origin: %![cc-]+K",
+                       clock_class);
 
-                       if (bt_uuid_compare(iterator->clock_expectation.uuid, clock_class_uuid)) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting a clock class with UUID, got one "
-                                       "with a different UUID: %![cc-]+K, expected-uuid=%!u",
-                                       clock_class, iterator->clock_expectation.uuid);
-                               result = false;
-                               goto end;
-                       }
-                       break;
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "clock-class-has-uuid",
+                       clock_class_uuid,
+                       "Expecting a clock class with UUID, got one without UUID: %![cc-]+K",
+                       clock_class);
 
-               case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID:
-                       if (!clock_class) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting clock class %![cc-]+K, got none.",
-                                       iterator->clock_expectation.clock_class);
-                               result = false;
-                               goto end;
-                       }
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "clock-class-has-expected-uuid",
+                       !bt_uuid_compare(iterator->clock_expectation.uuid, clock_class_uuid),
+                       "Expecting a clock class with UUID, got one "
+                               "with a different UUID: %![cc-]+K, expected-uuid=%!u",
+                               clock_class, iterator->clock_expectation.uuid);
+               break;
 
-                       if (clock_class != iterator->clock_expectation.clock_class) {
-                               BT_ASSERT_COND_DEV_MSG(
-                                       "Expecting clock class %![cc-]+K, got %![cc-]+K.",
-                                       iterator->clock_expectation.clock_class,
-                                       clock_class);
-                               result = false;
-                               goto end;
-                       }
+       case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID:
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "stream-class-has-clock-class", clock_class,
+                       "Expecting a clock class, got none.");
 
-                       break;
-               }
+               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+                       "clock-class-is-expected",
+                       clock_class == iterator->clock_expectation.clock_class,
+                       "Expecting clock class %![cc-]+K, got %![cc-]+K.",
+                       iterator->clock_expectation.clock_class,
+                       clock_class);
+               break;
        }
-
-       result = true;
-
-end:
-       return result;
 }
 
-BT_ASSERT_COND_DEV_FUNC
 static
-bool clock_classes_are_compatible(
+void assert_post_dev_clock_classes_are_compatible(
                struct bt_message_iterator *iterator,
                bt_message_array_const msgs, uint64_t msg_count)
 {
        uint64_t i;
-       bool result;
 
        for (i = 0; i < msg_count; i++) {
-               if (!clock_classes_are_compatible_one(iterator, msgs[i])) {
-                       result = false;
-                       goto end;
-               }
+               assert_post_dev_clock_classes_are_compatible_one(iterator, msgs[i]);
        }
-
-       result = true;
-
-end:
-       return result;
 }
 
-#ifdef BT_DEV_MODE
 static
 const bt_stream *get_stream_from_msg(const struct bt_message *msg)
 {
@@ -1028,11 +1002,7 @@ struct per_stream_state *get_per_stream_state(
 
        return state;
 }
-#endif
-
-#define NEXT_METHOD_NAME       "bt_message_iterator_class_next_method"
 
-#ifdef BT_DEV_MODE
 static
 void assert_post_dev_expected_sequence(struct bt_message_iterator *iterator,
                const struct bt_message *msg)
@@ -1183,11 +1153,9 @@ call_iterator_next_method(
                bt_common_func_status_string(status), *user_count);
 
        if (status == BT_FUNC_STATUS_OK) {
-               BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
-                       "message-clock-classes-are-compatible",
-                       clock_classes_are_compatible(iterator, msgs,
-                               *user_count),
-                       "Clocks are not compatible");
+               BT_IF_DEV_MODE(assert_post_dev_clock_classes_are_compatible(
+                       iterator, msgs, *user_count));
+
                BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
                        "message-clock-snapshots-are-monotonic",
                        clock_snapshots_are_monotonic(iterator, msgs,
@@ -1195,9 +1163,8 @@ call_iterator_next_method(
                        "Clock snapshots are not monotonic");
        }
 
-#ifdef BT_DEV_MODE
-       assert_post_dev_next(iterator, status, msgs, *user_count);
-#endif
+       BT_IF_DEV_MODE(assert_post_dev_next(iterator, status, msgs,
+               *user_count));
 
        BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(NEXT_METHOD_NAME,
                status);
@@ -1478,7 +1445,6 @@ void reset_iterator_expectations(
                struct bt_message_iterator *iterator)
 {
        iterator->last_ns_from_origin = INT64_MIN;
-       iterator->clock_expectation.type = CLOCK_EXPECTATION_UNSET;
 }
 
 static
This page took 0.02885 seconds and 4 git commands to generate.