Remove notification iterator seeking API until it's supported
[babeltrace.git] / tests / plugins / test-utils-muxer.c
index 8b0e5209de3b5c574812900a11a9861e18beca16..85ed44a92cfef868612e7b4e91e73184a647b603 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <inttypes.h>
 #include <string.h>
 #include <assert.h>
@@ -45,6 +46,7 @@
 #include <babeltrace/graph/notification-packet.h>
 #include <babeltrace/graph/port.h>
 #include <babeltrace/graph/private-component-source.h>
+#include <babeltrace/graph/private-component-sink.h>
 #include <babeltrace/graph/private-component.h>
 #include <babeltrace/graph/private-connection.h>
 #include <babeltrace/graph/private-notification-iterator.h>
 
 #include "tap/tap.h"
 
-#define NR_TESTS       14
+#define NR_TESTS       12
 
 enum test {
        TEST_NO_TS,
        TEST_NO_UPSTREAM_CONNECTION,
-       TEST_EVENT_NOTIF_VS_THE_REST,
        TEST_SIMPLE_4_PORTS,
        TEST_4_PORTS_WITH_RETRIES,
        TEST_SINGLE_END_THEN_MULTIPLE_FULL,
@@ -73,6 +74,8 @@ enum test_event_type {
        TEST_EV_TYPE_NOTIF_INACTIVITY,
        TEST_EV_TYPE_NOTIF_PACKET_BEGIN,
        TEST_EV_TYPE_NOTIF_PACKET_END,
+       TEST_EV_TYPE_NOTIF_STREAM_BEGIN,
+       TEST_EV_TYPE_NOTIF_STREAM_END,
        TEST_EV_TYPE_AGAIN,
        TEST_EV_TYPE_END,
        TEST_EV_TYPE_SENTINEL,
@@ -104,7 +107,10 @@ static struct bt_clock_class_priority_map *src_empty_cc_prio_map;
 static struct bt_ctf_clock_class *src_clock_class;
 static struct bt_ctf_stream_class *src_stream_class;
 static struct bt_ctf_event_class *src_event_class;
-static struct bt_ctf_packet *src_packet;
+static struct bt_ctf_packet *src_packet0;
+static struct bt_ctf_packet *src_packet1;
+static struct bt_ctf_packet *src_packet2;
+static struct bt_ctf_packet *src_packet3;
 
 enum {
        SEQ_END = -1,
@@ -117,6 +123,7 @@ struct src_iter_user_data {
        size_t iter_index;
        int64_t *seq;
        size_t at;
+       struct bt_ctf_packet *packet;
 };
 
 struct sink_user_data {
@@ -146,21 +153,20 @@ static int64_t seq4[] = {
 };
 
 static int64_t seq1_with_again[] = {
-       24, 53, 97, 105, 119, 210, SEQ_AGAIN, SEQ_AGAIN, 222, 240, 292,
-       317, 353, 407, 433, 473, 487, 504, 572, 615, 708, 766, 850, 852,
-       931, 951, 956, 996, SEQ_END,
+       24, 53, 97, 105, 119, 210, SEQ_AGAIN, 222, 240, 292, 317, 353,
+       407, 433, 473, 487, 504, 572, 615, 708, 766, 850, 852, 931, 951,
+       956, 996, SEQ_END,
 };
 
 static int64_t seq2_with_again[] = {
        51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631,
-       644, 668, 714, 744, 750, 778, 790, 836, SEQ_AGAIN, SEQ_AGAIN,
-       SEQ_END,
+       644, 668, 714, 744, 750, 778, 790, 836, SEQ_AGAIN, SEQ_END,
 };
 
 static int64_t seq3_with_again[] = {
        8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, SEQ_AGAIN,
-       SEQ_AGAIN, 678, 717, 731, 733, 788, 819, 820, 857, 892, 903,
-       944, 998, SEQ_END,
+       678, 717, 731, 733, 788, 819, 820, 857, 892, 903, 944, 998,
+       SEQ_END,
 };
 
 static int64_t seq4_with_again[] = {
@@ -173,14 +179,6 @@ static int64_t seq5[] = {
        1, 4, 189, 1001, SEQ_END,
 };
 
-static int64_t seq6[] = {
-       1, 2, 12, SEQ_PACKET_BEGIN, 14, 19, SEQ_END,
-};
-
-static int64_t seq7[] = {
-       8, 9, SEQ_PACKET_BEGIN, 10, 13, SEQ_PACKET_END, 22, SEQ_END,
-};
-
 static
 void clear_test_events(void)
 {
@@ -208,6 +206,12 @@ void print_test_event(FILE *fp, const struct test_event *event)
        case TEST_EV_TYPE_NOTIF_PACKET_END:
                fprintf(fp, "TEST_EV_TYPE_NOTIF_PACKET_END");
                break;
+       case TEST_EV_TYPE_NOTIF_STREAM_BEGIN:
+               fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
+               break;
+       case TEST_EV_TYPE_NOTIF_STREAM_END:
+               fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_END");
+               break;
        case TEST_EV_TYPE_AGAIN:
                fprintf(fp, "TEST_EV_TYPE_AGAIN");
                break;
@@ -299,6 +303,10 @@ bool compare_test_events(const struct test_event *expected_events)
        }
 
        if (i != test_events->len) {
+               if (debug) {
+                       fprintf(stderr, ":: Length mismatch\n");
+               }
+
                return false;
        }
 
@@ -327,7 +335,7 @@ void init_static_data(void)
        assert(ret == 0);
        ret = bt_ctf_trace_set_packet_header_type(trace, empty_struct_ft);
        assert(ret == 0);
-       src_clock_class = bt_ctf_clock_class_create("my-clock");
+       src_clock_class = bt_ctf_clock_class_create("my-clock", 1000000000);
        assert(src_clock_class);
        ret = bt_ctf_clock_class_set_is_absolute(src_clock_class, 1);
        assert(ret == 0);
@@ -363,13 +371,28 @@ void init_static_data(void)
        assert(ret == 0);
        ret = bt_ctf_trace_add_stream_class(trace, src_stream_class);
        assert(ret == 0);
-       stream = bt_ctf_stream_create(src_stream_class, "my-stream");
+       stream = bt_ctf_stream_create(src_stream_class, "stream0");
+       assert(stream);
+       src_packet0 = bt_ctf_packet_create(stream);
+       assert(src_packet0);
+       bt_put(stream);
+       stream = bt_ctf_stream_create(src_stream_class, "stream1");
        assert(stream);
-       src_packet = bt_ctf_packet_create(stream);
-       assert(src_packet);
+       src_packet1 = bt_ctf_packet_create(stream);
+       assert(src_packet0);
+       bt_put(stream);
+       stream = bt_ctf_stream_create(src_stream_class, "stream2");
+       assert(stream);
+       src_packet2 = bt_ctf_packet_create(stream);
+       assert(src_packet0);
+       bt_put(stream);
+       stream = bt_ctf_stream_create(src_stream_class, "stream3");
+       assert(stream);
+       src_packet3 = bt_ctf_packet_create(stream);
+       assert(src_packet0);
+       bt_put(stream);
 
        bt_put(trace);
-       bt_put(stream);
        bt_put(empty_struct_ft);
 }
 
@@ -385,6 +408,10 @@ void fini_static_data(void)
        bt_put(src_clock_class);
        bt_put(src_stream_class);
        bt_put(src_event_class);
+       bt_put(src_packet0);
+       bt_put(src_packet1);
+       bt_put(src_packet2);
+       bt_put(src_packet3);
 }
 
 static
@@ -421,19 +448,29 @@ enum bt_notification_iterator_status src_iter_init(
        user_data->iter_index = port_name[3] - '0';
        bt_put(port);
 
+       switch (user_data->iter_index) {
+       case 0:
+               user_data->packet = src_packet0;
+               break;
+       case 1:
+               user_data->packet = src_packet1;
+               break;
+       case 2:
+               user_data->packet = src_packet2;
+               break;
+       case 3:
+               user_data->packet = src_packet3;
+               break;
+       default:
+               abort();
+       }
+
        switch (current_test) {
        case TEST_NO_TS:
                if (user_data->iter_index == 1) {
                        user_data->seq = seq5;
                }
                break;
-       case TEST_EVENT_NOTIF_VS_THE_REST:
-               if (user_data->iter_index == 0) {
-                       user_data->seq = seq6;
-               } else {
-                       user_data->seq = seq7;
-               }
-               break;
        case TEST_SIMPLE_4_PORTS:
                if (user_data->iter_index == 0) {
                        user_data->seq = seq1;
@@ -467,20 +504,21 @@ enum bt_notification_iterator_status src_iter_init(
                }
                break;
        default:
-               assert(false);
+               abort();
        }
 
        return BT_NOTIFICATION_ITERATOR_STATUS_OK;
 }
 
 static
-struct bt_ctf_event *src_create_event(int64_t ts_ns)
+struct bt_ctf_event *src_create_event(struct bt_ctf_packet *packet,
+               int64_t ts_ns)
 {
        struct bt_ctf_event *event = bt_ctf_event_create(src_event_class);
        int ret;
 
        assert(event);
-       ret = bt_ctf_event_set_packet(event, src_packet);
+       ret = bt_ctf_event_set_packet(event, packet);
        assert(ret == 0);
 
        if (ts_ns != -1) {
@@ -490,6 +528,7 @@ struct bt_ctf_event *src_create_event(int64_t ts_ns)
                        (uint64_t) ts_ns);
                assert(clock_value);
                ret = bt_ctf_event_set_clock_value(event, clock_value);
+               assert(ret == 0);
                bt_put(clock_value);
        }
 
@@ -519,17 +558,18 @@ struct bt_notification_iterator_next_return src_iter_next_seq(
                break;
        case SEQ_PACKET_BEGIN:
                next_return.notification =
-                       bt_notification_packet_begin_create(src_packet);
+                       bt_notification_packet_begin_create(user_data->packet);
                assert(next_return.notification);
                break;
        case SEQ_PACKET_END:
                next_return.notification =
-                       bt_notification_packet_end_create(src_packet);
+                       bt_notification_packet_end_create(user_data->packet);
                assert(next_return.notification);
                break;
        default:
        {
-               struct bt_ctf_event *event = src_create_event(cur_ts_ns);
+               struct bt_ctf_event *event = src_create_event(
+                       user_data->packet, cur_ts_ns);
 
                assert(event);
                next_return.notification = bt_notification_event_create(event,
@@ -552,13 +592,14 @@ struct bt_notification_iterator_next_return src_iter_next(
                struct bt_private_notification_iterator *priv_iterator)
 {
        struct bt_notification_iterator_next_return next_return = {
-               .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
                .notification = NULL,
+               .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
        };
        struct src_iter_user_data *user_data =
                bt_private_notification_iterator_get_user_data(priv_iterator);
        struct bt_private_component *private_component =
                bt_private_notification_iterator_get_private_component(priv_iterator);
+       int ret;
 
        assert(user_data);
        assert(private_component);
@@ -568,10 +609,12 @@ struct bt_notification_iterator_next_return src_iter_next(
                if (user_data->iter_index == 0) {
                        if (user_data->at == 0) {
                                next_return.notification =
-                                       bt_notification_packet_begin_create(src_packet);
+                                       bt_notification_packet_begin_create(
+                                               user_data->packet);
                                assert(next_return.notification);
                        } else if (user_data->at < 6) {
-                               struct bt_ctf_event *event = src_create_event(-1);
+                               struct bt_ctf_event *event = src_create_event(
+                                       user_data->packet, -1);
 
                                assert(event);
                                next_return.notification =
@@ -589,23 +632,18 @@ struct bt_notification_iterator_next_return src_iter_next(
                        next_return = src_iter_next_seq(user_data);
                }
                break;
-       case TEST_EVENT_NOTIF_VS_THE_REST:
        case TEST_SIMPLE_4_PORTS:
        case TEST_4_PORTS_WITH_RETRIES:
                next_return = src_iter_next_seq(user_data);
                break;
        case TEST_SINGLE_END_THEN_MULTIPLE_FULL:
                if (user_data->iter_index == 0) {
-                       struct bt_private_port *priv_port;
-
-                       priv_port = bt_private_component_source_add_output_private_port(
-                               private_component, "out1");
-                       assert(priv_port);
-                       bt_put(priv_port);
-                       priv_port = bt_private_component_source_add_output_private_port(
-                               private_component, "out2");
-                       assert(priv_port);
-                       bt_put(priv_port);
+                       ret = bt_private_component_source_add_output_private_port(
+                               private_component, "out1", NULL, NULL);
+                       assert(ret == 0);
+                       ret = bt_private_component_source_add_output_private_port(
+                               private_component, "out2", NULL, NULL);
+                       assert(ret == 0);
                        next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END;
                } else {
                        next_return = src_iter_next_seq(user_data);
@@ -617,16 +655,12 @@ struct bt_notification_iterator_next_return src_iter_next(
                                next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN;
                                user_data->at++;
                        } else {
-                               struct bt_private_port *priv_port;
-
-                               priv_port = bt_private_component_source_add_output_private_port(
-                                       private_component, "out1");
-                               assert(priv_port);
-                               bt_put(priv_port);
-                               priv_port = bt_private_component_source_add_output_private_port(
-                                       private_component, "out2");
-                               assert(priv_port);
-                               bt_put(priv_port);
+                               ret = bt_private_component_source_add_output_private_port(
+                                       private_component, "out1", NULL, NULL);
+                               assert(ret == 0);
+                               ret = bt_private_component_source_add_output_private_port(
+                                       private_component, "out2", NULL, NULL);
+                               assert(ret == 0);
                                next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END;
                        }
                } else {
@@ -634,7 +668,7 @@ struct bt_notification_iterator_next_return src_iter_next(
                }
                break;
        default:
-               assert(false);
+               abort();
        }
 
        bt_put(private_component);
@@ -646,21 +680,11 @@ enum bt_component_status src_init(
                struct bt_private_component *private_component,
                struct bt_value *params, void *init_method_data)
 {
-       struct bt_private_port *priv_port;
        int ret;
        size_t nb_ports;
 
-       priv_port = bt_private_component_source_get_default_output_private_port(
-               private_component);
-       if (priv_port) {
-               ret = bt_private_port_remove_from_component(priv_port);
-               assert(ret == 0);
-               bt_put(priv_port);
-       }
-
        switch (current_test) {
        case TEST_NO_TS:
-       case TEST_EVENT_NOTIF_VS_THE_REST:
                nb_ports = 2;
                break;
        case TEST_SINGLE_END_THEN_MULTIPLE_FULL:
@@ -673,31 +697,27 @@ enum bt_component_status src_init(
        }
 
        if (nb_ports >= 1) {
-               priv_port = bt_private_component_source_add_output_private_port(
-                       private_component, "out0");
-               assert(priv_port);
-               bt_put(priv_port);
+               ret = bt_private_component_source_add_output_private_port(
+                       private_component, "out0", NULL, NULL);
+               assert(ret == 0);
        }
 
        if (nb_ports >= 2) {
-               priv_port = bt_private_component_source_add_output_private_port(
-                       private_component, "out1");
-               assert(priv_port);
-               bt_put(priv_port);
+               ret = bt_private_component_source_add_output_private_port(
+                       private_component, "out1", NULL, NULL);
+               assert(ret == 0);
        }
 
        if (nb_ports >= 3) {
-               priv_port = bt_private_component_source_add_output_private_port(
-                       private_component, "out2");
-               assert(priv_port);
-               bt_put(priv_port);
+               ret = bt_private_component_source_add_output_private_port(
+                       private_component, "out2", NULL, NULL);
+               assert(ret == 0);
        }
 
        if (nb_ports >= 4) {
-               priv_port = bt_private_component_source_add_output_private_port(
-                       private_component, "out3");
-               assert(priv_port);
-               bt_put(priv_port);
+               ret = bt_private_component_source_add_output_private_port(
+                       private_component, "out3", NULL, NULL);
+               assert(ret == 0);
        }
 
        return BT_COMPONENT_STATUS_OK;
@@ -822,6 +842,12 @@ enum bt_component_status sink_consume(
        case BT_NOTIFICATION_TYPE_PACKET_END:
                test_event.type = TEST_EV_TYPE_NOTIF_PACKET_END;
                break;
+       case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
+               test_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN;
+               break;
+       case BT_NOTIFICATION_TYPE_STREAM_END:
+               test_event.type = TEST_EV_TYPE_NOTIF_STREAM_END;
+               break;
        default:
                test_event.type = TEST_EV_TYPE_NOTIF_UNEXPECTED;
                break;
@@ -845,12 +871,13 @@ void sink_port_connected(struct bt_private_component *private_component,
                bt_private_port_get_private_connection(self_private_port);
        struct sink_user_data *user_data = bt_private_component_get_user_data(
                private_component);
+       enum bt_connection_status conn_status;
 
        assert(user_data);
        assert(priv_conn);
-       user_data->notif_iter =
-               bt_private_connection_create_notification_iterator(priv_conn);
-       assert(user_data->notif_iter);
+       conn_status = bt_private_connection_create_notification_iterator(
+               priv_conn, NULL, &user_data->notif_iter);
+       assert(conn_status == 0);
        bt_put(priv_conn);
 }
 
@@ -866,6 +893,9 @@ enum bt_component_status sink_init(
        ret = bt_private_component_set_user_data(private_component,
                user_data);
        assert(ret == 0);
+       ret = bt_private_component_sink_add_input_private_port(
+               private_component, "in", NULL, NULL);
+       assert(ret == 0);
        return BT_COMPONENT_STATUS_OK;
 }
 
@@ -882,7 +912,8 @@ void sink_finalize(struct bt_private_component *private_component)
 }
 
 static
-void create_source_muxer_sink(struct bt_component **source,
+void create_source_muxer_sink(struct bt_graph *graph,
+               struct bt_component **source,
                struct bt_component **muxer,
                struct bt_component **sink)
 {
@@ -905,15 +936,15 @@ void create_source_muxer_sink(struct bt_component **source,
        ret = bt_component_class_source_set_notification_iterator_finalize_method(
                src_comp_class, src_iter_finalize);
        assert(ret == 0);
-       *source = bt_component_create(src_comp_class, "source", NULL);
-       assert(*source);
+       ret = bt_graph_add_component(graph, src_comp_class, "source", NULL, source);
+       assert(ret == 0);
 
        /* Create muxer component */
        muxer_comp_class = bt_plugin_find_component_class("utils", "muxer",
                BT_COMPONENT_CLASS_TYPE_FILTER);
        assert(muxer_comp_class);
-       *muxer = bt_component_create(muxer_comp_class, "muxer", NULL);
-       assert(*muxer);
+       ret = bt_graph_add_component(graph, muxer_comp_class, "muxer", NULL, muxer);
+       assert(ret == 0);
 
        /* Create sink component */
        sink_comp_class = bt_component_class_sink_create("sink", sink_consume);
@@ -925,7 +956,8 @@ void create_source_muxer_sink(struct bt_component **source,
        ret = bt_component_class_set_port_connected_method(sink_comp_class,
                sink_port_connected);
        assert(ret == 0);
-       *sink = bt_component_create(sink_comp_class, "sink", NULL);
+       ret = bt_graph_add_component(graph, sink_comp_class, "sink", NULL, sink);
+       assert(ret == 0);
 
        bt_put(src_comp_class);
        bt_put(muxer_comp_class);
@@ -943,49 +975,46 @@ void do_std_test(enum test test, const char *name,
        struct bt_port *upstream_port;
        struct bt_port *downstream_port;
        struct bt_graph *graph;
-       size_t i;
-       uint64_t count;
-       void *conn;
-       int ret;
+       int64_t i;
+       int64_t count;
        enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
 
        clear_test_events();
        current_test = test;
        diag("test: %s", name);
-       create_source_muxer_sink(&src_comp, &muxer_comp, &sink_comp);
        graph = bt_graph_create();
        assert(graph);
+       create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp);
 
        /* Connect source output ports to muxer input ports */
        if (with_upstream) {
-               ret = bt_component_source_get_output_port_count(src_comp, &count);
-               assert(ret == 0);
+               count = bt_component_source_get_output_port_count(src_comp);
+               assert(count >= 0);
 
                for (i = 0; i < count; i++) {
-                       upstream_port = bt_component_source_get_output_port_at_index(
+                       upstream_port = bt_component_source_get_output_port_by_index(
                                src_comp, i);
                        assert(upstream_port);
-                       downstream_port = bt_component_filter_get_input_port_at_index(
+                       downstream_port = bt_component_filter_get_input_port_by_index(
                                muxer_comp, i);
                        assert(downstream_port);
-                       conn = bt_graph_connect_ports(graph,
-                               upstream_port, downstream_port);
-                       assert(conn);
-                       bt_put(conn);
+                       graph_status = bt_graph_connect_ports(graph,
+                               upstream_port, downstream_port, NULL);
+                       assert(graph_status == 0);
                        bt_put(upstream_port);
                        bt_put(downstream_port);
                }
        }
 
        /* Connect muxer output port to sink input port */
-       upstream_port = bt_component_filter_get_output_port(muxer_comp,
+       upstream_port = bt_component_filter_get_output_port_by_name(muxer_comp,
                "out");
        assert(upstream_port);
-       downstream_port = bt_component_sink_get_default_input_port(sink_comp);
+       downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in");
        assert(downstream_port);
-       conn = bt_graph_connect_ports(graph, upstream_port, downstream_port);
-       assert(conn);
-       bt_put(conn);
+       graph_status = bt_graph_connect_ports(graph, upstream_port,
+               downstream_port, NULL);
+       assert(graph_status == 0);
        bt_put(upstream_port);
        bt_put(downstream_port);
 
@@ -1008,16 +1037,23 @@ static
 void test_no_ts(void)
 {
        const struct test_event expected_test_events[] = {
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
                { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 1, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 4, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 189, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 1001, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_END, },
                { .type = TEST_EV_TYPE_SENTINEL, },
        };
@@ -1039,35 +1075,17 @@ void test_no_upstream_connection(void)
 }
 
 static
-void test_event_notif_vs_the_rest(void)
+void test_simple_4_ports(void)
 {
        const struct test_event expected_test_events[] = {
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 1, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 2, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 9, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
                { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 10, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 12, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
                { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 13, },
-               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 14, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 19, },
-               { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 22, },
-               { .type = TEST_EV_TYPE_END, },
-               { .type = TEST_EV_TYPE_SENTINEL, },
-       };
-
-       do_std_test(TEST_EVENT_NOTIF_VS_THE_REST, "event notifications vs. the rest",
-               expected_test_events, true);
-}
-
-
-static
-void test_simple_4_ports(void)
-{
-       const struct test_event expected_test_events[] = {
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 24 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 41 },
@@ -1146,6 +1164,8 @@ void test_simple_4_ports(void)
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 825 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 850 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 852 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
@@ -1162,8 +1182,14 @@ void test_simple_4_ports(void)
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 956 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 985 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 996 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 999 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_END, },
                { .type = TEST_EV_TYPE_SENTINEL, },
        };
@@ -1177,6 +1203,14 @@ void test_4_ports_with_retries(void)
 {
        const struct test_event expected_test_events[] = {
                { .type = TEST_EV_TYPE_AGAIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 24 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 41 },
@@ -1258,6 +1292,8 @@ void test_4_ports_with_retries(void)
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 825 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
                { .type = TEST_EV_TYPE_AGAIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 850 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 852 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
@@ -1274,8 +1310,14 @@ void test_4_ports_with_retries(void)
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 956 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 985 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 996 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 999 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_END, },
                { .type = TEST_EV_TYPE_SENTINEL, },
        };
@@ -1290,17 +1332,16 @@ void connect_port_to_first_avail_muxer_port(struct bt_graph *graph,
                struct bt_component *muxer_comp)
 {
        struct bt_port *avail_muxer_port = NULL;
-       void *conn;
-       uint64_t i;
-       uint64_t count;
-       int ret;
+       int64_t i;
+       int64_t count;
+       enum bt_graph_status graph_status;
 
-       ret = bt_component_filter_get_input_port_count(muxer_comp, &count);
-       assert(ret == 0);
+       count = bt_component_filter_get_input_port_count(muxer_comp);
+       assert(count >= 0);
 
        for (i = 0; i < count; i++) {
                struct bt_port *muxer_port =
-                       bt_component_filter_get_input_port_at_index(
+                       bt_component_filter_get_input_port_by_index(
                                muxer_comp, i);
 
                assert(muxer_port);
@@ -1313,9 +1354,9 @@ void connect_port_to_first_avail_muxer_port(struct bt_graph *graph,
                }
        }
 
-       conn = bt_graph_connect_ports(graph, source_port, avail_muxer_port);
-       assert(conn);
-       bt_put(conn);
+       graph_status = bt_graph_connect_ports(graph, source_port,
+               avail_muxer_port, NULL);
+       assert(graph_status == 0);
        bt_put(avail_muxer_port);
 }
 
@@ -1349,13 +1390,16 @@ void test_single_end_then_multiple_full(void)
        struct bt_port *upstream_port;
        struct bt_port *downstream_port;
        struct bt_graph *graph;
-       size_t i;
-       uint64_t count;
-       void *conn;
+       int64_t i;
+       int64_t count;
        int ret;
        enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
        struct graph_listener_data graph_listener_data;
        const struct test_event expected_test_events[] = {
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 },
@@ -1396,11 +1440,15 @@ void test_single_end_then_multiple_full(void)
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_END, },
                { .type = TEST_EV_TYPE_SENTINEL, },
        };
@@ -1408,24 +1456,24 @@ void test_single_end_then_multiple_full(void)
        clear_test_events();
        current_test = TEST_SINGLE_END_THEN_MULTIPLE_FULL;
        diag("test: single end then multiple full");
-       create_source_muxer_sink(&src_comp, &muxer_comp, &sink_comp);
        graph = bt_graph_create();
        assert(graph);
+       create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp);
        graph_listener_data.graph = graph;
        graph_listener_data.source = src_comp;
        graph_listener_data.muxer = muxer_comp;
        graph_listener_data.sink = sink_comp;
        ret = bt_graph_add_port_added_listener(graph,
-               graph_port_added_listener_connect_to_avail_muxer_port,
+               graph_port_added_listener_connect_to_avail_muxer_port, NULL,
                &graph_listener_data);
-       assert(ret == 0);
+       assert(ret >= 0);
 
        /* Connect source output ports to muxer input ports */
-       ret = bt_component_source_get_output_port_count(src_comp, &count);
+       count = bt_component_source_get_output_port_count(src_comp);
        assert(ret == 0);
 
        for (i = 0; i < count; i++) {
-               upstream_port = bt_component_source_get_output_port_at_index(
+               upstream_port = bt_component_source_get_output_port_by_index(
                        src_comp, i);
                assert(upstream_port);
                connect_port_to_first_avail_muxer_port(graph,
@@ -1434,14 +1482,14 @@ void test_single_end_then_multiple_full(void)
        }
 
        /* Connect muxer output port to sink input port */
-       upstream_port = bt_component_filter_get_output_port(muxer_comp,
+       upstream_port = bt_component_filter_get_output_port_by_name(muxer_comp,
                "out");
        assert(upstream_port);
-       downstream_port = bt_component_sink_get_default_input_port(sink_comp);
+       downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in");
        assert(downstream_port);
-       conn = bt_graph_connect_ports(graph, upstream_port, downstream_port);
-       assert(conn);
-       bt_put(conn);
+       graph_status = bt_graph_connect_ports(graph, upstream_port,
+               downstream_port, NULL);
+       assert(graph_status == 0);
        bt_put(upstream_port);
        bt_put(downstream_port);
 
@@ -1469,14 +1517,17 @@ void test_single_again_end_then_multiple_full(void)
        struct bt_port *upstream_port;
        struct bt_port *downstream_port;
        struct bt_graph *graph;
-       size_t i;
-       uint64_t count;
-       void *conn;
+       int64_t i;
+       int64_t count;
        int ret;
        enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
        struct graph_listener_data graph_listener_data;
        const struct test_event expected_test_events[] = {
                { .type = TEST_EV_TYPE_AGAIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 },
@@ -1517,11 +1568,15 @@ void test_single_again_end_then_multiple_full(void)
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 },
                { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
+               { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
+               { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
                { .type = TEST_EV_TYPE_END, },
                { .type = TEST_EV_TYPE_SENTINEL, },
        };
@@ -1529,24 +1584,24 @@ void test_single_again_end_then_multiple_full(void)
        clear_test_events();
        current_test = TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL;
        diag("test: single again then end then multiple full");
-       create_source_muxer_sink(&src_comp, &muxer_comp, &sink_comp);
        graph = bt_graph_create();
        assert(graph);
+       create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp);
        graph_listener_data.graph = graph;
        graph_listener_data.source = src_comp;
        graph_listener_data.muxer = muxer_comp;
        graph_listener_data.sink = sink_comp;
        ret = bt_graph_add_port_added_listener(graph,
-               graph_port_added_listener_connect_to_avail_muxer_port,
+               graph_port_added_listener_connect_to_avail_muxer_port, NULL,
                &graph_listener_data);
-       assert(ret == 0);
+       assert(ret >= 0);
 
        /* Connect source output ports to muxer input ports */
-       ret = bt_component_source_get_output_port_count(src_comp, &count);
+       count = bt_component_source_get_output_port_count(src_comp);
        assert(ret == 0);
 
        for (i = 0; i < count; i++) {
-               upstream_port = bt_component_source_get_output_port_at_index(
+               upstream_port = bt_component_source_get_output_port_by_index(
                        src_comp, i);
                assert(upstream_port);
                connect_port_to_first_avail_muxer_port(graph,
@@ -1555,14 +1610,14 @@ void test_single_again_end_then_multiple_full(void)
        }
 
        /* Connect muxer output port to sink input port */
-       upstream_port = bt_component_filter_get_output_port(muxer_comp,
+       upstream_port = bt_component_filter_get_output_port_by_name(muxer_comp,
                "out");
        assert(upstream_port);
-       downstream_port = bt_component_sink_get_default_input_port(sink_comp);
+       downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in");
        assert(downstream_port);
-       conn = bt_graph_connect_ports(graph, upstream_port, downstream_port);
-       assert(conn);
-       bt_put(conn);
+       graph_status = bt_graph_connect_ports(graph, upstream_port,
+               downstream_port, NULL);
+       assert(graph_status == 0);
        bt_put(upstream_port);
        bt_put(downstream_port);
 
@@ -1593,7 +1648,6 @@ int main(int argc, char **argv)
        init_static_data();
        test_no_ts();
        test_no_upstream_connection();
-       test_event_notif_vs_the_rest();
        test_simple_4_ports();
        test_4_ports_with_retries();
        test_single_end_then_multiple_full();
This page took 0.034604 seconds and 4 git commands to generate.