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