2 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; under version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <babeltrace/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/clock-class-priority-map.h>
34 #include <babeltrace/graph/component-class-filter.h>
35 #include <babeltrace/graph/component-class-sink.h>
36 #include <babeltrace/graph/component-class-source.h>
37 #include <babeltrace/graph/component-class.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/connection.h>
42 #include <babeltrace/graph/graph.h>
43 #include <babeltrace/graph/notification-event.h>
44 #include <babeltrace/graph/notification-inactivity.h>
45 #include <babeltrace/graph/notification-iterator.h>
46 #include <babeltrace/graph/notification-packet.h>
47 #include <babeltrace/graph/notification-stream.h>
48 #include <babeltrace/graph/output-port-notification-iterator.h>
49 #include <babeltrace/graph/port.h>
50 #include <babeltrace/graph/private-component-source.h>
51 #include <babeltrace/graph/private-component-sink.h>
52 #include <babeltrace/graph/private-component.h>
53 #include <babeltrace/graph/private-connection.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_clock_class_priority_map
*src_empty_cc_prio_map
;
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 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
));
290 empty_struct_ft
= bt_field_type_structure_create();
291 assert(empty_struct_ft
);
292 trace
= bt_trace_create();
294 ret
= bt_trace_set_packet_header_field_type(trace
, empty_struct_ft
);
296 src_empty_cc_prio_map
= bt_clock_class_priority_map_create();
297 assert(src_empty_cc_prio_map
);
298 src_stream_class
= bt_stream_class_create("my-stream-class");
299 assert(src_stream_class
);
300 ret
= bt_stream_class_set_packet_context_field_type(src_stream_class
,
303 ret
= bt_stream_class_set_event_header_field_type(src_stream_class
,
306 ret
= bt_stream_class_set_event_context_field_type(src_stream_class
,
309 src_event_class
= bt_event_class_create("my-event-class");
310 ret
= bt_event_class_set_context_field_type(src_event_class
,
313 ret
= bt_event_class_set_payload_field_type(src_event_class
,
316 ret
= bt_stream_class_add_event_class(src_stream_class
,
319 ret
= bt_trace_add_stream_class(trace
, src_stream_class
);
321 src_stream1
= bt_stream_create(src_stream_class
, "stream-1", 0);
323 src_stream2
= bt_stream_create(src_stream_class
, "stream-2", 1);
325 src_stream1_packet1
= bt_packet_create(src_stream1
);
326 assert(src_stream1_packet1
);
327 src_stream1_packet2
= bt_packet_create(src_stream1
);
328 assert(src_stream1_packet2
);
329 src_stream2_packet1
= bt_packet_create(src_stream2
);
330 assert(src_stream2_packet1
);
331 src_stream2_packet2
= bt_packet_create(src_stream2
);
332 assert(src_stream2_packet2
);
335 fprintf(stderr
, ":: stream 1: %p\n", src_stream1
);
336 fprintf(stderr
, ":: stream 2: %p\n", src_stream2
);
337 fprintf(stderr
, ":: stream 1, packet 1: %p\n", src_stream1_packet1
);
338 fprintf(stderr
, ":: stream 1, packet 2: %p\n", src_stream1_packet2
);
339 fprintf(stderr
, ":: stream 2, packet 1: %p\n", src_stream2_packet1
);
340 fprintf(stderr
, ":: stream 2, packet 2: %p\n", src_stream2_packet2
);
344 bt_put(empty_struct_ft
);
348 void fini_static_data(void)
351 g_array_free(test_events
, TRUE
);
354 bt_put(src_empty_cc_prio_map
);
355 bt_put(src_stream_class
);
356 bt_put(src_event_class
);
359 bt_put(src_stream1_packet1
);
360 bt_put(src_stream1_packet2
);
361 bt_put(src_stream2_packet1
);
362 bt_put(src_stream2_packet2
);
366 void src_iter_finalize(
367 struct bt_private_connection_private_notification_iterator
*private_notification_iterator
)
369 struct src_iter_user_data
*user_data
=
370 bt_private_connection_private_notification_iterator_get_user_data(
371 private_notification_iterator
);
379 enum bt_notification_iterator_status
src_iter_init(
380 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
381 struct bt_private_port
*private_port
)
383 struct src_iter_user_data
*user_data
=
384 g_new0(struct src_iter_user_data
, 1);
388 ret
= bt_private_connection_private_notification_iterator_set_user_data(
389 priv_notif_iter
, user_data
);
392 switch (current_test
) {
393 case TEST_NO_AUTO_NOTIFS
:
394 case TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
:
395 user_data
->seq
= seq_no_auto_notifs
;
401 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
405 struct bt_notification_iterator_next_method_return
src_iter_next_seq(
406 struct src_iter_user_data
*user_data
)
408 struct bt_notification_iterator_next_method_return next_return
= {
409 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
412 struct bt_packet
*event_packet
= NULL
;
414 assert(user_data
->seq
);
415 cur_ts_ns
= user_data
->seq
[user_data
->at
];
420 BT_NOTIFICATION_ITERATOR_STATUS_END
;
423 next_return
.notification
=
424 bt_notification_inactivity_create(src_empty_cc_prio_map
);
425 assert(next_return
.notification
);
427 case SEQ_STREAM1_BEGIN
:
428 next_return
.notification
=
429 bt_notification_stream_begin_create(src_stream1
);
430 assert(next_return
.notification
);
432 case SEQ_STREAM2_BEGIN
:
433 next_return
.notification
=
434 bt_notification_stream_begin_create(src_stream2
);
435 assert(next_return
.notification
);
437 case SEQ_STREAM1_END
:
438 next_return
.notification
=
439 bt_notification_stream_end_create(src_stream1
);
440 assert(next_return
.notification
);
442 case SEQ_STREAM2_END
:
443 next_return
.notification
=
444 bt_notification_stream_end_create(src_stream2
);
445 assert(next_return
.notification
);
447 case SEQ_STREAM1_PACKET1_BEGIN
:
448 next_return
.notification
=
449 bt_notification_packet_begin_create(src_stream1_packet1
);
450 assert(next_return
.notification
);
452 case SEQ_STREAM1_PACKET2_BEGIN
:
453 next_return
.notification
=
454 bt_notification_packet_begin_create(src_stream1_packet2
);
455 assert(next_return
.notification
);
457 case SEQ_STREAM2_PACKET1_BEGIN
:
458 next_return
.notification
=
459 bt_notification_packet_begin_create(src_stream2_packet1
);
460 assert(next_return
.notification
);
462 case SEQ_STREAM2_PACKET2_BEGIN
:
463 next_return
.notification
=
464 bt_notification_packet_begin_create(src_stream2_packet2
);
465 assert(next_return
.notification
);
467 case SEQ_STREAM1_PACKET1_END
:
468 next_return
.notification
=
469 bt_notification_packet_end_create(src_stream1_packet1
);
470 assert(next_return
.notification
);
472 case SEQ_STREAM1_PACKET2_END
:
473 next_return
.notification
=
474 bt_notification_packet_end_create(src_stream1_packet2
);
475 assert(next_return
.notification
);
477 case SEQ_STREAM2_PACKET1_END
:
478 next_return
.notification
=
479 bt_notification_packet_end_create(src_stream2_packet1
);
480 assert(next_return
.notification
);
482 case SEQ_STREAM2_PACKET2_END
:
483 next_return
.notification
=
484 bt_notification_packet_end_create(src_stream2_packet2
);
485 assert(next_return
.notification
);
487 case SEQ_EVENT_STREAM1_PACKET1
:
488 event_packet
= src_stream1_packet1
;
490 case SEQ_EVENT_STREAM1_PACKET2
:
491 event_packet
= src_stream1_packet2
;
493 case SEQ_EVENT_STREAM2_PACKET1
:
494 event_packet
= src_stream2_packet1
;
496 case SEQ_EVENT_STREAM2_PACKET2
:
497 event_packet
= src_stream2_packet2
;
504 next_return
.notification
=
505 bt_notification_event_create(src_event_class
,
507 src_empty_cc_prio_map
);
508 assert(next_return
.notification
);
511 if (next_return
.status
!= BT_NOTIFICATION_ITERATOR_STATUS_END
) {
519 struct bt_notification_iterator_next_method_return
src_iter_next(
520 struct bt_private_connection_private_notification_iterator
*priv_iterator
)
522 struct bt_notification_iterator_next_method_return next_return
= {
523 .status
= BT_NOTIFICATION_ITERATOR_STATUS_OK
,
524 .notification
= NULL
,
526 struct src_iter_user_data
*user_data
=
527 bt_private_connection_private_notification_iterator_get_user_data(priv_iterator
);
530 next_return
= src_iter_next_seq(user_data
);
535 enum bt_component_status
src_init(
536 struct bt_private_component
*private_component
,
537 struct bt_value
*params
, void *init_method_data
)
541 ret
= bt_private_component_source_add_output_private_port(
542 private_component
, "out", NULL
, NULL
);
544 return BT_COMPONENT_STATUS_OK
;
548 void src_finalize(struct bt_private_component
*private_component
)
553 enum bt_notification_iterator_status
common_consume(
554 struct bt_notification_iterator
*notif_iter
)
556 enum bt_notification_iterator_status ret
;
557 struct bt_notification
*notification
= NULL
;
558 struct test_event test_event
= { 0 };
559 bool do_append_test_event
= true;
562 ret
= bt_notification_iterator_next(notif_iter
);
564 do_append_test_event
= false;
569 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
570 test_event
.type
= TEST_EV_TYPE_END
;
572 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
578 notification
= bt_notification_iterator_get_notification(
580 assert(notification
);
582 switch (bt_notification_get_type(notification
)) {
583 case BT_NOTIFICATION_TYPE_EVENT
:
585 struct bt_event
*event
;
587 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
588 event
= bt_notification_event_borrow_event(notification
);
590 test_event
.packet
= bt_event_borrow_packet(event
);
591 assert(test_event
.packet
);
594 case BT_NOTIFICATION_TYPE_INACTIVITY
:
595 test_event
.type
= TEST_EV_TYPE_NOTIF_INACTIVITY
;
597 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
598 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
600 bt_notification_stream_begin_borrow_stream(notification
);
601 assert(test_event
.stream
);
603 case BT_NOTIFICATION_TYPE_STREAM_END
:
604 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
606 bt_notification_stream_end_borrow_stream(notification
);
607 assert(test_event
.stream
);
609 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
610 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
612 bt_notification_packet_begin_borrow_packet(notification
);
613 assert(test_event
.packet
);
615 case BT_NOTIFICATION_TYPE_PACKET_END
:
616 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
618 bt_notification_packet_end_borrow_packet(notification
);
619 assert(test_event
.packet
);
622 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
626 if (test_event
.packet
) {
627 test_event
.stream
= bt_packet_borrow_stream(test_event
.packet
);
628 assert(test_event
.stream
);
632 if (do_append_test_event
) {
633 append_test_event(&test_event
);
636 bt_put(notification
);
641 enum bt_component_status
sink_consume(
642 struct bt_private_component
*priv_component
)
644 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
645 struct sink_user_data
*user_data
=
646 bt_private_component_get_user_data(priv_component
);
647 enum bt_notification_iterator_status it_ret
;
649 assert(user_data
&& user_data
->notif_iter
);
650 it_ret
= common_consume(user_data
->notif_iter
);
653 ret
= BT_COMPONENT_STATUS_ERROR
;
658 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
659 ret
= BT_COMPONENT_STATUS_END
;
660 BT_PUT(user_data
->notif_iter
);
662 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
673 void sink_port_connected(struct bt_private_component
*private_component
,
674 struct bt_private_port
*self_private_port
,
675 struct bt_port
*other_port
)
677 struct bt_private_connection
*priv_conn
=
678 bt_private_port_get_private_connection(self_private_port
);
679 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
681 enum bt_connection_status conn_status
;
685 conn_status
= bt_private_connection_create_notification_iterator(
686 priv_conn
, &user_data
->notif_iter
);
687 assert(conn_status
== 0);
692 enum bt_component_status
sink_init(
693 struct bt_private_component
*private_component
,
694 struct bt_value
*params
, void *init_method_data
)
696 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
700 ret
= bt_private_component_set_user_data(private_component
,
703 ret
= bt_private_component_sink_add_input_private_port(
704 private_component
, "in", NULL
, NULL
);
706 return BT_COMPONENT_STATUS_OK
;
710 void sink_finalize(struct bt_private_component
*private_component
)
712 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
716 bt_put(user_data
->notif_iter
);
722 void create_source_sink(struct bt_graph
*graph
, struct bt_component
**source
,
723 struct bt_component
**sink
)
725 struct bt_component_class
*src_comp_class
;
726 struct bt_component_class
*sink_comp_class
;
729 /* Create source component */
731 src_comp_class
= bt_component_class_source_create("src",
733 assert(src_comp_class
);
734 ret
= bt_component_class_set_init_method(src_comp_class
,
737 ret
= bt_component_class_set_finalize_method(src_comp_class
,
740 ret
= bt_component_class_source_set_notification_iterator_init_method(
741 src_comp_class
, src_iter_init
);
743 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
744 src_comp_class
, src_iter_finalize
);
746 ret
= bt_graph_add_component(graph
, src_comp_class
, "source",
749 bt_put(src_comp_class
);
752 /* Create sink component */
754 sink_comp_class
= bt_component_class_sink_create("sink",
756 assert(sink_comp_class
);
757 ret
= bt_component_class_set_init_method(sink_comp_class
,
760 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
762 ret
= bt_component_class_set_port_connected_method(
763 sink_comp_class
, sink_port_connected
);
765 ret
= bt_graph_add_component(graph
, sink_comp_class
, "sink",
768 bt_put(sink_comp_class
);
773 void do_std_test(enum test test
, const char *name
,
774 const struct test_event
*expected_test_events
)
776 struct bt_component
*src_comp
;
777 struct bt_component
*sink_comp
;
778 struct bt_port
*upstream_port
;
779 struct bt_port
*downstream_port
;
780 struct bt_graph
*graph
;
781 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
785 diag("test: %s", name
);
786 graph
= bt_graph_create();
788 create_source_sink(graph
, &src_comp
, &sink_comp
);
790 /* Connect source to sink */
791 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
792 assert(upstream_port
);
793 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
794 assert(downstream_port
);
795 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
796 downstream_port
, NULL
);
797 bt_put(upstream_port
);
798 bt_put(downstream_port
);
800 /* Run the graph until the end */
801 while (graph_status
== BT_GRAPH_STATUS_OK
||
802 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
803 graph_status
= bt_graph_run(graph
);
806 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
808 /* Compare the resulting test events */
809 if (expected_test_events
) {
810 ok(compare_test_events(expected_test_events
),
811 "the produced sequence of test events is the expected one");
820 void test_no_auto_notifs(void)
822 const struct test_event expected_test_events
[] = {
823 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
824 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
825 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
826 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
827 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
828 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
829 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
830 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
831 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
832 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
833 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
834 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
835 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
836 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
837 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
838 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
839 { .type
= TEST_EV_TYPE_END
, },
840 { .type
= TEST_EV_TYPE_SENTINEL
, },
843 do_std_test(TEST_NO_AUTO_NOTIFS
, "no automatic notifications",
844 expected_test_events
);
848 void test_output_port_notification_iterator(void)
850 const struct test_event expected_test_events
[] = {
851 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
852 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
853 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
854 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
855 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
856 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
857 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
858 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
859 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
860 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
861 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
862 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
863 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
864 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
865 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
866 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
867 { .type
= TEST_EV_TYPE_END
, },
868 { .type
= TEST_EV_TYPE_SENTINEL
, },
870 struct bt_component
*src_comp
;
871 struct bt_notification_iterator
*notif_iter
;
872 enum bt_notification_iterator_status iter_status
=
873 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
874 struct bt_port
*upstream_port
;
875 struct bt_graph
*graph
;
878 current_test
= TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
;
879 diag("test: output port notification iterator");
880 graph
= bt_graph_create();
882 create_source_sink(graph
, &src_comp
, NULL
);
884 /* Create notification iterator on source's output port */
885 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
886 notif_iter
= bt_output_port_notification_iterator_create(upstream_port
,
888 ok(notif_iter
, "bt_output_port_notification_iterator_create() succeeds");
889 bt_put(upstream_port
);
891 /* Consume the notification iterator */
892 while (iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
893 iter_status
= common_consume(notif_iter
);
896 ok(iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_END
,
897 "output port notification iterator finishes without any error");
899 /* Compare the resulting test events */
900 ok(compare_test_events(expected_test_events
),
901 "the produced sequence of test events is the expected one");
909 void test_output_port_notification_iterator_cannot_consume(void)
911 struct bt_component
*src_comp
;
912 struct bt_notification_iterator
*notif_iter
;
913 struct bt_port
*upstream_port
;
914 struct bt_graph
*graph
;
917 current_test
= TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
;
918 diag("test: cannot consume graph with existing output port notification iterator");
919 graph
= bt_graph_create();
921 create_source_sink(graph
, &src_comp
, NULL
);
923 /* Create notification iterator on source's output port */
924 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
925 notif_iter
= bt_output_port_notification_iterator_create(upstream_port
,
928 bt_put(upstream_port
);
931 * This should fail because the graph is now managed by the
932 * notification iterator.
934 ok(bt_graph_run(graph
) == BT_GRAPH_STATUS_CANNOT_CONSUME
,
935 "bt_graph_run() returns BT_GRAPH_STATUS_CANNOT_CONSUME when there's an output port notification iterator");
942 #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
944 int main(int argc
, char **argv
)
946 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
950 plan_tests(NR_TESTS
);
952 test_no_auto_notifs();
953 test_output_port_notification_iterator();
954 test_output_port_notification_iterator_cannot_consume();
956 return exit_status();