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/babeltrace.h>
25 #include <babeltrace/assert-internal.h>
34 TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
,
37 enum test_event_type
{
38 TEST_EV_TYPE_NOTIF_UNEXPECTED
,
39 TEST_EV_TYPE_NOTIF_EVENT
,
40 TEST_EV_TYPE_NOTIF_STREAM_BEGIN
,
41 TEST_EV_TYPE_NOTIF_PACKET_BEGIN
,
42 TEST_EV_TYPE_NOTIF_PACKET_END
,
43 TEST_EV_TYPE_NOTIF_STREAM_END
,
45 TEST_EV_TYPE_SENTINEL
,
49 enum test_event_type type
;
50 struct bt_stream
*stream
;
51 struct bt_packet
*packet
;
54 static bool debug
= false;
55 static enum test current_test
;
56 static GArray
*test_events
;
57 static struct bt_private_graph
*graph
;
58 static struct bt_private_connection_private_notification_iterator
*cur_notif_iter
;
59 static struct bt_private_stream_class
*src_stream_class
;
60 static struct bt_private_event_class
*src_event_class
;
61 static struct bt_private_stream
*src_stream1
;
62 static struct bt_private_stream
*src_stream2
;
63 static struct bt_private_packet
*src_stream1_packet1
;
64 static struct bt_private_packet
*src_stream1_packet2
;
65 static struct bt_private_packet
*src_stream2_packet1
;
66 static struct bt_private_packet
*src_stream2_packet2
;
67 static struct bt_stream
*pub_src_stream1
;
68 static struct bt_stream
*pub_src_stream2
;
69 static struct bt_packet
*pub_src_stream1_packet1
;
70 static struct bt_packet
*pub_src_stream1_packet2
;
71 static struct bt_packet
*pub_src_stream2_packet1
;
72 static struct bt_packet
*pub_src_stream2_packet2
;
76 SEQ_STREAM1_BEGIN
= -2,
77 SEQ_STREAM2_BEGIN
= -3,
80 SEQ_STREAM1_PACKET1_BEGIN
= -6,
81 SEQ_STREAM1_PACKET2_BEGIN
= -7,
82 SEQ_STREAM2_PACKET1_BEGIN
= -8,
83 SEQ_STREAM2_PACKET2_BEGIN
= -9,
84 SEQ_STREAM1_PACKET1_END
= -10,
85 SEQ_STREAM1_PACKET2_END
= -11,
86 SEQ_STREAM2_PACKET1_END
= -12,
87 SEQ_STREAM2_PACKET2_END
= -13,
88 SEQ_EVENT_STREAM1_PACKET1
= -14,
89 SEQ_EVENT_STREAM1_PACKET2
= -15,
90 SEQ_EVENT_STREAM2_PACKET1
= -16,
91 SEQ_EVENT_STREAM2_PACKET2
= -17,
94 struct src_iter_user_data
{
99 struct sink_user_data
{
100 struct bt_notification_iterator
*notif_iter
;
104 * No automatic notifications generated in this block.
105 * Stream 2 notifications are more indented.
107 static int64_t seq_no_auto_notifs
[] = {
109 SEQ_STREAM1_PACKET1_BEGIN
,
110 SEQ_EVENT_STREAM1_PACKET1
,
111 SEQ_EVENT_STREAM1_PACKET1
,
113 SEQ_EVENT_STREAM1_PACKET1
,
114 SEQ_STREAM2_PACKET2_BEGIN
,
115 SEQ_EVENT_STREAM2_PACKET2
,
116 SEQ_EVENT_STREAM1_PACKET1
,
117 SEQ_STREAM1_PACKET1_END
,
118 SEQ_STREAM2_PACKET2_END
,
119 SEQ_STREAM1_PACKET2_BEGIN
,
120 SEQ_EVENT_STREAM1_PACKET2
,
122 SEQ_STREAM1_PACKET2_END
,
128 void clear_test_events(void)
130 g_array_set_size(test_events
, 0);
134 void print_test_event(FILE *fp
, const struct test_event
*event
)
136 fprintf(fp
, "{ type = ");
138 switch (event
->type
) {
139 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
140 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
142 case TEST_EV_TYPE_NOTIF_EVENT
:
143 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
145 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
146 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
148 case TEST_EV_TYPE_NOTIF_STREAM_END
:
149 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
151 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
152 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
154 case TEST_EV_TYPE_NOTIF_PACKET_END
:
155 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
157 case TEST_EV_TYPE_END
:
158 fprintf(fp
, "TEST_EV_TYPE_END");
160 case TEST_EV_TYPE_SENTINEL
:
161 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
164 fprintf(fp
, "(UNKNOWN)");
168 fprintf(fp
, ", stream = %p, packet = %p }", event
->stream
,
173 void append_test_event(struct test_event
*event
)
175 g_array_append_val(test_events
, *event
);
179 bool compare_single_test_events(const struct test_event
*ev_a
,
180 const struct test_event
*ev_b
)
183 fprintf(stderr
, ":: Comparing test events: ");
184 print_test_event(stderr
, ev_a
);
185 fprintf(stderr
, " vs. ");
186 print_test_event(stderr
, ev_b
);
187 fprintf(stderr
, "\n");
190 if (ev_a
->type
!= ev_b
->type
) {
194 switch (ev_a
->type
) {
195 case TEST_EV_TYPE_END
:
196 case TEST_EV_TYPE_SENTINEL
:
199 if (ev_a
->stream
!= ev_b
->stream
) {
203 if (ev_a
->packet
!= ev_b
->packet
) {
213 bool compare_test_events(const struct test_event
*expected_events
)
215 const struct test_event
*expected_event
= expected_events
;
218 BT_ASSERT(expected_events
);
221 const struct test_event
*event
;
223 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
227 if (i
>= test_events
->len
) {
231 event
= &g_array_index(test_events
, struct test_event
, i
);
233 if (!compare_single_test_events(event
, expected_event
)) {
241 if (i
!= test_events
->len
) {
249 void init_static_data(void)
251 struct bt_private_trace
*trace
;
254 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
255 BT_ASSERT(test_events
);
258 trace
= bt_private_trace_create();
260 src_stream_class
= bt_private_stream_class_create(trace
);
261 BT_ASSERT(src_stream_class
);
262 src_event_class
= bt_private_event_class_create(src_stream_class
);
263 BT_ASSERT(src_event_class
);
264 src_stream1
= bt_private_stream_create(src_stream_class
);
265 BT_ASSERT(src_stream1
);
266 pub_src_stream1
= bt_stream_borrow_from_private(src_stream1
);
267 src_stream2
= bt_private_stream_create(src_stream_class
);
268 BT_ASSERT(src_stream2
);
269 pub_src_stream2
= bt_stream_borrow_from_private(src_stream2
);
270 src_stream1_packet1
= bt_private_packet_create(src_stream1
);
271 BT_ASSERT(src_stream1_packet1
);
272 pub_src_stream1_packet1
= bt_packet_borrow_from_private(
273 src_stream1_packet1
);
274 src_stream1_packet2
= bt_private_packet_create(src_stream1
);
275 BT_ASSERT(src_stream1_packet2
);
276 pub_src_stream1_packet2
= bt_packet_borrow_from_private(
277 src_stream1_packet2
);
278 src_stream2_packet1
= bt_private_packet_create(src_stream2
);
279 BT_ASSERT(src_stream2_packet1
);
280 pub_src_stream2_packet1
= bt_packet_borrow_from_private(
281 src_stream2_packet1
);
282 src_stream2_packet2
= bt_private_packet_create(src_stream2
);
283 BT_ASSERT(src_stream2_packet2
);
284 pub_src_stream2_packet2
= bt_packet_borrow_from_private(
285 src_stream2_packet2
);
288 fprintf(stderr
, ":: stream 1: %p\n", src_stream1
);
289 fprintf(stderr
, ":: stream 2: %p\n", src_stream2
);
290 fprintf(stderr
, ":: stream 1, packet 1: %p\n", src_stream1_packet1
);
291 fprintf(stderr
, ":: stream 1, packet 2: %p\n", src_stream1_packet2
);
292 fprintf(stderr
, ":: stream 2, packet 1: %p\n", src_stream2_packet1
);
293 fprintf(stderr
, ":: stream 2, packet 2: %p\n", src_stream2_packet2
);
296 bt_object_put_ref(trace
);
300 void fini_static_data(void)
303 g_array_free(test_events
, TRUE
);
306 bt_object_put_ref(src_stream_class
);
307 bt_object_put_ref(src_event_class
);
308 bt_object_put_ref(src_stream1
);
309 bt_object_put_ref(src_stream2
);
310 bt_object_put_ref(src_stream1_packet1
);
311 bt_object_put_ref(src_stream1_packet2
);
312 bt_object_put_ref(src_stream2_packet1
);
313 bt_object_put_ref(src_stream2_packet2
);
317 void src_iter_finalize(
318 struct bt_private_connection_private_notification_iterator
*private_notification_iterator
)
320 struct src_iter_user_data
*user_data
=
321 bt_private_connection_private_notification_iterator_get_user_data(
322 private_notification_iterator
);
330 enum bt_notification_iterator_status
src_iter_init(
331 struct bt_private_connection_private_notification_iterator
*priv_notif_iter
,
332 struct bt_private_port
*private_port
)
334 struct src_iter_user_data
*user_data
=
335 g_new0(struct src_iter_user_data
, 1);
338 BT_ASSERT(user_data
);
339 ret
= bt_private_connection_private_notification_iterator_set_user_data(
340 priv_notif_iter
, user_data
);
343 switch (current_test
) {
344 case TEST_NO_AUTO_NOTIFS
:
345 case TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
:
346 user_data
->seq
= seq_no_auto_notifs
;
352 return BT_NOTIFICATION_ITERATOR_STATUS_OK
;
356 void src_iter_next_seq_one(struct src_iter_user_data
*user_data
,
357 struct bt_notification
**notif
)
359 struct bt_private_packet
*event_packet
= NULL
;
361 switch (user_data
->seq
[user_data
->at
]) {
362 case SEQ_STREAM1_BEGIN
:
363 *notif
= bt_notification_borrow_from_private(
364 bt_private_notification_stream_begin_create(
365 cur_notif_iter
, src_stream1
));
367 case SEQ_STREAM2_BEGIN
:
368 *notif
= bt_notification_borrow_from_private(
369 bt_private_notification_stream_begin_create(
370 cur_notif_iter
, src_stream2
));
372 case SEQ_STREAM1_END
:
373 *notif
= bt_notification_borrow_from_private(
374 bt_private_notification_stream_end_create(
375 cur_notif_iter
, src_stream1
));
377 case SEQ_STREAM2_END
:
378 *notif
= bt_notification_borrow_from_private(
379 bt_private_notification_stream_end_create(
380 cur_notif_iter
, src_stream2
));
382 case SEQ_STREAM1_PACKET1_BEGIN
:
383 *notif
= bt_notification_borrow_from_private(
384 bt_private_notification_packet_begin_create(
385 cur_notif_iter
, src_stream1_packet1
));
387 case SEQ_STREAM1_PACKET2_BEGIN
:
388 *notif
= bt_notification_borrow_from_private(
389 bt_private_notification_packet_begin_create(
390 cur_notif_iter
, src_stream1_packet2
));
392 case SEQ_STREAM2_PACKET1_BEGIN
:
393 *notif
= bt_notification_borrow_from_private(
394 bt_private_notification_packet_begin_create(
395 cur_notif_iter
, src_stream2_packet1
));
397 case SEQ_STREAM2_PACKET2_BEGIN
:
398 *notif
= bt_notification_borrow_from_private(
399 bt_private_notification_packet_begin_create(
400 cur_notif_iter
, src_stream2_packet2
));
402 case SEQ_STREAM1_PACKET1_END
:
403 *notif
= bt_notification_borrow_from_private(
404 bt_private_notification_packet_end_create(
405 cur_notif_iter
, src_stream1_packet1
));
407 case SEQ_STREAM1_PACKET2_END
:
408 *notif
= bt_notification_borrow_from_private(
409 bt_private_notification_packet_end_create(
410 cur_notif_iter
, src_stream1_packet2
));
412 case SEQ_STREAM2_PACKET1_END
:
413 *notif
= bt_notification_borrow_from_private(
414 bt_private_notification_packet_end_create(
415 cur_notif_iter
, src_stream2_packet1
));
417 case SEQ_STREAM2_PACKET2_END
:
418 *notif
= bt_notification_borrow_from_private(
419 bt_private_notification_packet_end_create(
420 cur_notif_iter
, src_stream2_packet2
));
422 case SEQ_EVENT_STREAM1_PACKET1
:
423 event_packet
= src_stream1_packet1
;
425 case SEQ_EVENT_STREAM1_PACKET2
:
426 event_packet
= src_stream1_packet2
;
428 case SEQ_EVENT_STREAM2_PACKET1
:
429 event_packet
= src_stream2_packet1
;
431 case SEQ_EVENT_STREAM2_PACKET2
:
432 event_packet
= src_stream2_packet2
;
439 *notif
= bt_notification_borrow_from_private(
440 bt_private_notification_event_create(
441 cur_notif_iter
, src_event_class
, event_packet
));
449 enum bt_notification_iterator_status
src_iter_next_seq(
450 struct src_iter_user_data
*user_data
,
451 bt_notification_array notifs
, uint64_t capacity
,
454 enum bt_notification_iterator_status status
=
455 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
458 BT_ASSERT(user_data
->seq
);
460 if (user_data
->seq
[user_data
->at
] == SEQ_END
) {
461 status
= BT_NOTIFICATION_ITERATOR_STATUS_END
;
465 while (i
< capacity
&& user_data
->seq
[user_data
->at
] != SEQ_END
) {
466 src_iter_next_seq_one(user_data
, ¬ifs
[i
]);
470 BT_ASSERT(i
> 0 && i
<= capacity
);
478 enum bt_notification_iterator_status
src_iter_next(
479 struct bt_private_connection_private_notification_iterator
*priv_iterator
,
480 bt_notification_array notifs
, uint64_t capacity
,
483 struct src_iter_user_data
*user_data
=
484 bt_private_connection_private_notification_iterator_get_user_data(priv_iterator
);
486 BT_ASSERT(user_data
);
487 cur_notif_iter
= priv_iterator
;
488 return src_iter_next_seq(user_data
, notifs
, capacity
, count
);
492 enum bt_component_status
src_init(
493 struct bt_private_component
*private_component
,
494 struct bt_value
*params
, void *init_method_data
)
498 ret
= bt_private_component_source_add_output_port(
499 private_component
, "out", NULL
, NULL
);
501 return BT_COMPONENT_STATUS_OK
;
505 void src_finalize(struct bt_private_component
*private_component
)
510 void append_test_events_from_notification(struct bt_notification
*notification
)
512 struct test_event test_event
= { 0 };
514 switch (bt_notification_get_type(notification
)) {
515 case BT_NOTIFICATION_TYPE_EVENT
:
517 struct bt_event
*event
;
519 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
520 event
= bt_notification_event_borrow_event(notification
);
522 test_event
.packet
= bt_event_borrow_packet(event
);
523 BT_ASSERT(test_event
.packet
);
526 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
527 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
529 bt_notification_stream_begin_borrow_stream(notification
);
530 BT_ASSERT(test_event
.stream
);
532 case BT_NOTIFICATION_TYPE_STREAM_END
:
533 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
535 bt_notification_stream_end_borrow_stream(notification
);
536 BT_ASSERT(test_event
.stream
);
538 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
539 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
541 bt_notification_packet_begin_borrow_packet(notification
);
542 BT_ASSERT(test_event
.packet
);
544 case BT_NOTIFICATION_TYPE_PACKET_END
:
545 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
547 bt_notification_packet_end_borrow_packet(notification
);
548 BT_ASSERT(test_event
.packet
);
551 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
555 if (test_event
.packet
) {
556 test_event
.stream
= bt_packet_borrow_stream(test_event
.packet
);
557 BT_ASSERT(test_event
.stream
);
560 append_test_event(&test_event
);
564 enum bt_notification_iterator_status
common_consume(
565 struct bt_notification_iterator
*notif_iter
,
566 bool is_output_port_notif_iter
)
568 enum bt_notification_iterator_status ret
;
569 bt_notification_array notifications
= NULL
;
571 struct test_event test_event
= { 0 };
574 BT_ASSERT(notif_iter
);
576 if (is_output_port_notif_iter
) {
577 ret
= bt_output_port_notification_iterator_next(notif_iter
,
578 ¬ifications
, &count
);
580 ret
= bt_private_connection_notification_iterator_next(
581 notif_iter
, ¬ifications
, &count
);
589 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
590 test_event
.type
= TEST_EV_TYPE_END
;
591 append_test_event(&test_event
);
593 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
599 BT_ASSERT(notifications
);
600 BT_ASSERT(count
> 0);
602 for (i
= 0; i
< count
; i
++) {
603 append_test_events_from_notification(notifications
[i
]);
604 bt_object_put_ref(notifications
[i
]);
612 enum bt_component_status
sink_consume(
613 struct bt_private_component
*priv_component
)
615 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
616 struct sink_user_data
*user_data
=
617 bt_private_component_get_user_data(priv_component
);
618 enum bt_notification_iterator_status it_ret
;
620 BT_ASSERT(user_data
&& user_data
->notif_iter
);
621 it_ret
= common_consume(user_data
->notif_iter
, false);
624 ret
= BT_COMPONENT_STATUS_ERROR
;
629 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
630 ret
= BT_COMPONENT_STATUS_END
;
631 BT_OBJECT_PUT_REF_AND_RESET(user_data
->notif_iter
);
633 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
644 enum bt_component_status
sink_port_connected(
645 struct bt_private_component
*private_component
,
646 struct bt_private_port
*self_private_port
,
647 struct bt_port
*other_port
)
649 struct bt_private_connection
*priv_conn
=
650 bt_private_port_get_connection(self_private_port
);
651 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
653 enum bt_connection_status conn_status
;
655 BT_ASSERT(user_data
);
656 BT_ASSERT(priv_conn
);
657 conn_status
= bt_private_connection_create_notification_iterator(
658 priv_conn
, &user_data
->notif_iter
);
659 BT_ASSERT(conn_status
== 0);
660 bt_object_put_ref(priv_conn
);
661 return BT_COMPONENT_STATUS_OK
;
665 enum bt_component_status
sink_init(
666 struct bt_private_component
*private_component
,
667 struct bt_value
*params
, void *init_method_data
)
669 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
672 BT_ASSERT(user_data
);
673 ret
= bt_private_component_set_user_data(private_component
,
676 ret
= bt_private_component_sink_add_input_port(
677 private_component
, "in", NULL
, NULL
);
679 return BT_COMPONENT_STATUS_OK
;
683 void sink_finalize(struct bt_private_component
*private_component
)
685 struct sink_user_data
*user_data
= bt_private_component_get_user_data(
689 bt_object_put_ref(user_data
->notif_iter
);
695 void create_source_sink(struct bt_private_graph
*graph
, struct bt_component
**source
,
696 struct bt_component
**sink
)
698 struct bt_component_class
*src_comp_class
;
699 struct bt_component_class
*sink_comp_class
;
702 /* Create source component */
704 src_comp_class
= bt_component_class_source_create("src",
706 BT_ASSERT(src_comp_class
);
707 ret
= bt_component_class_set_init_method(src_comp_class
,
710 ret
= bt_component_class_set_finalize_method(src_comp_class
,
713 ret
= bt_component_class_source_set_notification_iterator_init_method(
714 src_comp_class
, src_iter_init
);
716 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
717 src_comp_class
, src_iter_finalize
);
719 ret
= bt_private_graph_add_component(graph
, src_comp_class
, "source",
722 bt_object_put_ref(src_comp_class
);
725 /* Create sink component */
727 sink_comp_class
= bt_component_class_sink_create("sink",
729 BT_ASSERT(sink_comp_class
);
730 ret
= bt_component_class_set_init_method(sink_comp_class
,
733 ret
= bt_component_class_set_finalize_method(sink_comp_class
,
735 ret
= bt_component_class_set_port_connected_method(
736 sink_comp_class
, sink_port_connected
);
738 ret
= bt_private_graph_add_component(graph
, sink_comp_class
, "sink",
741 bt_object_put_ref(sink_comp_class
);
746 void do_std_test(enum test test
, const char *name
,
747 const struct test_event
*expected_test_events
)
749 struct bt_component
*src_comp
;
750 struct bt_component
*sink_comp
;
751 struct bt_port
*upstream_port
;
752 struct bt_port
*downstream_port
;
753 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
757 diag("test: %s", name
);
759 graph
= bt_private_graph_create();
761 create_source_sink(graph
, &src_comp
, &sink_comp
);
763 /* Connect source to sink */
764 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
765 BT_ASSERT(upstream_port
);
766 downstream_port
= bt_component_sink_get_input_port_by_name(sink_comp
, "in");
767 BT_ASSERT(downstream_port
);
768 graph_status
= bt_private_graph_connect_ports(graph
, upstream_port
,
769 downstream_port
, NULL
);
770 bt_object_put_ref(upstream_port
);
771 bt_object_put_ref(downstream_port
);
773 /* Run the graph until the end */
774 while (graph_status
== BT_GRAPH_STATUS_OK
||
775 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
776 graph_status
= bt_private_graph_run(graph
);
779 ok(graph_status
== BT_GRAPH_STATUS_END
, "graph finishes without any error");
781 /* Compare the resulting test events */
782 if (expected_test_events
) {
783 ok(compare_test_events(expected_test_events
),
784 "the produced sequence of test events is the expected one");
787 bt_object_put_ref(src_comp
);
788 bt_object_put_ref(sink_comp
);
789 BT_OBJECT_PUT_REF_AND_RESET(graph
);
793 void test_no_auto_notifs(void)
795 const struct test_event expected_test_events
[] = {
796 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream1
, .packet
= NULL
, },
797 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
798 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
799 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
800 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream2
, .packet
= NULL
, },
801 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
802 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
803 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
804 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
805 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
806 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
807 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
808 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
809 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream2
, .packet
= NULL
, },
810 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
811 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream1
, .packet
= NULL
, },
812 { .type
= TEST_EV_TYPE_END
, },
813 { .type
= TEST_EV_TYPE_SENTINEL
, },
816 do_std_test(TEST_NO_AUTO_NOTIFS
, "no automatic notifications",
817 expected_test_events
);
821 void test_output_port_notification_iterator(void)
823 const struct test_event expected_test_events
[] = {
824 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream1
, .packet
= NULL
, },
825 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
826 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
827 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
828 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream2
, .packet
= NULL
, },
829 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
830 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
831 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
832 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
833 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
834 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
835 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
836 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
837 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream2
, .packet
= NULL
, },
838 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
839 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream1
, .packet
= NULL
, },
840 { .type
= TEST_EV_TYPE_END
, },
841 { .type
= TEST_EV_TYPE_SENTINEL
, },
843 struct bt_component
*src_comp
;
844 struct bt_notification_iterator
*notif_iter
;
845 enum bt_notification_iterator_status iter_status
=
846 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
847 struct bt_port
*upstream_port
;
850 current_test
= TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
;
851 diag("test: output port notification iterator");
853 graph
= bt_private_graph_create();
855 create_source_sink(graph
, &src_comp
, NULL
);
857 /* Create notification iterator on source's output port */
858 upstream_port
= bt_component_source_get_output_port_by_name(src_comp
, "out");
859 notif_iter
= bt_output_port_notification_iterator_create(upstream_port
,
861 ok(notif_iter
, "bt_private_output_port_notification_iterator_create() succeeds");
862 bt_object_put_ref(upstream_port
);
864 /* Consume the notification iterator */
865 while (iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
866 iter_status
= common_consume(notif_iter
, true);
869 ok(iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_END
,
870 "output port notification iterator finishes without any error");
872 /* Compare the resulting test events */
873 ok(compare_test_events(expected_test_events
),
874 "the produced sequence of test events is the expected one");
876 bt_object_put_ref(src_comp
);
877 BT_OBJECT_PUT_REF_AND_RESET(graph
);
878 bt_object_put_ref(notif_iter
);
881 #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
883 int main(int argc
, char **argv
)
885 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
889 plan_tests(NR_TESTS
);
891 test_no_auto_notifs();
892 test_output_port_notification_iterator();
894 return exit_status();