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