X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Flib%2Ftest_bt_notification_iterator.c;h=90f4dff35f5bc3aefc2e765629e2c16ca9ff4558;hb=50842bdc4c21f3de2b63e29cdac730af8b6dcca6;hp=99664498b3df718a607c7ff3feb779042ba027d0;hpb=fa054faf3a18fd8003510c32718c1fd4fbf3dd46;p=babeltrace.git diff --git a/tests/lib/test_bt_notification_iterator.c b/tests/lib/test_bt_notification_iterator.c index 99664498..90f4dff3 100644 --- a/tests/lib/test_bt_notification_iterator.c +++ b/tests/lib/test_bt_notification_iterator.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -37,18 +38,20 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include #include #include -#include +#include #include #include #include @@ -56,7 +59,7 @@ #include "tap/tap.h" -#define NR_TESTS 24 +#define NR_TESTS 31 enum test { TEST_NO_AUTO_NOTIFS, @@ -71,6 +74,7 @@ enum test { TEST_AUTO_PACKET_END_STREAM_END_FROM_END, TEST_MULTIPLE_AUTO_STREAM_END_FROM_END, TEST_MULTIPLE_AUTO_PACKET_END_STREAM_END_FROM_END, + TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR, }; enum test_event_type { @@ -87,27 +91,22 @@ enum test_event_type { struct test_event { enum test_event_type type; - struct bt_ctf_stream *stream; - struct bt_ctf_packet *packet; -}; - -struct source_muxer_sink { - struct bt_component *source; - struct bt_component *sink; + struct bt_stream *stream; + struct bt_packet *packet; }; static bool debug = false; static enum test current_test; static GArray *test_events; static struct bt_clock_class_priority_map *src_empty_cc_prio_map; -static struct bt_ctf_stream_class *src_stream_class; -static struct bt_ctf_event_class *src_event_class; -static struct bt_ctf_stream *src_stream1; -static struct bt_ctf_stream *src_stream2; -static struct bt_ctf_packet *src_stream1_packet1; -static struct bt_ctf_packet *src_stream1_packet2; -static struct bt_ctf_packet *src_stream2_packet1; -static struct bt_ctf_packet *src_stream2_packet2; +static struct bt_stream_class *src_stream_class; +static struct bt_event_class *src_event_class; +static struct bt_stream *src_stream1; +static struct bt_stream *src_stream2; +static struct bt_packet *src_stream1_packet1; +static struct bt_packet *src_stream1_packet2; +static struct bt_packet *src_stream2_packet1; +static struct bt_packet *src_stream2_packet2; enum { SEQ_END = -1, @@ -396,59 +395,56 @@ static void init_static_data(void) { int ret; - struct bt_ctf_trace *trace; - struct bt_ctf_field_type *empty_struct_ft; + struct bt_trace *trace; + struct bt_field_type *empty_struct_ft; /* Test events */ test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event)); assert(test_events); /* Metadata */ - empty_struct_ft = bt_ctf_field_type_structure_create(); + empty_struct_ft = bt_field_type_structure_create(); assert(empty_struct_ft); - trace = bt_ctf_trace_create(); + trace = bt_trace_create(); assert(trace); - ret = bt_ctf_trace_set_native_byte_order(trace, - BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); - assert(ret == 0); - ret = bt_ctf_trace_set_packet_header_type(trace, empty_struct_ft); + ret = bt_trace_set_packet_header_type(trace, empty_struct_ft); assert(ret == 0); src_empty_cc_prio_map = bt_clock_class_priority_map_create(); assert(src_empty_cc_prio_map); - src_stream_class = bt_ctf_stream_class_create("my-stream-class"); + src_stream_class = bt_stream_class_create("my-stream-class"); assert(src_stream_class); - ret = bt_ctf_stream_class_set_packet_context_type(src_stream_class, + ret = bt_stream_class_set_packet_context_type(src_stream_class, empty_struct_ft); assert(ret == 0); - ret = bt_ctf_stream_class_set_event_header_type(src_stream_class, + ret = bt_stream_class_set_event_header_type(src_stream_class, empty_struct_ft); assert(ret == 0); - ret = bt_ctf_stream_class_set_event_context_type(src_stream_class, + ret = bt_stream_class_set_event_context_type(src_stream_class, empty_struct_ft); assert(ret == 0); - src_event_class = bt_ctf_event_class_create("my-event-class"); - ret = bt_ctf_event_class_set_context_type(src_event_class, + src_event_class = bt_event_class_create("my-event-class"); + ret = bt_event_class_set_context_type(src_event_class, empty_struct_ft); assert(ret == 0); - ret = bt_ctf_event_class_set_context_type(src_event_class, + ret = bt_event_class_set_context_type(src_event_class, empty_struct_ft); assert(ret == 0); - ret = bt_ctf_stream_class_add_event_class(src_stream_class, + ret = bt_stream_class_add_event_class(src_stream_class, src_event_class); assert(ret == 0); - ret = bt_ctf_trace_add_stream_class(trace, src_stream_class); + ret = bt_trace_add_stream_class(trace, src_stream_class); assert(ret == 0); - src_stream1 = bt_ctf_stream_create(src_stream_class, "stream-1"); + src_stream1 = bt_stream_create(src_stream_class, "stream-1"); assert(src_stream1); - src_stream2 = bt_ctf_stream_create(src_stream_class, "stream-2"); + src_stream2 = bt_stream_create(src_stream_class, "stream-2"); assert(src_stream2); - src_stream1_packet1 = bt_ctf_packet_create(src_stream1); + src_stream1_packet1 = bt_packet_create(src_stream1); assert(src_stream1_packet1); - src_stream1_packet2 = bt_ctf_packet_create(src_stream1); + src_stream1_packet2 = bt_packet_create(src_stream1); assert(src_stream1_packet2); - src_stream2_packet1 = bt_ctf_packet_create(src_stream2); + src_stream2_packet1 = bt_packet_create(src_stream2); assert(src_stream2_packet1); - src_stream2_packet2 = bt_ctf_packet_create(src_stream2); + src_stream2_packet2 = bt_packet_create(src_stream2); assert(src_stream2_packet2); if (debug) { @@ -484,10 +480,10 @@ void fini_static_data(void) static void src_iter_finalize( - struct bt_private_notification_iterator *private_notification_iterator) + struct bt_private_connection_private_notification_iterator *private_notification_iterator) { struct src_iter_user_data *user_data = - bt_private_notification_iterator_get_user_data( + bt_private_connection_private_notification_iterator_get_user_data( private_notification_iterator); if (user_data) { @@ -497,7 +493,7 @@ void src_iter_finalize( static enum bt_notification_iterator_status src_iter_init( - struct bt_private_notification_iterator *priv_notif_iter, + struct bt_private_connection_private_notification_iterator *priv_notif_iter, struct bt_private_port *private_port) { struct src_iter_user_data *user_data = @@ -505,12 +501,13 @@ enum bt_notification_iterator_status src_iter_init( int ret; assert(user_data); - ret = bt_private_notification_iterator_set_user_data(priv_notif_iter, - user_data); + ret = bt_private_connection_private_notification_iterator_set_user_data( + priv_notif_iter, user_data); assert(ret == 0); switch (current_test) { case TEST_NO_AUTO_NOTIFS: + case TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR: user_data->seq = seq_no_auto_notifs; break; case TEST_AUTO_STREAM_BEGIN_FROM_PACKET_BEGIN: @@ -547,33 +544,33 @@ enum bt_notification_iterator_status src_iter_init( user_data->seq = seq_multiple_auto_packet_end_stream_end_from_end; break; default: - assert(false); + abort(); } return BT_NOTIFICATION_ITERATOR_STATUS_OK; } static -struct bt_ctf_event *src_create_event(struct bt_ctf_packet *packet) +struct bt_event *src_create_event(struct bt_packet *packet) { - struct bt_ctf_event *event = bt_ctf_event_create(src_event_class); + struct bt_event *event = bt_event_create(src_event_class); int ret; assert(event); - ret = bt_ctf_event_set_packet(event, packet); + ret = bt_event_set_packet(event, packet); assert(ret == 0); return event; } static -struct bt_notification_iterator_next_return src_iter_next_seq( +struct bt_notification_iterator_next_method_return src_iter_next_seq( struct src_iter_user_data *user_data) { - struct bt_notification_iterator_next_return next_return = { + struct bt_notification_iterator_next_method_return next_return = { .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, }; int64_t cur_ts_ns; - struct bt_ctf_packet *event_packet = NULL; + struct bt_packet *event_packet = NULL; assert(user_data->seq); cur_ts_ns = user_data->seq[user_data->at]; @@ -661,11 +658,11 @@ struct bt_notification_iterator_next_return src_iter_next_seq( event_packet = src_stream2_packet2; break; default: - assert(false); + abort(); } if (event_packet) { - struct bt_ctf_event *event = src_create_event(event_packet); + struct bt_event *event = src_create_event(event_packet); assert(event); next_return.notification = bt_notification_event_create(event, @@ -682,15 +679,15 @@ struct bt_notification_iterator_next_return src_iter_next_seq( } static -struct bt_notification_iterator_next_return src_iter_next( - struct bt_private_notification_iterator *priv_iterator) +struct bt_notification_iterator_next_method_return src_iter_next( + struct bt_private_connection_private_notification_iterator *priv_iterator) { - struct bt_notification_iterator_next_return next_return = { + 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_notification_iterator_get_user_data(priv_iterator); + bt_private_connection_private_notification_iterator_get_user_data(priv_iterator); assert(user_data); next_return = src_iter_next_seq(user_data); @@ -702,12 +699,11 @@ enum bt_component_status src_init( struct bt_private_component *private_component, struct bt_value *params, void *init_method_data) { - void *priv_port; + int ret; - priv_port = bt_private_component_source_add_output_private_port( - private_component, "out", NULL); - assert(priv_port); - bt_put(priv_port); + ret = bt_private_component_source_add_output_private_port( + private_component, "out", NULL, NULL); + assert(ret == 0); return BT_COMPONENT_STATUS_OK; } @@ -717,51 +713,44 @@ void src_finalize(struct bt_private_component *private_component) } static -enum bt_component_status sink_consume( - struct bt_private_component *priv_component) +enum bt_notification_iterator_status common_consume( + struct bt_notification_iterator *notif_iter) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_notification_iterator_status ret; struct bt_notification *notification = NULL; - struct sink_user_data *user_data = - bt_private_component_get_user_data(priv_component); - enum bt_notification_iterator_status it_ret; struct test_event test_event = { 0 }; bool do_append_test_event = true; + assert(notif_iter); - assert(user_data && user_data->notif_iter); - it_ret = bt_notification_iterator_next(user_data->notif_iter); - - if (it_ret < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = bt_notification_iterator_next(notif_iter); + if (ret < 0) { do_append_test_event = false; goto end; } - switch (it_ret) { + switch (ret) { case BT_NOTIFICATION_ITERATOR_STATUS_END: test_event.type = TEST_EV_TYPE_END; - ret = BT_COMPONENT_STATUS_END; - BT_PUT(user_data->notif_iter); goto end; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: - assert(false); + abort(); default: break; } notification = bt_notification_iterator_get_notification( - user_data->notif_iter); + notif_iter); assert(notification); switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_EVENT: { - struct bt_ctf_event *event; + struct bt_event *event; test_event.type = TEST_EV_TYPE_NOTIF_EVENT; event = bt_notification_event_get_event(notification); assert(event); - test_event.packet = bt_ctf_event_get_packet(event); + test_event.packet = bt_event_get_packet(event); bt_put(event); assert(test_event.packet); bt_put(test_event.packet); @@ -804,7 +793,7 @@ enum bt_component_status sink_consume( } if (test_event.packet) { - test_event.stream = bt_ctf_packet_get_stream(test_event.packet); + test_event.stream = bt_packet_get_stream(test_event.packet); assert(test_event.stream); bt_put(test_event.stream); } @@ -818,6 +807,38 @@ end: return ret; } +static +enum bt_component_status sink_consume( + struct bt_private_component *priv_component) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + struct sink_user_data *user_data = + bt_private_component_get_user_data(priv_component); + enum bt_notification_iterator_status it_ret; + + assert(user_data && user_data->notif_iter); + it_ret = common_consume(user_data->notif_iter); + + if (it_ret < 0) { + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + } + + switch (it_ret) { + case BT_NOTIFICATION_ITERATOR_STATUS_END: + ret = BT_COMPONENT_STATUS_END; + BT_PUT(user_data->notif_iter); + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: + abort(); + default: + break; + } + +end: + return ret; +} + static void sink_port_connected(struct bt_private_component *private_component, struct bt_private_port *self_private_port, @@ -827,13 +848,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, - NULL); - 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); } @@ -844,16 +865,14 @@ enum bt_component_status sink_init( { struct sink_user_data *user_data = g_new0(struct sink_user_data, 1); int ret; - void *priv_port; assert(user_data); ret = bt_private_component_set_user_data(private_component, user_data); assert(ret == 0); - priv_port = bt_private_component_sink_add_input_private_port( - private_component, "in", NULL); - assert(priv_port); - bt_put(priv_port); + ret = bt_private_component_sink_add_input_private_port( + private_component, "in", NULL, NULL); + assert(ret == 0); return BT_COMPONENT_STATUS_OK; } @@ -870,7 +889,7 @@ void sink_finalize(struct bt_private_component *private_component) } static -void create_source_sink(struct bt_component **source, +void create_source_sink(struct bt_graph *graph, struct bt_component **source, struct bt_component **sink) { struct bt_component_class *src_comp_class; @@ -878,36 +897,46 @@ void create_source_sink(struct bt_component **source, int ret; /* Create source component */ - src_comp_class = bt_component_class_source_create("src", src_iter_next); - assert(src_comp_class); - ret = bt_component_class_set_init_method(src_comp_class, src_init); - assert(ret == 0); - ret = bt_component_class_set_finalize_method(src_comp_class, - src_finalize); - assert(ret == 0); - ret = bt_component_class_source_set_notification_iterator_init_method( - src_comp_class, src_iter_init); - assert(ret == 0); - 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); + if (source) { + src_comp_class = bt_component_class_source_create("src", + src_iter_next); + assert(src_comp_class); + ret = bt_component_class_set_init_method(src_comp_class, + src_init); + assert(ret == 0); + ret = bt_component_class_set_finalize_method(src_comp_class, + src_finalize); + assert(ret == 0); + ret = bt_component_class_source_set_notification_iterator_init_method( + src_comp_class, src_iter_init); + assert(ret == 0); + ret = bt_component_class_source_set_notification_iterator_finalize_method( + src_comp_class, src_iter_finalize); + assert(ret == 0); + ret = bt_graph_add_component(graph, src_comp_class, "source", + NULL, source); + assert(ret == 0); + bt_put(src_comp_class); + } /* Create sink component */ - sink_comp_class = bt_component_class_sink_create("sink", sink_consume); - assert(sink_comp_class); - ret = bt_component_class_set_init_method(sink_comp_class, sink_init); - assert(ret == 0); - ret = bt_component_class_set_finalize_method(sink_comp_class, - sink_finalize); - 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); - - bt_put(src_comp_class); - bt_put(sink_comp_class); + if (sink) { + sink_comp_class = bt_component_class_sink_create("sink", + sink_consume); + assert(sink_comp_class); + ret = bt_component_class_set_init_method(sink_comp_class, + sink_init); + assert(ret == 0); + ret = bt_component_class_set_finalize_method(sink_comp_class, + sink_finalize); + ret = bt_component_class_set_port_connected_method( + sink_comp_class, sink_port_connected); + assert(ret == 0); + ret = bt_graph_add_component(graph, sink_comp_class, "sink", + NULL, sink); + assert(ret == 0); + bt_put(sink_comp_class); + } } static @@ -919,24 +948,22 @@ void do_std_test(enum test test, const char *name, struct bt_port *upstream_port; struct bt_port *downstream_port; struct bt_graph *graph; - void *conn; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; clear_test_events(); current_test = test; diag("test: %s", name); - create_source_sink(&src_comp, &sink_comp); graph = bt_graph_create(); assert(graph); + create_source_sink(graph, &src_comp, &sink_comp); /* Connect source to sink */ upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out"); assert(upstream_port); 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); bt_put(upstream_port); bt_put(downstream_port); @@ -1308,6 +1335,156 @@ end: "the produced sequence of test events is the expected one"); } +static +void test_output_port_notification_iterator(void) +{ + const struct test_event expected_test_events[] = { + { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream2, .packet = NULL, }, + { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, + { .type = TEST_EV_TYPE_END, }, + { .type = TEST_EV_TYPE_SENTINEL, }, + }; + struct bt_component *src_comp; + struct bt_notification_iterator *notif_iter; + enum bt_notification_iterator_status iter_status = + BT_NOTIFICATION_ITERATOR_STATUS_OK; + struct bt_port *upstream_port; + struct bt_graph *graph; + + clear_test_events(); + current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; + diag("test: output port notification iterator"); + graph = bt_graph_create(); + 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, NULL); + ok(notif_iter, "bt_output_port_notification_iterator_create() succeeds"); + bt_put(upstream_port); + + /* Consume the notification iterator */ + while (iter_status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { + iter_status = common_consume(notif_iter); + } + + ok(iter_status == BT_NOTIFICATION_ITERATOR_STATUS_END, + "output port notification iterator finishes without any error"); + + /* Compare the resulting test events */ + ok(compare_test_events(expected_test_events), + "the produced sequence of test events is the expected one"); + + bt_put(src_comp); + bt_put(graph); + bt_put(notif_iter); +} + +static +void test_output_port_notification_iterator_subscribe_events(void) +{ + const struct test_event expected_test_events[] = { + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, + { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, + { .type = TEST_EV_TYPE_END, }, + { .type = TEST_EV_TYPE_SENTINEL, }, + }; + const enum bt_notification_type notification_types[] = { + BT_NOTIFICATION_TYPE_EVENT, + BT_NOTIFICATION_TYPE_SENTINEL, + }; + struct bt_component *src_comp; + struct bt_notification_iterator *notif_iter; + enum bt_notification_iterator_status iter_status = + BT_NOTIFICATION_ITERATOR_STATUS_OK; + struct bt_port *upstream_port; + struct bt_graph *graph; + + clear_test_events(); + current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; + diag("test: output port notification iterator with event subscription"); + graph = bt_graph_create(); + 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, notification_types); + ok(notif_iter, "bt_output_port_notification_iterator_create() succeeds"); + bt_put(upstream_port); + + /* Consume the notification iterator */ + while (iter_status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { + iter_status = common_consume(notif_iter); + } + + ok(iter_status == BT_NOTIFICATION_ITERATOR_STATUS_END, + "output port notification iterator finishes without any error"); + + /* Compare the resulting test events */ + ok(compare_test_events(expected_test_events), + "the produced sequence of test events is the expected one"); + + bt_put(src_comp); + bt_put(graph); + 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; + struct bt_graph *graph; + + clear_test_events(); + current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; + diag("test: cannot consume graph with existing output port notification iterator"); + graph = bt_graph_create(); + 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, NULL); + 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) @@ -1330,6 +1507,9 @@ int main(int argc, char **argv) test_auto_packet_end_stream_end_from_end(); test_multiple_auto_stream_end_from_end(); test_multiple_auto_packet_end_stream_end_from_end(); + test_output_port_notification_iterator(); + test_output_port_notification_iterator_subscribe_events(); + test_output_port_notification_iterator_cannot_consume(); fini_static_data(); return exit_status(); }