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