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; |
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 | 133 | SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 24, 53, 97, 105, 119, 210, |
3fd7b79d PP |
134 | SEQ_AGAIN, SEQ_AGAIN, 222, 240, 292, 317, 353, 407, 433, 473, |
135 | 487, 504, 572, 615, 708, 766, 850, 852, 931, 951, 956, 996, | |
6ff151ad | 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, | |
3fd7b79d PP |
142 | 778, 790, 836, SEQ_AGAIN, SEQ_AGAIN, SEQ_PACKET_END, |
143 | SEQ_STREAM_END, SEQ_END, | |
8deeabc6 PP |
144 | }; |
145 | ||
146 | static int64_t seq3_with_again[] = { | |
6ff151ad | 147 | SEQ_STREAM_BEGIN, SEQ_PACKET_BEGIN, 8, 71, 209, 254, 298, 320, |
3fd7b79d PP |
148 | 350, 393, 419, 624, 651, SEQ_AGAIN, SEQ_AGAIN, 678, 717, 731, |
149 | 733, 788, 819, 820, 857, 892, 903, 944, 998, SEQ_PACKET_END, | |
6ff151ad | 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 | ||
b8f13b8b | 265 | BT_ASSERT(expected_events); |
8deeabc6 PP |
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)); | |
b8f13b8b | 311 | BT_ASSERT(test_events); |
8deeabc6 PP |
312 | |
313 | /* Metadata */ | |
839d52a5 | 314 | empty_struct_ft = bt_field_type_structure_create(); |
b8f13b8b | 315 | BT_ASSERT(empty_struct_ft); |
a6918753 | 316 | src_clock_class = bt_clock_class_create("my-clock", 1000000000); |
b8f13b8b | 317 | BT_ASSERT(src_clock_class); |
839d52a5 | 318 | trace = bt_trace_create(); |
b8f13b8b | 319 | BT_ASSERT(trace); |
839d52a5 PP |
320 | ret = bt_trace_set_native_byte_order(trace, |
321 | BT_BYTE_ORDER_LITTLE_ENDIAN); | |
b8f13b8b | 322 | BT_ASSERT(ret == 0); |
8deee039 | 323 | ret = bt_trace_set_packet_header_field_type(trace, empty_struct_ft); |
b8f13b8b | 324 | BT_ASSERT(ret == 0); |
839d52a5 | 325 | ret = bt_clock_class_set_is_absolute(src_clock_class, 1); |
b8f13b8b | 326 | BT_ASSERT(ret == 0); |
839d52a5 | 327 | ret = bt_trace_add_clock_class(trace, src_clock_class); |
b8f13b8b | 328 | BT_ASSERT(ret == 0); |
8deeabc6 | 329 | src_empty_cc_prio_map = bt_clock_class_priority_map_create(); |
b8f13b8b | 330 | BT_ASSERT(src_empty_cc_prio_map); |
8deeabc6 | 331 | src_cc_prio_map = bt_clock_class_priority_map_create(); |
b8f13b8b | 332 | BT_ASSERT(src_cc_prio_map); |
8deeabc6 PP |
333 | ret = bt_clock_class_priority_map_add_clock_class(src_cc_prio_map, |
334 | src_clock_class, 0); | |
b8f13b8b | 335 | BT_ASSERT(ret == 0); |
839d52a5 | 336 | src_stream_class = bt_stream_class_create("my-stream-class"); |
b8f13b8b | 337 | BT_ASSERT(src_stream_class); |
8deee039 | 338 | ret = bt_stream_class_set_packet_context_field_type(src_stream_class, |
8deeabc6 | 339 | empty_struct_ft); |
b8f13b8b | 340 | BT_ASSERT(ret == 0); |
a6918753 | 341 | eh_ft = bt_field_type_structure_create(); |
b8f13b8b | 342 | BT_ASSERT(eh_ft); |
a6918753 | 343 | eh_ts_ft = bt_field_type_integer_create(64); |
b8f13b8b | 344 | BT_ASSERT(eh_ts_ft); |
a6918753 | 345 | ret = bt_field_type_structure_add_field(eh_ft, eh_ts_ft, "ts"); |
b8f13b8b | 346 | BT_ASSERT(ret == 0); |
a6918753 PP |
347 | ret = bt_field_type_integer_set_mapped_clock_class(eh_ts_ft, |
348 | src_clock_class); | |
b8f13b8b | 349 | BT_ASSERT(ret == 0); |
8deee039 | 350 | ret = bt_stream_class_set_event_header_field_type(src_stream_class, |
a6918753 | 351 | eh_ft); |
b8f13b8b | 352 | BT_ASSERT(ret == 0); |
8deee039 | 353 | ret = bt_stream_class_set_event_context_field_type(src_stream_class, |
8deeabc6 | 354 | empty_struct_ft); |
b8f13b8b | 355 | BT_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 | 358 | empty_struct_ft); |
b8f13b8b | 359 | BT_ASSERT(ret == 0); |
8deee039 | 360 | ret = bt_event_class_set_context_field_type(src_event_class, |
8deeabc6 | 361 | empty_struct_ft); |
b8f13b8b | 362 | BT_ASSERT(ret == 0); |
839d52a5 | 363 | ret = bt_stream_class_add_event_class(src_stream_class, |
8deeabc6 | 364 | src_event_class); |
b8f13b8b | 365 | BT_ASSERT(ret == 0); |
839d52a5 | 366 | ret = bt_trace_add_stream_class(trace, src_stream_class); |
b8f13b8b | 367 | BT_ASSERT(ret == 0); |
8deee039 | 368 | stream = bt_stream_create(src_stream_class, "stream0", 0); |
b8f13b8b | 369 | BT_ASSERT(stream); |
839d52a5 | 370 | src_packet0 = bt_packet_create(stream); |
b8f13b8b | 371 | BT_ASSERT(src_packet0); |
3230ee6b | 372 | bt_put(stream); |
8deee039 | 373 | stream = bt_stream_create(src_stream_class, "stream1", 1); |
b8f13b8b | 374 | BT_ASSERT(stream); |
839d52a5 | 375 | src_packet1 = bt_packet_create(stream); |
b8f13b8b | 376 | BT_ASSERT(src_packet0); |
3230ee6b | 377 | bt_put(stream); |
8deee039 | 378 | stream = bt_stream_create(src_stream_class, "stream2", 2); |
b8f13b8b | 379 | BT_ASSERT(stream); |
839d52a5 | 380 | src_packet2 = bt_packet_create(stream); |
b8f13b8b | 381 | BT_ASSERT(src_packet0); |
3230ee6b | 382 | bt_put(stream); |
8deee039 | 383 | stream = bt_stream_create(src_stream_class, "stream3", 3); |
b8f13b8b | 384 | BT_ASSERT(stream); |
839d52a5 | 385 | src_packet3 = bt_packet_create(stream); |
b8f13b8b | 386 | BT_ASSERT(src_packet0); |
3230ee6b | 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 | ||
b8f13b8b PP |
437 | BT_ASSERT(user_data); |
438 | BT_ASSERT(port); | |
fe7265b5 | 439 | ret = bt_private_connection_private_notification_iterator_set_user_data(priv_notif_iter, |
8deeabc6 | 440 | user_data); |
b8f13b8b | 441 | BT_ASSERT(ret == 0); |
8deeabc6 | 442 | port_name = bt_port_get_name(port); |
b8f13b8b | 443 | BT_ASSERT(port_name); |
8deeabc6 | 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 | 519 | packet, cc_prio_map); |
b8f13b8b | 520 | BT_ASSERT(notif); |
a6918753 | 521 | event = bt_notification_event_borrow_event(notif); |
b8f13b8b | 522 | BT_ASSERT(event); |
a6918753 | 523 | field = bt_event_borrow_header(event); |
b8f13b8b | 524 | BT_ASSERT(field); |
a6918753 | 525 | field = bt_field_structure_borrow_field_by_name(field, "ts"); |
b8f13b8b | 526 | BT_ASSERT(field); |
a6918753 | 527 | ret = bt_field_integer_unsigned_set_value(field, (uint64_t) ts_ns); |
b8f13b8b | 528 | BT_ASSERT(ret == 0); |
a6918753 | 529 | clock_value = bt_event_borrow_clock_value(event, src_clock_class); |
b8f13b8b | 530 | BT_ASSERT(clock_value); |
a6918753 | 531 | ret = bt_clock_value_set_value(clock_value, (uint64_t) ts_ns); |
b8f13b8b | 532 | BT_ASSERT(ret == 0); |
a6918753 | 533 | return notif; |
8deeabc6 PP |
534 | } |
535 | ||
536 | static | |
3fd7b79d PP |
537 | enum bt_notification_iterator_status src_iter_next_seq( |
538 | struct src_iter_user_data *user_data, | |
539 | bt_notification_array notifs) | |
8deeabc6 | 540 | { |
3fd7b79d PP |
541 | enum bt_notification_iterator_status status = |
542 | BT_NOTIFICATION_ITERATOR_STATUS_OK; | |
8deeabc6 | 543 | int64_t cur_ts_ns; |
6ff151ad | 544 | struct bt_stream *stream; |
8deeabc6 | 545 | |
b8f13b8b | 546 | BT_ASSERT(user_data->seq); |
8deeabc6 PP |
547 | cur_ts_ns = user_data->seq[user_data->at]; |
548 | ||
549 | switch (cur_ts_ns) { | |
550 | case SEQ_END: | |
3fd7b79d | 551 | status = BT_NOTIFICATION_ITERATOR_STATUS_END; |
8deeabc6 PP |
552 | break; |
553 | case SEQ_AGAIN: | |
3fd7b79d | 554 | status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN; |
8deeabc6 PP |
555 | break; |
556 | case SEQ_PACKET_BEGIN: | |
3fd7b79d | 557 | notifs[0] = bt_notification_packet_begin_create(graph, |
f7c3ac09 | 558 | user_data->packet); |
3fd7b79d | 559 | BT_ASSERT(notifs[0]); |
8deeabc6 PP |
560 | break; |
561 | case SEQ_PACKET_END: | |
3fd7b79d | 562 | notifs[0] = bt_notification_packet_end_create(graph, |
f7c3ac09 | 563 | user_data->packet); |
3fd7b79d | 564 | BT_ASSERT(notifs[0]); |
8deeabc6 | 565 | break; |
6ff151ad PP |
566 | case SEQ_STREAM_BEGIN: |
567 | stream = bt_packet_get_stream(user_data->packet); | |
3fd7b79d PP |
568 | notifs[0] = bt_notification_stream_begin_create(graph, stream); |
569 | BT_ASSERT(notifs[0]); | |
6ff151ad PP |
570 | bt_put(stream); |
571 | break; | |
572 | case SEQ_STREAM_END: | |
573 | stream = bt_packet_get_stream(user_data->packet); | |
3fd7b79d PP |
574 | notifs[0] = bt_notification_stream_end_create(graph, stream); |
575 | BT_ASSERT(notifs[0]); | |
6ff151ad PP |
576 | bt_put(stream); |
577 | break; | |
8deeabc6 PP |
578 | default: |
579 | { | |
3fd7b79d PP |
580 | notifs[0] = src_create_event_notif(user_data->packet, |
581 | src_cc_prio_map, cur_ts_ns); | |
582 | BT_ASSERT(notifs[0]); | |
8deeabc6 PP |
583 | break; |
584 | } | |
585 | } | |
586 | ||
3fd7b79d | 587 | if (status != BT_NOTIFICATION_ITERATOR_STATUS_END) { |
8deeabc6 PP |
588 | user_data->at++; |
589 | } | |
590 | ||
3fd7b79d | 591 | return status; |
8deeabc6 PP |
592 | } |
593 | ||
594 | static | |
3fd7b79d PP |
595 | enum bt_notification_iterator_status src_iter_next( |
596 | struct bt_private_connection_private_notification_iterator *priv_iterator, | |
597 | bt_notification_array notifs, uint64_t capacity, | |
598 | uint64_t *count) | |
8deeabc6 | 599 | { |
3fd7b79d PP |
600 | enum bt_notification_iterator_status status = |
601 | BT_NOTIFICATION_ITERATOR_STATUS_OK; | |
8deeabc6 | 602 | struct src_iter_user_data *user_data = |
fe7265b5 | 603 | bt_private_connection_private_notification_iterator_get_user_data(priv_iterator); |
8deeabc6 | 604 | struct bt_private_component *private_component = |
fe7265b5 | 605 | bt_private_connection_private_notification_iterator_get_private_component(priv_iterator); |
6ff151ad | 606 | struct bt_stream *stream; |
147337a3 | 607 | int ret; |
8deeabc6 | 608 | |
b8f13b8b PP |
609 | BT_ASSERT(user_data); |
610 | BT_ASSERT(private_component); | |
8deeabc6 | 611 | |
3fd7b79d PP |
612 | /* |
613 | * We can always set it to 1: it's not going to be considered | |
614 | * anyway if the status is not | |
615 | * BT_NOTIFICATION_ITERATOR_STATUS_OK. | |
616 | */ | |
617 | *count = 1; | |
618 | ||
8deeabc6 PP |
619 | switch (current_test) { |
620 | case TEST_NO_TS: | |
621 | if (user_data->iter_index == 0) { | |
622 | if (user_data->at == 0) { | |
6ff151ad | 623 | stream = bt_packet_get_stream(user_data->packet); |
3fd7b79d | 624 | notifs[0] = |
6ff151ad | 625 | bt_notification_stream_begin_create( |
f7c3ac09 | 626 | graph, stream); |
6ff151ad | 627 | bt_put(stream); |
3fd7b79d | 628 | BT_ASSERT(notifs[0]); |
6ff151ad | 629 | } else if (user_data->at == 1) { |
3fd7b79d | 630 | notifs[0] = |
3230ee6b | 631 | bt_notification_packet_begin_create( |
f7c3ac09 | 632 | graph, user_data->packet); |
3fd7b79d | 633 | BT_ASSERT(notifs[0]); |
6ff151ad | 634 | } else if (user_data->at < 7) { |
3fd7b79d | 635 | notifs[0] = |
a6918753 PP |
636 | src_create_event_notif( |
637 | user_data->packet, | |
638 | src_empty_cc_prio_map, 0); | |
3fd7b79d | 639 | BT_ASSERT(notifs[0]); |
6ff151ad | 640 | } else if (user_data->at == 7) { |
3fd7b79d | 641 | notifs[0] = |
6ff151ad | 642 | bt_notification_packet_end_create( |
f7c3ac09 | 643 | graph, user_data->packet); |
3fd7b79d | 644 | BT_ASSERT(notifs[0]); |
6ff151ad PP |
645 | } else if (user_data->at == 8) { |
646 | stream = bt_packet_get_stream(user_data->packet); | |
3fd7b79d | 647 | notifs[0] = |
6ff151ad | 648 | bt_notification_stream_end_create( |
f7c3ac09 | 649 | graph, stream); |
6ff151ad | 650 | bt_put(stream); |
3fd7b79d | 651 | BT_ASSERT(notifs[0]); |
8deeabc6 | 652 | } else { |
3fd7b79d | 653 | status = |
8deeabc6 PP |
654 | BT_NOTIFICATION_ITERATOR_STATUS_END; |
655 | } | |
656 | ||
657 | user_data->at++; | |
658 | } else { | |
3fd7b79d | 659 | status = src_iter_next_seq(user_data, notifs); |
8deeabc6 PP |
660 | } |
661 | break; | |
8deeabc6 PP |
662 | case TEST_SIMPLE_4_PORTS: |
663 | case TEST_4_PORTS_WITH_RETRIES: | |
3fd7b79d | 664 | status = src_iter_next_seq(user_data, notifs); |
8deeabc6 PP |
665 | break; |
666 | case TEST_SINGLE_END_THEN_MULTIPLE_FULL: | |
667 | if (user_data->iter_index == 0) { | |
147337a3 PP |
668 | ret = bt_private_component_source_add_output_private_port( |
669 | private_component, "out1", NULL, NULL); | |
b8f13b8b | 670 | BT_ASSERT(ret == 0); |
147337a3 PP |
671 | ret = bt_private_component_source_add_output_private_port( |
672 | private_component, "out2", NULL, NULL); | |
b8f13b8b | 673 | BT_ASSERT(ret == 0); |
3fd7b79d | 674 | status = BT_NOTIFICATION_ITERATOR_STATUS_END; |
8deeabc6 | 675 | } else { |
3fd7b79d | 676 | status = src_iter_next_seq(user_data, notifs); |
8deeabc6 PP |
677 | } |
678 | break; | |
679 | case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL: | |
680 | if (user_data->iter_index == 0) { | |
681 | if (user_data->at == 0) { | |
3fd7b79d | 682 | status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN; |
8deeabc6 PP |
683 | user_data->at++; |
684 | } else { | |
147337a3 PP |
685 | ret = bt_private_component_source_add_output_private_port( |
686 | private_component, "out1", NULL, NULL); | |
b8f13b8b | 687 | BT_ASSERT(ret == 0); |
147337a3 PP |
688 | ret = bt_private_component_source_add_output_private_port( |
689 | private_component, "out2", NULL, NULL); | |
b8f13b8b | 690 | BT_ASSERT(ret == 0); |
3fd7b79d | 691 | status = BT_NOTIFICATION_ITERATOR_STATUS_END; |
8deeabc6 PP |
692 | } |
693 | } else { | |
3fd7b79d | 694 | status = src_iter_next_seq(user_data, notifs); |
8deeabc6 PP |
695 | } |
696 | break; | |
697 | default: | |
0fbb9a9f | 698 | abort(); |
8deeabc6 PP |
699 | } |
700 | ||
701 | bt_put(private_component); | |
3fd7b79d | 702 | return status; |
8deeabc6 PP |
703 | } |
704 | ||
705 | static | |
706 | enum bt_component_status src_init( | |
707 | struct bt_private_component *private_component, | |
708 | struct bt_value *params, void *init_method_data) | |
709 | { | |
147337a3 | 710 | int ret; |
8deeabc6 PP |
711 | size_t nb_ports; |
712 | ||
8deeabc6 PP |
713 | switch (current_test) { |
714 | case TEST_NO_TS: | |
8deeabc6 PP |
715 | nb_ports = 2; |
716 | break; | |
717 | case TEST_SINGLE_END_THEN_MULTIPLE_FULL: | |
718 | case TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL: | |
719 | nb_ports = 1; | |
720 | break; | |
721 | default: | |
722 | nb_ports = 4; | |
723 | break; | |
724 | } | |
725 | ||
726 | if (nb_ports >= 1) { | |
147337a3 PP |
727 | ret = bt_private_component_source_add_output_private_port( |
728 | private_component, "out0", NULL, NULL); | |
b8f13b8b | 729 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
730 | } |
731 | ||
732 | if (nb_ports >= 2) { | |
147337a3 PP |
733 | ret = bt_private_component_source_add_output_private_port( |
734 | private_component, "out1", NULL, NULL); | |
b8f13b8b | 735 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
736 | } |
737 | ||
738 | if (nb_ports >= 3) { | |
147337a3 PP |
739 | ret = bt_private_component_source_add_output_private_port( |
740 | private_component, "out2", NULL, NULL); | |
b8f13b8b | 741 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
742 | } |
743 | ||
744 | if (nb_ports >= 4) { | |
147337a3 PP |
745 | ret = bt_private_component_source_add_output_private_port( |
746 | private_component, "out3", NULL, NULL); | |
b8f13b8b | 747 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
748 | } |
749 | ||
750 | return BT_COMPONENT_STATUS_OK; | |
751 | } | |
752 | ||
753 | static | |
754 | void src_finalize(struct bt_private_component *private_component) | |
755 | { | |
756 | } | |
757 | ||
758 | static | |
3fd7b79d | 759 | void append_test_event_from_notification(struct bt_notification *notification) |
8deeabc6 | 760 | { |
3fd7b79d | 761 | int ret; |
8deeabc6 | 762 | struct test_event test_event; |
8deeabc6 PP |
763 | |
764 | switch (bt_notification_get_type(notification)) { | |
765 | case BT_NOTIFICATION_TYPE_EVENT: | |
766 | { | |
839d52a5 | 767 | struct bt_event *event; |
8deeabc6 PP |
768 | struct bt_clock_class_priority_map *cc_prio_map; |
769 | ||
770 | test_event.type = TEST_EV_TYPE_NOTIF_EVENT; | |
771 | cc_prio_map = | |
a6918753 | 772 | bt_notification_event_borrow_clock_class_priority_map( |
8deeabc6 | 773 | notification); |
b8f13b8b | 774 | BT_ASSERT(cc_prio_map); |
a6918753 | 775 | event = bt_notification_event_borrow_event(notification); |
b8f13b8b | 776 | BT_ASSERT(event); |
8deeabc6 PP |
777 | |
778 | if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) { | |
839d52a5 PP |
779 | struct bt_clock_value *clock_value; |
780 | struct bt_clock_class *clock_class = | |
a6918753 | 781 | bt_clock_class_priority_map_borrow_highest_priority_clock_class( |
8deeabc6 PP |
782 | cc_prio_map); |
783 | ||
b8f13b8b | 784 | BT_ASSERT(clock_class); |
a6918753 | 785 | clock_value = bt_event_borrow_clock_value(event, |
8deeabc6 | 786 | clock_class); |
b8f13b8b | 787 | BT_ASSERT(clock_value); |
839d52a5 | 788 | ret = bt_clock_value_get_value_ns_from_epoch( |
8deeabc6 | 789 | clock_value, &test_event.ts_ns); |
b8f13b8b | 790 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
791 | } else { |
792 | test_event.ts_ns = -1; | |
793 | } | |
794 | ||
8deeabc6 PP |
795 | break; |
796 | } | |
797 | case BT_NOTIFICATION_TYPE_INACTIVITY: | |
798 | { | |
799 | struct bt_clock_class_priority_map *cc_prio_map; | |
800 | ||
801 | test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY; | |
a6918753 | 802 | cc_prio_map = bt_notification_inactivity_borrow_clock_class_priority_map( |
8deeabc6 | 803 | notification); |
b8f13b8b | 804 | BT_ASSERT(cc_prio_map); |
8deeabc6 PP |
805 | |
806 | if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) { | |
839d52a5 PP |
807 | struct bt_clock_value *clock_value; |
808 | struct bt_clock_class *clock_class = | |
a6918753 | 809 | bt_clock_class_priority_map_borrow_highest_priority_clock_class( |
8deeabc6 PP |
810 | cc_prio_map); |
811 | ||
b8f13b8b | 812 | BT_ASSERT(clock_class); |
8deeabc6 | 813 | clock_value = |
a6918753 | 814 | bt_notification_inactivity_borrow_clock_value( |
8deeabc6 | 815 | notification, clock_class); |
b8f13b8b | 816 | BT_ASSERT(clock_value); |
839d52a5 | 817 | ret = bt_clock_value_get_value_ns_from_epoch( |
8deeabc6 | 818 | clock_value, &test_event.ts_ns); |
b8f13b8b | 819 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
820 | } else { |
821 | test_event.ts_ns = -1; | |
822 | } | |
823 | ||
8deeabc6 PP |
824 | break; |
825 | } | |
826 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
827 | test_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; | |
828 | break; | |
829 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
830 | test_event.type = TEST_EV_TYPE_NOTIF_PACKET_END; | |
831 | break; | |
3230ee6b PP |
832 | case BT_NOTIFICATION_TYPE_STREAM_BEGIN: |
833 | test_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
834 | break; | |
835 | case BT_NOTIFICATION_TYPE_STREAM_END: | |
836 | test_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
837 | break; | |
8deeabc6 PP |
838 | default: |
839 | test_event.type = TEST_EV_TYPE_NOTIF_UNEXPECTED; | |
840 | break; | |
841 | } | |
842 | ||
3fd7b79d PP |
843 | append_test_event(&test_event); |
844 | } | |
845 | ||
846 | static | |
847 | enum bt_component_status sink_consume( | |
848 | struct bt_private_component *priv_component) | |
849 | { | |
850 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
851 | bt_notification_array notifications = NULL; | |
852 | uint64_t count; | |
853 | struct sink_user_data *user_data = | |
854 | bt_private_component_get_user_data(priv_component); | |
855 | enum bt_notification_iterator_status it_ret; | |
856 | struct test_event test_event; | |
857 | bool do_append_test_event = true; | |
858 | uint64_t i; | |
859 | ||
860 | BT_ASSERT(user_data && user_data->notif_iter); | |
861 | it_ret = bt_private_connection_notification_iterator_next( | |
862 | user_data->notif_iter, ¬ifications, &count); | |
863 | if (it_ret < 0) { | |
864 | ret = BT_COMPONENT_STATUS_ERROR; | |
865 | do_append_test_event = false; | |
866 | goto end; | |
867 | } | |
868 | ||
869 | switch (it_ret) { | |
870 | case BT_NOTIFICATION_ITERATOR_STATUS_END: | |
871 | test_event.type = TEST_EV_TYPE_END; | |
872 | ret = BT_COMPONENT_STATUS_END; | |
873 | BT_PUT(user_data->notif_iter); | |
874 | goto end; | |
875 | case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: | |
876 | test_event.type = TEST_EV_TYPE_AGAIN; | |
877 | ret = BT_COMPONENT_STATUS_AGAIN; | |
878 | goto end; | |
879 | default: | |
880 | break; | |
881 | } | |
882 | ||
883 | BT_ASSERT(notifications); | |
884 | ||
885 | for (i = 0; i < count; i++) { | |
886 | append_test_event_from_notification(notifications[i]); | |
887 | bt_put(notifications[i]); | |
888 | } | |
889 | ||
890 | do_append_test_event = false; | |
891 | ||
8deeabc6 PP |
892 | end: |
893 | if (do_append_test_event) { | |
894 | append_test_event(&test_event); | |
895 | } | |
896 | ||
8deeabc6 PP |
897 | return ret; |
898 | } | |
899 | ||
900 | static | |
634f394c PP |
901 | enum bt_component_status sink_port_connected( |
902 | struct bt_private_component *private_component, | |
8deeabc6 PP |
903 | struct bt_private_port *self_private_port, |
904 | struct bt_port *other_port) | |
905 | { | |
906 | struct bt_private_connection *priv_conn = | |
907 | bt_private_port_get_private_connection(self_private_port); | |
908 | struct sink_user_data *user_data = bt_private_component_get_user_data( | |
909 | private_component); | |
73d5c1ad | 910 | enum bt_connection_status conn_status; |
8deeabc6 | 911 | |
b8f13b8b PP |
912 | BT_ASSERT(user_data); |
913 | BT_ASSERT(priv_conn); | |
73d5c1ad | 914 | conn_status = bt_private_connection_create_notification_iterator( |
6ff151ad | 915 | priv_conn, &user_data->notif_iter); |
b8f13b8b | 916 | BT_ASSERT(conn_status == 0); |
8deeabc6 | 917 | bt_put(priv_conn); |
634f394c | 918 | return BT_COMPONENT_STATUS_OK; |
8deeabc6 PP |
919 | } |
920 | ||
921 | static | |
922 | enum bt_component_status sink_init( | |
923 | struct bt_private_component *private_component, | |
924 | struct bt_value *params, void *init_method_data) | |
925 | { | |
926 | struct sink_user_data *user_data = g_new0(struct sink_user_data, 1); | |
927 | int ret; | |
928 | ||
b8f13b8b | 929 | BT_ASSERT(user_data); |
8deeabc6 PP |
930 | ret = bt_private_component_set_user_data(private_component, |
931 | user_data); | |
b8f13b8b | 932 | BT_ASSERT(ret == 0); |
147337a3 PP |
933 | ret = bt_private_component_sink_add_input_private_port( |
934 | private_component, "in", NULL, NULL); | |
b8f13b8b | 935 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
936 | return BT_COMPONENT_STATUS_OK; |
937 | } | |
938 | ||
939 | static | |
940 | void sink_finalize(struct bt_private_component *private_component) | |
941 | { | |
942 | struct sink_user_data *user_data = bt_private_component_get_user_data( | |
943 | private_component); | |
944 | ||
945 | if (user_data) { | |
946 | bt_put(user_data->notif_iter); | |
947 | g_free(user_data); | |
948 | } | |
949 | } | |
950 | ||
951 | static | |
36712f1d PP |
952 | void create_source_muxer_sink(struct bt_graph *graph, |
953 | struct bt_component **source, | |
8deeabc6 PP |
954 | struct bt_component **muxer, |
955 | struct bt_component **sink) | |
956 | { | |
957 | struct bt_component_class *src_comp_class; | |
958 | struct bt_component_class *muxer_comp_class; | |
959 | struct bt_component_class *sink_comp_class; | |
960 | int ret; | |
961 | ||
962 | /* Create source component */ | |
963 | src_comp_class = bt_component_class_source_create("src", src_iter_next); | |
b8f13b8b | 964 | BT_ASSERT(src_comp_class); |
8deeabc6 | 965 | ret = bt_component_class_set_init_method(src_comp_class, src_init); |
b8f13b8b | 966 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
967 | ret = bt_component_class_set_finalize_method(src_comp_class, |
968 | src_finalize); | |
b8f13b8b | 969 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
970 | ret = bt_component_class_source_set_notification_iterator_init_method( |
971 | src_comp_class, src_iter_init); | |
b8f13b8b | 972 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
973 | ret = bt_component_class_source_set_notification_iterator_finalize_method( |
974 | src_comp_class, src_iter_finalize); | |
b8f13b8b | 975 | BT_ASSERT(ret == 0); |
36712f1d | 976 | ret = bt_graph_add_component(graph, src_comp_class, "source", NULL, source); |
b8f13b8b | 977 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
978 | |
979 | /* Create muxer component */ | |
980 | muxer_comp_class = bt_plugin_find_component_class("utils", "muxer", | |
981 | BT_COMPONENT_CLASS_TYPE_FILTER); | |
b8f13b8b | 982 | BT_ASSERT(muxer_comp_class); |
36712f1d | 983 | ret = bt_graph_add_component(graph, muxer_comp_class, "muxer", NULL, muxer); |
b8f13b8b | 984 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
985 | |
986 | /* Create sink component */ | |
987 | sink_comp_class = bt_component_class_sink_create("sink", sink_consume); | |
b8f13b8b | 988 | BT_ASSERT(sink_comp_class); |
8deeabc6 | 989 | ret = bt_component_class_set_init_method(sink_comp_class, sink_init); |
b8f13b8b | 990 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
991 | ret = bt_component_class_set_finalize_method(sink_comp_class, |
992 | sink_finalize); | |
993 | ret = bt_component_class_set_port_connected_method(sink_comp_class, | |
994 | sink_port_connected); | |
b8f13b8b | 995 | BT_ASSERT(ret == 0); |
36712f1d | 996 | ret = bt_graph_add_component(graph, sink_comp_class, "sink", NULL, sink); |
b8f13b8b | 997 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
998 | |
999 | bt_put(src_comp_class); | |
1000 | bt_put(muxer_comp_class); | |
1001 | bt_put(sink_comp_class); | |
1002 | } | |
1003 | ||
1004 | static | |
1005 | void do_std_test(enum test test, const char *name, | |
1006 | const struct test_event *expected_test_events, | |
1007 | bool with_upstream) | |
1008 | { | |
1009 | struct bt_component *src_comp; | |
1010 | struct bt_component *muxer_comp; | |
1011 | struct bt_component *sink_comp; | |
1012 | struct bt_port *upstream_port; | |
1013 | struct bt_port *downstream_port; | |
544d0515 PP |
1014 | int64_t i; |
1015 | int64_t count; | |
8deeabc6 PP |
1016 | enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; |
1017 | ||
1018 | clear_test_events(); | |
1019 | current_test = test; | |
1020 | diag("test: %s", name); | |
b8f13b8b | 1021 | BT_ASSERT(!graph); |
8deeabc6 | 1022 | graph = bt_graph_create(); |
b8f13b8b | 1023 | BT_ASSERT(graph); |
36712f1d | 1024 | create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp); |
8deeabc6 PP |
1025 | |
1026 | /* Connect source output ports to muxer input ports */ | |
1027 | if (with_upstream) { | |
544d0515 | 1028 | count = bt_component_source_get_output_port_count(src_comp); |
b8f13b8b | 1029 | BT_ASSERT(count >= 0); |
8deeabc6 PP |
1030 | |
1031 | for (i = 0; i < count; i++) { | |
9ac68eb1 | 1032 | upstream_port = bt_component_source_get_output_port_by_index( |
8deeabc6 | 1033 | src_comp, i); |
b8f13b8b | 1034 | BT_ASSERT(upstream_port); |
9ac68eb1 | 1035 | downstream_port = bt_component_filter_get_input_port_by_index( |
8deeabc6 | 1036 | muxer_comp, i); |
b8f13b8b | 1037 | BT_ASSERT(downstream_port); |
a256a42d PP |
1038 | graph_status = bt_graph_connect_ports(graph, |
1039 | upstream_port, downstream_port, NULL); | |
b8f13b8b | 1040 | BT_ASSERT(graph_status == 0); |
8deeabc6 PP |
1041 | bt_put(upstream_port); |
1042 | bt_put(downstream_port); | |
1043 | } | |
1044 | } | |
1045 | ||
1046 | /* Connect muxer output port to sink input port */ | |
9ac68eb1 | 1047 | upstream_port = bt_component_filter_get_output_port_by_name(muxer_comp, |
8deeabc6 | 1048 | "out"); |
b8f13b8b | 1049 | BT_ASSERT(upstream_port); |
b9d103be | 1050 | downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); |
b8f13b8b | 1051 | BT_ASSERT(downstream_port); |
a256a42d PP |
1052 | graph_status = bt_graph_connect_ports(graph, upstream_port, |
1053 | downstream_port, NULL); | |
b8f13b8b | 1054 | BT_ASSERT(graph_status == 0); |
8deeabc6 PP |
1055 | bt_put(upstream_port); |
1056 | bt_put(downstream_port); | |
1057 | ||
1058 | while (graph_status == BT_GRAPH_STATUS_OK || | |
1059 | graph_status == BT_GRAPH_STATUS_AGAIN) { | |
1060 | graph_status = bt_graph_run(graph); | |
1061 | } | |
1062 | ||
1063 | ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error"); | |
1064 | ok(compare_test_events(expected_test_events), | |
1065 | "the produced sequence of test events is the expected one"); | |
1066 | ||
1067 | bt_put(src_comp); | |
1068 | bt_put(muxer_comp); | |
1069 | bt_put(sink_comp); | |
f7c3ac09 | 1070 | BT_PUT(graph); |
8deeabc6 PP |
1071 | } |
1072 | ||
1073 | static | |
1074 | void test_no_ts(void) | |
1075 | { | |
1076 | const struct test_event expected_test_events[] = { | |
3230ee6b PP |
1077 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, |
1078 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1079 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
8deeabc6 PP |
1080 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, |
1081 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, }, | |
1082 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, }, | |
1083 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, }, | |
1084 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, }, | |
1085 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = -1, }, | |
3230ee6b PP |
1086 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1087 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1088 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 1, }, |
1089 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 4, }, | |
1090 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 189, }, | |
1091 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 1001, }, | |
3230ee6b PP |
1092 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1093 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1094 | { .type = TEST_EV_TYPE_END, }, |
1095 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1096 | }; | |
1097 | ||
1098 | do_std_test(TEST_NO_TS, "event notifications with no time", | |
1099 | expected_test_events, true); | |
1100 | } | |
1101 | ||
1102 | static | |
1103 | void test_no_upstream_connection(void) | |
1104 | { | |
1105 | const struct test_event expected_test_events[] = { | |
1106 | { .type = TEST_EV_TYPE_END, }, | |
1107 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1108 | }; | |
1109 | ||
1110 | do_std_test(TEST_NO_UPSTREAM_CONNECTION, "no upstream connection", | |
1111 | expected_test_events, false); | |
1112 | } | |
1113 | ||
1114 | static | |
3230ee6b | 1115 | void test_simple_4_ports(void) |
8deeabc6 PP |
1116 | { |
1117 | const struct test_event expected_test_events[] = { | |
3230ee6b | 1118 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, |
8deeabc6 | 1119 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, |
3230ee6b PP |
1120 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, |
1121 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1122 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
1123 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1124 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
8deeabc6 | 1125 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, |
8deeabc6 PP |
1126 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 }, |
1127 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 24 }, | |
1128 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 41 }, | |
1129 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 }, | |
1130 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 53 }, | |
1131 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 56 }, | |
1132 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 }, | |
1133 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 }, | |
1134 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 }, | |
1135 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 }, | |
1136 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 }, | |
1137 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 97 }, | |
1138 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 105 }, | |
1139 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 119 }, | |
1140 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 120 }, | |
1141 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 }, | |
1142 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 138 }, | |
1143 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 }, | |
1144 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 154 }, | |
1145 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 }, | |
1146 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 }, | |
1147 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 }, | |
1148 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 210 }, | |
1149 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 222 }, | |
1150 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 228 }, | |
1151 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 240 }, | |
1152 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 }, | |
1153 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 }, | |
1154 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 292 }, | |
1155 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 }, | |
1156 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 317 }, | |
1157 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 }, | |
1158 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 }, | |
1159 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 }, | |
1160 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 353 }, | |
1161 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 }, | |
1162 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 407 }, | |
1163 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 }, | |
1164 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 433 }, | |
1165 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 }, | |
1166 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 471 }, | |
1167 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 473 }, | |
1168 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 }, | |
1169 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 479 }, | |
1170 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 481 }, | |
1171 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 487 }, | |
1172 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 504 }, | |
1173 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 525 }, | |
1174 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 572 }, | |
1175 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 591 }, | |
1176 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 605 }, | |
1177 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 612 }, | |
1178 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 615 }, | |
1179 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 618 }, | |
1180 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 }, | |
1181 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 }, | |
1182 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 632 }, | |
1183 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 }, | |
1184 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 }, | |
1185 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 }, | |
1186 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 670 }, | |
1187 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 }, | |
1188 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 696 }, | |
1189 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 708 }, | |
1190 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 }, | |
1191 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 }, | |
1192 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 }, | |
1193 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 }, | |
1194 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 }, | |
1195 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 }, | |
1196 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 766 }, | |
1197 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 }, | |
1198 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 }, | |
1199 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 }, | |
1200 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 }, | |
1201 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 }, | |
1202 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 825 }, | |
1203 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 }, | |
3230ee6b PP |
1204 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1205 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1206 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 850 }, |
1207 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 852 }, | |
1208 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 }, | |
1209 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 863 }, | |
1210 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 867 }, | |
1211 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 871 }, | |
1212 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 884 }, | |
1213 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 }, | |
1214 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 }, | |
1215 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 931 }, | |
1216 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 }, | |
1217 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 951 }, | |
1218 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 953 }, | |
1219 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 956 }, | |
1220 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 985 }, | |
1221 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 996 }, | |
3230ee6b PP |
1222 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1223 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 | 1224 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 }, |
3230ee6b PP |
1225 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1226 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 | 1227 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 999 }, |
3230ee6b PP |
1228 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1229 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1230 | { .type = TEST_EV_TYPE_END, }, |
1231 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1232 | }; | |
1233 | ||
1234 | do_std_test(TEST_SIMPLE_4_PORTS, "simple: 4 ports without retries", | |
1235 | expected_test_events, true); | |
1236 | } | |
1237 | ||
1238 | static | |
1239 | void test_4_ports_with_retries(void) | |
1240 | { | |
1241 | const struct test_event expected_test_events[] = { | |
1242 | { .type = TEST_EV_TYPE_AGAIN, }, | |
3230ee6b PP |
1243 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, |
1244 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1245 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
1246 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1247 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
1248 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1249 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
1250 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
8deeabc6 PP |
1251 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 }, |
1252 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 24 }, | |
1253 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 41 }, | |
1254 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 }, | |
1255 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 53 }, | |
1256 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 56 }, | |
1257 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 }, | |
1258 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 }, | |
1259 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 }, | |
1260 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 }, | |
1261 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 }, | |
1262 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 97 }, | |
1263 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 105 }, | |
1264 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 119 }, | |
1265 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 120 }, | |
1266 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 }, | |
1267 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 138 }, | |
1268 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 }, | |
1269 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 154 }, | |
1270 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 }, | |
1271 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 }, | |
1272 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 }, | |
1273 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 210 }, | |
1274 | { .type = TEST_EV_TYPE_AGAIN, }, | |
1275 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 222 }, | |
1276 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 228 }, | |
1277 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 240 }, | |
1278 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 }, | |
1279 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 }, | |
1280 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 292 }, | |
1281 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 }, | |
1282 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 317 }, | |
1283 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 }, | |
1284 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 }, | |
1285 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 }, | |
1286 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 353 }, | |
1287 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 }, | |
1288 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 407 }, | |
1289 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 }, | |
1290 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 433 }, | |
1291 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 }, | |
1292 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 471 }, | |
1293 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 473 }, | |
1294 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 }, | |
1295 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 479 }, | |
1296 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 481 }, | |
1297 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 487 }, | |
1298 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 504 }, | |
1299 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 525 }, | |
1300 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 572 }, | |
1301 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 591 }, | |
1302 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 605 }, | |
1303 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 612 }, | |
1304 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 615 }, | |
1305 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 618 }, | |
1306 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 }, | |
1307 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 }, | |
1308 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 632 }, | |
1309 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 }, | |
1310 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 }, | |
1311 | { .type = TEST_EV_TYPE_AGAIN, }, | |
1312 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 }, | |
1313 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 670 }, | |
1314 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 }, | |
1315 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 696 }, | |
1316 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 708 }, | |
1317 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 }, | |
1318 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 }, | |
1319 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 }, | |
1320 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 }, | |
1321 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 }, | |
1322 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 }, | |
1323 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 766 }, | |
1324 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 }, | |
1325 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 }, | |
1326 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 }, | |
1327 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 }, | |
1328 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 }, | |
1329 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 825 }, | |
1330 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 }, | |
1331 | { .type = TEST_EV_TYPE_AGAIN, }, | |
3230ee6b PP |
1332 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1333 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1334 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 850 }, |
1335 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 852 }, | |
1336 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 }, | |
1337 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 863 }, | |
1338 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 867 }, | |
1339 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 871 }, | |
1340 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 884 }, | |
1341 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 }, | |
1342 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 }, | |
1343 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 931 }, | |
1344 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 }, | |
1345 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 951 }, | |
1346 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 953 }, | |
1347 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 956 }, | |
1348 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 985 }, | |
1349 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 996 }, | |
3230ee6b PP |
1350 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1351 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 | 1352 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 }, |
3230ee6b PP |
1353 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1354 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 | 1355 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 999 }, |
3230ee6b PP |
1356 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1357 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1358 | { .type = TEST_EV_TYPE_END, }, |
1359 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1360 | }; | |
1361 | ||
1362 | do_std_test(TEST_4_PORTS_WITH_RETRIES, "4 ports with retries", | |
1363 | expected_test_events, true); | |
1364 | } | |
1365 | ||
1366 | static | |
1367 | void connect_port_to_first_avail_muxer_port(struct bt_graph *graph, | |
1368 | struct bt_port *source_port, | |
1369 | struct bt_component *muxer_comp) | |
1370 | { | |
1371 | struct bt_port *avail_muxer_port = NULL; | |
544d0515 PP |
1372 | int64_t i; |
1373 | int64_t count; | |
a256a42d | 1374 | enum bt_graph_status graph_status; |
8deeabc6 | 1375 | |
544d0515 | 1376 | count = bt_component_filter_get_input_port_count(muxer_comp); |
b8f13b8b | 1377 | BT_ASSERT(count >= 0); |
8deeabc6 PP |
1378 | |
1379 | for (i = 0; i < count; i++) { | |
1380 | struct bt_port *muxer_port = | |
9ac68eb1 | 1381 | bt_component_filter_get_input_port_by_index( |
8deeabc6 PP |
1382 | muxer_comp, i); |
1383 | ||
b8f13b8b | 1384 | BT_ASSERT(muxer_port); |
8deeabc6 PP |
1385 | |
1386 | if (!bt_port_is_connected(muxer_port)) { | |
1387 | BT_MOVE(avail_muxer_port, muxer_port); | |
1388 | break; | |
1389 | } else { | |
1390 | bt_put(muxer_port); | |
1391 | } | |
1392 | } | |
1393 | ||
a256a42d PP |
1394 | graph_status = bt_graph_connect_ports(graph, source_port, |
1395 | avail_muxer_port, NULL); | |
b8f13b8b | 1396 | BT_ASSERT(graph_status == 0); |
8deeabc6 PP |
1397 | bt_put(avail_muxer_port); |
1398 | } | |
1399 | ||
1400 | static | |
1401 | void graph_port_added_listener_connect_to_avail_muxer_port(struct bt_port *port, | |
1402 | void *data) | |
1403 | { | |
1404 | struct graph_listener_data *graph_listener_data = data; | |
1405 | struct bt_component *comp; | |
1406 | ||
1407 | comp = bt_port_get_component(port); | |
b8f13b8b | 1408 | BT_ASSERT(comp); |
8deeabc6 PP |
1409 | |
1410 | if (comp != graph_listener_data->source) { | |
1411 | goto end; | |
1412 | } | |
1413 | ||
1414 | connect_port_to_first_avail_muxer_port(graph_listener_data->graph, | |
1415 | port, graph_listener_data->muxer); | |
1416 | ||
1417 | end: | |
1418 | bt_put(comp); | |
1419 | } | |
1420 | ||
1421 | static | |
1422 | void test_single_end_then_multiple_full(void) | |
1423 | { | |
1424 | struct bt_component *src_comp; | |
1425 | struct bt_component *muxer_comp; | |
1426 | struct bt_component *sink_comp; | |
1427 | struct bt_port *upstream_port; | |
1428 | struct bt_port *downstream_port; | |
544d0515 PP |
1429 | int64_t i; |
1430 | int64_t count; | |
8deeabc6 PP |
1431 | int ret; |
1432 | enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; | |
1433 | struct graph_listener_data graph_listener_data; | |
1434 | const struct test_event expected_test_events[] = { | |
3230ee6b PP |
1435 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, |
1436 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1437 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
1438 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
8deeabc6 PP |
1439 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 }, |
1440 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 }, | |
1441 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 }, | |
1442 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 }, | |
1443 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 }, | |
1444 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 }, | |
1445 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 }, | |
1446 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 }, | |
1447 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 }, | |
1448 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 }, | |
1449 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 }, | |
1450 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 }, | |
1451 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 }, | |
1452 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 }, | |
1453 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 }, | |
1454 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 }, | |
1455 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 }, | |
1456 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 }, | |
1457 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 }, | |
1458 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 }, | |
1459 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 }, | |
1460 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 }, | |
1461 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 }, | |
1462 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 }, | |
1463 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 }, | |
1464 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 }, | |
1465 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 }, | |
1466 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 }, | |
1467 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 }, | |
1468 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 }, | |
1469 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 }, | |
1470 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 }, | |
1471 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 }, | |
1472 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 }, | |
1473 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 }, | |
1474 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 }, | |
1475 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 }, | |
1476 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 }, | |
1477 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 }, | |
1478 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 }, | |
3230ee6b PP |
1479 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1480 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1481 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 }, |
1482 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 }, | |
1483 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 }, | |
1484 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 }, | |
1485 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 }, | |
3230ee6b PP |
1486 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1487 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1488 | { .type = TEST_EV_TYPE_END, }, |
1489 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1490 | }; | |
1491 | ||
1492 | clear_test_events(); | |
1493 | current_test = TEST_SINGLE_END_THEN_MULTIPLE_FULL; | |
1494 | diag("test: single end then multiple full"); | |
b8f13b8b | 1495 | BT_ASSERT(!graph); |
8deeabc6 | 1496 | graph = bt_graph_create(); |
b8f13b8b | 1497 | BT_ASSERT(graph); |
36712f1d | 1498 | create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp); |
8deeabc6 PP |
1499 | graph_listener_data.graph = graph; |
1500 | graph_listener_data.source = src_comp; | |
1501 | graph_listener_data.muxer = muxer_comp; | |
1502 | graph_listener_data.sink = sink_comp; | |
1503 | ret = bt_graph_add_port_added_listener(graph, | |
eb87cce7 | 1504 | graph_port_added_listener_connect_to_avail_muxer_port, NULL, |
8deeabc6 | 1505 | &graph_listener_data); |
b8f13b8b | 1506 | BT_ASSERT(ret >= 0); |
8deeabc6 PP |
1507 | |
1508 | /* Connect source output ports to muxer input ports */ | |
544d0515 | 1509 | count = bt_component_source_get_output_port_count(src_comp); |
b8f13b8b | 1510 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
1511 | |
1512 | for (i = 0; i < count; i++) { | |
9ac68eb1 | 1513 | upstream_port = bt_component_source_get_output_port_by_index( |
8deeabc6 | 1514 | src_comp, i); |
b8f13b8b | 1515 | BT_ASSERT(upstream_port); |
8deeabc6 PP |
1516 | connect_port_to_first_avail_muxer_port(graph, |
1517 | upstream_port, muxer_comp); | |
1518 | bt_put(upstream_port); | |
1519 | } | |
1520 | ||
1521 | /* Connect muxer output port to sink input port */ | |
9ac68eb1 | 1522 | upstream_port = bt_component_filter_get_output_port_by_name(muxer_comp, |
8deeabc6 | 1523 | "out"); |
b8f13b8b | 1524 | BT_ASSERT(upstream_port); |
b9d103be | 1525 | downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); |
b8f13b8b | 1526 | BT_ASSERT(downstream_port); |
a256a42d PP |
1527 | graph_status = bt_graph_connect_ports(graph, upstream_port, |
1528 | downstream_port, NULL); | |
b8f13b8b | 1529 | BT_ASSERT(graph_status == 0); |
8deeabc6 PP |
1530 | bt_put(upstream_port); |
1531 | bt_put(downstream_port); | |
1532 | ||
1533 | while (graph_status == BT_GRAPH_STATUS_OK || | |
1534 | graph_status == BT_GRAPH_STATUS_AGAIN) { | |
1535 | graph_status = bt_graph_run(graph); | |
1536 | } | |
1537 | ||
1538 | ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error"); | |
1539 | ok(compare_test_events(expected_test_events), | |
1540 | "the produced sequence of test events is the expected one"); | |
1541 | ||
1542 | bt_put(src_comp); | |
1543 | bt_put(muxer_comp); | |
1544 | bt_put(sink_comp); | |
f7c3ac09 | 1545 | BT_PUT(graph); |
8deeabc6 PP |
1546 | } |
1547 | ||
1548 | static | |
1549 | void test_single_again_end_then_multiple_full(void) | |
1550 | { | |
1551 | struct bt_component *src_comp; | |
1552 | struct bt_component *muxer_comp; | |
1553 | struct bt_component *sink_comp; | |
1554 | struct bt_port *upstream_port; | |
1555 | struct bt_port *downstream_port; | |
544d0515 PP |
1556 | int64_t i; |
1557 | int64_t count; | |
8deeabc6 PP |
1558 | int ret; |
1559 | enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; | |
1560 | struct graph_listener_data graph_listener_data; | |
1561 | const struct test_event expected_test_events[] = { | |
1562 | { .type = TEST_EV_TYPE_AGAIN, }, | |
3230ee6b PP |
1563 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, |
1564 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
1565 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, }, | |
1566 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, }, | |
8deeabc6 PP |
1567 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 8 }, |
1568 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 51 }, | |
1569 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 59 }, | |
1570 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 68 }, | |
1571 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 71 }, | |
1572 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 77 }, | |
1573 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 91 }, | |
1574 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 121 }, | |
1575 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 139 }, | |
1576 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 170 }, | |
1577 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 179 }, | |
1578 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 209 }, | |
1579 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 254 }, | |
1580 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 266 }, | |
1581 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 298 }, | |
1582 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 320 }, | |
1583 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 350 }, | |
1584 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 352 }, | |
1585 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 393 }, | |
1586 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 419 }, | |
1587 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 454 }, | |
1588 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 478 }, | |
1589 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 624 }, | |
1590 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 631 }, | |
1591 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 644 }, | |
1592 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 651 }, | |
1593 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 668 }, | |
1594 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 678 }, | |
1595 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 714 }, | |
1596 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 717 }, | |
1597 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 731 }, | |
1598 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 733 }, | |
1599 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 744 }, | |
1600 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 750 }, | |
1601 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 778 }, | |
1602 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 788 }, | |
1603 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 790 }, | |
1604 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 819 }, | |
1605 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 820 }, | |
1606 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 836 }, | |
3230ee6b PP |
1607 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1608 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1609 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 857 }, |
1610 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 892 }, | |
1611 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 903 }, | |
1612 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 944 }, | |
1613 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .ts_ns = 998 }, | |
3230ee6b PP |
1614 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, }, |
1615 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, }, | |
8deeabc6 PP |
1616 | { .type = TEST_EV_TYPE_END, }, |
1617 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1618 | }; | |
1619 | ||
1620 | clear_test_events(); | |
1621 | current_test = TEST_SINGLE_AGAIN_END_THEN_MULTIPLE_FULL; | |
1622 | diag("test: single again then end then multiple full"); | |
b8f13b8b | 1623 | BT_ASSERT(!graph); |
8deeabc6 | 1624 | graph = bt_graph_create(); |
b8f13b8b | 1625 | BT_ASSERT(graph); |
36712f1d | 1626 | create_source_muxer_sink(graph, &src_comp, &muxer_comp, &sink_comp); |
8deeabc6 PP |
1627 | graph_listener_data.graph = graph; |
1628 | graph_listener_data.source = src_comp; | |
1629 | graph_listener_data.muxer = muxer_comp; | |
1630 | graph_listener_data.sink = sink_comp; | |
1631 | ret = bt_graph_add_port_added_listener(graph, | |
eb87cce7 | 1632 | graph_port_added_listener_connect_to_avail_muxer_port, NULL, |
8deeabc6 | 1633 | &graph_listener_data); |
b8f13b8b | 1634 | BT_ASSERT(ret >= 0); |
8deeabc6 PP |
1635 | |
1636 | /* Connect source output ports to muxer input ports */ | |
544d0515 | 1637 | count = bt_component_source_get_output_port_count(src_comp); |
b8f13b8b | 1638 | BT_ASSERT(ret == 0); |
8deeabc6 PP |
1639 | |
1640 | for (i = 0; i < count; i++) { | |
9ac68eb1 | 1641 | upstream_port = bt_component_source_get_output_port_by_index( |
8deeabc6 | 1642 | src_comp, i); |
b8f13b8b | 1643 | BT_ASSERT(upstream_port); |
8deeabc6 PP |
1644 | connect_port_to_first_avail_muxer_port(graph, |
1645 | upstream_port, muxer_comp); | |
1646 | bt_put(upstream_port); | |
1647 | } | |
1648 | ||
1649 | /* Connect muxer output port to sink input port */ | |
9ac68eb1 | 1650 | upstream_port = bt_component_filter_get_output_port_by_name(muxer_comp, |
8deeabc6 | 1651 | "out"); |
b8f13b8b | 1652 | BT_ASSERT(upstream_port); |
b9d103be | 1653 | downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); |
b8f13b8b | 1654 | BT_ASSERT(downstream_port); |
a256a42d PP |
1655 | graph_status = bt_graph_connect_ports(graph, upstream_port, |
1656 | downstream_port, NULL); | |
b8f13b8b | 1657 | BT_ASSERT(graph_status == 0); |
8deeabc6 PP |
1658 | bt_put(upstream_port); |
1659 | bt_put(downstream_port); | |
1660 | ||
1661 | while (graph_status == BT_GRAPH_STATUS_OK || | |
1662 | graph_status == BT_GRAPH_STATUS_AGAIN) { | |
1663 | graph_status = bt_graph_run(graph); | |
1664 | } | |
1665 | ||
1666 | ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error"); | |
1667 | ok(compare_test_events(expected_test_events), | |
1668 | "the produced sequence of test events is the expected one"); | |
1669 | ||
1670 | bt_put(src_comp); | |
1671 | bt_put(muxer_comp); | |
1672 | bt_put(sink_comp); | |
f7c3ac09 | 1673 | BT_PUT(graph); |
8deeabc6 PP |
1674 | } |
1675 | ||
1676 | #define DEBUG_ENV_VAR "TEST_UTILS_MUXER_DEBUG" | |
1677 | ||
1678 | int main(int argc, char **argv) | |
1679 | { | |
1680 | if (getenv(DEBUG_ENV_VAR) && strcmp(getenv(DEBUG_ENV_VAR), "1") == 0) { | |
1681 | debug = true; | |
1682 | } | |
1683 | ||
1684 | plan_tests(NR_TESTS); | |
1685 | init_static_data(); | |
1686 | test_no_ts(); | |
1687 | test_no_upstream_connection(); | |
8deeabc6 PP |
1688 | test_simple_4_ports(); |
1689 | test_4_ports_with_retries(); | |
1690 | test_single_end_then_multiple_full(); | |
1691 | test_single_again_end_then_multiple_full(); | |
1692 | fini_static_data(); | |
1693 | return exit_status(); | |
1694 | } |