4 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <babeltrace2/babeltrace.h>
21 #include "common/assert.h"
32 SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION
,
33 SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION
,
34 SRC_COMP_OUTPUT_PORT_CONNECTED
,
35 SINK_COMP_INPUT_PORT_CONNECTED
,
36 GRAPH_SRC_OUTPUT_PORT_ADDED
,
37 GRAPH_SINK_INPUT_PORT_ADDED
,
38 GRAPH_SRC_SINK_PORTS_CONNECTED
,
44 TEST_SRC_PORT_CONNECTED_ERROR
,
45 TEST_SINK_PORT_CONNECTED_ERROR
,
46 TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED
,
54 const bt_component
*comp
;
55 const bt_port
*self_port
;
56 const bt_port
*other_port
;
57 } src_comp_accept_output_port_connection
;
60 const bt_component
*comp
;
61 const bt_port
*self_port
;
62 const bt_port
*other_port
;
63 } sink_comp_accept_input_port_connection
;
66 const bt_component
*comp
;
67 const bt_port
*self_port
;
68 const bt_port
*other_port
;
69 } src_comp_output_port_connected
;
72 const bt_component
*comp
;
73 const bt_port
*self_port
;
74 const bt_port
*other_port
;
75 } sink_comp_input_port_connected
;
78 const bt_component
*comp
;
80 } graph_src_output_port_added
;
83 const bt_component
*comp
;
85 } graph_sink_input_port_added
;
88 const bt_component
*upstream_comp
;
89 const bt_component
*downstream_comp
;
90 const bt_port
*upstream_port
;
91 const bt_port
*downstream_port
;
92 } graph_src_sink_ports_connected
;
96 static GArray
*events
;
97 static bt_component_class_source
*src_comp_class
;
98 static bt_component_class_sink
*sink_comp_class
;
99 static enum test current_test
;
102 void clear_events(void)
104 g_array_set_size(events
, 0);
108 void append_event(struct event
*event
)
110 g_array_append_val(events
, *event
);
114 bool compare_events(struct event
*ev_a
, struct event
*ev_b
)
116 if (ev_a
->type
!= ev_b
->type
) {
120 switch (ev_a
->type
) {
121 case SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION
:
122 if (ev_a
->data
.src_comp_accept_output_port_connection
.comp
!=
123 ev_b
->data
.src_comp_accept_output_port_connection
.comp
) {
127 if (ev_a
->data
.src_comp_accept_output_port_connection
.self_port
!=
128 ev_b
->data
.src_comp_accept_output_port_connection
.self_port
) {
132 if (ev_a
->data
.src_comp_accept_output_port_connection
.other_port
!=
133 ev_b
->data
.src_comp_accept_output_port_connection
.other_port
) {
137 case SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION
:
138 if (ev_a
->data
.sink_comp_accept_input_port_connection
.comp
!=
139 ev_b
->data
.sink_comp_accept_input_port_connection
.comp
) {
143 if (ev_a
->data
.sink_comp_accept_input_port_connection
.self_port
!=
144 ev_b
->data
.sink_comp_accept_input_port_connection
.self_port
) {
148 if (ev_a
->data
.sink_comp_accept_input_port_connection
.other_port
!=
149 ev_b
->data
.sink_comp_accept_input_port_connection
.other_port
) {
153 case SRC_COMP_OUTPUT_PORT_CONNECTED
:
154 if (ev_a
->data
.src_comp_output_port_connected
.comp
!=
155 ev_b
->data
.src_comp_output_port_connected
.comp
) {
159 if (ev_a
->data
.src_comp_output_port_connected
.self_port
!=
160 ev_b
->data
.src_comp_output_port_connected
.self_port
) {
164 if (ev_a
->data
.src_comp_output_port_connected
.other_port
!=
165 ev_b
->data
.src_comp_output_port_connected
.other_port
) {
169 case SINK_COMP_INPUT_PORT_CONNECTED
:
170 if (ev_a
->data
.sink_comp_input_port_connected
.comp
!=
171 ev_b
->data
.sink_comp_input_port_connected
.comp
) {
175 if (ev_a
->data
.sink_comp_input_port_connected
.self_port
!=
176 ev_b
->data
.sink_comp_input_port_connected
.self_port
) {
180 if (ev_a
->data
.sink_comp_input_port_connected
.other_port
!=
181 ev_b
->data
.sink_comp_input_port_connected
.other_port
) {
185 case GRAPH_SRC_OUTPUT_PORT_ADDED
:
186 if (ev_a
->data
.graph_src_output_port_added
.comp
!=
187 ev_b
->data
.graph_src_output_port_added
.comp
) {
191 if (ev_a
->data
.graph_src_output_port_added
.port
!=
192 ev_b
->data
.graph_src_output_port_added
.port
) {
196 case GRAPH_SINK_INPUT_PORT_ADDED
:
197 if (ev_a
->data
.graph_sink_input_port_added
.comp
!=
198 ev_b
->data
.graph_sink_input_port_added
.comp
) {
202 if (ev_a
->data
.graph_sink_input_port_added
.port
!=
203 ev_b
->data
.graph_sink_input_port_added
.port
) {
207 case GRAPH_SRC_SINK_PORTS_CONNECTED
:
208 if (ev_a
->data
.graph_src_sink_ports_connected
.upstream_comp
!=
209 ev_b
->data
.graph_src_sink_ports_connected
.upstream_comp
) {
213 if (ev_a
->data
.graph_src_sink_ports_connected
.downstream_comp
!=
214 ev_b
->data
.graph_src_sink_ports_connected
.downstream_comp
) {
218 if (ev_a
->data
.graph_src_sink_ports_connected
.upstream_port
!=
219 ev_b
->data
.graph_src_sink_ports_connected
.upstream_port
) {
223 if (ev_a
->data
.graph_src_sink_ports_connected
.downstream_port
!=
224 ev_b
->data
.graph_src_sink_ports_connected
.downstream_port
) {
236 bool has_event(struct event
*event
)
240 for (i
= 0; i
< events
->len
; i
++) {
241 struct event
*ev
= &g_array_index(events
, struct event
, i
);
243 if (compare_events(event
, ev
)) {
252 size_t event_pos(struct event
*event
)
256 for (i
= 0; i
< events
->len
; i
++) {
257 struct event
*ev
= &g_array_index(events
, struct event
, i
);
259 if (compare_events(event
, ev
)) {
268 bt_self_message_iterator_status
src_iter_next(
269 bt_self_message_iterator
*self_iterator
,
270 bt_message_array_const msgs
, uint64_t capacity
,
273 return BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR
;
277 bt_self_component_status
src_accept_output_port_connection(
278 bt_self_component_source
*self_comp
,
279 bt_self_component_port_output
*self_comp_port
,
280 const bt_port_input
*other_port
)
282 struct event event
= {
283 .type
= SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION
,
284 .data
.src_comp_accept_output_port_connection
= {
285 .comp
= bt_self_component_as_component(
286 bt_self_component_source_as_self_component(
288 .self_port
= bt_self_component_port_as_port(
289 bt_self_component_port_output_as_self_component_port(
291 .other_port
= bt_port_input_as_port_const(other_port
),
295 append_event(&event
);
296 return BT_SELF_COMPONENT_STATUS_OK
;
300 bt_self_component_status
sink_accept_input_port_connection(
301 bt_self_component_sink
*self_comp
,
302 bt_self_component_port_input
*self_comp_port
,
303 const bt_port_output
*other_port
)
305 struct event event
= {
306 .type
= SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION
,
307 .data
.sink_comp_accept_input_port_connection
= {
308 .comp
= bt_self_component_as_component(
309 bt_self_component_sink_as_self_component(
311 .self_port
= bt_self_component_port_as_port(
312 bt_self_component_port_input_as_self_component_port(
314 .other_port
= bt_port_output_as_port_const(other_port
),
318 append_event(&event
);
319 return BT_SELF_COMPONENT_STATUS_OK
;
323 bt_self_component_status
src_output_port_connected(
324 bt_self_component_source
*self_comp
,
325 bt_self_component_port_output
*self_comp_port
,
326 const bt_port_input
*other_port
)
329 struct event event
= {
330 .type
= SRC_COMP_OUTPUT_PORT_CONNECTED
,
331 .data
.src_comp_output_port_connected
= {
332 .comp
= bt_self_component_as_component(
333 bt_self_component_source_as_self_component(
335 .self_port
= bt_self_component_port_as_port(
336 bt_self_component_port_output_as_self_component_port(
338 .other_port
= bt_port_input_as_port_const(other_port
),
342 append_event(&event
);
344 switch (current_test
) {
345 case TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED
:
346 ret
= bt_self_component_source_add_output_port(
347 self_comp
, "hello", NULL
, NULL
);
350 case TEST_SRC_PORT_CONNECTED_ERROR
:
351 return BT_SELF_COMPONENT_STATUS_ERROR
;
356 return BT_SELF_COMPONENT_STATUS_OK
;
360 bt_self_component_status
sink_input_port_connected(
361 bt_self_component_sink
*self_comp
,
362 bt_self_component_port_input
*self_comp_port
,
363 const bt_port_output
*other_port
)
365 struct event event
= {
366 .type
= SINK_COMP_INPUT_PORT_CONNECTED
,
367 .data
.sink_comp_input_port_connected
= {
368 .comp
= bt_self_component_as_component(
369 bt_self_component_sink_as_self_component(
371 .self_port
= bt_self_component_port_as_port(
372 bt_self_component_port_input_as_self_component_port(
374 .other_port
= bt_port_output_as_port_const(other_port
),
378 append_event(&event
);
380 if (current_test
== TEST_SINK_PORT_CONNECTED_ERROR
) {
381 return BT_SELF_COMPONENT_STATUS_ERROR
;
383 return BT_SELF_COMPONENT_STATUS_OK
;
388 bt_self_component_status
src_init(
389 bt_self_component_source
*self_comp
,
390 const bt_value
*params
, void *init_method_data
)
394 ret
= bt_self_component_source_add_output_port(
395 self_comp
, "out", NULL
, NULL
);
397 return BT_SELF_COMPONENT_STATUS_OK
;
401 bt_self_component_status
sink_init(
402 bt_self_component_sink
*self_comp
,
403 const bt_value
*params
, void *init_method_data
)
407 ret
= bt_self_component_sink_add_input_port(self_comp
,
410 return BT_SELF_COMPONENT_STATUS_OK
;
414 bt_self_component_status
sink_consume(
415 bt_self_component_sink
*self_comp
)
417 return BT_SELF_COMPONENT_STATUS_OK
;
421 bt_graph_listener_status
graph_src_output_port_added(
422 const bt_component_source
*comp
, const bt_port_output
*port
,
425 struct event event
= {
426 .type
= GRAPH_SRC_OUTPUT_PORT_ADDED
,
427 .data
.graph_src_output_port_added
= {
428 .comp
= bt_component_source_as_component_const(comp
),
429 .port
= bt_port_output_as_port_const(port
),
433 append_event(&event
);
435 return BT_GRAPH_LISTENER_STATUS_OK
;
439 bt_graph_listener_status
graph_sink_input_port_added(
440 const bt_component_sink
*comp
, const bt_port_input
*port
,
443 struct event event
= {
444 .type
= GRAPH_SINK_INPUT_PORT_ADDED
,
445 .data
.graph_sink_input_port_added
= {
446 .comp
= bt_component_sink_as_component_const(comp
),
447 .port
= bt_port_input_as_port_const(port
),
451 append_event(&event
);
453 return BT_GRAPH_LISTENER_STATUS_OK
;
457 bt_graph_listener_status
graph_src_sink_ports_connected(
458 const bt_component_source
*upstream_comp
,
459 const bt_component_sink
*downstream_comp
,
460 const bt_port_output
*upstream_port
,
461 const bt_port_input
*downstream_port
, void *data
)
463 struct event event
= {
464 .type
= GRAPH_SRC_SINK_PORTS_CONNECTED
,
465 .data
.graph_src_sink_ports_connected
= {
467 bt_component_source_as_component_const(upstream_comp
),
469 bt_component_sink_as_component_const(downstream_comp
),
471 bt_port_output_as_port_const(upstream_port
),
473 bt_port_input_as_port_const(downstream_port
),
477 append_event(&event
);
479 return BT_GRAPH_LISTENER_STATUS_OK
;
487 src_comp_class
= bt_component_class_source_create(
488 "src", src_iter_next
);
489 BT_ASSERT(src_comp_class
);
490 ret
= bt_component_class_source_set_init_method(
491 src_comp_class
, src_init
);
493 ret
= bt_component_class_source_set_accept_output_port_connection_method(
494 src_comp_class
, src_accept_output_port_connection
);
496 ret
= bt_component_class_source_set_output_port_connected_method(
497 src_comp_class
, src_output_port_connected
);
499 sink_comp_class
= bt_component_class_sink_create("sink",
501 BT_ASSERT(sink_comp_class
);
502 ret
= bt_component_class_sink_set_init_method(sink_comp_class
,
505 ret
= bt_component_class_sink_set_accept_input_port_connection_method(
506 sink_comp_class
, sink_accept_input_port_connection
);
508 ret
= bt_component_class_sink_set_input_port_connected_method(
509 sink_comp_class
, sink_input_port_connected
);
511 events
= g_array_new(FALSE
, TRUE
, sizeof(struct event
));
518 bt_component_class_source_put_ref(src_comp_class
);
519 bt_component_class_sink_put_ref(sink_comp_class
);
520 g_array_free(events
, TRUE
);
524 const bt_component_source
*create_src(bt_graph
*graph
)
526 const bt_component_source
*comp
;
529 ret
= bt_graph_add_source_component(graph
, src_comp_class
,
530 "src-comp", NULL
, &comp
);
536 const bt_component_sink
*create_sink(bt_graph
*graph
)
538 const bt_component_sink
*comp
;
541 ret
= bt_graph_add_sink_component(graph
, sink_comp_class
,
542 "sink-comp", NULL
, &comp
);
548 bt_graph
*create_graph(void)
550 bt_graph
*graph
= bt_graph_create();
554 ret
= bt_graph_add_source_component_output_port_added_listener(
555 graph
, graph_src_output_port_added
, NULL
, NULL
, NULL
);
557 ret
= bt_graph_add_sink_component_input_port_added_listener(
558 graph
, graph_sink_input_port_added
, NULL
, NULL
, NULL
);
560 ret
= bt_graph_add_source_sink_component_ports_connected_listener(
561 graph
, graph_src_sink_ports_connected
, NULL
, NULL
, NULL
);
567 void prepare_test(enum test test
, const char *name
)
571 diag("test: %s", name
);
575 void test_src_adds_port_in_port_connected(void)
577 const bt_component_source
*src
;
578 const bt_component_sink
*sink
;
579 const bt_component
*gsrc
;
580 const bt_component
*gsink
;
582 const bt_port_output
*src_def_port
;
583 const bt_port_output
*src_hello_port
;
584 const bt_port_input
*sink_def_port
;
585 const bt_port
*gsrc_def_port
;
586 const bt_port
*gsrc_hello_port
;
587 const bt_port
*gsink_def_port
;
589 bt_graph_status status
;
590 size_t src_accept_port_connection_pos
;
591 size_t sink_accept_port_connection_pos
;
592 size_t src_port_connected_pos
;
593 size_t sink_port_connected_pos
;
594 size_t graph_ports_connected_pos
;
595 size_t graph_port_added_src_pos
;
597 prepare_test(TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED
,
598 "source adds port in port connected");
599 graph
= create_graph();
601 src
= create_src(graph
);
602 sink
= create_sink(graph
);
603 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
605 BT_ASSERT(src_def_port
);
606 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
608 BT_ASSERT(sink_def_port
);
609 status
= bt_graph_connect_ports(graph
, src_def_port
,
610 sink_def_port
, NULL
);
611 BT_ASSERT(status
== 0);
612 src_hello_port
= bt_component_source_borrow_output_port_by_name_const(src
,
614 BT_ASSERT(src_hello_port
);
615 gsrc
= bt_component_source_as_component_const(src
);
616 gsink
= bt_component_sink_as_component_const(sink
);
617 gsrc_def_port
= bt_port_output_as_port_const(src_def_port
);
618 gsrc_hello_port
= bt_port_output_as_port_const(src_hello_port
);
619 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
621 /* We're supposed to have 8 events */
622 ok(events
->len
== 8, "we have the expected number of events");
624 /* Source's port added */
625 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
626 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
627 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
628 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
630 /* Sink's port added */
631 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
632 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
633 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
634 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
636 /* Source's accept port connection */
637 event
.type
= SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION
;
638 event
.data
.src_comp_accept_output_port_connection
.comp
= gsrc
;
639 event
.data
.src_comp_accept_output_port_connection
.self_port
= gsrc_def_port
;
640 event
.data
.src_comp_accept_output_port_connection
.other_port
= gsink_def_port
;
641 ok(has_event(&event
), "got the expected source's accept port connection event");
642 src_accept_port_connection_pos
= event_pos(&event
);
644 /* Sink's accept port connection */
645 event
.type
= SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION
;
646 event
.data
.sink_comp_accept_input_port_connection
.comp
= gsink
;
647 event
.data
.sink_comp_accept_input_port_connection
.self_port
= gsink_def_port
;
648 event
.data
.sink_comp_accept_input_port_connection
.other_port
= gsrc_def_port
;
649 ok(has_event(&event
), "got the expected sink's accept port connection event");
650 sink_accept_port_connection_pos
= event_pos(&event
);
652 /* Source's port connected */
653 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
654 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
655 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
656 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
657 ok(has_event(&event
), "got the expected source's port connected event");
658 src_port_connected_pos
= event_pos(&event
);
660 /* Graph's port added (source) */
661 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
662 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
663 event
.data
.graph_src_output_port_added
.port
= gsrc_hello_port
;
664 ok(has_event(&event
), "got the expected graph's port added event (for source)");
665 graph_port_added_src_pos
= event_pos(&event
);
667 /* Sink's port connected */
668 event
.type
= SINK_COMP_INPUT_PORT_CONNECTED
;
669 event
.data
.sink_comp_input_port_connected
.comp
= gsink
;
670 event
.data
.sink_comp_input_port_connected
.self_port
= gsink_def_port
;
671 event
.data
.sink_comp_input_port_connected
.other_port
= gsrc_def_port
;
672 ok(has_event(&event
), "got the expected sink's port connected event");
673 sink_port_connected_pos
= event_pos(&event
);
675 /* Graph's ports connected */
676 event
.type
= GRAPH_SRC_SINK_PORTS_CONNECTED
;
677 event
.data
.graph_src_sink_ports_connected
.upstream_comp
= gsrc
;
678 event
.data
.graph_src_sink_ports_connected
.downstream_comp
= gsink
;
679 event
.data
.graph_src_sink_ports_connected
.upstream_port
= gsrc_def_port
;
680 event
.data
.graph_src_sink_ports_connected
.downstream_port
= gsink_def_port
;
681 ok(has_event(&event
), "got the expected graph's ports connected event");
682 graph_ports_connected_pos
= event_pos(&event
);
684 /* Order of events */
685 ok(src_port_connected_pos
< graph_ports_connected_pos
,
686 "event order is good (1)");
687 ok(sink_port_connected_pos
< graph_ports_connected_pos
,
688 "event order is good (2)");
689 ok(src_accept_port_connection_pos
< src_port_connected_pos
,
690 "event order is good (3)");
691 ok(sink_accept_port_connection_pos
< sink_port_connected_pos
,
692 "event order is good (4)");
693 ok(src_port_connected_pos
< graph_port_added_src_pos
,
694 "event order is good (5)");
695 ok(graph_port_added_src_pos
< graph_ports_connected_pos
,
696 "event order is good (6)");
698 bt_component_source_put_ref(src
);
699 bt_component_sink_put_ref(sink
);
700 bt_graph_put_ref(graph
);
704 void test_simple(void)
706 const bt_component_source
*src
;
707 const bt_component_sink
*sink
;
708 const bt_component
*gsrc
;
709 const bt_component
*gsink
;
711 const bt_port_output
*src_def_port
;
712 const bt_port_input
*sink_def_port
;
713 const bt_port
*gsrc_def_port
;
714 const bt_port
*gsink_def_port
;
716 bt_graph_status status
;
717 size_t src_accept_port_connection_pos
;
718 size_t sink_accept_port_connection_pos
;
719 size_t src_port_connected_pos
;
720 size_t sink_port_connected_pos
;
721 size_t graph_ports_connected_pos
;
723 prepare_test(TEST_SIMPLE
, "simple");
724 graph
= create_graph();
726 src
= create_src(graph
);
727 sink
= create_sink(graph
);
728 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
730 BT_ASSERT(src_def_port
);
731 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
733 BT_ASSERT(sink_def_port
);
734 status
= bt_graph_connect_ports(graph
, src_def_port
,
735 sink_def_port
, NULL
);
736 BT_ASSERT(status
== 0);
737 gsrc
= bt_component_source_as_component_const(src
);
738 gsink
= bt_component_sink_as_component_const(sink
);
739 gsrc_def_port
= bt_port_output_as_port_const(src_def_port
);
740 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
742 /* We're supposed to have 7 events */
743 ok(events
->len
== 7, "we have the expected number of events");
745 /* Source's port added */
746 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
747 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
748 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
749 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
751 /* Sink's port added */
752 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
753 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
754 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
755 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
757 /* Source's accept port connection */
758 event
.type
= SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION
;
759 event
.data
.src_comp_accept_output_port_connection
.comp
= gsrc
;
760 event
.data
.src_comp_accept_output_port_connection
.self_port
= gsrc_def_port
;
761 event
.data
.src_comp_accept_output_port_connection
.other_port
= gsink_def_port
;
762 ok(has_event(&event
), "got the expected source's accept port connection event");
763 src_accept_port_connection_pos
= event_pos(&event
);
765 /* Sink's accept port connection */
766 event
.type
= SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION
;
767 event
.data
.sink_comp_accept_input_port_connection
.comp
= gsink
;
768 event
.data
.sink_comp_accept_input_port_connection
.self_port
= gsink_def_port
;
769 event
.data
.sink_comp_accept_input_port_connection
.other_port
= gsrc_def_port
;
770 ok(has_event(&event
), "got the expected sink's accept port connection event");
771 sink_accept_port_connection_pos
= event_pos(&event
);
773 /* Source's port connected */
774 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
775 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
776 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
777 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
778 ok(has_event(&event
), "got the expected source's port connected event");
779 src_port_connected_pos
= event_pos(&event
);
781 /* Sink's port connected */
782 event
.type
= SINK_COMP_INPUT_PORT_CONNECTED
;
783 event
.data
.sink_comp_input_port_connected
.comp
= gsink
;
784 event
.data
.sink_comp_input_port_connected
.self_port
= gsink_def_port
;
785 event
.data
.sink_comp_input_port_connected
.other_port
= gsrc_def_port
;
786 ok(has_event(&event
), "got the expected sink's port connected event");
787 sink_port_connected_pos
= event_pos(&event
);
789 /* Graph's ports connected */
790 event
.type
= GRAPH_SRC_SINK_PORTS_CONNECTED
;
791 event
.data
.graph_src_sink_ports_connected
.upstream_comp
= gsrc
;
792 event
.data
.graph_src_sink_ports_connected
.downstream_comp
= gsink
;
793 event
.data
.graph_src_sink_ports_connected
.upstream_port
= gsrc_def_port
;
794 event
.data
.graph_src_sink_ports_connected
.downstream_port
= gsink_def_port
;
795 ok(has_event(&event
), "got the expected graph's ports connected event");
796 graph_ports_connected_pos
= event_pos(&event
);
798 /* Order of events */
799 ok(src_port_connected_pos
< graph_ports_connected_pos
,
800 "event order is good (1)");
801 ok(sink_port_connected_pos
< graph_ports_connected_pos
,
802 "event order is good (2)");
803 ok(src_accept_port_connection_pos
< src_port_connected_pos
,
804 "event order is good (3)");
805 ok(sink_accept_port_connection_pos
< sink_port_connected_pos
,
806 "event order is good (4)");
808 bt_component_sink_put_ref(sink
);
809 bt_graph_put_ref(graph
);
810 bt_component_source_put_ref(src
);
814 void test_src_port_connected_error(void)
816 const bt_component_source
*src
;
817 const bt_component_sink
*sink
;
818 const bt_component
*gsrc
;
819 const bt_component
*gsink
;
821 const bt_port_output
*src_def_port
;
822 const bt_port_input
*sink_def_port
;
823 const bt_port
*gsrc_def_port
;
824 const bt_port
*gsink_def_port
;
825 const bt_connection
*conn
= NULL
;
827 bt_graph_status status
;
828 size_t src_accept_port_connection_pos
;
829 size_t src_port_connected_pos
;
831 prepare_test(TEST_SRC_PORT_CONNECTED_ERROR
, "port connected error: source");
832 graph
= create_graph();
834 src
= create_src(graph
);
835 sink
= create_sink(graph
);
836 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
838 BT_ASSERT(src_def_port
);
839 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
841 BT_ASSERT(sink_def_port
);
842 status
= bt_graph_connect_ports(graph
, src_def_port
,
843 sink_def_port
, &conn
);
844 ok(status
!= BT_GRAPH_STATUS_OK
,
845 "bt_graph_connect_ports() returns an error");
846 ok(!conn
, "returned connection is still NULL");
847 gsrc
= bt_component_source_as_component_const(src
);
848 gsink
= bt_component_sink_as_component_const(sink
);
849 gsrc_def_port
= bt_port_output_as_port_const(src_def_port
);
850 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
852 /* We're supposed to have 5 events */
853 ok(events
->len
== 5, "we have the expected number of events");
855 /* Source's port added */
856 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
857 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
858 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
859 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
861 /* Sink's port added */
862 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
863 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
864 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
865 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
867 /* Source's accept port connection */
868 event
.type
= SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION
;
869 event
.data
.src_comp_accept_output_port_connection
.comp
= gsrc
;
870 event
.data
.src_comp_accept_output_port_connection
.self_port
= gsrc_def_port
;
871 event
.data
.src_comp_accept_output_port_connection
.other_port
= gsink_def_port
;
872 ok(has_event(&event
), "got the expected source's accept port connection event");
873 src_accept_port_connection_pos
= event_pos(&event
);
875 /* Sink's accept port connection */
876 event
.type
= SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION
;
877 event
.data
.sink_comp_accept_input_port_connection
.comp
= gsink
;
878 event
.data
.sink_comp_accept_input_port_connection
.self_port
= gsink_def_port
;
879 event
.data
.sink_comp_accept_input_port_connection
.other_port
= gsrc_def_port
;
880 ok(has_event(&event
), "got the expected sink's accept port connection event");
882 /* Source's port connected */
883 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
884 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
885 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
886 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
887 ok(has_event(&event
), "got the expected source's port connected event");
888 src_port_connected_pos
= event_pos(&event
);
890 /* Order of events */
891 ok(src_accept_port_connection_pos
< src_port_connected_pos
,
892 "event order is good (1)");
894 bt_graph_put_ref(graph
);
895 bt_component_sink_put_ref(sink
);
896 bt_component_source_put_ref(src
);
897 bt_connection_put_ref(conn
);
901 void test_sink_port_connected_error(void)
903 const bt_component_source
*src
;
904 const bt_component_sink
*sink
;
905 const bt_component
*gsrc
;
906 const bt_component
*gsink
;
908 const bt_port_output
*src_def_port
;
909 const bt_port_input
*sink_def_port
;
910 const bt_port
*gsrc_def_port
;
911 const bt_port
*gsink_def_port
;
912 const bt_connection
*conn
= NULL
;
914 bt_graph_status status
;
915 size_t src_accept_port_connection_pos
;
916 size_t sink_accept_port_connection_pos
;
917 size_t src_port_connected_pos
;
918 size_t sink_port_connected_pos
;
920 prepare_test(TEST_SINK_PORT_CONNECTED_ERROR
, "port connected error: sink");
921 graph
= create_graph();
923 src
= create_src(graph
);
924 sink
= create_sink(graph
);
925 src_def_port
= bt_component_source_borrow_output_port_by_name_const(src
,
927 BT_ASSERT(src_def_port
);
928 sink_def_port
= bt_component_sink_borrow_input_port_by_name_const(sink
,
930 BT_ASSERT(sink_def_port
);
931 status
= bt_graph_connect_ports(graph
, src_def_port
,
932 sink_def_port
, &conn
);
933 ok(status
!= BT_GRAPH_STATUS_OK
,
934 "bt_graph_connect_ports() returns an error");
935 ok(!conn
, "returned connection is still NULL");
936 gsrc
= bt_component_source_as_component_const(src
);
937 gsink
= bt_component_sink_as_component_const(sink
);
938 gsrc_def_port
= bt_port_output_as_port_const(src_def_port
);
939 gsink_def_port
= bt_port_input_as_port_const(sink_def_port
);
941 /* We're supposed to have 6 events */
942 ok(events
->len
== 6, "we have the expected number of events");
944 /* Source's port added */
945 event
.type
= GRAPH_SRC_OUTPUT_PORT_ADDED
;
946 event
.data
.graph_src_output_port_added
.comp
= gsrc
;
947 event
.data
.graph_src_output_port_added
.port
= gsrc_def_port
;
948 ok(has_event(&event
), "got the expected graph's port added event (for source, initial)");
950 /* Sink's port added */
951 event
.type
= GRAPH_SINK_INPUT_PORT_ADDED
;
952 event
.data
.graph_sink_input_port_added
.comp
= gsink
;
953 event
.data
.graph_sink_input_port_added
.port
= gsink_def_port
;
954 ok(has_event(&event
), "got the expected graph's port added event (for sink, initial)");
956 /* Source's accept port connection */
957 event
.type
= SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION
;
958 event
.data
.src_comp_accept_output_port_connection
.comp
= gsrc
;
959 event
.data
.src_comp_accept_output_port_connection
.self_port
= gsrc_def_port
;
960 event
.data
.src_comp_accept_output_port_connection
.other_port
= gsink_def_port
;
961 ok(has_event(&event
), "got the expected source's accept port connection event");
962 src_accept_port_connection_pos
= event_pos(&event
);
964 /* Sink's accept port connection */
965 event
.type
= SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION
;
966 event
.data
.sink_comp_accept_input_port_connection
.comp
= gsink
;
967 event
.data
.sink_comp_accept_input_port_connection
.self_port
= gsink_def_port
;
968 event
.data
.sink_comp_accept_input_port_connection
.other_port
= gsrc_def_port
;
969 ok(has_event(&event
), "got the expected sink's accept port connection event");
970 sink_accept_port_connection_pos
= event_pos(&event
);
972 /* Source's port connected */
973 event
.type
= SRC_COMP_OUTPUT_PORT_CONNECTED
;
974 event
.data
.src_comp_output_port_connected
.comp
= gsrc
;
975 event
.data
.src_comp_output_port_connected
.self_port
= gsrc_def_port
;
976 event
.data
.src_comp_output_port_connected
.other_port
= gsink_def_port
;
977 ok(has_event(&event
), "got the expected source's port connected event");
978 src_port_connected_pos
= event_pos(&event
);
980 /* Sink's port connected */
981 event
.type
= SINK_COMP_INPUT_PORT_CONNECTED
;
982 event
.data
.sink_comp_input_port_connected
.comp
= gsink
;
983 event
.data
.sink_comp_input_port_connected
.self_port
= gsink_def_port
;
984 event
.data
.sink_comp_input_port_connected
.other_port
= gsrc_def_port
;
985 ok(has_event(&event
), "got the expected sink's port connected event");
986 sink_port_connected_pos
= event_pos(&event
);
988 /* Order of events */
989 ok(src_accept_port_connection_pos
< src_port_connected_pos
,
990 "event order is good (1)");
991 ok(sink_accept_port_connection_pos
< sink_port_connected_pos
,
992 "event order is good (2)");
994 bt_connection_put_ref(conn
);
995 bt_graph_put_ref(graph
);
996 bt_component_sink_put_ref(sink
);
997 bt_component_source_put_ref(src
);
1001 void test_empty_graph(void)
1005 prepare_test(TEST_EMPTY_GRAPH
, "empty graph");
1006 graph
= create_graph();
1007 ok(events
->len
== 0, "empty graph generates no events");
1008 bt_graph_put_ref(graph
);
1011 int main(int argc
, char **argv
)
1013 plan_tests(NR_TESTS
);
1017 test_src_port_connected_error();
1018 test_sink_port_connected_error();
1019 test_src_adds_port_in_port_connected();
1021 return exit_status();