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> | |
21 | #include <inttypes.h> | |
22 | #include <string.h> | |
23 | #include <assert.h> | |
24 | #include <babeltrace/ctf-ir/event-class.h> | |
25 | #include <babeltrace/ctf-ir/event.h> | |
26 | #include <babeltrace/ctf-ir/field-types.h> | |
27 | #include <babeltrace/ctf-ir/fields.h> | |
28 | #include <babeltrace/ctf-ir/packet.h> | |
29 | #include <babeltrace/ctf-ir/stream-class.h> | |
30 | #include <babeltrace/ctf-ir/stream.h> | |
31 | #include <babeltrace/ctf-ir/trace.h> | |
32 | #include <babeltrace/graph/clock-class-priority-map.h> | |
33 | #include <babeltrace/graph/component-class-filter.h> | |
34 | #include <babeltrace/graph/component-class-sink.h> | |
35 | #include <babeltrace/graph/component-class-source.h> | |
36 | #include <babeltrace/graph/component-class.h> | |
37 | #include <babeltrace/graph/component-sink.h> | |
38 | #include <babeltrace/graph/component-source.h> | |
39 | #include <babeltrace/graph/component.h> | |
40 | #include <babeltrace/graph/graph.h> | |
41 | #include <babeltrace/graph/notification-event.h> | |
42 | #include <babeltrace/graph/notification-inactivity.h> | |
43 | #include <babeltrace/graph/notification-iterator.h> | |
44 | #include <babeltrace/graph/notification-packet.h> | |
45 | #include <babeltrace/graph/notification-stream.h> | |
46 | #include <babeltrace/graph/port.h> | |
47 | #include <babeltrace/graph/private-component-source.h> | |
48 | #include <babeltrace/graph/private-component.h> | |
49 | #include <babeltrace/graph/private-connection.h> | |
50 | #include <babeltrace/graph/private-notification-iterator.h> | |
51 | #include <babeltrace/graph/private-port.h> | |
52 | #include <babeltrace/plugin/plugin.h> | |
53 | #include <babeltrace/ref.h> | |
54 | #include <glib.h> | |
55 | ||
56 | #include "tap/tap.h" | |
57 | ||
58 | #define NR_TESTS 24 | |
59 | ||
60 | enum test { | |
61 | TEST_NO_AUTO_NOTIFS, | |
62 | TEST_AUTO_STREAM_BEGIN_FROM_PACKET_BEGIN, | |
63 | TEST_AUTO_STREAM_BEGIN_FROM_STREAM_END, | |
64 | TEST_AUTO_STREAM_END_FROM_END, | |
65 | TEST_AUTO_PACKET_BEGIN_FROM_PACKET_END, | |
66 | TEST_AUTO_PACKET_BEGIN_FROM_EVENT, | |
67 | TEST_AUTO_PACKET_END_FROM_PACKET_BEGIN, | |
68 | TEST_AUTO_PACKET_END_PACKET_BEGIN_FROM_EVENT, | |
69 | TEST_AUTO_PACKET_END_FROM_STREAM_END, | |
70 | TEST_AUTO_PACKET_END_STREAM_END_FROM_END, | |
71 | TEST_MULTIPLE_AUTO_STREAM_END_FROM_END, | |
72 | TEST_MULTIPLE_AUTO_PACKET_END_STREAM_END_FROM_END, | |
73 | }; | |
74 | ||
75 | enum test_event_type { | |
76 | TEST_EV_TYPE_NOTIF_UNEXPECTED, | |
77 | TEST_EV_TYPE_NOTIF_EVENT, | |
78 | TEST_EV_TYPE_NOTIF_INACTIVITY, | |
79 | TEST_EV_TYPE_NOTIF_STREAM_BEGIN, | |
80 | TEST_EV_TYPE_NOTIF_PACKET_BEGIN, | |
81 | TEST_EV_TYPE_NOTIF_PACKET_END, | |
82 | TEST_EV_TYPE_NOTIF_STREAM_END, | |
83 | TEST_EV_TYPE_END, | |
84 | TEST_EV_TYPE_SENTINEL, | |
85 | }; | |
86 | ||
87 | struct test_event { | |
88 | enum test_event_type type; | |
89 | struct bt_ctf_stream *stream; | |
90 | struct bt_ctf_packet *packet; | |
91 | }; | |
92 | ||
93 | struct source_muxer_sink { | |
94 | struct bt_component *source; | |
95 | struct bt_component *sink; | |
96 | }; | |
97 | ||
98 | static bool debug = false; | |
99 | static enum test current_test; | |
100 | static GArray *test_events; | |
101 | static struct bt_clock_class_priority_map *src_empty_cc_prio_map; | |
102 | static struct bt_ctf_stream_class *src_stream_class; | |
103 | static struct bt_ctf_event_class *src_event_class; | |
104 | static struct bt_ctf_stream *src_stream1; | |
105 | static struct bt_ctf_stream *src_stream2; | |
106 | static struct bt_ctf_packet *src_stream1_packet1; | |
107 | static struct bt_ctf_packet *src_stream1_packet2; | |
108 | static struct bt_ctf_packet *src_stream2_packet1; | |
109 | static struct bt_ctf_packet *src_stream2_packet2; | |
110 | ||
111 | enum { | |
112 | SEQ_END = -1, | |
113 | SEQ_STREAM1_BEGIN = -2, | |
114 | SEQ_STREAM2_BEGIN = -3, | |
115 | SEQ_STREAM1_END = -4, | |
116 | SEQ_STREAM2_END = -5, | |
117 | SEQ_STREAM1_PACKET1_BEGIN = -6, | |
118 | SEQ_STREAM1_PACKET2_BEGIN = -7, | |
119 | SEQ_STREAM2_PACKET1_BEGIN = -8, | |
120 | SEQ_STREAM2_PACKET2_BEGIN = -9, | |
121 | SEQ_STREAM1_PACKET1_END = -10, | |
122 | SEQ_STREAM1_PACKET2_END = -11, | |
123 | SEQ_STREAM2_PACKET1_END = -12, | |
124 | SEQ_STREAM2_PACKET2_END = -13, | |
125 | SEQ_EVENT_STREAM1_PACKET1 = -14, | |
126 | SEQ_EVENT_STREAM1_PACKET2 = -15, | |
127 | SEQ_EVENT_STREAM2_PACKET1 = -16, | |
128 | SEQ_EVENT_STREAM2_PACKET2 = -17, | |
129 | SEQ_INACTIVITY = -18, | |
130 | }; | |
131 | ||
132 | struct src_iter_user_data { | |
133 | int64_t *seq; | |
134 | size_t at; | |
135 | }; | |
136 | ||
137 | struct sink_user_data { | |
138 | struct bt_notification_iterator *notif_iter; | |
139 | }; | |
140 | ||
141 | /* | |
142 | * No automatic notifications generated in this block. | |
143 | * Stream 2 notifications are more indented. | |
144 | */ | |
145 | static int64_t seq_no_auto_notifs[] = { | |
146 | SEQ_STREAM1_BEGIN, | |
147 | SEQ_STREAM1_PACKET1_BEGIN, | |
148 | SEQ_EVENT_STREAM1_PACKET1, | |
149 | SEQ_EVENT_STREAM1_PACKET1, | |
150 | SEQ_STREAM2_BEGIN, | |
151 | SEQ_EVENT_STREAM1_PACKET1, | |
152 | SEQ_STREAM2_PACKET2_BEGIN, | |
153 | SEQ_EVENT_STREAM2_PACKET2, | |
154 | SEQ_EVENT_STREAM1_PACKET1, | |
155 | SEQ_STREAM1_PACKET1_END, | |
156 | SEQ_STREAM2_PACKET2_END, | |
157 | SEQ_STREAM1_PACKET2_BEGIN, | |
158 | SEQ_EVENT_STREAM1_PACKET2, | |
159 | SEQ_STREAM2_END, | |
160 | SEQ_STREAM1_PACKET2_END, | |
161 | SEQ_STREAM1_END, | |
162 | SEQ_END, | |
163 | }; | |
164 | ||
165 | /* Automatic "stream begin" from "packet begin" */ | |
166 | static int64_t seq_auto_stream_begin_from_packet_begin[] = { | |
167 | /* Automatic "stream begin" here */ | |
168 | SEQ_STREAM1_PACKET1_BEGIN, | |
169 | SEQ_STREAM1_PACKET1_END, | |
170 | SEQ_STREAM1_END, | |
171 | SEQ_END, | |
172 | }; | |
173 | ||
174 | /* Automatic "stream begin" from "stream end" */ | |
175 | static int64_t seq_auto_stream_begin_from_stream_end[] = { | |
176 | /* Automatic "stream begin" here */ | |
177 | SEQ_STREAM1_END, | |
178 | SEQ_END, | |
179 | }; | |
180 | ||
181 | /* Automatic "stream end" from END */ | |
182 | static int64_t seq_auto_stream_end_from_end[] = { | |
183 | SEQ_STREAM1_BEGIN, | |
184 | /* Automatic "packet end" here */ | |
185 | SEQ_END, | |
186 | }; | |
187 | ||
188 | /* Automatic "packet begin" from "packet end" */ | |
189 | static int64_t seq_auto_packet_begin_from_packet_end[] = { | |
190 | SEQ_STREAM1_BEGIN, | |
191 | /* Automatic "packet begin" here */ | |
192 | SEQ_STREAM1_PACKET1_END, | |
193 | SEQ_STREAM1_END, | |
194 | SEQ_END, | |
195 | }; | |
196 | ||
197 | /* Automatic "packet begin" from event */ | |
198 | static int64_t seq_auto_packet_begin_from_event[] = { | |
199 | SEQ_STREAM1_BEGIN, | |
200 | /* Automatic "packet begin" here */ | |
201 | SEQ_EVENT_STREAM1_PACKET1, | |
202 | SEQ_STREAM1_PACKET1_END, | |
203 | SEQ_STREAM1_END, | |
204 | SEQ_END, | |
205 | }; | |
206 | ||
207 | /* Automatic "packet end" from "packet begin" */ | |
208 | static int64_t seq_auto_packet_end_from_packet_begin[] = { | |
209 | SEQ_STREAM1_BEGIN, | |
210 | SEQ_STREAM1_PACKET1_BEGIN, | |
211 | /* Automatic "packet end" here */ | |
212 | SEQ_STREAM1_PACKET2_BEGIN, | |
213 | SEQ_STREAM1_PACKET2_END, | |
214 | SEQ_STREAM1_END, | |
215 | SEQ_END, | |
216 | }; | |
217 | ||
218 | /* Automatic "packet end" and "packet begin" from event */ | |
219 | static int64_t seq_auto_packet_end_packet_begin_from_event[] = { | |
220 | SEQ_STREAM1_BEGIN, | |
221 | SEQ_STREAM1_PACKET1_BEGIN, | |
222 | /* Automatic "packet end" here */ | |
223 | /* Automatic "packet begin" here */ | |
224 | SEQ_EVENT_STREAM1_PACKET2, | |
225 | SEQ_STREAM1_PACKET2_END, | |
226 | SEQ_STREAM1_END, | |
227 | SEQ_END, | |
228 | }; | |
229 | ||
230 | /* Automatic "packet end" from "stream end" */ | |
231 | static int64_t seq_auto_packet_end_from_stream_end[] = { | |
232 | SEQ_STREAM1_BEGIN, | |
233 | SEQ_STREAM1_PACKET1_BEGIN, | |
234 | /* Automatic "packet end" here */ | |
235 | SEQ_STREAM1_END, | |
236 | SEQ_END, | |
237 | }; | |
238 | ||
239 | /* Automatic "packet end" and "stream end" from END */ | |
240 | static int64_t seq_auto_packet_end_stream_end_from_end[] = { | |
241 | SEQ_STREAM1_BEGIN, | |
242 | SEQ_STREAM1_PACKET1_BEGIN, | |
243 | /* Automatic "packet end" here */ | |
244 | /* Automatic "stream end" here */ | |
245 | SEQ_END, | |
246 | }; | |
247 | ||
248 | /* Multiple automatic "stream end" from END */ | |
249 | static int64_t seq_multiple_auto_stream_end_from_end[] = { | |
250 | SEQ_STREAM1_BEGIN, | |
251 | SEQ_STREAM2_BEGIN, | |
252 | /* Automatic "stream end" here */ | |
253 | /* Automatic "stream end" here */ | |
254 | SEQ_END, | |
255 | }; | |
256 | ||
257 | /* Multiple automatic "packet end" and "stream end" from END */ | |
258 | static int64_t seq_multiple_auto_packet_end_stream_end_from_end[] = { | |
259 | SEQ_STREAM1_BEGIN, | |
260 | SEQ_STREAM2_BEGIN, | |
261 | SEQ_STREAM1_PACKET1_BEGIN, | |
262 | SEQ_STREAM2_PACKET1_BEGIN, | |
263 | /* Automatic "packet end" here */ | |
264 | /* Automatic "stream end" here */ | |
265 | /* Automatic "packet end" here */ | |
266 | /* Automatic "stream end" here */ | |
267 | SEQ_END, | |
268 | }; | |
269 | ||
270 | static | |
271 | void clear_test_events(void) | |
272 | { | |
273 | g_array_set_size(test_events, 0); | |
274 | } | |
275 | ||
276 | static | |
277 | void print_test_event(FILE *fp, const struct test_event *event) | |
278 | { | |
279 | fprintf(fp, "{ type = "); | |
280 | ||
281 | switch (event->type) { | |
282 | case TEST_EV_TYPE_NOTIF_UNEXPECTED: | |
283 | fprintf(fp, "TEST_EV_TYPE_NOTIF_UNEXPECTED"); | |
284 | break; | |
285 | case TEST_EV_TYPE_NOTIF_EVENT: | |
286 | fprintf(fp, "TEST_EV_TYPE_NOTIF_EVENT"); | |
287 | break; | |
288 | case TEST_EV_TYPE_NOTIF_INACTIVITY: | |
289 | fprintf(fp, "TEST_EV_TYPE_NOTIF_INACTIVITY"); | |
290 | break; | |
291 | case TEST_EV_TYPE_NOTIF_STREAM_BEGIN: | |
292 | fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_BEGIN"); | |
293 | break; | |
294 | case TEST_EV_TYPE_NOTIF_STREAM_END: | |
295 | fprintf(fp, "TEST_EV_TYPE_NOTIF_STREAM_END"); | |
296 | break; | |
297 | case TEST_EV_TYPE_NOTIF_PACKET_BEGIN: | |
298 | fprintf(fp, "TEST_EV_TYPE_NOTIF_PACKET_BEGIN"); | |
299 | break; | |
300 | case TEST_EV_TYPE_NOTIF_PACKET_END: | |
301 | fprintf(fp, "TEST_EV_TYPE_NOTIF_PACKET_END"); | |
302 | break; | |
303 | case TEST_EV_TYPE_END: | |
304 | fprintf(fp, "TEST_EV_TYPE_END"); | |
305 | break; | |
306 | case TEST_EV_TYPE_SENTINEL: | |
307 | fprintf(fp, "TEST_EV_TYPE_SENTINEL"); | |
308 | break; | |
309 | default: | |
310 | fprintf(fp, "(UNKNOWN)"); | |
311 | break; | |
312 | } | |
313 | ||
314 | fprintf(fp, ", stream = %p, packet = %p }", event->stream, | |
315 | event->packet); | |
316 | } | |
317 | ||
318 | static | |
319 | void append_test_event(struct test_event *event) | |
320 | { | |
321 | g_array_append_val(test_events, *event); | |
322 | } | |
323 | ||
324 | static | |
325 | bool compare_single_test_events(const struct test_event *ev_a, | |
326 | const struct test_event *ev_b) | |
327 | { | |
328 | if (debug) { | |
329 | fprintf(stderr, ":: Comparing test events: "); | |
330 | print_test_event(stderr, ev_a); | |
331 | fprintf(stderr, " vs. "); | |
332 | print_test_event(stderr, ev_b); | |
333 | fprintf(stderr, "\n"); | |
334 | } | |
335 | ||
336 | if (ev_a->type != ev_b->type) { | |
337 | return false; | |
338 | } | |
339 | ||
340 | switch (ev_a->type) { | |
341 | case TEST_EV_TYPE_END: | |
342 | case TEST_EV_TYPE_SENTINEL: | |
343 | break; | |
344 | default: | |
345 | if (ev_a->stream != ev_b->stream) { | |
346 | return false; | |
347 | } | |
348 | ||
349 | if (ev_a->packet != ev_b->packet) { | |
350 | return false; | |
351 | } | |
352 | break; | |
353 | } | |
354 | ||
355 | return true; | |
356 | } | |
357 | ||
358 | static | |
359 | bool compare_test_events(const struct test_event *expected_events) | |
360 | { | |
361 | const struct test_event *expected_event = expected_events; | |
362 | size_t i = 0; | |
363 | ||
364 | assert(expected_events); | |
365 | ||
366 | while (true) { | |
367 | const struct test_event *event; | |
368 | ||
369 | if (expected_event->type == TEST_EV_TYPE_SENTINEL) { | |
370 | break; | |
371 | } | |
372 | ||
373 | if (i >= test_events->len) { | |
374 | return false; | |
375 | } | |
376 | ||
377 | event = &g_array_index(test_events, struct test_event, i); | |
378 | ||
379 | if (!compare_single_test_events(event, expected_event)) { | |
380 | return false; | |
381 | } | |
382 | ||
383 | i++; | |
384 | expected_event++; | |
385 | } | |
386 | ||
387 | if (i != test_events->len) { | |
388 | return false; | |
389 | } | |
390 | ||
391 | return true; | |
392 | } | |
393 | ||
394 | static | |
395 | void init_static_data(void) | |
396 | { | |
397 | int ret; | |
398 | struct bt_ctf_trace *trace; | |
399 | struct bt_ctf_field_type *empty_struct_ft; | |
400 | ||
401 | /* Test events */ | |
402 | test_events = g_array_new(FALSE, TRUE, sizeof(struct test_event)); | |
403 | assert(test_events); | |
404 | ||
405 | /* Metadata */ | |
406 | empty_struct_ft = bt_ctf_field_type_structure_create(); | |
407 | assert(empty_struct_ft); | |
408 | trace = bt_ctf_trace_create(); | |
409 | assert(trace); | |
410 | ret = bt_ctf_trace_set_native_byte_order(trace, | |
411 | BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
412 | assert(ret == 0); | |
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: | |
549 | assert(false); | |
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: | |
663 | assert(false); | |
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 | { | |
704 | return BT_COMPONENT_STATUS_OK; | |
705 | } | |
706 | ||
707 | static | |
708 | void src_finalize(struct bt_private_component *private_component) | |
709 | { | |
710 | } | |
711 | ||
712 | static | |
713 | enum bt_component_status sink_consume( | |
714 | struct bt_private_component *priv_component) | |
715 | { | |
716 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; | |
717 | struct bt_notification *notification = NULL; | |
718 | struct sink_user_data *user_data = | |
719 | bt_private_component_get_user_data(priv_component); | |
720 | enum bt_notification_iterator_status it_ret; | |
721 | struct test_event test_event = { 0 }; | |
722 | bool do_append_test_event = true; | |
723 | ||
724 | assert(user_data && user_data->notif_iter); | |
725 | it_ret = bt_notification_iterator_next(user_data->notif_iter); | |
726 | ||
727 | if (it_ret < 0) { | |
728 | ret = BT_COMPONENT_STATUS_ERROR; | |
729 | do_append_test_event = false; | |
730 | goto end; | |
731 | } | |
732 | ||
733 | switch (it_ret) { | |
734 | case BT_NOTIFICATION_ITERATOR_STATUS_END: | |
735 | test_event.type = TEST_EV_TYPE_END; | |
736 | ret = BT_COMPONENT_STATUS_END; | |
737 | BT_PUT(user_data->notif_iter); | |
738 | goto end; | |
739 | case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: | |
740 | assert(false); | |
741 | default: | |
742 | break; | |
743 | } | |
744 | ||
745 | notification = bt_notification_iterator_get_notification( | |
746 | user_data->notif_iter); | |
747 | assert(notification); | |
748 | ||
749 | switch (bt_notification_get_type(notification)) { | |
750 | case BT_NOTIFICATION_TYPE_EVENT: | |
751 | { | |
752 | struct bt_ctf_event *event; | |
753 | ||
754 | test_event.type = TEST_EV_TYPE_NOTIF_EVENT; | |
755 | event = bt_notification_event_get_event(notification); | |
756 | assert(event); | |
757 | test_event.packet = bt_ctf_event_get_packet(event); | |
758 | bt_put(event); | |
759 | assert(test_event.packet); | |
760 | bt_put(test_event.packet); | |
761 | break; | |
762 | } | |
763 | case BT_NOTIFICATION_TYPE_INACTIVITY: | |
764 | test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY; | |
765 | break; | |
766 | case BT_NOTIFICATION_TYPE_STREAM_BEGIN: | |
767 | test_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
768 | test_event.stream = | |
769 | bt_notification_stream_begin_get_stream(notification); | |
770 | assert(test_event.stream); | |
771 | bt_put(test_event.stream); | |
772 | break; | |
773 | case BT_NOTIFICATION_TYPE_STREAM_END: | |
774 | test_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
775 | test_event.stream = | |
776 | bt_notification_stream_end_get_stream(notification); | |
777 | assert(test_event.stream); | |
778 | bt_put(test_event.stream); | |
779 | break; | |
780 | case BT_NOTIFICATION_TYPE_PACKET_BEGIN: | |
781 | test_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; | |
782 | test_event.packet = | |
783 | bt_notification_packet_begin_get_packet(notification); | |
784 | assert(test_event.packet); | |
785 | bt_put(test_event.packet); | |
786 | break; | |
787 | case BT_NOTIFICATION_TYPE_PACKET_END: | |
788 | test_event.type = TEST_EV_TYPE_NOTIF_PACKET_END; | |
789 | test_event.packet = | |
790 | bt_notification_packet_end_get_packet(notification); | |
791 | assert(test_event.packet); | |
792 | bt_put(test_event.packet); | |
793 | break; | |
794 | default: | |
795 | test_event.type = TEST_EV_TYPE_NOTIF_UNEXPECTED; | |
796 | break; | |
797 | } | |
798 | ||
799 | if (test_event.packet) { | |
800 | test_event.stream = bt_ctf_packet_get_stream(test_event.packet); | |
801 | assert(test_event.stream); | |
802 | bt_put(test_event.stream); | |
803 | } | |
804 | ||
805 | end: | |
806 | if (do_append_test_event) { | |
807 | append_test_event(&test_event); | |
808 | } | |
809 | ||
810 | bt_put(notification); | |
811 | return ret; | |
812 | } | |
813 | ||
814 | static | |
815 | void sink_port_connected(struct bt_private_component *private_component, | |
816 | struct bt_private_port *self_private_port, | |
817 | struct bt_port *other_port) | |
818 | { | |
819 | struct bt_private_connection *priv_conn = | |
820 | bt_private_port_get_private_connection(self_private_port); | |
821 | struct sink_user_data *user_data = bt_private_component_get_user_data( | |
822 | private_component); | |
823 | ||
824 | assert(user_data); | |
825 | assert(priv_conn); | |
826 | user_data->notif_iter = | |
827 | bt_private_connection_create_notification_iterator(priv_conn); | |
828 | assert(user_data->notif_iter); | |
829 | bt_put(priv_conn); | |
830 | } | |
831 | ||
832 | static | |
833 | enum bt_component_status sink_init( | |
834 | struct bt_private_component *private_component, | |
835 | struct bt_value *params, void *init_method_data) | |
836 | { | |
837 | struct sink_user_data *user_data = g_new0(struct sink_user_data, 1); | |
838 | int ret; | |
839 | ||
840 | assert(user_data); | |
841 | ret = bt_private_component_set_user_data(private_component, | |
842 | user_data); | |
843 | assert(ret == 0); | |
844 | return BT_COMPONENT_STATUS_OK; | |
845 | } | |
846 | ||
847 | static | |
848 | void sink_finalize(struct bt_private_component *private_component) | |
849 | { | |
850 | struct sink_user_data *user_data = bt_private_component_get_user_data( | |
851 | private_component); | |
852 | ||
853 | if (user_data) { | |
854 | bt_put(user_data->notif_iter); | |
855 | g_free(user_data); | |
856 | } | |
857 | } | |
858 | ||
859 | static | |
860 | void create_source_sink(struct bt_component **source, | |
861 | struct bt_component **sink) | |
862 | { | |
863 | struct bt_component_class *src_comp_class; | |
864 | struct bt_component_class *sink_comp_class; | |
865 | int ret; | |
866 | ||
867 | /* Create source component */ | |
868 | src_comp_class = bt_component_class_source_create("src", src_iter_next); | |
869 | assert(src_comp_class); | |
870 | ret = bt_component_class_set_init_method(src_comp_class, src_init); | |
871 | assert(ret == 0); | |
872 | ret = bt_component_class_set_finalize_method(src_comp_class, | |
873 | src_finalize); | |
874 | assert(ret == 0); | |
875 | ret = bt_component_class_source_set_notification_iterator_init_method( | |
876 | src_comp_class, src_iter_init); | |
877 | assert(ret == 0); | |
878 | ret = bt_component_class_source_set_notification_iterator_finalize_method( | |
879 | src_comp_class, src_iter_finalize); | |
880 | assert(ret == 0); | |
881 | *source = bt_component_create(src_comp_class, "source", NULL); | |
882 | assert(*source); | |
883 | ||
884 | /* Create sink component */ | |
885 | sink_comp_class = bt_component_class_sink_create("sink", sink_consume); | |
886 | assert(sink_comp_class); | |
887 | ret = bt_component_class_set_init_method(sink_comp_class, sink_init); | |
888 | assert(ret == 0); | |
889 | ret = bt_component_class_set_finalize_method(sink_comp_class, | |
890 | sink_finalize); | |
891 | ret = bt_component_class_set_port_connected_method(sink_comp_class, | |
892 | sink_port_connected); | |
893 | assert(ret == 0); | |
894 | *sink = bt_component_create(sink_comp_class, "sink", NULL); | |
895 | ||
896 | bt_put(src_comp_class); | |
897 | bt_put(sink_comp_class); | |
898 | } | |
899 | ||
900 | static | |
901 | void do_std_test(enum test test, const char *name, | |
902 | const struct test_event *expected_test_events) | |
903 | { | |
904 | struct bt_component *src_comp; | |
905 | struct bt_component *sink_comp; | |
906 | struct bt_port *upstream_port; | |
907 | struct bt_port *downstream_port; | |
908 | struct bt_graph *graph; | |
909 | void *conn; | |
910 | enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; | |
911 | ||
912 | clear_test_events(); | |
913 | current_test = test; | |
914 | diag("test: %s", name); | |
915 | create_source_sink(&src_comp, &sink_comp); | |
916 | graph = bt_graph_create(); | |
917 | assert(graph); | |
918 | ||
919 | /* Connect source to sink */ | |
920 | upstream_port = bt_component_source_get_default_output_port(src_comp); | |
921 | assert(upstream_port); | |
922 | downstream_port = bt_component_sink_get_default_input_port(sink_comp); | |
923 | assert(downstream_port); | |
924 | conn = bt_graph_connect_ports(graph, upstream_port, downstream_port); | |
925 | assert(conn); | |
926 | bt_put(conn); | |
927 | bt_put(upstream_port); | |
928 | bt_put(downstream_port); | |
929 | ||
930 | /* Run the graph until the end */ | |
931 | while (graph_status == BT_GRAPH_STATUS_OK || | |
932 | graph_status == BT_GRAPH_STATUS_AGAIN) { | |
933 | graph_status = bt_graph_run(graph); | |
934 | } | |
935 | ||
936 | ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error"); | |
937 | ||
938 | /* Compare the resulting test events */ | |
939 | if (expected_test_events) { | |
940 | ok(compare_test_events(expected_test_events), | |
941 | "the produced sequence of test events is the expected one"); | |
942 | } | |
943 | ||
944 | bt_put(src_comp); | |
945 | bt_put(sink_comp); | |
946 | bt_put(graph); | |
947 | } | |
948 | ||
949 | static | |
950 | void test_no_auto_notifs(void) | |
951 | { | |
952 | const struct test_event expected_test_events[] = { | |
953 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
954 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
955 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
956 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
957 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, }, | |
958 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
959 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, }, | |
960 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, }, | |
961 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
962 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
963 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, }, | |
964 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
965 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
966 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream2, .packet = NULL, }, | |
967 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
968 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
969 | { .type = TEST_EV_TYPE_END, }, | |
970 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
971 | }; | |
972 | ||
973 | do_std_test(TEST_NO_AUTO_NOTIFS, "no automatic notifications", | |
974 | expected_test_events); | |
975 | } | |
976 | ||
977 | static | |
978 | void test_auto_stream_begin_from_packet_begin(void) | |
979 | { | |
980 | const struct test_event expected_test_events[] = { | |
981 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
982 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
983 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
984 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
985 | { .type = TEST_EV_TYPE_END, }, | |
986 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
987 | }; | |
988 | ||
989 | do_std_test(TEST_AUTO_STREAM_BEGIN_FROM_PACKET_BEGIN, | |
990 | "automatic \"stream begin\" notif. caused by \"packet begin\" notif.", | |
991 | expected_test_events); | |
992 | } | |
993 | ||
994 | static | |
995 | void test_auto_stream_begin_from_stream_end(void) | |
996 | { | |
997 | const struct test_event expected_test_events[] = { | |
998 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
999 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1000 | { .type = TEST_EV_TYPE_END, }, | |
1001 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1002 | }; | |
1003 | ||
1004 | do_std_test(TEST_AUTO_STREAM_BEGIN_FROM_STREAM_END, | |
1005 | "automatic \"stream begin\" notif. caused by \"stream end\" notif.", | |
1006 | expected_test_events); | |
1007 | } | |
1008 | ||
1009 | static | |
1010 | void test_auto_stream_end_from_end(void) | |
1011 | { | |
1012 | const struct test_event expected_test_events[] = { | |
1013 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1014 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1015 | { .type = TEST_EV_TYPE_END, }, | |
1016 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1017 | }; | |
1018 | ||
1019 | do_std_test(TEST_AUTO_STREAM_END_FROM_END, | |
1020 | "automatic \"stream end\" notif. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1021 | expected_test_events); | |
1022 | } | |
1023 | ||
1024 | static | |
1025 | void test_auto_packet_begin_from_packet_end(void) | |
1026 | { | |
1027 | const struct test_event expected_test_events[] = { | |
1028 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1029 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1030 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1031 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1032 | { .type = TEST_EV_TYPE_END, }, | |
1033 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1034 | }; | |
1035 | ||
1036 | do_std_test(TEST_AUTO_PACKET_BEGIN_FROM_PACKET_END, | |
1037 | "automatic \"packet begin\" notif. caused by \"packet end\" notif.", | |
1038 | expected_test_events); | |
1039 | } | |
1040 | ||
1041 | static | |
1042 | void test_auto_packet_begin_from_event(void) | |
1043 | { | |
1044 | const struct test_event expected_test_events[] = { | |
1045 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1046 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1047 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1048 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1049 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1050 | { .type = TEST_EV_TYPE_END, }, | |
1051 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1052 | }; | |
1053 | ||
1054 | do_std_test(TEST_AUTO_PACKET_BEGIN_FROM_EVENT, | |
1055 | "automatic \"packet begin\" notif. caused by event notif.", | |
1056 | expected_test_events); | |
1057 | } | |
1058 | ||
1059 | static | |
1060 | void test_auto_packet_end_from_packet_begin(void) | |
1061 | { | |
1062 | const struct test_event expected_test_events[] = { | |
1063 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1064 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1065 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1066 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1067 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1068 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1069 | { .type = TEST_EV_TYPE_END, }, | |
1070 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1071 | }; | |
1072 | ||
1073 | do_std_test(TEST_AUTO_PACKET_END_FROM_PACKET_BEGIN, | |
1074 | "automatic \"packet end\" notif. caused by \"packet begin\" notif.", | |
1075 | expected_test_events); | |
1076 | } | |
1077 | ||
1078 | static | |
1079 | void test_auto_packet_end_packet_begin_from_event(void) | |
1080 | { | |
1081 | const struct test_event expected_test_events[] = { | |
1082 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1083 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1084 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1085 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1086 | { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1087 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, }, | |
1088 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1089 | { .type = TEST_EV_TYPE_END, }, | |
1090 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1091 | }; | |
1092 | ||
1093 | do_std_test(TEST_AUTO_PACKET_END_PACKET_BEGIN_FROM_EVENT, | |
1094 | "automatic \"packet end\" and \"packet begin\" notifs. caused by event notif.", | |
1095 | expected_test_events); | |
1096 | } | |
1097 | ||
1098 | static | |
1099 | void test_auto_packet_end_from_stream_end(void) | |
1100 | { | |
1101 | const struct test_event expected_test_events[] = { | |
1102 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1103 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1104 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1105 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1106 | { .type = TEST_EV_TYPE_END, }, | |
1107 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1108 | }; | |
1109 | ||
1110 | do_std_test(TEST_AUTO_PACKET_END_FROM_STREAM_END, | |
1111 | "automatic \"packet end\" notif. caused by \"stream end\" notif.", | |
1112 | expected_test_events); | |
1113 | } | |
1114 | ||
1115 | static | |
1116 | void test_auto_packet_end_stream_end_from_end(void) | |
1117 | { | |
1118 | const struct test_event expected_test_events[] = { | |
1119 | { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, }, | |
1120 | { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1121 | { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, }, | |
1122 | { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, }, | |
1123 | { .type = TEST_EV_TYPE_END, }, | |
1124 | { .type = TEST_EV_TYPE_SENTINEL, }, | |
1125 | }; | |
1126 | ||
1127 | do_std_test(TEST_AUTO_PACKET_END_STREAM_END_FROM_END, | |
1128 | "automatic \"packet end\" and \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1129 | expected_test_events); | |
1130 | } | |
1131 | ||
1132 | static | |
1133 | void test_multiple_auto_stream_end_from_end(void) | |
1134 | { | |
1135 | bool expected = true; | |
1136 | struct test_event expected_event; | |
1137 | struct test_event expected_event2; | |
1138 | struct test_event *event; | |
1139 | struct test_event *event2; | |
1140 | ||
1141 | do_std_test(TEST_MULTIPLE_AUTO_STREAM_END_FROM_END, | |
1142 | "multiple automatic \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1143 | NULL); | |
1144 | ||
1145 | if (test_events->len != 5) { | |
1146 | expected = false; | |
1147 | goto end; | |
1148 | } | |
1149 | ||
1150 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1151 | expected_event.stream = src_stream1; | |
1152 | expected_event.packet = NULL; | |
1153 | event = &g_array_index(test_events, struct test_event, 0); | |
1154 | if (!compare_single_test_events(event, &expected_event)) { | |
1155 | expected = false; | |
1156 | goto end; | |
1157 | } | |
1158 | ||
1159 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1160 | expected_event.stream = src_stream2; | |
1161 | expected_event.packet = NULL; | |
1162 | event = &g_array_index(test_events, struct test_event, 1); | |
1163 | if (!compare_single_test_events(event, &expected_event)) { | |
1164 | expected = false; | |
1165 | goto end; | |
1166 | } | |
1167 | ||
1168 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1169 | expected_event.stream = src_stream1; | |
1170 | expected_event.packet = NULL; | |
1171 | expected_event2.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1172 | expected_event2.stream = src_stream2; | |
1173 | expected_event2.packet = NULL; | |
1174 | event = &g_array_index(test_events, struct test_event, 2); | |
1175 | event2 = &g_array_index(test_events, struct test_event, 3); | |
1176 | if (!(compare_single_test_events(event, &expected_event) && | |
1177 | compare_single_test_events(event2, &expected_event2)) && | |
1178 | !(compare_single_test_events(event2, &expected_event) && | |
1179 | compare_single_test_events(event, &expected_event2))) { | |
1180 | expected = false; | |
1181 | goto end; | |
1182 | } | |
1183 | ||
1184 | expected_event.type = TEST_EV_TYPE_END; | |
1185 | expected_event.stream = NULL; | |
1186 | expected_event.packet = NULL; | |
1187 | event = &g_array_index(test_events, struct test_event, 4); | |
1188 | if (!compare_single_test_events(event, &expected_event)) { | |
1189 | expected = false; | |
1190 | goto end; | |
1191 | } | |
1192 | ||
1193 | end: | |
1194 | ok(expected, | |
1195 | "the produced sequence of test events is the expected one"); | |
1196 | } | |
1197 | ||
1198 | static | |
1199 | void test_multiple_auto_packet_end_stream_end_from_end(void) | |
1200 | { | |
1201 | bool expected = true; | |
1202 | struct test_event expected_event; | |
1203 | struct test_event expected_event2; | |
1204 | struct test_event *event; | |
1205 | struct test_event *event2; | |
1206 | ||
1207 | do_std_test(TEST_MULTIPLE_AUTO_PACKET_END_STREAM_END_FROM_END, | |
1208 | "multiple automatic \"packet end\" and \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END", | |
1209 | NULL); | |
1210 | ||
1211 | if (test_events->len != 9) { | |
1212 | expected = false; | |
1213 | goto end; | |
1214 | } | |
1215 | ||
1216 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1217 | expected_event.stream = src_stream1; | |
1218 | expected_event.packet = NULL; | |
1219 | event = &g_array_index(test_events, struct test_event, 0); | |
1220 | if (!compare_single_test_events(event, &expected_event)) { | |
1221 | expected = false; | |
1222 | goto end; | |
1223 | } | |
1224 | ||
1225 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN; | |
1226 | expected_event.stream = src_stream2; | |
1227 | expected_event.packet = NULL; | |
1228 | event = &g_array_index(test_events, struct test_event, 1); | |
1229 | if (!compare_single_test_events(event, &expected_event)) { | |
1230 | expected = false; | |
1231 | goto end; | |
1232 | } | |
1233 | ||
1234 | expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; | |
1235 | expected_event.stream = src_stream1; | |
1236 | expected_event.packet = src_stream1_packet1; | |
1237 | event = &g_array_index(test_events, struct test_event, 2); | |
1238 | if (!compare_single_test_events(event, &expected_event)) { | |
1239 | expected = false; | |
1240 | goto end; | |
1241 | } | |
1242 | ||
1243 | expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN; | |
1244 | expected_event.stream = src_stream2; | |
1245 | expected_event.packet = src_stream2_packet1; | |
1246 | event = &g_array_index(test_events, struct test_event, 3); | |
1247 | if (!compare_single_test_events(event, &expected_event)) { | |
1248 | expected = false; | |
1249 | goto end; | |
1250 | } | |
1251 | ||
1252 | expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_END; | |
1253 | expected_event.stream = src_stream1; | |
1254 | expected_event.packet = src_stream1_packet1; | |
1255 | expected_event2.type = TEST_EV_TYPE_NOTIF_PACKET_END; | |
1256 | expected_event2.stream = src_stream2; | |
1257 | expected_event2.packet = src_stream2_packet1; | |
1258 | event = &g_array_index(test_events, struct test_event, 4); | |
1259 | event2 = &g_array_index(test_events, struct test_event, 6); | |
1260 | if (!(compare_single_test_events(event, &expected_event) && | |
1261 | compare_single_test_events(event2, &expected_event2)) && | |
1262 | !(compare_single_test_events(event2, &expected_event) && | |
1263 | compare_single_test_events(event, &expected_event2))) { | |
1264 | expected = false; | |
1265 | goto end; | |
1266 | } | |
1267 | ||
1268 | expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1269 | expected_event.stream = src_stream1; | |
1270 | expected_event.packet = NULL; | |
1271 | expected_event2.type = TEST_EV_TYPE_NOTIF_STREAM_END; | |
1272 | expected_event2.stream = src_stream2; | |
1273 | expected_event2.packet = NULL; | |
1274 | event = &g_array_index(test_events, struct test_event, 5); | |
1275 | event2 = &g_array_index(test_events, struct test_event, 7); | |
1276 | if (!(compare_single_test_events(event, &expected_event) && | |
1277 | compare_single_test_events(event2, &expected_event2)) && | |
1278 | !(compare_single_test_events(event2, &expected_event) && | |
1279 | compare_single_test_events(event, &expected_event2))) { | |
1280 | expected = false; | |
1281 | goto end; | |
1282 | } | |
1283 | ||
1284 | expected_event.type = TEST_EV_TYPE_END; | |
1285 | expected_event.stream = NULL; | |
1286 | expected_event.packet = NULL; | |
1287 | event = &g_array_index(test_events, struct test_event, 8); | |
1288 | if (!compare_single_test_events(event, &expected_event)) { | |
1289 | expected = false; | |
1290 | goto end; | |
1291 | } | |
1292 | ||
1293 | end: | |
1294 | ok(expected, | |
1295 | "the produced sequence of test events is the expected one"); | |
1296 | } | |
1297 | ||
1298 | #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG" | |
1299 | ||
1300 | int main(int argc, char **argv) | |
1301 | { | |
1302 | if (getenv(DEBUG_ENV_VAR) && strcmp(getenv(DEBUG_ENV_VAR), "1") == 0) { | |
1303 | debug = true; | |
1304 | } | |
1305 | ||
1306 | plan_tests(NR_TESTS); | |
1307 | init_static_data(); | |
1308 | test_no_auto_notifs(); | |
1309 | test_auto_stream_begin_from_packet_begin(); | |
1310 | test_auto_stream_begin_from_stream_end(); | |
1311 | test_auto_stream_end_from_end(); | |
1312 | test_auto_packet_begin_from_packet_end(); | |
1313 | test_auto_packet_begin_from_event(); | |
1314 | test_auto_packet_end_from_packet_begin(); | |
1315 | test_auto_packet_end_packet_begin_from_event(); | |
1316 | test_auto_packet_end_from_stream_end(); | |
1317 | test_auto_packet_end_stream_end_from_end(); | |
1318 | test_multiple_auto_stream_end_from_end(); | |
1319 | test_multiple_auto_packet_end_stream_end_from_end(); | |
1320 | fini_static_data(); | |
1321 | return exit_status(); | |
1322 | } |