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