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/ctf-ir/event-class.h>
25 #include <babeltrace/ctf-ir/event.h>
26 #include <babeltrace/ctf-ir/field-types.h>
27 #include <babeltrace/ctf-ir/fields.h>
28 #include <babeltrace/ctf-ir/packet.h>
29 #include <babeltrace/ctf-ir/stream-class.h>
30 #include <babeltrace/ctf-ir/stream.h>
31 #include <babeltrace/ctf-ir/trace.h>
32 #include <babeltrace/graph/clock-class-priority-map.h>
33 #include <babeltrace/graph/component-class-filter.h>
34 #include <babeltrace/graph/component-class-sink.h>
35 #include <babeltrace/graph/component-class-source.h>
36 #include <babeltrace/graph/component-class.h>
37 #include <babeltrace/graph/component-filter.h>
38 #include <babeltrace/graph/component-sink.h>
39 #include <babeltrace/graph/component-source.h>
40 #include <babeltrace/graph/component.h>
41 #include <babeltrace/graph/graph.h>
42 #include <babeltrace/graph/notification-event.h>
43 #include <babeltrace/graph/notification-inactivity.h>
44 #include <babeltrace/graph/notification-iterator.h>
45 #include <babeltrace/graph/notification-packet.h>
46 #include <babeltrace/graph/port.h>
47 #include <babeltrace/graph/private-component-source.h>
48 #include <babeltrace/graph/private-component.h>
49 #include <babeltrace/graph/private-connection.h>
50 #include <babeltrace/graph/private-notification-iterator.h>
51 #include <babeltrace/graph/private-port.h>
52 #include <babeltrace/plugin/plugin.h>
53 #include <babeltrace/ref.h>
62 TEST_NO_UPSTREAM_CONNECTION
,
63 TEST_EVENT_NOTIF_VS_THE_REST
,
65 TEST_4_PORTS_WITH_RETRIES
,
66 TEST_SINGLE_END_THEN_MULTIPLE_FULL
,
67 TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
,
70 enum test_event_type
{
71 TEST_EV_TYPE_NOTIF_UNEXPECTED
,
72 TEST_EV_TYPE_NOTIF_EVENT
,
73 TEST_EV_TYPE_NOTIF_INACTIVITY
,
74 TEST_EV_TYPE_NOTIF_PACKET_BEGIN
,
75 TEST_EV_TYPE_NOTIF_PACKET_END
,
78 TEST_EV_TYPE_SENTINEL
,
82 enum test_event_type type
;
86 struct source_muxer_sink
{
87 struct bt_component
*source
;
88 struct bt_component
*muxer
;
89 struct bt_component
*sink
;
92 struct graph_listener_data
{
93 struct bt_graph
*graph
;
94 struct bt_component
*source
;
95 struct bt_component
*muxer
;
96 struct bt_component
*sink
;
99 static bool debug
= false;
100 static enum test current_test
;
101 static GArray
*test_events
;
102 static struct bt_clock_class_priority_map
*src_cc_prio_map
;
103 static struct bt_clock_class_priority_map
*src_empty_cc_prio_map
;
104 static struct bt_ctf_clock_class
*src_clock_class
;
105 static struct bt_ctf_stream_class
*src_stream_class
;
106 static struct bt_ctf_event_class
*src_event_class
;
107 static struct bt_ctf_packet
*src_packet
;
112 SEQ_PACKET_BEGIN
= -3,
116 struct src_iter_user_data
{
122 struct sink_user_data
{
123 struct bt_notification_iterator
*notif_iter
;
126 static int64_t seq1
[] = {
127 24, 53, 97, 105, 119, 210, 222, 240, 292, 317, 353, 407, 433,
128 473, 487, 504, 572, 615, 708, 766, 850, 852, 931, 951, 956, 996,
132 static int64_t seq2
[] = {
133 51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631,
134 644, 668, 714, 744, 750, 778, 790, 836, SEQ_END
,
137 static int64_t seq3
[] = {
138 8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, 678, 717,
139 731, 733, 788, 819, 820, 857, 892, 903, 944, 998, SEQ_END
,
142 static int64_t seq4
[] = {
143 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591, 605, 612,
144 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985, 999,
148 static int64_t seq1_with_again
[] = {
149 24, 53, 97, 105, 119, 210, SEQ_AGAIN
, SEQ_AGAIN
, 222, 240, 292,
150 317, 353, 407, 433, 473, 487, 504, 572, 615, 708, 766, 850, 852,
151 931, 951, 956, 996, SEQ_END
,
154 static int64_t seq2_with_again
[] = {
155 51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631,
156 644, 668, 714, 744, 750, 778, 790, 836, SEQ_AGAIN
, SEQ_AGAIN
,
160 static int64_t seq3_with_again
[] = {
161 8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, SEQ_AGAIN
,
162 SEQ_AGAIN
, 678, 717, 731, 733, 788, 819, 820, 857, 892, 903,
166 static int64_t seq4_with_again
[] = {
167 SEQ_AGAIN
, 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591,
168 605, 612, 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985,
172 static int64_t seq5
[] = {
173 1, 4, 189, 1001, SEQ_END
,
176 static int64_t seq6
[] = {
177 1, 2, 12, SEQ_PACKET_BEGIN
, 14, 19, SEQ_END
,
180 static int64_t seq7
[] = {
181 8, 9, SEQ_PACKET_BEGIN
, 10, 13, SEQ_PACKET_END
, 22, SEQ_END
,
185 void clear_test_events(void)
187 g_array_set_size(test_events
, 0);
191 void print_test_event(FILE *fp
, const struct test_event
*event
)
193 fprintf(fp
, "{ type = ");
195 switch (event
->type
) {
196 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
197 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
199 case TEST_EV_TYPE_NOTIF_EVENT
:
200 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
202 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
203 fprintf(fp
, "TEST_EV_TYPE_NOTIF_INACTIVITY");
205 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
206 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
208 case TEST_EV_TYPE_NOTIF_PACKET_END
:
209 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
211 case TEST_EV_TYPE_AGAIN
:
212 fprintf(fp
, "TEST_EV_TYPE_AGAIN");
214 case TEST_EV_TYPE_END
:
215 fprintf(fp
, "TEST_EV_TYPE_END");
217 case TEST_EV_TYPE_SENTINEL
:
218 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
221 fprintf(fp
, "(UNKNOWN)");
225 switch (event
->type
) {
226 case TEST_EV_TYPE_NOTIF_EVENT
:
227 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
228 fprintf(fp
, ", ts-ns = %" PRId64
, event
->ts_ns
);
237 void append_test_event(struct test_event
*event
)
239 g_array_append_val(test_events
, *event
);
243 bool compare_single_test_events(const struct test_event
*ev_a
,
244 const struct test_event
*ev_b
)
247 fprintf(stderr
, ":: Comparing test events: ");
248 print_test_event(stderr
, ev_a
);
249 fprintf(stderr
, " vs. ");
250 print_test_event(stderr
, ev_b
);
251 fprintf(stderr
, "\n");
254 if (ev_a
->type
!= ev_b
->type
) {
258 switch (ev_a
->type
) {
259 case TEST_EV_TYPE_NOTIF_EVENT
:
260 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
261 if (ev_a
->ts_ns
!= ev_b
->ts_ns
) {
273 bool compare_test_events(const struct test_event
*expected_events
)
275 const struct test_event
*expected_event
= expected_events
;
278 assert(expected_events
);
281 const struct test_event
*event
;
283 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
287 if (i
>= test_events
->len
) {
291 event
= &g_array_index(test_events
, struct test_event
, i
);
293 if (!compare_single_test_events(event
, expected_event
)) {
301 if (i
!= test_events
->len
) {
309 void init_static_data(void)
312 struct bt_ctf_trace
*trace
;
313 struct bt_ctf_stream
*stream
;
314 struct bt_ctf_field_type
*empty_struct_ft
;
317 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
321 empty_struct_ft
= bt_ctf_field_type_structure_create();
322 assert(empty_struct_ft
);
323 trace
= bt_ctf_trace_create();
325 ret
= bt_ctf_trace_set_native_byte_order(trace
,
326 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
);
328 ret
= bt_ctf_trace_set_packet_header_type(trace
, empty_struct_ft
);
330 src_clock_class
= bt_ctf_clock_class_create("my-clock");
331 assert(src_clock_class
);
332 ret
= bt_ctf_clock_class_set_is_absolute(src_clock_class
, 1);
334 ret
= bt_ctf_trace_add_clock_class(trace
, src_clock_class
);
336 src_empty_cc_prio_map
= bt_clock_class_priority_map_create();
337 assert(src_empty_cc_prio_map
);
338 src_cc_prio_map
= bt_clock_class_priority_map_create();
339 assert(src_cc_prio_map
);
340 ret
= bt_clock_class_priority_map_add_clock_class(src_cc_prio_map
,
343 src_stream_class
= bt_ctf_stream_class_create("my-stream-class");
344 assert(src_stream_class
);
345 ret
= bt_ctf_stream_class_set_packet_context_type(src_stream_class
,
348 ret
= bt_ctf_stream_class_set_event_header_type(src_stream_class
,
351 ret
= bt_ctf_stream_class_set_event_context_type(src_stream_class
,
354 src_event_class
= bt_ctf_event_class_create("my-event-class");
355 ret
= bt_ctf_event_class_set_context_type(src_event_class
,
358 ret
= bt_ctf_event_class_set_context_type(src_event_class
,
361 ret
= bt_ctf_stream_class_add_event_class(src_stream_class
,
364 ret
= bt_ctf_trace_add_stream_class(trace
, src_stream_class
);
366 stream
= bt_ctf_stream_create(src_stream_class
, "my-stream");
368 src_packet
= bt_ctf_packet_create(stream
);
373 bt_put(empty_struct_ft
);
377 void fini_static_data(void)
380 g_array_free(test_events
, TRUE
);
383 bt_put(src_empty_cc_prio_map
);
384 bt_put(src_cc_prio_map
);
385 bt_put(src_clock_class
);
386 bt_put(src_stream_class
);
387 bt_put(src_event_class
);
391 void src_iter_finalize(
392 struct bt_private_notification_iterator
*private_notification_iterator
)
394 struct src_iter_user_data
*user_data
=
395 bt_private_notification_iterator_get_user_data(
396 private_notification_iterator
);
404 enum bt_notification_iterator_status
src_iter_init(
405 struct bt_private_notification_iterator
*priv_notif_iter
,
406 struct bt_private_port
*private_port
)
408 struct src_iter_user_data
*user_data
=
409 g_new0(struct src_iter_user_data
, 1);
410 struct bt_port
*port
= bt_port_from_private_port(private_port
);
411 const char *port_name
;
416 ret
= bt_private_notification_iterator_set_user_data(priv_notif_iter
,
419 port_name
= bt_port_get_name(port
);
421 user_data
->iter_index
= port_name
[3] - '0';
424 switch (current_test
) {
426 if (user_data
->iter_index
== 1) {
427 user_data
->seq
= seq5
;
430 case TEST_EVENT_NOTIF_VS_THE_REST
:
431 if (user_data
->iter_index
== 0) {
432 user_data
->seq
= seq6
;
434 user_data
->seq
= seq7
;
437 case TEST_SIMPLE_4_PORTS
:
438 if (user_data
->iter_index
== 0) {
439 user_data
->seq
= seq1
;
440 } else if (user_data
->iter_index
== 1) {
441 user_data
->seq
= seq2
;
442 } else if (user_data
->iter_index
== 2) {
443 user_data
->seq
= seq3
;
445 user_data
->seq
= seq4
;
448 case TEST_4_PORTS_WITH_RETRIES
:
449 if (user_data
->iter_index
== 0) {
450 user_data
->seq
= seq1_with_again
;
451 } else if (user_data
->iter_index
== 1) {
452 user_data
->seq
= seq2_with_again
;
453 } else if (user_data
->iter_index
== 2) {
454 user_data
->seq
= seq3_with_again
;
456 user_data
->seq
= seq4_with_again
;
459 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
460 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
461 if (user_data
->iter_index
== 0) {
462 /* Ignore: this iterator only returns END */
463 } else if (user_data
->iter_index
== 1) {
464 user_data
->seq
= seq2
;
466 user_data
->seq
= seq3
;
473 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
477 struct bt_ctf_event
*src_create_event(int64_t ts_ns
)
479 struct bt_ctf_event
*event
= bt_ctf_event_create(src_event_class
);
483 ret
= bt_ctf_event_set_packet(event
, src_packet
);
487 struct bt_ctf_clock_value
*clock_value
;
489 clock_value
= bt_ctf_clock_value_create(src_clock_class
,
492 ret
= bt_ctf_event_set_clock_value(event
, clock_value
);
500 struct bt_notification_iterator_next_return
src_iter_next_seq(
501 struct src_iter_user_data
*user_data
)
503 struct bt_notification_iterator_next_return next_return
= {
504 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
508 assert(user_data
->seq
);
509 cur_ts_ns
= user_data
->seq
[user_data
->at
];
514 BT_NOTIFICATION_ITERATOR_STATUS_END
;
518 BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
520 case SEQ_PACKET_BEGIN
:
521 next_return
.notification
=
522 bt_notification_packet_begin_create(src_packet
);
523 assert(next_return
.notification
);
526 next_return
.notification
=
527 bt_notification_packet_end_create(src_packet
);
528 assert(next_return
.notification
);
532 struct bt_ctf_event
*event
= src_create_event(cur_ts_ns
);
535 next_return
.notification
= bt_notification_event_create(event
,
538 assert(next_return
.notification
);
543 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_END
) {
551 struct bt_notification_iterator_next_return
src_iter_next(
552 struct bt_private_notification_iterator
*priv_iterator
)
554 struct bt_notification_iterator_next_return next_return
= {
555 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
556 .notification
= NULL
,
558 struct src_iter_user_data
*user_data
=
559 bt_private_notification_iterator_get_user_data(priv_iterator
);
560 struct bt_private_component
*private_component
=
561 bt_private_notification_iterator_get_private_component(priv_iterator
);
564 assert(private_component
);
566 switch (current_test
) {
568 if (user_data
->iter_index
== 0) {
569 if (user_data
->at
== 0) {
570 next_return
.notification
=
571 bt_notification_packet_begin_create(src_packet
);
572 assert(next_return
.notification
);
573 } else if (user_data
->at
< 6) {
574 struct bt_ctf_event
*event
= src_create_event(-1);
577 next_return
.notification
=
578 bt_notification_event_create(event
,
579 src_empty_cc_prio_map
);
580 assert(next_return
.notification
);
584 BT_NOTIFICATION_ITERATOR_STATUS_END
;
589 next_return
= src_iter_next_seq(user_data
);
592 case TEST_EVENT_NOTIF_VS_THE_REST
:
593 case TEST_SIMPLE_4_PORTS
:
594 case TEST_4_PORTS_WITH_RETRIES
:
595 next_return
= src_iter_next_seq(user_data
);
597 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
598 if (user_data
->iter_index
== 0) {
599 struct bt_private_port
*priv_port
;
601 priv_port
= bt_private_component_source_add_output_private_port(
602 private_component
, "out1");
605 priv_port
= bt_private_component_source_add_output_private_port(
606 private_component
, "out2");
609 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
611 next_return
= src_iter_next_seq(user_data
);
614 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
615 if (user_data
->iter_index
== 0) {
616 if (user_data
->at
== 0) {
617 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
;
620 struct bt_private_port
*priv_port
;
622 priv_port
= bt_private_component_source_add_output_private_port(
623 private_component
, "out1");
626 priv_port
= bt_private_component_source_add_output_private_port(
627 private_component
, "out2");
630 next_return
.status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
633 next_return
= src_iter_next_seq(user_data
);
640 bt_put(private_component
);
645 enum bt_component_status
src_init(
646 struct bt_private_component
*private_component
,
647 struct bt_value
*params
, void *init_method_data
)
649 struct bt_private_port
*priv_port
;
653 priv_port
= bt_private_component_source_get_default_output_private_port(
656 ret
= bt_private_port_remove_from_component(priv_port
);
661 switch (current_test
) {
663 case TEST_EVENT_NOTIF_VS_THE_REST
:
666 case TEST_SINGLE_END_THEN_MULTIPLE_FULL
:
667 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
:
676 priv_port
= bt_private_component_source_add_output_private_port(
677 private_component
, "out0");
683 priv_port
= bt_private_component_source_add_output_private_port(
684 private_component
, "out1");
690 priv_port
= bt_private_component_source_add_output_private_port(
691 private_component
, "out2");
697 priv_port
= bt_private_component_source_add_output_private_port(
698 private_component
, "out3");
703 return BT_COMPONENT_STATUS_OK
;
707 void src_finalize(struct bt_private_component
*private_component
)
712 enum bt_component_status
sink_consume(
713 struct bt_private_component
*priv_component
)
715 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
716 struct bt_notification
*notification
= NULL
;
717 struct sink_user_data
*user_data
=
718 bt_private_component_get_user_data(priv_component
);
719 enum bt_notification_iterator_status it_ret
;
720 struct test_event test_event
;
721 bool do_append_test_event
= true;
723 assert(user_data
&& user_data
->notif_iter
);
724 it_ret
= bt_notification_iterator_next(user_data
->notif_iter
);
727 ret
= BT_COMPONENT_STATUS_ERROR
;
728 do_append_test_event
= false;
733 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
734 test_event
.type
= TEST_EV_TYPE_END
;
735 ret
= BT_COMPONENT_STATUS_END
;
736 BT_PUT(user_data
->notif_iter
);
738 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
739 test_event
.type
= TEST_EV_TYPE_AGAIN
;
740 ret
= BT_COMPONENT_STATUS_AGAIN
;
746 notification
= bt_notification_iterator_get_notification(
747 user_data
->notif_iter
);
748 assert(notification
);
750 switch (bt_notification_get_type(notification
)) {
751 case BT_NOTIFICATION_TYPE_EVENT
:
753 struct bt_ctf_event
*event
;
754 struct bt_clock_class_priority_map
*cc_prio_map
;
756 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
758 bt_notification_event_get_clock_class_priority_map(
761 event
= bt_notification_event_get_event(notification
);
764 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) > 0) {
765 struct bt_ctf_clock_value
*clock_value
;
766 struct bt_ctf_clock_class
*clock_class
=
767 bt_clock_class_priority_map_get_highest_priority_clock_class(
771 clock_value
= bt_ctf_event_get_clock_value(event
,
774 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(
775 clock_value
, &test_event
.ts_ns
);
780 test_event
.ts_ns
= -1;
787 case BT_NOTIFICATION_TYPE_INACTIVITY
:
789 struct bt_clock_class_priority_map
*cc_prio_map
;
791 test_event
.type
= TEST_EV_TYPE_NOTIF_INACTIVITY
;
792 cc_prio_map
= bt_notification_event_get_clock_class_priority_map(
796 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map
) > 0) {
797 struct bt_ctf_clock_value
*clock_value
;
798 struct bt_ctf_clock_class
*clock_class
=
799 bt_clock_class_priority_map_get_highest_priority_clock_class(
804 bt_notification_inactivity_get_clock_value(
805 notification
, clock_class
);
807 ret
= bt_ctf_clock_value_get_value_ns_from_epoch(
808 clock_value
, &test_event
.ts_ns
);
813 test_event
.ts_ns
= -1;
819 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
820 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
822 case BT_NOTIFICATION_TYPE_PACKET_END
:
823 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
826 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
831 if (do_append_test_event
) {
832 append_test_event(&test_event
);
835 bt_put(notification
);
840 void sink_port_connected(struct bt_private_component
*private_component
,
841 struct bt_private_port
*self_private_port
,
842 struct bt_port
*other_port
)
844 struct bt_private_connection
*priv_conn
=
845 bt_private_port_get_private_connection(self_private_port
);
846 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
851 user_data
->notif_iter
=
852 bt_private_connection_create_notification_iterator(priv_conn
);
853 assert(user_data
->notif_iter
);
858 enum bt_component_status
sink_init(
859 struct bt_private_component
*private_component
,
860 struct bt_value
*params
, void *init_method_data
)
862 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
866 ret
= bt_private_component_set_user_data(private_component
,
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_component
**source
,
886 struct bt_component
**muxer
,
887 struct bt_component
**sink
)
889 struct bt_component_class
*src_comp_class
;
890 struct bt_component_class
*muxer_comp_class
;
891 struct bt_component_class
*sink_comp_class
;
894 /* Create source component */
895 src_comp_class
= bt_component_class_source_create("src", src_iter_next
);
896 assert(src_comp_class
);
897 ret
= bt_component_class_set_init_method(src_comp_class
, src_init
);
899 ret
= bt_component_class_set_finalize_method(src_comp_class
,
902 ret
= bt_component_class_source_set_notification_iterator_init_method(
903 src_comp_class
, src_iter_init
);
905 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
906 src_comp_class
, src_iter_finalize
);
908 *source
= bt_component_create(src_comp_class
, "source", NULL
);
911 /* Create muxer component */
912 muxer_comp_class
= bt_plugin_find_component_class("utils", "muxer",
913 BT_COMPONENT_CLASS_TYPE_FILTER
);
914 assert(muxer_comp_class
);
915 *muxer
= bt_component_create(muxer_comp_class
, "muxer", NULL
);
918 /* Create sink component */
919 sink_comp_class
= bt_component_class_sink_create("sink", sink_consume
);
920 assert(sink_comp_class
);
921 ret
= bt_component_class_set_init_method(sink_comp_class
, sink_init
);
923 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
925 ret
= bt_component_class_set_port_connected_method(sink_comp_class
,
926 sink_port_connected
);
928 *sink
= bt_component_create(sink_comp_class
, "sink", NULL
);
930 bt_put(src_comp_class
);
931 bt_put(muxer_comp_class
);
932 bt_put(sink_comp_class
);
936 void do_std_test(enum test test
, const char *name
,
937 const struct test_event
*expected_test_events
,
940 struct bt_component
*src_comp
;
941 struct bt_component
*muxer_comp
;
942 struct bt_component
*sink_comp
;
943 struct bt_port
*upstream_port
;
944 struct bt_port
*downstream_port
;
945 struct bt_graph
*graph
;
950 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
954 diag("test: %s", name
);
955 create_source_muxer_sink(&src_comp
, &muxer_comp
, &sink_comp
);
956 graph
= bt_graph_create();
959 /* Connect source output ports to muxer input ports */
961 ret
= bt_component_source_get_output_port_count(src_comp
, &count
);
964 for (i
= 0; i
< count
; i
++) {
965 upstream_port
= bt_component_source_get_output_port_at_index(
967 assert(upstream_port
);
968 downstream_port
= bt_component_filter_get_input_port_at_index(
970 assert(downstream_port
);
971 conn
= bt_graph_connect_ports(graph
,
972 upstream_port
, downstream_port
);
975 bt_put(upstream_port
);
976 bt_put(downstream_port
);
980 /* Connect muxer output port to sink input port */
981 upstream_port
= bt_component_filter_get_output_port(muxer_comp
,
983 assert(upstream_port
);
984 downstream_port
= bt_component_sink_get_default_input_port(sink_comp
);
985 assert(downstream_port
);
986 conn
= bt_graph_connect_ports(graph
, upstream_port
, downstream_port
);
989 bt_put(upstream_port
);
990 bt_put(downstream_port
);
992 while (graph_status
== BT_GRAPH_STATUS_OK
||
993 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
994 graph_status
= bt_graph_run(graph
);
997 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
998 ok(compare_test_events(expected_test_events
),
999 "the produced sequence of test events is the expected one");
1008 void test_no_ts(void)
1010 const struct test_event expected_test_events
[] = {
1011 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1012 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
1013 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= -1, },
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
= 4, },
1019 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 189, },
1020 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1001, },
1021 { .type
= TEST_EV_TYPE_END
, },
1022 { .type
= TEST_EV_TYPE_SENTINEL
, },
1025 do_std_test(TEST_NO_TS
, "event notifications with no time",
1026 expected_test_events
, true);
1030 void test_no_upstream_connection(void)
1032 const struct test_event expected_test_events
[] = {
1033 { .type
= TEST_EV_TYPE_END
, },
1034 { .type
= TEST_EV_TYPE_SENTINEL
, },
1037 do_std_test(TEST_NO_UPSTREAM_CONNECTION
, "no upstream connection",
1038 expected_test_events
, false);
1042 void test_event_notif_vs_the_rest(void)
1044 const struct test_event expected_test_events
[] = {
1045 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 1, },
1046 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 2, },
1047 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8, },
1048 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 9, },
1049 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1050 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 10, },
1051 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 12, },
1052 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, },
1053 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 13, },
1054 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, },
1055 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 14, },
1056 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 19, },
1057 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 22, },
1058 { .type
= TEST_EV_TYPE_END
, },
1059 { .type
= TEST_EV_TYPE_SENTINEL
, },
1062 do_std_test(TEST_EVENT_NOTIF_VS_THE_REST
, "event notifications vs. the rest",
1063 expected_test_events
, true);
1068 void test_simple_4_ports(void)
1070 const struct test_event expected_test_events
[] = {
1071 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1072 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1073 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1074 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1075 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1076 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1077 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1078 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1079 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1080 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1081 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1082 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1083 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1084 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1085 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1086 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1087 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1088 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1089 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1090 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1091 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1092 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1093 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1094 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1095 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1096 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1097 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1098 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1099 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1100 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1101 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1102 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1103 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1104 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1105 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1106 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1107 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1108 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1109 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1110 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1111 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1112 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1113 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1114 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1115 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1116 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1117 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1118 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1119 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1120 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1121 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1122 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1123 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1124 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1125 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1126 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1127 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1128 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1129 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1130 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1131 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1132 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1133 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1134 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1135 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1136 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1137 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1138 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1139 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1140 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1141 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1142 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1143 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1144 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1145 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1146 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1147 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1148 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1149 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1150 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1151 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1152 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1153 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1154 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1155 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1156 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1157 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1158 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1159 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1160 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1161 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1162 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1163 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1164 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1165 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1166 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1167 { .type
= TEST_EV_TYPE_END
, },
1168 { .type
= TEST_EV_TYPE_SENTINEL
, },
1171 do_std_test(TEST_SIMPLE_4_PORTS
, "simple: 4 ports without retries",
1172 expected_test_events
, true);
1176 void test_4_ports_with_retries(void)
1178 const struct test_event expected_test_events
[] = {
1179 { .type
= TEST_EV_TYPE_AGAIN
, },
1180 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1181 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 24 },
1182 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 41 },
1183 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1184 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 53 },
1185 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 56 },
1186 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1187 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1188 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1189 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1190 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1191 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 97 },
1192 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 105 },
1193 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 119 },
1194 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 120 },
1195 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1196 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 138 },
1197 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1198 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 154 },
1199 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1200 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1201 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1202 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 210 },
1203 { .type
= TEST_EV_TYPE_AGAIN
, },
1204 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 222 },
1205 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 228 },
1206 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 240 },
1207 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1208 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1209 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 292 },
1210 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1211 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 317 },
1212 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1213 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1214 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1215 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 353 },
1216 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1217 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 407 },
1218 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1219 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 433 },
1220 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1221 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 471 },
1222 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 473 },
1223 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1224 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 479 },
1225 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 481 },
1226 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 487 },
1227 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 504 },
1228 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 525 },
1229 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 572 },
1230 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 591 },
1231 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 605 },
1232 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 612 },
1233 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 615 },
1234 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 618 },
1235 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1236 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1237 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 632 },
1238 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1239 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1240 { .type
= TEST_EV_TYPE_AGAIN
, },
1241 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1242 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 670 },
1243 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1244 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 696 },
1245 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 708 },
1246 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1247 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1248 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1249 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1250 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1251 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1252 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 766 },
1253 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1254 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1255 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1256 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1257 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1258 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 825 },
1259 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1260 { .type
= TEST_EV_TYPE_AGAIN
, },
1261 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 850 },
1262 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 852 },
1263 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1264 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 863 },
1265 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 867 },
1266 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 871 },
1267 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 884 },
1268 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1269 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1270 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 931 },
1271 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1272 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 951 },
1273 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 953 },
1274 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 956 },
1275 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 985 },
1276 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 996 },
1277 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1278 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 999 },
1279 { .type
= TEST_EV_TYPE_END
, },
1280 { .type
= TEST_EV_TYPE_SENTINEL
, },
1283 do_std_test(TEST_4_PORTS_WITH_RETRIES
, "4 ports with retries",
1284 expected_test_events
, true);
1288 void connect_port_to_first_avail_muxer_port(struct bt_graph
*graph
,
1289 struct bt_port
*source_port
,
1290 struct bt_component
*muxer_comp
)
1292 struct bt_port
*avail_muxer_port
= NULL
;
1298 ret
= bt_component_filter_get_input_port_count(muxer_comp
, &count
);
1301 for (i
= 0; i
< count
; i
++) {
1302 struct bt_port
*muxer_port
=
1303 bt_component_filter_get_input_port_at_index(
1308 if (!bt_port_is_connected(muxer_port
)) {
1309 BT_MOVE(avail_muxer_port
, muxer_port
);
1316 conn
= bt_graph_connect_ports(graph
, source_port
, avail_muxer_port
);
1319 bt_put(avail_muxer_port
);
1323 void graph_port_added_listener_connect_to_avail_muxer_port(struct bt_port
*port
,
1326 struct graph_listener_data
*graph_listener_data
= data
;
1327 struct bt_component
*comp
;
1329 comp
= bt_port_get_component(port
);
1332 if (comp
!= graph_listener_data
->source
) {
1336 connect_port_to_first_avail_muxer_port(graph_listener_data
->graph
,
1337 port
, graph_listener_data
->muxer
);
1344 void test_single_end_then_multiple_full(void)
1346 struct bt_component
*src_comp
;
1347 struct bt_component
*muxer_comp
;
1348 struct bt_component
*sink_comp
;
1349 struct bt_port
*upstream_port
;
1350 struct bt_port
*downstream_port
;
1351 struct bt_graph
*graph
;
1356 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1357 struct graph_listener_data graph_listener_data
;
1358 const struct test_event expected_test_events
[] = {
1359 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1360 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1361 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1362 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1363 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1364 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1365 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1366 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1367 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1368 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1369 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1370 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1371 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1372 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1373 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1374 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1375 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1376 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1377 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1378 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1379 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1380 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1381 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1382 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1383 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1384 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1385 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1386 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1387 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1388 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1389 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1390 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1391 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1392 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1393 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1394 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1395 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1396 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1397 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1398 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1399 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1400 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1401 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1402 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1403 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1404 { .type
= TEST_EV_TYPE_END
, },
1405 { .type
= TEST_EV_TYPE_SENTINEL
, },
1408 clear_test_events();
1409 current_test
= TEST_SINGLE_END_THEN_MULTIPLE_FULL
;
1410 diag("test: single end then multiple full");
1411 create_source_muxer_sink(&src_comp
, &muxer_comp
, &sink_comp
);
1412 graph
= bt_graph_create();
1414 graph_listener_data
.graph
= graph
;
1415 graph_listener_data
.source
= src_comp
;
1416 graph_listener_data
.muxer
= muxer_comp
;
1417 graph_listener_data
.sink
= sink_comp
;
1418 ret
= bt_graph_add_port_added_listener(graph
,
1419 graph_port_added_listener_connect_to_avail_muxer_port
,
1420 &graph_listener_data
);
1423 /* Connect source output ports to muxer input ports */
1424 ret
= bt_component_source_get_output_port_count(src_comp
, &count
);
1427 for (i
= 0; i
< count
; i
++) {
1428 upstream_port
= bt_component_source_get_output_port_at_index(
1430 assert(upstream_port
);
1431 connect_port_to_first_avail_muxer_port(graph
,
1432 upstream_port
, muxer_comp
);
1433 bt_put(upstream_port
);
1436 /* Connect muxer output port to sink input port */
1437 upstream_port
= bt_component_filter_get_output_port(muxer_comp
,
1439 assert(upstream_port
);
1440 downstream_port
= bt_component_sink_get_default_input_port(sink_comp
);
1441 assert(downstream_port
);
1442 conn
= bt_graph_connect_ports(graph
, upstream_port
, downstream_port
);
1445 bt_put(upstream_port
);
1446 bt_put(downstream_port
);
1448 while (graph_status
== BT_GRAPH_STATUS_OK
||
1449 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1450 graph_status
= bt_graph_run(graph
);
1453 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1454 ok(compare_test_events(expected_test_events
),
1455 "the produced sequence of test events is the expected one");
1464 void test_single_again_end_then_multiple_full(void)
1466 struct bt_component
*src_comp
;
1467 struct bt_component
*muxer_comp
;
1468 struct bt_component
*sink_comp
;
1469 struct bt_port
*upstream_port
;
1470 struct bt_port
*downstream_port
;
1471 struct bt_graph
*graph
;
1476 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
1477 struct graph_listener_data graph_listener_data
;
1478 const struct test_event expected_test_events
[] = {
1479 { .type
= TEST_EV_TYPE_AGAIN
, },
1480 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 8 },
1481 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 51 },
1482 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 59 },
1483 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 68 },
1484 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 71 },
1485 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 77 },
1486 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 91 },
1487 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 121 },
1488 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 139 },
1489 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 170 },
1490 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 179 },
1491 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 209 },
1492 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 254 },
1493 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 266 },
1494 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 298 },
1495 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 320 },
1496 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 350 },
1497 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 352 },
1498 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 393 },
1499 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 419 },
1500 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 454 },
1501 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 478 },
1502 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 624 },
1503 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 631 },
1504 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 644 },
1505 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 651 },
1506 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 668 },
1507 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 678 },
1508 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 714 },
1509 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 717 },
1510 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 731 },
1511 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 733 },
1512 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 744 },
1513 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 750 },
1514 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 778 },
1515 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 788 },
1516 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 790 },
1517 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 819 },
1518 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 820 },
1519 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 836 },
1520 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 857 },
1521 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 892 },
1522 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 903 },
1523 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 944 },
1524 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .ts_ns
= 998 },
1525 { .type
= TEST_EV_TYPE_END
, },
1526 { .type
= TEST_EV_TYPE_SENTINEL
, },
1529 clear_test_events();
1530 current_test
= TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL
;
1531 diag("test: single again then end then multiple full");
1532 create_source_muxer_sink(&src_comp
, &muxer_comp
, &sink_comp
);
1533 graph
= bt_graph_create();
1535 graph_listener_data
.graph
= graph
;
1536 graph_listener_data
.source
= src_comp
;
1537 graph_listener_data
.muxer
= muxer_comp
;
1538 graph_listener_data
.sink
= sink_comp
;
1539 ret
= bt_graph_add_port_added_listener(graph
,
1540 graph_port_added_listener_connect_to_avail_muxer_port
,
1541 &graph_listener_data
);
1544 /* Connect source output ports to muxer input ports */
1545 ret
= bt_component_source_get_output_port_count(src_comp
, &count
);
1548 for (i
= 0; i
< count
; i
++) {
1549 upstream_port
= bt_component_source_get_output_port_at_index(
1551 assert(upstream_port
);
1552 connect_port_to_first_avail_muxer_port(graph
,
1553 upstream_port
, muxer_comp
);
1554 bt_put(upstream_port
);
1557 /* Connect muxer output port to sink input port */
1558 upstream_port
= bt_component_filter_get_output_port(muxer_comp
,
1560 assert(upstream_port
);
1561 downstream_port
= bt_component_sink_get_default_input_port(sink_comp
);
1562 assert(downstream_port
);
1563 conn
= bt_graph_connect_ports(graph
, upstream_port
, downstream_port
);
1566 bt_put(upstream_port
);
1567 bt_put(downstream_port
);
1569 while (graph_status
== BT_GRAPH_STATUS_OK
||
1570 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
1571 graph_status
= bt_graph_run(graph
);
1574 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
1575 ok(compare_test_events(expected_test_events
),
1576 "the produced sequence of test events is the expected one");
1584 #define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG"
1586 int main(int argc
, char **argv
)
1588 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
1592 plan_tests(NR_TESTS
);
1595 test_no_upstream_connection();
1596 test_event_notif_vs_the_rest();
1597 test_simple_4_ports();
1598 test_4_ports_with_retries();
1599 test_single_end_then_multiple_full();
1600 test_single_again_end_then_multiple_full();
1602 return exit_status();