Make libctfcopytrace a convenience lib. and link to it in plugins
[babeltrace.git] / tests / plugins / test-utils-muxer.c
CommitLineData
8deeabc6
PP
1/*
2 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
3 *
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.
7 *
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.
12 *
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.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <stdint.h>
21#include <inttypes.h>
22#include <string.h>
23#include <assert.h>
24#include <babeltrace/ctf-ir/event-class.h>
25#include <babeltrace/ctf-ir/event.h>
26#include <babeltrace/ctf-ir/field-types.h>
27#include <babeltrace/ctf-ir/fields.h>
28#include <babeltrace/ctf-ir/packet.h>
29#include <babeltrace/ctf-ir/stream-class.h>
30#include <babeltrace/ctf-ir/stream.h>
31#include <babeltrace/ctf-ir/trace.h>
32#include <babeltrace/graph/clock-class-priority-map.h>
33#include <babeltrace/graph/component-class-filter.h>
34#include <babeltrace/graph/component-class-sink.h>
35#include <babeltrace/graph/component-class-source.h>
36#include <babeltrace/graph/component-class.h>
37#include <babeltrace/graph/component-filter.h>
38#include <babeltrace/graph/component-sink.h>
39#include <babeltrace/graph/component-source.h>
40#include <babeltrace/graph/component.h>
41#include <babeltrace/graph/graph.h>
42#include <babeltrace/graph/notification-event.h>
43#include <babeltrace/graph/notification-inactivity.h>
44#include <babeltrace/graph/notification-iterator.h>
45#include <babeltrace/graph/notification-packet.h>
46#include <babeltrace/graph/port.h>
47#include <babeltrace/graph/private-component-source.h>
48#include <babeltrace/graph/private-component.h>
49#include <babeltrace/graph/private-connection.h>
50#include <babeltrace/graph/private-notification-iterator.h>
51#include <babeltrace/graph/private-port.h>
52#include <babeltrace/plugin/plugin.h>
53#include <babeltrace/ref.h>
54#include <glib.h>
55
56#include "tap/tap.h"
57
3230ee6b 58#define NR_TESTS 12
8deeabc6
PP
59
60enum test {
61 TEST_NO_TS,
62 TEST_NO_UPSTREAM_CONNECTION,
8deeabc6
PP
63 TEST_SIMPLE_4_PORTS,
64 TEST_4_PORTS_WITH_RETRIES,
65 TEST_SINGLE_END_THEN_MULTIPLE_FULL,
66 TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL,
67};
68
69enum test_event_type {
70 TEST_EV_TYPE_NOTIF_UNEXPECTED,
71 TEST_EV_TYPE_NOTIF_EVENT,
72 TEST_EV_TYPE_NOTIF_INACTIVITY,
73 TEST_EV_TYPE_NOTIF_PACKET_BEGIN,
74 TEST_EV_TYPE_NOTIF_PACKET_END,
3230ee6b
PP
75 TEST_EV_TYPE_NOTIF_STREAM_BEGIN,
76 TEST_EV_TYPE_NOTIF_STREAM_END,
8deeabc6
PP
77 TEST_EV_TYPE_AGAIN,
78 TEST_EV_TYPE_END,
79 TEST_EV_TYPE_SENTINEL,
80};
81
82struct test_event {
83 enum test_event_type type;
84 int64_t ts_ns;
85};
86
87struct source_muxer_sink {
88 struct bt_component *source;
89 struct bt_component *muxer;
90 struct bt_component *sink;
91};
92
93struct graph_listener_data {
94 struct bt_graph *graph;
95 struct bt_component *source;
96 struct bt_component *muxer;
97 struct bt_component *sink;
98};
99
100static bool debug = false;
101static enum test current_test;
102static GArray *test_events;
103static struct bt_clock_class_priority_map *src_cc_prio_map;
104static struct bt_clock_class_priority_map *src_empty_cc_prio_map;
105static struct bt_ctf_clock_class *src_clock_class;
106static struct bt_ctf_stream_class *src_stream_class;
107static struct bt_ctf_event_class *src_event_class;
3230ee6b
PP
108static struct bt_ctf_packet *src_packet0;
109static struct bt_ctf_packet *src_packet1;
110static struct bt_ctf_packet *src_packet2;
111static struct bt_ctf_packet *src_packet3;
8deeabc6
PP
112
113enum {
114 SEQ_END = -1,
115 SEQ_AGAIN = -2,
116 SEQ_PACKET_BEGIN = -3,
117 SEQ_PACKET_END = -4,
118};
119
120struct src_iter_user_data {
121 size_t iter_index;
122 int64_t *seq;
123 size_t at;
3230ee6b 124 struct bt_ctf_packet *packet;
8deeabc6
PP
125};
126
127struct sink_user_data {
128 struct bt_notification_iterator *notif_iter;
129};
130
131static int64_t seq1[] = {
132 24, 53, 97, 105, 119, 210, 222, 240, 292, 317, 353, 407, 433,
133 473, 487, 504, 572, 615, 708, 766, 850, 852, 931, 951, 956, 996,
134 SEQ_END,
135};
136
137static int64_t seq2[] = {
138 51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631,
139 644, 668, 714, 744, 750, 778, 790, 836, SEQ_END,
140};
141
142static int64_t seq3[] = {
143 8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, 678, 717,
144 731, 733, 788, 819, 820, 857, 892, 903, 944, 998, SEQ_END,
145};
146
147static int64_t seq4[] = {
148 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591, 605, 612,
149 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985, 999,
150 SEQ_END,
151};
152
153static int64_t seq1_with_again[] = {
154 24, 53, 97, 105, 119, 210, SEQ_AGAIN, SEQ_AGAIN, 222, 240, 292,
155 317, 353, 407, 433, 473, 487, 504, 572, 615, 708, 766, 850, 852,
156 931, 951, 956, 996, SEQ_END,
157};
158
159static int64_t seq2_with_again[] = {
160 51, 59, 68, 77, 91, 121, 139, 170, 179, 266, 352, 454, 478, 631,
161 644, 668, 714, 744, 750, 778, 790, 836, SEQ_AGAIN, SEQ_AGAIN,
162 SEQ_END,
163};
164
165static int64_t seq3_with_again[] = {
166 8, 71, 209, 254, 298, 320, 350, 393, 419, 624, 651, SEQ_AGAIN,
167 SEQ_AGAIN, 678, 717, 731, 733, 788, 819, 820, 857, 892, 903,
168 944, 998, SEQ_END,
169};
170
171static int64_t seq4_with_again[] = {
172 SEQ_AGAIN, 41, 56, 120, 138, 154, 228, 471, 479, 481, 525, 591,
173 605, 612, 618, 632, 670, 696, 825, 863, 867, 871, 884, 953, 985,
174 999, SEQ_END,
175};
176
177static int64_t seq5[] = {
178 1, 4, 189, 1001, SEQ_END,
179};
180
8deeabc6
PP
181static
182void clear_test_events(void)
183{
184 g_array_set_size(test_events, 0);
185}
186
187static
188void print_test_event(FILE *fp, const struct test_event *event)
189{
190 fprintf(fp, "{ type = ");
191
192 switch (event->type) {
193 case TEST_EV_TYPE_NOTIF_UNEXPECTED:
194 fprintf(fp, "TEST_EV_TYPE_NOTIF_UNEXPECTED");
195 break;
196 case TEST_EV_TYPE_NOTIF_EVENT:
197 fprintf(fp, "TEST_EV_TYPE_NOTIF_EVENT");
198 break;
199 case TEST_EV_TYPE_NOTIF_INACTIVITY:
200 fprintf(fp, "TEST_EV_TYPE_NOTIF_INACTIVITY");
201 break;
202 case TEST_EV_TYPE_NOTIF_PACKET_BEGIN:
203 fprintf(fp, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN");
204 break;
205 case TEST_EV_TYPE_NOTIF_PACKET_END:
206 fprintf(fp, "TEST_EV_TYPE_NOTIF_PACKET_END");
207 break;
3230ee6b
PP
208 case TEST_EV_TYPE_NOTIF_STREAM_BEGIN:
209 fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN");
210 break;
211 case TEST_EV_TYPE_NOTIF_STREAM_END:
212 fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_END");
213 break;
8deeabc6
PP
214 case TEST_EV_TYPE_AGAIN:
215 fprintf(fp, "TEST_EV_TYPE_AGAIN");
216 break;
217 case TEST_EV_TYPE_END:
218 fprintf(fp, "TEST_EV_TYPE_END");
219 break;
220 case TEST_EV_TYPE_SENTINEL:
221 fprintf(fp, "TEST_EV_TYPE_SENTINEL");
222 break;
223 default:
224 fprintf(fp, "(UNKNOWN)");
225 break;
226 }
227
228 switch (event->type) {
229 case TEST_EV_TYPE_NOTIF_EVENT:
230 case TEST_EV_TYPE_NOTIF_INACTIVITY:
231 fprintf(fp, ", ts-ns = %" PRId64, event->ts_ns);
232 default:
233 break;
234 }
235
236 fprintf(fp, " }");
237}
238
239static
240void append_test_event(struct test_event *event)
241{
242 g_array_append_val(test_events, *event);
243}
244
245static
246bool compare_single_test_events(const struct test_event *ev_a,
247 const struct test_event *ev_b)
248{
249 if (debug) {
250 fprintf(stderr, ":: Comparing test events: ");
251 print_test_event(stderr, ev_a);
252 fprintf(stderr, " vs. ");
253 print_test_event(stderr, ev_b);
254 fprintf(stderr, "\n");
255 }
256
257 if (ev_a->type != ev_b->type) {
258 return false;
259 }
260
261 switch (ev_a->type) {
262 case TEST_EV_TYPE_NOTIF_EVENT:
263 case TEST_EV_TYPE_NOTIF_INACTIVITY:
264 if (ev_a->ts_ns != ev_b->ts_ns) {
265 return false;
266 }
267 break;
268 default:
269 break;
270 }
271
272 return true;
273}
274
275static
276bool compare_test_events(const struct test_event *expected_events)
277{
278 const struct test_event *expected_event = expected_events;
279 size_t i = 0;
280
281 assert(expected_events);
282
283 while (true) {
284 const struct test_event *event;
285
286 if (expected_event->type == TEST_EV_TYPE_SENTINEL) {
287 break;
288 }
289
290 if (i >= test_events->len) {
291 return false;
292 }
293
294 event = &g_array_index(test_events, struct test_event, i);
295
296 if (!compare_single_test_events(event, expected_event)) {
297 return false;
298 }
299
300 i++;
301 expected_event++;
302 }
303
304 if (i != test_events->len) {
305 return false;
306 }
307
308 return true;
309}
310
311static
312void init_static_data(void)
313{
314 int ret;
315 struct bt_ctf_trace *trace;
316 struct bt_ctf_stream *stream;
317 struct bt_ctf_field_type *empty_struct_ft;
318
319 /* Test events */
320 test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event));
321 assert(test_events);
322
323 /* Metadata */
324 empty_struct_ft = bt_ctf_field_type_structure_create();
325 assert(empty_struct_ft);
326 trace = bt_ctf_trace_create();
327 assert(trace);
328 ret = bt_ctf_trace_set_native_byte_order(trace,
329 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
330 assert(ret == 0);
331 ret = bt_ctf_trace_set_packet_header_type(trace, empty_struct_ft);
332 assert(ret == 0);
333 src_clock_class = bt_ctf_clock_class_create("my-clock");
334 assert(src_clock_class);
335 ret = bt_ctf_clock_class_set_is_absolute(src_clock_class, 1);
336 assert(ret == 0);
337 ret = bt_ctf_trace_add_clock_class(trace, src_clock_class);
338 assert(ret == 0);
339 src_empty_cc_prio_map = bt_clock_class_priority_map_create();
340 assert(src_empty_cc_prio_map);
341 src_cc_prio_map = bt_clock_class_priority_map_create();
342 assert(src_cc_prio_map);
343 ret = bt_clock_class_priority_map_add_clock_class(src_cc_prio_map,
344 src_clock_class, 0);
345 assert(ret == 0);
346 src_stream_class = bt_ctf_stream_class_create("my-stream-class");
347 assert(src_stream_class);
348 ret = bt_ctf_stream_class_set_packet_context_type(src_stream_class,
349 empty_struct_ft);
350 assert(ret == 0);
351 ret = bt_ctf_stream_class_set_event_header_type(src_stream_class,
352 empty_struct_ft);
353 assert(ret == 0);
354 ret = bt_ctf_stream_class_set_event_context_type(src_stream_class,
355 empty_struct_ft);
356 assert(ret == 0);
357 src_event_class = bt_ctf_event_class_create("my-event-class");
358 ret = bt_ctf_event_class_set_context_type(src_event_class,
359 empty_struct_ft);
360 assert(ret == 0);
361 ret = bt_ctf_event_class_set_context_type(src_event_class,
362 empty_struct_ft);
363 assert(ret == 0);
364 ret = bt_ctf_stream_class_add_event_class(src_stream_class,
365 src_event_class);
366 assert(ret == 0);
367 ret = bt_ctf_trace_add_stream_class(trace, src_stream_class);
368 assert(ret == 0);
3230ee6b
PP
369 stream = bt_ctf_stream_create(src_stream_class, "stream0");
370 assert(stream);
371 src_packet0 = bt_ctf_packet_create(stream);
372 assert(src_packet0);
373 bt_put(stream);
374 stream = bt_ctf_stream_create(src_stream_class, "stream1");
8deeabc6 375 assert(stream);
3230ee6b
PP
376 src_packet1 = bt_ctf_packet_create(stream);
377 assert(src_packet0);
378 bt_put(stream);
379 stream = bt_ctf_stream_create(src_stream_class, "stream2");
380 assert(stream);
381 src_packet2 = bt_ctf_packet_create(stream);
382 assert(src_packet0);
383 bt_put(stream);
384 stream = bt_ctf_stream_create(src_stream_class, "stream3");
385 assert(stream);
386 src_packet3 = bt_ctf_packet_create(stream);
387 assert(src_packet0);
388 bt_put(stream);
8deeabc6
PP
389
390 bt_put(trace);
8deeabc6
PP
391 bt_put(empty_struct_ft);
392}
393
394static
395void fini_static_data(void)
396{
397 /* Test events */
398 g_array_free(test_events, TRUE);
399
400 /* Metadata */
401 bt_put(src_empty_cc_prio_map);
402 bt_put(src_cc_prio_map);
403 bt_put(src_clock_class);
404 bt_put(src_stream_class);
405 bt_put(src_event_class);
3230ee6b
PP
406 bt_put(src_packet0);
407 bt_put(src_packet1);
408 bt_put(src_packet2);
409 bt_put(src_packet3);
8deeabc6
PP
410}
411
412static
413void src_iter_finalize(
414 struct bt_private_notification_iterator *private_notification_iterator)
415{
416 struct src_iter_user_data *user_data =
417 bt_private_notification_iterator_get_user_data(
418 private_notification_iterator);
419
420 if (user_data) {
421 g_free(user_data);
422 }
423}
424
425static
426enum bt_notification_iterator_status src_iter_init(
427 struct bt_private_notification_iterator *priv_notif_iter,
428 struct bt_private_port *private_port)
429{
430 struct src_iter_user_data *user_data =
431 g_new0(struct src_iter_user_data, 1);
432 struct bt_port *port = bt_port_from_private_port(private_port);
433 const char *port_name;
434 int ret;
435
436 assert(user_data);
437 assert(port);
438 ret = bt_private_notification_iterator_set_user_data(priv_notif_iter,
439 user_data);
440 assert(ret == 0);
441 port_name = bt_port_get_name(port);
442 assert(port_name);
443 user_data->iter_index = port_name[3] - '0';
444 bt_put(port);
445
3230ee6b
PP
446 switch (user_data->iter_index) {
447 case 0:
448 user_data->packet = src_packet0;
449 break;
450 case 1:
451 user_data->packet = src_packet1;
452 break;
453 case 2:
454 user_data->packet = src_packet2;
455 break;
456 case 3:
457 user_data->packet = src_packet3;
458 break;
459 default:
460 assert(false);
461 }
462
8deeabc6
PP
463 switch (current_test) {
464 case TEST_NO_TS:
465 if (user_data->iter_index == 1) {
466 user_data->seq = seq5;
467 }
468 break;
8deeabc6
PP
469 case TEST_SIMPLE_4_PORTS:
470 if (user_data->iter_index == 0) {
471 user_data->seq = seq1;
472 } else if (user_data->iter_index == 1) {
473 user_data->seq = seq2;
474 } else if (user_data->iter_index == 2) {
475 user_data->seq = seq3;
476 } else {
477 user_data->seq = seq4;
478 }
479 break;
480 case TEST_4_PORTS_WITH_RETRIES:
481 if (user_data->iter_index == 0) {
482 user_data->seq = seq1_with_again;
483 } else if (user_data->iter_index == 1) {
484 user_data->seq = seq2_with_again;
485 } else if (user_data->iter_index == 2) {
486 user_data->seq = seq3_with_again;
487 } else {
488 user_data->seq = seq4_with_again;
489 }
490 break;
491 case TEST_SINGLE_END_THEN_MULTIPLE_FULL:
492 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL:
493 if (user_data->iter_index == 0) {
494 /* Ignore: this iterator only returns END */
495 } else if (user_data->iter_index == 1) {
496 user_data->seq = seq2;
497 } else {
498 user_data->seq = seq3;
499 }
500 break;
501 default:
502 assert(false);
503 }
504
505 return BT_NOTIFICATION_ITERATOR_STATUS_OK;
506}
507
508static
3230ee6b
PP
509struct bt_ctf_event *src_create_event(struct bt_ctf_packet *packet,
510 int64_t ts_ns)
8deeabc6
PP
511{
512 struct bt_ctf_event *event = bt_ctf_event_create(src_event_class);
513 int ret;
514
515 assert(event);
3230ee6b 516 ret = bt_ctf_event_set_packet(event, packet);
8deeabc6
PP
517 assert(ret == 0);
518
519 if (ts_ns != -1) {
520 struct bt_ctf_clock_value *clock_value;
521
522 clock_value = bt_ctf_clock_value_create(src_clock_class,
523 (uint64_t) ts_ns);
524 assert(clock_value);
525 ret = bt_ctf_event_set_clock_value(event, clock_value);
526 bt_put(clock_value);
527 }
528
529 return event;
530}
531
532static
533struct bt_notification_iterator_next_return src_iter_next_seq(
534 struct src_iter_user_data *user_data)
535{
536 struct bt_notification_iterator_next_return next_return = {
537 .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
538 };
539 int64_t cur_ts_ns;
540
541 assert(user_data->seq);
542 cur_ts_ns = user_data->seq[user_data->at];
543
544 switch (cur_ts_ns) {
545 case SEQ_END:
546 next_return.status =
547 BT_NOTIFICATION_ITERATOR_STATUS_END;
548 break;
549 case SEQ_AGAIN:
550 next_return.status =
551 BT_NOTIFICATION_ITERATOR_STATUS_AGAIN;
552 break;
553 case SEQ_PACKET_BEGIN:
554 next_return.notification =
3230ee6b 555 bt_notification_packet_begin_create(user_data->packet);
8deeabc6
PP
556 assert(next_return.notification);
557 break;
558 case SEQ_PACKET_END:
559 next_return.notification =
3230ee6b 560 bt_notification_packet_end_create(user_data->packet);
8deeabc6
PP
561 assert(next_return.notification);
562 break;
563 default:
564 {
3230ee6b
PP
565 struct bt_ctf_event *event = src_create_event(
566 user_data->packet, cur_ts_ns);
8deeabc6
PP
567
568 assert(event);
569 next_return.notification = bt_notification_event_create(event,
570 src_cc_prio_map);
571 bt_put(event);
572 assert(next_return.notification);
573 break;
574 }
575 }
576
577 if (next_return.status != BT_NOTIFICATION_ITERATOR_STATUS_END) {
578 user_data->at++;
579 }
580
581 return next_return;
582}
583
584static
585struct bt_notification_iterator_next_return src_iter_next(
586 struct bt_private_notification_iterator *priv_iterator)
587{
588 struct bt_notification_iterator_next_return next_return = {
589 .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
590 .notification = NULL,
591 };
592 struct src_iter_user_data *user_data =
593 bt_private_notification_iterator_get_user_data(priv_iterator);
594 struct bt_private_component *private_component =
595 bt_private_notification_iterator_get_private_component(priv_iterator);
596
597 assert(user_data);
598 assert(private_component);
599
600 switch (current_test) {
601 case TEST_NO_TS:
602 if (user_data->iter_index == 0) {
603 if (user_data->at == 0) {
604 next_return.notification =
3230ee6b
PP
605 bt_notification_packet_begin_create(
606 user_data->packet);
8deeabc6
PP
607 assert(next_return.notification);
608 } else if (user_data->at < 6) {
3230ee6b
PP
609 struct bt_ctf_event *event = src_create_event(
610 user_data->packet, -1);
8deeabc6
PP
611
612 assert(event);
613 next_return.notification =
614 bt_notification_event_create(event,
615 src_empty_cc_prio_map);
616 assert(next_return.notification);
617 bt_put(event);
618 } else {
619 next_return.status =
620 BT_NOTIFICATION_ITERATOR_STATUS_END;
621 }
622
623 user_data->at++;
624 } else {
625 next_return = src_iter_next_seq(user_data);
626 }
627 break;
8deeabc6
PP
628 case TEST_SIMPLE_4_PORTS:
629 case TEST_4_PORTS_WITH_RETRIES:
630 next_return = src_iter_next_seq(user_data);
631 break;
632 case TEST_SINGLE_END_THEN_MULTIPLE_FULL:
633 if (user_data->iter_index == 0) {
634 struct bt_private_port *priv_port;
635
636 priv_port = bt_private_component_source_add_output_private_port(
637 private_component, "out1");
638 assert(priv_port);
639 bt_put(priv_port);
640 priv_port = bt_private_component_source_add_output_private_port(
641 private_component, "out2");
642 assert(priv_port);
643 bt_put(priv_port);
644 next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END;
645 } else {
646 next_return = src_iter_next_seq(user_data);
647 }
648 break;
649 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL:
650 if (user_data->iter_index == 0) {
651 if (user_data->at == 0) {
652 next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN;
653 user_data->at++;
654 } else {
655 struct bt_private_port *priv_port;
656
657 priv_port = bt_private_component_source_add_output_private_port(
658 private_component, "out1");
659 assert(priv_port);
660 bt_put(priv_port);
661 priv_port = bt_private_component_source_add_output_private_port(
662 private_component, "out2");
663 assert(priv_port);
664 bt_put(priv_port);
665 next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END;
666 }
667 } else {
668 next_return = src_iter_next_seq(user_data);
669 }
670 break;
671 default:
672 assert(false);
673 }
674
675 bt_put(private_component);
676 return next_return;
677}
678
679static
680enum bt_component_status src_init(
681 struct bt_private_component *private_component,
682 struct bt_value *params, void *init_method_data)
683{
684 struct bt_private_port *priv_port;
685 int ret;
686 size_t nb_ports;
687
688 priv_port = bt_private_component_source_get_default_output_private_port(
689 private_component);
690 if (priv_port) {
691 ret = bt_private_port_remove_from_component(priv_port);
692 assert(ret == 0);
693 bt_put(priv_port);
694 }
695
696 switch (current_test) {
697 case TEST_NO_TS:
8deeabc6
PP
698 nb_ports = 2;
699 break;
700 case TEST_SINGLE_END_THEN_MULTIPLE_FULL:
701 case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL:
702 nb_ports = 1;
703 break;
704 default:
705 nb_ports = 4;
706 break;
707 }
708
709 if (nb_ports >= 1) {
710 priv_port = bt_private_component_source_add_output_private_port(
711 private_component, "out0");
712 assert(priv_port);
713 bt_put(priv_port);
714 }
715
716 if (nb_ports >= 2) {
717 priv_port = bt_private_component_source_add_output_private_port(
718 private_component, "out1");
719 assert(priv_port);
720 bt_put(priv_port);
721 }
722
723 if (nb_ports >= 3) {
724 priv_port = bt_private_component_source_add_output_private_port(
725 private_component, "out2");
726 assert(priv_port);
727 bt_put(priv_port);
728 }
729
730 if (nb_ports >= 4) {
731 priv_port = bt_private_component_source_add_output_private_port(
732 private_component, "out3");
733 assert(priv_port);
734 bt_put(priv_port);
735 }
736
737 return BT_COMPONENT_STATUS_OK;
738}
739
740static
741void src_finalize(struct bt_private_component *private_component)
742{
743}
744
745static
746enum bt_component_status sink_consume(
747 struct bt_private_component *priv_component)
748{
749 enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
750 struct bt_notification *notification = NULL;
751 struct sink_user_data *user_data =
752 bt_private_component_get_user_data(priv_component);
753 enum bt_notification_iterator_status it_ret;
754 struct test_event test_event;
755 bool do_append_test_event = true;
756
757 assert(user_data && user_data->notif_iter);
758 it_ret = bt_notification_iterator_next(user_data->notif_iter);
759
760 if (it_ret < 0) {
761 ret = BT_COMPONENT_STATUS_ERROR;
762 do_append_test_event = false;
763 goto end;
764 }
765
766 switch (it_ret) {
767 case BT_NOTIFICATION_ITERATOR_STATUS_END:
768 test_event.type = TEST_EV_TYPE_END;
769 ret = BT_COMPONENT_STATUS_END;
770 BT_PUT(user_data->notif_iter);
771 goto end;
772 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
773 test_event.type = TEST_EV_TYPE_AGAIN;
774 ret = BT_COMPONENT_STATUS_AGAIN;
775 goto end;
776 default:
777 break;
778 }
779
780 notification = bt_notification_iterator_get_notification(
781 user_data->notif_iter);
782 assert(notification);
783
784 switch (bt_notification_get_type(notification)) {
785 case BT_NOTIFICATION_TYPE_EVENT:
786 {
787 struct bt_ctf_event *event;
788 struct bt_clock_class_priority_map *cc_prio_map;
789
790 test_event.type = TEST_EV_TYPE_NOTIF_EVENT;
791 cc_prio_map =
792 bt_notification_event_get_clock_class_priority_map(
793 notification);
794 assert(cc_prio_map);
795 event = bt_notification_event_get_event(notification);
796 assert(event);
797
798 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) {
799 struct bt_ctf_clock_value *clock_value;
800 struct bt_ctf_clock_class *clock_class =
801 bt_clock_class_priority_map_get_highest_priority_clock_class(
802 cc_prio_map);
803
804 assert(clock_class);
805 clock_value = bt_ctf_event_get_clock_value(event,
806 clock_class);
807 assert(clock_value);
808 ret = bt_ctf_clock_value_get_value_ns_from_epoch(
809 clock_value, &test_event.ts_ns);
810 assert(ret == 0);
811 bt_put(clock_value);
812 bt_put(clock_class);
813 } else {
814 test_event.ts_ns = -1;
815 }
816
817 bt_put(cc_prio_map);
818 bt_put(event);
819 break;
820 }
821 case BT_NOTIFICATION_TYPE_INACTIVITY:
822 {
823 struct bt_clock_class_priority_map *cc_prio_map;
824
825 test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY;
826 cc_prio_map = bt_notification_event_get_clock_class_priority_map(
827 notification);
828 assert(cc_prio_map);
829
830 if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) {
831 struct bt_ctf_clock_value *clock_value;
832 struct bt_ctf_clock_class *clock_class =
833 bt_clock_class_priority_map_get_highest_priority_clock_class(
834 cc_prio_map);
835
836 assert(clock_class);
837 clock_value =
838 bt_notification_inactivity_get_clock_value(
839 notification, clock_class);
840 assert(clock_value);
841 ret = bt_ctf_clock_value_get_value_ns_from_epoch(
842 clock_value, &test_event.ts_ns);
843 assert(ret == 0);
844 bt_put(clock_value);
845 bt_put(clock_class);
846 } else {
847 test_event.ts_ns = -1;
848 }
849
850 bt_put(cc_prio_map);
851 break;
852 }
853 case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
854 test_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN;
855 break;
856 case BT_NOTIFICATION_TYPE_PACKET_END:
857 test_event.type = TEST_EV_TYPE_NOTIF_PACKET_END;
858 break;
3230ee6b
PP
859 case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
860 test_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN;
861 break;
862 case BT_NOTIFICATION_TYPE_STREAM_END:
863 test_event.type = TEST_EV_TYPE_NOTIF_STREAM_END;
864 break;
8deeabc6
PP
865 default:
866 test_event.type = TEST_EV_TYPE_NOTIF_UNEXPECTED;
867 break;
868 }
869
870end:
871 if (do_append_test_event) {
872 append_test_event(&test_event);
873 }
874
875 bt_put(notification);
876 return ret;
877}
878
879static
880void sink_port_connected(struct bt_private_component *private_component,
881 struct bt_private_port *self_private_port,
882 struct bt_port *other_port)
883{
884 struct bt_private_connection *priv_conn =
885 bt_private_port_get_private_connection(self_private_port);
886 struct sink_user_data *user_data = bt_private_component_get_user_data(
887 private_component);
888
889 assert(user_data);
890 assert(priv_conn);
891 user_data->notif_iter =
892 bt_private_connection_create_notification_iterator(priv_conn);
893 assert(user_data->notif_iter);
894 bt_put(priv_conn);
895}
896
897static
898enum bt_component_status sink_init(
899 struct bt_private_component *private_component,
900 struct bt_value *params, void *init_method_data)
901{
902 struct sink_user_data *user_data = g_new0(struct sink_user_data, 1);
903 int ret;
904
905 assert(user_data);
906 ret = bt_private_component_set_user_data(private_component,
907 user_data);
908 assert(ret == 0);
909 return BT_COMPONENT_STATUS_OK;
910}
911
912static
913void sink_finalize(struct bt_private_component *private_component)
914{
915 struct sink_user_data *user_data = bt_private_component_get_user_data(
916 private_component);
917
918 if (user_data) {
919 bt_put(user_data->notif_iter);
920 g_free(user_data);
921 }
922}
923
924static
925void create_source_muxer_sink(struct bt_component **source,
926 struct bt_component **muxer,
927 struct bt_component **sink)
928{
929 struct bt_component_class *src_comp_class;
930 struct bt_component_class *muxer_comp_class;
931 struct bt_component_class *sink_comp_class;
932 int ret;
933
934 /* Create source component */
935 src_comp_class = bt_component_class_source_create("src", src_iter_next);
936 assert(src_comp_class);
937 ret = bt_component_class_set_init_method(src_comp_class, src_init);
938 assert(ret == 0);
939 ret = bt_component_class_set_finalize_method(src_comp_class,
940 src_finalize);
941 assert(ret == 0);
942 ret = bt_component_class_source_set_notification_iterator_init_method(
943 src_comp_class, src_iter_init);
944 assert(ret == 0);
945 ret = bt_component_class_source_set_notification_iterator_finalize_method(
946 src_comp_class, src_iter_finalize);
947 assert(ret == 0);
948 *source = bt_component_create(src_comp_class, "source", NULL);
949 assert(*source);
950
951 /* Create muxer component */
952 muxer_comp_class = bt_plugin_find_component_class("utils", "muxer",
953 BT_COMPONENT_CLASS_TYPE_FILTER);
954 assert(muxer_comp_class);
955 *muxer = bt_component_create(muxer_comp_class, "muxer", NULL);
956 assert(*muxer);
957
958 /* Create sink component */
959 sink_comp_class = bt_component_class_sink_create("sink", sink_consume);
960 assert(sink_comp_class);
961 ret = bt_component_class_set_init_method(sink_comp_class, sink_init);
962 assert(ret == 0);
963 ret = bt_component_class_set_finalize_method(sink_comp_class,
964 sink_finalize);
965 ret = bt_component_class_set_port_connected_method(sink_comp_class,
966 sink_port_connected);
967 assert(ret == 0);
968 *sink = bt_component_create(sink_comp_class, "sink", NULL);
969
970 bt_put(src_comp_class);
971 bt_put(muxer_comp_class);
972 bt_put(sink_comp_class);
973}
974
975static
976void do_std_test(enum test test, const char *name,
977 const struct test_event *expected_test_events,
978 bool with_upstream)
979{
980 struct bt_component *src_comp;
981 struct bt_component *muxer_comp;
982 struct bt_component *sink_comp;
983 struct bt_port *upstream_port;
984 struct bt_port *downstream_port;
985 struct bt_graph *graph;
544d0515
PP
986 int64_t i;
987 int64_t count;
8deeabc6 988 void *conn;
8deeabc6
PP
989 enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
990
991 clear_test_events();
992 current_test = test;
993 diag("test: %s", name);
994 create_source_muxer_sink(&src_comp, &muxer_comp, &sink_comp);
995 graph = bt_graph_create();
996 assert(graph);
997
998 /* Connect source output ports to muxer input ports */
999 if (with_upstream) {
544d0515
PP
1000 count = bt_component_source_get_output_port_count(src_comp);
1001 assert(count >= 0);
8deeabc6
PP
1002
1003 for (i = 0; i < count; i++) {
1004 upstream_port = bt_component_source_get_output_port_at_index(
1005 src_comp, i);
1006 assert(upstream_port);
1007 downstream_port = bt_component_filter_get_input_port_at_index(
1008 muxer_comp, i);
1009 assert(downstream_port);
1010 conn = bt_graph_connect_ports(graph,
1011 upstream_port, downstream_port);
1012 assert(conn);
1013 bt_put(conn);
1014 bt_put(upstream_port);
1015 bt_put(downstream_port);
1016 }
1017 }
1018
1019 /* Connect muxer output port to sink input port */
1020 upstream_port = bt_component_filter_get_output_port(muxer_comp,
1021 "out");
1022 assert(upstream_port);
1023 downstream_port = bt_component_sink_get_default_input_port(sink_comp);
1024 assert(downstream_port);
1025 conn = bt_graph_connect_ports(graph, upstream_port, downstream_port);
1026 assert(conn);
1027 bt_put(conn);
1028 bt_put(upstream_port);
1029 bt_put(downstream_port);
1030
1031 while (graph_status == BT_GRAPH_STATUS_OK ||
1032 graph_status == BT_GRAPH_STATUS_AGAIN) {
1033 graph_status = bt_graph_run(graph);
1034 }
1035
1036 ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error");
1037 ok(compare_test_events(expected_test_events),
1038 "the produced sequence of test events is the expected one");
1039
1040 bt_put(src_comp);
1041 bt_put(muxer_comp);
1042 bt_put(sink_comp);
1043 bt_put(graph);
1044}
1045
1046static
1047void test_no_ts(void)
1048{
1049 const struct test_event expected_test_events[] = {
3230ee6b
PP
1050 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1051 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1052 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
8deeabc6
PP
1053 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1054 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
1055 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
1056 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
1057 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
1058 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, },
3230ee6b
PP
1059 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1060 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1061 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 1, },
1062 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 4, },
1063 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 189, },
1064 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 1001, },
3230ee6b
PP
1065 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1066 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1067 { .type = TEST_EV_TYPE_END, },
1068 { .type = TEST_EV_TYPE_SENTINEL, },
1069 };
1070
1071 do_std_test(TEST_NO_TS, "event notifications with no time",
1072 expected_test_events, true);
1073}
1074
1075static
1076void test_no_upstream_connection(void)
1077{
1078 const struct test_event expected_test_events[] = {
1079 { .type = TEST_EV_TYPE_END, },
1080 { .type = TEST_EV_TYPE_SENTINEL, },
1081 };
1082
1083 do_std_test(TEST_NO_UPSTREAM_CONNECTION, "no upstream connection",
1084 expected_test_events, false);
1085}
1086
1087static
3230ee6b 1088void test_simple_4_ports(void)
8deeabc6
PP
1089{
1090 const struct test_event expected_test_events[] = {
3230ee6b 1091 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
8deeabc6 1092 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
3230ee6b
PP
1093 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1094 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1095 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1096 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1097 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
8deeabc6 1098 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
8deeabc6
PP
1099 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
1100 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 24 },
1101 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 41 },
1102 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 },
1103 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 53 },
1104 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 56 },
1105 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 },
1106 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 },
1107 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 },
1108 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 },
1109 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 },
1110 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 97 },
1111 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 105 },
1112 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 119 },
1113 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 120 },
1114 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 },
1115 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 138 },
1116 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 },
1117 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 154 },
1118 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 },
1119 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 },
1120 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 },
1121 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 210 },
1122 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 222 },
1123 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 228 },
1124 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 240 },
1125 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 },
1126 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 },
1127 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 292 },
1128 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 },
1129 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 317 },
1130 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 },
1131 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 },
1132 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 },
1133 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 353 },
1134 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 },
1135 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 407 },
1136 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 },
1137 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 433 },
1138 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 },
1139 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 471 },
1140 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 473 },
1141 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 },
1142 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 479 },
1143 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 481 },
1144 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 487 },
1145 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 504 },
1146 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 525 },
1147 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 572 },
1148 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 591 },
1149 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 605 },
1150 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 612 },
1151 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 615 },
1152 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 618 },
1153 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 },
1154 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 },
1155 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 632 },
1156 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 },
1157 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 },
1158 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 },
1159 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 670 },
1160 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 },
1161 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 696 },
1162 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 708 },
1163 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 },
1164 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 },
1165 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 },
1166 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 },
1167 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 },
1168 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 },
1169 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 766 },
1170 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 },
1171 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 },
1172 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 },
1173 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 },
1174 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 },
1175 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 825 },
1176 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
3230ee6b
PP
1177 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1178 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1179 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 850 },
1180 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 852 },
1181 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
1182 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 863 },
1183 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 867 },
1184 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 871 },
1185 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 884 },
1186 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 },
1187 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 },
1188 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 931 },
1189 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 },
1190 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 951 },
1191 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 953 },
1192 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 956 },
1193 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 985 },
1194 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 996 },
3230ee6b
PP
1195 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1196 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6 1197 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
3230ee6b
PP
1198 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1199 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6 1200 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 999 },
3230ee6b
PP
1201 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1202 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1203 { .type = TEST_EV_TYPE_END, },
1204 { .type = TEST_EV_TYPE_SENTINEL, },
1205 };
1206
1207 do_std_test(TEST_SIMPLE_4_PORTS, "simple: 4 ports without retries",
1208 expected_test_events, true);
1209}
1210
1211static
1212void test_4_ports_with_retries(void)
1213{
1214 const struct test_event expected_test_events[] = {
1215 { .type = TEST_EV_TYPE_AGAIN, },
3230ee6b
PP
1216 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1217 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1218 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1219 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1220 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1221 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1222 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1223 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
8deeabc6
PP
1224 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
1225 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 24 },
1226 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 41 },
1227 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 },
1228 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 53 },
1229 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 56 },
1230 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 },
1231 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 },
1232 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 },
1233 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 },
1234 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 },
1235 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 97 },
1236 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 105 },
1237 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 119 },
1238 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 120 },
1239 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 },
1240 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 138 },
1241 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 },
1242 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 154 },
1243 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 },
1244 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 },
1245 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 },
1246 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 210 },
1247 { .type = TEST_EV_TYPE_AGAIN, },
1248 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 222 },
1249 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 228 },
1250 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 240 },
1251 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 },
1252 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 },
1253 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 292 },
1254 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 },
1255 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 317 },
1256 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 },
1257 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 },
1258 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 },
1259 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 353 },
1260 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 },
1261 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 407 },
1262 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 },
1263 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 433 },
1264 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 },
1265 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 471 },
1266 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 473 },
1267 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 },
1268 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 479 },
1269 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 481 },
1270 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 487 },
1271 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 504 },
1272 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 525 },
1273 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 572 },
1274 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 591 },
1275 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 605 },
1276 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 612 },
1277 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 615 },
1278 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 618 },
1279 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 },
1280 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 },
1281 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 632 },
1282 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 },
1283 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 },
1284 { .type = TEST_EV_TYPE_AGAIN, },
1285 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 },
1286 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 670 },
1287 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 },
1288 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 696 },
1289 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 708 },
1290 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 },
1291 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 },
1292 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 },
1293 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 },
1294 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 },
1295 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 },
1296 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 766 },
1297 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 },
1298 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 },
1299 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 },
1300 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 },
1301 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 },
1302 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 825 },
1303 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
1304 { .type = TEST_EV_TYPE_AGAIN, },
3230ee6b
PP
1305 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1306 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1307 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 850 },
1308 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 852 },
1309 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
1310 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 863 },
1311 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 867 },
1312 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 871 },
1313 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 884 },
1314 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 },
1315 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 },
1316 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 931 },
1317 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 },
1318 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 951 },
1319 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 953 },
1320 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 956 },
1321 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 985 },
1322 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 996 },
3230ee6b
PP
1323 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1324 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6 1325 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
3230ee6b
PP
1326 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1327 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6 1328 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 999 },
3230ee6b
PP
1329 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1330 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1331 { .type = TEST_EV_TYPE_END, },
1332 { .type = TEST_EV_TYPE_SENTINEL, },
1333 };
1334
1335 do_std_test(TEST_4_PORTS_WITH_RETRIES, "4 ports with retries",
1336 expected_test_events, true);
1337}
1338
1339static
1340void connect_port_to_first_avail_muxer_port(struct bt_graph *graph,
1341 struct bt_port *source_port,
1342 struct bt_component *muxer_comp)
1343{
1344 struct bt_port *avail_muxer_port = NULL;
1345 void *conn;
544d0515
PP
1346 int64_t i;
1347 int64_t count;
8deeabc6 1348
544d0515
PP
1349 count = bt_component_filter_get_input_port_count(muxer_comp);
1350 assert(count >= 0);
8deeabc6
PP
1351
1352 for (i = 0; i < count; i++) {
1353 struct bt_port *muxer_port =
1354 bt_component_filter_get_input_port_at_index(
1355 muxer_comp, i);
1356
1357 assert(muxer_port);
1358
1359 if (!bt_port_is_connected(muxer_port)) {
1360 BT_MOVE(avail_muxer_port, muxer_port);
1361 break;
1362 } else {
1363 bt_put(muxer_port);
1364 }
1365 }
1366
1367 conn = bt_graph_connect_ports(graph, source_port, avail_muxer_port);
1368 assert(conn);
1369 bt_put(conn);
1370 bt_put(avail_muxer_port);
1371}
1372
1373static
1374void graph_port_added_listener_connect_to_avail_muxer_port(struct bt_port *port,
1375 void *data)
1376{
1377 struct graph_listener_data *graph_listener_data = data;
1378 struct bt_component *comp;
1379
1380 comp = bt_port_get_component(port);
1381 assert(comp);
1382
1383 if (comp != graph_listener_data->source) {
1384 goto end;
1385 }
1386
1387 connect_port_to_first_avail_muxer_port(graph_listener_data->graph,
1388 port, graph_listener_data->muxer);
1389
1390end:
1391 bt_put(comp);
1392}
1393
1394static
1395void test_single_end_then_multiple_full(void)
1396{
1397 struct bt_component *src_comp;
1398 struct bt_component *muxer_comp;
1399 struct bt_component *sink_comp;
1400 struct bt_port *upstream_port;
1401 struct bt_port *downstream_port;
1402 struct bt_graph *graph;
544d0515
PP
1403 int64_t i;
1404 int64_t count;
8deeabc6
PP
1405 void *conn;
1406 int ret;
1407 enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
1408 struct graph_listener_data graph_listener_data;
1409 const struct test_event expected_test_events[] = {
3230ee6b
PP
1410 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1411 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1412 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1413 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
8deeabc6
PP
1414 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
1415 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 },
1416 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 },
1417 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 },
1418 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 },
1419 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 },
1420 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 },
1421 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 },
1422 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 },
1423 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 },
1424 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 },
1425 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 },
1426 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 },
1427 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 },
1428 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 },
1429 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 },
1430 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 },
1431 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 },
1432 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 },
1433 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 },
1434 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 },
1435 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 },
1436 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 },
1437 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 },
1438 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 },
1439 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 },
1440 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 },
1441 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 },
1442 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 },
1443 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 },
1444 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 },
1445 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 },
1446 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 },
1447 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 },
1448 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 },
1449 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 },
1450 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 },
1451 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 },
1452 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 },
1453 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
3230ee6b
PP
1454 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1455 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1456 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
1457 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 },
1458 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 },
1459 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 },
1460 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
3230ee6b
PP
1461 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1462 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1463 { .type = TEST_EV_TYPE_END, },
1464 { .type = TEST_EV_TYPE_SENTINEL, },
1465 };
1466
1467 clear_test_events();
1468 current_test = TEST_SINGLE_END_THEN_MULTIPLE_FULL;
1469 diag("test: single end then multiple full");
1470 create_source_muxer_sink(&src_comp, &muxer_comp, &sink_comp);
1471 graph = bt_graph_create();
1472 assert(graph);
1473 graph_listener_data.graph = graph;
1474 graph_listener_data.source = src_comp;
1475 graph_listener_data.muxer = muxer_comp;
1476 graph_listener_data.sink = sink_comp;
1477 ret = bt_graph_add_port_added_listener(graph,
1478 graph_port_added_listener_connect_to_avail_muxer_port,
1479 &graph_listener_data);
1480 assert(ret == 0);
1481
1482 /* Connect source output ports to muxer input ports */
544d0515 1483 count = bt_component_source_get_output_port_count(src_comp);
8deeabc6
PP
1484 assert(ret == 0);
1485
1486 for (i = 0; i < count; i++) {
1487 upstream_port = bt_component_source_get_output_port_at_index(
1488 src_comp, i);
1489 assert(upstream_port);
1490 connect_port_to_first_avail_muxer_port(graph,
1491 upstream_port, muxer_comp);
1492 bt_put(upstream_port);
1493 }
1494
1495 /* Connect muxer output port to sink input port */
1496 upstream_port = bt_component_filter_get_output_port(muxer_comp,
1497 "out");
1498 assert(upstream_port);
1499 downstream_port = bt_component_sink_get_default_input_port(sink_comp);
1500 assert(downstream_port);
1501 conn = bt_graph_connect_ports(graph, upstream_port, downstream_port);
1502 assert(conn);
1503 bt_put(conn);
1504 bt_put(upstream_port);
1505 bt_put(downstream_port);
1506
1507 while (graph_status == BT_GRAPH_STATUS_OK ||
1508 graph_status == BT_GRAPH_STATUS_AGAIN) {
1509 graph_status = bt_graph_run(graph);
1510 }
1511
1512 ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error");
1513 ok(compare_test_events(expected_test_events),
1514 "the produced sequence of test events is the expected one");
1515
1516 bt_put(src_comp);
1517 bt_put(muxer_comp);
1518 bt_put(sink_comp);
1519 bt_put(graph);
1520}
1521
1522static
1523void test_single_again_end_then_multiple_full(void)
1524{
1525 struct bt_component *src_comp;
1526 struct bt_component *muxer_comp;
1527 struct bt_component *sink_comp;
1528 struct bt_port *upstream_port;
1529 struct bt_port *downstream_port;
1530 struct bt_graph *graph;
544d0515
PP
1531 int64_t i;
1532 int64_t count;
8deeabc6
PP
1533 void *conn;
1534 int ret;
1535 enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
1536 struct graph_listener_data graph_listener_data;
1537 const struct test_event expected_test_events[] = {
1538 { .type = TEST_EV_TYPE_AGAIN, },
3230ee6b
PP
1539 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1540 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
1541 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, },
1542 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, },
8deeabc6
PP
1543 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 },
1544 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 },
1545 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 },
1546 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 },
1547 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 },
1548 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 },
1549 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 },
1550 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 },
1551 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 },
1552 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 },
1553 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 },
1554 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 },
1555 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 },
1556 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 },
1557 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 },
1558 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 },
1559 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 },
1560 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 },
1561 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 },
1562 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 },
1563 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 },
1564 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 },
1565 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 },
1566 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 },
1567 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 },
1568 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 },
1569 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 },
1570 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 },
1571 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 },
1572 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 },
1573 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 },
1574 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 },
1575 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 },
1576 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 },
1577 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 },
1578 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 },
1579 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 },
1580 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 },
1581 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 },
1582 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 },
3230ee6b
PP
1583 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1584 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1585 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 },
1586 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 },
1587 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 },
1588 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 },
1589 { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 },
3230ee6b
PP
1590 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, },
1591 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, },
8deeabc6
PP
1592 { .type = TEST_EV_TYPE_END, },
1593 { .type = TEST_EV_TYPE_SENTINEL, },
1594 };
1595
1596 clear_test_events();
1597 current_test = TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL;
1598 diag("test: single again then end then multiple full");
1599 create_source_muxer_sink(&src_comp, &muxer_comp, &sink_comp);
1600 graph = bt_graph_create();
1601 assert(graph);
1602 graph_listener_data.graph = graph;
1603 graph_listener_data.source = src_comp;
1604 graph_listener_data.muxer = muxer_comp;
1605 graph_listener_data.sink = sink_comp;
1606 ret = bt_graph_add_port_added_listener(graph,
1607 graph_port_added_listener_connect_to_avail_muxer_port,
1608 &graph_listener_data);
1609 assert(ret == 0);
1610
1611 /* Connect source output ports to muxer input ports */
544d0515 1612 count = bt_component_source_get_output_port_count(src_comp);
8deeabc6
PP
1613 assert(ret == 0);
1614
1615 for (i = 0; i < count; i++) {
1616 upstream_port = bt_component_source_get_output_port_at_index(
1617 src_comp, i);
1618 assert(upstream_port);
1619 connect_port_to_first_avail_muxer_port(graph,
1620 upstream_port, muxer_comp);
1621 bt_put(upstream_port);
1622 }
1623
1624 /* Connect muxer output port to sink input port */
1625 upstream_port = bt_component_filter_get_output_port(muxer_comp,
1626 "out");
1627 assert(upstream_port);
1628 downstream_port = bt_component_sink_get_default_input_port(sink_comp);
1629 assert(downstream_port);
1630 conn = bt_graph_connect_ports(graph, upstream_port, downstream_port);
1631 assert(conn);
1632 bt_put(conn);
1633 bt_put(upstream_port);
1634 bt_put(downstream_port);
1635
1636 while (graph_status == BT_GRAPH_STATUS_OK ||
1637 graph_status == BT_GRAPH_STATUS_AGAIN) {
1638 graph_status = bt_graph_run(graph);
1639 }
1640
1641 ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error");
1642 ok(compare_test_events(expected_test_events),
1643 "the produced sequence of test events is the expected one");
1644
1645 bt_put(src_comp);
1646 bt_put(muxer_comp);
1647 bt_put(sink_comp);
1648 bt_put(graph);
1649}
1650
1651#define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG"
1652
1653int main(int argc, char **argv)
1654{
1655 if (getenv(DEBUG_ENV_VAR) && strcmp(getenv(DEBUG_ENV_VAR), "1") == 0) {
1656 debug = true;
1657 }
1658
1659 plan_tests(NR_TESTS);
1660 init_static_data();
1661 test_no_ts();
1662 test_no_upstream_connection();
8deeabc6
PP
1663 test_simple_4_ports();
1664 test_4_ports_with_retries();
1665 test_single_end_then_multiple_full();
1666 test_single_again_end_then_multiple_full();
1667 fini_static_data();
1668 return exit_status();
1669}
This page took 0.097371 seconds and 4 git commands to generate.