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