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