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