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