2 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; under version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <babeltrace/assert-internal.h>
25 #include <babeltrace/babeltrace.h>
34 TEST_NO_UPSTREAM_CONNECTION
,
36 TEST_4_PORTS_WITH_RETRIES
,
37 TEST_SINGLE_END_THEN_MULTIPLE_FULL
,
38 TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
,
41 enum test_event_type
{
42 TEST_EV_TYPE_NOTIF_UNEXPECTED
,
43 TEST_EV_TYPE_NOTIF_EVENT
,
44 TEST_EV_TYPE_NOTIF_INACTIVITY
,
45 TEST_EV_TYPE_NOTIF_PACKET_BEGIN
,
46 TEST_EV_TYPE_NOTIF_PACKET_END
,
47 TEST_EV_TYPE_NOTIF_STREAM_BEGIN
,
48 TEST_EV_TYPE_NOTIF_STREAM_END
,
51 TEST_EV_TYPE_SENTINEL
,
55 enum test_event_type type
;
59 struct source_muxer_sink
{
60 struct bt_component
*source
;
61 struct bt_component
*muxer
;
62 struct bt_component
*sink
;
65 struct graph_listener_data
{
66 struct bt_graph
*graph
;
67 struct bt_component
*source
;
68 struct bt_component
*muxer
;
69 struct bt_component
*sink
;
72 static bool debug
= false;
73 static enum test current_test
;
74 static GArray
*test_events
;
75 static struct bt_graph
*graph
;
76 static struct bt_clock_class
*src_clock_class
;
77 static struct bt_stream_class
*src_stream_class
;
78 static struct bt_event_class
*src_event_class
;
79 static struct bt_packet
*src_packet0
;
80 static struct bt_packet
*src_packet1
;
81 static struct bt_packet
*src_packet2
;
82 static struct bt_packet
*src_packet3
;
87 SEQ_PACKET_BEGIN
= -3,
89 SEQ_STREAM_BEGIN
= -5,
93 struct src_iter_user_data
{
97 struct bt_packet
*packet
;
100 struct sink_user_data
{
101 struct bt_notification_iterator
*notif_iter
;
104 static int64_t seq1
[] = {
105 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 24, 53, 97, 105, 119, 210,
106 222, 240, 292, 317, 353, 407, 433, 473, 487, 504, 572, 615, 708,
107 766, 850, 852, 931, 951, 956, 996, SEQ_PACKET_END
,
108 SEQ_STREAM_END
, SEQ_END
,
111 static int64_t seq2
[] = {
112 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 51, 59, 68, 77, 91, 121,
113 139, 170, 179, 266, 352, 454, 478, 631, 644, 668, 714, 744, 750,
114 778, 790, 836, SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
117 static int64_t seq3
[] = {
118 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 8, 71, 209, 254, 298, 320,
119 350, 393, 419, 624, 651, 678, 717, 731, 733, 788, 819, 820, 857,
120 892, 903, 944, 998, SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
123 static int64_t seq4
[] = {
124 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 41, 56, 120, 138, 154, 228,
125 471, 479, 481, 525, 591, 605, 612, 618, 632, 670, 696, 825, 863,
126 867, 871, 884, 953, 985, 999, SEQ_PACKET_END
, SEQ_STREAM_END
,
130 static int64_t seq1_with_again
[] = {
131 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 24, 53, 97, 105, 119, 210,
132 SEQ_AGAIN
, SEQ_AGAIN
, 222, 240, 292, 317, 353, 407, 433, 473,
133 487, 504, 572, 615, 708, 766, 850, 852, 931, 951, 956, 996,
134 SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
137 static int64_t seq2_with_again
[] = {
138 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 51, 59, 68, 77, 91, 121,
139 139, 170, 179, 266, 352, 454, 478, 631, 644, 668, 714, 744, 750,
140 778, 790, 836, SEQ_AGAIN
, SEQ_AGAIN
, SEQ_PACKET_END
,
141 SEQ_STREAM_END
, SEQ_END
,
144 static int64_t seq3_with_again
[] = {
145 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 8, 71, 209, 254, 298, 320,
146 350, 393, 419, 624, 651, SEQ_AGAIN
, SEQ_AGAIN
, 678, 717, 731,
147 733, 788, 819, 820, 857, 892, 903, 944, 998, SEQ_PACKET_END
,
148 SEQ_STREAM_END
, SEQ_END
,
151 static int64_t seq4_with_again
[] = {
152 SEQ_AGAIN
, SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 41, 56, 120, 138,
153 154, 228, 471, 479, 481, 525, 591, 605, 612, 618, 632, 670, 696,
154 825, 863, 867, 871, 884, 953, 985, 999, SEQ_PACKET_END
,
155 SEQ_STREAM_END
, SEQ_END
,
158 static int64_t seq5
[] = {
159 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 1, 4, 189, 1001,
160 SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
164 void clear_test_events(void)
166 g_array_set_size(test_events
, 0);
170 void print_test_event(FILE *fp
, const struct test_event
*event
)
172 fprintf(fp
, "{ type = ");
174 switch (event
->type
) {
175 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
176 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
178 case TEST_EV_TYPE_NOTIF_EVENT
:
179 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
181 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
182 fprintf(fp
, "TEST_EV_TYPE_NOTIF_INACTIVITY");
184 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
185 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
187 case TEST_EV_TYPE_NOTIF_PACKET_END
:
188 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
190 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
191 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
193 case TEST_EV_TYPE_NOTIF_STREAM_END
:
194 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
196 case TEST_EV_TYPE_AGAIN
:
197 fprintf(fp
, "TEST_EV_TYPE_AGAIN");
199 case TEST_EV_TYPE_END
:
200 fprintf(fp
, "TEST_EV_TYPE_END");
202 case TEST_EV_TYPE_SENTINEL
:
203 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
206 fprintf(fp
, "(UNKNOWN)");
210 switch (event
->type
) {
211 case TEST_EV_TYPE_NOTIF_EVENT
:
212 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
213 fprintf(fp
, ", ts-ns = %" PRId64
, event
->ts_ns
);
222 void append_test_event(struct test_event
*event
)
224 g_array_append_val(test_events
, *event
);
228 bool compare_single_test_events(const struct test_event
*ev_a
,
229 const struct test_event
*ev_b
)
232 fprintf(stderr
, ":: Comparing test events: ");
233 print_test_event(stderr
, ev_a
);
234 fprintf(stderr
, " vs. ");
235 print_test_event(stderr
, ev_b
);
236 fprintf(stderr
, "\n");
239 if (ev_a
->type
!= ev_b
->type
) {
243 switch (ev_a
->type
) {
244 case TEST_EV_TYPE_NOTIF_EVENT
:
245 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
246 if (ev_a
->ts_ns
!= ev_b
->ts_ns
) {
258 bool compare_test_events(const struct test_event
*expected_events
)
260 const struct test_event
*expected_event
= expected_events
;
263 BT_ASSERT(expected_events
);
266 const struct test_event
*event
;
268 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
272 if (i
>= test_events
->len
) {
276 event
= &g_array_index(test_events
, struct test_event
, i
);
278 if (!compare_single_test_events(event
, expected_event
)) {
286 if (i
!= test_events
->len
) {
288 fprintf(stderr
, ":: Length mismatch\n");
298 void init_static_data(void)
301 struct bt_trace
*trace
;
302 struct bt_stream
*stream
;
303 struct bt_field_type
*empty_struct_ft
;
304 struct bt_field_type
*eh_ft
;
305 struct bt_field_type
*eh_ts_ft
;
308 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
309 BT_ASSERT(test_events
);
312 empty_struct_ft
= bt_field_type_structure_create();
313 BT_ASSERT(empty_struct_ft
);
314 src_clock_class
= bt_clock_class_create("my-clock", 1000000000);
315 BT_ASSERT(src_clock_class
);
316 trace
= bt_trace_create();
318 ret
= bt_trace_set_native_byte_order(trace
,
319 BT_BYTE_ORDER_LITTLE_ENDIAN
);
321 ret
= bt_trace_set_packet_header_field_type(trace
, empty_struct_ft
);
323 ret
= bt_clock_class_set_is_absolute(src_clock_class
, 1);
325 ret
= bt_trace_add_clock_class(trace
, src_clock_class
);
327 src_stream_class
= bt_stream_class_create("my-stream-class");
328 BT_ASSERT(src_stream_class
);
329 ret
= bt_stream_class_set_packet_context_field_type(src_stream_class
,
332 eh_ft
= bt_field_type_structure_create();
334 eh_ts_ft
= bt_field_type_integer_create(64);
336 ret
= bt_field_type_structure_add_field(eh_ft
, eh_ts_ft
, "ts");
338 ret
= bt_field_type_integer_set_mapped_clock_class(eh_ts_ft
,
341 ret
= bt_stream_class_set_event_header_field_type(src_stream_class
,
344 ret
= bt_stream_class_set_event_context_field_type(src_stream_class
,
347 src_event_class
= bt_event_class_create("my-event-class");
348 ret
= bt_event_class_set_context_field_type(src_event_class
,
351 ret
= bt_event_class_set_context_field_type(src_event_class
,
354 ret
= bt_stream_class_add_event_class(src_stream_class
,
357 ret
= bt_trace_add_stream_class(trace
, src_stream_class
);
359 stream
= bt_stream_create(src_stream_class
, "stream0", 0);
361 src_packet0
= bt_packet_create(stream
);
362 BT_ASSERT(src_packet0
);
364 stream
= bt_stream_create(src_stream_class
, "stream1", 1);
366 src_packet1
= bt_packet_create(stream
);
367 BT_ASSERT(src_packet0
);
369 stream
= bt_stream_create(src_stream_class
, "stream2", 2);
371 src_packet2
= bt_packet_create(stream
);
372 BT_ASSERT(src_packet0
);
374 stream
= bt_stream_create(src_stream_class
, "stream3", 3);
376 src_packet3
= bt_packet_create(stream
);
377 BT_ASSERT(src_packet0
);
381 bt_put(empty_struct_ft
);
387 void fini_static_data(void)
390 g_array_free(test_events
, TRUE
);
393 bt_put(src_clock_class
);
394 bt_put(src_stream_class
);
395 bt_put(src_event_class
);
403 void src_iter_finalize(
404 struct bt_private_connection_private_notification_iterator
*private_notification_iterator
)
406 struct src_iter_user_data
*user_data
=
407 bt_private_connection_private_notification_iterator_get_user_data(
408 private_notification_iterator
);
416 enum bt_notification_iterator_status
src_iter_init(
417 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
418 struct bt_private_port
*private_port
)
420 struct src_iter_user_data
*user_data
=
421 g_new0(struct src_iter_user_data
, 1);
422 struct bt_port
*port
= bt_port_borrow_from_private(private_port
);
423 const char *port_name
;
426 BT_ASSERT(user_data
);
428 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
431 port_name
= bt_port_get_name(port
);
432 BT_ASSERT(port_name
);
433 user_data
->iter_index
= port_name
[3] - '0';
435 switch (user_data
->iter_index
) {
437 user_data
->packet
= src_packet0
;
440 user_data
->packet
= src_packet1
;
443 user_data
->packet
= src_packet2
;
446 user_data
->packet
= src_packet3
;
452 switch (current_test
) {
454 if (user_data
->iter_index
== 1) {
455 user_data
->seq
= seq5
;
458 case TEST_SIMPLE_4_PORTS
:
459 if (user_data
->iter_index
== 0) {
460 user_data
->seq
= seq1
;
461 } else if (user_data
->iter_index
== 1) {
462 user_data
->seq
= seq2
;
463 } else if (user_data
->iter_index
== 2) {
464 user_data
->seq
= seq3
;
466 user_data
->seq
= seq4
;
469 case TEST_4_PORTS_WITH_RETRIES
:
470 if (user_data
->iter_index
== 0) {
471 user_data
->seq
= seq1_with_again
;
472 } else if (user_data
->iter_index
== 1) {
473 user_data
->seq
= seq2_with_again
;
474 } else if (user_data
->iter_index
== 2) {
475 user_data
->seq
= seq3_with_again
;
477 user_data
->seq
= seq4_with_again
;
480 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
481 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
482 if (user_data
->iter_index
== 0) {
483 /* Ignore: this iterator only returns END */
484 } else if (user_data
->iter_index
== 1) {
485 user_data
->seq
= seq2
;
487 user_data
->seq
= seq3
;
494 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
498 struct bt_notification
*src_create_event_notif(struct bt_packet
*packet
,
502 struct bt_event
*event
;
503 struct bt_notification
*notif
;
504 struct bt_field
*field
;
506 notif
= bt_notification_event_create(graph
, src_event_class
, packet
);
508 event
= bt_notification_event_borrow_event(notif
);
510 field
= bt_event_borrow_header(event
);
512 field
= bt_field_structure_borrow_field_by_name(field
, "ts");
514 ret
= bt_field_integer_unsigned_set_value(field
, (uint64_t) ts_ns
);
517 if (ts_ns
!= UINT64_C(-1)) {
518 ret
= bt_event_set_clock_value(event
, src_clock_class
, (uint64_t) ts_ns
,
527 enum bt_notification_iterator_status
src_iter_next_seq(
528 struct src_iter_user_data
*user_data
,
529 bt_notification_array notifs
)
531 enum bt_notification_iterator_status status
=
532 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
534 struct bt_stream
*stream
;
536 BT_ASSERT(user_data
->seq
);
537 cur_ts_ns
= user_data
->seq
[user_data
->at
];
541 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
544 status
= BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
546 case SEQ_PACKET_BEGIN
:
547 notifs
[0] = bt_notification_packet_begin_create(graph
,
549 BT_ASSERT(notifs
[0]);
552 notifs
[0] = bt_notification_packet_end_create(graph
,
554 BT_ASSERT(notifs
[0]);
556 case SEQ_STREAM_BEGIN
:
557 stream
= bt_packet_get_stream(user_data
->packet
);
558 notifs
[0] = bt_notification_stream_begin_create(graph
, stream
);
559 BT_ASSERT(notifs
[0]);
563 stream
= bt_packet_get_stream(user_data
->packet
);
564 notifs
[0] = bt_notification_stream_end_create(graph
, stream
);
565 BT_ASSERT(notifs
[0]);
570 notifs
[0] = src_create_event_notif(user_data
->packet
,
572 BT_ASSERT(notifs
[0]);
577 if (status
!= BT_NOTIFICATION_ITERATOR_STATUS_END
) {
585 enum bt_notification_iterator_status
src_iter_next(
586 struct bt_private_connection_private_notification_iterator
*priv_iterator
,
587 bt_notification_array notifs
, uint64_t capacity
,
590 enum bt_notification_iterator_status status
=
591 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
592 struct src_iter_user_data
*user_data
=
593 bt_private_connection_private_notification_iterator_get_user_data(priv_iterator
);
594 struct bt_private_component
*private_component
=
595 bt_private_connection_private_notification_iterator_get_private_component(priv_iterator
);
596 struct bt_stream
*stream
;
599 BT_ASSERT(user_data
);
600 BT_ASSERT(private_component
);
603 * We can always set it to 1: it's not going to be considered
604 * anyway if the status is not
605 * BT_NOTIFICATION_ITERATOR_STATUS_OK.
609 switch (current_test
) {
611 if (user_data
->iter_index
== 0) {
612 if (user_data
->at
== 0) {
613 stream
= bt_packet_get_stream(user_data
->packet
);
615 bt_notification_stream_begin_create(
618 BT_ASSERT(notifs
[0]);
619 } else if (user_data
->at
== 1) {
621 bt_notification_packet_begin_create(
622 graph
, user_data
->packet
);
623 BT_ASSERT(notifs
[0]);
624 } else if (user_data
->at
< 7) {
626 src_create_event_notif(
627 user_data
->packet
, UINT64_C(-1));
628 BT_ASSERT(notifs
[0]);
629 } else if (user_data
->at
== 7) {
631 bt_notification_packet_end_create(
632 graph
, user_data
->packet
);
633 BT_ASSERT(notifs
[0]);
634 } else if (user_data
->at
== 8) {
635 stream
= bt_packet_get_stream(user_data
->packet
);
637 bt_notification_stream_end_create(
640 BT_ASSERT(notifs
[0]);
643 BT_NOTIFICATION_ITERATOR_STATUS_END
;
648 status
= src_iter_next_seq(user_data
, notifs
);
651 case TEST_SIMPLE_4_PORTS
:
652 case TEST_4_PORTS_WITH_RETRIES
:
653 status
= src_iter_next_seq(user_data
, notifs
);
655 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
656 if (user_data
->iter_index
== 0) {
657 ret
= bt_private_component_source_add_output_private_port(
658 private_component
, "out1", NULL
, NULL
);
660 ret
= bt_private_component_source_add_output_private_port(
661 private_component
, "out2", NULL
, NULL
);
663 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
665 status
= src_iter_next_seq(user_data
, notifs
);
668 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
669 if (user_data
->iter_index
== 0) {
670 if (user_data
->at
== 0) {
671 status
= BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
674 ret
= bt_private_component_source_add_output_private_port(
675 private_component
, "out1", NULL
, NULL
);
677 ret
= bt_private_component_source_add_output_private_port(
678 private_component
, "out2", NULL
, NULL
);
680 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
683 status
= src_iter_next_seq(user_data
, notifs
);
690 bt_put(private_component
);
695 enum bt_component_status
src_init(
696 struct bt_private_component
*private_component
,
697 struct bt_value
*params
, void *init_method_data
)
702 switch (current_test
) {
706 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
707 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
716 ret
= bt_private_component_source_add_output_private_port(
717 private_component
, "out0", NULL
, NULL
);
722 ret
= bt_private_component_source_add_output_private_port(
723 private_component
, "out1", NULL
, NULL
);
728 ret
= bt_private_component_source_add_output_private_port(
729 private_component
, "out2", NULL
, NULL
);
734 ret
= bt_private_component_source_add_output_private_port(
735 private_component
, "out3", NULL
, NULL
);
739 return BT_COMPONENT_STATUS_OK
;
743 void src_finalize(struct bt_private_component
*private_component
)
748 void append_test_event_from_notification(struct bt_notification
*notification
)
751 struct test_event test_event
;
752 struct bt_clock_value
*cv
;
754 switch (bt_notification_get_type(notification
)) {
755 case BT_NOTIFICATION_TYPE_EVENT
:
757 struct bt_event
*event
;
759 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
760 event
= bt_notification_event_borrow_event(notification
);
762 cv
= bt_event_borrow_default_clock_value(event
);
765 ret
= bt_clock_value_get_value_ns_from_epoch(
766 cv
, &test_event
.ts_ns
);
769 test_event
.ts_ns
= -1;
774 case BT_NOTIFICATION_TYPE_INACTIVITY
:
776 test_event
.type
= TEST_EV_TYPE_NOTIF_INACTIVITY
;
777 cv
= bt_notification_inactivity_borrow_default_clock_value(
781 ret
= bt_clock_value_get_value_ns_from_epoch(
782 cv
, &test_event
.ts_ns
);
785 test_event
.ts_ns
= -1;
790 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
791 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
793 case BT_NOTIFICATION_TYPE_PACKET_END
:
794 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
796 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
797 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
799 case BT_NOTIFICATION_TYPE_STREAM_END
:
800 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
803 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
807 append_test_event(&test_event
);
811 enum bt_component_status
sink_consume(
812 struct bt_private_component
*priv_component
)
814 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
815 bt_notification_array notifications
= NULL
;
817 struct sink_user_data
*user_data
=
818 bt_private_component_get_user_data(priv_component
);
819 enum bt_notification_iterator_status it_ret
;
820 struct test_event test_event
;
821 bool do_append_test_event
= true;
824 BT_ASSERT(user_data
&& user_data
->notif_iter
);
825 it_ret
= bt_private_connection_notification_iterator_next(
826 user_data
->notif_iter
, ¬ifications
, &count
);
828 ret
= BT_COMPONENT_STATUS_ERROR
;
829 do_append_test_event
= false;
834 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
835 test_event
.type
= TEST_EV_TYPE_END
;
836 ret
= BT_COMPONENT_STATUS_END
;
837 BT_PUT(user_data
->notif_iter
);
839 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
840 test_event
.type
= TEST_EV_TYPE_AGAIN
;
841 ret
= BT_COMPONENT_STATUS_AGAIN
;
847 BT_ASSERT(notifications
);
849 for (i
= 0; i
< count
; i
++) {
850 append_test_event_from_notification(notifications
[i
]);
851 bt_put(notifications
[i
]);
854 do_append_test_event
= false;
857 if (do_append_test_event
) {
858 append_test_event(&test_event
);
865 enum bt_component_status
sink_port_connected(
866 struct bt_private_component
*private_component
,
867 struct bt_private_port
*self_private_port
,
868 struct bt_port
*other_port
)
870 struct bt_private_connection
*priv_conn
=
871 bt_private_port_get_private_connection(self_private_port
);
872 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
874 enum bt_connection_status conn_status
;
876 BT_ASSERT(user_data
);
877 BT_ASSERT(priv_conn
);
878 conn_status
= bt_private_connection_create_notification_iterator(
879 priv_conn
, &user_data
->notif_iter
);
880 BT_ASSERT(conn_status
== 0);
882 return BT_COMPONENT_STATUS_OK
;
886 enum bt_component_status
sink_init(
887 struct bt_private_component
*private_component
,
888 struct bt_value
*params
, void *init_method_data
)
890 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
893 BT_ASSERT(user_data
);
894 ret
= bt_private_component_set_user_data(private_component
,
897 ret
= bt_private_component_sink_add_input_private_port(
898 private_component
, "in", NULL
, NULL
);
900 return BT_COMPONENT_STATUS_OK
;
904 void sink_finalize(struct bt_private_component
*private_component
)
906 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
910 bt_put(user_data
->notif_iter
);
916 void create_source_muxer_sink(struct bt_graph
*graph
,
917 struct bt_component
**source
,
918 struct bt_component
**muxer
,
919 struct bt_component
**sink
)
921 struct bt_component_class
*src_comp_class
;
922 struct bt_component_class
*muxer_comp_class
;
923 struct bt_component_class
*sink_comp_class
;
926 /* Create source component */
927 src_comp_class
= bt_component_class_source_create("src", src_iter_next
);
928 BT_ASSERT(src_comp_class
);
929 ret
= bt_component_class_set_init_method(src_comp_class
, src_init
);
931 ret
= bt_component_class_set_finalize_method(src_comp_class
,
934 ret
= bt_component_class_source_set_notification_iterator_init_method(
935 src_comp_class
, src_iter_init
);
937 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
938 src_comp_class
, src_iter_finalize
);
940 ret
= bt_graph_add_component(graph
, src_comp_class
, "source", NULL
, source
);
943 /* Create muxer component */
944 muxer_comp_class
= bt_plugin_find_component_class("utils", "muxer",
945 BT_COMPONENT_CLASS_TYPE_FILTER
);
946 BT_ASSERT(muxer_comp_class
);
947 ret
= bt_graph_add_component(graph
, muxer_comp_class
, "muxer", NULL
, muxer
);
950 /* Create sink component */
951 sink_comp_class
= bt_component_class_sink_create("sink", sink_consume
);
952 BT_ASSERT(sink_comp_class
);
953 ret
= bt_component_class_set_init_method(sink_comp_class
, sink_init
);
955 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
957 ret
= bt_component_class_set_port_connected_method(sink_comp_class
,
958 sink_port_connected
);
960 ret
= bt_graph_add_component(graph
, sink_comp_class
, "sink", NULL
, sink
);
963 bt_put(src_comp_class
);
964 bt_put(muxer_comp_class
);
965 bt_put(sink_comp_class
);
969 void do_std_test(enum test test
, const char *name
,
970 const struct test_event
*expected_test_events
,
973 struct bt_component
*src_comp
;
974 struct bt_component
*muxer_comp
;
975 struct bt_component
*sink_comp
;
976 struct bt_port
*upstream_port
;
977 struct bt_port
*downstream_port
;
980 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
984 diag("test: %s", name
);
986 graph
= bt_graph_create();
988 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
990 /* Connect source output ports to muxer input ports */
992 count
= bt_component_source_get_output_port_count(src_comp
);
993 BT_ASSERT(count
>= 0);
995 for (i
= 0; i
< count
; i
++) {
996 upstream_port
= bt_component_source_get_output_port_by_index(
998 BT_ASSERT(upstream_port
);
999 downstream_port
= bt_component_filter_get_input_port_by_index(
1001 BT_ASSERT(downstream_port
);
1002 graph_status
= bt_graph_connect_ports(graph
,
1003 upstream_port
, downstream_port
, NULL
);
1004 BT_ASSERT(graph_status
== 0);
1005 bt_put(upstream_port
);
1006 bt_put(downstream_port
);
1010 /* Connect muxer output port to sink input port */
1011 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1013 BT_ASSERT(upstream_port
);
1014 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1015 BT_ASSERT(downstream_port
);
1016 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1017 downstream_port
, NULL
);
1018 BT_ASSERT(graph_status
== 0);
1019 bt_put(upstream_port
);
1020 bt_put(downstream_port
);
1022 while (graph_status
== BT_GRAPH_STATUS_OK
||
1023 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1024 graph_status
= bt_graph_run(graph
);
1027 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1028 ok(compare_test_events(expected_test_events
),
1029 "the produced sequence of test events is the expected one");
1038 void test_no_ts(void)
1040 const struct test_event expected_test_events
[] = {
1041 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1042 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1043 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1044 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1045 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1046 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1047 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1048 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1049 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1050 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1051 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1052 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1, },
1053 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 4, },
1054 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 189, },
1055 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1001, },
1056 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1057 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1058 { .type
= TEST_EV_TYPE_END
, },
1059 { .type
= TEST_EV_TYPE_SENTINEL
, },
1062 do_std_test(TEST_NO_TS
, "event notifications with no time",
1063 expected_test_events
, true);
1067 void test_no_upstream_connection(void)
1069 const struct test_event expected_test_events
[] = {
1070 { .type
= TEST_EV_TYPE_END
, },
1071 { .type
= TEST_EV_TYPE_SENTINEL
, },
1074 do_std_test(TEST_NO_UPSTREAM_CONNECTION
, "no upstream connection",
1075 expected_test_events
, false);
1079 void test_simple_4_ports(void)
1081 const struct test_event expected_test_events
[] = {
1082 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1083 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1084 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1085 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1086 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1087 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1088 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1089 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1090 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1091 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1092 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1093 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1094 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1095 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1096 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1097 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1098 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1099 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1100 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1101 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1102 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1103 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1104 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1105 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1106 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1107 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1108 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1109 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1110 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1111 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1112 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1113 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1114 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1115 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1116 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1117 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1118 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1119 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1120 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1121 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1122 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1123 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1124 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1125 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1126 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1127 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1128 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1129 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1130 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1131 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1132 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1133 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1134 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1135 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1136 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1137 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1138 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1139 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1140 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1141 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1142 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1143 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1144 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1145 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1146 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1147 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1148 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1149 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1150 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1151 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1152 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1153 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1154 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1155 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1156 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1157 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1158 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1159 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1160 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1161 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1162 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1163 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1164 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1165 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1166 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1167 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1168 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1169 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1170 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1171 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1172 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1173 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1174 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1175 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1176 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1177 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1178 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1179 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1180 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1181 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1182 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1183 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1184 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1185 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1186 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1187 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1188 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1189 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1190 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1191 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1192 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1193 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1194 { .type
= TEST_EV_TYPE_END
, },
1195 { .type
= TEST_EV_TYPE_SENTINEL
, },
1198 do_std_test(TEST_SIMPLE_4_PORTS
, "simple: 4 ports without retries",
1199 expected_test_events
, true);
1203 void test_4_ports_with_retries(void)
1205 const struct test_event expected_test_events
[] = {
1206 { .type
= TEST_EV_TYPE_AGAIN
, },
1207 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1208 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1209 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1210 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1211 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1212 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1213 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1214 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1215 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1216 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1217 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1218 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1219 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1220 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1221 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1222 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1223 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1224 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1225 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1226 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1227 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1228 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1229 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1230 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1231 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1232 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1233 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1234 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1235 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1236 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1237 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1238 { .type
= TEST_EV_TYPE_AGAIN
, },
1239 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1240 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1241 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1242 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1243 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1244 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1245 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1246 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1247 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1248 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1249 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1250 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1251 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1252 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1253 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1254 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1255 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1256 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1257 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1258 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1259 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1260 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1261 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1262 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1263 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1264 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1265 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1266 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1267 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1268 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1269 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1270 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1271 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1272 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1273 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1274 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1275 { .type
= TEST_EV_TYPE_AGAIN
, },
1276 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1277 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1278 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1279 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1280 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1281 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1282 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1283 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1284 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1285 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1286 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1287 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1288 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1289 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1290 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1291 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1292 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1293 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1294 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1295 { .type
= TEST_EV_TYPE_AGAIN
, },
1296 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1297 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1298 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1299 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1300 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1301 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1302 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1303 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1304 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1305 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1306 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1307 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1308 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1309 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1310 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1311 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1312 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1313 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1314 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1315 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1316 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1317 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1318 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1319 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1320 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1321 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1322 { .type
= TEST_EV_TYPE_END
, },
1323 { .type
= TEST_EV_TYPE_SENTINEL
, },
1326 do_std_test(TEST_4_PORTS_WITH_RETRIES
, "4 ports with retries",
1327 expected_test_events
, true);
1331 void connect_port_to_first_avail_muxer_port(struct bt_graph
*graph
,
1332 struct bt_port
*source_port
,
1333 struct bt_component
*muxer_comp
)
1335 struct bt_port
*avail_muxer_port
= NULL
;
1338 enum bt_graph_status graph_status
;
1340 count
= bt_component_filter_get_input_port_count(muxer_comp
);
1341 BT_ASSERT(count
>= 0);
1343 for (i
= 0; i
< count
; i
++) {
1344 struct bt_port
*muxer_port
=
1345 bt_component_filter_get_input_port_by_index(
1348 BT_ASSERT(muxer_port
);
1350 if (!bt_port_is_connected(muxer_port
)) {
1351 BT_MOVE(avail_muxer_port
, muxer_port
);
1358 graph_status
= bt_graph_connect_ports(graph
, source_port
,
1359 avail_muxer_port
, NULL
);
1360 BT_ASSERT(graph_status
== 0);
1361 bt_put(avail_muxer_port
);
1365 void graph_port_added_listener_connect_to_avail_muxer_port(struct bt_port
*port
,
1368 struct graph_listener_data
*graph_listener_data
= data
;
1369 struct bt_component
*comp
;
1371 comp
= bt_port_get_component(port
);
1374 if (comp
!= graph_listener_data
->source
) {
1378 connect_port_to_first_avail_muxer_port(graph_listener_data
->graph
,
1379 port
, graph_listener_data
->muxer
);
1386 void test_single_end_then_multiple_full(void)
1388 struct bt_component
*src_comp
;
1389 struct bt_component
*muxer_comp
;
1390 struct bt_component
*sink_comp
;
1391 struct bt_port
*upstream_port
;
1392 struct bt_port
*downstream_port
;
1396 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1397 struct graph_listener_data graph_listener_data
;
1398 const struct test_event expected_test_events
[] = {
1399 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1400 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1401 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1402 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1403 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1404 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1405 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1406 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1407 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1408 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1409 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1410 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1411 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1412 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1413 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1414 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1415 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1416 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1417 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1418 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1419 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1420 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1421 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1422 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1423 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1424 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1425 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1426 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1427 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1428 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1429 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1430 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1431 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1432 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1433 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1434 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1435 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1436 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1437 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1438 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1439 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1440 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1441 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1442 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1443 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1444 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1445 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1446 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1447 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1448 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1449 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1450 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1451 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1452 { .type
= TEST_EV_TYPE_END
, },
1453 { .type
= TEST_EV_TYPE_SENTINEL
, },
1456 clear_test_events();
1457 current_test
= TEST_SINGLE_END_THEN_MULTIPLE_FULL
;
1458 diag("test: single end then multiple full");
1460 graph
= bt_graph_create();
1462 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
1463 graph_listener_data
.graph
= graph
;
1464 graph_listener_data
.source
= src_comp
;
1465 graph_listener_data
.muxer
= muxer_comp
;
1466 graph_listener_data
.sink
= sink_comp
;
1467 ret
= bt_graph_add_port_added_listener(graph
,
1468 graph_port_added_listener_connect_to_avail_muxer_port
, NULL
,
1469 &graph_listener_data
);
1470 BT_ASSERT(ret
>= 0);
1472 /* Connect source output ports to muxer input ports */
1473 count
= bt_component_source_get_output_port_count(src_comp
);
1474 BT_ASSERT(ret
== 0);
1476 for (i
= 0; i
< count
; i
++) {
1477 upstream_port
= bt_component_source_get_output_port_by_index(
1479 BT_ASSERT(upstream_port
);
1480 connect_port_to_first_avail_muxer_port(graph
,
1481 upstream_port
, muxer_comp
);
1482 bt_put(upstream_port
);
1485 /* Connect muxer output port to sink input port */
1486 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1488 BT_ASSERT(upstream_port
);
1489 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1490 BT_ASSERT(downstream_port
);
1491 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1492 downstream_port
, NULL
);
1493 BT_ASSERT(graph_status
== 0);
1494 bt_put(upstream_port
);
1495 bt_put(downstream_port
);
1497 while (graph_status
== BT_GRAPH_STATUS_OK
||
1498 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1499 graph_status
= bt_graph_run(graph
);
1502 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1503 ok(compare_test_events(expected_test_events
),
1504 "the produced sequence of test events is the expected one");
1513 void test_single_again_end_then_multiple_full(void)
1515 struct bt_component
*src_comp
;
1516 struct bt_component
*muxer_comp
;
1517 struct bt_component
*sink_comp
;
1518 struct bt_port
*upstream_port
;
1519 struct bt_port
*downstream_port
;
1523 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1524 struct graph_listener_data graph_listener_data
;
1525 const struct test_event expected_test_events
[] = {
1526 { .type
= TEST_EV_TYPE_AGAIN
, },
1527 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1528 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1529 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1530 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1531 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1532 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1533 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1534 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1535 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1536 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1537 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1538 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1539 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1540 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1541 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1542 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1543 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1544 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1545 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1546 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1547 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1548 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1549 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1550 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1551 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1552 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1553 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1554 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1555 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1556 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1557 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1558 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1559 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1560 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1561 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1562 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1563 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1564 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1565 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1566 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1567 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1568 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1569 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1570 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1571 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1572 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1573 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1574 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1575 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1576 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1577 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1578 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1579 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1580 { .type
= TEST_EV_TYPE_END
, },
1581 { .type
= TEST_EV_TYPE_SENTINEL
, },
1584 clear_test_events();
1585 current_test
= TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
;
1586 diag("test: single again then end then multiple full");
1588 graph
= bt_graph_create();
1590 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
1591 graph_listener_data
.graph
= graph
;
1592 graph_listener_data
.source
= src_comp
;
1593 graph_listener_data
.muxer
= muxer_comp
;
1594 graph_listener_data
.sink
= sink_comp
;
1595 ret
= bt_graph_add_port_added_listener(graph
,
1596 graph_port_added_listener_connect_to_avail_muxer_port
, NULL
,
1597 &graph_listener_data
);
1598 BT_ASSERT(ret
>= 0);
1600 /* Connect source output ports to muxer input ports */
1601 count
= bt_component_source_get_output_port_count(src_comp
);
1602 BT_ASSERT(ret
== 0);
1604 for (i
= 0; i
< count
; i
++) {
1605 upstream_port
= bt_component_source_get_output_port_by_index(
1607 BT_ASSERT(upstream_port
);
1608 connect_port_to_first_avail_muxer_port(graph
,
1609 upstream_port
, muxer_comp
);
1610 bt_put(upstream_port
);
1613 /* Connect muxer output port to sink input port */
1614 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1616 BT_ASSERT(upstream_port
);
1617 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1618 BT_ASSERT(downstream_port
);
1619 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1620 downstream_port
, NULL
);
1621 BT_ASSERT(graph_status
== 0);
1622 bt_put(upstream_port
);
1623 bt_put(downstream_port
);
1625 while (graph_status
== BT_GRAPH_STATUS_OK
||
1626 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1627 graph_status
= bt_graph_run(graph
);
1630 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1631 ok(compare_test_events(expected_test_events
),
1632 "the produced sequence of test events is the expected one");
1640 #define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG"
1642 int main(int argc
, char **argv
)
1644 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
1648 plan_tests(NR_TESTS
);
1651 test_no_upstream_connection();
1652 test_simple_4_ports();
1653 test_4_ports_with_retries();
1654 test_single_end_then_multiple_full();
1655 test_single_again_end_then_multiple_full();
1657 return exit_status();