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_stream_class
*src_stream_class
;
59 static struct bt_private_event_class
*src_event_class
;
60 static struct bt_private_stream
*src_stream1
;
61 static struct bt_private_stream
*src_stream2
;
62 static struct bt_private_packet
*src_stream1_packet1
;
63 static struct bt_private_packet
*src_stream1_packet2
;
64 static struct bt_private_packet
*src_stream2_packet1
;
65 static struct bt_private_packet
*src_stream2_packet2
;
66 static struct bt_stream
*pub_src_stream1
;
67 static struct bt_stream
*pub_src_stream2
;
68 static struct bt_packet
*pub_src_stream1_packet1
;
69 static struct bt_packet
*pub_src_stream1_packet2
;
70 static struct bt_packet
*pub_src_stream2_packet1
;
71 static struct bt_packet
*pub_src_stream2_packet2
;
75 SEQ_STREAM1_BEGIN
= -2,
76 SEQ_STREAM2_BEGIN
= -3,
79 SEQ_STREAM1_PACKET1_BEGIN
= -6,
80 SEQ_STREAM1_PACKET2_BEGIN
= -7,
81 SEQ_STREAM2_PACKET1_BEGIN
= -8,
82 SEQ_STREAM2_PACKET2_BEGIN
= -9,
83 SEQ_STREAM1_PACKET1_END
= -10,
84 SEQ_STREAM1_PACKET2_END
= -11,
85 SEQ_STREAM2_PACKET1_END
= -12,
86 SEQ_STREAM2_PACKET2_END
= -13,
87 SEQ_EVENT_STREAM1_PACKET1
= -14,
88 SEQ_EVENT_STREAM1_PACKET2
= -15,
89 SEQ_EVENT_STREAM2_PACKET1
= -16,
90 SEQ_EVENT_STREAM2_PACKET2
= -17,
93 struct src_iter_user_data
{
98 struct sink_user_data
{
103 * No automatic notifications generated in this block.
104 * Stream 2 notifications are more indented.
106 static int64_t seq_no_auto_notifs
[] = {
108 SEQ_STREAM1_PACKET1_BEGIN
,
109 SEQ_EVENT_STREAM1_PACKET1
,
110 SEQ_EVENT_STREAM1_PACKET1
,
112 SEQ_EVENT_STREAM1_PACKET1
,
113 SEQ_STREAM2_PACKET2_BEGIN
,
114 SEQ_EVENT_STREAM2_PACKET2
,
115 SEQ_EVENT_STREAM1_PACKET1
,
116 SEQ_STREAM1_PACKET1_END
,
117 SEQ_STREAM2_PACKET2_END
,
118 SEQ_STREAM1_PACKET2_BEGIN
,
119 SEQ_EVENT_STREAM1_PACKET2
,
121 SEQ_STREAM1_PACKET2_END
,
127 void clear_test_events(void)
129 g_array_set_size(test_events
, 0);
133 void print_test_event(FILE *fp
, const struct test_event
*event
)
135 fprintf(fp
, "{ type = ");
137 switch (event
->type
) {
138 case TEST_EV_TYPE_NOTIF_UNEXPECTED
:
139 fprintf(fp
, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
141 case TEST_EV_TYPE_NOTIF_EVENT
:
142 fprintf(fp
, "TEST_EV_TYPE_NOTIF_EVENT");
144 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN
:
145 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
147 case TEST_EV_TYPE_NOTIF_STREAM_END
:
148 fprintf(fp
, "TEST_EV_TYPE_NOTIF_STREAM_END");
150 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN
:
151 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
153 case TEST_EV_TYPE_NOTIF_PACKET_END
:
154 fprintf(fp
, "TEST_EV_TYPE_NOTIF_PACKET_END");
156 case TEST_EV_TYPE_END
:
157 fprintf(fp
, "TEST_EV_TYPE_END");
159 case TEST_EV_TYPE_SENTINEL
:
160 fprintf(fp
, "TEST_EV_TYPE_SENTINEL");
163 fprintf(fp
, "(UNKNOWN)");
167 fprintf(fp
, ", stream = %p, packet = %p }", event
->stream
,
172 void append_test_event(struct test_event
*event
)
174 g_array_append_val(test_events
, *event
);
178 bool compare_single_test_events(const struct test_event
*ev_a
,
179 const struct test_event
*ev_b
)
182 fprintf(stderr
, ":: Comparing test events: ");
183 print_test_event(stderr
, ev_a
);
184 fprintf(stderr
, " vs. ");
185 print_test_event(stderr
, ev_b
);
186 fprintf(stderr
, "\n");
189 if (ev_a
->type
!= ev_b
->type
) {
193 switch (ev_a
->type
) {
194 case TEST_EV_TYPE_END
:
195 case TEST_EV_TYPE_SENTINEL
:
198 if (ev_a
->stream
!= ev_b
->stream
) {
202 if (ev_a
->packet
!= ev_b
->packet
) {
212 bool compare_test_events(const struct test_event
*expected_events
)
214 const struct test_event
*expected_event
= expected_events
;
217 BT_ASSERT(expected_events
);
220 const struct test_event
*event
;
222 if (expected_event
->type
== TEST_EV_TYPE_SENTINEL
) {
226 if (i
>= test_events
->len
) {
230 event
= &g_array_index(test_events
, struct test_event
, i
);
232 if (!compare_single_test_events(event
, expected_event
)) {
240 if (i
!= test_events
->len
) {
248 void init_static_data(void)
250 struct bt_private_trace
*trace
;
253 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
254 BT_ASSERT(test_events
);
257 trace
= bt_private_trace_create();
259 src_stream_class
= bt_private_stream_class_create(trace
);
260 BT_ASSERT(src_stream_class
);
261 src_event_class
= bt_private_event_class_create(src_stream_class
);
262 BT_ASSERT(src_event_class
);
263 src_stream1
= bt_private_stream_create(src_stream_class
);
264 BT_ASSERT(src_stream1
);
265 pub_src_stream1
= bt_private_stream_as_stream(src_stream1
);
266 src_stream2
= bt_private_stream_create(src_stream_class
);
267 BT_ASSERT(src_stream2
);
268 pub_src_stream2
= bt_private_stream_as_stream(src_stream2
);
269 src_stream1_packet1
= bt_private_packet_create(src_stream1
);
270 BT_ASSERT(src_stream1_packet1
);
271 pub_src_stream1_packet1
= bt_private_packet_as_packet(
272 src_stream1_packet1
);
273 src_stream1_packet2
= bt_private_packet_create(src_stream1
);
274 BT_ASSERT(src_stream1_packet2
);
275 pub_src_stream1_packet2
= bt_private_packet_as_packet(
276 src_stream1_packet2
);
277 src_stream2_packet1
= bt_private_packet_create(src_stream2
);
278 BT_ASSERT(src_stream2_packet1
);
279 pub_src_stream2_packet1
= bt_private_packet_as_packet(
280 src_stream2_packet1
);
281 src_stream2_packet2
= bt_private_packet_create(src_stream2
);
282 BT_ASSERT(src_stream2_packet2
);
283 pub_src_stream2_packet2
= bt_private_packet_as_packet(
284 src_stream2_packet2
);
287 fprintf(stderr
, ":: stream 1: %p\n", src_stream1
);
288 fprintf(stderr
, ":: stream 2: %p\n", src_stream2
);
289 fprintf(stderr
, ":: stream 1, packet 1: %p\n", src_stream1_packet1
);
290 fprintf(stderr
, ":: stream 1, packet 2: %p\n", src_stream1_packet2
);
291 fprintf(stderr
, ":: stream 2, packet 1: %p\n", src_stream2_packet1
);
292 fprintf(stderr
, ":: stream 2, packet 2: %p\n", src_stream2_packet2
);
295 bt_object_put_ref(trace
);
299 void fini_static_data(void)
302 g_array_free(test_events
, TRUE
);
305 bt_object_put_ref(src_stream_class
);
306 bt_object_put_ref(src_event_class
);
307 bt_object_put_ref(src_stream1
);
308 bt_object_put_ref(src_stream2
);
309 bt_object_put_ref(src_stream1_packet1
);
310 bt_object_put_ref(src_stream1_packet2
);
311 bt_object_put_ref(src_stream2_packet1
);
312 bt_object_put_ref(src_stream2_packet2
);
316 void src_iter_finalize(struct bt_self_notification_iterator
*self_notif_iter
)
318 struct src_iter_user_data
*user_data
=
319 bt_self_notification_iterator_get_data(
328 enum bt_self_notification_iterator_status
src_iter_init(
329 struct bt_self_notification_iterator
*self_notif_iter
,
330 struct bt_self_component_source
*self_comp
,
331 struct bt_self_component_port_output
*self_port
)
333 struct src_iter_user_data
*user_data
=
334 g_new0(struct src_iter_user_data
, 1);
336 BT_ASSERT(user_data
);
337 bt_self_notification_iterator_set_data(self_notif_iter
, user_data
);
339 switch (current_test
) {
340 case TEST_NO_AUTO_NOTIFS
:
341 case TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
:
342 user_data
->seq
= seq_no_auto_notifs
;
348 return BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK
;
352 void src_iter_next_seq_one(struct bt_self_notification_iterator
* notif_iter
,
353 struct src_iter_user_data
*user_data
,
354 struct bt_notification
**notif
)
356 struct bt_private_packet
*event_packet
= NULL
;
358 switch (user_data
->seq
[user_data
->at
]) {
359 case SEQ_STREAM1_BEGIN
:
360 *notif
= bt_private_notification_as_notification(
361 bt_private_notification_stream_begin_create(
362 notif_iter
, src_stream1
));
364 case SEQ_STREAM2_BEGIN
:
365 *notif
= bt_private_notification_as_notification(
366 bt_private_notification_stream_begin_create(
367 notif_iter
, src_stream2
));
369 case SEQ_STREAM1_END
:
370 *notif
= bt_private_notification_as_notification(
371 bt_private_notification_stream_end_create(
372 notif_iter
, src_stream1
));
374 case SEQ_STREAM2_END
:
375 *notif
= bt_private_notification_as_notification(
376 bt_private_notification_stream_end_create(
377 notif_iter
, src_stream2
));
379 case SEQ_STREAM1_PACKET1_BEGIN
:
380 *notif
= bt_private_notification_as_notification(
381 bt_private_notification_packet_begin_create(
382 notif_iter
, src_stream1_packet1
));
384 case SEQ_STREAM1_PACKET2_BEGIN
:
385 *notif
= bt_private_notification_as_notification(
386 bt_private_notification_packet_begin_create(
387 notif_iter
, src_stream1_packet2
));
389 case SEQ_STREAM2_PACKET1_BEGIN
:
390 *notif
= bt_private_notification_as_notification(
391 bt_private_notification_packet_begin_create(
392 notif_iter
, src_stream2_packet1
));
394 case SEQ_STREAM2_PACKET2_BEGIN
:
395 *notif
= bt_private_notification_as_notification(
396 bt_private_notification_packet_begin_create(
397 notif_iter
, src_stream2_packet2
));
399 case SEQ_STREAM1_PACKET1_END
:
400 *notif
= bt_private_notification_as_notification(
401 bt_private_notification_packet_end_create(
402 notif_iter
, src_stream1_packet1
));
404 case SEQ_STREAM1_PACKET2_END
:
405 *notif
= bt_private_notification_as_notification(
406 bt_private_notification_packet_end_create(
407 notif_iter
, src_stream1_packet2
));
409 case SEQ_STREAM2_PACKET1_END
:
410 *notif
= bt_private_notification_as_notification(
411 bt_private_notification_packet_end_create(
412 notif_iter
, src_stream2_packet1
));
414 case SEQ_STREAM2_PACKET2_END
:
415 *notif
= bt_private_notification_as_notification(
416 bt_private_notification_packet_end_create(
417 notif_iter
, src_stream2_packet2
));
419 case SEQ_EVENT_STREAM1_PACKET1
:
420 event_packet
= src_stream1_packet1
;
422 case SEQ_EVENT_STREAM1_PACKET2
:
423 event_packet
= src_stream1_packet2
;
425 case SEQ_EVENT_STREAM2_PACKET1
:
426 event_packet
= src_stream2_packet1
;
428 case SEQ_EVENT_STREAM2_PACKET2
:
429 event_packet
= src_stream2_packet2
;
436 *notif
= bt_private_notification_as_notification(
437 bt_private_notification_event_create(
438 notif_iter
, src_event_class
, event_packet
));
446 enum bt_self_notification_iterator_status
src_iter_next_seq(
447 struct bt_self_notification_iterator
*notif_iter
,
448 struct src_iter_user_data
*user_data
,
449 bt_notification_array notifs
, uint64_t capacity
,
452 enum bt_self_notification_iterator_status status
=
453 BT_SELF_NOTIFICATION_ITERATOR_STATUS_OK
;
456 BT_ASSERT(user_data
->seq
);
458 if (user_data
->seq
[user_data
->at
] == SEQ_END
) {
459 status
= BT_SELF_NOTIFICATION_ITERATOR_STATUS_END
;
463 while (i
< capacity
&& user_data
->seq
[user_data
->at
] != SEQ_END
) {
464 src_iter_next_seq_one(notif_iter
, user_data
, ¬ifs
[i
]);
468 BT_ASSERT(i
> 0 && i
<= capacity
);
476 enum bt_self_notification_iterator_status
src_iter_next(
477 struct bt_self_notification_iterator
*self_notif_iter
,
478 bt_notification_array notifs
, uint64_t capacity
,
481 struct src_iter_user_data
*user_data
=
482 bt_self_notification_iterator_get_data(self_notif_iter
);
484 BT_ASSERT(user_data
);
485 return src_iter_next_seq(self_notif_iter
, user_data
, notifs
,
490 enum bt_self_component_status
src_init(
491 struct bt_self_component_source
*self_comp
,
492 struct bt_value
*params
, void *init_method_data
)
496 ret
= bt_self_component_source_add_output_port(
497 self_comp
, "out", NULL
, NULL
);
499 return BT_SELF_COMPONENT_STATUS_OK
;
503 void src_finalize(struct bt_self_component_source
*self_comp
)
508 void append_test_events_from_notification(struct bt_notification
*notification
)
510 struct test_event test_event
= { 0 };
512 switch (bt_notification_get_type(notification
)) {
513 case BT_NOTIFICATION_TYPE_EVENT
:
515 struct bt_event
*event
;
517 test_event
.type
= TEST_EV_TYPE_NOTIF_EVENT
;
518 event
= bt_notification_event_borrow_event(notification
);
520 test_event
.packet
= bt_event_borrow_packet(event
);
521 BT_ASSERT(test_event
.packet
);
524 case BT_NOTIFICATION_TYPE_STREAM_BEGIN
:
525 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
;
527 bt_notification_stream_begin_borrow_stream(notification
);
528 BT_ASSERT(test_event
.stream
);
530 case BT_NOTIFICATION_TYPE_STREAM_END
:
531 test_event
.type
= TEST_EV_TYPE_NOTIF_STREAM_END
;
533 bt_notification_stream_end_borrow_stream(notification
);
534 BT_ASSERT(test_event
.stream
);
536 case BT_NOTIFICATION_TYPE_PACKET_BEGIN
:
537 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
;
539 bt_notification_packet_begin_borrow_packet(notification
);
540 BT_ASSERT(test_event
.packet
);
542 case BT_NOTIFICATION_TYPE_PACKET_END
:
543 test_event
.type
= TEST_EV_TYPE_NOTIF_PACKET_END
;
545 bt_notification_packet_end_borrow_packet(notification
);
546 BT_ASSERT(test_event
.packet
);
549 test_event
.type
= TEST_EV_TYPE_NOTIF_UNEXPECTED
;
553 if (test_event
.packet
) {
554 test_event
.stream
= bt_packet_borrow_stream(test_event
.packet
);
555 BT_ASSERT(test_event
.stream
);
558 append_test_event(&test_event
);
562 enum bt_notification_iterator_status
common_consume(
563 void *notif_iter
, bool is_output_port_notif_iter
)
565 enum bt_notification_iterator_status ret
;
566 bt_notification_array notifications
= NULL
;
568 struct test_event test_event
= { 0 };
571 BT_ASSERT(notif_iter
);
573 if (is_output_port_notif_iter
) {
574 ret
= bt_port_output_notification_iterator_next(notif_iter
,
575 ¬ifications
, &count
);
577 ret
= bt_self_component_port_input_notification_iterator_next(
578 notif_iter
, ¬ifications
, &count
);
586 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
587 test_event
.type
= TEST_EV_TYPE_END
;
588 append_test_event(&test_event
);
590 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
596 BT_ASSERT(notifications
);
597 BT_ASSERT(count
> 0);
599 for (i
= 0; i
< count
; i
++) {
600 append_test_events_from_notification(notifications
[i
]);
601 bt_object_put_ref(notifications
[i
]);
609 enum bt_self_component_status
sink_consume(
610 struct bt_self_component_sink
*self_comp
)
612 enum bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
613 struct sink_user_data
*user_data
=
614 bt_self_component_get_data(
615 bt_self_component_sink_as_self_component(
617 enum bt_notification_iterator_status it_ret
;
619 BT_ASSERT(user_data
&& user_data
->notif_iter
);
620 it_ret
= common_consume(user_data
->notif_iter
, false);
623 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
628 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
629 ret
= BT_SELF_COMPONENT_STATUS_END
;
630 BT_OBJECT_PUT_REF_AND_RESET(user_data
->notif_iter
);
632 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
643 enum bt_self_component_status
sink_port_connected(
644 struct bt_self_component_sink
*self_comp
,
645 struct bt_self_component_port_input
*self_port
,
646 struct bt_port_output
*other_port
)
648 struct sink_user_data
*user_data
=
649 bt_self_component_get_data(
650 bt_self_component_sink_as_self_component(
653 BT_ASSERT(user_data
);
654 user_data
->notif_iter
=
655 bt_self_component_port_input_notification_iterator_create(
657 return BT_SELF_COMPONENT_STATUS_OK
;
661 enum bt_self_component_status
sink_init(
662 struct bt_self_component_sink
*self_comp
,
663 struct bt_value
*params
, void *init_method_data
)
665 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
668 BT_ASSERT(user_data
);
669 bt_self_component_set_data(
670 bt_self_component_sink_as_self_component(self_comp
),
672 ret
= bt_self_component_sink_add_input_port(
673 self_comp
, "in", NULL
, NULL
);
675 return BT_SELF_COMPONENT_STATUS_OK
;
679 void sink_finalize(struct bt_self_component_sink
*self_comp
)
681 struct sink_user_data
*user_data
=
682 bt_self_component_get_data(
683 bt_self_component_sink_as_self_component(
687 bt_object_put_ref(user_data
->notif_iter
);
693 void create_source_sink(struct bt_private_graph
*graph
,
694 struct bt_component_source
**source
,
695 struct bt_component_sink
**sink
)
697 struct bt_private_component_class_source
*src_comp_class
;
698 struct bt_private_component_class_sink
*sink_comp_class
;
701 /* Create source component */
703 src_comp_class
= bt_private_component_class_source_create("src",
705 BT_ASSERT(src_comp_class
);
706 ret
= bt_private_component_class_source_set_init_method(
707 src_comp_class
, src_init
);
709 ret
= bt_private_component_class_source_set_finalize_method(
710 src_comp_class
, src_finalize
);
712 ret
= bt_private_component_class_source_set_notification_iterator_init_method(
713 src_comp_class
, src_iter_init
);
715 ret
= bt_private_component_class_source_set_notification_iterator_finalize_method(
716 src_comp_class
, src_iter_finalize
);
718 ret
= bt_private_graph_add_source_component(graph
,
719 bt_private_component_class_source_as_component_class_source(
720 src_comp_class
), "source", NULL
, source
);
722 bt_object_put_ref(src_comp_class
);
725 /* Create sink component */
727 sink_comp_class
= bt_private_component_class_sink_create("sink",
729 BT_ASSERT(sink_comp_class
);
730 ret
= bt_private_component_class_sink_set_init_method(
731 sink_comp_class
, sink_init
);
733 ret
= bt_private_component_class_sink_set_finalize_method(
734 sink_comp_class
, sink_finalize
);
735 ret
= bt_private_component_class_sink_set_input_port_connected_method(
736 sink_comp_class
, sink_port_connected
);
738 ret
= bt_private_graph_add_sink_component(graph
,
739 bt_private_component_class_sink_as_component_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_source
*src_comp
;
752 struct bt_component_sink
*sink_comp
;
753 struct bt_port_output
*upstream_port
;
754 struct bt_port_input
*downstream_port
;
755 enum bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
759 diag("test: %s", name
);
761 graph
= bt_private_graph_create();
763 create_source_sink(graph
, &src_comp
, &sink_comp
);
765 /* Connect source to sink */
766 upstream_port
= bt_component_source_borrow_output_port_by_name(
768 BT_ASSERT(upstream_port
);
769 downstream_port
= bt_component_sink_borrow_input_port_by_name(
771 BT_ASSERT(downstream_port
);
772 graph_status
= bt_private_graph_connect_ports(graph
, upstream_port
,
773 downstream_port
, NULL
);
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_private_graph_run(graph
);
781 ok(graph_status
== BT_GRAPH_STATUS_END
,
782 "graph finishes without any error");
784 /* Compare the resulting test events */
785 if (expected_test_events
) {
786 ok(compare_test_events(expected_test_events
),
787 "the produced sequence of test events is the expected one");
790 bt_object_put_ref(src_comp
);
791 bt_object_put_ref(sink_comp
);
792 BT_OBJECT_PUT_REF_AND_RESET(graph
);
796 void test_no_auto_notifs(void)
798 const struct test_event expected_test_events
[] = {
799 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream1
, .packet
= NULL
, },
800 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
801 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
802 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
803 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream2
, .packet
= NULL
, },
804 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
805 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
806 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
807 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
808 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
809 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
810 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
811 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
812 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream2
, .packet
= NULL
, },
813 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
814 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream1
, .packet
= NULL
, },
815 { .type
= TEST_EV_TYPE_END
, },
816 { .type
= TEST_EV_TYPE_SENTINEL
, },
819 do_std_test(TEST_NO_AUTO_NOTIFS
, "no automatic notifications",
820 expected_test_events
);
824 void test_output_port_notification_iterator(void)
826 const struct test_event expected_test_events
[] = {
827 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream1
, .packet
= NULL
, },
828 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
829 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
830 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
831 { .type
= TEST_EV_TYPE_NOTIF_STREAM_BEGIN
, .stream
= pub_src_stream2
, .packet
= NULL
, },
832 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
833 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
834 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
835 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
836 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet1
, },
837 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream2
, .packet
= pub_src_stream2_packet2
, },
838 { .type
= TEST_EV_TYPE_NOTIF_PACKET_BEGIN
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
839 { .type
= TEST_EV_TYPE_NOTIF_EVENT
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
840 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream2
, .packet
= NULL
, },
841 { .type
= TEST_EV_TYPE_NOTIF_PACKET_END
, .stream
= pub_src_stream1
, .packet
= pub_src_stream1_packet2
, },
842 { .type
= TEST_EV_TYPE_NOTIF_STREAM_END
, .stream
= pub_src_stream1
, .packet
= NULL
, },
843 { .type
= TEST_EV_TYPE_END
, },
844 { .type
= TEST_EV_TYPE_SENTINEL
, },
846 struct bt_component_source
*src_comp
;
847 struct bt_port_output_notification_iterator
*notif_iter
;
848 enum bt_notification_iterator_status iter_status
=
849 BT_NOTIFICATION_ITERATOR_STATUS_OK
;
850 struct bt_port_output
*upstream_port
;
853 current_test
= TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR
;
854 diag("test: output port notification iterator");
856 graph
= bt_private_graph_create();
858 create_source_sink(graph
, &src_comp
, NULL
);
860 /* Create notification iterator on source's output port */
861 upstream_port
= bt_component_source_borrow_output_port_by_name(
863 notif_iter
= bt_port_output_notification_iterator_create(graph
,
865 ok(notif_iter
, "bt_private_output_port_notification_iterator_create() succeeds");
867 /* Consume the notification iterator */
868 while (iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_OK
) {
869 iter_status
= common_consume(notif_iter
, true);
872 ok(iter_status
== BT_NOTIFICATION_ITERATOR_STATUS_END
,
873 "output port notification iterator finishes without any error");
875 /* Compare the resulting test events */
876 ok(compare_test_events(expected_test_events
),
877 "the produced sequence of test events is the expected one");
879 bt_object_put_ref(src_comp
);
880 BT_OBJECT_PUT_REF_AND_RESET(graph
);
881 bt_object_put_ref(notif_iter
);
884 #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
886 int main(int argc
, char **argv
)
888 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
892 plan_tests(NR_TESTS
);
894 test_no_auto_notifs();
895 test_output_port_notification_iterator();
897 return exit_status();