2 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; under version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <babeltrace/assert-internal.h>
25 #include <babeltrace/ctf-ir/event-class.h>
26 #include <babeltrace/ctf-ir/event.h>
27 #include <babeltrace/ctf-ir/field-types.h>
28 #include <babeltrace/ctf-ir/fields.h>
29 #include <babeltrace/ctf-ir/packet.h>
30 #include <babeltrace/ctf-ir/stream-class.h>
31 #include <babeltrace/ctf-ir/stream.h>
32 #include <babeltrace/ctf-ir/trace.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-sink.h>
38 #include <babeltrace/graph/component-source.h>
39 #include <babeltrace/graph/component.h>
40 #include <babeltrace/graph/connection.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/notification-stream.h>
47 #include <babeltrace/graph/output-port-notification-iterator.h>
48 #include <babeltrace/graph/port.h>
49 #include <babeltrace/graph/private-component-source.h>
50 #include <babeltrace/graph/private-component-sink.h>
51 #include <babeltrace/graph/private-component.h>
52 #include <babeltrace/graph/private-connection.h>
53 #include <babeltrace/graph/private-connection-notification-iterator.h>
54 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
55 #include <babeltrace/graph/private-port.h>
56 #include <babeltrace/plugin/plugin.h>
57 #include <babeltrace/ref.h>
66 TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
,
69 enum test_event_type
{
70 TEST_EV_TYPE_NOTIF_UNEXPECTED
,
71 TEST_EV_TYPE_NOTIF_EVENT
,
72 TEST_EV_TYPE_NOTIF_INACTIVITY
,
73 TEST_EV_TYPE_NOTIF_STREAM_BEGIN
,
74 TEST_EV_TYPE_NOTIF_PACKET_BEGIN
,
75 TEST_EV_TYPE_NOTIF_PACKET_END
,
76 TEST_EV_TYPE_NOTIF_STREAM_END
,
78 TEST_EV_TYPE_SENTINEL
,
82 enum test_event_type type
;
83 struct bt_stream
*stream
;
84 struct bt_packet
*packet
;
87 static bool debug
= false;
88 static enum test current_test
;
89 static GArray
*test_events
;
90 static struct bt_graph
*graph
;
91 static struct bt_stream_class
*src_stream_class
;
92 static struct bt_event_class
*src_event_class
;
93 static struct bt_stream
*src_stream1
;
94 static struct bt_stream
*src_stream2
;
95 static struct bt_packet
*src_stream1_packet1
;
96 static struct bt_packet
*src_stream1_packet2
;
97 static struct bt_packet
*src_stream2_packet1
;
98 static struct bt_packet
*src_stream2_packet2
;
102 SEQ_STREAM1_BEGIN
= -2,
103 SEQ_STREAM2_BEGIN
= -3,
104 SEQ_STREAM1_END
= -4,
105 SEQ_STREAM2_END
= -5,
106 SEQ_STREAM1_PACKET1_BEGIN
= -6,
107 SEQ_STREAM1_PACKET2_BEGIN
= -7,
108 SEQ_STREAM2_PACKET1_BEGIN
= -8,
109 SEQ_STREAM2_PACKET2_BEGIN
= -9,
110 SEQ_STREAM1_PACKET1_END
= -10,
111 SEQ_STREAM1_PACKET2_END
= -11,
112 SEQ_STREAM2_PACKET1_END
= -12,
113 SEQ_STREAM2_PACKET2_END
= -13,
114 SEQ_EVENT_STREAM1_PACKET1
= -14,
115 SEQ_EVENT_STREAM1_PACKET2
= -15,
116 SEQ_EVENT_STREAM2_PACKET1
= -16,
117 SEQ_EVENT_STREAM2_PACKET2
= -17,
118 SEQ_INACTIVITY
= -18,
121 struct src_iter_user_data
{
126 struct sink_user_data
{
127 struct bt_notification_iterator
*notif_iter
;
131 * No automatic notifications generated in this block.
132 * Stream 2 notifications are more indented.
134 static int64_t seq_no_auto_notifs
[] = {
136 SEQ_STREAM1_PACKET1_BEGIN
,
137 SEQ_EVENT_STREAM1_PACKET1
,
138 SEQ_EVENT_STREAM1_PACKET1
,
140 SEQ_EVENT_STREAM1_PACKET1
,
141 SEQ_STREAM2_PACKET2_BEGIN
,
142 SEQ_EVENT_STREAM2_PACKET2
,
143 SEQ_EVENT_STREAM1_PACKET1
,
144 SEQ_STREAM1_PACKET1_END
,
145 SEQ_STREAM2_PACKET2_END
,
146 SEQ_STREAM1_PACKET2_BEGIN
,
147 SEQ_EVENT_STREAM1_PACKET2
,
149 SEQ_STREAM1_PACKET2_END
,
155 void clear_test_events(void)
157 g_array_set_size(test_events
, 0);
161 void print_test_event(FILE *fp
, const struct test_event
*event
)
163 fprintf(fp
, "{ type = ");
165 switch (event
->type
) {
166 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
167 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
169 case TEST_EV_TYPE_NOTIF_EVENT
:
170 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
172 case TEST_EV_TYPE_NOTIF_INACTIVITY
:
173 fprintf(fp
, "TEST_EV_TYPE_NOTIF_INACTIVITY");
175 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
176 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
178 case TEST_EV_TYPE_NOTIF_STREAM_END
:
179 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
181 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
182 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
184 case TEST_EV_TYPE_NOTIF_PACKET_END
:
185 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
187 case TEST_EV_TYPE_END
:
188 fprintf(fp
, "TEST_EV_TYPE_END");
190 case TEST_EV_TYPE_SENTINEL
:
191 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
194 fprintf(fp
, "(UNKNOWN)");
198 fprintf(fp
, ", stream = %p, packet = %p }", event
->stream
,
203 void append_test_event(struct test_event
*event
)
205 g_array_append_val(test_events
, *event
);
209 bool compare_single_test_events(const struct test_event
*ev_a
,
210 const struct test_event
*ev_b
)
213 fprintf(stderr
, ":: Comparing test events: ");
214 print_test_event(stderr
, ev_a
);
215 fprintf(stderr
, " vs. ");
216 print_test_event(stderr
, ev_b
);
217 fprintf(stderr
, "\n");
220 if (ev_a
->type
!= ev_b
->type
) {
224 switch (ev_a
->type
) {
225 case TEST_EV_TYPE_END
:
226 case TEST_EV_TYPE_SENTINEL
:
229 if (ev_a
->stream
!= ev_b
->stream
) {
233 if (ev_a
->packet
!= ev_b
->packet
) {
243 bool compare_test_events(const struct test_event
*expected_events
)
245 const struct test_event
*expected_event
= expected_events
;
248 BT_ASSERT(expected_events
);
251 const struct test_event
*event
;
253 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
257 if (i
>= test_events
->len
) {
261 event
= &g_array_index(test_events
, struct test_event
, i
);
263 if (!compare_single_test_events(event
, expected_event
)) {
271 if (i
!= test_events
->len
) {
279 void init_static_data(void)
282 struct bt_trace
*trace
;
283 struct bt_field_type
*empty_struct_ft
;
286 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
287 BT_ASSERT(test_events
);
290 empty_struct_ft
= bt_field_type_structure_create();
291 BT_ASSERT(empty_struct_ft
);
292 trace
= bt_trace_create();
294 ret
= bt_trace_set_packet_header_field_type(trace
, empty_struct_ft
);
296 src_stream_class
= bt_stream_class_create("my-stream-class");
297 BT_ASSERT(src_stream_class
);
298 ret
= bt_stream_class_set_packet_context_field_type(src_stream_class
,
301 ret
= bt_stream_class_set_event_header_field_type(src_stream_class
,
304 ret
= bt_stream_class_set_event_context_field_type(src_stream_class
,
307 src_event_class
= bt_event_class_create("my-event-class");
308 ret
= bt_event_class_set_context_field_type(src_event_class
,
311 ret
= bt_event_class_set_payload_field_type(src_event_class
,
314 ret
= bt_stream_class_add_event_class(src_stream_class
,
317 ret
= bt_trace_add_stream_class(trace
, src_stream_class
);
319 src_stream1
= bt_stream_create(src_stream_class
, "stream-1", 0);
320 BT_ASSERT(src_stream1
);
321 src_stream2
= bt_stream_create(src_stream_class
, "stream-2", 1);
322 BT_ASSERT(src_stream2
);
323 src_stream1_packet1
= bt_packet_create(src_stream1
);
324 BT_ASSERT(src_stream1_packet1
);
325 src_stream1_packet2
= bt_packet_create(src_stream1
);
326 BT_ASSERT(src_stream1_packet2
);
327 src_stream2_packet1
= bt_packet_create(src_stream2
);
328 BT_ASSERT(src_stream2_packet1
);
329 src_stream2_packet2
= bt_packet_create(src_stream2
);
330 BT_ASSERT(src_stream2_packet2
);
333 fprintf(stderr
, ":: stream 1: %p\n", src_stream1
);
334 fprintf(stderr
, ":: stream 2: %p\n", src_stream2
);
335 fprintf(stderr
, ":: stream 1, packet 1: %p\n", src_stream1_packet1
);
336 fprintf(stderr
, ":: stream 1, packet 2: %p\n", src_stream1_packet2
);
337 fprintf(stderr
, ":: stream 2, packet 1: %p\n", src_stream2_packet1
);
338 fprintf(stderr
, ":: stream 2, packet 2: %p\n", src_stream2_packet2
);
342 bt_put(empty_struct_ft
);
346 void fini_static_data(void)
349 g_array_free(test_events
, TRUE
);
352 bt_put(src_stream_class
);
353 bt_put(src_event_class
);
356 bt_put(src_stream1_packet1
);
357 bt_put(src_stream1_packet2
);
358 bt_put(src_stream2_packet1
);
359 bt_put(src_stream2_packet2
);
363 void src_iter_finalize(
364 struct bt_private_connection_private_notification_iterator
*private_notification_iterator
)
366 struct src_iter_user_data
*user_data
=
367 bt_private_connection_private_notification_iterator_get_user_data(
368 private_notification_iterator
);
376 enum bt_notification_iterator_status
src_iter_init(
377 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
378 struct bt_private_port
*private_port
)
380 struct src_iter_user_data
*user_data
=
381 g_new0(struct src_iter_user_data
, 1);
384 BT_ASSERT(user_data
);
385 ret
= bt_private_connection_private_notification_iterator_set_user_data(
386 priv_notif_iter
, user_data
);
389 switch (current_test
) {
390 case TEST_NO_AUTO_NOTIFS
:
391 case TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
:
392 user_data
->seq
= seq_no_auto_notifs
;
398 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
402 void src_iter_next_seq_one(struct src_iter_user_data
*user_data
,
403 struct bt_notification
**notif
)
405 struct bt_packet
*event_packet
= NULL
;
407 switch (user_data
->seq
[user_data
->at
]) {
409 *notif
= bt_notification_inactivity_create(graph
);
411 case SEQ_STREAM1_BEGIN
:
412 *notif
= bt_notification_stream_begin_create(graph
,
415 case SEQ_STREAM2_BEGIN
:
416 *notif
= bt_notification_stream_begin_create(graph
,
419 case SEQ_STREAM1_END
:
420 *notif
= bt_notification_stream_end_create(graph
, src_stream1
);
422 case SEQ_STREAM2_END
:
423 *notif
= bt_notification_stream_end_create(graph
, src_stream2
);
425 case SEQ_STREAM1_PACKET1_BEGIN
:
426 *notif
= bt_notification_packet_begin_create(graph
,
427 src_stream1_packet1
);
429 case SEQ_STREAM1_PACKET2_BEGIN
:
430 *notif
= bt_notification_packet_begin_create(graph
,
431 src_stream1_packet2
);
433 case SEQ_STREAM2_PACKET1_BEGIN
:
434 *notif
= bt_notification_packet_begin_create(graph
,
435 src_stream2_packet1
);
437 case SEQ_STREAM2_PACKET2_BEGIN
:
438 *notif
= bt_notification_packet_begin_create(graph
,
439 src_stream2_packet2
);
441 case SEQ_STREAM1_PACKET1_END
:
442 *notif
= bt_notification_packet_end_create(graph
,
443 src_stream1_packet1
);
445 case SEQ_STREAM1_PACKET2_END
:
446 *notif
= bt_notification_packet_end_create(graph
,
447 src_stream1_packet2
);
449 case SEQ_STREAM2_PACKET1_END
:
450 *notif
= bt_notification_packet_end_create(graph
,
451 src_stream2_packet1
);
453 case SEQ_STREAM2_PACKET2_END
:
454 *notif
= bt_notification_packet_end_create(graph
,
455 src_stream2_packet2
);
457 case SEQ_EVENT_STREAM1_PACKET1
:
458 event_packet
= src_stream1_packet1
;
460 case SEQ_EVENT_STREAM1_PACKET2
:
461 event_packet
= src_stream1_packet2
;
463 case SEQ_EVENT_STREAM2_PACKET1
:
464 event_packet
= src_stream2_packet1
;
466 case SEQ_EVENT_STREAM2_PACKET2
:
467 event_packet
= src_stream2_packet2
;
474 *notif
= bt_notification_event_create(graph
, src_event_class
,
483 enum bt_notification_iterator_status
src_iter_next_seq(
484 struct src_iter_user_data
*user_data
,
485 bt_notification_array notifs
, uint64_t capacity
,
488 enum bt_notification_iterator_status status
=
489 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
492 BT_ASSERT(user_data
->seq
);
494 if (user_data
->seq
[user_data
->at
] == SEQ_END
) {
495 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
499 while (i
< capacity
&& user_data
->seq
[user_data
->at
] != SEQ_END
) {
500 src_iter_next_seq_one(user_data
, ¬ifs
[i
]);
504 BT_ASSERT(i
> 0 && i
<= capacity
);
512 enum bt_notification_iterator_status
src_iter_next(
513 struct bt_private_connection_private_notification_iterator
*priv_iterator
,
514 bt_notification_array notifs
, uint64_t capacity
,
517 struct src_iter_user_data
*user_data
=
518 bt_private_connection_private_notification_iterator_get_user_data(priv_iterator
);
520 BT_ASSERT(user_data
);
521 return src_iter_next_seq(user_data
, notifs
, capacity
, count
);
525 enum bt_component_status
src_init(
526 struct bt_private_component
*private_component
,
527 struct bt_value
*params
, void *init_method_data
)
531 ret
= bt_private_component_source_add_output_private_port(
532 private_component
, "out", NULL
, NULL
);
534 return BT_COMPONENT_STATUS_OK
;
538 void src_finalize(struct bt_private_component
*private_component
)
543 void append_test_events_from_notification(struct bt_notification
*notification
)
545 struct test_event test_event
= { 0 };
547 switch (bt_notification_get_type(notification
)) {
548 case BT_NOTIFICATION_TYPE_EVENT
:
550 struct bt_event
*event
;
552 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
553 event
= bt_notification_event_borrow_event(notification
);
555 test_event
.packet
= bt_event_borrow_packet(event
);
556 BT_ASSERT(test_event
.packet
);
559 case BT_NOTIFICATION_TYPE_INACTIVITY
:
560 test_event
.type
= TEST_EV_TYPE_NOTIF_INACTIVITY
;
562 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
563 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
565 bt_notification_stream_begin_borrow_stream(notification
);
566 BT_ASSERT(test_event
.stream
);
568 case BT_NOTIFICATION_TYPE_STREAM_END
:
569 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
571 bt_notification_stream_end_borrow_stream(notification
);
572 BT_ASSERT(test_event
.stream
);
574 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
575 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
577 bt_notification_packet_begin_borrow_packet(notification
);
578 BT_ASSERT(test_event
.packet
);
580 case BT_NOTIFICATION_TYPE_PACKET_END
:
581 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
583 bt_notification_packet_end_borrow_packet(notification
);
584 BT_ASSERT(test_event
.packet
);
587 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
591 if (test_event
.packet
) {
592 test_event
.stream
= bt_packet_borrow_stream(test_event
.packet
);
593 BT_ASSERT(test_event
.stream
);
596 append_test_event(&test_event
);
600 enum bt_notification_iterator_status
common_consume(
601 struct bt_notification_iterator
*notif_iter
,
602 bool is_output_port_notif_iter
)
604 enum bt_notification_iterator_status ret
;
605 bt_notification_array notifications
= NULL
;
607 struct test_event test_event
= { 0 };
610 BT_ASSERT(notif_iter
);
612 if (is_output_port_notif_iter
) {
613 ret
= bt_output_port_notification_iterator_next(notif_iter
,
614 ¬ifications
, &count
);
616 ret
= bt_private_connection_notification_iterator_next(
617 notif_iter
, ¬ifications
, &count
);
625 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
626 test_event
.type
= TEST_EV_TYPE_END
;
627 append_test_event(&test_event
);
629 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
635 BT_ASSERT(notifications
);
636 BT_ASSERT(count
> 0);
638 for (i
= 0; i
< count
; i
++) {
639 append_test_events_from_notification(notifications
[i
]);
640 bt_put(notifications
[i
]);
648 enum bt_component_status
sink_consume(
649 struct bt_private_component
*priv_component
)
651 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
652 struct sink_user_data
*user_data
=
653 bt_private_component_get_user_data(priv_component
);
654 enum bt_notification_iterator_status it_ret
;
656 BT_ASSERT(user_data
&& user_data
->notif_iter
);
657 it_ret
= common_consume(user_data
->notif_iter
, false);
660 ret
= BT_COMPONENT_STATUS_ERROR
;
665 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
666 ret
= BT_COMPONENT_STATUS_END
;
667 BT_PUT(user_data
->notif_iter
);
669 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
680 enum bt_component_status
sink_port_connected(
681 struct bt_private_component
*private_component
,
682 struct bt_private_port
*self_private_port
,
683 struct bt_port
*other_port
)
685 struct bt_private_connection
*priv_conn
=
686 bt_private_port_get_private_connection(self_private_port
);
687 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
689 enum bt_connection_status conn_status
;
691 BT_ASSERT(user_data
);
692 BT_ASSERT(priv_conn
);
693 conn_status
= bt_private_connection_create_notification_iterator(
694 priv_conn
, &user_data
->notif_iter
);
695 BT_ASSERT(conn_status
== 0);
697 return BT_COMPONENT_STATUS_OK
;
701 enum bt_component_status
sink_init(
702 struct bt_private_component
*private_component
,
703 struct bt_value
*params
, void *init_method_data
)
705 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
708 BT_ASSERT(user_data
);
709 ret
= bt_private_component_set_user_data(private_component
,
712 ret
= bt_private_component_sink_add_input_private_port(
713 private_component
, "in", NULL
, NULL
);
715 return BT_COMPONENT_STATUS_OK
;
719 void sink_finalize(struct bt_private_component
*private_component
)
721 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
725 bt_put(user_data
->notif_iter
);
731 void create_source_sink(struct bt_graph
*graph
, struct bt_component
**source
,
732 struct bt_component
**sink
)
734 struct bt_component_class
*src_comp_class
;
735 struct bt_component_class
*sink_comp_class
;
738 /* Create source component */
740 src_comp_class
= bt_component_class_source_create("src",
742 BT_ASSERT(src_comp_class
);
743 ret
= bt_component_class_set_init_method(src_comp_class
,
746 ret
= bt_component_class_set_finalize_method(src_comp_class
,
749 ret
= bt_component_class_source_set_notification_iterator_init_method(
750 src_comp_class
, src_iter_init
);
752 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
753 src_comp_class
, src_iter_finalize
);
755 ret
= bt_graph_add_component(graph
, src_comp_class
, "source",
758 bt_put(src_comp_class
);
761 /* Create sink component */
763 sink_comp_class
= bt_component_class_sink_create("sink",
765 BT_ASSERT(sink_comp_class
);
766 ret
= bt_component_class_set_init_method(sink_comp_class
,
769 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
771 ret
= bt_component_class_set_port_connected_method(
772 sink_comp_class
, sink_port_connected
);
774 ret
= bt_graph_add_component(graph
, sink_comp_class
, "sink",
777 bt_put(sink_comp_class
);
782 void do_std_test(enum test test
, const char *name
,
783 const struct test_event
*expected_test_events
)
785 struct bt_component
*src_comp
;
786 struct bt_component
*sink_comp
;
787 struct bt_port
*upstream_port
;
788 struct bt_port
*downstream_port
;
789 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
793 diag("test: %s", name
);
795 graph
= bt_graph_create();
797 create_source_sink(graph
, &src_comp
, &sink_comp
);
799 /* Connect source to sink */
800 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
801 BT_ASSERT(upstream_port
);
802 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
803 BT_ASSERT(downstream_port
);
804 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
805 downstream_port
, NULL
);
806 bt_put(upstream_port
);
807 bt_put(downstream_port
);
809 /* Run the graph until the end */
810 while (graph_status
== BT_GRAPH_STATUS_OK
||
811 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
812 graph_status
= bt_graph_run(graph
);
815 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
817 /* Compare the resulting test events */
818 if (expected_test_events
) {
819 ok(compare_test_events(expected_test_events
),
820 "the produced sequence of test events is the expected one");
829 void test_no_auto_notifs(void)
831 const struct test_event expected_test_events
[] = {
832 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
833 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
834 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
835 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
836 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
837 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
838 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
839 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
840 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
841 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
842 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
843 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
844 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
845 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
846 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
847 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
848 { .type
= TEST_EV_TYPE_END
, },
849 { .type
= TEST_EV_TYPE_SENTINEL
, },
852 do_std_test(TEST_NO_AUTO_NOTIFS
, "no automatic notifications",
853 expected_test_events
);
857 void test_output_port_notification_iterator(void)
859 const struct test_event expected_test_events
[] = {
860 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
861 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
862 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
863 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
864 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
865 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
866 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
867 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
868 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
869 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
870 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
871 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
872 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
873 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
874 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
875 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
876 { .type
= TEST_EV_TYPE_END
, },
877 { .type
= TEST_EV_TYPE_SENTINEL
, },
879 struct bt_component
*src_comp
;
880 struct bt_notification_iterator
*notif_iter
;
881 enum bt_notification_iterator_status iter_status
=
882 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
883 struct bt_port
*upstream_port
;
886 current_test
= TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
;
887 diag("test: output port notification iterator");
889 graph
= bt_graph_create();
891 create_source_sink(graph
, &src_comp
, NULL
);
893 /* Create notification iterator on source's output port */
894 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
895 notif_iter
= bt_output_port_notification_iterator_create(upstream_port
,
897 ok(notif_iter
, "bt_output_port_notification_iterator_create() succeeds");
898 bt_put(upstream_port
);
900 /* Consume the notification iterator */
901 while (iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
902 iter_status
= common_consume(notif_iter
, true);
905 ok(iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_END
,
906 "output port notification iterator finishes without any error");
908 /* Compare the resulting test events */
909 ok(compare_test_events(expected_test_events
),
910 "the produced sequence of test events is the expected one");
917 #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
919 int main(int argc
, char **argv
)
921 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
925 plan_tests(NR_TESTS
);
927 test_no_auto_notifs();
928 test_output_port_notification_iterator();
930 return exit_status();