Remove default port API
[babeltrace.git] / tests / lib / test_bt_notification_iterator.c
1 /*
2 * Copyright 2017 - Philippe Proulx <pproulx@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; under version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <stdint.h>
21 #include <inttypes.h>
22 #include <string.h>
23 #include <assert.h>
24 #include <babeltrace/ctf-ir/event-class.h>
25 #include <babeltrace/ctf-ir/event.h>
26 #include <babeltrace/ctf-ir/field-types.h>
27 #include <babeltrace/ctf-ir/fields.h>
28 #include <babeltrace/ctf-ir/packet.h>
29 #include <babeltrace/ctf-ir/stream-class.h>
30 #include <babeltrace/ctf-ir/stream.h>
31 #include <babeltrace/ctf-ir/trace.h>
32 #include <babeltrace/graph/clock-class-priority-map.h>
33 #include <babeltrace/graph/component-class-filter.h>
34 #include <babeltrace/graph/component-class-sink.h>
35 #include <babeltrace/graph/component-class-source.h>
36 #include <babeltrace/graph/component-class.h>
37 #include <babeltrace/graph/component-sink.h>
38 #include <babeltrace/graph/component-source.h>
39 #include <babeltrace/graph/component.h>
40 #include <babeltrace/graph/graph.h>
41 #include <babeltrace/graph/notification-event.h>
42 #include <babeltrace/graph/notification-inactivity.h>
43 #include <babeltrace/graph/notification-iterator.h>
44 #include <babeltrace/graph/notification-packet.h>
45 #include <babeltrace/graph/notification-stream.h>
46 #include <babeltrace/graph/port.h>
47 #include <babeltrace/graph/private-component-source.h>
48 #include <babeltrace/graph/private-component-sink.h>
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 {
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);
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 =
834 bt_private_connection_create_notification_iterator(priv_conn);
835 assert(user_data->notif_iter);
836 bt_put(priv_conn);
837 }
838
839 static
840 enum bt_component_status sink_init(
841 struct bt_private_component *private_component,
842 struct bt_value *params, void *init_method_data)
843 {
844 struct sink_user_data *user_data = g_new0(struct sink_user_data, 1);
845 int ret;
846 void *priv_port;
847
848 assert(user_data);
849 ret = bt_private_component_set_user_data(private_component,
850 user_data);
851 assert(ret == 0);
852 priv_port = bt_private_component_sink_add_input_private_port(
853 private_component, "in", NULL);
854 assert(priv_port);
855 bt_put(priv_port);
856 return BT_COMPONENT_STATUS_OK;
857 }
858
859 static
860 void sink_finalize(struct bt_private_component *private_component)
861 {
862 struct sink_user_data *user_data = bt_private_component_get_user_data(
863 private_component);
864
865 if (user_data) {
866 bt_put(user_data->notif_iter);
867 g_free(user_data);
868 }
869 }
870
871 static
872 void create_source_sink(struct bt_component **source,
873 struct bt_component **sink)
874 {
875 struct bt_component_class *src_comp_class;
876 struct bt_component_class *sink_comp_class;
877 int ret;
878
879 /* Create source component */
880 src_comp_class = bt_component_class_source_create("src", src_iter_next);
881 assert(src_comp_class);
882 ret = bt_component_class_set_init_method(src_comp_class, src_init);
883 assert(ret == 0);
884 ret = bt_component_class_set_finalize_method(src_comp_class,
885 src_finalize);
886 assert(ret == 0);
887 ret = bt_component_class_source_set_notification_iterator_init_method(
888 src_comp_class, src_iter_init);
889 assert(ret == 0);
890 ret = bt_component_class_source_set_notification_iterator_finalize_method(
891 src_comp_class, src_iter_finalize);
892 assert(ret == 0);
893 *source = bt_component_create(src_comp_class, "source", NULL);
894 assert(*source);
895
896 /* Create sink component */
897 sink_comp_class = bt_component_class_sink_create("sink", sink_consume);
898 assert(sink_comp_class);
899 ret = bt_component_class_set_init_method(sink_comp_class, sink_init);
900 assert(ret == 0);
901 ret = bt_component_class_set_finalize_method(sink_comp_class,
902 sink_finalize);
903 ret = bt_component_class_set_port_connected_method(sink_comp_class,
904 sink_port_connected);
905 assert(ret == 0);
906 *sink = bt_component_create(sink_comp_class, "sink", NULL);
907
908 bt_put(src_comp_class);
909 bt_put(sink_comp_class);
910 }
911
912 static
913 void do_std_test(enum test test, const char *name,
914 const struct test_event *expected_test_events)
915 {
916 struct bt_component *src_comp;
917 struct bt_component *sink_comp;
918 struct bt_port *upstream_port;
919 struct bt_port *downstream_port;
920 struct bt_graph *graph;
921 void *conn;
922 enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
923
924 clear_test_events();
925 current_test = test;
926 diag("test: %s", name);
927 create_source_sink(&src_comp, &sink_comp);
928 graph = bt_graph_create();
929 assert(graph);
930
931 /* Connect source to sink */
932 upstream_port = bt_component_source_get_output_port_by_name(src_comp, "out");
933 assert(upstream_port);
934 downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in");
935 assert(downstream_port);
936 conn = bt_graph_connect_ports(graph, upstream_port, downstream_port);
937 assert(conn);
938 bt_put(conn);
939 bt_put(upstream_port);
940 bt_put(downstream_port);
941
942 /* Run the graph until the end */
943 while (graph_status == BT_GRAPH_STATUS_OK ||
944 graph_status == BT_GRAPH_STATUS_AGAIN) {
945 graph_status = bt_graph_run(graph);
946 }
947
948 ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error");
949
950 /* Compare the resulting test events */
951 if (expected_test_events) {
952 ok(compare_test_events(expected_test_events),
953 "the produced sequence of test events is the expected one");
954 }
955
956 bt_put(src_comp);
957 bt_put(sink_comp);
958 bt_put(graph);
959 }
960
961 static
962 void test_no_auto_notifs(void)
963 {
964 const struct test_event expected_test_events[] = {
965 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
966 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
967 { .type = TEST_EV_TYPE_NOTIF_EVENT, .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_STREAM_BEGIN, .stream = src_stream2, .packet = NULL, },
970 { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
971 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream2, .packet = src_stream2_packet2, },
972 { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream2, .packet = src_stream2_packet2, },
973 { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
974 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
975 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream2, .packet = src_stream2_packet2, },
976 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, },
977 { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, },
978 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream2, .packet = NULL, },
979 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, },
980 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
981 { .type = TEST_EV_TYPE_END, },
982 { .type = TEST_EV_TYPE_SENTINEL, },
983 };
984
985 do_std_test(TEST_NO_AUTO_NOTIFS, "no automatic notifications",
986 expected_test_events);
987 }
988
989 static
990 void test_auto_stream_begin_from_packet_begin(void)
991 {
992 const struct test_event expected_test_events[] = {
993 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
994 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
995 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
996 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
997 { .type = TEST_EV_TYPE_END, },
998 { .type = TEST_EV_TYPE_SENTINEL, },
999 };
1000
1001 do_std_test(TEST_AUTO_STREAM_BEGIN_FROM_PACKET_BEGIN,
1002 "automatic \"stream begin\" notif. caused by \"packet begin\" notif.",
1003 expected_test_events);
1004 }
1005
1006 static
1007 void test_auto_stream_begin_from_stream_end(void)
1008 {
1009 const struct test_event expected_test_events[] = {
1010 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1011 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1012 { .type = TEST_EV_TYPE_END, },
1013 { .type = TEST_EV_TYPE_SENTINEL, },
1014 };
1015
1016 do_std_test(TEST_AUTO_STREAM_BEGIN_FROM_STREAM_END,
1017 "automatic \"stream begin\" notif. caused by \"stream end\" notif.",
1018 expected_test_events);
1019 }
1020
1021 static
1022 void test_auto_stream_end_from_end(void)
1023 {
1024 const struct test_event expected_test_events[] = {
1025 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1026 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1027 { .type = TEST_EV_TYPE_END, },
1028 { .type = TEST_EV_TYPE_SENTINEL, },
1029 };
1030
1031 do_std_test(TEST_AUTO_STREAM_END_FROM_END,
1032 "automatic \"stream end\" notif. caused by BT_NOTIFICATION_ITERATOR_STATUS_END",
1033 expected_test_events);
1034 }
1035
1036 static
1037 void test_auto_packet_begin_from_packet_end(void)
1038 {
1039 const struct test_event expected_test_events[] = {
1040 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1041 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
1042 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
1043 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1044 { .type = TEST_EV_TYPE_END, },
1045 { .type = TEST_EV_TYPE_SENTINEL, },
1046 };
1047
1048 do_std_test(TEST_AUTO_PACKET_BEGIN_FROM_PACKET_END,
1049 "automatic \"packet begin\" notif. caused by \"packet end\" notif.",
1050 expected_test_events);
1051 }
1052
1053 static
1054 void test_auto_packet_begin_from_event(void)
1055 {
1056 const struct test_event expected_test_events[] = {
1057 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1058 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
1059 { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet1, },
1060 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
1061 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1062 { .type = TEST_EV_TYPE_END, },
1063 { .type = TEST_EV_TYPE_SENTINEL, },
1064 };
1065
1066 do_std_test(TEST_AUTO_PACKET_BEGIN_FROM_EVENT,
1067 "automatic \"packet begin\" notif. caused by event notif.",
1068 expected_test_events);
1069 }
1070
1071 static
1072 void test_auto_packet_end_from_packet_begin(void)
1073 {
1074 const struct test_event expected_test_events[] = {
1075 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1076 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
1077 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
1078 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, },
1079 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, },
1080 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1081 { .type = TEST_EV_TYPE_END, },
1082 { .type = TEST_EV_TYPE_SENTINEL, },
1083 };
1084
1085 do_std_test(TEST_AUTO_PACKET_END_FROM_PACKET_BEGIN,
1086 "automatic \"packet end\" notif. caused by \"packet begin\" notif.",
1087 expected_test_events);
1088 }
1089
1090 static
1091 void test_auto_packet_end_packet_begin_from_event(void)
1092 {
1093 const struct test_event expected_test_events[] = {
1094 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1095 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
1096 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
1097 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet2, },
1098 { .type = TEST_EV_TYPE_NOTIF_EVENT, .stream = src_stream1, .packet = src_stream1_packet2, },
1099 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet2, },
1100 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1101 { .type = TEST_EV_TYPE_END, },
1102 { .type = TEST_EV_TYPE_SENTINEL, },
1103 };
1104
1105 do_std_test(TEST_AUTO_PACKET_END_PACKET_BEGIN_FROM_EVENT,
1106 "automatic \"packet end\" and \"packet begin\" notifs. caused by event notif.",
1107 expected_test_events);
1108 }
1109
1110 static
1111 void test_auto_packet_end_from_stream_end(void)
1112 {
1113 const struct test_event expected_test_events[] = {
1114 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1115 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
1116 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
1117 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1118 { .type = TEST_EV_TYPE_END, },
1119 { .type = TEST_EV_TYPE_SENTINEL, },
1120 };
1121
1122 do_std_test(TEST_AUTO_PACKET_END_FROM_STREAM_END,
1123 "automatic \"packet end\" notif. caused by \"stream end\" notif.",
1124 expected_test_events);
1125 }
1126
1127 static
1128 void test_auto_packet_end_stream_end_from_end(void)
1129 {
1130 const struct test_event expected_test_events[] = {
1131 { .type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN, .stream = src_stream1, .packet = NULL, },
1132 { .type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN, .stream = src_stream1, .packet = src_stream1_packet1, },
1133 { .type = TEST_EV_TYPE_NOTIF_PACKET_END, .stream = src_stream1, .packet = src_stream1_packet1, },
1134 { .type = TEST_EV_TYPE_NOTIF_STREAM_END, .stream = src_stream1, .packet = NULL, },
1135 { .type = TEST_EV_TYPE_END, },
1136 { .type = TEST_EV_TYPE_SENTINEL, },
1137 };
1138
1139 do_std_test(TEST_AUTO_PACKET_END_STREAM_END_FROM_END,
1140 "automatic \"packet end\" and \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END",
1141 expected_test_events);
1142 }
1143
1144 static
1145 void test_multiple_auto_stream_end_from_end(void)
1146 {
1147 bool expected = true;
1148 struct test_event expected_event;
1149 struct test_event expected_event2;
1150 struct test_event *event;
1151 struct test_event *event2;
1152
1153 do_std_test(TEST_MULTIPLE_AUTO_STREAM_END_FROM_END,
1154 "multiple automatic \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END",
1155 NULL);
1156
1157 if (test_events->len != 5) {
1158 expected = false;
1159 goto end;
1160 }
1161
1162 expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN;
1163 expected_event.stream = src_stream1;
1164 expected_event.packet = NULL;
1165 event = &g_array_index(test_events, struct test_event, 0);
1166 if (!compare_single_test_events(event, &expected_event)) {
1167 expected = false;
1168 goto end;
1169 }
1170
1171 expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN;
1172 expected_event.stream = src_stream2;
1173 expected_event.packet = NULL;
1174 event = &g_array_index(test_events, struct test_event, 1);
1175 if (!compare_single_test_events(event, &expected_event)) {
1176 expected = false;
1177 goto end;
1178 }
1179
1180 expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_END;
1181 expected_event.stream = src_stream1;
1182 expected_event.packet = NULL;
1183 expected_event2.type = TEST_EV_TYPE_NOTIF_STREAM_END;
1184 expected_event2.stream = src_stream2;
1185 expected_event2.packet = NULL;
1186 event = &g_array_index(test_events, struct test_event, 2);
1187 event2 = &g_array_index(test_events, struct test_event, 3);
1188 if (!(compare_single_test_events(event, &expected_event) &&
1189 compare_single_test_events(event2, &expected_event2)) &&
1190 !(compare_single_test_events(event2, &expected_event) &&
1191 compare_single_test_events(event, &expected_event2))) {
1192 expected = false;
1193 goto end;
1194 }
1195
1196 expected_event.type = TEST_EV_TYPE_END;
1197 expected_event.stream = NULL;
1198 expected_event.packet = NULL;
1199 event = &g_array_index(test_events, struct test_event, 4);
1200 if (!compare_single_test_events(event, &expected_event)) {
1201 expected = false;
1202 goto end;
1203 }
1204
1205 end:
1206 ok(expected,
1207 "the produced sequence of test events is the expected one");
1208 }
1209
1210 static
1211 void test_multiple_auto_packet_end_stream_end_from_end(void)
1212 {
1213 bool expected = true;
1214 struct test_event expected_event;
1215 struct test_event expected_event2;
1216 struct test_event *event;
1217 struct test_event *event2;
1218
1219 do_std_test(TEST_MULTIPLE_AUTO_PACKET_END_STREAM_END_FROM_END,
1220 "multiple automatic \"packet end\" and \"stream end\" notifs. caused by BT_NOTIFICATION_ITERATOR_STATUS_END",
1221 NULL);
1222
1223 if (test_events->len != 9) {
1224 expected = false;
1225 goto end;
1226 }
1227
1228 expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN;
1229 expected_event.stream = src_stream1;
1230 expected_event.packet = NULL;
1231 event = &g_array_index(test_events, struct test_event, 0);
1232 if (!compare_single_test_events(event, &expected_event)) {
1233 expected = false;
1234 goto end;
1235 }
1236
1237 expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_BEGIN;
1238 expected_event.stream = src_stream2;
1239 expected_event.packet = NULL;
1240 event = &g_array_index(test_events, struct test_event, 1);
1241 if (!compare_single_test_events(event, &expected_event)) {
1242 expected = false;
1243 goto end;
1244 }
1245
1246 expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN;
1247 expected_event.stream = src_stream1;
1248 expected_event.packet = src_stream1_packet1;
1249 event = &g_array_index(test_events, struct test_event, 2);
1250 if (!compare_single_test_events(event, &expected_event)) {
1251 expected = false;
1252 goto end;
1253 }
1254
1255 expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_BEGIN;
1256 expected_event.stream = src_stream2;
1257 expected_event.packet = src_stream2_packet1;
1258 event = &g_array_index(test_events, struct test_event, 3);
1259 if (!compare_single_test_events(event, &expected_event)) {
1260 expected = false;
1261 goto end;
1262 }
1263
1264 expected_event.type = TEST_EV_TYPE_NOTIF_PACKET_END;
1265 expected_event.stream = src_stream1;
1266 expected_event.packet = src_stream1_packet1;
1267 expected_event2.type = TEST_EV_TYPE_NOTIF_PACKET_END;
1268 expected_event2.stream = src_stream2;
1269 expected_event2.packet = src_stream2_packet1;
1270 event = &g_array_index(test_events, struct test_event, 4);
1271 event2 = &g_array_index(test_events, struct test_event, 6);
1272 if (!(compare_single_test_events(event, &expected_event) &&
1273 compare_single_test_events(event2, &expected_event2)) &&
1274 !(compare_single_test_events(event2, &expected_event) &&
1275 compare_single_test_events(event, &expected_event2))) {
1276 expected = false;
1277 goto end;
1278 }
1279
1280 expected_event.type = TEST_EV_TYPE_NOTIF_STREAM_END;
1281 expected_event.stream = src_stream1;
1282 expected_event.packet = NULL;
1283 expected_event2.type = TEST_EV_TYPE_NOTIF_STREAM_END;
1284 expected_event2.stream = src_stream2;
1285 expected_event2.packet = NULL;
1286 event = &g_array_index(test_events, struct test_event, 5);
1287 event2 = &g_array_index(test_events, struct test_event, 7);
1288 if (!(compare_single_test_events(event, &expected_event) &&
1289 compare_single_test_events(event2, &expected_event2)) &&
1290 !(compare_single_test_events(event2, &expected_event) &&
1291 compare_single_test_events(event, &expected_event2))) {
1292 expected = false;
1293 goto end;
1294 }
1295
1296 expected_event.type = TEST_EV_TYPE_END;
1297 expected_event.stream = NULL;
1298 expected_event.packet = NULL;
1299 event = &g_array_index(test_events, struct test_event, 8);
1300 if (!compare_single_test_events(event, &expected_event)) {
1301 expected = false;
1302 goto end;
1303 }
1304
1305 end:
1306 ok(expected,
1307 "the produced sequence of test events is the expected one");
1308 }
1309
1310 #define DEBUG_ENV_VAR "TEST_BT_NOTIFICATION_ITERATOR_DEBUG"
1311
1312 int main(int argc, char **argv)
1313 {
1314 if (getenv(DEBUG_ENV_VAR) && strcmp(getenv(DEBUG_ENV_VAR), "1") == 0) {
1315 debug = true;
1316 }
1317
1318 plan_tests(NR_TESTS);
1319 init_static_data();
1320 test_no_auto_notifs();
1321 test_auto_stream_begin_from_packet_begin();
1322 test_auto_stream_begin_from_stream_end();
1323 test_auto_stream_end_from_end();
1324 test_auto_packet_begin_from_packet_end();
1325 test_auto_packet_begin_from_event();
1326 test_auto_packet_end_from_packet_begin();
1327 test_auto_packet_end_packet_begin_from_event();
1328 test_auto_packet_end_from_stream_end();
1329 test_auto_packet_end_stream_end_from_end();
1330 test_multiple_auto_stream_end_from_end();
1331 test_multiple_auto_packet_end_stream_end_from_end();
1332 fini_static_data();
1333 return exit_status();
1334 }
This page took 0.07761 seconds and 5 git commands to generate.