X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=tests%2Fplugins%2Ftest-utils-muxer.c;h=d7c582bba38318275251b5a2be52152b20fa3de6;hp=8b0e5209de3b5c574812900a11a9861e18beca16;hb=c800eb3790218d2f33df01e77ec38cbd43cc02a1;hpb=8deeabc63f54ef7e479a0142c03270358c6671b6 diff --git a/tests/plugins/test-utils-muxer.c b/tests/plugins/test-utils-muxer.c index 8b0e5209..d7c582bb 100644 --- a/tests/plugins/test-utils-muxer.c +++ b/tests/plugins/test-utils-muxer.c @@ -18,49 +18,20 @@ #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 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 +44,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, @@ -99,24 +72,30 @@ struct graph_listener_data { static bool debug = false; static enum test current_test; static GArray *test_events; -static struct bt_clock_class_priority_map *src_cc_prio_map; -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_graph *graph; +static struct bt_private_connection_private_notification_iterator *cur_notif_iter; +static struct bt_clock_class *src_clock_class; +static struct bt_stream_class *src_stream_class; +static struct bt_event_class *src_event_class; +static struct bt_packet *src_packet0; +static struct bt_packet *src_packet1; +static struct bt_packet *src_packet2; +static struct bt_packet *src_packet3; enum { SEQ_END = -1, SEQ_AGAIN = -2, SEQ_PACKET_BEGIN = -3, SEQ_PACKET_END = -4, + SEQ_STREAM_BEGIN = -5, + SEQ_STREAM_END = -6, }; struct src_iter_user_data { size_t iter_index; int64_t *seq; size_t at; + struct bt_packet *packet; }; struct sink_user_data { @@ -124,61 +103,62 @@ struct sink_user_data { }; static int64_t seq1[] = { - 24, 53, 97, 105, 119, 210, 222, 240, 292, 317, 353, 407, 433, - 473, 487, 504, 572, 615, 708, 766, 850, 852, 931, 951, 956, 996, - SEQ_END, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 24, 53, 97, 105, 119, 210, + 222, 240, 292, 317, 353, 407, 433, 473, 487, 504, 572, 615, 708, + 766, 850, 852, 931, 951, 956, 996, SEQ_PACKET_END, + SEQ_STREAM_END, SEQ_END, }; static int64_t seq2[] = { - 51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631, - 644, 668, 714, 744, 750, 778, 790, 836, SEQ_END, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 51, 59, 68, 77, 91, 121, + 139, 170, 179, 266, 352, 454, 478, 631, 644, 668, 714, 744, 750, + 778, 790, 836, SEQ_PACKET_END, SEQ_STREAM_END, SEQ_END, }; static int64_t seq3[] = { - 8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, 678, 717, - 731, 733, 788, 819, 820, 857, 892, 903, 944, 998, SEQ_END, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 8, 71, 209, 254, 298, 320, + 350, 393, 419, 624, 651, 678, 717, 731, 733, 788, 819, 820, 857, + 892, 903, 944, 998, SEQ_PACKET_END, SEQ_STREAM_END, SEQ_END, }; static int64_t seq4[] = { - 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591, 605, 612, - 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985, 999, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 41, 56, 120, 138, 154, 228, + 471, 479, 481, 525, 591, 605, 612, 618, 632, 670, 696, 825, 863, + 867, 871, 884, 953, 985, 999, SEQ_PACKET_END, SEQ_STREAM_END, SEQ_END, }; 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, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 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_PACKET_END, SEQ_STREAM_END, 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, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 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_PACKET_END, + SEQ_STREAM_END, 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, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 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_PACKET_END, + SEQ_STREAM_END, SEQ_END, }; static int64_t seq4_with_again[] = { - SEQ_AGAIN, 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591, - 605, 612, 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985, - 999, SEQ_END, + SEQ_AGAIN, SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 41, 56, 120, 138, + 154, 228, 471, 479, 481, 525, 591, 605, 612, 618, 632, 670, 696, + 825, 863, 867, 871, 884, 953, 985, 999, SEQ_PACKET_END, + SEQ_STREAM_END, SEQ_END, }; 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, + SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 1, 4, 189, 1001, + SEQ_PACKET_END, SEQ_STREAM_END, SEQ_END, }; static @@ -208,6 +188,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; @@ -275,7 +261,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; @@ -299,6 +285,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; } @@ -309,68 +299,93 @@ static void init_static_data(void) { int ret; - struct bt_ctf_trace *trace; - struct bt_ctf_stream *stream; - struct bt_ctf_field_type *empty_struct_ft; + struct bt_trace *trace; + struct bt_stream *stream; + struct bt_field_type *empty_struct_ft; + struct bt_field_type *eh_ft; + struct bt_field_type *eh_ts_ft; /* Test events */ test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event)); - assert(test_events); + BT_ASSERT(test_events); /* Metadata */ - empty_struct_ft = bt_ctf_field_type_structure_create(); - assert(empty_struct_ft); - trace = bt_ctf_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); - assert(ret == 0); - src_clock_class = bt_ctf_clock_class_create("my-clock"); - assert(src_clock_class); - ret = bt_ctf_clock_class_set_is_absolute(src_clock_class, 1); - assert(ret == 0); - ret = bt_ctf_trace_add_clock_class(trace, src_clock_class); - assert(ret == 0); - src_empty_cc_prio_map = bt_clock_class_priority_map_create(); - assert(src_empty_cc_prio_map); - src_cc_prio_map = bt_clock_class_priority_map_create(); - assert(src_cc_prio_map); - ret = bt_clock_class_priority_map_add_clock_class(src_cc_prio_map, - src_clock_class, 0); - assert(ret == 0); - src_stream_class = bt_ctf_stream_class_create("my-stream-class"); - assert(src_stream_class); - ret = bt_ctf_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, + empty_struct_ft = bt_field_type_structure_create(); + BT_ASSERT(empty_struct_ft); + src_clock_class = bt_clock_class_create("my-clock", 1000000000); + BT_ASSERT(src_clock_class); + trace = bt_trace_create(); + BT_ASSERT(trace); + ret = bt_trace_set_native_byte_order(trace, + BT_BYTE_ORDER_LITTLE_ENDIAN); + BT_ASSERT(ret == 0); + ret = bt_trace_set_packet_header_field_type(trace, empty_struct_ft); + BT_ASSERT(ret == 0); + ret = bt_clock_class_set_is_absolute(src_clock_class, 1); + BT_ASSERT(ret == 0); + ret = bt_trace_add_clock_class(trace, src_clock_class); + BT_ASSERT(ret == 0); + src_stream_class = bt_stream_class_create("my-stream-class"); + BT_ASSERT(src_stream_class); + ret = bt_stream_class_set_packet_context_field_type(src_stream_class, empty_struct_ft); - assert(ret == 0); - ret = bt_ctf_stream_class_set_event_context_type(src_stream_class, + BT_ASSERT(ret == 0); + eh_ft = bt_field_type_structure_create(); + BT_ASSERT(eh_ft); + eh_ts_ft = bt_field_type_integer_create(64); + BT_ASSERT(eh_ts_ft); + ret = bt_field_type_structure_add_field(eh_ft, eh_ts_ft, "ts"); + BT_ASSERT(ret == 0); + ret = bt_field_type_integer_set_mapped_clock_class(eh_ts_ft, + src_clock_class); + BT_ASSERT(ret == 0); + ret = bt_stream_class_set_event_header_field_type(src_stream_class, + eh_ft); + BT_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_ctf_event_class_create("my-event-class"); - ret = bt_ctf_event_class_set_context_type(src_event_class, + BT_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_ctf_event_class_set_context_type(src_event_class, + BT_ASSERT(ret == 0); + ret = bt_event_class_set_context_field_type(src_event_class, empty_struct_ft); - assert(ret == 0); - ret = bt_ctf_stream_class_add_event_class(src_stream_class, + BT_ASSERT(ret == 0); + 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); - assert(ret == 0); - stream = bt_ctf_stream_create(src_stream_class, "my-stream"); - assert(stream); - src_packet = bt_ctf_packet_create(stream); - assert(src_packet); + BT_ASSERT(ret == 0); + ret = bt_trace_add_stream_class(trace, src_stream_class); + BT_ASSERT(ret == 0); + stream = bt_stream_create(src_stream_class, "stream0", 0); + BT_ASSERT(stream); + src_packet0 = bt_packet_create(stream, + BT_PACKET_PREVIOUS_PACKET_AVAILABILITY_NONE, NULL); + BT_ASSERT(src_packet0); + bt_put(stream); + stream = bt_stream_create(src_stream_class, "stream1", 1); + BT_ASSERT(stream); + src_packet1 = bt_packet_create(stream, + BT_PACKET_PREVIOUS_PACKET_AVAILABILITY_NONE, NULL); + BT_ASSERT(src_packet0); + bt_put(stream); + stream = bt_stream_create(src_stream_class, "stream2", 2); + BT_ASSERT(stream); + src_packet2 = bt_packet_create(stream, + BT_PACKET_PREVIOUS_PACKET_AVAILABILITY_NONE, NULL); + BT_ASSERT(src_packet0); + bt_put(stream); + stream = bt_stream_create(src_stream_class, "stream3", 3); + BT_ASSERT(stream); + src_packet3 = bt_packet_create(stream, + BT_PACKET_PREVIOUS_PACKET_AVAILABILITY_NONE, NULL); + BT_ASSERT(src_packet0); + bt_put(stream); bt_put(trace); - bt_put(stream); bt_put(empty_struct_ft); + bt_put(eh_ft); + bt_put(eh_ts_ft); } static @@ -380,19 +395,21 @@ void fini_static_data(void) g_array_free(test_events, TRUE); /* Metadata */ - bt_put(src_empty_cc_prio_map); - bt_put(src_cc_prio_map); 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 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) { @@ -402,24 +419,40 @@ 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 = g_new0(struct src_iter_user_data, 1); - struct bt_port *port = bt_port_from_private_port(private_port); + struct bt_port *port = bt_port_borrow_from_private(private_port); const char *port_name; int ret; - assert(user_data); - assert(port); - ret = bt_private_notification_iterator_set_user_data(priv_notif_iter, + BT_ASSERT(user_data); + BT_ASSERT(port); + ret = bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, user_data); - assert(ret == 0); + BT_ASSERT(ret == 0); port_name = bt_port_get_name(port); - assert(port_name); + BT_ASSERT(port_name); 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: @@ -427,13 +460,6 @@ enum bt_notification_iterator_status src_iter_init( 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,178 +493,213 @@ 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_notification *src_create_event_notif(struct bt_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); - assert(ret == 0); - - if (ts_ns != -1) { - struct bt_ctf_clock_value *clock_value; - - clock_value = bt_ctf_clock_value_create(src_clock_class, - (uint64_t) ts_ns); - assert(clock_value); - ret = bt_ctf_event_set_clock_value(event, clock_value); - bt_put(clock_value); + struct bt_event *event; + struct bt_notification *notif; + struct bt_field *field; + + notif = bt_notification_event_create(cur_notif_iter, + src_event_class, packet); + BT_ASSERT(notif); + event = bt_notification_event_borrow_event(notif); + BT_ASSERT(event); + field = bt_event_borrow_header(event); + BT_ASSERT(field); + field = bt_field_structure_borrow_field_by_name(field, "ts"); + BT_ASSERT(field); + ret = bt_field_integer_unsigned_set_value(field, (uint64_t) ts_ns); + BT_ASSERT(ret == 0); + + if (ts_ns != UINT64_C(-1)) { + ret = bt_event_set_clock_value(event, src_clock_class, (uint64_t) ts_ns, + BT_TRUE); + BT_ASSERT(ret == 0); } - return event; + return notif; } static -struct bt_notification_iterator_next_return src_iter_next_seq( - struct src_iter_user_data *user_data) +enum bt_notification_iterator_status src_iter_next_seq( + struct src_iter_user_data *user_data, + bt_notification_array notifs) { - struct bt_notification_iterator_next_return next_return = { - .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, - }; + enum bt_notification_iterator_status status = + BT_NOTIFICATION_ITERATOR_STATUS_OK; int64_t cur_ts_ns; + struct bt_stream *stream; - assert(user_data->seq); + BT_ASSERT(user_data->seq); cur_ts_ns = user_data->seq[user_data->at]; switch (cur_ts_ns) { case SEQ_END: - next_return.status = - BT_NOTIFICATION_ITERATOR_STATUS_END; + status = BT_NOTIFICATION_ITERATOR_STATUS_END; break; case SEQ_AGAIN: - next_return.status = - BT_NOTIFICATION_ITERATOR_STATUS_AGAIN; + status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN; break; case SEQ_PACKET_BEGIN: - next_return.notification = - bt_notification_packet_begin_create(src_packet); - assert(next_return.notification); + notifs[0] = bt_notification_packet_begin_create(cur_notif_iter, + user_data->packet); + BT_ASSERT(notifs[0]); break; case SEQ_PACKET_END: - next_return.notification = - bt_notification_packet_end_create(src_packet); - assert(next_return.notification); + notifs[0] = bt_notification_packet_end_create(cur_notif_iter, + user_data->packet); + BT_ASSERT(notifs[0]); + break; + case SEQ_STREAM_BEGIN: + stream = bt_packet_get_stream(user_data->packet); + notifs[0] = bt_notification_stream_begin_create(cur_notif_iter, + stream); + BT_ASSERT(notifs[0]); + bt_put(stream); + break; + case SEQ_STREAM_END: + stream = bt_packet_get_stream(user_data->packet); + notifs[0] = bt_notification_stream_end_create(cur_notif_iter, + stream); + BT_ASSERT(notifs[0]); + bt_put(stream); break; default: { - struct bt_ctf_event *event = src_create_event(cur_ts_ns); - - assert(event); - next_return.notification = bt_notification_event_create(event, - src_cc_prio_map); - bt_put(event); - assert(next_return.notification); + notifs[0] = src_create_event_notif(user_data->packet, + cur_ts_ns); + BT_ASSERT(notifs[0]); break; } } - if (next_return.status != BT_NOTIFICATION_ITERATOR_STATUS_END) { + if (status != BT_NOTIFICATION_ITERATOR_STATUS_END) { user_data->at++; } - return next_return; + return status; } static -struct bt_notification_iterator_next_return src_iter_next( - struct bt_private_notification_iterator *priv_iterator) +enum bt_notification_iterator_status src_iter_next( + struct bt_private_connection_private_notification_iterator *priv_iterator, + bt_notification_array notifs, uint64_t capacity, + uint64_t *count) { - struct bt_notification_iterator_next_return next_return = { - .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, - .notification = NULL, - }; + enum bt_notification_iterator_status status = + BT_NOTIFICATION_ITERATOR_STATUS_OK; 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); struct bt_private_component *private_component = - bt_private_notification_iterator_get_private_component(priv_iterator); + bt_private_connection_private_notification_iterator_get_private_component(priv_iterator); + struct bt_stream *stream; + int ret; + + BT_ASSERT(user_data); + BT_ASSERT(private_component); + cur_notif_iter = priv_iterator; - assert(user_data); - assert(private_component); + /* + * We can always set it to 1: it's not going to be considered + * anyway if the status is not + * BT_NOTIFICATION_ITERATOR_STATUS_OK. + */ + *count = 1; switch (current_test) { case TEST_NO_TS: if (user_data->iter_index == 0) { if (user_data->at == 0) { - next_return.notification = - bt_notification_packet_begin_create(src_packet); - assert(next_return.notification); - } else if (user_data->at < 6) { - struct bt_ctf_event *event = src_create_event(-1); - - assert(event); - next_return.notification = - bt_notification_event_create(event, - src_empty_cc_prio_map); - assert(next_return.notification); - bt_put(event); + stream = bt_packet_get_stream(user_data->packet); + notifs[0] = + bt_notification_stream_begin_create( + cur_notif_iter, stream); + bt_put(stream); + BT_ASSERT(notifs[0]); + } else if (user_data->at == 1) { + notifs[0] = + bt_notification_packet_begin_create( + cur_notif_iter, + user_data->packet); + BT_ASSERT(notifs[0]); + } else if (user_data->at < 7) { + notifs[0] = + src_create_event_notif( + user_data->packet, UINT64_C(-1)); + BT_ASSERT(notifs[0]); + } else if (user_data->at == 7) { + notifs[0] = + bt_notification_packet_end_create( + cur_notif_iter, + user_data->packet); + BT_ASSERT(notifs[0]); + } else if (user_data->at == 8) { + stream = bt_packet_get_stream(user_data->packet); + notifs[0] = + bt_notification_stream_end_create( + cur_notif_iter, stream); + bt_put(stream); + BT_ASSERT(notifs[0]); } else { - next_return.status = + status = BT_NOTIFICATION_ITERATOR_STATUS_END; } user_data->at++; } else { - next_return = src_iter_next_seq(user_data); + status = src_iter_next_seq(user_data, notifs); } 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); + status = src_iter_next_seq(user_data, notifs); 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); - next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END; + ret = bt_private_component_source_add_output_private_port( + private_component, "out1", NULL, NULL); + BT_ASSERT(ret == 0); + ret = bt_private_component_source_add_output_private_port( + private_component, "out2", NULL, NULL); + BT_ASSERT(ret == 0); + status = BT_NOTIFICATION_ITERATOR_STATUS_END; } else { - next_return = src_iter_next_seq(user_data); + status = src_iter_next_seq(user_data, notifs); } break; case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL: if (user_data->iter_index == 0) { if (user_data->at == 0) { - next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN; + 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); - next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END; + ret = bt_private_component_source_add_output_private_port( + private_component, "out1", NULL, NULL); + BT_ASSERT(ret == 0); + ret = bt_private_component_source_add_output_private_port( + private_component, "out2", NULL, NULL); + BT_ASSERT(ret == 0); + status = BT_NOTIFICATION_ITERATOR_STATUS_END; } } else { - next_return = src_iter_next_seq(user_data); + status = src_iter_next_seq(user_data, notifs); } break; default: - assert(false); + abort(); } bt_put(private_component); - return next_return; + return status; } static @@ -646,21 +707,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 +724,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); + BT_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); + BT_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); + BT_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); + BT_ASSERT(ret == 0); } return BT_COMPONENT_STATUS_OK; @@ -709,111 +756,46 @@ void src_finalize(struct bt_private_component *private_component) } static -enum bt_component_status sink_consume( - struct bt_private_component *priv_component) +void append_test_event_from_notification(struct bt_notification *notification) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - 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; + int ret; struct test_event test_event; - bool do_append_test_event = true; - - 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; - do_append_test_event = false; - goto end; - } - - switch (it_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: - test_event.type = TEST_EV_TYPE_AGAIN; - ret = BT_COMPONENT_STATUS_AGAIN; - goto end; - default: - break; - } - - notification = bt_notification_iterator_get_notification( - user_data->notif_iter); - assert(notification); + struct bt_clock_value *cv; switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_EVENT: { - struct bt_ctf_event *event; - struct bt_clock_class_priority_map *cc_prio_map; + struct bt_event *event; test_event.type = TEST_EV_TYPE_NOTIF_EVENT; - cc_prio_map = - bt_notification_event_get_clock_class_priority_map( - notification); - assert(cc_prio_map); - event = bt_notification_event_get_event(notification); - assert(event); - - if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) { - struct bt_ctf_clock_value *clock_value; - struct bt_ctf_clock_class *clock_class = - bt_clock_class_priority_map_get_highest_priority_clock_class( - cc_prio_map); - - assert(clock_class); - clock_value = bt_ctf_event_get_clock_value(event, - clock_class); - assert(clock_value); - ret = bt_ctf_clock_value_get_value_ns_from_epoch( - clock_value, &test_event.ts_ns); - assert(ret == 0); - bt_put(clock_value); - bt_put(clock_class); + event = bt_notification_event_borrow_event(notification); + BT_ASSERT(event); + cv = bt_event_borrow_default_clock_value(event); + + if (cv) { + ret = bt_clock_value_get_value_ns_from_epoch( + cv, &test_event.ts_ns); + BT_ASSERT(ret == 0); } else { test_event.ts_ns = -1; } - bt_put(cc_prio_map); - bt_put(event); break; } case BT_NOTIFICATION_TYPE_INACTIVITY: { - struct bt_clock_class_priority_map *cc_prio_map; - test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY; - cc_prio_map = bt_notification_event_get_clock_class_priority_map( + cv = bt_notification_inactivity_borrow_default_clock_value( notification); - assert(cc_prio_map); - - if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) { - struct bt_ctf_clock_value *clock_value; - struct bt_ctf_clock_class *clock_class = - bt_clock_class_priority_map_get_highest_priority_clock_class( - cc_prio_map); - - assert(clock_class); - clock_value = - bt_notification_inactivity_get_clock_value( - notification, clock_class); - assert(clock_value); - ret = bt_ctf_clock_value_get_value_ns_from_epoch( - clock_value, &test_event.ts_ns); - assert(ret == 0); - bt_put(clock_value); - bt_put(clock_class); + + if (cv) { + ret = bt_clock_value_get_value_ns_from_epoch( + cv, &test_event.ts_ns); + BT_ASSERT(ret == 0); } else { test_event.ts_ns = -1; } - bt_put(cc_prio_map); break; } case BT_NOTIFICATION_TYPE_PACKET_BEGIN: @@ -822,22 +804,77 @@ 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; } + append_test_event(&test_event); +} + +static +enum bt_component_status sink_consume( + struct bt_private_component *priv_component) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + bt_notification_array notifications = NULL; + uint64_t count; + 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; + bool do_append_test_event = true; + uint64_t i; + + BT_ASSERT(user_data && user_data->notif_iter); + it_ret = bt_private_connection_notification_iterator_next( + user_data->notif_iter, ¬ifications, &count); + if (it_ret < 0) { + ret = BT_COMPONENT_STATUS_ERROR; + do_append_test_event = false; + goto end; + } + + switch (it_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: + test_event.type = TEST_EV_TYPE_AGAIN; + ret = BT_COMPONENT_STATUS_AGAIN; + goto end; + default: + break; + } + + BT_ASSERT(notifications); + + for (i = 0; i < count; i++) { + append_test_event_from_notification(notifications[i]); + bt_put(notifications[i]); + } + + do_append_test_event = false; + end: if (do_append_test_event) { append_test_event(&test_event); } - bt_put(notification); return ret; } static -void sink_port_connected(struct bt_private_component *private_component, +enum bt_component_status sink_port_connected( + struct bt_private_component *private_component, struct bt_private_port *self_private_port, struct bt_port *other_port) { @@ -845,13 +882,15 @@ 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); + BT_ASSERT(user_data); + BT_ASSERT(priv_conn); + conn_status = bt_private_connection_create_notification_iterator( + priv_conn, &user_data->notif_iter); + BT_ASSERT(conn_status == 0); bt_put(priv_conn); + return BT_COMPONENT_STATUS_OK; } static @@ -862,10 +901,13 @@ enum bt_component_status sink_init( struct sink_user_data *user_data = g_new0(struct sink_user_data, 1); int ret; - assert(user_data); + BT_ASSERT(user_data); ret = bt_private_component_set_user_data(private_component, user_data); - assert(ret == 0); + BT_ASSERT(ret == 0); + ret = bt_private_component_sink_add_input_private_port( + private_component, "in", NULL, NULL); + BT_ASSERT(ret == 0); return BT_COMPONENT_STATUS_OK; } @@ -882,7 +924,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) { @@ -893,39 +936,40 @@ void create_source_muxer_sink(struct bt_component **source, /* Create source component */ src_comp_class = bt_component_class_source_create("src", src_iter_next); - assert(src_comp_class); + BT_ASSERT(src_comp_class); ret = bt_component_class_set_init_method(src_comp_class, src_init); - assert(ret == 0); + BT_ASSERT(ret == 0); ret = bt_component_class_set_finalize_method(src_comp_class, src_finalize); - assert(ret == 0); + 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); - *source = bt_component_create(src_comp_class, "source", NULL); - assert(*source); + BT_ASSERT(ret == 0); + ret = bt_graph_add_component(graph, src_comp_class, "source", NULL, source); + BT_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); + BT_ASSERT(muxer_comp_class); + ret = bt_graph_add_component(graph, muxer_comp_class, "muxer", NULL, muxer); + BT_ASSERT(ret == 0); /* Create sink component */ sink_comp_class = bt_component_class_sink_create("sink", sink_consume); - assert(sink_comp_class); + BT_ASSERT(sink_comp_class); ret = bt_component_class_set_init_method(sink_comp_class, sink_init); - assert(ret == 0); + BT_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_ASSERT(ret == 0); + ret = bt_graph_add_component(graph, sink_comp_class, "sink", NULL, sink); + BT_ASSERT(ret == 0); bt_put(src_comp_class); bt_put(muxer_comp_class); @@ -942,50 +986,47 @@ void do_std_test(enum test test, const char *name, struct bt_component *sink_comp; 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); + BT_ASSERT(!graph); graph = bt_graph_create(); - assert(graph); + BT_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); + BT_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( + BT_ASSERT(upstream_port); + 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); + BT_ASSERT(downstream_port); + graph_status = bt_graph_connect_ports(graph, + upstream_port, downstream_port, NULL); + BT_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); - assert(downstream_port); - conn = bt_graph_connect_ports(graph, upstream_port, downstream_port); - assert(conn); - bt_put(conn); + BT_ASSERT(upstream_port); + downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); + BT_ASSERT(downstream_port); + graph_status = bt_graph_connect_ports(graph, upstream_port, + downstream_port, NULL); + BT_ASSERT(graph_status == 0); bt_put(upstream_port); bt_put(downstream_port); @@ -1001,23 +1042,30 @@ void do_std_test(enum test test, const char *name, bt_put(src_comp); bt_put(muxer_comp); bt_put(sink_comp); - bt_put(graph); + BT_PUT(graph); } 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 +1087,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 +1176,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 +1194,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 +1215,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 +1304,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 +1322,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,20 +1344,19 @@ 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); + BT_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); + BT_ASSERT(muxer_port); if (!bt_port_is_connected(muxer_port)) { BT_MOVE(avail_muxer_port, muxer_port); @@ -1313,9 +1366,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); + BT_ASSERT(graph_status == 0); bt_put(avail_muxer_port); } @@ -1327,7 +1380,7 @@ void graph_port_added_listener_connect_to_avail_muxer_port(struct bt_port *port, struct bt_component *comp; comp = bt_port_get_component(port); - assert(comp); + BT_ASSERT(comp); if (comp != graph_listener_data->source) { goto end; @@ -1348,14 +1401,16 @@ void test_single_end_then_multiple_full(void) struct bt_component *sink_comp; 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 +1451,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,40 +1467,41 @@ 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); + BT_ASSERT(!graph); graph = bt_graph_create(); - assert(graph); + BT_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); + BT_ASSERT(ret >= 0); /* Connect source output ports to muxer input ports */ - ret = bt_component_source_get_output_port_count(src_comp, &count); - assert(ret == 0); + count = bt_component_source_get_output_port_count(src_comp); + BT_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); + BT_ASSERT(upstream_port); connect_port_to_first_avail_muxer_port(graph, upstream_port, muxer_comp); bt_put(upstream_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); - assert(downstream_port); - conn = bt_graph_connect_ports(graph, upstream_port, downstream_port); - assert(conn); - bt_put(conn); + BT_ASSERT(upstream_port); + downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); + BT_ASSERT(downstream_port); + graph_status = bt_graph_connect_ports(graph, upstream_port, + downstream_port, NULL); + BT_ASSERT(graph_status == 0); bt_put(upstream_port); bt_put(downstream_port); @@ -1457,7 +1517,7 @@ void test_single_end_then_multiple_full(void) bt_put(src_comp); bt_put(muxer_comp); bt_put(sink_comp); - bt_put(graph); + BT_PUT(graph); } static @@ -1468,15 +1528,17 @@ void test_single_again_end_then_multiple_full(void) struct bt_component *sink_comp; 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 +1579,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,40 +1595,41 @@ 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); + BT_ASSERT(!graph); graph = bt_graph_create(); - assert(graph); + BT_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); + BT_ASSERT(ret >= 0); /* Connect source output ports to muxer input ports */ - ret = bt_component_source_get_output_port_count(src_comp, &count); - assert(ret == 0); + count = bt_component_source_get_output_port_count(src_comp); + BT_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); + BT_ASSERT(upstream_port); connect_port_to_first_avail_muxer_port(graph, upstream_port, muxer_comp); bt_put(upstream_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); - assert(downstream_port); - conn = bt_graph_connect_ports(graph, upstream_port, downstream_port); - assert(conn); - bt_put(conn); + BT_ASSERT(upstream_port); + downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); + BT_ASSERT(downstream_port); + graph_status = bt_graph_connect_ports(graph, upstream_port, + downstream_port, NULL); + BT_ASSERT(graph_status == 0); bt_put(upstream_port); bt_put(downstream_port); @@ -1578,7 +1645,7 @@ void test_single_again_end_then_multiple_full(void) bt_put(src_comp); bt_put(muxer_comp); bt_put(sink_comp); - bt_put(graph); + BT_PUT(graph); } #define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG" @@ -1593,7 +1660,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();