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