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_priority_map
*src_cc_prio_map
;
77 static struct bt_clock_class_priority_map
*src_empty_cc_prio_map
;
78 static struct bt_clock_class
*src_clock_class
;
79 static struct bt_stream_class
*src_stream_class
;
80 static struct bt_event_class
*src_event_class
;
81 static struct bt_packet
*src_packet0
;
82 static struct bt_packet
*src_packet1
;
83 static struct bt_packet
*src_packet2
;
84 static struct bt_packet
*src_packet3
;
89 SEQ_PACKET_BEGIN
= -3,
91 SEQ_STREAM_BEGIN
= -5,
95 struct src_iter_user_data
{
99 struct bt_packet
*packet
;
102 struct sink_user_data
{
103 struct bt_notification_iterator
*notif_iter
;
106 static int64_t seq1
[] = {
107 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 24, 53, 97, 105, 119, 210,
108 222, 240, 292, 317, 353, 407, 433, 473, 487, 504, 572, 615, 708,
109 766, 850, 852, 931, 951, 956, 996, SEQ_PACKET_END
,
110 SEQ_STREAM_END
, SEQ_END
,
113 static int64_t seq2
[] = {
114 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 51, 59, 68, 77, 91, 121,
115 139, 170, 179, 266, 352, 454, 478, 631, 644, 668, 714, 744, 750,
116 778, 790, 836, SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
119 static int64_t seq3
[] = {
120 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 8, 71, 209, 254, 298, 320,
121 350, 393, 419, 624, 651, 678, 717, 731, 733, 788, 819, 820, 857,
122 892, 903, 944, 998, SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
125 static int64_t seq4
[] = {
126 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 41, 56, 120, 138, 154, 228,
127 471, 479, 481, 525, 591, 605, 612, 618, 632, 670, 696, 825, 863,
128 867, 871, 884, 953, 985, 999, SEQ_PACKET_END
, SEQ_STREAM_END
,
132 static int64_t seq1_with_again
[] = {
133 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 24, 53, 97, 105, 119, 210,
134 SEQ_AGAIN
, 222, 240, 292, 317, 353, 407, 433, 473, 487, 504,
135 572, 615, 708, 766, 850, 852, 931, 951, 956, 996,
136 SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
139 static int64_t seq2_with_again
[] = {
140 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 51, 59, 68, 77, 91, 121,
141 139, 170, 179, 266, 352, 454, 478, 631, 644, 668, 714, 744, 750,
142 778, 790, 836, SEQ_AGAIN
, SEQ_PACKET_END
, SEQ_STREAM_END
,
146 static int64_t seq3_with_again
[] = {
147 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 8, 71, 209, 254, 298, 320,
148 350, 393, 419, 624, 651, SEQ_AGAIN
, 678, 717, 731, 733, 788,
149 819, 820, 857, 892, 903, 944, 998, SEQ_PACKET_END
,
150 SEQ_STREAM_END
, SEQ_END
,
153 static int64_t seq4_with_again
[] = {
154 SEQ_AGAIN
, SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 41, 56, 120, 138,
155 154, 228, 471, 479, 481, 525, 591, 605, 612, 618, 632, 670, 696,
156 825, 863, 867, 871, 884, 953, 985, 999, SEQ_PACKET_END
,
157 SEQ_STREAM_END
, SEQ_END
,
160 static int64_t seq5
[] = {
161 SEQ_STREAM_BEGIN
, SEQ_PACKET_BEGIN
, 1, 4, 189, 1001,
162 SEQ_PACKET_END
, SEQ_STREAM_END
, SEQ_END
,
166 void clear_test_events(void)
168 g_array_set_size(test_events
, 0);
172 void print_test_event(FILE *fp
, const struct test_event
*event
)
174 fprintf(fp
, "{ type = ");
176 switch (event
->type
) {
177 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
178 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
180 case TEST_EV_TYPE_NOTIF_EVENT
:
181 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
183 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
184 fprintf(fp
, "TEST_EV_TYPE_NOTIF_INACTIVITY");
186 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
187 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
189 case TEST_EV_TYPE_NOTIF_PACKET_END
:
190 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
192 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
193 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
195 case TEST_EV_TYPE_NOTIF_STREAM_END
:
196 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
198 case TEST_EV_TYPE_AGAIN
:
199 fprintf(fp
, "TEST_EV_TYPE_AGAIN");
201 case TEST_EV_TYPE_END
:
202 fprintf(fp
, "TEST_EV_TYPE_END");
204 case TEST_EV_TYPE_SENTINEL
:
205 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
208 fprintf(fp
, "(UNKNOWN)");
212 switch (event
->type
) {
213 case TEST_EV_TYPE_NOTIF_EVENT
:
214 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
215 fprintf(fp
, ", ts-ns = %" PRId64
, event
->ts_ns
);
224 void append_test_event(struct test_event
*event
)
226 g_array_append_val(test_events
, *event
);
230 bool compare_single_test_events(const struct test_event
*ev_a
,
231 const struct test_event
*ev_b
)
234 fprintf(stderr
, ":: Comparing test events: ");
235 print_test_event(stderr
, ev_a
);
236 fprintf(stderr
, " vs. ");
237 print_test_event(stderr
, ev_b
);
238 fprintf(stderr
, "\n");
241 if (ev_a
->type
!= ev_b
->type
) {
245 switch (ev_a
->type
) {
246 case TEST_EV_TYPE_NOTIF_EVENT
:
247 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
248 if (ev_a
->ts_ns
!= ev_b
->ts_ns
) {
260 bool compare_test_events(const struct test_event
*expected_events
)
262 const struct test_event
*expected_event
= expected_events
;
265 BT_ASSERT(expected_events
);
268 const struct test_event
*event
;
270 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
274 if (i
>= test_events
->len
) {
278 event
= &g_array_index(test_events
, struct test_event
, i
);
280 if (!compare_single_test_events(event
, expected_event
)) {
288 if (i
!= test_events
->len
) {
290 fprintf(stderr
, ":: Length mismatch\n");
300 void init_static_data(void)
303 struct bt_trace
*trace
;
304 struct bt_stream
*stream
;
305 struct bt_field_type
*empty_struct_ft
;
306 struct bt_field_type
*eh_ft
;
307 struct bt_field_type
*eh_ts_ft
;
310 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
311 BT_ASSERT(test_events
);
314 empty_struct_ft
= bt_field_type_structure_create();
315 BT_ASSERT(empty_struct_ft
);
316 src_clock_class
= bt_clock_class_create("my-clock", 1000000000);
317 BT_ASSERT(src_clock_class
);
318 trace
= bt_trace_create();
320 ret
= bt_trace_set_native_byte_order(trace
,
321 BT_BYTE_ORDER_LITTLE_ENDIAN
);
323 ret
= bt_trace_set_packet_header_field_type(trace
, empty_struct_ft
);
325 ret
= bt_clock_class_set_is_absolute(src_clock_class
, 1);
327 ret
= bt_trace_add_clock_class(trace
, src_clock_class
);
329 src_empty_cc_prio_map
= bt_clock_class_priority_map_create();
330 BT_ASSERT(src_empty_cc_prio_map
);
331 src_cc_prio_map
= bt_clock_class_priority_map_create();
332 BT_ASSERT(src_cc_prio_map
);
333 ret
= bt_clock_class_priority_map_add_clock_class(src_cc_prio_map
,
336 src_stream_class
= bt_stream_class_create("my-stream-class");
337 BT_ASSERT(src_stream_class
);
338 ret
= bt_stream_class_set_packet_context_field_type(src_stream_class
,
341 eh_ft
= bt_field_type_structure_create();
343 eh_ts_ft
= bt_field_type_integer_create(64);
345 ret
= bt_field_type_structure_add_field(eh_ft
, eh_ts_ft
, "ts");
347 ret
= bt_field_type_integer_set_mapped_clock_class(eh_ts_ft
,
350 ret
= bt_stream_class_set_event_header_field_type(src_stream_class
,
353 ret
= bt_stream_class_set_event_context_field_type(src_stream_class
,
356 src_event_class
= bt_event_class_create("my-event-class");
357 ret
= bt_event_class_set_context_field_type(src_event_class
,
360 ret
= bt_event_class_set_context_field_type(src_event_class
,
363 ret
= bt_stream_class_add_event_class(src_stream_class
,
366 ret
= bt_trace_add_stream_class(trace
, src_stream_class
);
368 stream
= bt_stream_create(src_stream_class
, "stream0", 0);
370 src_packet0
= bt_packet_create(stream
);
371 BT_ASSERT(src_packet0
);
373 stream
= bt_stream_create(src_stream_class
, "stream1", 1);
375 src_packet1
= bt_packet_create(stream
);
376 BT_ASSERT(src_packet0
);
378 stream
= bt_stream_create(src_stream_class
, "stream2", 2);
380 src_packet2
= bt_packet_create(stream
);
381 BT_ASSERT(src_packet0
);
383 stream
= bt_stream_create(src_stream_class
, "stream3", 3);
385 src_packet3
= bt_packet_create(stream
);
386 BT_ASSERT(src_packet0
);
390 bt_put(empty_struct_ft
);
396 void fini_static_data(void)
399 g_array_free(test_events
, TRUE
);
402 bt_put(src_empty_cc_prio_map
);
403 bt_put(src_cc_prio_map
);
404 bt_put(src_clock_class
);
405 bt_put(src_stream_class
);
406 bt_put(src_event_class
);
414 void src_iter_finalize(
415 struct bt_private_connection_private_notification_iterator
*private_notification_iterator
)
417 struct src_iter_user_data
*user_data
=
418 bt_private_connection_private_notification_iterator_get_user_data(
419 private_notification_iterator
);
427 enum bt_notification_iterator_status
src_iter_init(
428 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
429 struct bt_private_port
*private_port
)
431 struct src_iter_user_data
*user_data
=
432 g_new0(struct src_iter_user_data
, 1);
433 struct bt_port
*port
= bt_port_borrow_from_private(private_port
);
434 const char *port_name
;
437 BT_ASSERT(user_data
);
439 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
442 port_name
= bt_port_get_name(port
);
443 BT_ASSERT(port_name
);
444 user_data
->iter_index
= port_name
[3] - '0';
446 switch (user_data
->iter_index
) {
448 user_data
->packet
= src_packet0
;
451 user_data
->packet
= src_packet1
;
454 user_data
->packet
= src_packet2
;
457 user_data
->packet
= src_packet3
;
463 switch (current_test
) {
465 if (user_data
->iter_index
== 1) {
466 user_data
->seq
= seq5
;
469 case TEST_SIMPLE_4_PORTS
:
470 if (user_data
->iter_index
== 0) {
471 user_data
->seq
= seq1
;
472 } else if (user_data
->iter_index
== 1) {
473 user_data
->seq
= seq2
;
474 } else if (user_data
->iter_index
== 2) {
475 user_data
->seq
= seq3
;
477 user_data
->seq
= seq4
;
480 case TEST_4_PORTS_WITH_RETRIES
:
481 if (user_data
->iter_index
== 0) {
482 user_data
->seq
= seq1_with_again
;
483 } else if (user_data
->iter_index
== 1) {
484 user_data
->seq
= seq2_with_again
;
485 } else if (user_data
->iter_index
== 2) {
486 user_data
->seq
= seq3_with_again
;
488 user_data
->seq
= seq4_with_again
;
491 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
492 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
493 if (user_data
->iter_index
== 0) {
494 /* Ignore: this iterator only returns END */
495 } else if (user_data
->iter_index
== 1) {
496 user_data
->seq
= seq2
;
498 user_data
->seq
= seq3
;
505 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
509 struct bt_notification
*src_create_event_notif(struct bt_packet
*packet
,
510 struct bt_clock_class_priority_map
*cc_prio_map
, int64_t ts_ns
)
513 struct bt_event
*event
;
514 struct bt_notification
*notif
;
515 struct bt_clock_value
*clock_value
;
516 struct bt_field
*field
;
518 notif
= bt_notification_event_create(graph
, src_event_class
,
519 packet
, cc_prio_map
);
521 event
= bt_notification_event_borrow_event(notif
);
523 field
= bt_event_borrow_header(event
);
525 field
= bt_field_structure_borrow_field_by_name(field
, "ts");
527 ret
= bt_field_integer_unsigned_set_value(field
, (uint64_t) ts_ns
);
529 clock_value
= bt_event_borrow_clock_value(event
, src_clock_class
);
530 BT_ASSERT(clock_value
);
531 ret
= bt_clock_value_set_value(clock_value
, (uint64_t) ts_ns
);
537 struct bt_notification_iterator_next_method_return
src_iter_next_seq(
538 struct src_iter_user_data
*user_data
)
540 struct bt_notification_iterator_next_method_return next_return
= {
541 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
544 struct bt_stream
*stream
;
546 BT_ASSERT(user_data
->seq
);
547 cur_ts_ns
= user_data
->seq
[user_data
->at
];
552 BT_NOTIFICATION_ITERATOR_STATUS_END
;
556 BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
558 case SEQ_PACKET_BEGIN
:
559 next_return
.notification
=
560 bt_notification_packet_begin_create(graph
,
562 BT_ASSERT(next_return
.notification
);
565 next_return
.notification
=
566 bt_notification_packet_end_create(graph
,
568 BT_ASSERT(next_return
.notification
);
570 case SEQ_STREAM_BEGIN
:
571 stream
= bt_packet_get_stream(user_data
->packet
);
572 next_return
.notification
=
573 bt_notification_stream_begin_create(graph
, stream
);
574 BT_ASSERT(next_return
.notification
);
578 stream
= bt_packet_get_stream(user_data
->packet
);
579 next_return
.notification
=
580 bt_notification_stream_end_create(graph
, stream
);
581 BT_ASSERT(next_return
.notification
);
586 next_return
.notification
= src_create_event_notif(
587 user_data
->packet
, src_cc_prio_map
, cur_ts_ns
);
588 BT_ASSERT(next_return
.notification
);
593 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_END
) {
601 struct bt_notification_iterator_next_method_return
src_iter_next(
602 struct bt_private_connection_private_notification_iterator
*priv_iterator
)
604 struct bt_notification_iterator_next_method_return next_return
= {
605 .notification
= NULL
,
606 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
608 struct src_iter_user_data
*user_data
=
609 bt_private_connection_private_notification_iterator_get_user_data(priv_iterator
);
610 struct bt_private_component
*private_component
=
611 bt_private_connection_private_notification_iterator_get_private_component(priv_iterator
);
612 struct bt_stream
*stream
;
615 BT_ASSERT(user_data
);
616 BT_ASSERT(private_component
);
618 switch (current_test
) {
620 if (user_data
->iter_index
== 0) {
621 if (user_data
->at
== 0) {
622 stream
= bt_packet_get_stream(user_data
->packet
);
623 next_return
.notification
=
624 bt_notification_stream_begin_create(
627 BT_ASSERT(next_return
.notification
);
628 } else if (user_data
->at
== 1) {
629 next_return
.notification
=
630 bt_notification_packet_begin_create(
631 graph
, user_data
->packet
);
632 BT_ASSERT(next_return
.notification
);
633 } else if (user_data
->at
< 7) {
634 next_return
.notification
=
635 src_create_event_notif(
637 src_empty_cc_prio_map
, 0);
638 BT_ASSERT(next_return
.notification
);
639 } else if (user_data
->at
== 7) {
640 next_return
.notification
=
641 bt_notification_packet_end_create(
642 graph
, user_data
->packet
);
643 BT_ASSERT(next_return
.notification
);
644 } else if (user_data
->at
== 8) {
645 stream
= bt_packet_get_stream(user_data
->packet
);
646 next_return
.notification
=
647 bt_notification_stream_end_create(
650 BT_ASSERT(next_return
.notification
);
653 BT_NOTIFICATION_ITERATOR_STATUS_END
;
658 next_return
= src_iter_next_seq(user_data
);
661 case TEST_SIMPLE_4_PORTS
:
662 case TEST_4_PORTS_WITH_RETRIES
:
663 next_return
= src_iter_next_seq(user_data
);
665 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
666 if (user_data
->iter_index
== 0) {
667 ret
= bt_private_component_source_add_output_private_port(
668 private_component
, "out1", NULL
, NULL
);
670 ret
= bt_private_component_source_add_output_private_port(
671 private_component
, "out2", NULL
, NULL
);
673 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
675 next_return
= src_iter_next_seq(user_data
);
678 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
679 if (user_data
->iter_index
== 0) {
680 if (user_data
->at
== 0) {
681 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
684 ret
= bt_private_component_source_add_output_private_port(
685 private_component
, "out1", NULL
, NULL
);
687 ret
= bt_private_component_source_add_output_private_port(
688 private_component
, "out2", NULL
, NULL
);
690 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
693 next_return
= src_iter_next_seq(user_data
);
700 bt_put(private_component
);
705 enum bt_component_status
src_init(
706 struct bt_private_component
*private_component
,
707 struct bt_value
*params
, void *init_method_data
)
712 switch (current_test
) {
716 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
717 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
726 ret
= bt_private_component_source_add_output_private_port(
727 private_component
, "out0", NULL
, NULL
);
732 ret
= bt_private_component_source_add_output_private_port(
733 private_component
, "out1", NULL
, NULL
);
738 ret
= bt_private_component_source_add_output_private_port(
739 private_component
, "out2", NULL
, NULL
);
744 ret
= bt_private_component_source_add_output_private_port(
745 private_component
, "out3", NULL
, NULL
);
749 return BT_COMPONENT_STATUS_OK
;
753 void src_finalize(struct bt_private_component
*private_component
)
758 enum bt_component_status
sink_consume(
759 struct bt_private_component
*priv_component
)
761 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
762 struct bt_notification
*notification
= NULL
;
763 struct sink_user_data
*user_data
=
764 bt_private_component_get_user_data(priv_component
);
765 enum bt_notification_iterator_status it_ret
;
766 struct test_event test_event
;
767 bool do_append_test_event
= true;
769 BT_ASSERT(user_data
&& user_data
->notif_iter
);
770 it_ret
= bt_private_connection_notification_iterator_next(
771 user_data
->notif_iter
, ¬ification
);
774 ret
= BT_COMPONENT_STATUS_ERROR
;
775 do_append_test_event
= false;
780 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
781 test_event
.type
= TEST_EV_TYPE_END
;
782 ret
= BT_COMPONENT_STATUS_END
;
783 BT_PUT(user_data
->notif_iter
);
785 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
786 test_event
.type
= TEST_EV_TYPE_AGAIN
;
787 ret
= BT_COMPONENT_STATUS_AGAIN
;
793 BT_ASSERT(notification
);
795 switch (bt_notification_get_type(notification
)) {
796 case BT_NOTIFICATION_TYPE_EVENT
:
798 struct bt_event
*event
;
799 struct bt_clock_class_priority_map
*cc_prio_map
;
801 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
803 bt_notification_event_borrow_clock_class_priority_map(
805 BT_ASSERT(cc_prio_map
);
806 event
= bt_notification_event_borrow_event(notification
);
809 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) > 0) {
810 struct bt_clock_value
*clock_value
;
811 struct bt_clock_class
*clock_class
=
812 bt_clock_class_priority_map_borrow_highest_priority_clock_class(
815 BT_ASSERT(clock_class
);
816 clock_value
= bt_event_borrow_clock_value(event
,
818 BT_ASSERT(clock_value
);
819 ret
= bt_clock_value_get_value_ns_from_epoch(
820 clock_value
, &test_event
.ts_ns
);
823 test_event
.ts_ns
= -1;
828 case BT_NOTIFICATION_TYPE_INACTIVITY
:
830 struct bt_clock_class_priority_map
*cc_prio_map
;
832 test_event
.type
= TEST_EV_TYPE_NOTIF_INACTIVITY
;
833 cc_prio_map
= bt_notification_inactivity_borrow_clock_class_priority_map(
835 BT_ASSERT(cc_prio_map
);
837 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) > 0) {
838 struct bt_clock_value
*clock_value
;
839 struct bt_clock_class
*clock_class
=
840 bt_clock_class_priority_map_borrow_highest_priority_clock_class(
843 BT_ASSERT(clock_class
);
845 bt_notification_inactivity_borrow_clock_value(
846 notification
, clock_class
);
847 BT_ASSERT(clock_value
);
848 ret
= bt_clock_value_get_value_ns_from_epoch(
849 clock_value
, &test_event
.ts_ns
);
852 test_event
.ts_ns
= -1;
857 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
858 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
860 case BT_NOTIFICATION_TYPE_PACKET_END
:
861 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
863 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
864 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
866 case BT_NOTIFICATION_TYPE_STREAM_END
:
867 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
870 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
875 if (do_append_test_event
) {
876 append_test_event(&test_event
);
879 bt_put(notification
);
884 void sink_port_connected(struct bt_private_component
*private_component
,
885 struct bt_private_port
*self_private_port
,
886 struct bt_port
*other_port
)
888 struct bt_private_connection
*priv_conn
=
889 bt_private_port_get_private_connection(self_private_port
);
890 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
892 enum bt_connection_status conn_status
;
894 BT_ASSERT(user_data
);
895 BT_ASSERT(priv_conn
);
896 conn_status
= bt_private_connection_create_notification_iterator(
897 priv_conn
, &user_data
->notif_iter
);
898 BT_ASSERT(conn_status
== 0);
903 enum bt_component_status
sink_init(
904 struct bt_private_component
*private_component
,
905 struct bt_value
*params
, void *init_method_data
)
907 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
910 BT_ASSERT(user_data
);
911 ret
= bt_private_component_set_user_data(private_component
,
914 ret
= bt_private_component_sink_add_input_private_port(
915 private_component
, "in", NULL
, NULL
);
917 return BT_COMPONENT_STATUS_OK
;
921 void sink_finalize(struct bt_private_component
*private_component
)
923 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
927 bt_put(user_data
->notif_iter
);
933 void create_source_muxer_sink(struct bt_graph
*graph
,
934 struct bt_component
**source
,
935 struct bt_component
**muxer
,
936 struct bt_component
**sink
)
938 struct bt_component_class
*src_comp_class
;
939 struct bt_component_class
*muxer_comp_class
;
940 struct bt_component_class
*sink_comp_class
;
943 /* Create source component */
944 src_comp_class
= bt_component_class_source_create("src", src_iter_next
);
945 BT_ASSERT(src_comp_class
);
946 ret
= bt_component_class_set_init_method(src_comp_class
, src_init
);
948 ret
= bt_component_class_set_finalize_method(src_comp_class
,
951 ret
= bt_component_class_source_set_notification_iterator_init_method(
952 src_comp_class
, src_iter_init
);
954 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
955 src_comp_class
, src_iter_finalize
);
957 ret
= bt_graph_add_component(graph
, src_comp_class
, "source", NULL
, source
);
960 /* Create muxer component */
961 muxer_comp_class
= bt_plugin_find_component_class("utils", "muxer",
962 BT_COMPONENT_CLASS_TYPE_FILTER
);
963 BT_ASSERT(muxer_comp_class
);
964 ret
= bt_graph_add_component(graph
, muxer_comp_class
, "muxer", NULL
, muxer
);
967 /* Create sink component */
968 sink_comp_class
= bt_component_class_sink_create("sink", sink_consume
);
969 BT_ASSERT(sink_comp_class
);
970 ret
= bt_component_class_set_init_method(sink_comp_class
, sink_init
);
972 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
974 ret
= bt_component_class_set_port_connected_method(sink_comp_class
,
975 sink_port_connected
);
977 ret
= bt_graph_add_component(graph
, sink_comp_class
, "sink", NULL
, sink
);
980 bt_put(src_comp_class
);
981 bt_put(muxer_comp_class
);
982 bt_put(sink_comp_class
);
986 void do_std_test(enum test test
, const char *name
,
987 const struct test_event
*expected_test_events
,
990 struct bt_component
*src_comp
;
991 struct bt_component
*muxer_comp
;
992 struct bt_component
*sink_comp
;
993 struct bt_port
*upstream_port
;
994 struct bt_port
*downstream_port
;
997 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1000 current_test
= test
;
1001 diag("test: %s", name
);
1003 graph
= bt_graph_create();
1005 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
1007 /* Connect source output ports to muxer input ports */
1008 if (with_upstream
) {
1009 count
= bt_component_source_get_output_port_count(src_comp
);
1010 BT_ASSERT(count
>= 0);
1012 for (i
= 0; i
< count
; i
++) {
1013 upstream_port
= bt_component_source_get_output_port_by_index(
1015 BT_ASSERT(upstream_port
);
1016 downstream_port
= bt_component_filter_get_input_port_by_index(
1018 BT_ASSERT(downstream_port
);
1019 graph_status
= bt_graph_connect_ports(graph
,
1020 upstream_port
, downstream_port
, NULL
);
1021 BT_ASSERT(graph_status
== 0);
1022 bt_put(upstream_port
);
1023 bt_put(downstream_port
);
1027 /* Connect muxer output port to sink input port */
1028 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1030 BT_ASSERT(upstream_port
);
1031 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1032 BT_ASSERT(downstream_port
);
1033 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1034 downstream_port
, NULL
);
1035 BT_ASSERT(graph_status
== 0);
1036 bt_put(upstream_port
);
1037 bt_put(downstream_port
);
1039 while (graph_status
== BT_GRAPH_STATUS_OK
||
1040 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1041 graph_status
= bt_graph_run(graph
);
1044 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1045 ok(compare_test_events(expected_test_events
),
1046 "the produced sequence of test events is the expected one");
1055 void test_no_ts(void)
1057 const struct test_event expected_test_events
[] = {
1058 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1059 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1060 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1061 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1062 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1063 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1064 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1065 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1066 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1067 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1068 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1069 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1, },
1070 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 4, },
1071 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 189, },
1072 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1001, },
1073 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1074 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1075 { .type
= TEST_EV_TYPE_END
, },
1076 { .type
= TEST_EV_TYPE_SENTINEL
, },
1079 do_std_test(TEST_NO_TS
, "event notifications with no time",
1080 expected_test_events
, true);
1084 void test_no_upstream_connection(void)
1086 const struct test_event expected_test_events
[] = {
1087 { .type
= TEST_EV_TYPE_END
, },
1088 { .type
= TEST_EV_TYPE_SENTINEL
, },
1091 do_std_test(TEST_NO_UPSTREAM_CONNECTION
, "no upstream connection",
1092 expected_test_events
, false);
1096 void test_simple_4_ports(void)
1098 const struct test_event expected_test_events
[] = {
1099 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1100 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1101 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1102 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1103 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1104 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1105 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1106 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1107 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1108 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1109 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1110 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1111 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1112 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1113 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1114 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1115 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1116 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1117 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1118 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1119 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1120 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1121 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1122 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1123 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1124 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1125 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1126 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1127 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1128 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1129 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1130 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1131 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1132 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1133 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1134 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1135 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1136 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1137 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1138 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1139 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1140 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1141 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1142 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1143 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1144 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1145 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1146 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1147 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1148 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1149 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1150 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1151 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1152 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1153 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1154 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1155 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1156 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1157 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1158 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1159 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1160 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1161 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1162 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1163 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1164 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1165 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1166 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1167 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1168 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1169 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1170 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1171 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1172 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1173 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1174 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1175 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1176 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1177 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1178 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1179 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1180 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1181 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1182 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1183 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1184 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1185 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1186 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1187 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1188 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1189 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1190 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1191 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1192 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1193 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1194 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1195 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1196 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1197 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1198 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1199 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1200 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1201 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1202 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1203 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1204 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1205 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1206 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1207 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1208 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1209 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1210 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1211 { .type
= TEST_EV_TYPE_END
, },
1212 { .type
= TEST_EV_TYPE_SENTINEL
, },
1215 do_std_test(TEST_SIMPLE_4_PORTS
, "simple: 4 ports without retries",
1216 expected_test_events
, true);
1220 void test_4_ports_with_retries(void)
1222 const struct test_event expected_test_events
[] = {
1223 { .type
= TEST_EV_TYPE_AGAIN
, },
1224 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1225 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1226 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1227 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1228 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1229 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1230 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1231 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1232 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1233 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1234 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1235 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1236 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1237 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1238 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1239 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1240 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1241 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1242 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1243 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1244 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1245 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1246 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1247 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1248 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1249 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1250 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1251 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1252 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1253 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1254 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1255 { .type
= TEST_EV_TYPE_AGAIN
, },
1256 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1257 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1258 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1259 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1260 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1261 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1262 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1263 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1264 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1265 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1266 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1267 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1268 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1269 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1270 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1271 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1272 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1273 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1274 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1275 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1276 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1277 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1278 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1279 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1280 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1281 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1282 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1283 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1284 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1285 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1286 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1287 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1288 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1289 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1290 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1291 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1292 { .type
= TEST_EV_TYPE_AGAIN
, },
1293 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1294 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1295 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1296 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1297 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1298 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1299 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1300 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1301 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1302 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1303 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1304 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1305 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1306 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1307 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1308 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1309 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1310 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1311 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1312 { .type
= TEST_EV_TYPE_AGAIN
, },
1313 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1314 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1315 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1316 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1317 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1318 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1319 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1320 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1321 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1322 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1323 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1324 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1325 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1326 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1327 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1328 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1329 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1330 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1331 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1332 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1333 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1334 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1335 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1336 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1337 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1338 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1339 { .type
= TEST_EV_TYPE_END
, },
1340 { .type
= TEST_EV_TYPE_SENTINEL
, },
1343 do_std_test(TEST_4_PORTS_WITH_RETRIES
, "4 ports with retries",
1344 expected_test_events
, true);
1348 void connect_port_to_first_avail_muxer_port(struct bt_graph
*graph
,
1349 struct bt_port
*source_port
,
1350 struct bt_component
*muxer_comp
)
1352 struct bt_port
*avail_muxer_port
= NULL
;
1355 enum bt_graph_status graph_status
;
1357 count
= bt_component_filter_get_input_port_count(muxer_comp
);
1358 BT_ASSERT(count
>= 0);
1360 for (i
= 0; i
< count
; i
++) {
1361 struct bt_port
*muxer_port
=
1362 bt_component_filter_get_input_port_by_index(
1365 BT_ASSERT(muxer_port
);
1367 if (!bt_port_is_connected(muxer_port
)) {
1368 BT_MOVE(avail_muxer_port
, muxer_port
);
1375 graph_status
= bt_graph_connect_ports(graph
, source_port
,
1376 avail_muxer_port
, NULL
);
1377 BT_ASSERT(graph_status
== 0);
1378 bt_put(avail_muxer_port
);
1382 void graph_port_added_listener_connect_to_avail_muxer_port(struct bt_port
*port
,
1385 struct graph_listener_data
*graph_listener_data
= data
;
1386 struct bt_component
*comp
;
1388 comp
= bt_port_get_component(port
);
1391 if (comp
!= graph_listener_data
->source
) {
1395 connect_port_to_first_avail_muxer_port(graph_listener_data
->graph
,
1396 port
, graph_listener_data
->muxer
);
1403 void test_single_end_then_multiple_full(void)
1405 struct bt_component
*src_comp
;
1406 struct bt_component
*muxer_comp
;
1407 struct bt_component
*sink_comp
;
1408 struct bt_port
*upstream_port
;
1409 struct bt_port
*downstream_port
;
1413 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1414 struct graph_listener_data graph_listener_data
;
1415 const struct test_event expected_test_events
[] = {
1416 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1417 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1418 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1419 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1420 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1421 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1422 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1423 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1424 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1425 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1426 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1427 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1428 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1429 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1430 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1431 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1432 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1433 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1434 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1435 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1436 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1437 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1438 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1439 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1440 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1441 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1442 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1443 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1444 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1445 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1446 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1447 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1448 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1449 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1450 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1451 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1452 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1453 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1454 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1455 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1456 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1457 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1458 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1459 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1460 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1461 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1462 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1463 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1464 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1465 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1466 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1467 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1468 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1469 { .type
= TEST_EV_TYPE_END
, },
1470 { .type
= TEST_EV_TYPE_SENTINEL
, },
1473 clear_test_events();
1474 current_test
= TEST_SINGLE_END_THEN_MULTIPLE_FULL
;
1475 diag("test: single end then multiple full");
1477 graph
= bt_graph_create();
1479 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
1480 graph_listener_data
.graph
= graph
;
1481 graph_listener_data
.source
= src_comp
;
1482 graph_listener_data
.muxer
= muxer_comp
;
1483 graph_listener_data
.sink
= sink_comp
;
1484 ret
= bt_graph_add_port_added_listener(graph
,
1485 graph_port_added_listener_connect_to_avail_muxer_port
, NULL
,
1486 &graph_listener_data
);
1487 BT_ASSERT(ret
>= 0);
1489 /* Connect source output ports to muxer input ports */
1490 count
= bt_component_source_get_output_port_count(src_comp
);
1491 BT_ASSERT(ret
== 0);
1493 for (i
= 0; i
< count
; i
++) {
1494 upstream_port
= bt_component_source_get_output_port_by_index(
1496 BT_ASSERT(upstream_port
);
1497 connect_port_to_first_avail_muxer_port(graph
,
1498 upstream_port
, muxer_comp
);
1499 bt_put(upstream_port
);
1502 /* Connect muxer output port to sink input port */
1503 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1505 BT_ASSERT(upstream_port
);
1506 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1507 BT_ASSERT(downstream_port
);
1508 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1509 downstream_port
, NULL
);
1510 BT_ASSERT(graph_status
== 0);
1511 bt_put(upstream_port
);
1512 bt_put(downstream_port
);
1514 while (graph_status
== BT_GRAPH_STATUS_OK
||
1515 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1516 graph_status
= bt_graph_run(graph
);
1519 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1520 ok(compare_test_events(expected_test_events
),
1521 "the produced sequence of test events is the expected one");
1530 void test_single_again_end_then_multiple_full(void)
1532 struct bt_component
*src_comp
;
1533 struct bt_component
*muxer_comp
;
1534 struct bt_component
*sink_comp
;
1535 struct bt_port
*upstream_port
;
1536 struct bt_port
*downstream_port
;
1540 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1541 struct graph_listener_data graph_listener_data
;
1542 const struct test_event expected_test_events
[] = {
1543 { .type
= TEST_EV_TYPE_AGAIN
, },
1544 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1545 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1546 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1547 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1548 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1549 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1550 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1551 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1552 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1553 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1554 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1555 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1556 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1557 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1558 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1559 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1560 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1561 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1562 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1563 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1564 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1565 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1566 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1567 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1568 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1569 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1570 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1571 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1572 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1573 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1574 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1575 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1576 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1577 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1578 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1579 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1580 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1581 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1582 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1583 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1584 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1585 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1586 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1587 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1588 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1589 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1590 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1591 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1592 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1593 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1594 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1595 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1596 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1597 { .type
= TEST_EV_TYPE_END
, },
1598 { .type
= TEST_EV_TYPE_SENTINEL
, },
1601 clear_test_events();
1602 current_test
= TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
;
1603 diag("test: single again then end then multiple full");
1605 graph
= bt_graph_create();
1607 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
1608 graph_listener_data
.graph
= graph
;
1609 graph_listener_data
.source
= src_comp
;
1610 graph_listener_data
.muxer
= muxer_comp
;
1611 graph_listener_data
.sink
= sink_comp
;
1612 ret
= bt_graph_add_port_added_listener(graph
,
1613 graph_port_added_listener_connect_to_avail_muxer_port
, NULL
,
1614 &graph_listener_data
);
1615 BT_ASSERT(ret
>= 0);
1617 /* Connect source output ports to muxer input ports */
1618 count
= bt_component_source_get_output_port_count(src_comp
);
1619 BT_ASSERT(ret
== 0);
1621 for (i
= 0; i
< count
; i
++) {
1622 upstream_port
= bt_component_source_get_output_port_by_index(
1624 BT_ASSERT(upstream_port
);
1625 connect_port_to_first_avail_muxer_port(graph
,
1626 upstream_port
, muxer_comp
);
1627 bt_put(upstream_port
);
1630 /* Connect muxer output port to sink input port */
1631 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1633 BT_ASSERT(upstream_port
);
1634 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1635 BT_ASSERT(downstream_port
);
1636 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1637 downstream_port
, NULL
);
1638 BT_ASSERT(graph_status
== 0);
1639 bt_put(upstream_port
);
1640 bt_put(downstream_port
);
1642 while (graph_status
== BT_GRAPH_STATUS_OK
||
1643 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1644 graph_status
= bt_graph_run(graph
);
1647 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1648 ok(compare_test_events(expected_test_events
),
1649 "the produced sequence of test events is the expected one");
1657 #define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG"
1659 int main(int argc
, char **argv
)
1661 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
1665 plan_tests(NR_TESTS
);
1668 test_no_upstream_connection();
1669 test_simple_4_ports();
1670 test_4_ports_with_retries();
1671 test_single_end_then_multiple_full();
1672 test_single_again_end_then_multiple_full();
1674 return exit_status();