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