X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=tests%2Flib%2Ftest_bt_notification_iterator.c;h=387eaa81f22b2135f1c280bc410a8aad41b3ecd4;hb=b19ff26f04df428047676dd736bd7cc9473906fe;hp=be3f6dd85013aa61926bf5317454165113f0d99b;hpb=5c5632787fc9cafa602c89a28966bcfd01ec0204;p=babeltrace.git diff --git a/tests/lib/test_bt_notification_iterator.c b/tests/lib/test_bt_notification_iterator.c index be3f6dd8..387eaa81 100644 --- a/tests/lib/test_bt_notification_iterator.c +++ b/tests/lib/test_bt_notification_iterator.c @@ -21,45 +21,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include "tap/tap.h" -#define NR_TESTS 6 +#define NR_TESTS 5 enum test { TEST_NO_AUTO_NOTIFS, @@ -69,7 +37,6 @@ enum test { enum test_event_type { TEST_EV_TYPE_NOTIF_UNEXPECTED, TEST_EV_TYPE_NOTIF_EVENT, - TEST_EV_TYPE_NOTIF_INACTIVITY, TEST_EV_TYPE_NOTIF_STREAM_BEGIN, TEST_EV_TYPE_NOTIF_PACKET_BEGIN, TEST_EV_TYPE_NOTIF_PACKET_END, @@ -80,23 +47,22 @@ enum test_event_type { struct test_event { enum test_event_type type; - struct bt_stream *stream; - struct bt_packet *packet; + const bt_stream *stream; + const bt_packet *packet; }; 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; -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; +static bt_graph *graph; +static bt_stream_class *src_stream_class; +static bt_event_class *src_event_class; +static bt_stream *src_stream1; +static bt_stream *src_stream2; +static bt_packet *src_stream1_packet1; +static bt_packet *src_stream1_packet2; +static bt_packet *src_stream2_packet1; +static bt_packet *src_stream2_packet2; enum { SEQ_END = -1, @@ -116,7 +82,6 @@ enum { SEQ_EVENT_STREAM1_PACKET2 = -15, SEQ_EVENT_STREAM2_PACKET1 = -16, SEQ_EVENT_STREAM2_PACKET2 = -17, - SEQ_INACTIVITY = -18, }; struct src_iter_user_data { @@ -125,7 +90,7 @@ struct src_iter_user_data { }; struct sink_user_data { - struct bt_notification_iterator *notif_iter; + bt_self_component_port_input_notification_iterator *notif_iter; }; /* @@ -170,9 +135,6 @@ void print_test_event(FILE *fp, const struct test_event *event) case TEST_EV_TYPE_NOTIF_EVENT: fprintf(fp, "TEST_EV_TYPE_NOTIF_EVENT"); break; - case TEST_EV_TYPE_NOTIF_INACTIVITY: - fprintf(fp, "TEST_EV_TYPE_NOTIF_INACTIVITY"); - break; case TEST_EV_TYPE_NOTIF_STREAM_BEGIN: fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN"); break; @@ -246,7 +208,7 @@ bool compare_test_events(const struct test_event *expected_events) const struct test_event *expected_event = expected_events; size_t i = 0; - assert(expected_events); + BT_ASSERT(expected_events); while (true) { const struct test_event *event; @@ -279,58 +241,34 @@ bool compare_test_events(const struct test_event *expected_events) static void init_static_data(void) { - int ret; - struct bt_trace *trace; - struct bt_field_type *empty_struct_ft; + bt_trace_class *trace_class; + bt_trace *trace; /* Test events */ test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event)); - assert(test_events); - - /* Metadata */ - empty_struct_ft = bt_field_type_structure_create(); - assert(empty_struct_ft); - trace = bt_trace_create(); - assert(trace); - ret = bt_trace_set_packet_header_field_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_stream_class_create("my-stream-class"); - assert(src_stream_class); - ret = bt_stream_class_set_packet_context_field_type(src_stream_class, - empty_struct_ft); - assert(ret == 0); - ret = bt_stream_class_set_event_header_field_type(src_stream_class, - empty_struct_ft); - assert(ret == 0); - ret = bt_stream_class_set_event_context_field_type(src_stream_class, - empty_struct_ft); - assert(ret == 0); - src_event_class = bt_event_class_create("my-event-class"); - ret = bt_event_class_set_context_field_type(src_event_class, - empty_struct_ft); - assert(ret == 0); - ret = bt_event_class_set_payload_field_type(src_event_class, - empty_struct_ft); - assert(ret == 0); - ret = bt_stream_class_add_event_class(src_stream_class, - src_event_class); - assert(ret == 0); - ret = bt_trace_add_stream_class(trace, src_stream_class); - assert(ret == 0); - src_stream1 = bt_stream_create(src_stream_class, "stream-1", 0); - assert(src_stream1); - src_stream2 = bt_stream_create(src_stream_class, "stream-2", 1); - assert(src_stream2); + BT_ASSERT(test_events); + + /* Metadata, streams, and packets*/ + trace_class = bt_trace_class_create(); + BT_ASSERT(trace); + src_stream_class = bt_stream_class_create(trace_class); + BT_ASSERT(src_stream_class); + src_event_class = bt_event_class_create(src_stream_class); + BT_ASSERT(src_event_class); + trace = bt_trace_create(trace_class); + BT_ASSERT(trace); + src_stream1 = bt_stream_create(src_stream_class, trace); + BT_ASSERT(src_stream1); + src_stream2 = bt_stream_create(src_stream_class, trace); + BT_ASSERT(src_stream2); src_stream1_packet1 = bt_packet_create(src_stream1); - assert(src_stream1_packet1); + BT_ASSERT(src_stream1_packet1); src_stream1_packet2 = bt_packet_create(src_stream1); - assert(src_stream1_packet2); + BT_ASSERT(src_stream1_packet2); src_stream2_packet1 = bt_packet_create(src_stream2); - assert(src_stream2_packet1); + BT_ASSERT(src_stream2_packet1); src_stream2_packet2 = bt_packet_create(src_stream2); - assert(src_stream2_packet2); + BT_ASSERT(src_stream2_packet2); if (debug) { fprintf(stderr, ":: stream 1: %p\n", src_stream1); @@ -341,8 +279,8 @@ void init_static_data(void) fprintf(stderr, ":: stream 2, packet 2: %p\n", src_stream2_packet2); } - bt_put(trace); - bt_put(empty_struct_ft); + bt_trace_put_ref(trace); + bt_trace_class_put_ref(trace_class); } static @@ -352,24 +290,22 @@ 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); - bt_put(src_stream2); - bt_put(src_stream1_packet1); - bt_put(src_stream1_packet2); - bt_put(src_stream2_packet1); - bt_put(src_stream2_packet2); + bt_stream_class_put_ref(src_stream_class); + bt_event_class_put_ref(src_event_class); + bt_stream_put_ref(src_stream1); + bt_stream_put_ref(src_stream2); + bt_packet_put_ref(src_stream1_packet1); + bt_packet_put_ref(src_stream1_packet2); + bt_packet_put_ref(src_stream2_packet1); + bt_packet_put_ref(src_stream2_packet2); } static -void src_iter_finalize( - struct bt_private_connection_private_notification_iterator *private_notification_iterator) +void src_iter_finalize(bt_self_notification_iterator *self_notif_iter) { struct src_iter_user_data *user_data = - bt_private_connection_private_notification_iterator_get_user_data( - private_notification_iterator); + bt_self_notification_iterator_get_data( + self_notif_iter); if (user_data) { g_free(user_data); @@ -377,18 +313,16 @@ void src_iter_finalize( } static -enum bt_notification_iterator_status src_iter_init( - struct bt_private_connection_private_notification_iterator *priv_notif_iter, - struct bt_private_port *private_port) +enum bt_self_notification_iterator_status src_iter_init( + bt_self_notification_iterator *self_notif_iter, + bt_self_component_source *self_comp, + bt_self_component_port_output *self_port) { struct src_iter_user_data *user_data = g_new0(struct src_iter_user_data, 1); - int ret; - assert(user_data); - ret = bt_private_connection_private_notification_iterator_set_user_data( - priv_notif_iter, user_data); - assert(ret == 0); + BT_ASSERT(user_data); + bt_self_notification_iterator_set_data(self_notif_iter, user_data); switch (current_test) { case TEST_NO_AUTO_NOTIFS: @@ -399,100 +333,64 @@ enum bt_notification_iterator_status src_iter_init( abort(); } - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + return BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; } 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(bt_self_notification_iterator* notif_iter, + struct src_iter_user_data *user_data, + const 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_packet *event_packet = NULL; - 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; - case SEQ_INACTIVITY: - next_return.notification = - bt_notification_inactivity_create(graph, - src_empty_cc_prio_map); - assert(next_return.notification); - break; + switch (user_data->seq[user_data->at]) { case SEQ_STREAM1_BEGIN: - next_return.notification = - bt_notification_stream_begin_create(graph, src_stream1); - assert(next_return.notification); + *notif = bt_notification_stream_beginning_create(notif_iter, + src_stream1); break; case SEQ_STREAM2_BEGIN: - next_return.notification = - bt_notification_stream_begin_create(graph, src_stream2); - assert(next_return.notification); + *notif = bt_notification_stream_beginning_create(notif_iter, + src_stream2); break; case SEQ_STREAM1_END: - next_return.notification = - bt_notification_stream_end_create(graph, src_stream1); - assert(next_return.notification); + *notif = bt_notification_stream_end_create(notif_iter, + src_stream1); break; case SEQ_STREAM2_END: - next_return.notification = - bt_notification_stream_end_create(graph, src_stream2); - assert(next_return.notification); + *notif = bt_notification_stream_end_create(notif_iter, + src_stream2); break; case SEQ_STREAM1_PACKET1_BEGIN: - next_return.notification = - bt_notification_packet_begin_create(graph, - src_stream1_packet1); - assert(next_return.notification); + *notif = bt_notification_packet_beginning_create(notif_iter, + src_stream1_packet1); break; case SEQ_STREAM1_PACKET2_BEGIN: - next_return.notification = - bt_notification_packet_begin_create(graph, - src_stream1_packet2); - assert(next_return.notification); + *notif = bt_notification_packet_beginning_create(notif_iter, + src_stream1_packet2); break; case SEQ_STREAM2_PACKET1_BEGIN: - next_return.notification = - bt_notification_packet_begin_create(graph, - src_stream2_packet1); - assert(next_return.notification); + *notif = bt_notification_packet_beginning_create(notif_iter, + src_stream2_packet1); break; case SEQ_STREAM2_PACKET2_BEGIN: - next_return.notification = - bt_notification_packet_begin_create(graph, - src_stream2_packet2); - assert(next_return.notification); + *notif = bt_notification_packet_beginning_create(notif_iter, + src_stream2_packet2); break; case SEQ_STREAM1_PACKET1_END: - next_return.notification = - bt_notification_packet_end_create(graph, - src_stream1_packet1); - assert(next_return.notification); + *notif = bt_notification_packet_end_create(notif_iter, + src_stream1_packet1); break; case SEQ_STREAM1_PACKET2_END: - next_return.notification = - bt_notification_packet_end_create(graph, - src_stream1_packet2); - assert(next_return.notification); + *notif = bt_notification_packet_end_create(notif_iter, + src_stream1_packet2); break; case SEQ_STREAM2_PACKET1_END: - next_return.notification = - bt_notification_packet_end_create(graph, - src_stream2_packet1); - assert(next_return.notification); + *notif = bt_notification_packet_end_create(notif_iter, + src_stream2_packet1); break; case SEQ_STREAM2_PACKET2_END: - next_return.notification = - bt_notification_packet_end_create(graph, - src_stream2_packet2); - assert(next_return.notification); + *notif = bt_notification_packet_end_create(notif_iter, + src_stream2_packet2); break; case SEQ_EVENT_STREAM1_PACKET1: event_packet = src_stream1_packet1; @@ -511,121 +409,117 @@ 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); - assert(next_return.notification); + *notif = bt_notification_event_create(notif_iter, + src_event_class, + event_packet); } - if (next_return.status != BT_NOTIFICATION_ITERATOR_STATUS_END) { - user_data->at++; + BT_ASSERT(*notif); + user_data->at++; +} + +static +enum bt_self_notification_iterator_status src_iter_next_seq( + bt_self_notification_iterator *notif_iter, + struct src_iter_user_data *user_data, + bt_notification_array_const notifs, uint64_t capacity, + uint64_t *count) +{ + enum bt_self_notification_iterator_status status = + BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK; + uint64_t i = 0; + + BT_ASSERT(user_data->seq); + + if (user_data->seq[user_data->at] == SEQ_END) { + status = BT_SELF_NOTIFICATION_ITERATOR_STATUS_END; + goto end; } - return next_return; + while (i < capacity && user_data->seq[user_data->at] != SEQ_END) { + src_iter_next_seq_one(notif_iter, user_data, ¬ifs[i]); + i++; + } + + 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_self_notification_iterator_status src_iter_next( + bt_self_notification_iterator *self_notif_iter, + bt_notification_array_const 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_self_notification_iterator_get_data(self_notif_iter); - assert(user_data); - next_return = src_iter_next_seq(user_data); - return next_return; + BT_ASSERT(user_data); + return src_iter_next_seq(self_notif_iter, user_data, notifs, + capacity, count); } static -enum bt_component_status src_init( - struct bt_private_component *private_component, - struct bt_value *params, void *init_method_data) +enum bt_self_component_status src_init( + bt_self_component_source *self_comp, + const bt_value *params, void *init_method_data) { int ret; - ret = bt_private_component_source_add_output_private_port( - private_component, "out", NULL, NULL); - assert(ret == 0); - return BT_COMPONENT_STATUS_OK; + ret = bt_self_component_source_add_output_port( + self_comp, "out", NULL, NULL); + BT_ASSERT(ret == 0); + return BT_SELF_COMPONENT_STATUS_OK; } static -void src_finalize(struct bt_private_component *private_component) +void src_finalize(bt_self_component_source *self_comp) { } static -enum bt_notification_iterator_status common_consume( - struct bt_notification_iterator *notif_iter) +void append_test_events_from_notification(const 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; - 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); - assert(notification); switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_EVENT: { - struct bt_event *event; + const bt_event *event; test_event.type = TEST_EV_TYPE_NOTIF_EVENT; - event = bt_notification_event_borrow_event(notification); - assert(event); - test_event.packet = bt_event_borrow_packet(event); - assert(test_event.packet); + event = bt_notification_event_borrow_event_const(notification); + BT_ASSERT(event); + test_event.packet = bt_event_borrow_packet_const(event); + BT_ASSERT(test_event.packet); break; } - case BT_NOTIFICATION_TYPE_INACTIVITY: - test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY; - break; - case BT_NOTIFICATION_TYPE_STREAM_BEGIN: + case BT_NOTIFICATION_TYPE_STREAM_BEGINNING: test_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; test_event.stream = - bt_notification_stream_begin_borrow_stream(notification); - assert(test_event.stream); + bt_notification_stream_beginning_borrow_stream_const(notification); + BT_ASSERT(test_event.stream); break; case BT_NOTIFICATION_TYPE_STREAM_END: test_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; test_event.stream = - bt_notification_stream_end_borrow_stream(notification); - assert(test_event.stream); + bt_notification_stream_end_borrow_stream_const(notification); + BT_ASSERT(test_event.stream); break; - case BT_NOTIFICATION_TYPE_PACKET_BEGIN: + case BT_NOTIFICATION_TYPE_PACKET_BEGINNING: test_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; test_event.packet = - bt_notification_packet_begin_borrow_packet(notification); - assert(test_event.packet); + bt_notification_packet_beginning_borrow_packet_const(notification); + BT_ASSERT(test_event.packet); break; case BT_NOTIFICATION_TYPE_PACKET_END: test_event.type = TEST_EV_TYPE_NOTIF_PACKET_END; test_event.packet = - bt_notification_packet_end_borrow_packet(notification); - assert(test_event.packet); + bt_notification_packet_end_borrow_packet_const(notification); + BT_ASSERT(test_event.packet); break; default: test_event.type = TEST_EV_TYPE_NOTIF_UNEXPECTED; @@ -633,40 +527,85 @@ enum bt_notification_iterator_status common_consume( } if (test_event.packet) { - test_event.stream = bt_packet_borrow_stream(test_event.packet); - assert(test_event.stream); + test_event.stream = bt_packet_borrow_stream_const( + test_event.packet); + BT_ASSERT(test_event.stream); } -end: - if (do_append_test_event) { + append_test_event(&test_event); +} + +static +enum bt_notification_iterator_status common_consume( + void *notif_iter, bool is_output_port_notif_iter) +{ + enum bt_notification_iterator_status ret; + bt_notification_array_const 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_port_output_notification_iterator_next(notif_iter, + ¬ifications, &count); + } else { + ret = bt_self_component_port_input_notification_iterator_next( + notif_iter, ¬ifications, &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_notification_put_ref(notifications[i]); } - bt_put(notification); +end: return ret; } static -enum bt_component_status sink_consume( - struct bt_private_component *priv_component) +enum bt_self_component_status sink_consume( + bt_self_component_sink *self_comp) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; struct sink_user_data *user_data = - bt_private_component_get_user_data(priv_component); + bt_self_component_get_data( + bt_self_component_sink_as_self_component( + self_comp)); enum bt_notification_iterator_status it_ret; - assert(user_data && user_data->notif_iter); - it_ret = common_consume(user_data->notif_iter); + BT_ASSERT(user_data && user_data->notif_iter); + it_ret = common_consume(user_data->notif_iter, false); if (it_ret < 0) { - ret = BT_COMPONENT_STATUS_ERROR; + ret = BT_SELF_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); + ret = BT_SELF_COMPONENT_STATUS_END; + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_PUT_REF_AND_RESET( + user_data->notif_iter); goto end; case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: abort(); @@ -679,102 +618,106 @@ end: } static -void sink_port_connected(struct bt_private_component *private_component, - struct bt_private_port *self_private_port, - struct bt_port *other_port) +enum bt_self_component_status sink_port_connected( + bt_self_component_sink *self_comp, + bt_self_component_port_input *self_port, + const bt_port_output *other_port) { - struct bt_private_connection *priv_conn = - 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); - conn_status = bt_private_connection_create_notification_iterator( - priv_conn, &user_data->notif_iter); - assert(conn_status == 0); - bt_put(priv_conn); + struct sink_user_data *user_data = + bt_self_component_get_data( + bt_self_component_sink_as_self_component( + self_comp)); + + BT_ASSERT(user_data); + user_data->notif_iter = + bt_self_component_port_input_notification_iterator_create( + self_port); + return BT_SELF_COMPONENT_STATUS_OK; } static -enum bt_component_status sink_init( - struct bt_private_component *private_component, - struct bt_value *params, void *init_method_data) +enum bt_self_component_status sink_init( + bt_self_component_sink *self_comp, + const bt_value *params, void *init_method_data) { struct sink_user_data *user_data = g_new0(struct sink_user_data, 1); int ret; - assert(user_data); - ret = bt_private_component_set_user_data(private_component, + BT_ASSERT(user_data); + bt_self_component_set_data( + bt_self_component_sink_as_self_component(self_comp), 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; + ret = bt_self_component_sink_add_input_port( + self_comp, "in", NULL, NULL); + BT_ASSERT(ret == 0); + return BT_SELF_COMPONENT_STATUS_OK; } static -void sink_finalize(struct bt_private_component *private_component) +void sink_finalize(bt_self_component_sink *self_comp) { - struct sink_user_data *user_data = bt_private_component_get_user_data( - private_component); + struct sink_user_data *user_data = + bt_self_component_get_data( + bt_self_component_sink_as_self_component( + self_comp)); if (user_data) { - bt_put(user_data->notif_iter); + BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_PUT_REF_AND_RESET( + user_data->notif_iter); g_free(user_data); } } static -void create_source_sink(struct bt_graph *graph, struct bt_component **source, - struct bt_component **sink) +void create_source_sink(bt_graph *graph, + const bt_component_source **source, + const bt_component_sink **sink) { - struct bt_component_class *src_comp_class; - struct bt_component_class *sink_comp_class; + bt_component_class_source *src_comp_class; + bt_component_class_sink *sink_comp_class; int ret; /* Create source component */ 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); + BT_ASSERT(src_comp_class); + ret = bt_component_class_source_set_init_method( + src_comp_class, src_init); + BT_ASSERT(ret == 0); + ret = bt_component_class_source_set_finalize_method( + src_comp_class, src_finalize); + BT_ASSERT(ret == 0); ret = bt_component_class_source_set_notification_iterator_init_method( src_comp_class, src_iter_init); - assert(ret == 0); + BT_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); + BT_ASSERT(ret == 0); + ret = bt_graph_add_source_component(graph, + src_comp_class, "source", NULL, source); + BT_ASSERT(ret == 0); + bt_component_class_source_put_ref(src_comp_class); } /* Create sink component */ 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( + BT_ASSERT(sink_comp_class); + ret = bt_component_class_sink_set_init_method( + sink_comp_class, sink_init); + BT_ASSERT(ret == 0); + ret = bt_component_class_sink_set_finalize_method( + sink_comp_class, sink_finalize); + ret = bt_component_class_sink_set_input_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); + BT_ASSERT(ret == 0); + ret = bt_graph_add_sink_component(graph, + sink_comp_class, + "sink", NULL, sink); + BT_ASSERT(ret == 0); + bt_component_class_sink_put_ref(sink_comp_class); } } @@ -782,29 +725,30 @@ static void do_std_test(enum test test, const char *name, const struct test_event *expected_test_events) { - struct bt_component *src_comp; - struct bt_component *sink_comp; - struct bt_port *upstream_port; - struct bt_port *downstream_port; + const bt_component_source *src_comp; + const bt_component_sink *sink_comp; + const bt_port_output *upstream_port; + const bt_port_input *downstream_port; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; clear_test_events(); current_test = test; diag("test: %s", name); - assert(!graph); + BT_ASSERT(!graph); graph = bt_graph_create(); - assert(graph); + BT_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); + upstream_port = + bt_component_source_borrow_output_port_by_name_const( + src_comp, "out"); + BT_ASSERT(upstream_port); + downstream_port = bt_component_sink_borrow_input_port_by_name_const( + sink_comp, "in"); + BT_ASSERT(downstream_port); graph_status = bt_graph_connect_ports(graph, upstream_port, downstream_port, NULL); - bt_put(upstream_port); - bt_put(downstream_port); /* Run the graph until the end */ while (graph_status == BT_GRAPH_STATUS_OK || @@ -812,7 +756,8 @@ void do_std_test(enum test test, const char *name, graph_status = bt_graph_run(graph); } - ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error"); + ok(graph_status == BT_GRAPH_STATUS_END, + "graph finishes without any error"); /* Compare the resulting test events */ if (expected_test_events) { @@ -820,9 +765,9 @@ void do_std_test(enum test test, const char *name, "the produced sequence of test events is the expected one"); } - bt_put(src_comp); - bt_put(sink_comp); - BT_PUT(graph); + bt_component_source_put_ref(src_comp); + bt_component_sink_put_ref(sink_comp); + BT_GRAPH_PUT_REF_AND_RESET(graph); } static @@ -876,30 +821,30 @@ void test_output_port_notification_iterator(void) { .type = TEST_EV_TYPE_END, }, { .type = TEST_EV_TYPE_SENTINEL, }, }; - struct bt_component *src_comp; - struct bt_notification_iterator *notif_iter; + const bt_component_source *src_comp; + bt_port_output_notification_iterator *notif_iter; enum bt_notification_iterator_status iter_status = BT_NOTIFICATION_ITERATOR_STATUS_OK; - struct bt_port *upstream_port; + const bt_port_output *upstream_port; clear_test_events(); current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; diag("test: output port notification iterator"); - assert(!graph); + BT_ASSERT(!graph); graph = bt_graph_create(); - assert(graph); + 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); - ok(notif_iter, "bt_output_port_notification_iterator_create() succeeds"); - bt_put(upstream_port); + upstream_port = bt_component_source_borrow_output_port_by_name_const(src_comp, + "out"); + notif_iter = bt_port_output_notification_iterator_create(graph, + upstream_port); + ok(notif_iter, "bt_private_output_port_notification_iterator_create() succeeds"); /* 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, @@ -909,43 +854,9 @@ void test_output_port_notification_iterator(void) 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; - - clear_test_events(); - current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR; - diag("test: cannot consume graph with existing output port notification iterator"); - assert(!graph); - 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); - 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); + bt_component_source_put_ref(src_comp); + BT_GRAPH_PUT_REF_AND_RESET(graph); + bt_port_output_notification_iterator_put_ref(notif_iter); } #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG" @@ -960,7 +871,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(); }