Commit | Line | Data |
---|---|---|
fb9935cc PP |
1 | /* |
2 | * test_graph_topo.c | |
3 | * | |
4 | * Copyright 2017 - Philippe Proulx <pproulx@efficios.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; under version 2 of the License. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | ||
834e9996 PP |
20 | #include <babeltrace/babeltrace.h> |
21 | #include <babeltrace/assert-internal.h> | |
fb9935cc PP |
22 | #include <stdlib.h> |
23 | #include <string.h> | |
24 | #include <stdbool.h> | |
fb9935cc PP |
25 | #include <glib.h> |
26 | ||
27 | #include "tap/tap.h" | |
28 | ||
634f394c | 29 | #define NR_TESTS 99 |
fb9935cc PP |
30 | |
31 | enum event_type { | |
834e9996 PP |
32 | SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, |
33 | SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, | |
34 | SRC_COMP_OUTPUT_PORT_CONNECTED, | |
35 | SINK_COMP_INPUT_PORT_CONNECTED, | |
36 | SRC_COMP_OUTPUT_PORT_DISCONNECTED, | |
37 | SINK_COMP_INPUT_PORT_DISCONNECTED, | |
38 | GRAPH_SRC_OUTPUT_PORT_ADDED, | |
39 | GRAPH_SINK_INPUT_PORT_ADDED, | |
40 | GRAPH_SRC_OUTPUT_PORT_REMOVED, | |
41 | GRAPH_SINK_INPUT_PORT_REMOVED, | |
42 | GRAPH_SRC_SINK_PORTS_CONNECTED, | |
43 | GRAPH_SRC_SINK_PORTS_DISCONNECTED, | |
fb9935cc PP |
44 | }; |
45 | ||
46 | enum test { | |
47 | TEST_EMPTY_GRAPH, | |
48 | TEST_SIMPLE, | |
634f394c PP |
49 | TEST_SRC_PORT_CONNECTED_ERROR, |
50 | TEST_SINK_PORT_CONNECTED_ERROR, | |
c14181ff | 51 | TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED, |
fb9935cc PP |
52 | TEST_SINK_REMOVES_PORT_IN_CONSUME, |
53 | TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT, | |
54 | }; | |
55 | ||
56 | struct event { | |
57 | enum event_type type; | |
58 | ||
59 | union { | |
60 | struct { | |
61 | struct bt_component *comp; | |
62 | struct bt_port *self_port; | |
63 | struct bt_port *other_port; | |
834e9996 PP |
64 | } src_comp_accept_output_port_connection; |
65 | ||
66 | struct { | |
67 | struct bt_component *comp; | |
68 | struct bt_port *self_port; | |
69 | struct bt_port *other_port; | |
70 | } sink_comp_accept_input_port_connection; | |
71 | ||
72 | struct { | |
73 | struct bt_component *comp; | |
74 | struct bt_port *self_port; | |
75 | struct bt_port *other_port; | |
76 | } src_comp_output_port_connected; | |
fb9935cc | 77 | |
c14181ff PP |
78 | struct { |
79 | struct bt_component *comp; | |
80 | struct bt_port *self_port; | |
81 | struct bt_port *other_port; | |
834e9996 PP |
82 | } sink_comp_input_port_connected; |
83 | ||
84 | struct { | |
85 | struct bt_component *comp; | |
86 | struct bt_port *self_port; | |
87 | } src_comp_output_port_disconnected; | |
88 | ||
89 | struct { | |
90 | struct bt_component *comp; | |
91 | struct bt_port *self_port; | |
92 | } sink_comp_input_port_disconnected; | |
c14181ff | 93 | |
fb9935cc PP |
94 | struct { |
95 | struct bt_component *comp; | |
96 | struct bt_port *port; | |
834e9996 | 97 | } graph_src_output_port_added; |
fb9935cc PP |
98 | |
99 | struct { | |
100 | struct bt_component *comp; | |
101 | struct bt_port *port; | |
834e9996 | 102 | } graph_sink_input_port_added; |
fb9935cc PP |
103 | |
104 | struct { | |
105 | struct bt_component *comp; | |
106 | struct bt_port *port; | |
834e9996 PP |
107 | } graph_src_output_port_removed; |
108 | ||
109 | struct { | |
110 | struct bt_component *comp; | |
111 | struct bt_port *port; | |
112 | } graph_sink_input_port_removed; | |
fb9935cc PP |
113 | |
114 | struct { | |
115 | struct bt_component *upstream_comp; | |
116 | struct bt_component *downstream_comp; | |
117 | struct bt_port *upstream_port; | |
118 | struct bt_port *downstream_port; | |
834e9996 | 119 | } graph_src_sink_ports_connected; |
fb9935cc PP |
120 | |
121 | struct { | |
122 | struct bt_component *upstream_comp; | |
123 | struct bt_component *downstream_comp; | |
124 | struct bt_port *upstream_port; | |
125 | struct bt_port *downstream_port; | |
834e9996 | 126 | } graph_src_sink_ports_disconnected; |
fb9935cc PP |
127 | } data; |
128 | }; | |
129 | ||
130 | static GArray *events; | |
834e9996 PP |
131 | static struct bt_private_component_class_source *src_comp_class; |
132 | static struct bt_private_component_class_sink *sink_comp_class; | |
fb9935cc PP |
133 | static enum test current_test; |
134 | ||
135 | static | |
136 | void clear_events(void) | |
137 | { | |
138 | g_array_set_size(events, 0); | |
139 | } | |
140 | ||
141 | static | |
142 | void append_event(struct event *event) | |
143 | { | |
144 | g_array_append_val(events, *event); | |
145 | } | |
146 | ||
147 | static | |
148 | bool compare_events(struct event *ev_a, struct event *ev_b) | |
149 | { | |
150 | if (ev_a->type != ev_b->type) { | |
151 | return false; | |
152 | } | |
153 | ||
154 | switch (ev_a->type) { | |
834e9996 PP |
155 | case SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION: |
156 | if (ev_a->data.src_comp_accept_output_port_connection.comp != | |
157 | ev_b->data.src_comp_accept_output_port_connection.comp) { | |
fb9935cc PP |
158 | return false; |
159 | } | |
160 | ||
834e9996 PP |
161 | if (ev_a->data.src_comp_accept_output_port_connection.self_port != |
162 | ev_b->data.src_comp_accept_output_port_connection.self_port) { | |
fb9935cc PP |
163 | return false; |
164 | } | |
165 | ||
834e9996 PP |
166 | if (ev_a->data.src_comp_accept_output_port_connection.other_port != |
167 | ev_b->data.src_comp_accept_output_port_connection.other_port) { | |
fb9935cc PP |
168 | return false; |
169 | } | |
170 | break; | |
834e9996 PP |
171 | case SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION: |
172 | if (ev_a->data.sink_comp_accept_input_port_connection.comp != | |
173 | ev_b->data.sink_comp_accept_input_port_connection.comp) { | |
c14181ff PP |
174 | return false; |
175 | } | |
176 | ||
834e9996 PP |
177 | if (ev_a->data.sink_comp_accept_input_port_connection.self_port != |
178 | ev_b->data.sink_comp_accept_input_port_connection.self_port) { | |
c14181ff PP |
179 | return false; |
180 | } | |
181 | ||
834e9996 PP |
182 | if (ev_a->data.sink_comp_accept_input_port_connection.other_port != |
183 | ev_b->data.sink_comp_accept_input_port_connection.other_port) { | |
c14181ff PP |
184 | return false; |
185 | } | |
186 | break; | |
834e9996 PP |
187 | case SRC_COMP_OUTPUT_PORT_CONNECTED: |
188 | if (ev_a->data.src_comp_output_port_connected.comp != | |
189 | ev_b->data.src_comp_output_port_connected.comp) { | |
190 | return false; | |
191 | } | |
192 | ||
193 | if (ev_a->data.src_comp_output_port_connected.self_port != | |
194 | ev_b->data.src_comp_output_port_connected.self_port) { | |
fb9935cc PP |
195 | return false; |
196 | } | |
197 | ||
834e9996 PP |
198 | if (ev_a->data.src_comp_output_port_connected.other_port != |
199 | ev_b->data.src_comp_output_port_connected.other_port) { | |
fb9935cc PP |
200 | return false; |
201 | } | |
202 | break; | |
834e9996 PP |
203 | case SINK_COMP_INPUT_PORT_CONNECTED: |
204 | if (ev_a->data.sink_comp_input_port_connected.comp != | |
205 | ev_b->data.sink_comp_input_port_connected.comp) { | |
fb9935cc PP |
206 | return false; |
207 | } | |
208 | ||
834e9996 PP |
209 | if (ev_a->data.sink_comp_input_port_connected.self_port != |
210 | ev_b->data.sink_comp_input_port_connected.self_port) { | |
211 | return false; | |
212 | } | |
213 | ||
214 | if (ev_a->data.sink_comp_input_port_connected.other_port != | |
215 | ev_b->data.sink_comp_input_port_connected.other_port) { | |
fb9935cc PP |
216 | return false; |
217 | } | |
218 | break; | |
834e9996 PP |
219 | case SRC_COMP_OUTPUT_PORT_DISCONNECTED: |
220 | if (ev_a->data.src_comp_output_port_disconnected.comp != | |
221 | ev_b->data.src_comp_output_port_disconnected.comp) { | |
fb9935cc PP |
222 | return false; |
223 | } | |
224 | ||
834e9996 PP |
225 | if (ev_a->data.src_comp_output_port_disconnected.self_port != |
226 | ev_b->data.src_comp_output_port_disconnected.self_port) { | |
fb9935cc PP |
227 | return false; |
228 | } | |
229 | break; | |
834e9996 PP |
230 | case SINK_COMP_INPUT_PORT_DISCONNECTED: |
231 | if (ev_a->data.sink_comp_input_port_disconnected.comp != | |
232 | ev_b->data.sink_comp_input_port_disconnected.comp) { | |
fb9935cc PP |
233 | return false; |
234 | } | |
235 | ||
834e9996 PP |
236 | if (ev_a->data.sink_comp_input_port_disconnected.self_port != |
237 | ev_b->data.sink_comp_input_port_disconnected.self_port) { | |
238 | return false; | |
239 | } | |
240 | break; | |
241 | case GRAPH_SRC_OUTPUT_PORT_ADDED: | |
242 | if (ev_a->data.graph_src_output_port_added.comp != | |
243 | ev_b->data.graph_src_output_port_added.comp) { | |
fb9935cc PP |
244 | return false; |
245 | } | |
246 | ||
834e9996 PP |
247 | if (ev_a->data.graph_src_output_port_added.port != |
248 | ev_b->data.graph_src_output_port_added.port) { | |
249 | return false; | |
250 | } | |
251 | break; | |
252 | case GRAPH_SINK_INPUT_PORT_ADDED: | |
253 | if (ev_a->data.graph_sink_input_port_added.comp != | |
254 | ev_b->data.graph_sink_input_port_added.comp) { | |
255 | return false; | |
256 | } | |
257 | ||
258 | if (ev_a->data.graph_sink_input_port_added.port != | |
259 | ev_b->data.graph_sink_input_port_added.port) { | |
260 | return false; | |
261 | } | |
262 | break; | |
263 | case GRAPH_SRC_OUTPUT_PORT_REMOVED: | |
264 | if (ev_a->data.graph_src_output_port_removed.comp != | |
265 | ev_b->data.graph_src_output_port_removed.comp) { | |
266 | return false; | |
267 | } | |
268 | ||
269 | if (ev_a->data.graph_src_output_port_removed.port != | |
270 | ev_b->data.graph_src_output_port_removed.port) { | |
271 | return false; | |
272 | } | |
273 | break; | |
274 | case GRAPH_SINK_INPUT_PORT_REMOVED: | |
275 | if (ev_a->data.graph_sink_input_port_removed.comp != | |
276 | ev_b->data.graph_sink_input_port_removed.comp) { | |
277 | return false; | |
278 | } | |
279 | ||
280 | if (ev_a->data.graph_sink_input_port_removed.port != | |
281 | ev_b->data.graph_sink_input_port_removed.port) { | |
282 | return false; | |
283 | } | |
284 | break; | |
285 | case GRAPH_SRC_SINK_PORTS_CONNECTED: | |
286 | if (ev_a->data.graph_src_sink_ports_connected.upstream_comp != | |
287 | ev_b->data.graph_src_sink_ports_connected.upstream_comp) { | |
288 | return false; | |
289 | } | |
290 | ||
291 | if (ev_a->data.graph_src_sink_ports_connected.downstream_comp != | |
292 | ev_b->data.graph_src_sink_ports_connected.downstream_comp) { | |
fb9935cc PP |
293 | return false; |
294 | } | |
295 | ||
834e9996 PP |
296 | if (ev_a->data.graph_src_sink_ports_connected.upstream_port != |
297 | ev_b->data.graph_src_sink_ports_connected.upstream_port) { | |
fb9935cc PP |
298 | return false; |
299 | } | |
300 | ||
834e9996 PP |
301 | if (ev_a->data.graph_src_sink_ports_connected.downstream_port != |
302 | ev_b->data.graph_src_sink_ports_connected.downstream_port) { | |
fb9935cc PP |
303 | return false; |
304 | } | |
305 | break; | |
834e9996 PP |
306 | case GRAPH_SRC_SINK_PORTS_DISCONNECTED: |
307 | if (ev_a->data.graph_src_sink_ports_disconnected.upstream_comp != | |
308 | ev_b->data.graph_src_sink_ports_disconnected.upstream_comp) { | |
fb9935cc PP |
309 | return false; |
310 | } | |
311 | ||
834e9996 PP |
312 | if (ev_a->data.graph_src_sink_ports_disconnected.downstream_comp != |
313 | ev_b->data.graph_src_sink_ports_disconnected.downstream_comp) { | |
fb9935cc PP |
314 | return false; |
315 | } | |
316 | ||
834e9996 PP |
317 | if (ev_a->data.graph_src_sink_ports_disconnected.upstream_port != |
318 | ev_b->data.graph_src_sink_ports_disconnected.upstream_port) { | |
fb9935cc PP |
319 | return false; |
320 | } | |
321 | ||
834e9996 PP |
322 | if (ev_a->data.graph_src_sink_ports_disconnected.downstream_port != |
323 | ev_b->data.graph_src_sink_ports_disconnected.downstream_port) { | |
fb9935cc PP |
324 | return false; |
325 | } | |
326 | break; | |
327 | default: | |
0fbb9a9f | 328 | abort(); |
fb9935cc PP |
329 | } |
330 | ||
331 | return true; | |
332 | } | |
333 | ||
334 | static | |
335 | bool has_event(struct event *event) | |
336 | { | |
337 | size_t i; | |
338 | ||
339 | for (i = 0; i < events->len; i++) { | |
340 | struct event *ev = &g_array_index(events, struct event, i); | |
341 | ||
342 | if (compare_events(event, ev)) { | |
343 | return true; | |
344 | } | |
345 | } | |
346 | ||
347 | return false; | |
348 | } | |
349 | ||
350 | static | |
351 | size_t event_pos(struct event *event) | |
352 | { | |
353 | size_t i; | |
354 | ||
355 | for (i = 0; i < events->len; i++) { | |
356 | struct event *ev = &g_array_index(events, struct event, i); | |
357 | ||
358 | if (compare_events(event, ev)) { | |
359 | return i; | |
360 | } | |
361 | } | |
362 | ||
41342c71 | 363 | return SIZE_MAX; |
fb9935cc PP |
364 | } |
365 | ||
366 | static | |
834e9996 PP |
367 | enum bt_self_notification_iterator_status src_iter_next( |
368 | struct bt_self_notification_iterator *self_iterator, | |
3fd7b79d PP |
369 | bt_notification_array notifs, uint64_t capacity, |
370 | uint64_t *count) | |
fb9935cc | 371 | { |
834e9996 | 372 | return BT_SELF_NOTIFICATION_ITERATOR_STATUS_ERROR; |
fb9935cc PP |
373 | } |
374 | ||
375 | static | |
834e9996 PP |
376 | enum bt_self_component_status src_accept_output_port_connection( |
377 | struct bt_self_component_source *self_comp, | |
378 | struct bt_self_component_port_output *self_comp_port, | |
379 | struct bt_port_input *other_port) | |
fb9935cc | 380 | { |
fb9935cc | 381 | struct event event = { |
834e9996 PP |
382 | .type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, |
383 | .data.src_comp_accept_output_port_connection = { | |
bb61965b PP |
384 | .comp = bt_self_component_as_component( |
385 | bt_self_component_source_as_self_component( | |
834e9996 | 386 | self_comp)), |
bb61965b PP |
387 | .self_port = bt_self_component_port_as_port( |
388 | bt_self_component_port_output_as_self_component_port( | |
834e9996 | 389 | self_comp_port)), |
bb61965b | 390 | .other_port = bt_port_input_as_port(other_port), |
fb9935cc PP |
391 | }, |
392 | }; | |
393 | ||
fb9935cc | 394 | append_event(&event); |
834e9996 | 395 | return BT_SELF_COMPONENT_STATUS_OK; |
c14181ff PP |
396 | } |
397 | ||
398 | static | |
834e9996 PP |
399 | enum bt_self_component_status sink_accept_input_port_connection( |
400 | struct bt_self_component_sink *self_comp, | |
401 | struct bt_self_component_port_input *self_comp_port, | |
402 | struct bt_port_output *other_port) | |
c14181ff | 403 | { |
834e9996 PP |
404 | struct event event = { |
405 | .type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, | |
406 | .data.sink_comp_accept_input_port_connection = { | |
bb61965b PP |
407 | .comp = bt_self_component_as_component( |
408 | bt_self_component_sink_as_self_component( | |
834e9996 | 409 | self_comp)), |
bb61965b PP |
410 | .self_port = bt_self_component_port_as_port( |
411 | bt_self_component_port_input_as_self_component_port( | |
834e9996 | 412 | self_comp_port)), |
bb61965b | 413 | .other_port = bt_port_output_as_port(other_port), |
834e9996 PP |
414 | }, |
415 | }; | |
c14181ff | 416 | |
834e9996 PP |
417 | append_event(&event); |
418 | return BT_SELF_COMPONENT_STATUS_OK; | |
419 | } | |
420 | ||
421 | static | |
422 | enum bt_self_component_status src_output_port_connected( | |
423 | struct bt_self_component_source *self_comp, | |
424 | struct bt_self_component_port_output *self_comp_port, | |
425 | struct bt_port_input *other_port) | |
426 | { | |
427 | int ret; | |
c14181ff | 428 | struct event event = { |
834e9996 PP |
429 | .type = SRC_COMP_OUTPUT_PORT_CONNECTED, |
430 | .data.src_comp_output_port_connected = { | |
bb61965b PP |
431 | .comp = bt_self_component_as_component( |
432 | bt_self_component_source_as_self_component( | |
834e9996 | 433 | self_comp)), |
bb61965b PP |
434 | .self_port = bt_self_component_port_as_port( |
435 | bt_self_component_port_output_as_self_component_port( | |
834e9996 | 436 | self_comp_port)), |
bb61965b | 437 | .other_port = bt_port_input_as_port(other_port), |
c14181ff PP |
438 | }, |
439 | }; | |
440 | ||
c14181ff | 441 | append_event(&event); |
fb9935cc PP |
442 | |
443 | switch (current_test) { | |
c14181ff | 444 | case TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED: |
834e9996 PP |
445 | ret = bt_self_component_source_add_output_port( |
446 | self_comp, "hello", NULL, NULL); | |
b8f13b8b | 447 | BT_ASSERT(ret == 0); |
fb9935cc | 448 | break; |
634f394c | 449 | case TEST_SRC_PORT_CONNECTED_ERROR: |
834e9996 | 450 | return BT_SELF_COMPONENT_STATUS_ERROR; |
fb9935cc PP |
451 | default: |
452 | break; | |
453 | } | |
634f394c | 454 | |
834e9996 | 455 | return BT_SELF_COMPONENT_STATUS_OK; |
fb9935cc PP |
456 | } |
457 | ||
458 | static | |
834e9996 PP |
459 | enum bt_self_component_status sink_input_port_connected( |
460 | struct bt_self_component_sink *self_comp, | |
461 | struct bt_self_component_port_input *self_comp_port, | |
462 | struct bt_port_output *other_port) | |
463 | { | |
464 | struct event event = { | |
465 | .type = SINK_COMP_INPUT_PORT_CONNECTED, | |
466 | .data.sink_comp_input_port_connected = { | |
bb61965b PP |
467 | .comp = bt_self_component_as_component( |
468 | bt_self_component_sink_as_self_component( | |
834e9996 | 469 | self_comp)), |
bb61965b PP |
470 | .self_port = bt_self_component_port_as_port( |
471 | bt_self_component_port_input_as_self_component_port( | |
834e9996 | 472 | self_comp_port)), |
bb61965b | 473 | .other_port = bt_port_output_as_port(other_port), |
834e9996 PP |
474 | }, |
475 | }; | |
476 | ||
477 | append_event(&event); | |
478 | ||
479 | if (current_test == TEST_SINK_PORT_CONNECTED_ERROR) { | |
480 | return BT_SELF_COMPONENT_STATUS_ERROR; | |
481 | } else { | |
482 | return BT_SELF_COMPONENT_STATUS_OK; | |
483 | } | |
484 | } | |
485 | ||
486 | static | |
487 | void src_output_port_disconnected(struct bt_self_component_source *self_comp, | |
488 | struct bt_self_component_port_output *self_comp_port) | |
fb9935cc PP |
489 | { |
490 | int ret; | |
491 | struct event event = { | |
834e9996 PP |
492 | .type = SRC_COMP_OUTPUT_PORT_DISCONNECTED, |
493 | .data.src_comp_output_port_disconnected = { | |
bb61965b PP |
494 | .comp = bt_self_component_as_component( |
495 | bt_self_component_source_as_self_component( | |
834e9996 | 496 | self_comp)), |
bb61965b PP |
497 | .self_port = bt_self_component_port_as_port( |
498 | bt_self_component_port_output_as_self_component_port( | |
834e9996 | 499 | self_comp_port)), |
fb9935cc PP |
500 | }, |
501 | }; | |
502 | ||
fb9935cc PP |
503 | append_event(&event); |
504 | ||
505 | switch (current_test) { | |
506 | case TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT: | |
834e9996 | 507 | ret = bt_self_component_port_remove_from_component( |
bb61965b | 508 | bt_self_component_port_output_as_self_component_port( |
834e9996 | 509 | self_comp_port)); |
b8f13b8b | 510 | BT_ASSERT(ret == 0); |
fb9935cc PP |
511 | default: |
512 | break; | |
513 | } | |
514 | } | |
515 | ||
b9d103be | 516 | static |
834e9996 PP |
517 | void sink_input_port_disconnected(struct bt_self_component_sink *self_comp, |
518 | struct bt_self_component_port_input *self_comp_port) | |
519 | { | |
520 | struct event event = { | |
521 | .type = SINK_COMP_INPUT_PORT_DISCONNECTED, | |
522 | .data.sink_comp_input_port_disconnected = { | |
bb61965b PP |
523 | .comp = bt_self_component_as_component( |
524 | bt_self_component_sink_as_self_component( | |
834e9996 | 525 | self_comp)), |
bb61965b PP |
526 | .self_port = bt_self_component_port_as_port( |
527 | bt_self_component_port_input_as_self_component_port( | |
834e9996 PP |
528 | self_comp_port)), |
529 | }, | |
530 | }; | |
531 | ||
532 | append_event(&event); | |
533 | } | |
534 | ||
535 | static | |
536 | enum bt_self_component_status src_init( | |
537 | struct bt_self_component_source *self_comp, | |
b9d103be PP |
538 | struct bt_value *params, void *init_method_data) |
539 | { | |
147337a3 | 540 | int ret; |
b9d103be | 541 | |
834e9996 PP |
542 | ret = bt_self_component_source_add_output_port( |
543 | self_comp, "out", NULL, NULL); | |
b8f13b8b | 544 | BT_ASSERT(ret == 0); |
834e9996 | 545 | return BT_SELF_COMPONENT_STATUS_OK; |
b9d103be PP |
546 | } |
547 | ||
fb9935cc | 548 | static |
834e9996 PP |
549 | enum bt_self_component_status sink_init( |
550 | struct bt_self_component_sink *self_comp, | |
551 | struct bt_value *params, void *init_method_data) | |
fb9935cc | 552 | { |
834e9996 PP |
553 | int ret; |
554 | ||
555 | ret = bt_self_component_sink_add_input_port(self_comp, | |
556 | "in", NULL, NULL); | |
557 | BT_ASSERT(ret == 0); | |
558 | return BT_SELF_COMPONENT_STATUS_OK; | |
559 | } | |
560 | ||
561 | static | |
562 | enum bt_self_component_status sink_consume( | |
563 | struct bt_self_component_sink *self_comp) | |
564 | { | |
565 | struct bt_self_component_port_input *def_port; | |
fb9935cc PP |
566 | int ret; |
567 | ||
568 | switch (current_test) { | |
569 | case TEST_SINK_REMOVES_PORT_IN_CONSUME: | |
570 | case TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT: | |
834e9996 PP |
571 | def_port = bt_self_component_sink_borrow_input_port_by_name( |
572 | self_comp, "in"); | |
b8f13b8b | 573 | BT_ASSERT(def_port); |
834e9996 | 574 | ret = bt_self_component_port_remove_from_component( |
bb61965b | 575 | bt_self_component_port_input_as_self_component_port( |
834e9996 | 576 | def_port)); |
b8f13b8b | 577 | BT_ASSERT(ret == 0); |
fb9935cc PP |
578 | break; |
579 | default: | |
580 | break; | |
581 | } | |
582 | ||
834e9996 | 583 | return BT_SELF_COMPONENT_STATUS_OK; |
fb9935cc PP |
584 | } |
585 | ||
586 | static | |
834e9996 PP |
587 | void graph_src_output_port_added(struct bt_component_source *comp, |
588 | struct bt_port_output *port, void *data) | |
fb9935cc PP |
589 | { |
590 | struct event event = { | |
834e9996 PP |
591 | .type = GRAPH_SRC_OUTPUT_PORT_ADDED, |
592 | .data.graph_src_output_port_added = { | |
bb61965b PP |
593 | .comp = bt_component_source_as_component(comp), |
594 | .port = bt_port_output_as_port(port), | |
fb9935cc PP |
595 | }, |
596 | }; | |
597 | ||
fb9935cc | 598 | append_event(&event); |
fb9935cc PP |
599 | } |
600 | ||
601 | static | |
834e9996 PP |
602 | void graph_sink_input_port_added(struct bt_component_sink *comp, |
603 | struct bt_port_input *port, void *data) | |
fb9935cc PP |
604 | { |
605 | struct event event = { | |
834e9996 PP |
606 | .type = GRAPH_SINK_INPUT_PORT_ADDED, |
607 | .data.graph_sink_input_port_added = { | |
bb61965b PP |
608 | .comp = bt_component_sink_as_component(comp), |
609 | .port = bt_port_input_as_port(port), | |
fb9935cc PP |
610 | }, |
611 | }; | |
612 | ||
fb9935cc PP |
613 | append_event(&event); |
614 | } | |
615 | ||
b9d103be | 616 | static |
834e9996 PP |
617 | void graph_src_output_port_removed(struct bt_component_source *comp, |
618 | struct bt_port_output *port, void *data) | |
fb9935cc | 619 | { |
fb9935cc | 620 | struct event event = { |
834e9996 PP |
621 | .type = GRAPH_SRC_OUTPUT_PORT_REMOVED, |
622 | .data.graph_src_output_port_removed = { | |
bb61965b PP |
623 | .comp = bt_component_source_as_component(comp), |
624 | .port = bt_port_output_as_port(port), | |
fb9935cc PP |
625 | }, |
626 | }; | |
627 | ||
628 | append_event(&event); | |
629 | } | |
630 | ||
631 | static | |
834e9996 PP |
632 | void graph_sink_input_port_removed(struct bt_component_sink *comp, |
633 | struct bt_port_input *port, void *data) | |
fb9935cc PP |
634 | { |
635 | struct event event = { | |
834e9996 PP |
636 | .type = GRAPH_SINK_INPUT_PORT_REMOVED, |
637 | .data.graph_sink_input_port_removed = { | |
bb61965b PP |
638 | .comp = bt_component_sink_as_component(comp), |
639 | .port = bt_port_input_as_port(port), | |
fb9935cc PP |
640 | }, |
641 | }; | |
642 | ||
643 | append_event(&event); | |
644 | } | |
645 | ||
646 | static | |
834e9996 PP |
647 | void graph_src_sink_ports_connected(struct bt_component_source *upstream_comp, |
648 | struct bt_component_sink *downstream_comp, | |
649 | struct bt_port_output *upstream_port, | |
650 | struct bt_port_input *downstream_port, void *data) | |
fb9935cc | 651 | { |
fb9935cc | 652 | struct event event = { |
834e9996 PP |
653 | .type = GRAPH_SRC_SINK_PORTS_CONNECTED, |
654 | .data.graph_src_sink_ports_connected = { | |
655 | .upstream_comp = | |
bb61965b | 656 | bt_component_source_as_component(upstream_comp), |
834e9996 | 657 | .downstream_comp = |
bb61965b | 658 | bt_component_sink_as_component(downstream_comp), |
834e9996 | 659 | .upstream_port = |
bb61965b | 660 | bt_port_output_as_port(upstream_port), |
834e9996 | 661 | .downstream_port = |
bb61965b | 662 | bt_port_input_as_port(downstream_port), |
fb9935cc PP |
663 | }, |
664 | }; | |
665 | ||
666 | append_event(&event); | |
667 | } | |
668 | ||
669 | static | |
834e9996 PP |
670 | void graph_src_sink_ports_disconnected(struct bt_component_source *upstream_comp, |
671 | struct bt_component_sink *downstream_comp, | |
672 | struct bt_port_output *upstream_port, | |
673 | struct bt_port_input *downstream_port, void *data) | |
fb9935cc PP |
674 | { |
675 | struct event event = { | |
834e9996 PP |
676 | .type = GRAPH_SRC_SINK_PORTS_DISCONNECTED, |
677 | .data.graph_src_sink_ports_disconnected = { | |
678 | .upstream_comp = | |
bb61965b | 679 | bt_component_source_as_component(upstream_comp), |
834e9996 | 680 | .downstream_comp = |
bb61965b | 681 | bt_component_sink_as_component(downstream_comp), |
834e9996 | 682 | .upstream_port = |
bb61965b | 683 | bt_port_output_as_port(upstream_port), |
834e9996 | 684 | .downstream_port = |
bb61965b | 685 | bt_port_input_as_port(downstream_port), |
fb9935cc PP |
686 | }, |
687 | }; | |
688 | ||
689 | append_event(&event); | |
690 | } | |
691 | ||
692 | static | |
693 | void init_test(void) | |
694 | { | |
695 | int ret; | |
696 | ||
834e9996 PP |
697 | src_comp_class = bt_private_component_class_source_create( |
698 | "src", src_iter_next); | |
b8f13b8b | 699 | BT_ASSERT(src_comp_class); |
834e9996 PP |
700 | ret = bt_private_component_class_source_set_init_method( |
701 | src_comp_class, src_init); | |
b8f13b8b | 702 | BT_ASSERT(ret == 0); |
834e9996 PP |
703 | ret = bt_private_component_class_source_set_accept_output_port_connection_method( |
704 | src_comp_class, src_accept_output_port_connection); | |
b8f13b8b | 705 | BT_ASSERT(ret == 0); |
834e9996 PP |
706 | ret = bt_private_component_class_source_set_output_port_connected_method( |
707 | src_comp_class, src_output_port_connected); | |
b8f13b8b | 708 | BT_ASSERT(ret == 0); |
834e9996 PP |
709 | ret = bt_private_component_class_source_set_output_port_disconnected_method( |
710 | src_comp_class, src_output_port_disconnected); | |
b8f13b8b | 711 | BT_ASSERT(ret == 0); |
834e9996 PP |
712 | sink_comp_class = bt_private_component_class_sink_create("sink", |
713 | sink_consume); | |
b8f13b8b | 714 | BT_ASSERT(sink_comp_class); |
834e9996 PP |
715 | ret = bt_private_component_class_sink_set_init_method(sink_comp_class, |
716 | sink_init); | |
b8f13b8b | 717 | BT_ASSERT(ret == 0); |
834e9996 PP |
718 | ret = bt_private_component_class_sink_set_accept_input_port_connection_method( |
719 | sink_comp_class, sink_accept_input_port_connection); | |
b8f13b8b | 720 | BT_ASSERT(ret == 0); |
834e9996 PP |
721 | ret = bt_private_component_class_sink_set_input_port_connected_method( |
722 | sink_comp_class, sink_input_port_connected); | |
b8f13b8b | 723 | BT_ASSERT(ret == 0); |
834e9996 PP |
724 | ret = bt_private_component_class_sink_set_input_port_disconnected_method( |
725 | sink_comp_class, sink_input_port_disconnected); | |
b8f13b8b | 726 | BT_ASSERT(ret == 0); |
fb9935cc | 727 | events = g_array_new(FALSE, TRUE, sizeof(struct event)); |
b8f13b8b | 728 | BT_ASSERT(events); |
fb9935cc PP |
729 | } |
730 | ||
731 | static | |
732 | void fini_test(void) | |
733 | { | |
8138bfe1 PP |
734 | bt_object_put_ref(src_comp_class); |
735 | bt_object_put_ref(sink_comp_class); | |
fb9935cc PP |
736 | g_array_free(events, TRUE); |
737 | } | |
738 | ||
739 | static | |
834e9996 | 740 | struct bt_component_source *create_src(struct bt_private_graph *graph) |
fb9935cc | 741 | { |
834e9996 | 742 | struct bt_component_source *comp; |
36712f1d | 743 | int ret; |
fb9935cc | 744 | |
834e9996 | 745 | ret = bt_private_graph_add_source_component(graph, |
bb61965b | 746 | bt_private_component_class_source_as_component_class_source( |
834e9996 PP |
747 | src_comp_class), |
748 | "src-comp", NULL, &comp); | |
b8f13b8b | 749 | BT_ASSERT(ret == 0); |
fb9935cc PP |
750 | return comp; |
751 | } | |
752 | ||
753 | static | |
834e9996 | 754 | struct bt_component_sink *create_sink(struct bt_private_graph *graph) |
fb9935cc | 755 | { |
834e9996 | 756 | struct bt_component_sink *comp; |
36712f1d | 757 | int ret; |
fb9935cc | 758 | |
834e9996 | 759 | ret = bt_private_graph_add_sink_component(graph, |
bb61965b | 760 | bt_private_component_class_sink_as_component_class_sink( |
834e9996 PP |
761 | sink_comp_class), |
762 | "sink-comp", NULL, &comp); | |
b8f13b8b | 763 | BT_ASSERT(ret == 0); |
fb9935cc PP |
764 | return comp; |
765 | } | |
766 | ||
767 | static | |
8d750b42 | 768 | struct bt_private_graph *create_graph(void) |
fb9935cc | 769 | { |
8d750b42 | 770 | struct bt_private_graph *graph = bt_private_graph_create(); |
fb9935cc PP |
771 | int ret; |
772 | ||
b8f13b8b | 773 | BT_ASSERT(graph); |
834e9996 PP |
774 | ret = bt_private_graph_add_source_component_output_port_added_listener( |
775 | graph, graph_src_output_port_added, NULL, NULL, NULL); | |
776 | BT_ASSERT(ret >= 0); | |
777 | ret = bt_private_graph_add_sink_component_input_port_added_listener( | |
778 | graph, graph_sink_input_port_added, NULL, NULL, NULL); | |
b8f13b8b | 779 | BT_ASSERT(ret >= 0); |
834e9996 PP |
780 | ret = bt_private_graph_add_source_component_output_port_removed_listener( |
781 | graph, graph_src_output_port_removed, NULL, NULL, NULL); | |
b8f13b8b | 782 | BT_ASSERT(ret >= 0); |
834e9996 PP |
783 | ret = bt_private_graph_add_sink_component_input_port_removed_listener( |
784 | graph, graph_sink_input_port_removed, NULL, NULL, NULL); | |
b8f13b8b | 785 | BT_ASSERT(ret >= 0); |
834e9996 PP |
786 | ret = bt_private_graph_add_source_sink_component_ports_connected_listener( |
787 | graph, graph_src_sink_ports_connected, NULL, NULL, NULL); | |
788 | BT_ASSERT(ret >= 0); | |
789 | ret = bt_private_graph_add_source_sink_component_ports_disconnected_listener( | |
790 | graph, graph_src_sink_ports_disconnected, NULL, NULL, NULL); | |
b8f13b8b | 791 | BT_ASSERT(ret >= 0); |
fb9935cc PP |
792 | return graph; |
793 | } | |
794 | ||
795 | static | |
796 | void prepare_test(enum test test, const char *name) | |
797 | { | |
798 | clear_events(); | |
799 | current_test = test; | |
800 | diag("test: %s", name); | |
801 | } | |
802 | ||
803 | static | |
834e9996 | 804 | void test_sink_removes_port_in_consume_then_src_removes_disconnected_port(void) |
fb9935cc PP |
805 | { |
806 | int ret; | |
834e9996 PP |
807 | struct bt_component_source *src; |
808 | struct bt_component_sink *sink; | |
809 | struct bt_component *gsrc; | |
810 | struct bt_component *gsink; | |
8d750b42 | 811 | struct bt_private_graph *graph; |
834e9996 PP |
812 | struct bt_port_output *src_def_port; |
813 | struct bt_port_input *sink_def_port; | |
814 | struct bt_port *gsrc_def_port; | |
815 | struct bt_port *gsink_def_port; | |
fb9935cc | 816 | struct event event; |
a256a42d | 817 | enum bt_graph_status status; |
c14181ff PP |
818 | size_t src_accept_port_connection_pos; |
819 | size_t sink_accept_port_connection_pos; | |
820 | size_t src_port_connected_pos; | |
821 | size_t sink_port_connected_pos; | |
834e9996 | 822 | size_t graph_ports_connected_pos; |
fb9935cc PP |
823 | size_t src_port_disconnected_pos; |
824 | size_t sink_port_disconnected_pos; | |
825 | size_t graph_ports_disconnected_pos; | |
826 | size_t graph_port_removed_src_pos; | |
827 | size_t graph_port_removed_sink_pos; | |
828 | ||
829 | prepare_test(TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT, | |
830 | "sink removes port in consume, then source removes disconnected port"); | |
fb9935cc | 831 | graph = create_graph(); |
b8f13b8b | 832 | BT_ASSERT(graph); |
36712f1d PP |
833 | src = create_src(graph); |
834 | sink = create_sink(graph); | |
834e9996 | 835 | src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); |
b8f13b8b | 836 | BT_ASSERT(src_def_port); |
834e9996 | 837 | sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); |
b8f13b8b | 838 | BT_ASSERT(sink_def_port); |
834e9996 PP |
839 | status = bt_private_graph_connect_ports(graph, src_def_port, |
840 | sink_def_port, NULL); | |
b8f13b8b | 841 | BT_ASSERT(status == 0); |
bb61965b PP |
842 | gsrc = bt_component_source_as_component(src); |
843 | gsink = bt_component_sink_as_component(sink); | |
844 | gsrc_def_port = bt_port_output_as_port(src_def_port); | |
845 | gsink_def_port = bt_port_input_as_port(sink_def_port); | |
fb9935cc | 846 | |
36712f1d PP |
847 | /* We're supposed to have 7 events so far */ |
848 | ok(events->len == 7, "we have the expected number of events (before consume)"); | |
849 | ||
850 | /* Source's port added */ | |
834e9996 PP |
851 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
852 | event.data.graph_src_output_port_added.comp = gsrc; | |
853 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
854 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
855 | ||
856 | /* Sink's port added */ | |
834e9996 PP |
857 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
858 | event.data.graph_sink_input_port_added.comp = gsink; | |
859 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 860 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
861 | |
862 | /* Source's accept port connection */ | |
834e9996 PP |
863 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
864 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
865 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
866 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 867 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff | 868 | src_accept_port_connection_pos = event_pos(&event); |
fb9935cc PP |
869 | |
870 | /* Sink's accept port connection */ | |
834e9996 PP |
871 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
872 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
873 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
874 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
fb9935cc | 875 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
c14181ff PP |
876 | sink_accept_port_connection_pos = event_pos(&event); |
877 | ||
878 | /* Source's port connected */ | |
834e9996 PP |
879 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
880 | event.data.src_comp_output_port_connected.comp = gsrc; | |
881 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
882 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
883 | ok(has_event(&event), "got the expected source's port connected event"); |
884 | src_port_connected_pos = event_pos(&event); | |
885 | ||
886 | /* Sink's port connected */ | |
834e9996 PP |
887 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
888 | event.data.sink_comp_input_port_connected.comp = gsink; | |
889 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
890 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
891 | ok(has_event(&event), "got the expected sink's port connected event"); |
892 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
893 | |
894 | /* Graph's ports connected */ | |
834e9996 PP |
895 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; |
896 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
897 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
898 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
899 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
fb9935cc | 900 | ok(has_event(&event), "got the expected graph's ports connected event"); |
834e9996 | 901 | graph_ports_connected_pos = event_pos(&event); |
fb9935cc PP |
902 | |
903 | /* Order of events */ | |
834e9996 | 904 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 905 | "event order is good (1)"); |
834e9996 | 906 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 907 | "event order is good (2)"); |
c14181ff PP |
908 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
909 | "event order is good (3)"); | |
910 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
911 | "event order is good (4)"); | |
fb9935cc PP |
912 | |
913 | /* Consume sink once */ | |
914 | clear_events(); | |
8d750b42 | 915 | ret = bt_private_graph_consume(graph); |
b8f13b8b | 916 | BT_ASSERT(ret == 0); |
fb9935cc PP |
917 | |
918 | /* We're supposed to have 5 new events */ | |
919 | ok(events->len == 5, "we have the expected number of events (after consume)"); | |
920 | ||
921 | /* Source's port disconnected */ | |
834e9996 PP |
922 | event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; |
923 | event.data.src_comp_output_port_disconnected.comp = gsrc; | |
924 | event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; | |
fb9935cc PP |
925 | ok(has_event(&event), "got the expected source's port disconnected event"); |
926 | src_port_disconnected_pos = event_pos(&event); | |
927 | ||
928 | /* Sink's port disconnected */ | |
834e9996 PP |
929 | event.type = SINK_COMP_INPUT_PORT_DISCONNECTED; |
930 | event.data.sink_comp_input_port_disconnected.comp = gsink; | |
931 | event.data.sink_comp_input_port_disconnected.self_port = gsink_def_port; | |
fb9935cc PP |
932 | ok(has_event(&event), "got the expected sink's port disconnected event"); |
933 | sink_port_disconnected_pos = event_pos(&event); | |
934 | ||
935 | /* Graph's ports disconnected */ | |
834e9996 PP |
936 | event.type = GRAPH_SRC_SINK_PORTS_DISCONNECTED; |
937 | event.data.graph_src_sink_ports_disconnected.upstream_comp = gsrc; | |
938 | event.data.graph_src_sink_ports_disconnected.downstream_comp = gsink; | |
939 | event.data.graph_src_sink_ports_disconnected.upstream_port = gsrc_def_port; | |
940 | event.data.graph_src_sink_ports_disconnected.downstream_port = gsink_def_port; | |
fb9935cc PP |
941 | ok(has_event(&event), "got the expected graph's ports disconnected event"); |
942 | graph_ports_disconnected_pos = event_pos(&event); | |
943 | ||
944 | /* Graph's port removed (sink) */ | |
834e9996 PP |
945 | event.type = GRAPH_SINK_INPUT_PORT_REMOVED; |
946 | event.data.graph_sink_input_port_removed.comp = gsink; | |
947 | event.data.graph_sink_input_port_removed.port = gsink_def_port; | |
fb9935cc PP |
948 | ok(has_event(&event), "got the expected graph's port removed event (for sink)"); |
949 | graph_port_removed_sink_pos = event_pos(&event); | |
950 | ||
951 | /* Graph's port removed (source) */ | |
834e9996 PP |
952 | event.type = GRAPH_SRC_OUTPUT_PORT_REMOVED; |
953 | event.data.graph_src_output_port_removed.comp = gsrc; | |
954 | event.data.graph_src_output_port_removed.port = gsrc_def_port; | |
fb9935cc PP |
955 | ok(has_event(&event), "got the expected graph's port removed event (for source)"); |
956 | graph_port_removed_src_pos = event_pos(&event); | |
957 | ||
958 | /* Order of events */ | |
959 | ok(src_port_disconnected_pos < graph_ports_disconnected_pos, | |
960 | "event order is good (5)"); | |
961 | ok(src_port_disconnected_pos < graph_port_removed_sink_pos, | |
962 | "event order is good (6)"); | |
963 | ok(src_port_disconnected_pos < graph_port_removed_src_pos, | |
964 | "event order is good (7)"); | |
965 | ok(sink_port_disconnected_pos < graph_ports_disconnected_pos, | |
966 | "event order is good (8)"); | |
967 | ok(sink_port_disconnected_pos < graph_port_removed_sink_pos, | |
968 | "event order is good (9)"); | |
969 | ok(sink_port_disconnected_pos < graph_port_removed_src_pos, | |
970 | "event order is good (10)"); | |
971 | ok(graph_ports_disconnected_pos < graph_port_removed_sink_pos, | |
972 | "event order is good (11)"); | |
973 | ok(graph_port_removed_src_pos < graph_ports_disconnected_pos, | |
974 | "event order is good (12)"); | |
975 | ok(graph_port_removed_src_pos < graph_port_removed_sink_pos, | |
976 | "event order is good (13)"); | |
977 | ||
8138bfe1 PP |
978 | bt_object_put_ref(graph); |
979 | bt_object_put_ref(sink); | |
980 | bt_object_put_ref(src); | |
fb9935cc PP |
981 | } |
982 | ||
983 | static | |
834e9996 | 984 | void test_sink_removes_port_in_consume(void) |
fb9935cc PP |
985 | { |
986 | int ret; | |
834e9996 PP |
987 | struct bt_component_source *src; |
988 | struct bt_component_sink *sink; | |
989 | struct bt_component *gsrc; | |
990 | struct bt_component *gsink; | |
8d750b42 | 991 | struct bt_private_graph *graph; |
834e9996 PP |
992 | struct bt_port_output *src_def_port; |
993 | struct bt_port_input *sink_def_port; | |
994 | struct bt_port *gsrc_def_port; | |
995 | struct bt_port *gsink_def_port; | |
fb9935cc | 996 | struct event event; |
a256a42d | 997 | enum bt_graph_status status; |
c14181ff PP |
998 | size_t src_accept_port_connection_pos; |
999 | size_t sink_accept_port_connection_pos; | |
1000 | size_t src_port_connected_pos; | |
1001 | size_t sink_port_connected_pos; | |
fb9935cc PP |
1002 | size_t graph_ports_connected_pos; |
1003 | size_t src_port_disconnected_pos; | |
1004 | size_t sink_port_disconnected_pos; | |
1005 | size_t graph_ports_disconnected_pos; | |
1006 | size_t graph_port_removed_sink_pos; | |
1007 | ||
1008 | prepare_test(TEST_SINK_REMOVES_PORT_IN_CONSUME, | |
1009 | "sink removes port in consume"); | |
fb9935cc | 1010 | graph = create_graph(); |
b8f13b8b | 1011 | BT_ASSERT(graph); |
36712f1d PP |
1012 | src = create_src(graph); |
1013 | sink = create_sink(graph); | |
834e9996 | 1014 | src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); |
b8f13b8b | 1015 | BT_ASSERT(src_def_port); |
834e9996 | 1016 | sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); |
b8f13b8b | 1017 | BT_ASSERT(sink_def_port); |
834e9996 PP |
1018 | status = bt_private_graph_connect_ports(graph, src_def_port, |
1019 | sink_def_port, NULL); | |
b8f13b8b | 1020 | BT_ASSERT(status == 0); |
bb61965b PP |
1021 | gsrc = bt_component_source_as_component(src); |
1022 | gsink = bt_component_sink_as_component(sink); | |
1023 | gsrc_def_port = bt_port_output_as_port(src_def_port); | |
1024 | gsink_def_port = bt_port_input_as_port(sink_def_port); | |
fb9935cc | 1025 | |
36712f1d PP |
1026 | /* We're supposed to have 7 events so far */ |
1027 | ok(events->len == 7, "we have the expected number of events (before consume)"); | |
1028 | ||
1029 | /* Source's port added */ | |
834e9996 PP |
1030 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
1031 | event.data.graph_src_output_port_added.comp = gsrc; | |
1032 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
1033 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
1034 | ||
1035 | /* Sink's port added */ | |
834e9996 PP |
1036 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
1037 | event.data.graph_sink_input_port_added.comp = gsink; | |
1038 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 1039 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
1040 | |
1041 | /* Source's accept port connection */ | |
834e9996 PP |
1042 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
1043 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
1044 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
1045 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 1046 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff | 1047 | src_accept_port_connection_pos = event_pos(&event); |
fb9935cc PP |
1048 | |
1049 | /* Sink's accept port connection */ | |
834e9996 PP |
1050 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
1051 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
1052 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
1053 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
fb9935cc | 1054 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
c14181ff PP |
1055 | sink_accept_port_connection_pos = event_pos(&event); |
1056 | ||
1057 | /* Source's port connected */ | |
834e9996 PP |
1058 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
1059 | event.data.src_comp_output_port_connected.comp = gsrc; | |
1060 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
1061 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
1062 | ok(has_event(&event), "got the expected source's port connected event"); |
1063 | src_port_connected_pos = event_pos(&event); | |
1064 | ||
1065 | /* Sink's port connected */ | |
834e9996 PP |
1066 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
1067 | event.data.sink_comp_input_port_connected.comp = gsink; | |
1068 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
1069 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
1070 | ok(has_event(&event), "got the expected sink's port connected event"); |
1071 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
1072 | |
1073 | /* Graph's ports connected */ | |
834e9996 PP |
1074 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; |
1075 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
1076 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
1077 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
1078 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
fb9935cc PP |
1079 | ok(has_event(&event), "got the expected graph's ports connected event"); |
1080 | graph_ports_connected_pos = event_pos(&event); | |
1081 | ||
1082 | /* Order of events */ | |
c14181ff | 1083 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 1084 | "event order is good (1)"); |
c14181ff | 1085 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 1086 | "event order is good (2)"); |
c14181ff PP |
1087 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
1088 | "event order is good (3)"); | |
1089 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
1090 | "event order is good (4)"); | |
fb9935cc PP |
1091 | |
1092 | /* Consume sink once */ | |
1093 | clear_events(); | |
8d750b42 | 1094 | ret = bt_private_graph_consume(graph); |
b8f13b8b | 1095 | BT_ASSERT(ret == 0); |
fb9935cc PP |
1096 | |
1097 | /* We're supposed to have 4 new events */ | |
1098 | ok(events->len == 4, "we have the expected number of events (after consume)"); | |
1099 | ||
1100 | /* Source's port disconnected */ | |
834e9996 PP |
1101 | event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; |
1102 | event.data.src_comp_output_port_disconnected.comp = gsrc; | |
1103 | event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; | |
fb9935cc PP |
1104 | ok(has_event(&event), "got the expected source's port disconnected event"); |
1105 | src_port_disconnected_pos = event_pos(&event); | |
1106 | ||
1107 | /* Sink's port disconnected */ | |
834e9996 PP |
1108 | event.type = SINK_COMP_INPUT_PORT_DISCONNECTED; |
1109 | event.data.sink_comp_input_port_disconnected.comp = gsink; | |
1110 | event.data.sink_comp_input_port_disconnected.self_port = gsink_def_port; | |
fb9935cc PP |
1111 | ok(has_event(&event), "got the expected sink's port disconnected event"); |
1112 | sink_port_disconnected_pos = event_pos(&event); | |
1113 | ||
1114 | /* Graph's ports disconnected */ | |
834e9996 PP |
1115 | event.type = GRAPH_SRC_SINK_PORTS_DISCONNECTED; |
1116 | event.data.graph_src_sink_ports_disconnected.upstream_comp = gsrc; | |
1117 | event.data.graph_src_sink_ports_disconnected.downstream_comp = gsink; | |
1118 | event.data.graph_src_sink_ports_disconnected.upstream_port = gsrc_def_port; | |
1119 | event.data.graph_src_sink_ports_disconnected.downstream_port = gsink_def_port; | |
fb9935cc PP |
1120 | ok(has_event(&event), "got the expected graph's ports disconnected event"); |
1121 | graph_ports_disconnected_pos = event_pos(&event); | |
1122 | ||
1123 | /* Graph's port removed (sink) */ | |
834e9996 PP |
1124 | event.type = GRAPH_SINK_INPUT_PORT_REMOVED; |
1125 | event.data.graph_sink_input_port_removed.comp = gsink; | |
1126 | event.data.graph_sink_input_port_removed.port = gsink_def_port; | |
fb9935cc PP |
1127 | ok(has_event(&event), "got the expected graph's port removed event (for sink)"); |
1128 | graph_port_removed_sink_pos = event_pos(&event); | |
1129 | ||
1130 | /* Order of events */ | |
1131 | ok(src_port_disconnected_pos < graph_ports_disconnected_pos, | |
1132 | "event order is good (5)"); | |
1133 | ok(src_port_disconnected_pos < graph_port_removed_sink_pos, | |
1134 | "event order is good (7)"); | |
1135 | ok(sink_port_disconnected_pos < graph_ports_disconnected_pos, | |
1136 | "event order is good (8)"); | |
1137 | ok(sink_port_disconnected_pos < graph_port_removed_sink_pos, | |
1138 | "event order is good (10)"); | |
1139 | ok(graph_ports_disconnected_pos < graph_port_removed_sink_pos, | |
1140 | "event order is good (11)"); | |
1141 | ||
8138bfe1 PP |
1142 | bt_object_put_ref(sink); |
1143 | bt_object_put_ref(src); | |
834e9996 | 1144 | bt_object_put_ref(graph); |
fb9935cc PP |
1145 | } |
1146 | ||
1147 | static | |
c14181ff | 1148 | void test_src_adds_port_in_port_connected(void) |
fb9935cc | 1149 | { |
834e9996 PP |
1150 | struct bt_component_source *src; |
1151 | struct bt_component_sink *sink; | |
1152 | struct bt_component *gsrc; | |
1153 | struct bt_component *gsink; | |
8d750b42 | 1154 | struct bt_private_graph *graph; |
834e9996 PP |
1155 | struct bt_port_output *src_def_port; |
1156 | struct bt_port_output *src_hello_port; | |
1157 | struct bt_port_input *sink_def_port; | |
1158 | struct bt_port *gsrc_def_port; | |
1159 | struct bt_port *gsrc_hello_port; | |
1160 | struct bt_port *gsink_def_port; | |
fb9935cc | 1161 | struct event event; |
a256a42d | 1162 | enum bt_graph_status status; |
c14181ff PP |
1163 | size_t src_accept_port_connection_pos; |
1164 | size_t sink_accept_port_connection_pos; | |
1165 | size_t src_port_connected_pos; | |
1166 | size_t sink_port_connected_pos; | |
fb9935cc PP |
1167 | size_t graph_ports_connected_pos; |
1168 | size_t graph_port_added_src_pos; | |
1169 | ||
c14181ff PP |
1170 | prepare_test(TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED, |
1171 | "source adds port in port connected"); | |
fb9935cc | 1172 | graph = create_graph(); |
b8f13b8b | 1173 | BT_ASSERT(graph); |
36712f1d PP |
1174 | src = create_src(graph); |
1175 | sink = create_sink(graph); | |
834e9996 | 1176 | src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); |
b8f13b8b | 1177 | BT_ASSERT(src_def_port); |
834e9996 | 1178 | sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); |
b8f13b8b | 1179 | BT_ASSERT(sink_def_port); |
834e9996 PP |
1180 | status = bt_private_graph_connect_ports(graph, src_def_port, |
1181 | sink_def_port, NULL); | |
b8f13b8b | 1182 | BT_ASSERT(status == 0); |
834e9996 | 1183 | src_hello_port = bt_component_source_borrow_output_port_by_name(src, |
9ac68eb1 | 1184 | "hello"); |
b8f13b8b | 1185 | BT_ASSERT(src_hello_port); |
bb61965b PP |
1186 | gsrc = bt_component_source_as_component(src); |
1187 | gsink = bt_component_sink_as_component(sink); | |
1188 | gsrc_def_port = bt_port_output_as_port(src_def_port); | |
1189 | gsrc_hello_port = bt_port_output_as_port(src_hello_port); | |
1190 | gsink_def_port = bt_port_input_as_port(sink_def_port); | |
fb9935cc | 1191 | |
36712f1d PP |
1192 | /* We're supposed to have 8 events */ |
1193 | ok(events->len == 8, "we have the expected number of events"); | |
1194 | ||
1195 | /* Source's port added */ | |
834e9996 PP |
1196 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
1197 | event.data.graph_src_output_port_added.comp = gsrc; | |
1198 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
1199 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
1200 | ||
1201 | /* Sink's port added */ | |
834e9996 PP |
1202 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
1203 | event.data.graph_sink_input_port_added.comp = gsink; | |
1204 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 1205 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
1206 | |
1207 | /* Source's accept port connection */ | |
834e9996 PP |
1208 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
1209 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
1210 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
1211 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 1212 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff PP |
1213 | src_accept_port_connection_pos = event_pos(&event); |
1214 | ||
1215 | /* Sink's accept port connection */ | |
834e9996 PP |
1216 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
1217 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
1218 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
1219 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
c14181ff PP |
1220 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
1221 | sink_accept_port_connection_pos = event_pos(&event); | |
1222 | ||
1223 | /* Source's port connected */ | |
834e9996 PP |
1224 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
1225 | event.data.src_comp_output_port_connected.comp = gsrc; | |
1226 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
1227 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
1228 | ok(has_event(&event), "got the expected source's port connected event"); |
1229 | src_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
1230 | |
1231 | /* Graph's port added (source) */ | |
834e9996 PP |
1232 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
1233 | event.data.graph_src_output_port_added.comp = gsrc; | |
1234 | event.data.graph_src_output_port_added.port = gsrc_hello_port; | |
fb9935cc PP |
1235 | ok(has_event(&event), "got the expected graph's port added event (for source)"); |
1236 | graph_port_added_src_pos = event_pos(&event); | |
1237 | ||
c14181ff | 1238 | /* Sink's port connected */ |
834e9996 PP |
1239 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
1240 | event.data.sink_comp_input_port_connected.comp = gsink; | |
1241 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
1242 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
1243 | ok(has_event(&event), "got the expected sink's port connected event"); |
1244 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc PP |
1245 | |
1246 | /* Graph's ports connected */ | |
834e9996 PP |
1247 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; |
1248 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
1249 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
1250 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
1251 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
1252 | ok(has_event(&event), "got the expected graph's ports connected event"); | |
fb9935cc PP |
1253 | graph_ports_connected_pos = event_pos(&event); |
1254 | ||
1255 | /* Order of events */ | |
c14181ff | 1256 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 1257 | "event order is good (1)"); |
c14181ff | 1258 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 1259 | "event order is good (2)"); |
c14181ff | 1260 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
fb9935cc | 1261 | "event order is good (3)"); |
c14181ff | 1262 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, |
fb9935cc | 1263 | "event order is good (4)"); |
c14181ff PP |
1264 | ok(src_port_connected_pos < graph_port_added_src_pos, |
1265 | "event order is good (5)"); | |
1266 | ok(graph_port_added_src_pos < graph_ports_connected_pos, | |
1267 | "event order is good (6)"); | |
fb9935cc | 1268 | |
8138bfe1 | 1269 | bt_object_put_ref(src); |
834e9996 PP |
1270 | bt_object_put_ref(sink); |
1271 | bt_object_put_ref(graph); | |
fb9935cc PP |
1272 | } |
1273 | ||
1274 | static | |
1275 | void test_simple(void) | |
1276 | { | |
834e9996 PP |
1277 | struct bt_component_source *src; |
1278 | struct bt_component_sink *sink; | |
1279 | struct bt_component *gsrc; | |
1280 | struct bt_component *gsink; | |
8d750b42 | 1281 | struct bt_private_graph *graph; |
834e9996 PP |
1282 | struct bt_port_output *src_def_port; |
1283 | struct bt_port_input *sink_def_port; | |
1284 | struct bt_port *gsrc_def_port; | |
1285 | struct bt_port *gsink_def_port; | |
fb9935cc | 1286 | struct event event; |
a256a42d | 1287 | enum bt_graph_status status; |
c14181ff PP |
1288 | size_t src_accept_port_connection_pos; |
1289 | size_t sink_accept_port_connection_pos; | |
1290 | size_t src_port_connected_pos; | |
1291 | size_t sink_port_connected_pos; | |
fb9935cc PP |
1292 | size_t graph_ports_connected_pos; |
1293 | ||
1294 | prepare_test(TEST_SIMPLE, "simple"); | |
fb9935cc | 1295 | graph = create_graph(); |
b8f13b8b | 1296 | BT_ASSERT(graph); |
36712f1d PP |
1297 | src = create_src(graph); |
1298 | sink = create_sink(graph); | |
834e9996 | 1299 | src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); |
b8f13b8b | 1300 | BT_ASSERT(src_def_port); |
834e9996 | 1301 | sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); |
b8f13b8b | 1302 | BT_ASSERT(sink_def_port); |
834e9996 PP |
1303 | status = bt_private_graph_connect_ports(graph, src_def_port, |
1304 | sink_def_port, NULL); | |
b8f13b8b | 1305 | BT_ASSERT(status == 0); |
bb61965b PP |
1306 | gsrc = bt_component_source_as_component(src); |
1307 | gsink = bt_component_sink_as_component(sink); | |
1308 | gsrc_def_port = bt_port_output_as_port(src_def_port); | |
1309 | gsink_def_port = bt_port_input_as_port(sink_def_port); | |
fb9935cc | 1310 | |
36712f1d PP |
1311 | /* We're supposed to have 7 events */ |
1312 | ok(events->len == 7, "we have the expected number of events"); | |
1313 | ||
1314 | /* Source's port added */ | |
834e9996 PP |
1315 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
1316 | event.data.graph_src_output_port_added.comp = gsrc; | |
1317 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
36712f1d PP |
1318 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
1319 | ||
1320 | /* Sink's port added */ | |
834e9996 PP |
1321 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
1322 | event.data.graph_sink_input_port_added.comp = gsink; | |
1323 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
36712f1d | 1324 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
fb9935cc PP |
1325 | |
1326 | /* Source's accept port connection */ | |
834e9996 PP |
1327 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
1328 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
1329 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
1330 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
fb9935cc | 1331 | ok(has_event(&event), "got the expected source's accept port connection event"); |
c14181ff | 1332 | src_accept_port_connection_pos = event_pos(&event); |
fb9935cc PP |
1333 | |
1334 | /* Sink's accept port connection */ | |
834e9996 PP |
1335 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
1336 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
1337 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
1338 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
fb9935cc | 1339 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
c14181ff PP |
1340 | sink_accept_port_connection_pos = event_pos(&event); |
1341 | ||
1342 | /* Source's port connected */ | |
834e9996 PP |
1343 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
1344 | event.data.src_comp_output_port_connected.comp = gsrc; | |
1345 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
1346 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
c14181ff PP |
1347 | ok(has_event(&event), "got the expected source's port connected event"); |
1348 | src_port_connected_pos = event_pos(&event); | |
1349 | ||
1350 | /* Sink's port connected */ | |
834e9996 PP |
1351 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
1352 | event.data.sink_comp_input_port_connected.comp = gsink; | |
1353 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
1354 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
c14181ff PP |
1355 | ok(has_event(&event), "got the expected sink's port connected event"); |
1356 | sink_port_connected_pos = event_pos(&event); | |
fb9935cc | 1357 | |
834e9996 PP |
1358 | /* Graph's ports connected */ |
1359 | event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; | |
1360 | event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; | |
1361 | event.data.graph_src_sink_ports_connected.downstream_comp = gsink; | |
1362 | event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; | |
1363 | event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; | |
fb9935cc PP |
1364 | ok(has_event(&event), "got the expected graph's ports connected event"); |
1365 | graph_ports_connected_pos = event_pos(&event); | |
1366 | ||
1367 | /* Order of events */ | |
c14181ff | 1368 | ok(src_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 1369 | "event order is good (1)"); |
c14181ff | 1370 | ok(sink_port_connected_pos < graph_ports_connected_pos, |
fb9935cc | 1371 | "event order is good (2)"); |
c14181ff PP |
1372 | ok(src_accept_port_connection_pos < src_port_connected_pos, |
1373 | "event order is good (3)"); | |
1374 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
1375 | "event order is good (4)"); | |
fb9935cc | 1376 | |
8138bfe1 | 1377 | bt_object_put_ref(sink); |
834e9996 | 1378 | bt_object_put_ref(graph); |
8138bfe1 | 1379 | bt_object_put_ref(src); |
fb9935cc PP |
1380 | } |
1381 | ||
634f394c PP |
1382 | static |
1383 | void test_src_port_connected_error(void) | |
1384 | { | |
834e9996 PP |
1385 | struct bt_component_source *src; |
1386 | struct bt_component_sink *sink; | |
1387 | struct bt_component *gsrc; | |
1388 | struct bt_component *gsink; | |
8d750b42 | 1389 | struct bt_private_graph *graph; |
834e9996 PP |
1390 | struct bt_port_output *src_def_port; |
1391 | struct bt_port_input *sink_def_port; | |
1392 | struct bt_port *gsrc_def_port; | |
1393 | struct bt_port *gsink_def_port; | |
634f394c PP |
1394 | struct bt_connection *conn = NULL; |
1395 | struct event event; | |
1396 | enum bt_graph_status status; | |
1397 | size_t src_accept_port_connection_pos; | |
1398 | size_t src_port_connected_pos; | |
1399 | ||
1400 | prepare_test(TEST_SRC_PORT_CONNECTED_ERROR, "port connected error: source"); | |
1401 | graph = create_graph(); | |
1402 | BT_ASSERT(graph); | |
1403 | src = create_src(graph); | |
1404 | sink = create_sink(graph); | |
834e9996 | 1405 | src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); |
634f394c | 1406 | BT_ASSERT(src_def_port); |
834e9996 | 1407 | sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); |
634f394c | 1408 | BT_ASSERT(sink_def_port); |
834e9996 PP |
1409 | status = bt_private_graph_connect_ports(graph, src_def_port, |
1410 | sink_def_port, &conn); | |
634f394c | 1411 | ok(status != BT_GRAPH_STATUS_OK, |
8d750b42 | 1412 | "bt_private_graph_connect_ports() returns an error"); |
834e9996 | 1413 | ok(!conn, "returned connection is still NULL"); |
bb61965b PP |
1414 | gsrc = bt_component_source_as_component(src); |
1415 | gsink = bt_component_sink_as_component(sink); | |
1416 | gsrc_def_port = bt_port_output_as_port(src_def_port); | |
1417 | gsink_def_port = bt_port_input_as_port(sink_def_port); | |
634f394c PP |
1418 | |
1419 | /* We're supposed to have 5 events */ | |
1420 | ok(events->len == 5, "we have the expected number of events"); | |
1421 | ||
1422 | /* Source's port added */ | |
834e9996 PP |
1423 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
1424 | event.data.graph_src_output_port_added.comp = gsrc; | |
1425 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
634f394c PP |
1426 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
1427 | ||
1428 | /* Sink's port added */ | |
834e9996 PP |
1429 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
1430 | event.data.graph_sink_input_port_added.comp = gsink; | |
1431 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
634f394c PP |
1432 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
1433 | ||
1434 | /* Source's accept port connection */ | |
834e9996 PP |
1435 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
1436 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
1437 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
1438 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
634f394c PP |
1439 | ok(has_event(&event), "got the expected source's accept port connection event"); |
1440 | src_accept_port_connection_pos = event_pos(&event); | |
1441 | ||
1442 | /* Sink's accept port connection */ | |
834e9996 PP |
1443 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
1444 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
1445 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
1446 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
634f394c PP |
1447 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
1448 | ||
1449 | /* Source's port connected */ | |
834e9996 PP |
1450 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
1451 | event.data.src_comp_output_port_connected.comp = gsrc; | |
1452 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
1453 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
634f394c PP |
1454 | ok(has_event(&event), "got the expected source's port connected event"); |
1455 | src_port_connected_pos = event_pos(&event); | |
1456 | ||
1457 | /* Order of events */ | |
1458 | ok(src_accept_port_connection_pos < src_port_connected_pos, | |
1459 | "event order is good (1)"); | |
1460 | ||
8138bfe1 PP |
1461 | bt_object_put_ref(graph); |
1462 | bt_object_put_ref(sink); | |
1463 | bt_object_put_ref(src); | |
1464 | bt_object_put_ref(conn); | |
634f394c PP |
1465 | } |
1466 | ||
1467 | static | |
1468 | void test_sink_port_connected_error(void) | |
1469 | { | |
834e9996 PP |
1470 | struct bt_component_source *src; |
1471 | struct bt_component_sink *sink; | |
1472 | struct bt_component *gsrc; | |
1473 | struct bt_component *gsink; | |
8d750b42 | 1474 | struct bt_private_graph *graph; |
834e9996 PP |
1475 | struct bt_port_output *src_def_port; |
1476 | struct bt_port_input *sink_def_port; | |
1477 | struct bt_port *gsrc_def_port; | |
1478 | struct bt_port *gsink_def_port; | |
634f394c PP |
1479 | struct bt_connection *conn = NULL; |
1480 | struct event event; | |
1481 | enum bt_graph_status status; | |
1482 | size_t src_accept_port_connection_pos; | |
1483 | size_t sink_accept_port_connection_pos; | |
1484 | size_t src_port_connected_pos; | |
1485 | size_t src_port_disconnected_pos; | |
1486 | size_t sink_port_connected_pos; | |
1487 | ||
1488 | prepare_test(TEST_SINK_PORT_CONNECTED_ERROR, "port connected error: sink"); | |
1489 | graph = create_graph(); | |
1490 | BT_ASSERT(graph); | |
1491 | src = create_src(graph); | |
1492 | sink = create_sink(graph); | |
834e9996 | 1493 | src_def_port = bt_component_source_borrow_output_port_by_name(src, "out"); |
634f394c | 1494 | BT_ASSERT(src_def_port); |
834e9996 | 1495 | sink_def_port = bt_component_sink_borrow_input_port_by_name(sink, "in"); |
634f394c | 1496 | BT_ASSERT(sink_def_port); |
834e9996 PP |
1497 | status = bt_private_graph_connect_ports(graph, src_def_port, |
1498 | sink_def_port, &conn); | |
634f394c | 1499 | ok(status != BT_GRAPH_STATUS_OK, |
8d750b42 | 1500 | "bt_private_graph_connect_ports() returns an error"); |
834e9996 | 1501 | ok(!conn, "returned connection is still NULL"); |
bb61965b PP |
1502 | gsrc = bt_component_source_as_component(src); |
1503 | gsink = bt_component_sink_as_component(sink); | |
1504 | gsrc_def_port = bt_port_output_as_port(src_def_port); | |
1505 | gsink_def_port = bt_port_input_as_port(sink_def_port); | |
634f394c PP |
1506 | |
1507 | /* We're supposed to have 5 events */ | |
1508 | ok(events->len == 7, "we have the expected number of events"); | |
1509 | ||
1510 | /* Source's port added */ | |
834e9996 PP |
1511 | event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; |
1512 | event.data.graph_src_output_port_added.comp = gsrc; | |
1513 | event.data.graph_src_output_port_added.port = gsrc_def_port; | |
634f394c PP |
1514 | ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); |
1515 | ||
1516 | /* Sink's port added */ | |
834e9996 PP |
1517 | event.type = GRAPH_SINK_INPUT_PORT_ADDED; |
1518 | event.data.graph_sink_input_port_added.comp = gsink; | |
1519 | event.data.graph_sink_input_port_added.port = gsink_def_port; | |
634f394c PP |
1520 | ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); |
1521 | ||
1522 | /* Source's accept port connection */ | |
834e9996 PP |
1523 | event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; |
1524 | event.data.src_comp_accept_output_port_connection.comp = gsrc; | |
1525 | event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; | |
1526 | event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; | |
634f394c PP |
1527 | ok(has_event(&event), "got the expected source's accept port connection event"); |
1528 | src_accept_port_connection_pos = event_pos(&event); | |
1529 | ||
1530 | /* Sink's accept port connection */ | |
834e9996 PP |
1531 | event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; |
1532 | event.data.sink_comp_accept_input_port_connection.comp = gsink; | |
1533 | event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; | |
1534 | event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; | |
634f394c PP |
1535 | ok(has_event(&event), "got the expected sink's accept port connection event"); |
1536 | sink_accept_port_connection_pos = event_pos(&event); | |
1537 | ||
1538 | /* Source's port connected */ | |
834e9996 PP |
1539 | event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; |
1540 | event.data.src_comp_output_port_connected.comp = gsrc; | |
1541 | event.data.src_comp_output_port_connected.self_port = gsrc_def_port; | |
1542 | event.data.src_comp_output_port_connected.other_port = gsink_def_port; | |
634f394c PP |
1543 | ok(has_event(&event), "got the expected source's port connected event"); |
1544 | src_port_connected_pos = event_pos(&event); | |
1545 | ||
1546 | /* Sink's port connected */ | |
834e9996 PP |
1547 | event.type = SINK_COMP_INPUT_PORT_CONNECTED; |
1548 | event.data.sink_comp_input_port_connected.comp = gsink; | |
1549 | event.data.sink_comp_input_port_connected.self_port = gsink_def_port; | |
1550 | event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; | |
634f394c PP |
1551 | ok(has_event(&event), "got the expected sink's port connected event"); |
1552 | sink_port_connected_pos = event_pos(&event); | |
1553 | ||
1554 | /* Source's port disconnected */ | |
834e9996 PP |
1555 | event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; |
1556 | event.data.src_comp_output_port_disconnected.comp = gsrc; | |
1557 | event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; | |
634f394c PP |
1558 | ok(has_event(&event), "got the expected source's port disconnected event"); |
1559 | src_port_disconnected_pos = event_pos(&event); | |
1560 | ||
1561 | /* Order of events */ | |
1562 | ok(src_accept_port_connection_pos < src_port_connected_pos, | |
1563 | "event order is good (1)"); | |
1564 | ok(sink_accept_port_connection_pos < sink_port_connected_pos, | |
1565 | "event order is good (2)"); | |
1566 | ok(sink_port_connected_pos < src_port_disconnected_pos, | |
1567 | "event order is good (3)"); | |
1568 | ||
834e9996 | 1569 | bt_object_put_ref(conn); |
8138bfe1 PP |
1570 | bt_object_put_ref(graph); |
1571 | bt_object_put_ref(sink); | |
1572 | bt_object_put_ref(src); | |
634f394c PP |
1573 | } |
1574 | ||
fb9935cc PP |
1575 | static |
1576 | void test_empty_graph(void) | |
1577 | { | |
8d750b42 | 1578 | struct bt_private_graph *graph; |
fb9935cc PP |
1579 | |
1580 | prepare_test(TEST_EMPTY_GRAPH, "empty graph"); | |
1581 | graph = create_graph(); | |
1582 | ok(events->len == 0, "empty graph generates no events"); | |
8138bfe1 | 1583 | bt_object_put_ref(graph); |
fb9935cc PP |
1584 | } |
1585 | ||
1586 | int main(int argc, char **argv) | |
1587 | { | |
1588 | plan_tests(NR_TESTS); | |
1589 | init_test(); | |
1590 | test_empty_graph(); | |
1591 | test_simple(); | |
634f394c PP |
1592 | test_src_port_connected_error(); |
1593 | test_sink_port_connected_error(); | |
c14181ff | 1594 | test_src_adds_port_in_port_connected(); |
834e9996 PP |
1595 | test_sink_removes_port_in_consume(); |
1596 | test_sink_removes_port_in_consume_then_src_removes_disconnected_port(); | |
fb9935cc PP |
1597 | fini_test(); |
1598 | return exit_status(); | |
1599 | } |