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.
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_clock_class_priority_map
*src_cc_prio_map
;
76 static struct bt_clock_class_priority_map
*src_empty_cc_prio_map
;
77 static struct bt_clock_class
*src_clock_class
;
78 static struct bt_stream_class
*src_stream_class
;
79 static struct bt_event_class
*src_event_class
;
80 static struct bt_packet
*src_packet0
;
81 static struct bt_packet
*src_packet1
;
82 static struct bt_packet
*src_packet2
;
83 static struct bt_packet
*src_packet3
;
88 SEQ_PACKET_BEGIN
= -3,
92 struct src_iter_user_data
{
96 struct bt_packet
*packet
;
99 struct sink_user_data
{
100 struct bt_notification_iterator
*notif_iter
;
103 static int64_t seq1
[] = {
104 24, 53, 97, 105, 119, 210, 222, 240, 292, 317, 353, 407, 433,
105 473, 487, 504, 572, 615, 708, 766, 850, 852, 931, 951, 956, 996,
109 static int64_t seq2
[] = {
110 51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631,
111 644, 668, 714, 744, 750, 778, 790, 836, SEQ_END
,
114 static int64_t seq3
[] = {
115 8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, 678, 717,
116 731, 733, 788, 819, 820, 857, 892, 903, 944, 998, SEQ_END
,
119 static int64_t seq4
[] = {
120 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591, 605, 612,
121 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985, 999,
125 static int64_t seq1_with_again
[] = {
126 24, 53, 97, 105, 119, 210, SEQ_AGAIN
, 222, 240, 292, 317, 353,
127 407, 433, 473, 487, 504, 572, 615, 708, 766, 850, 852, 931, 951,
131 static int64_t seq2_with_again
[] = {
132 51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631,
133 644, 668, 714, 744, 750, 778, 790, 836, SEQ_AGAIN
, SEQ_END
,
136 static int64_t seq3_with_again
[] = {
137 8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, SEQ_AGAIN
,
138 678, 717, 731, 733, 788, 819, 820, 857, 892, 903, 944, 998,
142 static int64_t seq4_with_again
[] = {
143 SEQ_AGAIN
, 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591,
144 605, 612, 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985,
148 static int64_t seq5
[] = {
149 1, 4, 189, 1001, SEQ_END
,
153 void clear_test_events(void)
155 g_array_set_size(test_events
, 0);
159 void print_test_event(FILE *fp
, const struct test_event
*event
)
161 fprintf(fp
, "{ type = ");
163 switch (event
->type
) {
164 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
165 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
167 case TEST_EV_TYPE_NOTIF_EVENT
:
168 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
170 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
171 fprintf(fp
, "TEST_EV_TYPE_NOTIF_INACTIVITY");
173 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
174 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
176 case TEST_EV_TYPE_NOTIF_PACKET_END
:
177 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
179 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
180 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
182 case TEST_EV_TYPE_NOTIF_STREAM_END
:
183 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
185 case TEST_EV_TYPE_AGAIN
:
186 fprintf(fp
, "TEST_EV_TYPE_AGAIN");
188 case TEST_EV_TYPE_END
:
189 fprintf(fp
, "TEST_EV_TYPE_END");
191 case TEST_EV_TYPE_SENTINEL
:
192 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
195 fprintf(fp
, "(UNKNOWN)");
199 switch (event
->type
) {
200 case TEST_EV_TYPE_NOTIF_EVENT
:
201 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
202 fprintf(fp
, ", ts-ns = %" PRId64
, event
->ts_ns
);
211 void append_test_event(struct test_event
*event
)
213 g_array_append_val(test_events
, *event
);
217 bool compare_single_test_events(const struct test_event
*ev_a
,
218 const struct test_event
*ev_b
)
221 fprintf(stderr
, ":: Comparing test events: ");
222 print_test_event(stderr
, ev_a
);
223 fprintf(stderr
, " vs. ");
224 print_test_event(stderr
, ev_b
);
225 fprintf(stderr
, "\n");
228 if (ev_a
->type
!= ev_b
->type
) {
232 switch (ev_a
->type
) {
233 case TEST_EV_TYPE_NOTIF_EVENT
:
234 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
235 if (ev_a
->ts_ns
!= ev_b
->ts_ns
) {
247 bool compare_test_events(const struct test_event
*expected_events
)
249 const struct test_event
*expected_event
= expected_events
;
252 assert(expected_events
);
255 const struct test_event
*event
;
257 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
261 if (i
>= test_events
->len
) {
265 event
= &g_array_index(test_events
, struct test_event
, i
);
267 if (!compare_single_test_events(event
, expected_event
)) {
275 if (i
!= test_events
->len
) {
277 fprintf(stderr
, ":: Length mismatch\n");
287 void init_static_data(void)
290 struct bt_trace
*trace
;
291 struct bt_stream
*stream
;
292 struct bt_field_type
*empty_struct_ft
;
295 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
299 empty_struct_ft
= bt_field_type_structure_create();
300 assert(empty_struct_ft
);
301 trace
= bt_trace_create();
303 ret
= bt_trace_set_native_byte_order(trace
,
304 BT_BYTE_ORDER_LITTLE_ENDIAN
);
306 ret
= bt_trace_set_packet_header_type(trace
, empty_struct_ft
);
308 src_clock_class
= bt_clock_class_create("my-clock", 1000000000);
309 assert(src_clock_class
);
310 ret
= bt_clock_class_set_is_absolute(src_clock_class
, 1);
312 ret
= bt_trace_add_clock_class(trace
, src_clock_class
);
314 src_empty_cc_prio_map
= bt_clock_class_priority_map_create();
315 assert(src_empty_cc_prio_map
);
316 src_cc_prio_map
= bt_clock_class_priority_map_create();
317 assert(src_cc_prio_map
);
318 ret
= bt_clock_class_priority_map_add_clock_class(src_cc_prio_map
,
321 src_stream_class
= bt_stream_class_create("my-stream-class");
322 assert(src_stream_class
);
323 ret
= bt_stream_class_set_packet_context_type(src_stream_class
,
326 ret
= bt_stream_class_set_event_header_type(src_stream_class
,
329 ret
= bt_stream_class_set_event_context_type(src_stream_class
,
332 src_event_class
= bt_event_class_create("my-event-class");
333 ret
= bt_event_class_set_context_type(src_event_class
,
336 ret
= bt_event_class_set_context_type(src_event_class
,
339 ret
= bt_stream_class_add_event_class(src_stream_class
,
342 ret
= bt_trace_add_stream_class(trace
, src_stream_class
);
344 stream
= bt_stream_create(src_stream_class
, "stream0");
346 src_packet0
= bt_packet_create(stream
);
349 stream
= bt_stream_create(src_stream_class
, "stream1");
351 src_packet1
= bt_packet_create(stream
);
354 stream
= bt_stream_create(src_stream_class
, "stream2");
356 src_packet2
= bt_packet_create(stream
);
359 stream
= bt_stream_create(src_stream_class
, "stream3");
361 src_packet3
= bt_packet_create(stream
);
366 bt_put(empty_struct_ft
);
370 void fini_static_data(void)
373 g_array_free(test_events
, TRUE
);
376 bt_put(src_empty_cc_prio_map
);
377 bt_put(src_cc_prio_map
);
378 bt_put(src_clock_class
);
379 bt_put(src_stream_class
);
380 bt_put(src_event_class
);
388 void src_iter_finalize(
389 struct bt_private_connection_private_notification_iterator
*private_notification_iterator
)
391 struct src_iter_user_data
*user_data
=
392 bt_private_connection_private_notification_iterator_get_user_data(
393 private_notification_iterator
);
401 enum bt_notification_iterator_status
src_iter_init(
402 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
403 struct bt_private_port
*private_port
)
405 struct src_iter_user_data
*user_data
=
406 g_new0(struct src_iter_user_data
, 1);
407 struct bt_port
*port
= bt_port_from_private(private_port
);
408 const char *port_name
;
413 ret
= bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter
,
416 port_name
= bt_port_get_name(port
);
418 user_data
->iter_index
= port_name
[3] - '0';
421 switch (user_data
->iter_index
) {
423 user_data
->packet
= src_packet0
;
426 user_data
->packet
= src_packet1
;
429 user_data
->packet
= src_packet2
;
432 user_data
->packet
= src_packet3
;
438 switch (current_test
) {
440 if (user_data
->iter_index
== 1) {
441 user_data
->seq
= seq5
;
444 case TEST_SIMPLE_4_PORTS
:
445 if (user_data
->iter_index
== 0) {
446 user_data
->seq
= seq1
;
447 } else if (user_data
->iter_index
== 1) {
448 user_data
->seq
= seq2
;
449 } else if (user_data
->iter_index
== 2) {
450 user_data
->seq
= seq3
;
452 user_data
->seq
= seq4
;
455 case TEST_4_PORTS_WITH_RETRIES
:
456 if (user_data
->iter_index
== 0) {
457 user_data
->seq
= seq1_with_again
;
458 } else if (user_data
->iter_index
== 1) {
459 user_data
->seq
= seq2_with_again
;
460 } else if (user_data
->iter_index
== 2) {
461 user_data
->seq
= seq3_with_again
;
463 user_data
->seq
= seq4_with_again
;
466 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
467 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
468 if (user_data
->iter_index
== 0) {
469 /* Ignore: this iterator only returns END */
470 } else if (user_data
->iter_index
== 1) {
471 user_data
->seq
= seq2
;
473 user_data
->seq
= seq3
;
480 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
484 struct bt_event
*src_create_event(struct bt_packet
*packet
,
487 struct bt_event
*event
= bt_event_create(src_event_class
);
491 ret
= bt_event_set_packet(event
, packet
);
495 struct bt_clock_value
*clock_value
;
497 clock_value
= bt_clock_value_create(src_clock_class
,
500 ret
= bt_event_set_clock_value(event
, clock_value
);
509 struct bt_notification_iterator_next_method_return
src_iter_next_seq(
510 struct src_iter_user_data
*user_data
)
512 struct bt_notification_iterator_next_method_return next_return
= {
513 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
517 assert(user_data
->seq
);
518 cur_ts_ns
= user_data
->seq
[user_data
->at
];
523 BT_NOTIFICATION_ITERATOR_STATUS_END
;
527 BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
529 case SEQ_PACKET_BEGIN
:
530 next_return
.notification
=
531 bt_notification_packet_begin_create(user_data
->packet
);
532 assert(next_return
.notification
);
535 next_return
.notification
=
536 bt_notification_packet_end_create(user_data
->packet
);
537 assert(next_return
.notification
);
541 struct bt_event
*event
= src_create_event(
542 user_data
->packet
, cur_ts_ns
);
545 next_return
.notification
= bt_notification_event_create(event
,
548 assert(next_return
.notification
);
553 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_END
) {
561 struct bt_notification_iterator_next_method_return
src_iter_next(
562 struct bt_private_connection_private_notification_iterator
*priv_iterator
)
564 struct bt_notification_iterator_next_method_return next_return
= {
565 .notification
= NULL
,
566 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
568 struct src_iter_user_data
*user_data
=
569 bt_private_connection_private_notification_iterator_get_user_data(priv_iterator
);
570 struct bt_private_component
*private_component
=
571 bt_private_connection_private_notification_iterator_get_private_component(priv_iterator
);
575 assert(private_component
);
577 switch (current_test
) {
579 if (user_data
->iter_index
== 0) {
580 if (user_data
->at
== 0) {
581 next_return
.notification
=
582 bt_notification_packet_begin_create(
584 assert(next_return
.notification
);
585 } else if (user_data
->at
< 6) {
586 struct bt_event
*event
= src_create_event(
587 user_data
->packet
, -1);
590 next_return
.notification
=
591 bt_notification_event_create(event
,
592 src_empty_cc_prio_map
);
593 assert(next_return
.notification
);
597 BT_NOTIFICATION_ITERATOR_STATUS_END
;
602 next_return
= src_iter_next_seq(user_data
);
605 case TEST_SIMPLE_4_PORTS
:
606 case TEST_4_PORTS_WITH_RETRIES
:
607 next_return
= src_iter_next_seq(user_data
);
609 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
610 if (user_data
->iter_index
== 0) {
611 ret
= bt_private_component_source_add_output_private_port(
612 private_component
, "out1", NULL
, NULL
);
614 ret
= bt_private_component_source_add_output_private_port(
615 private_component
, "out2", NULL
, NULL
);
617 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
619 next_return
= src_iter_next_seq(user_data
);
622 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
623 if (user_data
->iter_index
== 0) {
624 if (user_data
->at
== 0) {
625 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
628 ret
= bt_private_component_source_add_output_private_port(
629 private_component
, "out1", NULL
, NULL
);
631 ret
= bt_private_component_source_add_output_private_port(
632 private_component
, "out2", NULL
, NULL
);
634 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
637 next_return
= src_iter_next_seq(user_data
);
644 bt_put(private_component
);
649 enum bt_component_status
src_init(
650 struct bt_private_component
*private_component
,
651 struct bt_value
*params
, void *init_method_data
)
656 switch (current_test
) {
660 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
661 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
670 ret
= bt_private_component_source_add_output_private_port(
671 private_component
, "out0", NULL
, NULL
);
676 ret
= bt_private_component_source_add_output_private_port(
677 private_component
, "out1", NULL
, NULL
);
682 ret
= bt_private_component_source_add_output_private_port(
683 private_component
, "out2", NULL
, NULL
);
688 ret
= bt_private_component_source_add_output_private_port(
689 private_component
, "out3", NULL
, NULL
);
693 return BT_COMPONENT_STATUS_OK
;
697 void src_finalize(struct bt_private_component
*private_component
)
702 enum bt_component_status
sink_consume(
703 struct bt_private_component
*priv_component
)
705 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
706 struct bt_notification
*notification
= NULL
;
707 struct sink_user_data
*user_data
=
708 bt_private_component_get_user_data(priv_component
);
709 enum bt_notification_iterator_status it_ret
;
710 struct test_event test_event
;
711 bool do_append_test_event
= true;
713 assert(user_data
&& user_data
->notif_iter
);
714 it_ret
= bt_notification_iterator_next(user_data
->notif_iter
);
717 ret
= BT_COMPONENT_STATUS_ERROR
;
718 do_append_test_event
= false;
723 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
724 test_event
.type
= TEST_EV_TYPE_END
;
725 ret
= BT_COMPONENT_STATUS_END
;
726 BT_PUT(user_data
->notif_iter
);
728 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
729 test_event
.type
= TEST_EV_TYPE_AGAIN
;
730 ret
= BT_COMPONENT_STATUS_AGAIN
;
736 notification
= bt_notification_iterator_get_notification(
737 user_data
->notif_iter
);
738 assert(notification
);
740 switch (bt_notification_get_type(notification
)) {
741 case BT_NOTIFICATION_TYPE_EVENT
:
743 struct bt_event
*event
;
744 struct bt_clock_class_priority_map
*cc_prio_map
;
746 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
748 bt_notification_event_get_clock_class_priority_map(
751 event
= bt_notification_event_get_event(notification
);
754 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) > 0) {
755 struct bt_clock_value
*clock_value
;
756 struct bt_clock_class
*clock_class
=
757 bt_clock_class_priority_map_get_highest_priority_clock_class(
761 clock_value
= bt_event_get_clock_value(event
,
764 ret
= bt_clock_value_get_value_ns_from_epoch(
765 clock_value
, &test_event
.ts_ns
);
770 test_event
.ts_ns
= -1;
777 case BT_NOTIFICATION_TYPE_INACTIVITY
:
779 struct bt_clock_class_priority_map
*cc_prio_map
;
781 test_event
.type
= TEST_EV_TYPE_NOTIF_INACTIVITY
;
782 cc_prio_map
= bt_notification_event_get_clock_class_priority_map(
786 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) > 0) {
787 struct bt_clock_value
*clock_value
;
788 struct bt_clock_class
*clock_class
=
789 bt_clock_class_priority_map_get_highest_priority_clock_class(
794 bt_notification_inactivity_get_clock_value(
795 notification
, clock_class
);
797 ret
= bt_clock_value_get_value_ns_from_epoch(
798 clock_value
, &test_event
.ts_ns
);
803 test_event
.ts_ns
= -1;
809 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
810 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
812 case BT_NOTIFICATION_TYPE_PACKET_END
:
813 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
815 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
816 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
818 case BT_NOTIFICATION_TYPE_STREAM_END
:
819 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
822 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
827 if (do_append_test_event
) {
828 append_test_event(&test_event
);
831 bt_put(notification
);
836 void sink_port_connected(struct bt_private_component
*private_component
,
837 struct bt_private_port
*self_private_port
,
838 struct bt_port
*other_port
)
840 struct bt_private_connection
*priv_conn
=
841 bt_private_port_get_private_connection(self_private_port
);
842 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
844 enum bt_connection_status conn_status
;
848 conn_status
= bt_private_connection_create_notification_iterator(
849 priv_conn
, NULL
, &user_data
->notif_iter
);
850 assert(conn_status
== 0);
855 enum bt_component_status
sink_init(
856 struct bt_private_component
*private_component
,
857 struct bt_value
*params
, void *init_method_data
)
859 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
863 ret
= bt_private_component_set_user_data(private_component
,
866 ret
= bt_private_component_sink_add_input_private_port(
867 private_component
, "in", NULL
, NULL
);
869 return BT_COMPONENT_STATUS_OK
;
873 void sink_finalize(struct bt_private_component
*private_component
)
875 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
879 bt_put(user_data
->notif_iter
);
885 void create_source_muxer_sink(struct bt_graph
*graph
,
886 struct bt_component
**source
,
887 struct bt_component
**muxer
,
888 struct bt_component
**sink
)
890 struct bt_component_class
*src_comp_class
;
891 struct bt_component_class
*muxer_comp_class
;
892 struct bt_component_class
*sink_comp_class
;
895 /* Create source component */
896 src_comp_class
= bt_component_class_source_create("src", src_iter_next
);
897 assert(src_comp_class
);
898 ret
= bt_component_class_set_init_method(src_comp_class
, src_init
);
900 ret
= bt_component_class_set_finalize_method(src_comp_class
,
903 ret
= bt_component_class_source_set_notification_iterator_init_method(
904 src_comp_class
, src_iter_init
);
906 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
907 src_comp_class
, src_iter_finalize
);
909 ret
= bt_graph_add_component(graph
, src_comp_class
, "source", NULL
, source
);
912 /* Create muxer component */
913 muxer_comp_class
= bt_plugin_find_component_class("utils", "muxer",
914 BT_COMPONENT_CLASS_TYPE_FILTER
);
915 assert(muxer_comp_class
);
916 ret
= bt_graph_add_component(graph
, muxer_comp_class
, "muxer", NULL
, muxer
);
919 /* Create sink component */
920 sink_comp_class
= bt_component_class_sink_create("sink", sink_consume
);
921 assert(sink_comp_class
);
922 ret
= bt_component_class_set_init_method(sink_comp_class
, sink_init
);
924 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
926 ret
= bt_component_class_set_port_connected_method(sink_comp_class
,
927 sink_port_connected
);
929 ret
= bt_graph_add_component(graph
, sink_comp_class
, "sink", NULL
, sink
);
932 bt_put(src_comp_class
);
933 bt_put(muxer_comp_class
);
934 bt_put(sink_comp_class
);
938 void do_std_test(enum test test
, const char *name
,
939 const struct test_event
*expected_test_events
,
942 struct bt_component
*src_comp
;
943 struct bt_component
*muxer_comp
;
944 struct bt_component
*sink_comp
;
945 struct bt_port
*upstream_port
;
946 struct bt_port
*downstream_port
;
947 struct bt_graph
*graph
;
950 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
954 diag("test: %s", name
);
955 graph
= bt_graph_create();
957 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
959 /* Connect source output ports to muxer input ports */
961 count
= bt_component_source_get_output_port_count(src_comp
);
964 for (i
= 0; i
< count
; i
++) {
965 upstream_port
= bt_component_source_get_output_port_by_index(
967 assert(upstream_port
);
968 downstream_port
= bt_component_filter_get_input_port_by_index(
970 assert(downstream_port
);
971 graph_status
= bt_graph_connect_ports(graph
,
972 upstream_port
, downstream_port
, NULL
);
973 assert(graph_status
== 0);
974 bt_put(upstream_port
);
975 bt_put(downstream_port
);
979 /* Connect muxer output port to sink input port */
980 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
982 assert(upstream_port
);
983 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
984 assert(downstream_port
);
985 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
986 downstream_port
, NULL
);
987 assert(graph_status
== 0);
988 bt_put(upstream_port
);
989 bt_put(downstream_port
);
991 while (graph_status
== BT_GRAPH_STATUS_OK
||
992 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
993 graph_status
= bt_graph_run(graph
);
996 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
997 ok(compare_test_events(expected_test_events
),
998 "the produced sequence of test events is the expected one");
1007 void test_no_ts(void)
1009 const struct test_event expected_test_events
[] = {
1010 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1011 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1012 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1013 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1014 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1015 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1016 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1017 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1018 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1019 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1020 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1021 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1, },
1022 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 4, },
1023 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 189, },
1024 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1001, },
1025 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1026 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1027 { .type
= TEST_EV_TYPE_END
, },
1028 { .type
= TEST_EV_TYPE_SENTINEL
, },
1031 do_std_test(TEST_NO_TS
, "event notifications with no time",
1032 expected_test_events
, true);
1036 void test_no_upstream_connection(void)
1038 const struct test_event expected_test_events
[] = {
1039 { .type
= TEST_EV_TYPE_END
, },
1040 { .type
= TEST_EV_TYPE_SENTINEL
, },
1043 do_std_test(TEST_NO_UPSTREAM_CONNECTION
, "no upstream connection",
1044 expected_test_events
, false);
1048 void test_simple_4_ports(void)
1050 const struct test_event expected_test_events
[] = {
1051 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1052 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1053 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1054 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1055 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1056 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1057 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1058 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1059 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1060 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1061 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1062 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1063 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1064 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1065 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1066 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1067 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1068 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1069 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1070 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1071 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1072 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1073 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1074 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1075 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1076 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1077 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1078 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1079 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1080 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1081 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1082 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1083 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1084 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1085 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1086 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1087 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1088 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1089 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1090 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1091 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1092 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1093 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1094 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1095 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1096 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1097 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1098 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1099 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1100 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1101 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1102 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1103 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1104 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1105 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1106 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1107 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1108 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1109 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1110 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1111 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1112 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1113 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1114 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1115 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1116 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1117 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1118 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1119 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1120 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1121 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1122 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1123 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1124 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1125 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1126 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1127 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1128 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1129 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1130 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1131 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1132 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1133 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1134 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1135 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1136 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1137 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1138 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1139 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1140 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1141 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1142 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1143 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1144 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1145 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1146 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1147 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1148 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1149 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1150 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1151 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1152 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1153 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1154 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1155 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1156 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1157 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1158 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1159 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1160 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1161 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1162 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1163 { .type
= TEST_EV_TYPE_END
, },
1164 { .type
= TEST_EV_TYPE_SENTINEL
, },
1167 do_std_test(TEST_SIMPLE_4_PORTS
, "simple: 4 ports without retries",
1168 expected_test_events
, true);
1172 void test_4_ports_with_retries(void)
1174 const struct test_event expected_test_events
[] = {
1175 { .type
= TEST_EV_TYPE_AGAIN
, },
1176 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1177 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1178 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1179 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1180 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1181 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1182 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1183 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1184 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1185 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1186 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1187 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1188 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1189 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1190 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1191 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1192 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1193 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1194 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1195 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1196 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1197 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1198 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1199 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1200 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1201 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1202 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1203 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1204 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1205 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1206 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1207 { .type
= TEST_EV_TYPE_AGAIN
, },
1208 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1209 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1210 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1211 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1212 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1213 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1214 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1215 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1216 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1217 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1218 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1219 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1220 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1221 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1222 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1223 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1224 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1225 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1226 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1227 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1228 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1229 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1230 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1231 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1232 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1233 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1234 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1235 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1236 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1237 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1238 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1239 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1240 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1241 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1242 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1243 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1244 { .type
= TEST_EV_TYPE_AGAIN
, },
1245 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1246 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1247 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1248 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1249 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1250 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1251 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1252 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1253 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1254 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1255 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1256 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1257 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1258 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1259 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1260 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1261 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1262 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1263 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1264 { .type
= TEST_EV_TYPE_AGAIN
, },
1265 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1266 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1267 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1268 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1269 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1270 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1271 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1272 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1273 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1274 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1275 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1276 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1277 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1278 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1279 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1280 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1281 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1282 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1283 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1284 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1285 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1286 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1287 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1288 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1289 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1290 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1291 { .type
= TEST_EV_TYPE_END
, },
1292 { .type
= TEST_EV_TYPE_SENTINEL
, },
1295 do_std_test(TEST_4_PORTS_WITH_RETRIES
, "4 ports with retries",
1296 expected_test_events
, true);
1300 void connect_port_to_first_avail_muxer_port(struct bt_graph
*graph
,
1301 struct bt_port
*source_port
,
1302 struct bt_component
*muxer_comp
)
1304 struct bt_port
*avail_muxer_port
= NULL
;
1307 enum bt_graph_status graph_status
;
1309 count
= bt_component_filter_get_input_port_count(muxer_comp
);
1312 for (i
= 0; i
< count
; i
++) {
1313 struct bt_port
*muxer_port
=
1314 bt_component_filter_get_input_port_by_index(
1319 if (!bt_port_is_connected(muxer_port
)) {
1320 BT_MOVE(avail_muxer_port
, muxer_port
);
1327 graph_status
= bt_graph_connect_ports(graph
, source_port
,
1328 avail_muxer_port
, NULL
);
1329 assert(graph_status
== 0);
1330 bt_put(avail_muxer_port
);
1334 void graph_port_added_listener_connect_to_avail_muxer_port(struct bt_port
*port
,
1337 struct graph_listener_data
*graph_listener_data
= data
;
1338 struct bt_component
*comp
;
1340 comp
= bt_port_get_component(port
);
1343 if (comp
!= graph_listener_data
->source
) {
1347 connect_port_to_first_avail_muxer_port(graph_listener_data
->graph
,
1348 port
, graph_listener_data
->muxer
);
1355 void test_single_end_then_multiple_full(void)
1357 struct bt_component
*src_comp
;
1358 struct bt_component
*muxer_comp
;
1359 struct bt_component
*sink_comp
;
1360 struct bt_port
*upstream_port
;
1361 struct bt_port
*downstream_port
;
1362 struct bt_graph
*graph
;
1366 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1367 struct graph_listener_data graph_listener_data
;
1368 const struct test_event expected_test_events
[] = {
1369 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1370 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1371 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1372 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1373 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1374 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1375 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1376 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1377 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1378 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1379 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1380 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1381 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1382 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1383 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1384 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1385 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1386 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1387 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1388 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1389 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1390 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1391 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1392 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1393 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1394 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1395 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1396 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1397 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1398 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1399 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1400 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1401 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1402 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1403 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1404 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1405 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1406 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1407 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1408 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1409 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1410 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1411 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1412 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1413 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1414 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1415 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1416 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1417 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1418 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1419 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1420 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1421 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1422 { .type
= TEST_EV_TYPE_END
, },
1423 { .type
= TEST_EV_TYPE_SENTINEL
, },
1426 clear_test_events();
1427 current_test
= TEST_SINGLE_END_THEN_MULTIPLE_FULL
;
1428 diag("test: single end then multiple full");
1429 graph
= bt_graph_create();
1431 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
1432 graph_listener_data
.graph
= graph
;
1433 graph_listener_data
.source
= src_comp
;
1434 graph_listener_data
.muxer
= muxer_comp
;
1435 graph_listener_data
.sink
= sink_comp
;
1436 ret
= bt_graph_add_port_added_listener(graph
,
1437 graph_port_added_listener_connect_to_avail_muxer_port
, NULL
,
1438 &graph_listener_data
);
1441 /* Connect source output ports to muxer input ports */
1442 count
= bt_component_source_get_output_port_count(src_comp
);
1445 for (i
= 0; i
< count
; i
++) {
1446 upstream_port
= bt_component_source_get_output_port_by_index(
1448 assert(upstream_port
);
1449 connect_port_to_first_avail_muxer_port(graph
,
1450 upstream_port
, muxer_comp
);
1451 bt_put(upstream_port
);
1454 /* Connect muxer output port to sink input port */
1455 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1457 assert(upstream_port
);
1458 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1459 assert(downstream_port
);
1460 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1461 downstream_port
, NULL
);
1462 assert(graph_status
== 0);
1463 bt_put(upstream_port
);
1464 bt_put(downstream_port
);
1466 while (graph_status
== BT_GRAPH_STATUS_OK
||
1467 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1468 graph_status
= bt_graph_run(graph
);
1471 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1472 ok(compare_test_events(expected_test_events
),
1473 "the produced sequence of test events is the expected one");
1482 void test_single_again_end_then_multiple_full(void)
1484 struct bt_component
*src_comp
;
1485 struct bt_component
*muxer_comp
;
1486 struct bt_component
*sink_comp
;
1487 struct bt_port
*upstream_port
;
1488 struct bt_port
*downstream_port
;
1489 struct bt_graph
*graph
;
1493 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1494 struct graph_listener_data graph_listener_data
;
1495 const struct test_event expected_test_events
[] = {
1496 { .type
= TEST_EV_TYPE_AGAIN
, },
1497 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1498 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1499 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, },
1500 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1501 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1502 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1503 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1504 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1505 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1506 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1507 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1508 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1509 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1510 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1511 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1512 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1513 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1514 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1515 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1516 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1517 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1518 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1519 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1520 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1521 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1522 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1523 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1524 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1525 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1526 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1527 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1528 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1529 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1530 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1531 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1532 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1533 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1534 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1535 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1536 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1537 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1538 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1539 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1540 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1541 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1542 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1543 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1544 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1545 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1546 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1547 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1548 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1549 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, },
1550 { .type
= TEST_EV_TYPE_END
, },
1551 { .type
= TEST_EV_TYPE_SENTINEL
, },
1554 clear_test_events();
1555 current_test
= TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
;
1556 diag("test: single again then end then multiple full");
1557 graph
= bt_graph_create();
1559 create_source_muxer_sink(graph
, &src_comp
, &muxer_comp
, &sink_comp
);
1560 graph_listener_data
.graph
= graph
;
1561 graph_listener_data
.source
= src_comp
;
1562 graph_listener_data
.muxer
= muxer_comp
;
1563 graph_listener_data
.sink
= sink_comp
;
1564 ret
= bt_graph_add_port_added_listener(graph
,
1565 graph_port_added_listener_connect_to_avail_muxer_port
, NULL
,
1566 &graph_listener_data
);
1569 /* Connect source output ports to muxer input ports */
1570 count
= bt_component_source_get_output_port_count(src_comp
);
1573 for (i
= 0; i
< count
; i
++) {
1574 upstream_port
= bt_component_source_get_output_port_by_index(
1576 assert(upstream_port
);
1577 connect_port_to_first_avail_muxer_port(graph
,
1578 upstream_port
, muxer_comp
);
1579 bt_put(upstream_port
);
1582 /* Connect muxer output port to sink input port */
1583 upstream_port
= bt_component_filter_get_output_port_by_name(muxer_comp
,
1585 assert(upstream_port
);
1586 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
1587 assert(downstream_port
);
1588 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
1589 downstream_port
, NULL
);
1590 assert(graph_status
== 0);
1591 bt_put(upstream_port
);
1592 bt_put(downstream_port
);
1594 while (graph_status
== BT_GRAPH_STATUS_OK
||
1595 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1596 graph_status
= bt_graph_run(graph
);
1599 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1600 ok(compare_test_events(expected_test_events
),
1601 "the produced sequence of test events is the expected one");
1609 #define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG"
1611 int main(int argc
, char **argv
)
1613 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
1617 plan_tests(NR_TESTS
);
1620 test_no_upstream_connection();
1621 test_simple_4_ports();
1622 test_4_ports_with_retries();
1623 test_single_end_then_multiple_full();
1624 test_single_again_end_then_multiple_full();
1626 return exit_status();