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_MESSAGE_ITERATOR
,
37 enum test_event_type
{
38 TEST_EV_TYPE_MSG_UNEXPECTED
,
39 TEST_EV_TYPE_MSG_EVENT
,
40 TEST_EV_TYPE_MSG_STREAM_BEGIN
,
41 TEST_EV_TYPE_MSG_PACKET_BEGIN
,
42 TEST_EV_TYPE_MSG_PACKET_END
,
43 TEST_EV_TYPE_MSG_STREAM_END
,
45 TEST_EV_TYPE_SENTINEL
,
49 enum test_event_type type
;
50 const bt_stream
*stream
;
51 const bt_packet
*packet
;
54 static bool debug
= false;
55 static enum test current_test
;
56 static GArray
*test_events
;
57 static bt_graph
*graph
;
58 static bt_stream_class
*src_stream_class
;
59 static bt_event_class
*src_event_class
;
60 static bt_stream
*src_stream1
;
61 static bt_stream
*src_stream2
;
62 static bt_packet
*src_stream1_packet1
;
63 static bt_packet
*src_stream1_packet2
;
64 static bt_packet
*src_stream2_packet1
;
65 static 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 bt_self_component_port_input_message_iterator
*msg_iter
;
97 * No automatic messages generated in this block.
98 * Stream 2 messages are more indented.
100 static int64_t seq_no_auto_msgs
[] = {
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_MSG_UNEXPECTED
:
133 fprintf(fp
, "TEST_EV_TYPE_MSG_UNEXPECTED");
135 case TEST_EV_TYPE_MSG_EVENT
:
136 fprintf(fp
, "TEST_EV_TYPE_MSG_EVENT");
138 case TEST_EV_TYPE_MSG_STREAM_BEGIN
:
139 fprintf(fp
, "TEST_EV_TYPE_MSG_STREAM_BEGIN");
141 case TEST_EV_TYPE_MSG_STREAM_END
:
142 fprintf(fp
, "TEST_EV_TYPE_MSG_STREAM_END");
144 case TEST_EV_TYPE_MSG_PACKET_BEGIN
:
145 fprintf(fp
, "TEST_EV_TYPE_MSG_PACKET_BEGIN");
147 case TEST_EV_TYPE_MSG_PACKET_END
:
148 fprintf(fp
, "TEST_EV_TYPE_MSG_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(bt_self_component_source
*self_comp
)
244 bt_trace_class
*trace_class
;
247 /* Metadata, streams, and packets*/
248 trace_class
= bt_trace_class_create(
249 bt_self_component_source_as_self_component(self_comp
));
250 BT_ASSERT(trace_class
);
251 src_stream_class
= bt_stream_class_create(trace_class
);
252 BT_ASSERT(src_stream_class
);
253 src_event_class
= bt_event_class_create(src_stream_class
);
254 BT_ASSERT(src_event_class
);
255 trace
= bt_trace_create(trace_class
);
257 src_stream1
= bt_stream_create(src_stream_class
, trace
);
258 BT_ASSERT(src_stream1
);
259 src_stream2
= bt_stream_create(src_stream_class
, trace
);
260 BT_ASSERT(src_stream2
);
261 src_stream1_packet1
= bt_packet_create(src_stream1
);
262 BT_ASSERT(src_stream1_packet1
);
263 src_stream1_packet2
= bt_packet_create(src_stream1
);
264 BT_ASSERT(src_stream1_packet2
);
265 src_stream2_packet1
= bt_packet_create(src_stream2
);
266 BT_ASSERT(src_stream2_packet1
);
267 src_stream2_packet2
= bt_packet_create(src_stream2
);
268 BT_ASSERT(src_stream2_packet2
);
271 fprintf(stderr
, ":: stream 1: %p\n", src_stream1
);
272 fprintf(stderr
, ":: stream 2: %p\n", src_stream2
);
273 fprintf(stderr
, ":: stream 1, packet 1: %p\n", src_stream1_packet1
);
274 fprintf(stderr
, ":: stream 1, packet 2: %p\n", src_stream1_packet2
);
275 fprintf(stderr
, ":: stream 2, packet 1: %p\n", src_stream2_packet1
);
276 fprintf(stderr
, ":: stream 2, packet 2: %p\n", src_stream2_packet2
);
279 bt_trace_put_ref(trace
);
280 bt_trace_class_put_ref(trace_class
);
284 void fini_static_data(void)
287 bt_stream_class_put_ref(src_stream_class
);
288 bt_event_class_put_ref(src_event_class
);
289 bt_stream_put_ref(src_stream1
);
290 bt_stream_put_ref(src_stream2
);
291 bt_packet_put_ref(src_stream1_packet1
);
292 bt_packet_put_ref(src_stream1_packet2
);
293 bt_packet_put_ref(src_stream2_packet1
);
294 bt_packet_put_ref(src_stream2_packet2
);
298 void src_iter_finalize(bt_self_message_iterator
*self_msg_iter
)
300 struct src_iter_user_data
*user_data
=
301 bt_self_message_iterator_get_data(
310 bt_self_message_iterator_status
src_iter_init(
311 bt_self_message_iterator
*self_msg_iter
,
312 bt_self_component_source
*self_comp
,
313 bt_self_component_port_output
*self_port
)
315 struct src_iter_user_data
*user_data
=
316 g_new0(struct src_iter_user_data
, 1);
318 BT_ASSERT(user_data
);
319 bt_self_message_iterator_set_data(self_msg_iter
, user_data
);
321 switch (current_test
) {
322 case TEST_NO_AUTO_MSGS
:
323 case TEST_OUTPUT_PORT_MESSAGE_ITERATOR
:
324 user_data
->seq
= seq_no_auto_msgs
;
330 return BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
334 void src_iter_next_seq_one(bt_self_message_iterator
* msg_iter
,
335 struct src_iter_user_data
*user_data
,
336 const bt_message
**msg
)
338 bt_packet
*event_packet
= NULL
;
340 switch (user_data
->seq
[user_data
->at
]) {
341 case SEQ_STREAM1_BEGIN
:
342 *msg
= bt_message_stream_beginning_create(msg_iter
,
345 case SEQ_STREAM2_BEGIN
:
346 *msg
= bt_message_stream_beginning_create(msg_iter
,
349 case SEQ_STREAM1_END
:
350 *msg
= bt_message_stream_end_create(msg_iter
,
353 case SEQ_STREAM2_END
:
354 *msg
= bt_message_stream_end_create(msg_iter
,
357 case SEQ_STREAM1_PACKET1_BEGIN
:
358 *msg
= bt_message_packet_beginning_create(msg_iter
,
359 src_stream1_packet1
);
361 case SEQ_STREAM1_PACKET2_BEGIN
:
362 *msg
= bt_message_packet_beginning_create(msg_iter
,
363 src_stream1_packet2
);
365 case SEQ_STREAM2_PACKET1_BEGIN
:
366 *msg
= bt_message_packet_beginning_create(msg_iter
,
367 src_stream2_packet1
);
369 case SEQ_STREAM2_PACKET2_BEGIN
:
370 *msg
= bt_message_packet_beginning_create(msg_iter
,
371 src_stream2_packet2
);
373 case SEQ_STREAM1_PACKET1_END
:
374 *msg
= bt_message_packet_end_create(msg_iter
,
375 src_stream1_packet1
);
377 case SEQ_STREAM1_PACKET2_END
:
378 *msg
= bt_message_packet_end_create(msg_iter
,
379 src_stream1_packet2
);
381 case SEQ_STREAM2_PACKET1_END
:
382 *msg
= bt_message_packet_end_create(msg_iter
,
383 src_stream2_packet1
);
385 case SEQ_STREAM2_PACKET2_END
:
386 *msg
= bt_message_packet_end_create(msg_iter
,
387 src_stream2_packet2
);
389 case SEQ_EVENT_STREAM1_PACKET1
:
390 event_packet
= src_stream1_packet1
;
392 case SEQ_EVENT_STREAM1_PACKET2
:
393 event_packet
= src_stream1_packet2
;
395 case SEQ_EVENT_STREAM2_PACKET1
:
396 event_packet
= src_stream2_packet1
;
398 case SEQ_EVENT_STREAM2_PACKET2
:
399 event_packet
= src_stream2_packet2
;
406 *msg
= bt_message_event_create(msg_iter
,
416 bt_self_message_iterator_status
src_iter_next_seq(
417 bt_self_message_iterator
*msg_iter
,
418 struct src_iter_user_data
*user_data
,
419 bt_message_array_const msgs
, uint64_t capacity
,
422 bt_self_message_iterator_status status
=
423 BT_SELF_MESSAGE_ITERATOR_STATUS_OK
;
426 BT_ASSERT(user_data
->seq
);
428 if (user_data
->seq
[user_data
->at
] == SEQ_END
) {
429 status
= BT_SELF_MESSAGE_ITERATOR_STATUS_END
;
433 while (i
< capacity
&& user_data
->seq
[user_data
->at
] != SEQ_END
) {
434 src_iter_next_seq_one(msg_iter
, user_data
, &msgs
[i
]);
438 BT_ASSERT(i
> 0 && i
<= capacity
);
446 bt_self_message_iterator_status
src_iter_next(
447 bt_self_message_iterator
*self_msg_iter
,
448 bt_message_array_const msgs
, uint64_t capacity
,
451 struct src_iter_user_data
*user_data
=
452 bt_self_message_iterator_get_data(self_msg_iter
);
454 BT_ASSERT(user_data
);
455 return src_iter_next_seq(self_msg_iter
, user_data
, msgs
,
460 bt_self_component_status
src_init(
461 bt_self_component_source
*self_comp
,
462 const bt_value
*params
, void *init_method_data
)
466 init_static_data(self_comp
);
467 ret
= bt_self_component_source_add_output_port(
468 self_comp
, "out", NULL
, NULL
);
470 return BT_SELF_COMPONENT_STATUS_OK
;
474 void src_finalize(bt_self_component_source
*self_comp
)
479 void append_test_events_from_message(const bt_message
*message
)
481 struct test_event test_event
= { 0 };
483 switch (bt_message_get_type(message
)) {
484 case BT_MESSAGE_TYPE_EVENT
:
486 const bt_event
*event
;
488 test_event
.type
= TEST_EV_TYPE_MSG_EVENT
;
489 event
= bt_message_event_borrow_event_const(message
);
491 test_event
.packet
= bt_event_borrow_packet_const(event
);
492 BT_ASSERT(test_event
.packet
);
495 case BT_MESSAGE_TYPE_STREAM_BEGINNING
:
496 test_event
.type
= TEST_EV_TYPE_MSG_STREAM_BEGIN
;
498 bt_message_stream_beginning_borrow_stream_const(message
);
499 BT_ASSERT(test_event
.stream
);
501 case BT_MESSAGE_TYPE_STREAM_END
:
502 test_event
.type
= TEST_EV_TYPE_MSG_STREAM_END
;
504 bt_message_stream_end_borrow_stream_const(message
);
505 BT_ASSERT(test_event
.stream
);
507 case BT_MESSAGE_TYPE_PACKET_BEGINNING
:
508 test_event
.type
= TEST_EV_TYPE_MSG_PACKET_BEGIN
;
510 bt_message_packet_beginning_borrow_packet_const(message
);
511 BT_ASSERT(test_event
.packet
);
513 case BT_MESSAGE_TYPE_PACKET_END
:
514 test_event
.type
= TEST_EV_TYPE_MSG_PACKET_END
;
516 bt_message_packet_end_borrow_packet_const(message
);
517 BT_ASSERT(test_event
.packet
);
520 test_event
.type
= TEST_EV_TYPE_MSG_UNEXPECTED
;
524 if (test_event
.packet
) {
525 test_event
.stream
= bt_packet_borrow_stream_const(
527 BT_ASSERT(test_event
.stream
);
530 append_test_event(&test_event
);
534 bt_message_iterator_status
common_consume(
535 void *msg_iter
, bool is_output_port_msg_iter
)
537 bt_message_iterator_status ret
;
538 bt_message_array_const messages
= NULL
;
540 struct test_event test_event
= { 0 };
545 if (is_output_port_msg_iter
) {
546 ret
= bt_port_output_message_iterator_next(msg_iter
,
549 ret
= bt_self_component_port_input_message_iterator_next(
550 msg_iter
, &messages
, &count
);
558 case BT_MESSAGE_ITERATOR_STATUS_END
:
559 test_event
.type
= TEST_EV_TYPE_END
;
560 append_test_event(&test_event
);
562 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
569 BT_ASSERT(count
> 0);
571 for (i
= 0; i
< count
; i
++) {
572 append_test_events_from_message(messages
[i
]);
573 bt_message_put_ref(messages
[i
]);
581 bt_self_component_status
sink_consume(
582 bt_self_component_sink
*self_comp
)
584 bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
585 struct sink_user_data
*user_data
=
586 bt_self_component_get_data(
587 bt_self_component_sink_as_self_component(
589 bt_message_iterator_status it_ret
;
591 BT_ASSERT(user_data
&& user_data
->msg_iter
);
592 it_ret
= common_consume(user_data
->msg_iter
, false);
595 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
600 case BT_MESSAGE_ITERATOR_STATUS_END
:
601 ret
= BT_SELF_COMPONENT_STATUS_END
;
602 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(
603 user_data
->msg_iter
);
605 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
616 bt_self_component_status
sink_port_connected(
617 bt_self_component_sink
*self_comp
,
618 bt_self_component_port_input
*self_port
,
619 const bt_port_output
*other_port
)
621 struct sink_user_data
*user_data
=
622 bt_self_component_get_data(
623 bt_self_component_sink_as_self_component(
626 BT_ASSERT(user_data
);
627 user_data
->msg_iter
=
628 bt_self_component_port_input_message_iterator_create(
630 return BT_SELF_COMPONENT_STATUS_OK
;
634 bt_self_component_status
sink_init(
635 bt_self_component_sink
*self_comp
,
636 const bt_value
*params
, void *init_method_data
)
638 struct sink_user_data
*user_data
= g_new0(struct sink_user_data
, 1);
641 BT_ASSERT(user_data
);
642 bt_self_component_set_data(
643 bt_self_component_sink_as_self_component(self_comp
),
645 ret
= bt_self_component_sink_add_input_port(
646 self_comp
, "in", NULL
, NULL
);
648 return BT_SELF_COMPONENT_STATUS_OK
;
652 void sink_finalize(bt_self_component_sink
*self_comp
)
654 struct sink_user_data
*user_data
=
655 bt_self_component_get_data(
656 bt_self_component_sink_as_self_component(
660 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(
661 user_data
->msg_iter
);
667 void create_source_sink(bt_graph
*graph
,
668 const bt_component_source
**source
,
669 const bt_component_sink
**sink
)
671 bt_component_class_source
*src_comp_class
;
672 bt_component_class_sink
*sink_comp_class
;
675 /* Create source component */
677 src_comp_class
= bt_component_class_source_create("src",
679 BT_ASSERT(src_comp_class
);
680 ret
= bt_component_class_source_set_init_method(
681 src_comp_class
, src_init
);
683 ret
= bt_component_class_source_set_finalize_method(
684 src_comp_class
, src_finalize
);
686 ret
= bt_component_class_source_set_message_iterator_init_method(
687 src_comp_class
, src_iter_init
);
689 ret
= bt_component_class_source_set_message_iterator_finalize_method(
690 src_comp_class
, src_iter_finalize
);
692 ret
= bt_graph_add_source_component(graph
,
693 src_comp_class
, "source", NULL
, source
);
695 bt_component_class_source_put_ref(src_comp_class
);
698 /* Create sink component */
700 sink_comp_class
= bt_component_class_sink_create("sink",
702 BT_ASSERT(sink_comp_class
);
703 ret
= bt_component_class_sink_set_init_method(
704 sink_comp_class
, sink_init
);
706 ret
= bt_component_class_sink_set_finalize_method(
707 sink_comp_class
, sink_finalize
);
708 ret
= bt_component_class_sink_set_input_port_connected_method(
709 sink_comp_class
, sink_port_connected
);
711 ret
= bt_graph_add_sink_component(graph
,
715 bt_component_class_sink_put_ref(sink_comp_class
);
719 typedef void (*compare_func_t
)(void);
722 void do_std_test(enum test test
, const char *name
, compare_func_t compare_func
)
724 const bt_component_source
*src_comp
;
725 const bt_component_sink
*sink_comp
;
726 const bt_port_output
*upstream_port
;
727 const bt_port_input
*downstream_port
;
728 bt_graph_status graph_status
= BT_GRAPH_STATUS_OK
;
732 diag("test: %s", name
);
734 graph
= bt_graph_create();
736 create_source_sink(graph
, &src_comp
, &sink_comp
);
738 /* Connect source to sink */
740 bt_component_source_borrow_output_port_by_name_const(
742 BT_ASSERT(upstream_port
);
743 downstream_port
= bt_component_sink_borrow_input_port_by_name_const(
745 BT_ASSERT(downstream_port
);
746 graph_status
= bt_graph_connect_ports(graph
, upstream_port
,
747 downstream_port
, NULL
);
749 /* Run the graph until the end */
750 while (graph_status
== BT_GRAPH_STATUS_OK
||
751 graph_status
== BT_GRAPH_STATUS_AGAIN
) {
752 graph_status
= bt_graph_run(graph
);
755 ok(graph_status
== BT_GRAPH_STATUS_END
,
756 "graph finishes without any error");
758 /* Compare the resulting test events */
763 bt_component_source_put_ref(src_comp
);
764 bt_component_sink_put_ref(sink_comp
);
766 BT_GRAPH_PUT_REF_AND_RESET(graph
);
770 void test_no_auto_msgs_compare(void)
772 const struct test_event expected_test_events
[] = {
773 { .type
= TEST_EV_TYPE_MSG_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
774 { .type
= TEST_EV_TYPE_MSG_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
775 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
776 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
777 { .type
= TEST_EV_TYPE_MSG_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
778 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
779 { .type
= TEST_EV_TYPE_MSG_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
780 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
781 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
782 { .type
= TEST_EV_TYPE_MSG_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
783 { .type
= TEST_EV_TYPE_MSG_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
784 { .type
= TEST_EV_TYPE_MSG_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
785 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
786 { .type
= TEST_EV_TYPE_MSG_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
787 { .type
= TEST_EV_TYPE_MSG_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
788 { .type
= TEST_EV_TYPE_MSG_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
789 { .type
= TEST_EV_TYPE_END
, },
790 { .type
= TEST_EV_TYPE_SENTINEL
, },
793 ok(compare_test_events(expected_test_events
),
794 "the produced sequence of test events is the expected one");
798 void test_no_auto_msgs(void)
800 do_std_test(TEST_NO_AUTO_MSGS
, "no automatic messages",
801 test_no_auto_msgs_compare
);
805 void test_output_port_message_iterator(void)
807 const bt_component_source
*src_comp
;
808 bt_port_output_message_iterator
*msg_iter
;
809 bt_message_iterator_status iter_status
=
810 BT_MESSAGE_ITERATOR_STATUS_OK
;
811 const bt_port_output
*upstream_port
;
814 current_test
= TEST_OUTPUT_PORT_MESSAGE_ITERATOR
;
815 diag("test: output port message iterator");
817 graph
= bt_graph_create();
819 create_source_sink(graph
, &src_comp
, NULL
);
821 /* Create message iterator on source's output port */
822 upstream_port
= bt_component_source_borrow_output_port_by_name_const(
824 msg_iter
= bt_port_output_message_iterator_create(graph
, upstream_port
);
825 ok(msg_iter
, "bt_private_output_port_message_iterator_create() succeeds");
827 /* Consume the message iterator */
828 while (iter_status
== BT_MESSAGE_ITERATOR_STATUS_OK
) {
829 iter_status
= common_consume(msg_iter
, true);
832 ok(iter_status
== BT_MESSAGE_ITERATOR_STATUS_END
,
833 "output port message iterator finishes without any error");
835 /* Compare the resulting test events */
837 const struct test_event expected_test_events
[] = {
838 { .type
= TEST_EV_TYPE_MSG_STREAM_BEGIN
, .stream
= src_stream1
, .packet
= NULL
, },
839 { .type
= TEST_EV_TYPE_MSG_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
840 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
841 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
842 { .type
= TEST_EV_TYPE_MSG_STREAM_BEGIN
, .stream
= src_stream2
, .packet
= NULL
, },
843 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
844 { .type
= TEST_EV_TYPE_MSG_PACKET_BEGIN
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
845 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
846 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
847 { .type
= TEST_EV_TYPE_MSG_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet1
, },
848 { .type
= TEST_EV_TYPE_MSG_PACKET_END
, .stream
= src_stream2
, .packet
= src_stream2_packet2
, },
849 { .type
= TEST_EV_TYPE_MSG_PACKET_BEGIN
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
850 { .type
= TEST_EV_TYPE_MSG_EVENT
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
851 { .type
= TEST_EV_TYPE_MSG_STREAM_END
, .stream
= src_stream2
, .packet
= NULL
, },
852 { .type
= TEST_EV_TYPE_MSG_PACKET_END
, .stream
= src_stream1
, .packet
= src_stream1_packet2
, },
853 { .type
= TEST_EV_TYPE_MSG_STREAM_END
, .stream
= src_stream1
, .packet
= NULL
, },
854 { .type
= TEST_EV_TYPE_END
, },
855 { .type
= TEST_EV_TYPE_SENTINEL
, },
858 ok(compare_test_events(expected_test_events
),
859 "the produced sequence of test events is the expected one");
863 bt_component_source_put_ref(src_comp
);
864 BT_GRAPH_PUT_REF_AND_RESET(graph
);
865 bt_port_output_message_iterator_put_ref(msg_iter
);
868 #define DEBUG_ENV_VAR "TEST_BT_MESSAGE_ITERATOR_DEBUG"
870 int main(int argc
, char **argv
)
872 if (getenv(DEBUG_ENV_VAR
) && strcmp(getenv(DEBUG_ENV_VAR
), "1") == 0) {
876 plan_tests(NR_TESTS
);
877 test_events
= g_array_new(FALSE
, TRUE
, sizeof(struct test_event
));
878 BT_ASSERT(test_events
);
880 test_output_port_message_iterator();
881 g_array_free(test_events
, TRUE
);
882 return exit_status();