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