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/trace-ir/event-class.h>
26 #include <babeltrace/trace-ir/event.h>
27 #include <babeltrace/trace-ir/field-classes.h>
28 #include <babeltrace/trace-ir/fields.h>
29 #include <babeltrace/trace-ir/packet.h>
30 #include <babeltrace/trace-ir/stream-class.h>
31 #include <babeltrace/trace-ir/stream.h>
32 #include <babeltrace/trace-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-iterator.h>
44 #include <babeltrace/graph/notification-packet.h>
45 #include <babeltrace/graph/notification-stream.h>
46 #include <babeltrace/graph/output-port-notification-iterator.h>
47 #include <babeltrace/graph/port.h>
48 #include <babeltrace/graph/private-component-source.h>
49 #include <babeltrace/graph/private-component-sink.h>
50 #include <babeltrace/graph/private-component.h>
51 #include <babeltrace/graph/private-connection.h>
52 #include <babeltrace/graph/private-connection-notification-iterator.h>
53 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
54 #include <babeltrace/graph/private-port.h>
55 #include <babeltrace/plugin/plugin.h>
56 #include <babeltrace/object.h>
65 TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
,
68 enum test_event_type
{
69 TEST_EV_TYPE_NOTIF_UNEXPECTED
,
70 TEST_EV_TYPE_NOTIF_EVENT
,
71 TEST_EV_TYPE_NOTIF_STREAM_BEGIN
,
72 TEST_EV_TYPE_NOTIF_PACKET_BEGIN
,
73 TEST_EV_TYPE_NOTIF_PACKET_END
,
74 TEST_EV_TYPE_NOTIF_STREAM_END
,
76 TEST_EV_TYPE_SENTINEL
,
80 enum test_event_type type
;
81 struct bt_stream
*stream
;
82 struct bt_packet
*packet
;
85 static bool debug
= false;
86 static enum test current_test
;
87 static GArray
*test_events
;
88 static struct bt_graph
*graph
;
89 static struct bt_private_connection_private_notification_iterator
*cur_notif_iter
;
90 static struct bt_stream_class
*src_stream_class
;
91 static struct bt_event_class
*src_event_class
;
92 static struct bt_stream
*src_stream1
;
93 static struct bt_stream
*src_stream2
;
94 static struct bt_packet
*src_stream1_packet1
;
95 static struct bt_packet
*src_stream1_packet2
;
96 static struct bt_packet
*src_stream2_packet1
;
97 static struct bt_packet
*src_stream2_packet2
;
101 SEQ_STREAM1_BEGIN
= -2,
102 SEQ_STREAM2_BEGIN
= -3,
103 SEQ_STREAM1_END
= -4,
104 SEQ_STREAM2_END
= -5,
105 SEQ_STREAM1_PACKET1_BEGIN
= -6,
106 SEQ_STREAM1_PACKET2_BEGIN
= -7,
107 SEQ_STREAM2_PACKET1_BEGIN
= -8,
108 SEQ_STREAM2_PACKET2_BEGIN
= -9,
109 SEQ_STREAM1_PACKET1_END
= -10,
110 SEQ_STREAM1_PACKET2_END
= -11,
111 SEQ_STREAM2_PACKET1_END
= -12,
112 SEQ_STREAM2_PACKET2_END
= -13,
113 SEQ_EVENT_STREAM1_PACKET1
= -14,
114 SEQ_EVENT_STREAM1_PACKET2
= -15,
115 SEQ_EVENT_STREAM2_PACKET1
= -16,
116 SEQ_EVENT_STREAM2_PACKET2
= -17,
119 struct src_iter_user_data
{
124 struct sink_user_data
{
125 struct bt_notification_iterator
*notif_iter
;
129 * No automatic notifications generated in this block.
130 * Stream 2 notifications are more indented.
132 static int64_t seq_no_auto_notifs
[] = {
134 SEQ_STREAM1_PACKET1_BEGIN
,
135 SEQ_EVENT_STREAM1_PACKET1
,
136 SEQ_EVENT_STREAM1_PACKET1
,
138 SEQ_EVENT_STREAM1_PACKET1
,
139 SEQ_STREAM2_PACKET2_BEGIN
,
140 SEQ_EVENT_STREAM2_PACKET2
,
141 SEQ_EVENT_STREAM1_PACKET1
,
142 SEQ_STREAM1_PACKET1_END
,
143 SEQ_STREAM2_PACKET2_END
,
144 SEQ_STREAM1_PACKET2_BEGIN
,
145 SEQ_EVENT_STREAM1_PACKET2
,
147 SEQ_STREAM1_PACKET2_END
,
153 void clear_test_events(void)
155 g_array_set_size(test_events
, 0);
159 void print_test_event(FILE *fp
, const struct test_event
*event
)
161 fprintf(fp
, "{ type = ");
163 switch (event
->type
) {
164 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
165 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
167 case TEST_EV_TYPE_NOTIF_EVENT
:
168 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
170 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
171 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
173 case TEST_EV_TYPE_NOTIF_STREAM_END
:
174 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
176 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
177 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
179 case TEST_EV_TYPE_NOTIF_PACKET_END
:
180 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
182 case TEST_EV_TYPE_END
:
183 fprintf(fp
, "TEST_EV_TYPE_END");
185 case TEST_EV_TYPE_SENTINEL
:
186 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
189 fprintf(fp
, "(UNKNOWN)");
193 fprintf(fp
, ", stream = %p, packet = %p }", event
->stream
,
198 void append_test_event(struct test_event
*event
)
200 g_array_append_val(test_events
, *event
);
204 bool compare_single_test_events(const struct test_event
*ev_a
,
205 const struct test_event
*ev_b
)
208 fprintf(stderr
, ":: Comparing test events: ");
209 print_test_event(stderr
, ev_a
);
210 fprintf(stderr
, " vs. ");
211 print_test_event(stderr
, ev_b
);
212 fprintf(stderr
, "\n");
215 if (ev_a
->type
!= ev_b
->type
) {
219 switch (ev_a
->type
) {
220 case TEST_EV_TYPE_END
:
221 case TEST_EV_TYPE_SENTINEL
:
224 if (ev_a
->stream
!= ev_b
->stream
) {
228 if (ev_a
->packet
!= ev_b
->packet
) {
238 bool compare_test_events(const struct test_event
*expected_events
)
240 const struct test_event
*expected_event
= expected_events
;
243 BT_ASSERT(expected_events
);
246 const struct test_event
*event
;
248 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
252 if (i
>= test_events
->len
) {
256 event
= &g_array_index(test_events
, struct test_event
, i
);
258 if (!compare_single_test_events(event
, expected_event
)) {
266 if (i
!= test_events
->len
) {
274 void init_static_data(void)
276 struct bt_trace
*trace
;
279 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
280 BT_ASSERT(test_events
);
283 trace
= bt_trace_create();
285 src_stream_class
= bt_stream_class_create(trace
);
286 BT_ASSERT(src_stream_class
);
287 src_event_class
= bt_event_class_create(src_stream_class
);
288 BT_ASSERT(src_event_class
);
289 src_stream1
= bt_stream_create(src_stream_class
);
290 BT_ASSERT(src_stream1
);
291 src_stream2
= bt_stream_create(src_stream_class
);
292 BT_ASSERT(src_stream2
);
293 src_stream1_packet1
= bt_packet_create(src_stream1
);
294 BT_ASSERT(src_stream1_packet1
);
295 src_stream1_packet2
= bt_packet_create(src_stream1
);
296 BT_ASSERT(src_stream1_packet2
);
297 src_stream2_packet1
= bt_packet_create(src_stream2
);
298 BT_ASSERT(src_stream2_packet1
);
299 src_stream2_packet2
= bt_packet_create(src_stream2
);
300 BT_ASSERT(src_stream2_packet2
);
303 fprintf(stderr
, ":: stream 1: %p\n", src_stream1
);
304 fprintf(stderr
, ":: stream 2: %p\n", src_stream2
);
305 fprintf(stderr
, ":: stream 1, packet 1: %p\n", src_stream1_packet1
);
306 fprintf(stderr
, ":: stream 1, packet 2: %p\n", src_stream1_packet2
);
307 fprintf(stderr
, ":: stream 2, packet 1: %p\n", src_stream2_packet1
);
308 fprintf(stderr
, ":: stream 2, packet 2: %p\n", src_stream2_packet2
);
311 bt_object_put_ref(trace
);
315 void fini_static_data(void)
318 g_array_free(test_events
, TRUE
);
321 bt_object_put_ref(src_stream_class
);
322 bt_object_put_ref(src_event_class
);
323 bt_object_put_ref(src_stream1
);
324 bt_object_put_ref(src_stream2
);
325 bt_object_put_ref(src_stream1_packet1
);
326 bt_object_put_ref(src_stream1_packet2
);
327 bt_object_put_ref(src_stream2_packet1
);
328 bt_object_put_ref(src_stream2_packet2
);
332 void src_iter_finalize(
333 struct bt_private_connection_private_notification_iterator
*private_notification_iterator
)
335 struct src_iter_user_data
*user_data
=
336 bt_private_connection_private_notification_iterator_get_user_data(
337 private_notification_iterator
);
345 enum bt_notification_iterator_status
src_iter_init(
346 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
347 struct bt_private_port
*private_port
)
349 struct src_iter_user_data
*user_data
=
350 g_new0(struct src_iter_user_data
, 1);
353 BT_ASSERT(user_data
);
354 ret
= bt_private_connection_private_notification_iterator_set_user_data(
355 priv_notif_iter
, user_data
);
358 switch (current_test
) {
359 case TEST_NO_AUTO_NOTIFS
:
360 case TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
:
361 user_data
->seq
= seq_no_auto_notifs
;
367 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
371 void src_iter_next_seq_one(struct src_iter_user_data
*user_data
,
372 struct bt_notification
**notif
)
374 struct bt_packet
*event_packet
= NULL
;
376 switch (user_data
->seq
[user_data
->at
]) {
377 case SEQ_STREAM1_BEGIN
:
378 *notif
= bt_notification_stream_begin_create(cur_notif_iter
,
381 case SEQ_STREAM2_BEGIN
:
382 *notif
= bt_notification_stream_begin_create(cur_notif_iter
,
385 case SEQ_STREAM1_END
:
386 *notif
= bt_notification_stream_end_create(cur_notif_iter
,
389 case SEQ_STREAM2_END
:
390 *notif
= bt_notification_stream_end_create(cur_notif_iter
,
393 case SEQ_STREAM1_PACKET1_BEGIN
:
394 *notif
= bt_notification_packet_begin_create(cur_notif_iter
,
395 src_stream1_packet1
);
397 case SEQ_STREAM1_PACKET2_BEGIN
:
398 *notif
= bt_notification_packet_begin_create(cur_notif_iter
,
399 src_stream1_packet2
);
401 case SEQ_STREAM2_PACKET1_BEGIN
:
402 *notif
= bt_notification_packet_begin_create(cur_notif_iter
,
403 src_stream2_packet1
);
405 case SEQ_STREAM2_PACKET2_BEGIN
:
406 *notif
= bt_notification_packet_begin_create(cur_notif_iter
,
407 src_stream2_packet2
);
409 case SEQ_STREAM1_PACKET1_END
:
410 *notif
= bt_notification_packet_end_create(cur_notif_iter
,
411 src_stream1_packet1
);
413 case SEQ_STREAM1_PACKET2_END
:
414 *notif
= bt_notification_packet_end_create(cur_notif_iter
,
415 src_stream1_packet2
);
417 case SEQ_STREAM2_PACKET1_END
:
418 *notif
= bt_notification_packet_end_create(cur_notif_iter
,
419 src_stream2_packet1
);
421 case SEQ_STREAM2_PACKET2_END
:
422 *notif
= bt_notification_packet_end_create(cur_notif_iter
,
423 src_stream2_packet2
);
425 case SEQ_EVENT_STREAM1_PACKET1
:
426 event_packet
= src_stream1_packet1
;
428 case SEQ_EVENT_STREAM1_PACKET2
:
429 event_packet
= src_stream1_packet2
;
431 case SEQ_EVENT_STREAM2_PACKET1
:
432 event_packet
= src_stream2_packet1
;
434 case SEQ_EVENT_STREAM2_PACKET2
:
435 event_packet
= src_stream2_packet2
;
442 *notif
= bt_notification_event_create(cur_notif_iter
,
443 src_event_class
, event_packet
);
451 enum bt_notification_iterator_status
src_iter_next_seq(
452 struct src_iter_user_data
*user_data
,
453 bt_notification_array notifs
, uint64_t capacity
,
456 enum bt_notification_iterator_status status
=
457 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
460 BT_ASSERT(user_data
->seq
);
462 if (user_data
->seq
[user_data
->at
] == SEQ_END
) {
463 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
467 while (i
< capacity
&& user_data
->seq
[user_data
->at
] != SEQ_END
) {
468 src_iter_next_seq_one(user_data
, ¬ifs
[i
]);
472 BT_ASSERT(i
> 0 && i
<= capacity
);
480 enum bt_notification_iterator_status
src_iter_next(
481 struct bt_private_connection_private_notification_iterator
*priv_iterator
,
482 bt_notification_array notifs
, uint64_t capacity
,
485 struct src_iter_user_data
*user_data
=
486 bt_private_connection_private_notification_iterator_get_user_data(priv_iterator
);
488 BT_ASSERT(user_data
);
489 cur_notif_iter
= priv_iterator
;
490 return src_iter_next_seq(user_data
, notifs
, capacity
, count
);
494 enum bt_component_status
src_init(
495 struct bt_private_component
*private_component
,
496 struct bt_value
*params
, void *init_method_data
)
500 ret
= bt_private_component_source_add_output_private_port(
501 private_component
, "out", NULL
, NULL
);
503 return BT_COMPONENT_STATUS_OK
;
507 void src_finalize(struct bt_private_component
*private_component
)
512 void append_test_events_from_notification(struct bt_notification
*notification
)
514 struct test_event test_event
= { 0 };
516 switch (bt_notification_get_type(notification
)) {
517 case BT_NOTIFICATION_TYPE_EVENT
:
519 struct bt_event
*event
;
521 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
522 event
= bt_notification_event_borrow_event(notification
);
524 test_event
.packet
= bt_event_borrow_packet(event
);
525 BT_ASSERT(test_event
.packet
);
528 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
529 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
531 bt_notification_stream_begin_borrow_stream(notification
);
532 BT_ASSERT(test_event
.stream
);
534 case BT_NOTIFICATION_TYPE_STREAM_END
:
535 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
537 bt_notification_stream_end_borrow_stream(notification
);
538 BT_ASSERT(test_event
.stream
);
540 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
541 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
543 bt_notification_packet_begin_borrow_packet(notification
);
544 BT_ASSERT(test_event
.packet
);
546 case BT_NOTIFICATION_TYPE_PACKET_END
:
547 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
549 bt_notification_packet_end_borrow_packet(notification
);
550 BT_ASSERT(test_event
.packet
);
553 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
557 if (test_event
.packet
) {
558 test_event
.stream
= bt_packet_borrow_stream(test_event
.packet
);
559 BT_ASSERT(test_event
.stream
);
562 append_test_event(&test_event
);
566 enum bt_notification_iterator_status
common_consume(
567 struct bt_notification_iterator
*notif_iter
,
568 bool is_output_port_notif_iter
)
570 enum bt_notification_iterator_status ret
;
571 bt_notification_array notifications
= NULL
;
573 struct test_event test_event
= { 0 };
576 BT_ASSERT(notif_iter
);
578 if (is_output_port_notif_iter
) {
579 ret
= bt_output_port_notification_iterator_next(notif_iter
,
580 ¬ifications
, &count
);
582 ret
= bt_private_connection_notification_iterator_next(
583 notif_iter
, ¬ifications
, &count
);
591 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
592 test_event
.type
= TEST_EV_TYPE_END
;
593 append_test_event(&test_event
);
595 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
601 BT_ASSERT(notifications
);
602 BT_ASSERT(count
> 0);
604 for (i
= 0; i
< count
; i
++) {
605 append_test_events_from_notification(notifications
[i
]);
606 bt_object_put_ref(notifications
[i
]);
614 enum bt_component_status
sink_consume(
615 struct bt_private_component
*priv_component
)
617 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
618 struct sink_user_data
*user_data
=
619 bt_private_component_get_user_data(priv_component
);
620 enum bt_notification_iterator_status it_ret
;
622 BT_ASSERT(user_data
&& user_data
->notif_iter
);
623 it_ret
= common_consume(user_data
->notif_iter
, false);
626 ret
= BT_COMPONENT_STATUS_ERROR
;
631 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
632 ret
= BT_COMPONENT_STATUS_END
;
633 BT_OBJECT_PUT_REF_AND_RESET(user_data
->notif_iter
);
635 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
646 enum bt_component_status
sink_port_connected(
647 struct bt_private_component
*private_component
,
648 struct bt_private_port
*self_private_port
,
649 struct bt_port
*other_port
)
651 struct bt_private_connection
*priv_conn
=
652 bt_private_port_get_private_connection(self_private_port
);
653 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
655 enum bt_connection_status conn_status
;
657 BT_ASSERT(user_data
);
658 BT_ASSERT(priv_conn
);
659 conn_status
= bt_private_connection_create_notification_iterator(
660 priv_conn
, &user_data
->notif_iter
);
661 BT_ASSERT(conn_status
== 0);
662 bt_object_put_ref(priv_conn
);
663 return BT_COMPONENT_STATUS_OK
;
667 enum bt_component_status
sink_init(
668 struct bt_private_component
*private_component
,
669 struct bt_value
*params
, void *init_method_data
)
671 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
674 BT_ASSERT(user_data
);
675 ret
= bt_private_component_set_user_data(private_component
,
678 ret
= bt_private_component_sink_add_input_private_port(
679 private_component
, "in", NULL
, NULL
);
681 return BT_COMPONENT_STATUS_OK
;
685 void sink_finalize(struct bt_private_component
*private_component
)
687 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
691 bt_object_put_ref(user_data
->notif_iter
);
697 void create_source_sink(struct bt_graph
*graph
, struct bt_component
**source
,
698 struct bt_component
**sink
)
700 struct bt_component_class
*src_comp_class
;
701 struct bt_component_class
*sink_comp_class
;
704 /* Create source component */
706 src_comp_class
= bt_component_class_source_create("src",
708 BT_ASSERT(src_comp_class
);
709 ret
= bt_component_class_set_init_method(src_comp_class
,
712 ret
= bt_component_class_set_finalize_method(src_comp_class
,
715 ret
= bt_component_class_source_set_notification_iterator_init_method(
716 src_comp_class
, src_iter_init
);
718 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
719 src_comp_class
, src_iter_finalize
);
721 ret
= bt_graph_add_component(graph
, src_comp_class
, "source",
724 bt_object_put_ref(src_comp_class
);
727 /* Create sink component */
729 sink_comp_class
= bt_component_class_sink_create("sink",
731 BT_ASSERT(sink_comp_class
);
732 ret
= bt_component_class_set_init_method(sink_comp_class
,
735 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
737 ret
= bt_component_class_set_port_connected_method(
738 sink_comp_class
, sink_port_connected
);
740 ret
= bt_graph_add_component(graph
, sink_comp_class
, "sink",
743 bt_object_put_ref(sink_comp_class
);
748 void do_std_test(enum test test
, const char *name
,
749 const struct test_event
*expected_test_events
)
751 struct bt_component
*src_comp
;
752 struct bt_component
*sink_comp
;
753 struct bt_port
*upstream_port
;
754 struct bt_port
*downstream_port
;
755 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
759 diag("test: %s", name
);
761 graph
= bt_graph_create();
763 create_source_sink(graph
, &src_comp
, &sink_comp
);
765 /* Connect source to sink */
766 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
767 BT_ASSERT(upstream_port
);
768 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
769 BT_ASSERT(downstream_port
);
770 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
771 downstream_port
, NULL
);
772 bt_object_put_ref(upstream_port
);
773 bt_object_put_ref(downstream_port
);
775 /* Run the graph until the end */
776 while (graph_status
== BT_GRAPH_STATUS_OK
||
777 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
778 graph_status
= bt_graph_run(graph
);
781 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
783 /* Compare the resulting test events */
784 if (expected_test_events
) {
785 ok(compare_test_events(expected_test_events
),
786 "the produced sequence of test events is the expected one");
789 bt_object_put_ref(src_comp
);
790 bt_object_put_ref(sink_comp
);
791 BT_OBJECT_PUT_REF_AND_RESET(graph
);
795 void test_no_auto_notifs(void)
797 const struct test_event expected_test_events
[] = {
798 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
799 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
800 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
801 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
802 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
803 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
804 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
805 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
806 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
807 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
808 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
809 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
810 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
811 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
812 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
813 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
814 { .type
= TEST_EV_TYPE_END
, },
815 { .type
= TEST_EV_TYPE_SENTINEL
, },
818 do_std_test(TEST_NO_AUTO_NOTIFS
, "no automatic notifications",
819 expected_test_events
);
823 void test_output_port_notification_iterator(void)
825 const struct test_event expected_test_events
[] = {
826 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
827 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
828 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
829 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
830 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
831 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
832 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
833 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
834 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
835 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
836 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
837 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
838 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
839 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
840 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
841 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
842 { .type
= TEST_EV_TYPE_END
, },
843 { .type
= TEST_EV_TYPE_SENTINEL
, },
845 struct bt_component
*src_comp
;
846 struct bt_notification_iterator
*notif_iter
;
847 enum bt_notification_iterator_status iter_status
=
848 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
849 struct bt_port
*upstream_port
;
852 current_test
= TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
;
853 diag("test: output port notification iterator");
855 graph
= bt_graph_create();
857 create_source_sink(graph
, &src_comp
, NULL
);
859 /* Create notification iterator on source's output port */
860 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
861 notif_iter
= bt_output_port_notification_iterator_create(upstream_port
,
863 ok(notif_iter
, "bt_output_port_notification_iterator_create() succeeds");
864 bt_object_put_ref(upstream_port
);
866 /* Consume the notification iterator */
867 while (iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
868 iter_status
= common_consume(notif_iter
, true);
871 ok(iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_END
,
872 "output port notification iterator finishes without any error");
874 /* Compare the resulting test events */
875 ok(compare_test_events(expected_test_events
),
876 "the produced sequence of test events is the expected one");
878 bt_object_put_ref(src_comp
);
879 BT_OBJECT_PUT_REF_AND_RESET(graph
);
880 bt_object_put_ref(notif_iter
);
883 #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
885 int main(int argc
, char **argv
)
887 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
891 plan_tests(NR_TESTS
);
893 test_no_auto_notifs();
894 test_output_port_notification_iterator();
896 return exit_status();