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