Commit | Line | Data |
---|---|---|
223c70b2 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> |
223c70b2 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-sink.h> | |
39 | #include <babeltrace/graph/component-source.h> | |
40 | #include <babeltrace/graph/component.h> | |
73d5c1ad | 41 | #include <babeltrace/graph/connection.h> |
223c70b2 PP |
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/notification-stream.h> | |
48 | #include <babeltrace/graph/port.h> | |
49 | #include <babeltrace/graph/private-component-source.h> | |
b9d103be | 50 | #include <babeltrace/graph/private-component-sink.h> |
223c70b2 PP |
51 | #include <babeltrace/graph/private-component.h> |
52 | #include <babeltrace/graph/private-connection.h> | |
53 | #include <babeltrace/graph/private-notification-iterator.h> | |
54 | #include <babeltrace/graph/private-port.h> | |
55 | #include <babeltrace/plugin/plugin.h> | |
56 | #include <babeltrace/ref.h> | |
57 | #include <glib.h> | |
58 | ||
59 | #include "tap/tap.h" | |
60 | ||
61 | #define NR_TESTS 24 | |
62 | ||
63 | enum test { | |
64 | TEST_NO_AUTO_NOTIFS, | |
65 | TEST_AUTO_STREAM_BEGIN_FROM_PACKET_BEGIN, | |
66 | TEST_AUTO_STREAM_BEGIN_FROM_STREAM_END, | |
67 | TEST_AUTO_STREAM_END_FROM_END, | |
68 | TEST_AUTO_PACKET_BEGIN_FROM_PACKET_END, | |
69 | TEST_AUTO_PACKET_BEGIN_FROM_EVENT, | |
70 | TEST_AUTO_PACKET_END_FROM_PACKET_BEGIN, | |
71 | TEST_AUTO_PACKET_END_PACKET_BEGIN_FROM_EVENT, | |
72 | TEST_AUTO_PACKET_END_FROM_STREAM_END, | |
73 | TEST_AUTO_PACKET_END_STREAM_END_FROM_END, | |
74 | TEST_MULTIPLE_AUTO_STREAM_END_FROM_END, | |
75 | TEST_MULTIPLE_AUTO_PACKET_END_STREAM_END_FROM_END, | |
76 | }; | |
77 | ||
78 | enum test_event_type { | |
79 | TEST_EV_TYPE_NOTIF_UNEXPECTED, | |
80 | TEST_EV_TYPE_NOTIF_EVENT, | |
81 | TEST_EV_TYPE_NOTIF_INACTIVITY, | |
82 | TEST_EV_TYPE_NOTIF_STREAM_BEGIN, | |
83 | TEST_EV_TYPE_NOTIF_PACKET_BEGIN, | |
84 | TEST_EV_TYPE_NOTIF_PACKET_END, | |
85 | TEST_EV_TYPE_NOTIF_STREAM_END, | |
86 | TEST_EV_TYPE_END, | |
87 | TEST_EV_TYPE_SENTINEL, | |
88 | }; | |
89 | ||
90 | struct test_event { | |
91 | enum test_event_type type; | |
92 | struct bt_ctf_stream *stream; | |
93 | struct bt_ctf_packet *packet; | |
94 | }; | |
95 | ||
96 | struct source_muxer_sink { | |
97 | struct bt_component *source; | |
98 | struct bt_component *sink; | |
99 | }; | |
100 | ||
101 | static bool debug = false; | |
102 | static enum test current_test; | |
103 | static GArray *test_events; | |
104 | static struct bt_clock_class_priority_map *src_empty_cc_prio_map; | |
105 | static struct bt_ctf_stream_class *src_stream_class; | |
106 | static struct bt_ctf_event_class *src_event_class; | |
107 | static struct bt_ctf_stream *src_stream1; | |
108 | static struct bt_ctf_stream *src_stream2; | |
109 | static struct bt_ctf_packet *src_stream1_packet1; | |
110 | static struct bt_ctf_packet *src_stream1_packet2; | |
111 | static struct bt_ctf_packet *src_stream2_packet1; | |
112 | static struct bt_ctf_packet *src_stream2_packet2; | |
113 | ||
114 | enum { | |
115 | SEQ_END = -1, | |
116 | SEQ_STREAM1_BEGIN = -2, | |
117 | SEQ_STREAM2_BEGIN = -3, | |
118 | SEQ_STREAM1_END = -4, | |
119 | SEQ_STREAM2_END = -5, | |
120 | SEQ_STREAM1_PACKET1_BEGIN = -6, | |
121 | SEQ_STREAM1_PACKET2_BEGIN = -7, | |
122 | SEQ_STREAM2_PACKET1_BEGIN = -8, | |
123 | SEQ_STREAM2_PACKET2_BEGIN = -9, | |
124 | SEQ_STREAM1_PACKET1_END = -10, | |
125 | SEQ_STREAM1_PACKET2_END = -11, | |
126 | SEQ_STREAM2_PACKET1_END = -12, | |
127 | SEQ_STREAM2_PACKET2_END = -13, | |
128 | SEQ_EVENT_STREAM1_PACKET1 = -14, | |
129 | SEQ_EVENT_STREAM1_PACKET2 = -15, | |
130 | SEQ_EVENT_STREAM2_PACKET1 = -16, | |
131 | SEQ_EVENT_STREAM2_PACKET2 = -17, | |
132 | SEQ_INACTIVITY = -18, | |
133 | }; | |
134 | ||
135 | struct src_iter_user_data { | |
136 | int64_t *seq; | |
137 | size_t at; | |
138 | }; | |
139 | ||
140 | struct sink_user_data { | |
141 | struct bt_notification_iterator *notif_iter; | |
142 | }; | |
143 | ||
144 | /* | |
145 | * No automatic notifications generated in this block. | |
146 | * Stream 2 notifications are more indented. | |
147 | */ | |
148 | static int64_t seq_no_auto_notifs[] = { | |
149 | SEQ_STREAM1_BEGIN, | |
150 | SEQ_STREAM1_PACKET1_BEGIN, | |
151 | SEQ_EVENT_STREAM1_PACKET1, | |
152 | SEQ_EVENT_STREAM1_PACKET1, | |
153 | SEQ_STREAM2_BEGIN, | |
154 | SEQ_EVENT_STREAM1_PACKET1, | |
155 | SEQ_STREAM2_PACKET2_BEGIN, | |
156 | SEQ_EVENT_STREAM2_PACKET2, | |
157 | SEQ_EVENT_STREAM1_PACKET1, | |
158 | SEQ_STREAM1_PACKET1_END, | |
159 | SEQ_STREAM2_PACKET2_END, | |
160 | SEQ_STREAM1_PACKET2_BEGIN, | |
161 | SEQ_EVENT_STREAM1_PACKET2, | |
162 | SEQ_STREAM2_END, | |
163 | SEQ_STREAM1_PACKET2_END, | |
164 | SEQ_STREAM1_END, | |
165 | SEQ_END, | |
166 | }; | |
167 | ||
168 | /* Automatic "stream begin" from "packet begin" */ | |
169 | static int64_t seq_auto_stream_begin_from_packet_begin[] = { | |
170 | /* Automatic "stream begin" here */ | |
171 | SEQ_STREAM1_PACKET1_BEGIN, | |
172 | SEQ_STREAM1_PACKET1_END, | |
173 | SEQ_STREAM1_END, | |
174 | SEQ_END, | |
175 | }; | |
176 | ||
177 | /* Automatic "stream begin" from "stream end" */ | |
178 | static int64_t seq_auto_stream_begin_from_stream_end[] = { | |
179 | /* Automatic "stream begin" here */ | |
180 | SEQ_STREAM1_END, | |
181 | SEQ_END, | |
182 | }; | |
183 | ||
184 | /* Automatic "stream end" from END */ | |
185 | static int64_t seq_auto_stream_end_from_end[] = { | |
186 | SEQ_STREAM1_BEGIN, | |
187 | /* Automatic "packet end" here */ | |
188 | SEQ_END, | |
189 | }; | |
190 | ||
191 | /* Automatic "packet begin" from "packet end" */ | |
192 | static int64_t seq_auto_packet_begin_from_packet_end[] = { | |
193 | SEQ_STREAM1_BEGIN, | |
194 | /* Automatic "packet begin" here */ | |
195 | SEQ_STREAM1_PACKET1_END, | |
196 | SEQ_STREAM1_END, | |
197 | SEQ_END, | |
198 | }; | |
199 | ||
200 | /* Automatic "packet begin" from event */ | |
201 | static int64_t seq_auto_packet_begin_from_event[] = { | |
202 | SEQ_STREAM1_BEGIN, | |
203 | /* Automatic "packet begin" here */ | |
204 | SEQ_EVENT_STREAM1_PACKET1, | |
205 | SEQ_STREAM1_PACKET1_END, | |
206 | SEQ_STREAM1_END, | |
207 | SEQ_END, | |
208 | }; | |
209 | ||
210 | /* Automatic "packet end" from "packet begin" */ | |
211 | static int64_t seq_auto_packet_end_from_packet_begin[] = { | |
212 | SEQ_STREAM1_BEGIN, | |
213 | SEQ_STREAM1_PACKET1_BEGIN, | |
214 | /* Automatic "packet end" here */ | |
215 | SEQ_STREAM1_PACKET2_BEGIN, | |
216 | SEQ_STREAM1_PACKET2_END, | |
217 | SEQ_STREAM1_END, | |
218 | SEQ_END, | |
219 | }; | |
220 | ||
221 | /* Automatic "packet end" and "packet begin" from event */ | |
222 | static int64_t seq_auto_packet_end_packet_begin_from_event[] = { | |
223 | SEQ_STREAM1_BEGIN, | |
224 | SEQ_STREAM1_PACKET1_BEGIN, | |
225 | /* Automatic "packet end" here */ | |
226 | /* Automatic "packet begin" here */ | |
227 | SEQ_EVENT_STREAM1_PACKET2, | |
228 | SEQ_STREAM1_PACKET2_END, | |
229 | SEQ_STREAM1_END, | |
230 | SEQ_END, | |
231 | }; | |
232 | ||
233 | /* Automatic "packet end" from "stream end" */ | |
234 | static int64_t seq_auto_packet_end_from_stream_end[] = { | |
235 | SEQ_STREAM1_BEGIN, | |
236 | SEQ_STREAM1_PACKET1_BEGIN, | |
237 | /* Automatic "packet end" here */ | |
238 | SEQ_STREAM1_END, | |
239 | SEQ_END, | |
240 | }; | |
241 | ||
242 | /* Automatic "packet end" and "stream end" from END */ | |
243 | static int64_t seq_auto_packet_end_stream_end_from_end[] = { | |
244 | SEQ_STREAM1_BEGIN, | |
245 | SEQ_STREAM1_PACKET1_BEGIN, | |
246 | /* Automatic "packet end" here */ | |
247 | /* Automatic "stream end" here */ | |
248 | SEQ_END, | |
249 | }; | |
250 | ||
251 | /* Multiple automatic "stream end" from END */ | |
252 | static int64_t seq_multiple_auto_stream_end_from_end[] = { | |
253 | SEQ_STREAM1_BEGIN, | |
254 | SEQ_STREAM2_BEGIN, | |
255 | /* Automatic "stream end" here */ | |
256 | /* Automatic "stream end" here */ | |
257 | SEQ_END, | |
258 | }; | |
259 | ||
260 | /* Multiple automatic "packet end" and "stream end" from END */ | |
261 | static int64_t seq_multiple_auto_packet_end_stream_end_from_end[] = { | |
262 | SEQ_STREAM1_BEGIN, | |
263 | SEQ_STREAM2_BEGIN, | |
264 | SEQ_STREAM1_PACKET1_BEGIN, | |
265 | SEQ_STREAM2_PACKET1_BEGIN, | |
266 | /* Automatic "packet end" here */ | |
267 | /* Automatic "stream end" here */ | |
268 | /* Automatic "packet end" here */ | |
269 | /* Automatic "stream end" here */ | |
270 | SEQ_END, | |
271 | }; | |
272 | ||
273 | static | |
274 | void clear_test_events(void) | |
275 | { | |
276 | g_array_set_size(test_events, 0); | |
277 | } | |
278 | ||
279 | static | |
280 | void print_test_event(FILE *fp, const struct test_event *event) | |
281 | { | |
282 | fprintf(fp, "{ type = "); | |
283 | ||
284 | switch (event->type) { | |
285 | case TEST_EV_TYPE_NOTIF_UNEXPECTED: | |
286 | fprintf(fp, "TEST_EV_TYPE_NOTIF_UNEXPECTED"); | |
287 | break; | |
288 | case TEST_EV_TYPE_NOTIF_EVENT: | |
289 | fprintf(fp, "TEST_EV_TYPE_NOTIF_EVENT"); | |
290 | break; | |
291 | case TEST_EV_TYPE_NOTIF_INACTIVITY: | |
292 | fprintf(fp, "TEST_EV_TYPE_NOTIF_INACTIVITY"); | |
293 | break; | |
294 | case TEST_EV_TYPE_NOTIF_STREAM_BEGIN: | |
295 | fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN"); | |
296 | break; | |
297 | case TEST_EV_TYPE_NOTIF_STREAM_END: | |
298 | fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_END"); | |
299 | break; | |
300 | case TEST_EV_TYPE_NOTIF_PACKET_BEGIN: | |
301 | fprintf(fp, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN"); | |
302 | break; | |
303 | case TEST_EV_TYPE_NOTIF_PACKET_END: | |
304 | fprintf(fp, "TEST_EV_TYPE_NOTIF_PACKET_END"); | |
305 | break; | |
306 | case TEST_EV_TYPE_END: | |
307 | fprintf(fp, "TEST_EV_TYPE_END"); | |
308 | break; | |
309 | case TEST_EV_TYPE_SENTINEL: | |
310 | fprintf(fp, "TEST_EV_TYPE_SENTINEL"); | |
311 | break; | |
312 | default: | |
313 | fprintf(fp, "(UNKNOWN)"); | |
314 | break; | |
315 | } | |
316 | ||
317 | fprintf(fp, ", stream = %p, packet = %p }", event->stream, | |
318 | event->packet); | |
319 | } | |
320 | ||
321 | static | |
322 | void append_test_event(struct test_event *event) | |
323 | { | |
324 | g_array_append_val(test_events, *event); | |
325 | } | |
326 | ||
327 | static | |
328 | bool compare_single_test_events(const struct test_event *ev_a, | |
329 | const struct test_event *ev_b) | |
330 | { | |
331 | if (debug) { | |
332 | fprintf(stderr, ":: Comparing test events: "); | |
333 | print_test_event(stderr, ev_a); | |
334 | fprintf(stderr, " vs. "); | |
335 | print_test_event(stderr, ev_b); | |
336 | fprintf(stderr, "\n"); | |
337 | } | |
338 | ||
339 | if (ev_a->type != ev_b->type) { | |
340 | return false; | |
341 | } | |
342 | ||
343 | switch (ev_a->type) { | |
344 | case TEST_EV_TYPE_END: | |
345 | case TEST_EV_TYPE_SENTINEL: | |
346 | break; | |
347 | default: | |
348 | if (ev_a->stream != ev_b->stream) { | |
349 | return false; | |
350 | } | |
351 | ||
352 | if (ev_a->packet != ev_b->packet) { | |
353 | return false; | |
354 | } | |
355 | break; | |
356 | } | |
357 | ||
358 | return true; | |
359 | } | |
360 | ||
361 | static | |
362 | bool compare_test_events(const struct test_event *expected_events) | |
363 | { | |
364 | const struct test_event *expected_event = expected_events; | |
365 | size_t i = 0; | |
366 | ||
367 | assert(expected_events); | |
368 | ||
369 | while (true) { | |
370 | const struct test_event *event; | |
371 | ||
372 | if (expected_event->type == TEST_EV_TYPE_SENTINEL) { | |
373 | break; | |
374 | } | |
375 | ||
376 | if (i >= test_events->len) { | |
377 | return false; | |
378 | } | |
379 | ||
380 | event = &g_array_index(test_events, struct test_event, i); | |
381 | ||
382 | if (!compare_single_test_events(event, expected_event)) { | |
383 | return false; | |
384 | } | |
385 | ||
386 | i++; | |
387 | expected_event++; | |
388 | } | |
389 | ||
390 | if (i != test_events->len) { | |
391 | return false; | |
392 | } | |
393 | ||
394 | return true; | |
395 | } | |
396 | ||
397 | static | |
398 | void init_static_data(void) | |
399 | { | |
400 | int ret; | |
401 | struct bt_ctf_trace *trace; | |
402 | struct bt_ctf_field_type *empty_struct_ft; | |
403 | ||
404 | /* Test events */ | |
405 | test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event)); | |
406 | assert(test_events); | |
407 | ||
408 | /* Metadata */ | |
409 | empty_struct_ft = bt_ctf_field_type_structure_create(); | |
410 | assert(empty_struct_ft); | |
411 | trace = bt_ctf_trace_create(); | |
412 | assert(trace); | |
223c70b2 PP |
413 | ret = bt_ctf_trace_set_packet_header_type(trace, empty_struct_ft); |
414 | assert(ret == 0); | |
415 | src_empty_cc_prio_map = bt_clock_class_priority_map_create(); | |
416 | assert(src_empty_cc_prio_map); | |
417 | src_stream_class = bt_ctf_stream_class_create("my-stream-class"); | |
418 | assert(src_stream_class); | |
419 | ret = bt_ctf_stream_class_set_packet_context_type(src_stream_class, | |
420 | empty_struct_ft); | |
421 | assert(ret == 0); | |
422 | ret = bt_ctf_stream_class_set_event_header_type(src_stream_class, | |
423 | empty_struct_ft); | |
424 | assert(ret == 0); | |
425 | ret = bt_ctf_stream_class_set_event_context_type(src_stream_class, | |
426 | empty_struct_ft); | |
427 | assert(ret == 0); | |
428 | src_event_class = bt_ctf_event_class_create("my-event-class"); | |
429 | ret = bt_ctf_event_class_set_context_type(src_event_class, | |
430 | empty_struct_ft); | |
431 | assert(ret == 0); | |
432 | ret = bt_ctf_event_class_set_context_type(src_event_class, | |
433 | empty_struct_ft); | |
434 | assert(ret == 0); | |
435 | ret = bt_ctf_stream_class_add_event_class(src_stream_class, | |
436 | src_event_class); | |
437 | assert(ret == 0); | |
438 | ret = bt_ctf_trace_add_stream_class(trace, src_stream_class); | |
439 | assert(ret == 0); | |
440 | src_stream1 = bt_ctf_stream_create(src_stream_class, "stream-1"); | |
441 | assert(src_stream1); | |
442 | src_stream2 = bt_ctf_stream_create(src_stream_class, "stream-2"); | |
443 | assert(src_stream2); | |
444 | src_stream1_packet1 = bt_ctf_packet_create(src_stream1); | |
445 | assert(src_stream1_packet1); | |
446 | src_stream1_packet2 = bt_ctf_packet_create(src_stream1); | |
447 | assert(src_stream1_packet2); | |
448 | src_stream2_packet1 = bt_ctf_packet_create(src_stream2); | |
449 | assert(src_stream2_packet1); | |
450 | src_stream2_packet2 = bt_ctf_packet_create(src_stream2); | |
451 | assert(src_stream2_packet2); | |
452 | ||
453 | if (debug) { | |
454 | fprintf(stderr, ":: stream 1: %p\n", src_stream1); | |
455 | fprintf(stderr, ":: stream 2: %p\n", src_stream2); | |
456 | fprintf(stderr, ":: stream 1, packet 1: %p\n", src_stream1_packet1); | |
457 | fprintf(stderr, ":: stream 1, packet 2: %p\n", src_stream1_packet2); | |
458 | fprintf(stderr, ":: stream 2, packet 1: %p\n", src_stream2_packet1); | |
459 | fprintf(stderr, ":: stream 2, packet 2: %p\n", src_stream2_packet2); | |
460 | } | |
461 | ||
462 | bt_put(trace); | |
463 | bt_put(empty_struct_ft); | |
464 | } | |
465 | ||
466 | static | |
467 | void fini_static_data(void) | |
468 | { | |
469 | /* Test events */ | |
470 | g_array_free(test_events, TRUE); | |
471 | ||
472 | /* Metadata */ | |
473 | bt_put(src_empty_cc_prio_map); | |
474 | bt_put(src_stream_class); | |
475 | bt_put(src_event_class); | |
476 | bt_put(src_stream1); | |
477 | bt_put(src_stream2); | |
478 | bt_put(src_stream1_packet1); | |
479 | bt_put(src_stream1_packet2); | |
480 | bt_put(src_stream2_packet1); | |
481 | bt_put(src_stream2_packet2); | |
482 | } | |
483 | ||
484 | static | |
485 | void src_iter_finalize( | |
486 | struct bt_private_notification_iterator *private_notification_iterator) | |
487 | { | |
488 | struct src_iter_user_data *user_data = | |
489 | bt_private_notification_iterator_get_user_data( | |
490 | private_notification_iterator); | |
491 | ||
492 | if (user_data) { | |
493 | g_free(user_data); | |
494 | } | |
495 | } | |
496 | ||
497 | static | |
498 | enum bt_notification_iterator_status src_iter_init( | |
499 | struct bt_private_notification_iterator *priv_notif_iter, | |
500 | struct bt_private_port *private_port) | |
501 | { | |
502 | struct src_iter_user_data *user_data = | |
503 | g_new0(struct src_iter_user_data, 1); | |
504 | int ret; | |
505 | ||
506 | assert(user_data); | |
507 | ret = bt_private_notification_iterator_set_user_data(priv_notif_iter, | |
508 | user_data); | |
509 | assert(ret == 0); | |
510 | ||
511 | switch (current_test) { | |
512 | case TEST_NO_AUTO_NOTIFS: | |
513 | user_data->seq = seq_no_auto_notifs; | |
514 | break; | |
515 | case TEST_AUTO_STREAM_BEGIN_FROM_PACKET_BEGIN: | |
516 | user_data->seq = seq_auto_stream_begin_from_packet_begin; | |
517 | break; | |
518 | case TEST_AUTO_STREAM_BEGIN_FROM_STREAM_END: | |
519 | user_data->seq = seq_auto_stream_begin_from_stream_end; | |
520 | break; | |
521 | case TEST_AUTO_STREAM_END_FROM_END: | |
522 | user_data->seq = seq_auto_stream_end_from_end; | |
523 | break; | |
524 | case TEST_AUTO_PACKET_BEGIN_FROM_PACKET_END: | |
525 | user_data->seq = seq_auto_packet_begin_from_packet_end; | |
526 | break; | |
527 | case TEST_AUTO_PACKET_BEGIN_FROM_EVENT: | |
528 | user_data->seq = seq_auto_packet_begin_from_event; | |
529 | break; | |
530 | case TEST_AUTO_PACKET_END_FROM_PACKET_BEGIN: | |
531 | user_data->seq = seq_auto_packet_end_from_packet_begin; | |
532 | break; | |
533 | case TEST_AUTO_PACKET_END_PACKET_BEGIN_FROM_EVENT: | |
534 | user_data->seq = seq_auto_packet_end_packet_begin_from_event; | |
535 | break; | |
536 | case TEST_AUTO_PACKET_END_FROM_STREAM_END: | |
537 | user_data->seq = seq_auto_packet_end_from_stream_end; | |
538 | break; | |
539 | case TEST_AUTO_PACKET_END_STREAM_END_FROM_END: | |
540 | user_data->seq = seq_auto_packet_end_stream_end_from_end; | |
541 | break; | |
542 | case TEST_MULTIPLE_AUTO_STREAM_END_FROM_END: | |
543 | user_data->seq = seq_multiple_auto_stream_end_from_end; | |
544 | break; | |
545 | case TEST_MULTIPLE_AUTO_PACKET_END_STREAM_END_FROM_END: | |
546 | user_data->seq = seq_multiple_auto_packet_end_stream_end_from_end; | |
547 | break; | |
548 | default: | |
0fbb9a9f | 549 | abort(); |
223c70b2 PP |
550 | } |
551 | ||
552 | return BT_NOTIFICATION_ITERATOR_STATUS_OK; | |
553 | } | |
554 | ||
555 | static | |
556 | struct bt_ctf_event *src_create_event(struct bt_ctf_packet *packet) | |
557 | { | |
558 | struct bt_ctf_event *event = bt_ctf_event_create(src_event_class); | |
559 | int ret; | |
560 | ||
561 | assert(event); | |
562 | ret = bt_ctf_event_set_packet(event, packet); | |
563 | assert(ret == 0); | |
564 | return event; | |
565 | } | |
566 | ||
567 | static | |
568 | struct bt_notification_iterator_next_return src_iter_next_seq( | |
569 | struct src_iter_user_data *user_data) | |
570 | { | |
571 | struct bt_notification_iterator_next_return next_return = { | |
572 | .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, | |
573 | }; | |
574 | int64_t cur_ts_ns; | |
575 | struct bt_ctf_packet *event_packet = NULL; | |
576 | ||
577 | assert(user_data->seq); | |
578 | cur_ts_ns = user_data->seq[user_data->at]; | |
579 | ||
580 | switch (cur_ts_ns) { | |
581 | case SEQ_END: | |
582 | next_return.status = | |
583 | BT_NOTIFICATION_ITERATOR_STATUS_END; | |
584 | break; | |
585 | case SEQ_INACTIVITY: | |
586 | next_return.notification = | |
587 | bt_notification_inactivity_create(src_empty_cc_prio_map); | |
588 | assert(next_return.notification); | |
589 | break; | |
590 | case SEQ_STREAM1_BEGIN: | |
591 | next_return.notification = | |
592 | bt_notification_stream_begin_create(src_stream1); | |
593 | assert(next_return.notification); | |
594 | break; | |
595 | case SEQ_STREAM2_BEGIN: | |
596 | next_return.notification = | |
597 | bt_notification_stream_begin_create(src_stream2); | |
598 | assert(next_return.notification); | |
599 | break; | |
600 | case SEQ_STREAM1_END: | |
601 | next_return.notification = | |
602 | bt_notification_stream_end_create(src_stream1); | |
603 | assert(next_return.notification); | |
604 | break; | |
605 | case SEQ_STREAM2_END: | |
606 | next_return.notification = | |
607 | bt_notification_stream_end_create(src_stream2); | |
608 | assert(next_return.notification); | |
609 | break; | |
610 | case SEQ_STREAM1_PACKET1_BEGIN: | |
611 | next_return.notification = | |
612 | bt_notification_packet_begin_create(src_stream1_packet1); | |
613 | assert(next_return.notification); | |
614 | break; | |
615 | case SEQ_STREAM1_PACKET2_BEGIN: | |
616 | next_return.notification = | |
617 | bt_notification_packet_begin_create(src_stream1_packet2); | |
618 | assert(next_return.notification); | |
619 | break; | |
620 | case SEQ_STREAM2_PACKET1_BEGIN: | |
621 | next_return.notification = | |
622 | bt_notification_packet_begin_create(src_stream2_packet1); | |
623 | assert(next_return.notification); | |
624 | break; | |
625 | case SEQ_STREAM2_PACKET2_BEGIN: | |
626 | next_return.notification = | |
627 | bt_notification_packet_begin_create(src_stream2_packet2); | |
628 | assert(next_return.notification); | |
629 | break; | |
630 | case SEQ_STREAM1_PACKET1_END: | |
631 | next_return.notification = | |
632 | bt_notification_packet_end_create(src_stream1_packet1); | |
633 | assert(next_return.notification); | |
634 | break; | |
635 | case SEQ_STREAM1_PACKET2_END: | |
636 | next_return.notification = | |
637 | bt_notification_packet_end_create(src_stream1_packet2); | |
638 | assert(next_return.notification); | |
639 | break; | |
640 | case SEQ_STREAM2_PACKET1_END: | |
641 | next_return.notification = | |
642 | bt_notification_packet_end_create(src_stream2_packet1); | |
643 | assert(next_return.notification); | |
644 | break; | |
645 | case SEQ_STREAM2_PACKET2_END: | |
646 | next_return.notification = | |
647 | bt_notification_packet_end_create(src_stream2_packet2); | |
648 | assert(next_return.notification); | |
649 | break; | |
650 | case SEQ_EVENT_STREAM1_PACKET1: | |
651 | event_packet = src_stream1_packet1; | |
652 | break; | |
653 | case SEQ_EVENT_STREAM1_PACKET2: | |
654 | event_packet = src_stream1_packet2; | |
655 | break; | |
656 | case SEQ_EVENT_STREAM2_PACKET1: | |
657 | event_packet = src_stream2_packet1; | |
658 | break; | |
659 | case SEQ_EVENT_STREAM2_PACKET2: | |
660 | event_packet = src_stream2_packet2; | |
661 | break; | |
662 | default: | |
0fbb9a9f | 663 | abort(); |
223c70b2 PP |
664 | } |
665 | ||
666 | if (event_packet) { | |
667 | struct bt_ctf_event *event = src_create_event(event_packet); | |
668 | ||
669 | assert(event); | |
670 | next_return.notification = bt_notification_event_create(event, | |
671 | src_empty_cc_prio_map); | |
672 | bt_put(event); | |
673 | assert(next_return.notification); | |
674 | } | |
675 | ||
676 | if (next_return.status != BT_NOTIFICATION_ITERATOR_STATUS_END) { | |
677 | user_data->at++; | |
678 | } | |
679 | ||
680 | return next_return; | |
681 | } | |
682 | ||
683 | static | |
684 | struct bt_notification_iterator_next_return src_iter_next( | |
685 | struct bt_private_notification_iterator *priv_iterator) | |
686 | { | |
687 | struct bt_notification_iterator_next_return next_return = { | |
688 | .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, | |
689 | .notification = NULL, | |
690 | }; | |
691 | struct src_iter_user_data *user_data = | |
692 | bt_private_notification_iterator_get_user_data(priv_iterator); | |
693 | ||
694 | assert(user_data); | |
695 | next_return = src_iter_next_seq(user_data); | |
696 | return next_return; | |
697 | } | |
698 | ||
699 | static | |
700 | enum bt_component_status src_init( | |
701 | struct bt_private_component *private_component, | |
702 | struct bt_value *params, void *init_method_data) | |
703 | { | |
147337a3 | 704 | int ret; |
b9d103be | 705 | |
147337a3 PP |
706 | ret = bt_private_component_source_add_output_private_port( |
707 | private_component, "out", NULL, NULL); | |
708 | assert(ret == 0); | |
223c70b2 PP |
709 | return BT_COMPONENT_STATUS_OK; |
710 | } | |
711 | ||
712 | static | |
713 | void src_finalize(struct bt_private_component *private_component) | |
714 | { | |
715 | } | |
716 | ||
717 | static | |
718 | enum bt_component_status sink_consume( | |
719 | struct bt_private_component *priv_component) | |
720 | { | |
721 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
722 | struct bt_notification *notification = NULL; | |
723 | struct sink_user_data *user_data = | |
724 | bt_private_component_get_user_data(priv_component); | |
725 | enum bt_notification_iterator_status it_ret; | |
726 | struct test_event test_event = { 0 }; | |
727 | bool do_append_test_event = true; | |
728 | ||
729 | assert(user_data && user_data->notif_iter); | |
730 | it_ret = bt_notification_iterator_next(user_data->notif_iter); | |
731 | ||
732 | if (it_ret < 0) { | |
733 | ret = BT_COMPONENT_STATUS_ERROR; | |
734 | do_append_test_event = false; | |
735 | goto end; | |
736 | } | |
737 | ||
738 | switch (it_ret) { | |
739 | case BT_NOTIFICATION_ITERATOR_STATUS_END: | |
740 | test_event.type = TEST_EV_TYPE_END; | |
741 | ret = BT_COMPONENT_STATUS_END; | |
742 | BT_PUT(user_data->notif_iter); | |
743 | goto end; | |
744 | case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: | |
0fbb9a9f | 745 | abort(); |
223c70b2 PP |
746 | default: |
747 | break; | |
748 | } | |
749 | ||
750 | notification = bt_notification_iterator_get_notification( | |
751 | user_data->notif_iter); | |
752 | assert(notification); | |
753 | ||
754 | switch (bt_notification_get_type(notification)) { | |
755 | case BT_NOTIFICATION_TYPE_EVENT: | |
756 | { | |
757 | struct bt_ctf_event *event; | |
758 | ||
759 | test_event.type = TEST_EV_TYPE_NOTIF_EVENT; | |
760 | event = bt_notification_event_get_event(notification); | |
761 | assert(event); | |
762 | test_event.packet = bt_ctf_event_get_packet(event); | |
763 | bt_put(event); | |
764 | assert(test_event.packet); | |
765 | bt_put(test_event.packet); | |
766 | break; | |
767 | } | |
768 | case BT_NOTIFICATION_TYPE_INACTIVITY: | |
769 | test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY; | |
770 | break; | |
771 | case BT_NOTIFICATION_TYPE_STREAM_BEGIN: | |
772 | test_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
773 | test_event.stream = | |
774 | bt_notification_stream_begin_get_stream(notification); | |
775 | assert(test_event.stream); | |
776 | bt_put(test_event.stream); | |
777 | break; | |
778 | case BT_NOTIFICATION_TYPE_STREAM_END: | |
779 | test_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
780 | test_event.stream = | |
781 | bt_notification_stream_end_get_stream(notification); | |
782 | assert(test_event.stream); | |
783 | bt_put(test_event.stream); | |
784 | break; | |
785 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
786 | test_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; | |
787 | test_event.packet = | |
788 | bt_notification_packet_begin_get_packet(notification); | |
789 | assert(test_event.packet); | |
790 | bt_put(test_event.packet); | |
791 | break; | |
792 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
793 | test_event.type = TEST_EV_TYPE_NOTIF_PACKET_END; | |
794 | test_event.packet = | |
795 | bt_notification_packet_end_get_packet(notification); | |
796 | assert(test_event.packet); | |
797 | bt_put(test_event.packet); | |
798 | break; | |
799 | default: | |
800 | test_event.type = TEST_EV_TYPE_NOTIF_UNEXPECTED; | |
801 | break; | |
802 | } | |
803 | ||
804 | if (test_event.packet) { | |
805 | test_event.stream = bt_ctf_packet_get_stream(test_event.packet); | |
806 | assert(test_event.stream); | |
807 | bt_put(test_event.stream); | |
808 | } | |
809 | ||
810 | end: | |
811 | if (do_append_test_event) { | |
812 | append_test_event(&test_event); | |
813 | } | |
814 | ||
815 | bt_put(notification); | |
816 | return ret; | |
817 | } | |
818 | ||
819 | static | |
820 | void sink_port_connected(struct bt_private_component *private_component, | |
821 | struct bt_private_port *self_private_port, | |
822 | struct bt_port *other_port) | |
823 | { | |
824 | struct bt_private_connection *priv_conn = | |
825 | bt_private_port_get_private_connection(self_private_port); | |
826 | struct sink_user_data *user_data = bt_private_component_get_user_data( | |
827 | private_component); | |
73d5c1ad | 828 | enum bt_connection_status conn_status; |
223c70b2 PP |
829 | |
830 | assert(user_data); | |
831 | assert(priv_conn); | |
73d5c1ad PP |
832 | conn_status = bt_private_connection_create_notification_iterator( |
833 | priv_conn, NULL, &user_data->notif_iter); | |
834 | assert(conn_status == 0); | |
223c70b2 PP |
835 | bt_put(priv_conn); |
836 | } | |
837 | ||
838 | static | |
839 | enum bt_component_status sink_init( | |
840 | struct bt_private_component *private_component, | |
841 | struct bt_value *params, void *init_method_data) | |
842 | { | |
843 | struct sink_user_data *user_data = g_new0(struct sink_user_data, 1); | |
844 | int ret; | |
845 | ||
846 | assert(user_data); | |
847 | ret = bt_private_component_set_user_data(private_component, | |
848 | user_data); | |
849 | assert(ret == 0); | |
147337a3 PP |
850 | ret = bt_private_component_sink_add_input_private_port( |
851 | private_component, "in", NULL, NULL); | |
852 | assert(ret == 0); | |
223c70b2 PP |
853 | return BT_COMPONENT_STATUS_OK; |
854 | } | |
855 | ||
856 | static | |
857 | void sink_finalize(struct bt_private_component *private_component) | |
858 | { | |
859 | struct sink_user_data *user_data = bt_private_component_get_user_data( | |
860 | private_component); | |
861 | ||
862 | if (user_data) { | |
863 | bt_put(user_data->notif_iter); | |
864 | g_free(user_data); | |
865 | } | |
866 | } | |
867 | ||
868 | static | |
869 | void create_source_sink(struct bt_component **source, | |
870 | struct bt_component **sink) | |
871 | { | |
872 | struct bt_component_class *src_comp_class; | |
873 | struct bt_component_class *sink_comp_class; | |
874 | int ret; | |
875 | ||
876 | /* Create source component */ | |
877 | src_comp_class = bt_component_class_source_create("src", src_iter_next); | |
878 | assert(src_comp_class); | |
879 | ret = bt_component_class_set_init_method(src_comp_class, src_init); | |
880 | assert(ret == 0); | |
881 | ret = bt_component_class_set_finalize_method(src_comp_class, | |
882 | src_finalize); | |
883 | assert(ret == 0); | |
884 | ret = bt_component_class_source_set_notification_iterator_init_method( | |
885 | src_comp_class, src_iter_init); | |
886 | assert(ret == 0); | |
887 | ret = bt_component_class_source_set_notification_iterator_finalize_method( | |
888 | src_comp_class, src_iter_finalize); | |
889 | assert(ret == 0); | |
890 | *source = bt_component_create(src_comp_class, "source", NULL); | |
891 | assert(*source); | |
892 | ||
893 | /* Create sink component */ | |
894 | sink_comp_class = bt_component_class_sink_create("sink", sink_consume); | |
895 | assert(sink_comp_class); | |
896 | ret = bt_component_class_set_init_method(sink_comp_class, sink_init); | |
897 | assert(ret == 0); | |
898 | ret = bt_component_class_set_finalize_method(sink_comp_class, | |
899 | sink_finalize); | |
900 | ret = bt_component_class_set_port_connected_method(sink_comp_class, | |
901 | sink_port_connected); | |
902 | assert(ret == 0); | |
903 | *sink = bt_component_create(sink_comp_class, "sink", NULL); | |
904 | ||
905 | bt_put(src_comp_class); | |
906 | bt_put(sink_comp_class); | |
907 | } | |
908 | ||
909 | static | |
910 | void do_std_test(enum test test, const char *name, | |
911 | const struct test_event *expected_test_events) | |
912 | { | |
913 | struct bt_component *src_comp; | |
914 | struct bt_component *sink_comp; | |
915 | struct bt_port *upstream_port; | |
916 | struct bt_port *downstream_port; | |
917 | struct bt_graph *graph; | |
223c70b2 PP |
918 | enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; |
919 | ||
920 | clear_test_events(); | |
921 | current_test = test; | |
922 | diag("test: %s", name); | |
923 | create_source_sink(&src_comp, &sink_comp); | |
924 | graph = bt_graph_create(); | |
925 | assert(graph); | |
926 | ||
927 | /* Connect source to sink */ | |
b9d103be | 928 | upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out"); |
223c70b2 | 929 | assert(upstream_port); |
b9d103be | 930 | downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in"); |
223c70b2 | 931 | assert(downstream_port); |
a256a42d PP |
932 | graph_status = bt_graph_connect_ports(graph, upstream_port, |
933 | downstream_port, NULL); | |
223c70b2 PP |
934 | bt_put(upstream_port); |
935 | bt_put(downstream_port); | |
936 | ||
937 | /* Run the graph until the end */ | |
938 | while (graph_status == BT_GRAPH_STATUS_OK || | |
939 | graph_status == BT_GRAPH_STATUS_AGAIN) { | |
940 | graph_status = bt_graph_run(graph); | |
941 | } | |
942 | ||
943 | ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error"); | |
944 | ||
945 | /* Compare the resulting test events */ | |
946 | if (expected_test_events) { | |
947 | ok(compare_test_events(expected_test_events), | |
948 | "the produced sequence of test events is the expected one"); | |
949 | } | |
950 | ||
951 | bt_put(src_comp); | |
952 | bt_put(sink_comp); | |
953 | bt_put(graph); | |
954 | } | |
955 | ||
956 | static | |
957 | void test_no_auto_notifs(void) | |
958 | { | |
959 | const struct test_event expected_test_events[] = { | |
960 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
961 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
962 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
963 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
964 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, }, | |
965 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
966 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, }, | |
967 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, }, | |
968 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
969 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
970 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, }, | |
971 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
972 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
973 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream2, .packet = NULL, }, | |
974 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
975 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
976 | { .type = TEST_EV_TYPE_END, }, | |
977 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
978 | }; | |
979 | ||
980 | do_std_test(TEST_NO_AUTO_NOTIFS, "no automatic notifications", | |
981 | expected_test_events); | |
982 | } | |
983 | ||
984 | static | |
985 | void test_auto_stream_begin_from_packet_begin(void) | |
986 | { | |
987 | const struct test_event expected_test_events[] = { | |
988 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
989 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
990 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
991 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
992 | { .type = TEST_EV_TYPE_END, }, | |
993 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
994 | }; | |
995 | ||
996 | do_std_test(TEST_AUTO_STREAM_BEGIN_FROM_PACKET_BEGIN, | |
997 | "automatic \"stream begin\" notif. caused by \"packet begin\" notif.", | |
998 | expected_test_events); | |
999 | } | |
1000 | ||
1001 | static | |
1002 | void test_auto_stream_begin_from_stream_end(void) | |
1003 | { | |
1004 | const struct test_event expected_test_events[] = { | |
1005 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1006 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1007 | { .type = TEST_EV_TYPE_END, }, | |
1008 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1009 | }; | |
1010 | ||
1011 | do_std_test(TEST_AUTO_STREAM_BEGIN_FROM_STREAM_END, | |
1012 | "automatic \"stream begin\" notif. caused by \"stream end\" notif.", | |
1013 | expected_test_events); | |
1014 | } | |
1015 | ||
1016 | static | |
1017 | void test_auto_stream_end_from_end(void) | |
1018 | { | |
1019 | const struct test_event expected_test_events[] = { | |
1020 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1021 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1022 | { .type = TEST_EV_TYPE_END, }, | |
1023 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1024 | }; | |
1025 | ||
1026 | do_std_test(TEST_AUTO_STREAM_END_FROM_END, | |
1027 | "automatic \"stream end\" notif. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1028 | expected_test_events); | |
1029 | } | |
1030 | ||
1031 | static | |
1032 | void test_auto_packet_begin_from_packet_end(void) | |
1033 | { | |
1034 | const struct test_event expected_test_events[] = { | |
1035 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1036 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1037 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1038 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1039 | { .type = TEST_EV_TYPE_END, }, | |
1040 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1041 | }; | |
1042 | ||
1043 | do_std_test(TEST_AUTO_PACKET_BEGIN_FROM_PACKET_END, | |
1044 | "automatic \"packet begin\" notif. caused by \"packet end\" notif.", | |
1045 | expected_test_events); | |
1046 | } | |
1047 | ||
1048 | static | |
1049 | void test_auto_packet_begin_from_event(void) | |
1050 | { | |
1051 | const struct test_event expected_test_events[] = { | |
1052 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1053 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1054 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1055 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1056 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1057 | { .type = TEST_EV_TYPE_END, }, | |
1058 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1059 | }; | |
1060 | ||
1061 | do_std_test(TEST_AUTO_PACKET_BEGIN_FROM_EVENT, | |
1062 | "automatic \"packet begin\" notif. caused by event notif.", | |
1063 | expected_test_events); | |
1064 | } | |
1065 | ||
1066 | static | |
1067 | void test_auto_packet_end_from_packet_begin(void) | |
1068 | { | |
1069 | const struct test_event expected_test_events[] = { | |
1070 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1071 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1072 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1073 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1074 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1075 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1076 | { .type = TEST_EV_TYPE_END, }, | |
1077 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1078 | }; | |
1079 | ||
1080 | do_std_test(TEST_AUTO_PACKET_END_FROM_PACKET_BEGIN, | |
1081 | "automatic \"packet end\" notif. caused by \"packet begin\" notif.", | |
1082 | expected_test_events); | |
1083 | } | |
1084 | ||
1085 | static | |
1086 | void test_auto_packet_end_packet_begin_from_event(void) | |
1087 | { | |
1088 | const struct test_event expected_test_events[] = { | |
1089 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1090 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1091 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1092 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1093 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1094 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1095 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1096 | { .type = TEST_EV_TYPE_END, }, | |
1097 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1098 | }; | |
1099 | ||
1100 | do_std_test(TEST_AUTO_PACKET_END_PACKET_BEGIN_FROM_EVENT, | |
1101 | "automatic \"packet end\" and \"packet begin\" notifs. caused by event notif.", | |
1102 | expected_test_events); | |
1103 | } | |
1104 | ||
1105 | static | |
1106 | void test_auto_packet_end_from_stream_end(void) | |
1107 | { | |
1108 | const struct test_event expected_test_events[] = { | |
1109 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1110 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1111 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1112 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1113 | { .type = TEST_EV_TYPE_END, }, | |
1114 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1115 | }; | |
1116 | ||
1117 | do_std_test(TEST_AUTO_PACKET_END_FROM_STREAM_END, | |
1118 | "automatic \"packet end\" notif. caused by \"stream end\" notif.", | |
1119 | expected_test_events); | |
1120 | } | |
1121 | ||
1122 | static | |
1123 | void test_auto_packet_end_stream_end_from_end(void) | |
1124 | { | |
1125 | const struct test_event expected_test_events[] = { | |
1126 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1127 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1128 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1129 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1130 | { .type = TEST_EV_TYPE_END, }, | |
1131 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1132 | }; | |
1133 | ||
1134 | do_std_test(TEST_AUTO_PACKET_END_STREAM_END_FROM_END, | |
1135 | "automatic \"packet end\" and \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1136 | expected_test_events); | |
1137 | } | |
1138 | ||
1139 | static | |
1140 | void test_multiple_auto_stream_end_from_end(void) | |
1141 | { | |
1142 | bool expected = true; | |
1143 | struct test_event expected_event; | |
1144 | struct test_event expected_event2; | |
1145 | struct test_event *event; | |
1146 | struct test_event *event2; | |
1147 | ||
1148 | do_std_test(TEST_MULTIPLE_AUTO_STREAM_END_FROM_END, | |
1149 | "multiple automatic \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1150 | NULL); | |
1151 | ||
1152 | if (test_events->len != 5) { | |
1153 | expected = false; | |
1154 | goto end; | |
1155 | } | |
1156 | ||
1157 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1158 | expected_event.stream = src_stream1; | |
1159 | expected_event.packet = NULL; | |
1160 | event = &g_array_index(test_events, struct test_event, 0); | |
1161 | if (!compare_single_test_events(event, &expected_event)) { | |
1162 | expected = false; | |
1163 | goto end; | |
1164 | } | |
1165 | ||
1166 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1167 | expected_event.stream = src_stream2; | |
1168 | expected_event.packet = NULL; | |
1169 | event = &g_array_index(test_events, struct test_event, 1); | |
1170 | if (!compare_single_test_events(event, &expected_event)) { | |
1171 | expected = false; | |
1172 | goto end; | |
1173 | } | |
1174 | ||
1175 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1176 | expected_event.stream = src_stream1; | |
1177 | expected_event.packet = NULL; | |
1178 | expected_event2.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1179 | expected_event2.stream = src_stream2; | |
1180 | expected_event2.packet = NULL; | |
1181 | event = &g_array_index(test_events, struct test_event, 2); | |
1182 | event2 = &g_array_index(test_events, struct test_event, 3); | |
1183 | if (!(compare_single_test_events(event, &expected_event) && | |
1184 | compare_single_test_events(event2, &expected_event2)) && | |
1185 | !(compare_single_test_events(event2, &expected_event) && | |
1186 | compare_single_test_events(event, &expected_event2))) { | |
1187 | expected = false; | |
1188 | goto end; | |
1189 | } | |
1190 | ||
1191 | expected_event.type = TEST_EV_TYPE_END; | |
1192 | expected_event.stream = NULL; | |
1193 | expected_event.packet = NULL; | |
1194 | event = &g_array_index(test_events, struct test_event, 4); | |
1195 | if (!compare_single_test_events(event, &expected_event)) { | |
1196 | expected = false; | |
1197 | goto end; | |
1198 | } | |
1199 | ||
1200 | end: | |
1201 | ok(expected, | |
1202 | "the produced sequence of test events is the expected one"); | |
1203 | } | |
1204 | ||
1205 | static | |
1206 | void test_multiple_auto_packet_end_stream_end_from_end(void) | |
1207 | { | |
1208 | bool expected = true; | |
1209 | struct test_event expected_event; | |
1210 | struct test_event expected_event2; | |
1211 | struct test_event *event; | |
1212 | struct test_event *event2; | |
1213 | ||
1214 | do_std_test(TEST_MULTIPLE_AUTO_PACKET_END_STREAM_END_FROM_END, | |
1215 | "multiple automatic \"packet end\" and \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1216 | NULL); | |
1217 | ||
1218 | if (test_events->len != 9) { | |
1219 | expected = false; | |
1220 | goto end; | |
1221 | } | |
1222 | ||
1223 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1224 | expected_event.stream = src_stream1; | |
1225 | expected_event.packet = NULL; | |
1226 | event = &g_array_index(test_events, struct test_event, 0); | |
1227 | if (!compare_single_test_events(event, &expected_event)) { | |
1228 | expected = false; | |
1229 | goto end; | |
1230 | } | |
1231 | ||
1232 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1233 | expected_event.stream = src_stream2; | |
1234 | expected_event.packet = NULL; | |
1235 | event = &g_array_index(test_events, struct test_event, 1); | |
1236 | if (!compare_single_test_events(event, &expected_event)) { | |
1237 | expected = false; | |
1238 | goto end; | |
1239 | } | |
1240 | ||
1241 | expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; | |
1242 | expected_event.stream = src_stream1; | |
1243 | expected_event.packet = src_stream1_packet1; | |
1244 | event = &g_array_index(test_events, struct test_event, 2); | |
1245 | if (!compare_single_test_events(event, &expected_event)) { | |
1246 | expected = false; | |
1247 | goto end; | |
1248 | } | |
1249 | ||
1250 | expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; | |
1251 | expected_event.stream = src_stream2; | |
1252 | expected_event.packet = src_stream2_packet1; | |
1253 | event = &g_array_index(test_events, struct test_event, 3); | |
1254 | if (!compare_single_test_events(event, &expected_event)) { | |
1255 | expected = false; | |
1256 | goto end; | |
1257 | } | |
1258 | ||
1259 | expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_END; | |
1260 | expected_event.stream = src_stream1; | |
1261 | expected_event.packet = src_stream1_packet1; | |
1262 | expected_event2.type = TEST_EV_TYPE_NOTIF_PACKET_END; | |
1263 | expected_event2.stream = src_stream2; | |
1264 | expected_event2.packet = src_stream2_packet1; | |
1265 | event = &g_array_index(test_events, struct test_event, 4); | |
1266 | event2 = &g_array_index(test_events, struct test_event, 6); | |
1267 | if (!(compare_single_test_events(event, &expected_event) && | |
1268 | compare_single_test_events(event2, &expected_event2)) && | |
1269 | !(compare_single_test_events(event2, &expected_event) && | |
1270 | compare_single_test_events(event, &expected_event2))) { | |
1271 | expected = false; | |
1272 | goto end; | |
1273 | } | |
1274 | ||
1275 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1276 | expected_event.stream = src_stream1; | |
1277 | expected_event.packet = NULL; | |
1278 | expected_event2.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1279 | expected_event2.stream = src_stream2; | |
1280 | expected_event2.packet = NULL; | |
1281 | event = &g_array_index(test_events, struct test_event, 5); | |
1282 | event2 = &g_array_index(test_events, struct test_event, 7); | |
1283 | if (!(compare_single_test_events(event, &expected_event) && | |
1284 | compare_single_test_events(event2, &expected_event2)) && | |
1285 | !(compare_single_test_events(event2, &expected_event) && | |
1286 | compare_single_test_events(event, &expected_event2))) { | |
1287 | expected = false; | |
1288 | goto end; | |
1289 | } | |
1290 | ||
1291 | expected_event.type = TEST_EV_TYPE_END; | |
1292 | expected_event.stream = NULL; | |
1293 | expected_event.packet = NULL; | |
1294 | event = &g_array_index(test_events, struct test_event, 8); | |
1295 | if (!compare_single_test_events(event, &expected_event)) { | |
1296 | expected = false; | |
1297 | goto end; | |
1298 | } | |
1299 | ||
1300 | end: | |
1301 | ok(expected, | |
1302 | "the produced sequence of test events is the expected one"); | |
1303 | } | |
1304 | ||
1305 | #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG" | |
1306 | ||
1307 | int main(int argc, char **argv) | |
1308 | { | |
1309 | if (getenv(DEBUG_ENV_VAR) && strcmp(getenv(DEBUG_ENV_VAR), "1") == 0) { | |
1310 | debug = true; | |
1311 | } | |
1312 | ||
1313 | plan_tests(NR_TESTS); | |
1314 | init_static_data(); | |
1315 | test_no_auto_notifs(); | |
1316 | test_auto_stream_begin_from_packet_begin(); | |
1317 | test_auto_stream_begin_from_stream_end(); | |
1318 | test_auto_stream_end_from_end(); | |
1319 | test_auto_packet_begin_from_packet_end(); | |
1320 | test_auto_packet_begin_from_event(); | |
1321 | test_auto_packet_end_from_packet_begin(); | |
1322 | test_auto_packet_end_packet_begin_from_event(); | |
1323 | test_auto_packet_end_from_stream_end(); | |
1324 | test_auto_packet_end_stream_end_from_end(); | |
1325 | test_multiple_auto_stream_end_from_end(); | |
1326 | test_multiple_auto_packet_end_stream_end_from_end(); | |
1327 | fini_static_data(); | |
1328 | return exit_status(); | |
1329 | } |