lib: remove clock class priority map, use default clock value
[babeltrace.git] / tests / lib / test_bt_notification_iterator.c
index 97c2075aa914243c918425b162b1da074900f09d..d451140821a8cf53215cb5a50e232128993166c5 100644 (file)
@@ -30,7 +30,6 @@
 #include <babeltrace/ctf-ir/stream-class.h>
 #include <babeltrace/ctf-ir/stream.h>
 #include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/graph/component-class-filter.h>
 #include <babeltrace/graph/component-class-sink.h>
 #include <babeltrace/graph/component-class-source.h>
@@ -51,6 +50,7 @@
 #include <babeltrace/graph/private-component-sink.h>
 #include <babeltrace/graph/private-component.h>
 #include <babeltrace/graph/private-connection.h>
+#include <babeltrace/graph/private-connection-notification-iterator.h>
 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
 #include <babeltrace/graph/private-port.h>
 #include <babeltrace/plugin/plugin.h>
@@ -59,7 +59,7 @@
 
 #include "tap/tap.h"
 
-#define NR_TESTS       6
+#define NR_TESTS       5
 
 enum test {
        TEST_NO_AUTO_NOTIFS,
@@ -88,7 +88,6 @@ static bool debug = false;
 static enum test current_test;
 static GArray *test_events;
 static struct bt_graph *graph;
-static struct bt_clock_class_priority_map *src_empty_cc_prio_map;
 static struct bt_stream_class *src_stream_class;
 static struct bt_event_class *src_event_class;
 static struct bt_stream *src_stream1;
@@ -294,8 +293,6 @@ void init_static_data(void)
        BT_ASSERT(trace);
        ret = bt_trace_set_packet_header_field_type(trace, empty_struct_ft);
        BT_ASSERT(ret == 0);
-       src_empty_cc_prio_map = bt_clock_class_priority_map_create();
-       BT_ASSERT(src_empty_cc_prio_map);
        src_stream_class = bt_stream_class_create("my-stream-class");
        BT_ASSERT(src_stream_class);
        ret = bt_stream_class_set_packet_context_field_type(src_stream_class,
@@ -352,7 +349,6 @@ void fini_static_data(void)
        g_array_free(test_events, TRUE);
 
        /* Metadata */
-       bt_put(src_empty_cc_prio_map);
        bt_put(src_stream_class);
        bt_put(src_event_class);
        bt_put(src_stream1);
@@ -403,96 +399,60 @@ enum bt_notification_iterator_status src_iter_init(
 }
 
 static
-struct bt_notification_iterator_next_method_return src_iter_next_seq(
-               struct src_iter_user_data *user_data)
+void src_iter_next_seq_one(struct src_iter_user_data *user_data,
+               struct bt_notification **notif)
 {
-       struct bt_notification_iterator_next_method_return next_return = {
-               .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
-       };
-       int64_t cur_ts_ns;
        struct bt_packet *event_packet = NULL;
 
-       BT_ASSERT(user_data->seq);
-       cur_ts_ns = user_data->seq[user_data->at];
-
-       switch (cur_ts_ns) {
-       case SEQ_END:
-               next_return.status =
-                       BT_NOTIFICATION_ITERATOR_STATUS_END;
-               break;
+       switch (user_data->seq[user_data->at]) {
        case SEQ_INACTIVITY:
-               next_return.notification =
-                       bt_notification_inactivity_create(graph,
-                               src_empty_cc_prio_map);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_inactivity_create(graph);
                break;
        case SEQ_STREAM1_BEGIN:
-               next_return.notification =
-                       bt_notification_stream_begin_create(graph, src_stream1);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_stream_begin_create(graph,
+                       src_stream1);
                break;
        case SEQ_STREAM2_BEGIN:
-               next_return.notification =
-                       bt_notification_stream_begin_create(graph, src_stream2);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_stream_begin_create(graph,
+                       src_stream2);
                break;
        case SEQ_STREAM1_END:
-               next_return.notification =
-                       bt_notification_stream_end_create(graph, src_stream1);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_stream_end_create(graph, src_stream1);
                break;
        case SEQ_STREAM2_END:
-               next_return.notification =
-                       bt_notification_stream_end_create(graph, src_stream2);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_stream_end_create(graph, src_stream2);
                break;
        case SEQ_STREAM1_PACKET1_BEGIN:
-               next_return.notification =
-                       bt_notification_packet_begin_create(graph,
-                               src_stream1_packet1);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_begin_create(graph,
+                       src_stream1_packet1);
                break;
        case SEQ_STREAM1_PACKET2_BEGIN:
-               next_return.notification =
-                       bt_notification_packet_begin_create(graph,
-                               src_stream1_packet2);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_begin_create(graph,
+                       src_stream1_packet2);
                break;
        case SEQ_STREAM2_PACKET1_BEGIN:
-               next_return.notification =
-                       bt_notification_packet_begin_create(graph,
-                               src_stream2_packet1);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_begin_create(graph,
+                       src_stream2_packet1);
                break;
        case SEQ_STREAM2_PACKET2_BEGIN:
-               next_return.notification =
-                       bt_notification_packet_begin_create(graph,
-                               src_stream2_packet2);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_begin_create(graph,
+                       src_stream2_packet2);
                break;
        case SEQ_STREAM1_PACKET1_END:
-               next_return.notification =
-                       bt_notification_packet_end_create(graph,
-                               src_stream1_packet1);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_end_create(graph,
+                       src_stream1_packet1);
                break;
        case SEQ_STREAM1_PACKET2_END:
-               next_return.notification =
-                       bt_notification_packet_end_create(graph,
-                               src_stream1_packet2);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_end_create(graph,
+                       src_stream1_packet2);
                break;
        case SEQ_STREAM2_PACKET1_END:
-               next_return.notification =
-                       bt_notification_packet_end_create(graph,
-                               src_stream2_packet1);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_end_create(graph,
+                       src_stream2_packet1);
                break;
        case SEQ_STREAM2_PACKET2_END:
-               next_return.notification =
-                       bt_notification_packet_end_create(graph,
-                               src_stream2_packet2);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_packet_end_create(graph,
+                       src_stream2_packet2);
                break;
        case SEQ_EVENT_STREAM1_PACKET1:
                event_packet = src_stream1_packet1;
@@ -511,33 +471,54 @@ struct bt_notification_iterator_next_method_return src_iter_next_seq(
        }
 
        if (event_packet) {
-               next_return.notification =
-                       bt_notification_event_create(graph, src_event_class,
-                               event_packet, src_empty_cc_prio_map);
-               BT_ASSERT(next_return.notification);
+               *notif = bt_notification_event_create(graph, src_event_class,
+                       event_packet);
+       }
+
+       BT_ASSERT(*notif);
+       user_data->at++;
+}
+
+static
+enum bt_notification_iterator_status src_iter_next_seq(
+               struct src_iter_user_data *user_data,
+               bt_notification_array notifs, uint64_t capacity,
+               uint64_t *count)
+{
+       enum bt_notification_iterator_status status =
+               BT_NOTIFICATION_ITERATOR_STATUS_OK;
+       uint64_t i = 0;
+
+       BT_ASSERT(user_data->seq);
+
+       if (user_data->seq[user_data->at] == SEQ_END) {
+               status = BT_NOTIFICATION_ITERATOR_STATUS_END;
+               goto end;
        }
 
-       if (next_return.status != BT_NOTIFICATION_ITERATOR_STATUS_END) {
-               user_data->at++;
+       while (i < capacity && user_data->seq[user_data->at] != SEQ_END) {
+               src_iter_next_seq_one(user_data, &notifs[i]);
+               i++;
        }
 
-       return next_return;
+       BT_ASSERT(i > 0 && i <= capacity);
+       *count = i;
+
+end:
+       return status;
 }
 
 static
-struct bt_notification_iterator_next_method_return src_iter_next(
-               struct bt_private_connection_private_notification_iterator *priv_iterator)
+enum bt_notification_iterator_status src_iter_next(
+               struct bt_private_connection_private_notification_iterator *priv_iterator,
+               bt_notification_array notifs, uint64_t capacity,
+               uint64_t *count)
 {
-       struct bt_notification_iterator_next_method_return next_return = {
-               .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
-               .notification = NULL,
-       };
        struct src_iter_user_data *user_data =
                bt_private_connection_private_notification_iterator_get_user_data(priv_iterator);
 
        BT_ASSERT(user_data);
-       next_return = src_iter_next_seq(user_data);
-       return next_return;
+       return src_iter_next_seq(user_data, notifs, capacity, count);
 }
 
 static
@@ -559,34 +540,9 @@ void src_finalize(struct bt_private_component *private_component)
 }
 
 static
-enum bt_notification_iterator_status common_consume(
-               struct bt_notification_iterator *notif_iter)
+void append_test_events_from_notification(struct bt_notification *notification)
 {
-       enum bt_notification_iterator_status ret;
-       struct bt_notification *notification = NULL;
        struct test_event test_event = { 0 };
-       bool do_append_test_event = true;
-       BT_ASSERT(notif_iter);
-
-       ret = bt_notification_iterator_next(notif_iter);
-       if (ret < 0) {
-               do_append_test_event = false;
-               goto end;
-       }
-
-       switch (ret) {
-       case BT_NOTIFICATION_ITERATOR_STATUS_END:
-               test_event.type = TEST_EV_TYPE_END;
-               goto end;
-       case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
-               abort();
-       default:
-               break;
-       }
-
-       notification = bt_notification_iterator_get_notification(
-               notif_iter);
-       BT_ASSERT(notification);
 
        switch (bt_notification_get_type(notification)) {
        case BT_NOTIFICATION_TYPE_EVENT:
@@ -637,12 +593,54 @@ enum bt_notification_iterator_status common_consume(
                BT_ASSERT(test_event.stream);
        }
 
-end:
-       if (do_append_test_event) {
+       append_test_event(&test_event);
+}
+
+static
+enum bt_notification_iterator_status common_consume(
+               struct bt_notification_iterator *notif_iter,
+               bool is_output_port_notif_iter)
+{
+       enum bt_notification_iterator_status ret;
+       bt_notification_array notifications = NULL;
+       uint64_t count = 0;
+       struct test_event test_event = { 0 };
+       uint64_t i;
+
+       BT_ASSERT(notif_iter);
+
+       if (is_output_port_notif_iter) {
+               ret = bt_output_port_notification_iterator_next(notif_iter,
+                       &notifications, &count);
+       } else {
+               ret = bt_private_connection_notification_iterator_next(
+                       notif_iter, &notifications, &count);
+       }
+
+       if (ret < 0) {
+               goto end;
+       }
+
+       switch (ret) {
+       case BT_NOTIFICATION_ITERATOR_STATUS_END:
+               test_event.type = TEST_EV_TYPE_END;
                append_test_event(&test_event);
+               goto end;
+       case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
+               abort();
+       default:
+               break;
+       }
+
+       BT_ASSERT(notifications);
+       BT_ASSERT(count > 0);
+
+       for (i = 0; i < count; i++) {
+               append_test_events_from_notification(notifications[i]);
+               bt_put(notifications[i]);
        }
 
-       bt_put(notification);
+end:
        return ret;
 }
 
@@ -656,7 +654,7 @@ enum bt_component_status sink_consume(
        enum bt_notification_iterator_status it_ret;
 
        BT_ASSERT(user_data && user_data->notif_iter);
-       it_ret = common_consume(user_data->notif_iter);
+       it_ret = common_consume(user_data->notif_iter, false);
 
        if (it_ret < 0) {
                ret = BT_COMPONENT_STATUS_ERROR;
@@ -679,7 +677,8 @@ end:
 }
 
 static
-void sink_port_connected(struct bt_private_component *private_component,
+enum bt_component_status sink_port_connected(
+               struct bt_private_component *private_component,
                struct bt_private_port *self_private_port,
                struct bt_port *other_port)
 {
@@ -695,6 +694,7 @@ void sink_port_connected(struct bt_private_component *private_component,
                priv_conn, &user_data->notif_iter);
        BT_ASSERT(conn_status == 0);
        bt_put(priv_conn);
+       return BT_COMPONENT_STATUS_OK;
 }
 
 static
@@ -899,7 +899,7 @@ void test_output_port_notification_iterator(void)
 
        /* Consume the notification iterator */
        while (iter_status == BT_NOTIFICATION_ITERATOR_STATUS_OK) {
-               iter_status = common_consume(notif_iter);
+               iter_status = common_consume(notif_iter, true);
        }
 
        ok(iter_status == BT_NOTIFICATION_ITERATOR_STATUS_END,
@@ -914,40 +914,6 @@ void test_output_port_notification_iterator(void)
        bt_put(notif_iter);
 }
 
-static
-void test_output_port_notification_iterator_cannot_consume(void)
-{
-       struct bt_component *src_comp;
-       struct bt_notification_iterator *notif_iter;
-       struct bt_port *upstream_port;
-
-       clear_test_events();
-       current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR;
-       diag("test: cannot consume graph with existing output port notification iterator");
-       BT_ASSERT(!graph);
-       graph = bt_graph_create();
-       BT_ASSERT(graph);
-       create_source_sink(graph, &src_comp, NULL);
-
-       /* Create notification iterator on source's output port */
-       upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out");
-       notif_iter = bt_output_port_notification_iterator_create(upstream_port,
-               NULL);
-       BT_ASSERT(notif_iter);
-       bt_put(upstream_port);
-
-       /*
-        * This should fail because the graph is now managed by the
-        * notification iterator.
-        */
-       ok(bt_graph_run(graph) == BT_GRAPH_STATUS_CANNOT_CONSUME,
-               "bt_graph_run() returns BT_GRAPH_STATUS_CANNOT_CONSUME when there's an output port notification iterator");
-
-       bt_put(src_comp);
-       BT_PUT(graph);
-       bt_put(notif_iter);
-}
-
 #define DEBUG_ENV_VAR  "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
 
 int main(int argc, char **argv)
@@ -960,7 +926,6 @@ int main(int argc, char **argv)
        init_static_data();
        test_no_auto_notifs();
        test_output_port_notification_iterator();
-       test_output_port_notification_iterator_cannot_consume();
        fini_static_data();
        return exit_status();
 }
This page took 0.029876 seconds and 4 git commands to generate.