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 const struct bt_stream
*stream
;
51 const struct bt_packet
*packet
;
54 static bool debug
= false;
55 static enum test current_test
;
56 static GArray
*test_events
;
57 static struct bt_graph
*graph
;
58 static struct bt_stream_class
*src_stream_class
;
59 static struct bt_event_class
*src_event_class
;
60 static struct bt_stream
*src_stream1
;
61 static struct bt_stream
*src_stream2
;
62 static struct bt_packet
*src_stream1_packet1
;
63 static struct bt_packet
*src_stream1_packet2
;
64 static struct bt_packet
*src_stream2_packet1
;
65 static struct bt_packet
*src_stream2_packet2
;
69 SEQ_STREAM1_BEGIN
= -2,
70 SEQ_STREAM2_BEGIN
= -3,
73 SEQ_STREAM1_PACKET1_BEGIN
= -6,
74 SEQ_STREAM1_PACKET2_BEGIN
= -7,
75 SEQ_STREAM2_PACKET1_BEGIN
= -8,
76 SEQ_STREAM2_PACKET2_BEGIN
= -9,
77 SEQ_STREAM1_PACKET1_END
= -10,
78 SEQ_STREAM1_PACKET2_END
= -11,
79 SEQ_STREAM2_PACKET1_END
= -12,
80 SEQ_STREAM2_PACKET2_END
= -13,
81 SEQ_EVENT_STREAM1_PACKET1
= -14,
82 SEQ_EVENT_STREAM1_PACKET2
= -15,
83 SEQ_EVENT_STREAM2_PACKET1
= -16,
84 SEQ_EVENT_STREAM2_PACKET2
= -17,
87 struct src_iter_user_data
{
92 struct sink_user_data
{
93 struct bt_self_component_port_input_notification_iterator
*notif_iter
;
97 * No automatic notifications generated in this block.
98 * Stream 2 notifications are more indented.
100 static int64_t seq_no_auto_notifs
[] = {
102 SEQ_STREAM1_PACKET1_BEGIN
,
103 SEQ_EVENT_STREAM1_PACKET1
,
104 SEQ_EVENT_STREAM1_PACKET1
,
106 SEQ_EVENT_STREAM1_PACKET1
,
107 SEQ_STREAM2_PACKET2_BEGIN
,
108 SEQ_EVENT_STREAM2_PACKET2
,
109 SEQ_EVENT_STREAM1_PACKET1
,
110 SEQ_STREAM1_PACKET1_END
,
111 SEQ_STREAM2_PACKET2_END
,
112 SEQ_STREAM1_PACKET2_BEGIN
,
113 SEQ_EVENT_STREAM1_PACKET2
,
115 SEQ_STREAM1_PACKET2_END
,
121 void clear_test_events(void)
123 g_array_set_size(test_events
, 0);
127 void print_test_event(FILE *fp
, const struct test_event
*event
)
129 fprintf(fp
, "{ type = ");
131 switch (event
->type
) {
132 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
133 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
135 case TEST_EV_TYPE_NOTIF_EVENT
:
136 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
138 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
139 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
141 case TEST_EV_TYPE_NOTIF_STREAM_END
:
142 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
144 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
145 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
147 case TEST_EV_TYPE_NOTIF_PACKET_END
:
148 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
150 case TEST_EV_TYPE_END
:
151 fprintf(fp
, "TEST_EV_TYPE_END");
153 case TEST_EV_TYPE_SENTINEL
:
154 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
157 fprintf(fp
, "(UNKNOWN)");
161 fprintf(fp
, ", stream = %p, packet = %p }", event
->stream
,
166 void append_test_event(struct test_event
*event
)
168 g_array_append_val(test_events
, *event
);
172 bool compare_single_test_events(const struct test_event
*ev_a
,
173 const struct test_event
*ev_b
)
176 fprintf(stderr
, ":: Comparing test events: ");
177 print_test_event(stderr
, ev_a
);
178 fprintf(stderr
, " vs. ");
179 print_test_event(stderr
, ev_b
);
180 fprintf(stderr
, "\n");
183 if (ev_a
->type
!= ev_b
->type
) {
187 switch (ev_a
->type
) {
188 case TEST_EV_TYPE_END
:
189 case TEST_EV_TYPE_SENTINEL
:
192 if (ev_a
->stream
!= ev_b
->stream
) {
196 if (ev_a
->packet
!= ev_b
->packet
) {
206 bool compare_test_events(const struct test_event
*expected_events
)
208 const struct test_event
*expected_event
= expected_events
;
211 BT_ASSERT(expected_events
);
214 const struct test_event
*event
;
216 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
220 if (i
>= test_events
->len
) {
224 event
= &g_array_index(test_events
, struct test_event
, i
);
226 if (!compare_single_test_events(event
, expected_event
)) {
234 if (i
!= test_events
->len
) {
242 void init_static_data(void)
244 struct bt_trace_class
*trace_class
;
245 struct bt_trace
*trace
;
248 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
249 BT_ASSERT(test_events
);
251 /* Metadata, streams, and packets*/
252 trace_class
= bt_trace_class_create();
254 src_stream_class
= bt_stream_class_create(trace_class
);
255 BT_ASSERT(src_stream_class
);
256 src_event_class
= bt_event_class_create(src_stream_class
);
257 BT_ASSERT(src_event_class
);
258 trace
= bt_trace_create(trace_class
);
260 src_stream1
= bt_stream_create(src_stream_class
, trace
);
261 BT_ASSERT(src_stream1
);
262 src_stream2
= bt_stream_create(src_stream_class
, trace
);
263 BT_ASSERT(src_stream2
);
264 src_stream1_packet1
= bt_packet_create(src_stream1
);
265 BT_ASSERT(src_stream1_packet1
);
266 src_stream1_packet2
= bt_packet_create(src_stream1
);
267 BT_ASSERT(src_stream1_packet2
);
268 src_stream2_packet1
= bt_packet_create(src_stream2
);
269 BT_ASSERT(src_stream2_packet1
);
270 src_stream2_packet2
= bt_packet_create(src_stream2
);
271 BT_ASSERT(src_stream2_packet2
);
274 fprintf(stderr
, ":: stream 1: %p\n", src_stream1
);
275 fprintf(stderr
, ":: stream 2: %p\n", src_stream2
);
276 fprintf(stderr
, ":: stream 1, packet 1: %p\n", src_stream1_packet1
);
277 fprintf(stderr
, ":: stream 1, packet 2: %p\n", src_stream1_packet2
);
278 fprintf(stderr
, ":: stream 2, packet 1: %p\n", src_stream2_packet1
);
279 fprintf(stderr
, ":: stream 2, packet 2: %p\n", src_stream2_packet2
);
282 bt_trace_put_ref(trace
);
283 bt_trace_class_put_ref(trace_class
);
287 void fini_static_data(void)
290 g_array_free(test_events
, TRUE
);
293 bt_stream_class_put_ref(src_stream_class
);
294 bt_event_class_put_ref(src_event_class
);
295 bt_stream_put_ref(src_stream1
);
296 bt_stream_put_ref(src_stream2
);
297 bt_packet_put_ref(src_stream1_packet1
);
298 bt_packet_put_ref(src_stream1_packet2
);
299 bt_packet_put_ref(src_stream2_packet1
);
300 bt_packet_put_ref(src_stream2_packet2
);
304 void src_iter_finalize(struct bt_self_notification_iterator
*self_notif_iter
)
306 struct src_iter_user_data
*user_data
=
307 bt_self_notification_iterator_get_data(
316 enum bt_self_notification_iterator_status
src_iter_init(
317 struct bt_self_notification_iterator
*self_notif_iter
,
318 struct bt_self_component_source
*self_comp
,
319 struct bt_self_component_port_output
*self_port
)
321 struct src_iter_user_data
*user_data
=
322 g_new0(struct src_iter_user_data
, 1);
324 BT_ASSERT(user_data
);
325 bt_self_notification_iterator_set_data(self_notif_iter
, user_data
);
327 switch (current_test
) {
328 case TEST_NO_AUTO_NOTIFS
:
329 case TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
:
330 user_data
->seq
= seq_no_auto_notifs
;
336 return BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK
;
340 void src_iter_next_seq_one(struct bt_self_notification_iterator
* notif_iter
,
341 struct src_iter_user_data
*user_data
,
342 const struct bt_notification
**notif
)
344 struct bt_packet
*event_packet
= NULL
;
346 switch (user_data
->seq
[user_data
->at
]) {
347 case SEQ_STREAM1_BEGIN
:
348 *notif
= bt_notification_stream_beginning_create(notif_iter
,
351 case SEQ_STREAM2_BEGIN
:
352 *notif
= bt_notification_stream_beginning_create(notif_iter
,
355 case SEQ_STREAM1_END
:
356 *notif
= bt_notification_stream_end_create(notif_iter
,
359 case SEQ_STREAM2_END
:
360 *notif
= bt_notification_stream_end_create(notif_iter
,
363 case SEQ_STREAM1_PACKET1_BEGIN
:
364 *notif
= bt_notification_packet_beginning_create(notif_iter
,
365 src_stream1_packet1
);
367 case SEQ_STREAM1_PACKET2_BEGIN
:
368 *notif
= bt_notification_packet_beginning_create(notif_iter
,
369 src_stream1_packet2
);
371 case SEQ_STREAM2_PACKET1_BEGIN
:
372 *notif
= bt_notification_packet_beginning_create(notif_iter
,
373 src_stream2_packet1
);
375 case SEQ_STREAM2_PACKET2_BEGIN
:
376 *notif
= bt_notification_packet_beginning_create(notif_iter
,
377 src_stream2_packet2
);
379 case SEQ_STREAM1_PACKET1_END
:
380 *notif
= bt_notification_packet_end_create(notif_iter
,
381 src_stream1_packet1
);
383 case SEQ_STREAM1_PACKET2_END
:
384 *notif
= bt_notification_packet_end_create(notif_iter
,
385 src_stream1_packet2
);
387 case SEQ_STREAM2_PACKET1_END
:
388 *notif
= bt_notification_packet_end_create(notif_iter
,
389 src_stream2_packet1
);
391 case SEQ_STREAM2_PACKET2_END
:
392 *notif
= bt_notification_packet_end_create(notif_iter
,
393 src_stream2_packet2
);
395 case SEQ_EVENT_STREAM1_PACKET1
:
396 event_packet
= src_stream1_packet1
;
398 case SEQ_EVENT_STREAM1_PACKET2
:
399 event_packet
= src_stream1_packet2
;
401 case SEQ_EVENT_STREAM2_PACKET1
:
402 event_packet
= src_stream2_packet1
;
404 case SEQ_EVENT_STREAM2_PACKET2
:
405 event_packet
= src_stream2_packet2
;
412 *notif
= bt_notification_event_create(notif_iter
,
422 enum bt_self_notification_iterator_status
src_iter_next_seq(
423 struct bt_self_notification_iterator
*notif_iter
,
424 struct src_iter_user_data
*user_data
,
425 bt_notification_array_const notifs
, uint64_t capacity
,
428 enum bt_self_notification_iterator_status status
=
429 BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK
;
432 BT_ASSERT(user_data
->seq
);
434 if (user_data
->seq
[user_data
->at
] == SEQ_END
) {
435 status
= BT_SELF_NOTIFICATION_ITERATOR_STATUS_END
;
439 while (i
< capacity
&& user_data
->seq
[user_data
->at
] != SEQ_END
) {
440 src_iter_next_seq_one(notif_iter
, user_data
, ¬ifs
[i
]);
444 BT_ASSERT(i
> 0 && i
<= capacity
);
452 enum bt_self_notification_iterator_status
src_iter_next(
453 struct bt_self_notification_iterator
*self_notif_iter
,
454 bt_notification_array_const notifs
, uint64_t capacity
,
457 struct src_iter_user_data
*user_data
=
458 bt_self_notification_iterator_get_data(self_notif_iter
);
460 BT_ASSERT(user_data
);
461 return src_iter_next_seq(self_notif_iter
, user_data
, notifs
,
466 enum bt_self_component_status
src_init(
467 struct bt_self_component_source
*self_comp
,
468 const struct bt_value
*params
, void *init_method_data
)
472 ret
= bt_self_component_source_add_output_port(
473 self_comp
, "out", NULL
, NULL
);
475 return BT_SELF_COMPONENT_STATUS_OK
;
479 void src_finalize(struct bt_self_component_source
*self_comp
)
484 void append_test_events_from_notification(const struct bt_notification
*notification
)
486 struct test_event test_event
= { 0 };
488 switch (bt_notification_get_type(notification
)) {
489 case BT_NOTIFICATION_TYPE_EVENT
:
491 const struct bt_event
*event
;
493 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
494 event
= bt_notification_event_borrow_event_const(notification
);
496 test_event
.packet
= bt_event_borrow_packet_const(event
);
497 BT_ASSERT(test_event
.packet
);
500 case BT_NOTIFICATION_TYPE_STREAM_BEGINNING
:
501 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
503 bt_notification_stream_beginning_borrow_stream_const(notification
);
504 BT_ASSERT(test_event
.stream
);
506 case BT_NOTIFICATION_TYPE_STREAM_END
:
507 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
509 bt_notification_stream_end_borrow_stream_const(notification
);
510 BT_ASSERT(test_event
.stream
);
512 case BT_NOTIFICATION_TYPE_PACKET_BEGINNING
:
513 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
515 bt_notification_packet_beginning_borrow_packet_const(notification
);
516 BT_ASSERT(test_event
.packet
);
518 case BT_NOTIFICATION_TYPE_PACKET_END
:
519 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
521 bt_notification_packet_end_borrow_packet_const(notification
);
522 BT_ASSERT(test_event
.packet
);
525 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
529 if (test_event
.packet
) {
530 test_event
.stream
= bt_packet_borrow_stream_const(
532 BT_ASSERT(test_event
.stream
);
535 append_test_event(&test_event
);
539 enum bt_notification_iterator_status
common_consume(
540 void *notif_iter
, bool is_output_port_notif_iter
)
542 enum bt_notification_iterator_status ret
;
543 bt_notification_array_const notifications
= NULL
;
545 struct test_event test_event
= { 0 };
548 BT_ASSERT(notif_iter
);
550 if (is_output_port_notif_iter
) {
551 ret
= bt_port_output_notification_iterator_next(notif_iter
,
552 ¬ifications
, &count
);
554 ret
= bt_self_component_port_input_notification_iterator_next(
555 notif_iter
, ¬ifications
, &count
);
563 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
564 test_event
.type
= TEST_EV_TYPE_END
;
565 append_test_event(&test_event
);
567 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
573 BT_ASSERT(notifications
);
574 BT_ASSERT(count
> 0);
576 for (i
= 0; i
< count
; i
++) {
577 append_test_events_from_notification(notifications
[i
]);
578 bt_notification_put_ref(notifications
[i
]);
586 enum bt_self_component_status
sink_consume(
587 struct bt_self_component_sink
*self_comp
)
589 enum bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
590 struct sink_user_data
*user_data
=
591 bt_self_component_get_data(
592 bt_self_component_sink_as_self_component(
594 enum bt_notification_iterator_status it_ret
;
596 BT_ASSERT(user_data
&& user_data
->notif_iter
);
597 it_ret
= common_consume(user_data
->notif_iter
, false);
600 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
605 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
606 ret
= BT_SELF_COMPONENT_STATUS_END
;
607 BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_PUT_REF_AND_RESET(
608 user_data
->notif_iter
);
610 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
621 enum bt_self_component_status
sink_port_connected(
622 struct bt_self_component_sink
*self_comp
,
623 struct bt_self_component_port_input
*self_port
,
624 const struct bt_port_output
*other_port
)
626 struct sink_user_data
*user_data
=
627 bt_self_component_get_data(
628 bt_self_component_sink_as_self_component(
631 BT_ASSERT(user_data
);
632 user_data
->notif_iter
=
633 bt_self_component_port_input_notification_iterator_create(
635 return BT_SELF_COMPONENT_STATUS_OK
;
639 enum bt_self_component_status
sink_init(
640 struct bt_self_component_sink
*self_comp
,
641 const struct bt_value
*params
, void *init_method_data
)
643 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
646 BT_ASSERT(user_data
);
647 bt_self_component_set_data(
648 bt_self_component_sink_as_self_component(self_comp
),
650 ret
= bt_self_component_sink_add_input_port(
651 self_comp
, "in", NULL
, NULL
);
653 return BT_SELF_COMPONENT_STATUS_OK
;
657 void sink_finalize(struct bt_self_component_sink
*self_comp
)
659 struct sink_user_data
*user_data
=
660 bt_self_component_get_data(
661 bt_self_component_sink_as_self_component(
665 BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_PUT_REF_AND_RESET(
666 user_data
->notif_iter
);
672 void create_source_sink(struct bt_graph
*graph
,
673 const struct bt_component_source
**source
,
674 const struct bt_component_sink
**sink
)
676 struct bt_component_class_source
*src_comp_class
;
677 struct bt_component_class_sink
*sink_comp_class
;
680 /* Create source component */
682 src_comp_class
= bt_component_class_source_create("src",
684 BT_ASSERT(src_comp_class
);
685 ret
= bt_component_class_source_set_init_method(
686 src_comp_class
, src_init
);
688 ret
= bt_component_class_source_set_finalize_method(
689 src_comp_class
, src_finalize
);
691 ret
= bt_component_class_source_set_notification_iterator_init_method(
692 src_comp_class
, src_iter_init
);
694 ret
= bt_component_class_source_set_notification_iterator_finalize_method(
695 src_comp_class
, src_iter_finalize
);
697 ret
= bt_graph_add_source_component(graph
,
698 src_comp_class
, "source", NULL
, source
);
700 bt_component_class_source_put_ref(src_comp_class
);
703 /* Create sink component */
705 sink_comp_class
= bt_component_class_sink_create("sink",
707 BT_ASSERT(sink_comp_class
);
708 ret
= bt_component_class_sink_set_init_method(
709 sink_comp_class
, sink_init
);
711 ret
= bt_component_class_sink_set_finalize_method(
712 sink_comp_class
, sink_finalize
);
713 ret
= bt_component_class_sink_set_input_port_connected_method(
714 sink_comp_class
, sink_port_connected
);
716 ret
= bt_graph_add_sink_component(graph
,
720 bt_component_class_sink_put_ref(sink_comp_class
);
725 void do_std_test(enum test test
, const char *name
,
726 const struct test_event
*expected_test_events
)
728 const struct bt_component_source
*src_comp
;
729 const struct bt_component_sink
*sink_comp
;
730 const struct bt_port_output
*upstream_port
;
731 const struct bt_port_input
*downstream_port
;
732 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
736 diag("test: %s", name
);
738 graph
= bt_graph_create();
740 create_source_sink(graph
, &src_comp
, &sink_comp
);
742 /* Connect source to sink */
744 bt_component_source_borrow_output_port_by_name_const(
746 BT_ASSERT(upstream_port
);
747 downstream_port
= bt_component_sink_borrow_input_port_by_name_const(
749 BT_ASSERT(downstream_port
);
750 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
751 downstream_port
, NULL
);
753 /* Run the graph until the end */
754 while (graph_status
== BT_GRAPH_STATUS_OK
||
755 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
756 graph_status
= bt_graph_run(graph
);
759 ok(graph_status
== BT_GRAPH_STATUS_END
,
760 "graph finishes without any error");
762 /* Compare the resulting test events */
763 if (expected_test_events
) {
764 ok(compare_test_events(expected_test_events
),
765 "the produced sequence of test events is the expected one");
768 bt_component_source_put_ref(src_comp
);
769 bt_component_sink_put_ref(sink_comp
);
770 BT_GRAPH_PUT_REF_AND_RESET(graph
);
774 void test_no_auto_notifs(void)
776 const struct test_event expected_test_events
[] = {
777 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
778 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
779 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
780 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
781 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
782 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
783 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
784 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
785 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
786 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
787 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
788 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
789 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
790 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
791 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
792 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
793 { .type
= TEST_EV_TYPE_END
, },
794 { .type
= TEST_EV_TYPE_SENTINEL
, },
797 do_std_test(TEST_NO_AUTO_NOTIFS
, "no automatic notifications",
798 expected_test_events
);
802 void test_output_port_notification_iterator(void)
804 const struct test_event expected_test_events
[] = {
805 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
806 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
807 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
808 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
809 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
810 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
811 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
812 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
813 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
814 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
815 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
816 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
817 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
818 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
819 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
820 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
821 { .type
= TEST_EV_TYPE_END
, },
822 { .type
= TEST_EV_TYPE_SENTINEL
, },
824 const struct bt_component_source
*src_comp
;
825 struct bt_port_output_notification_iterator
*notif_iter
;
826 enum bt_notification_iterator_status iter_status
=
827 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
828 const struct bt_port_output
*upstream_port
;
831 current_test
= TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
;
832 diag("test: output port notification iterator");
834 graph
= bt_graph_create();
836 create_source_sink(graph
, &src_comp
, NULL
);
838 /* Create notification iterator on source's output port */
839 upstream_port
= bt_component_source_borrow_output_port_by_name_const(src_comp
,
841 notif_iter
= bt_port_output_notification_iterator_create(graph
,
843 ok(notif_iter
, "bt_private_output_port_notification_iterator_create() succeeds");
845 /* Consume the notification iterator */
846 while (iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
847 iter_status
= common_consume(notif_iter
, true);
850 ok(iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_END
,
851 "output port notification iterator finishes without any error");
853 /* Compare the resulting test events */
854 ok(compare_test_events(expected_test_events
),
855 "the produced sequence of test events is the expected one");
857 bt_component_source_put_ref(src_comp
);
858 BT_GRAPH_PUT_REF_AND_RESET(graph
);
859 bt_port_output_notification_iterator_put_ref(notif_iter
);
862 #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
864 int main(int argc
, char **argv
)
866 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
870 plan_tests(NR_TESTS
);
872 test_no_auto_notifs();
873 test_output_port_notification_iterator();
875 return exit_status();