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