Do not use `bool` type; use new `bt_bool` instead
[babeltrace.git] / tests / lib / test_bt_ctf_field_type_validation.c
1 /*
2 * test_bt_ctf_field_type_validation.c
3 *
4 * Babeltrace CTF IR field type validation test
5 *
6 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; under version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include <babeltrace/ctf-ir/field-types.h>
23 #include <babeltrace/ctf-ir/field-path.h>
24 #include <babeltrace/ctf-ir/event.h>
25 #include <babeltrace/ctf-ir/event-class.h>
26 #include <babeltrace/ctf-ir/stream-class.h>
27 #include <babeltrace/ctf-ir/trace.h>
28 #include <assert.h>
29 #include <stdbool.h>
30 #include <string.h>
31 #include <stdarg.h>
32 #include <glib.h>
33 #include "tap/tap.h"
34
35 static
36 struct bt_ctf_field_type *get_good_packet_header_type(void)
37 {
38 /*
39 Generated by bt-ctfirtg using the following input:
40
41 class: struct
42 fields:
43 magic:
44 class: int
45 size: 32
46 uuid:
47 class: array
48 length: 16
49 element-type:
50 class: int
51 size: 8
52 stream_id:
53 class: int
54 size: 32
55 iron:
56 class: struct
57 fields:
58 listen:
59 class: string
60 dust:
61 class: int
62 size: 23
63 parallel:
64 class: enum
65 value-type:
66 class: int
67 size: 10
68 members:
69 - RED
70 - BLUE
71 - YELLOW
72 fire:
73 class: struct
74 fields:
75 word:
76 class: int
77 size: 17
78 rabbit:
79 class: string
80 keen:
81 class: array
82 length: word
83 element-type:
84 class: variant
85 tag: iron.parallel
86 types:
87 RED:
88 class: string
89 BLUE:
90 class: array
91 length: magic
92 element-type:
93 class: int
94 size: 5
95 YELLOW:
96 class: struct
97 report:
98 class: array
99 length: trace.packet.header.iron.dust
100 element-type:
101 class: string
102 group:
103 class: array
104 length: trace.packet.header.stream_id
105 element-type:
106 class: string
107 serious:
108 class: int
109 size: 1
110
111 */
112
113 struct bt_ctf_field_type *root = NULL;
114 struct bt_ctf_field_type *root_magic = NULL;
115 struct bt_ctf_field_type *root_uuid = NULL;
116 struct bt_ctf_field_type *root_uuid_elem = NULL;
117 struct bt_ctf_field_type *root_stream_id = NULL;
118 struct bt_ctf_field_type *root_iron = NULL;
119 struct bt_ctf_field_type *root_iron_listen = NULL;
120 struct bt_ctf_field_type *root_iron_dust = NULL;
121 struct bt_ctf_field_type *root_iron_parallel = NULL;
122 struct bt_ctf_field_type *root_iron_parallel_int = NULL;
123 struct bt_ctf_field_type *root_iron_fire = NULL;
124 struct bt_ctf_field_type *root_iron_fire_word = NULL;
125 struct bt_ctf_field_type *root_iron_fire_rabbit = NULL;
126 struct bt_ctf_field_type *root_iron_fire_keen = NULL;
127 struct bt_ctf_field_type *root_iron_fire_keen_elem = NULL;
128 struct bt_ctf_field_type *root_iron_fire_keen_elem_RED = NULL;
129 struct bt_ctf_field_type *root_iron_fire_keen_elem_BLUE = NULL;
130 struct bt_ctf_field_type *root_iron_fire_keen_elem_BLUE_elem = NULL;
131 struct bt_ctf_field_type *root_iron_fire_keen_elem_YELLOW = NULL;
132 struct bt_ctf_field_type *root_iron_report = NULL;
133 struct bt_ctf_field_type *root_iron_report_elem = NULL;
134 struct bt_ctf_field_type *root_iron_group = NULL;
135 struct bt_ctf_field_type *root_iron_group_elem = NULL;
136 struct bt_ctf_field_type *root_serious = NULL;
137
138 int ret;
139 root = bt_ctf_field_type_structure_create();
140 assert(root);
141 ret = bt_ctf_field_type_set_alignment(root, 8);
142 assert(ret == 0);
143 root_magic = bt_ctf_field_type_integer_create(32);
144 assert(root_magic);
145 ret = bt_ctf_field_type_integer_set_signed(root_magic, 0);
146 assert(ret == 0);
147 ret = bt_ctf_field_type_integer_set_base(root_magic, 10);
148 assert(ret == 0);
149 ret = bt_ctf_field_type_integer_set_encoding(root_magic, BT_CTF_STRING_ENCODING_NONE);
150 assert(ret == 0);
151 ret = bt_ctf_field_type_set_byte_order(root_magic, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
152 assert(ret == 0);
153 ret = bt_ctf_field_type_set_alignment(root_magic, 8);
154 assert(ret == 0);
155 ret = bt_ctf_field_type_structure_add_field(root, root_magic, "magic");
156 assert(ret == 0);
157 root_uuid_elem = bt_ctf_field_type_integer_create(8);
158 assert(root_uuid_elem);
159 ret = bt_ctf_field_type_integer_set_signed(root_uuid_elem, 0);
160 assert(ret == 0);
161 ret = bt_ctf_field_type_integer_set_base(root_uuid_elem, 10);
162 assert(ret == 0);
163 ret = bt_ctf_field_type_integer_set_encoding(root_uuid_elem, BT_CTF_STRING_ENCODING_NONE);
164 assert(ret == 0);
165 ret = bt_ctf_field_type_set_byte_order(root_uuid_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
166 assert(ret == 0);
167 ret = bt_ctf_field_type_set_alignment(root_uuid_elem, 8);
168 assert(ret == 0);
169 root_uuid = bt_ctf_field_type_array_create(root_uuid_elem, 16);
170 assert(root_uuid);
171 ret = bt_ctf_field_type_structure_add_field(root, root_uuid, "uuid");
172 assert(ret == 0);
173 root_stream_id = bt_ctf_field_type_integer_create(32);
174 assert(root_stream_id);
175 ret = bt_ctf_field_type_integer_set_signed(root_stream_id, 0);
176 assert(ret == 0);
177 ret = bt_ctf_field_type_integer_set_base(root_stream_id, 10);
178 assert(ret == 0);
179 ret = bt_ctf_field_type_integer_set_encoding(root_stream_id, BT_CTF_STRING_ENCODING_NONE);
180 assert(ret == 0);
181 ret = bt_ctf_field_type_set_byte_order(root_stream_id, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
182 assert(ret == 0);
183 ret = bt_ctf_field_type_set_alignment(root_stream_id, 8);
184 assert(ret == 0);
185 ret = bt_ctf_field_type_structure_add_field(root, root_stream_id, "stream_id");
186 assert(ret == 0);
187 root_iron = bt_ctf_field_type_structure_create();
188 assert(root_iron);
189 ret = bt_ctf_field_type_set_alignment(root_iron, 8);
190 assert(ret == 0);
191 root_iron_listen = bt_ctf_field_type_string_create();
192 assert(root_iron_listen);
193 ret = bt_ctf_field_type_string_set_encoding(root_iron_listen, BT_CTF_STRING_ENCODING_UTF8);
194 assert(ret == 0);
195 ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_listen, "listen");
196 assert(ret == 0);
197 root_iron_dust = bt_ctf_field_type_integer_create(23);
198 assert(root_iron_dust);
199 ret = bt_ctf_field_type_integer_set_signed(root_iron_dust, 0);
200 assert(ret == 0);
201 ret = bt_ctf_field_type_integer_set_base(root_iron_dust, 10);
202 assert(ret == 0);
203 ret = bt_ctf_field_type_integer_set_encoding(root_iron_dust, BT_CTF_STRING_ENCODING_NONE);
204 assert(ret == 0);
205 ret = bt_ctf_field_type_set_byte_order(root_iron_dust, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
206 assert(ret == 0);
207 ret = bt_ctf_field_type_set_alignment(root_iron_dust, 1);
208 assert(ret == 0);
209 ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_dust, "dust");
210 assert(ret == 0);
211 root_iron_parallel_int = bt_ctf_field_type_integer_create(10);
212 assert(root_iron_parallel_int);
213 ret = bt_ctf_field_type_integer_set_signed(root_iron_parallel_int, 0);
214 assert(ret == 0);
215 ret = bt_ctf_field_type_integer_set_base(root_iron_parallel_int, 10);
216 assert(ret == 0);
217 ret = bt_ctf_field_type_integer_set_encoding(root_iron_parallel_int, BT_CTF_STRING_ENCODING_NONE);
218 assert(ret == 0);
219 ret = bt_ctf_field_type_set_byte_order(root_iron_parallel_int, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
220 assert(ret == 0);
221 ret = bt_ctf_field_type_set_alignment(root_iron_parallel_int, 1);
222 assert(ret == 0);
223 root_iron_parallel = bt_ctf_field_type_enumeration_create(root_iron_parallel_int);
224 assert(root_iron_parallel);
225 ret = bt_ctf_field_type_enumeration_add_mapping(root_iron_parallel, "RED", 0, 0);
226 assert(ret == 0);
227 ret = bt_ctf_field_type_enumeration_add_mapping(root_iron_parallel, "BLUE", 1, 1);
228 assert(ret == 0);
229 ret = bt_ctf_field_type_enumeration_add_mapping(root_iron_parallel, "YELLOW", 2, 2);
230 assert(ret == 0);
231 ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_parallel, "parallel");
232 assert(ret == 0);
233 root_iron_fire = bt_ctf_field_type_structure_create();
234 assert(root_iron_fire);
235 ret = bt_ctf_field_type_set_alignment(root_iron_fire, 8);
236 assert(ret == 0);
237 root_iron_fire_word = bt_ctf_field_type_integer_create(17);
238 assert(root_iron_fire_word);
239 ret = bt_ctf_field_type_integer_set_signed(root_iron_fire_word, 0);
240 assert(ret == 0);
241 ret = bt_ctf_field_type_integer_set_base(root_iron_fire_word, 10);
242 assert(ret == 0);
243 ret = bt_ctf_field_type_integer_set_encoding(root_iron_fire_word, BT_CTF_STRING_ENCODING_NONE);
244 assert(ret == 0);
245 ret = bt_ctf_field_type_set_byte_order(root_iron_fire_word, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
246 assert(ret == 0);
247 ret = bt_ctf_field_type_set_alignment(root_iron_fire_word, 1);
248 assert(ret == 0);
249 ret = bt_ctf_field_type_structure_add_field(root_iron_fire, root_iron_fire_word, "word");
250 assert(ret == 0);
251 root_iron_fire_rabbit = bt_ctf_field_type_string_create();
252 assert(root_iron_fire_rabbit);
253 ret = bt_ctf_field_type_string_set_encoding(root_iron_fire_rabbit, BT_CTF_STRING_ENCODING_UTF8);
254 assert(ret == 0);
255 ret = bt_ctf_field_type_structure_add_field(root_iron_fire, root_iron_fire_rabbit, "rabbit");
256 assert(ret == 0);
257 root_iron_fire_keen_elem = bt_ctf_field_type_variant_create(NULL, "iron.parallel");
258 assert(root_iron_fire_keen_elem);
259 root_iron_fire_keen_elem_RED = bt_ctf_field_type_string_create();
260 assert(root_iron_fire_keen_elem_RED);
261 ret = bt_ctf_field_type_string_set_encoding(root_iron_fire_keen_elem_RED, BT_CTF_STRING_ENCODING_UTF8);
262 assert(ret == 0);
263 ret = bt_ctf_field_type_variant_add_field(root_iron_fire_keen_elem, root_iron_fire_keen_elem_RED, "RED");
264 assert(ret == 0);
265 root_iron_fire_keen_elem_BLUE_elem = bt_ctf_field_type_integer_create(5);
266 assert(root_iron_fire_keen_elem_BLUE_elem);
267 ret = bt_ctf_field_type_integer_set_signed(root_iron_fire_keen_elem_BLUE_elem, 0);
268 assert(ret == 0);
269 ret = bt_ctf_field_type_integer_set_base(root_iron_fire_keen_elem_BLUE_elem, 10);
270 assert(ret == 0);
271 ret = bt_ctf_field_type_integer_set_encoding(root_iron_fire_keen_elem_BLUE_elem, BT_CTF_STRING_ENCODING_NONE);
272 assert(ret == 0);
273 ret = bt_ctf_field_type_set_byte_order(root_iron_fire_keen_elem_BLUE_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
274 assert(ret == 0);
275 ret = bt_ctf_field_type_set_alignment(root_iron_fire_keen_elem_BLUE_elem, 1);
276 assert(ret == 0);
277 root_iron_fire_keen_elem_BLUE = bt_ctf_field_type_sequence_create(root_iron_fire_keen_elem_BLUE_elem, "magic");
278 assert(root_iron_fire_keen_elem_BLUE);
279 ret = bt_ctf_field_type_variant_add_field(root_iron_fire_keen_elem, root_iron_fire_keen_elem_BLUE, "BLUE");
280 assert(ret == 0);
281 root_iron_fire_keen_elem_YELLOW = bt_ctf_field_type_structure_create();
282 assert(root_iron_fire_keen_elem_YELLOW);
283 ret = bt_ctf_field_type_set_alignment(root_iron_fire_keen_elem_YELLOW, 1);
284 assert(ret == 0);
285 ret = bt_ctf_field_type_variant_add_field(root_iron_fire_keen_elem, root_iron_fire_keen_elem_YELLOW, "YELLOW");
286 assert(ret == 0);
287 root_iron_fire_keen = bt_ctf_field_type_sequence_create(root_iron_fire_keen_elem, "word");
288 assert(root_iron_fire_keen);
289 ret = bt_ctf_field_type_structure_add_field(root_iron_fire, root_iron_fire_keen, "keen");
290 assert(ret == 0);
291 ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_fire, "fire");
292 assert(ret == 0);
293 root_iron_report_elem = bt_ctf_field_type_string_create();
294 assert(root_iron_report_elem);
295 ret = bt_ctf_field_type_string_set_encoding(root_iron_report_elem, BT_CTF_STRING_ENCODING_UTF8);
296 assert(ret == 0);
297 root_iron_report = bt_ctf_field_type_sequence_create(root_iron_report_elem, "trace.packet.header.iron.dust");
298 assert(root_iron_report);
299 ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_report, "report");
300 assert(ret == 0);
301 root_iron_group_elem = bt_ctf_field_type_string_create();
302 assert(root_iron_group_elem);
303 ret = bt_ctf_field_type_string_set_encoding(root_iron_group_elem, BT_CTF_STRING_ENCODING_UTF8);
304 assert(ret == 0);
305 root_iron_group = bt_ctf_field_type_sequence_create(root_iron_group_elem, "trace.packet.header.stream_id");
306 assert(root_iron_group);
307 ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_group, "group");
308 assert(ret == 0);
309 ret = bt_ctf_field_type_structure_add_field(root, root_iron, "iron");
310 assert(ret == 0);
311 root_serious = bt_ctf_field_type_integer_create(1);
312 assert(root_serious);
313 ret = bt_ctf_field_type_integer_set_signed(root_serious, 0);
314 assert(ret == 0);
315 ret = bt_ctf_field_type_integer_set_base(root_serious, 10);
316 assert(ret == 0);
317 ret = bt_ctf_field_type_integer_set_encoding(root_serious, BT_CTF_STRING_ENCODING_NONE);
318 assert(ret == 0);
319 ret = bt_ctf_field_type_set_byte_order(root_serious, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
320 assert(ret == 0);
321 ret = bt_ctf_field_type_set_alignment(root_serious, 1);
322 assert(ret == 0);
323 ret = bt_ctf_field_type_structure_add_field(root, root_serious, "serious");
324 assert(ret == 0);
325
326 BT_PUT(root_magic);
327 BT_PUT(root_uuid);
328 BT_PUT(root_uuid_elem);
329 BT_PUT(root_stream_id);
330 BT_PUT(root_iron);
331 BT_PUT(root_iron_listen);
332 BT_PUT(root_iron_dust);
333 BT_PUT(root_iron_parallel);
334 BT_PUT(root_iron_parallel_int);
335 BT_PUT(root_iron_fire);
336 BT_PUT(root_iron_fire_word);
337 BT_PUT(root_iron_fire_rabbit);
338 BT_PUT(root_iron_fire_keen);
339 BT_PUT(root_iron_fire_keen_elem);
340 BT_PUT(root_iron_fire_keen_elem_RED);
341 BT_PUT(root_iron_fire_keen_elem_BLUE);
342 BT_PUT(root_iron_fire_keen_elem_BLUE_elem);
343 BT_PUT(root_iron_fire_keen_elem_YELLOW);
344 BT_PUT(root_iron_report);
345 BT_PUT(root_iron_report_elem);
346 BT_PUT(root_iron_group);
347 BT_PUT(root_iron_group_elem);
348 BT_PUT(root_serious);
349
350 return root;
351 }
352
353 static
354 struct bt_ctf_field_type *get_good_packet_context_type(void)
355 {
356 /*
357 Generated by bt-ctfirtg using the following input:
358
359 class: struct
360 fields:
361 placid:
362 class: int
363 size: 32
364 meow:
365 class: string
366 serious:
367 class: int
368 size: 11
369 naive:
370 class: array
371 length: 17
372 element-type:
373 class: array
374 length: placid
375 element-type:
376 class: string
377 clover:
378 class: struct
379 fields:
380 oval:
381 class: int
382 size: 17
383 whole:
384 class: variant
385 tag: iron.parallel
386 types:
387 BLUE:
388 class: array
389 length: trace.packet.header.iron.fire.word
390 element-type:
391 class: string
392 RED:
393 class: int
394 size: 44
395 YELLOW:
396 class: string
397 egg:
398 class: array
399 length: stream.packet.context.clover.oval
400 element-type:
401 class: int
402 size: 55
403 square:
404 class: enum
405 value-type:
406 class: int
407 size: 12
408 members:
409 - YOUNG
410 - OLD
411 useful:
412 class: array
413 length: serious
414 element-type:
415 class: int
416 size: 2
417 tart:
418 class: string
419
420 */
421
422 struct bt_ctf_field_type *root = NULL;
423 struct bt_ctf_field_type *root_placid = NULL;
424 struct bt_ctf_field_type *root_meow = NULL;
425 struct bt_ctf_field_type *root_serious = NULL;
426 struct bt_ctf_field_type *root_naive = NULL;
427 struct bt_ctf_field_type *root_naive_elem = NULL;
428 struct bt_ctf_field_type *root_naive_elem_elem = NULL;
429 struct bt_ctf_field_type *root_clover = NULL;
430 struct bt_ctf_field_type *root_clover_oval = NULL;
431 struct bt_ctf_field_type *root_clover_whole = NULL;
432 struct bt_ctf_field_type *root_clover_whole_BLUE = NULL;
433 struct bt_ctf_field_type *root_clover_whole_BLUE_elem = NULL;
434 struct bt_ctf_field_type *root_clover_whole_RED = NULL;
435 struct bt_ctf_field_type *root_clover_whole_YELLOW = NULL;
436 struct bt_ctf_field_type *root_clover_egg = NULL;
437 struct bt_ctf_field_type *root_clover_egg_elem = NULL;
438 struct bt_ctf_field_type *root_clover_square = NULL;
439 struct bt_ctf_field_type *root_clover_square_int = NULL;
440 struct bt_ctf_field_type *root_clover_useful = NULL;
441 struct bt_ctf_field_type *root_clover_useful_elem = NULL;
442 struct bt_ctf_field_type *root_tart = NULL;
443
444 int ret;
445 root = bt_ctf_field_type_structure_create();
446 assert(root);
447 ret = bt_ctf_field_type_set_alignment(root, 8);
448 assert(ret == 0);
449 root_placid = bt_ctf_field_type_integer_create(32);
450 assert(root_placid);
451 ret = bt_ctf_field_type_integer_set_signed(root_placid, 0);
452 assert(ret == 0);
453 ret = bt_ctf_field_type_integer_set_base(root_placid, 10);
454 assert(ret == 0);
455 ret = bt_ctf_field_type_integer_set_encoding(root_placid, BT_CTF_STRING_ENCODING_NONE);
456 assert(ret == 0);
457 ret = bt_ctf_field_type_set_byte_order(root_placid, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
458 assert(ret == 0);
459 ret = bt_ctf_field_type_set_alignment(root_placid, 8);
460 assert(ret == 0);
461 ret = bt_ctf_field_type_structure_add_field(root, root_placid, "placid");
462 assert(ret == 0);
463 root_meow = bt_ctf_field_type_string_create();
464 assert(root_meow);
465 ret = bt_ctf_field_type_string_set_encoding(root_meow, BT_CTF_STRING_ENCODING_UTF8);
466 assert(ret == 0);
467 ret = bt_ctf_field_type_structure_add_field(root, root_meow, "meow");
468 assert(ret == 0);
469 root_serious = bt_ctf_field_type_integer_create(11);
470 assert(root_serious);
471 ret = bt_ctf_field_type_integer_set_signed(root_serious, 0);
472 assert(ret == 0);
473 ret = bt_ctf_field_type_integer_set_base(root_serious, 10);
474 assert(ret == 0);
475 ret = bt_ctf_field_type_integer_set_encoding(root_serious, BT_CTF_STRING_ENCODING_NONE);
476 assert(ret == 0);
477 ret = bt_ctf_field_type_set_byte_order(root_serious, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
478 assert(ret == 0);
479 ret = bt_ctf_field_type_set_alignment(root_serious, 1);
480 assert(ret == 0);
481 ret = bt_ctf_field_type_structure_add_field(root, root_serious, "serious");
482 assert(ret == 0);
483 root_naive_elem_elem = bt_ctf_field_type_string_create();
484 assert(root_naive_elem_elem);
485 ret = bt_ctf_field_type_string_set_encoding(root_naive_elem_elem, BT_CTF_STRING_ENCODING_UTF8);
486 assert(ret == 0);
487 root_naive_elem = bt_ctf_field_type_sequence_create(root_naive_elem_elem, "placid");
488 assert(root_naive_elem);
489 root_naive = bt_ctf_field_type_array_create(root_naive_elem, 17);
490 assert(root_naive);
491 ret = bt_ctf_field_type_structure_add_field(root, root_naive, "naive");
492 assert(ret == 0);
493 root_clover = bt_ctf_field_type_structure_create();
494 assert(root_clover);
495 ret = bt_ctf_field_type_set_alignment(root_clover, 1);
496 assert(ret == 0);
497 root_clover_oval = bt_ctf_field_type_integer_create(17);
498 assert(root_clover_oval);
499 ret = bt_ctf_field_type_integer_set_signed(root_clover_oval, 0);
500 assert(ret == 0);
501 ret = bt_ctf_field_type_integer_set_base(root_clover_oval, 10);
502 assert(ret == 0);
503 ret = bt_ctf_field_type_integer_set_encoding(root_clover_oval, BT_CTF_STRING_ENCODING_NONE);
504 assert(ret == 0);
505 ret = bt_ctf_field_type_set_byte_order(root_clover_oval, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
506 assert(ret == 0);
507 ret = bt_ctf_field_type_set_alignment(root_clover_oval, 1);
508 assert(ret == 0);
509 ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_oval, "oval");
510 assert(ret == 0);
511 root_clover_whole = bt_ctf_field_type_variant_create(NULL, "iron.parallel");
512 assert(root_clover_whole);
513 root_clover_whole_BLUE_elem = bt_ctf_field_type_string_create();
514 assert(root_clover_whole_BLUE_elem);
515 ret = bt_ctf_field_type_string_set_encoding(root_clover_whole_BLUE_elem, BT_CTF_STRING_ENCODING_UTF8);
516 assert(ret == 0);
517 root_clover_whole_BLUE = bt_ctf_field_type_sequence_create(root_clover_whole_BLUE_elem, "trace.packet.header.iron.fire.word");
518 assert(root_clover_whole_BLUE);
519 ret = bt_ctf_field_type_variant_add_field(root_clover_whole, root_clover_whole_BLUE, "BLUE");
520 assert(ret == 0);
521 root_clover_whole_RED = bt_ctf_field_type_integer_create(44);
522 assert(root_clover_whole_RED);
523 ret = bt_ctf_field_type_integer_set_signed(root_clover_whole_RED, 0);
524 assert(ret == 0);
525 ret = bt_ctf_field_type_integer_set_base(root_clover_whole_RED, 10);
526 assert(ret == 0);
527 ret = bt_ctf_field_type_integer_set_encoding(root_clover_whole_RED, BT_CTF_STRING_ENCODING_NONE);
528 assert(ret == 0);
529 ret = bt_ctf_field_type_set_byte_order(root_clover_whole_RED, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
530 assert(ret == 0);
531 ret = bt_ctf_field_type_set_alignment(root_clover_whole_RED, 1);
532 assert(ret == 0);
533 ret = bt_ctf_field_type_variant_add_field(root_clover_whole, root_clover_whole_RED, "RED");
534 assert(ret == 0);
535 root_clover_whole_YELLOW = bt_ctf_field_type_string_create();
536 assert(root_clover_whole_YELLOW);
537 ret = bt_ctf_field_type_string_set_encoding(root_clover_whole_YELLOW, BT_CTF_STRING_ENCODING_UTF8);
538 assert(ret == 0);
539 ret = bt_ctf_field_type_variant_add_field(root_clover_whole, root_clover_whole_YELLOW, "YELLOW");
540 assert(ret == 0);
541 ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_whole, "whole");
542 assert(ret == 0);
543 root_clover_egg_elem = bt_ctf_field_type_integer_create(55);
544 assert(root_clover_egg_elem);
545 ret = bt_ctf_field_type_integer_set_signed(root_clover_egg_elem, 0);
546 assert(ret == 0);
547 ret = bt_ctf_field_type_integer_set_base(root_clover_egg_elem, 10);
548 assert(ret == 0);
549 ret = bt_ctf_field_type_integer_set_encoding(root_clover_egg_elem, BT_CTF_STRING_ENCODING_NONE);
550 assert(ret == 0);
551 ret = bt_ctf_field_type_set_byte_order(root_clover_egg_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
552 assert(ret == 0);
553 ret = bt_ctf_field_type_set_alignment(root_clover_egg_elem, 1);
554 assert(ret == 0);
555 root_clover_egg = bt_ctf_field_type_sequence_create(root_clover_egg_elem, "stream.packet.context.clover.oval");
556 assert(root_clover_egg);
557 ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_egg, "egg");
558 assert(ret == 0);
559 root_clover_square_int = bt_ctf_field_type_integer_create(12);
560 assert(root_clover_square_int);
561 ret = bt_ctf_field_type_integer_set_signed(root_clover_square_int, 0);
562 assert(ret == 0);
563 ret = bt_ctf_field_type_integer_set_base(root_clover_square_int, 10);
564 assert(ret == 0);
565 ret = bt_ctf_field_type_integer_set_encoding(root_clover_square_int, BT_CTF_STRING_ENCODING_NONE);
566 assert(ret == 0);
567 ret = bt_ctf_field_type_set_byte_order(root_clover_square_int, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
568 assert(ret == 0);
569 ret = bt_ctf_field_type_set_alignment(root_clover_square_int, 1);
570 assert(ret == 0);
571 root_clover_square = bt_ctf_field_type_enumeration_create(root_clover_square_int);
572 assert(root_clover_square);
573 ret = bt_ctf_field_type_enumeration_add_mapping(root_clover_square, "YOUNG", 0, 0);
574 assert(ret == 0);
575 ret = bt_ctf_field_type_enumeration_add_mapping(root_clover_square, "OLD", 1, 1);
576 assert(ret == 0);
577 ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_square, "square");
578 assert(ret == 0);
579 root_clover_useful_elem = bt_ctf_field_type_integer_create(2);
580 assert(root_clover_useful_elem);
581 ret = bt_ctf_field_type_integer_set_signed(root_clover_useful_elem, 0);
582 assert(ret == 0);
583 ret = bt_ctf_field_type_integer_set_base(root_clover_useful_elem, 10);
584 assert(ret == 0);
585 ret = bt_ctf_field_type_integer_set_encoding(root_clover_useful_elem, BT_CTF_STRING_ENCODING_NONE);
586 assert(ret == 0);
587 ret = bt_ctf_field_type_set_byte_order(root_clover_useful_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
588 assert(ret == 0);
589 ret = bt_ctf_field_type_set_alignment(root_clover_useful_elem, 1);
590 assert(ret == 0);
591 root_clover_useful = bt_ctf_field_type_sequence_create(root_clover_useful_elem, "serious");
592 assert(root_clover_useful);
593 ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_useful, "useful");
594 assert(ret == 0);
595 ret = bt_ctf_field_type_structure_add_field(root, root_clover, "clover");
596 assert(ret == 0);
597 root_tart = bt_ctf_field_type_string_create();
598 assert(root_tart);
599 ret = bt_ctf_field_type_string_set_encoding(root_tart, BT_CTF_STRING_ENCODING_UTF8);
600 assert(ret == 0);
601 ret = bt_ctf_field_type_structure_add_field(root, root_tart, "tart");
602 assert(ret == 0);
603
604 BT_PUT(root_placid);
605 BT_PUT(root_meow);
606 BT_PUT(root_serious);
607 BT_PUT(root_naive);
608 BT_PUT(root_naive_elem);
609 BT_PUT(root_naive_elem_elem);
610 BT_PUT(root_clover);
611 BT_PUT(root_clover_oval);
612 BT_PUT(root_clover_whole);
613 BT_PUT(root_clover_whole_BLUE);
614 BT_PUT(root_clover_whole_BLUE_elem);
615 BT_PUT(root_clover_whole_RED);
616 BT_PUT(root_clover_whole_YELLOW);
617 BT_PUT(root_clover_egg);
618 BT_PUT(root_clover_egg_elem);
619 BT_PUT(root_clover_square);
620 BT_PUT(root_clover_square_int);
621 BT_PUT(root_clover_useful);
622 BT_PUT(root_clover_useful_elem);
623 BT_PUT(root_tart);
624
625 return root;
626 }
627
628
629 static
630 struct bt_ctf_field_type *get_good_event_header_type(void)
631 {
632 /*
633 Generated by bt-ctfirtg using the following input:
634
635 class: struct
636 fields:
637 id:
638 class: int
639 size: 17
640 timestamp:
641 class: int
642 size: 64
643 action:
644 class: struct
645 fields:
646 special:
647 class: int
648 size: 17
649 lucky:
650 class: array
651 length: stream.packet.context.placid
652 element-type:
653 class: string
654 dream:
655 class: string
656 grandiose:
657 class: array
658 length: trace.packet.header.serious
659 element-type:
660 class: int
661 size: 3
662 stiff:
663 class: array
664 length: clover.whole.RED
665 element-type:
666 class: string
667 fruit:
668 class: struct
669 fields:
670 apple:
671 class: array
672 length: action.special
673 element-type:
674 class: int
675 size: 5
676
677 */
678
679 struct bt_ctf_field_type *root = NULL;
680 struct bt_ctf_field_type *root_id = NULL;
681 struct bt_ctf_field_type *root_timestamp = NULL;
682 struct bt_ctf_field_type *root_action = NULL;
683 struct bt_ctf_field_type *root_action_special = NULL;
684 struct bt_ctf_field_type *root_action_lucky = NULL;
685 struct bt_ctf_field_type *root_action_lucky_elem = NULL;
686 struct bt_ctf_field_type *root_action_dream = NULL;
687 struct bt_ctf_field_type *root_action_grandiose = NULL;
688 struct bt_ctf_field_type *root_action_grandiose_elem = NULL;
689 struct bt_ctf_field_type *root_stiff = NULL;
690 struct bt_ctf_field_type *root_stiff_elem = NULL;
691 struct bt_ctf_field_type *root_fruit = NULL;
692 struct bt_ctf_field_type *root_fruit_apple = NULL;
693 struct bt_ctf_field_type *root_fruit_apple_elem = NULL;
694
695 int ret;
696 root = bt_ctf_field_type_structure_create();
697 assert(root);
698 ret = bt_ctf_field_type_set_alignment(root, 8);
699 assert(ret == 0);
700 root_id = bt_ctf_field_type_integer_create(17);
701 assert(root_id);
702 ret = bt_ctf_field_type_integer_set_signed(root_id, 0);
703 assert(ret == 0);
704 ret = bt_ctf_field_type_integer_set_base(root_id, 10);
705 assert(ret == 0);
706 ret = bt_ctf_field_type_integer_set_encoding(root_id, BT_CTF_STRING_ENCODING_NONE);
707 assert(ret == 0);
708 ret = bt_ctf_field_type_set_byte_order(root_id, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
709 assert(ret == 0);
710 ret = bt_ctf_field_type_set_alignment(root_id, 1);
711 assert(ret == 0);
712 ret = bt_ctf_field_type_structure_add_field(root, root_id, "id");
713 assert(ret == 0);
714 root_timestamp = bt_ctf_field_type_integer_create(64);
715 assert(root_timestamp);
716 ret = bt_ctf_field_type_integer_set_signed(root_timestamp, 0);
717 assert(ret == 0);
718 ret = bt_ctf_field_type_integer_set_base(root_timestamp, 10);
719 assert(ret == 0);
720 ret = bt_ctf_field_type_integer_set_encoding(root_timestamp, BT_CTF_STRING_ENCODING_NONE);
721 assert(ret == 0);
722 ret = bt_ctf_field_type_set_byte_order(root_timestamp, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
723 assert(ret == 0);
724 ret = bt_ctf_field_type_set_alignment(root_timestamp, 8);
725 assert(ret == 0);
726 ret = bt_ctf_field_type_structure_add_field(root, root_timestamp, "timestamp");
727 assert(ret == 0);
728 root_action = bt_ctf_field_type_structure_create();
729 assert(root_action);
730 ret = bt_ctf_field_type_set_alignment(root_action, 8);
731 assert(ret == 0);
732 root_action_special = bt_ctf_field_type_integer_create(17);
733 assert(root_action_special);
734 ret = bt_ctf_field_type_integer_set_signed(root_action_special, 0);
735 assert(ret == 0);
736 ret = bt_ctf_field_type_integer_set_base(root_action_special, 10);
737 assert(ret == 0);
738 ret = bt_ctf_field_type_integer_set_encoding(root_action_special, BT_CTF_STRING_ENCODING_NONE);
739 assert(ret == 0);
740 ret = bt_ctf_field_type_set_byte_order(root_action_special, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
741 assert(ret == 0);
742 ret = bt_ctf_field_type_set_alignment(root_action_special, 1);
743 assert(ret == 0);
744 ret = bt_ctf_field_type_structure_add_field(root_action, root_action_special, "special");
745 assert(ret == 0);
746 root_action_lucky_elem = bt_ctf_field_type_string_create();
747 assert(root_action_lucky_elem);
748 ret = bt_ctf_field_type_string_set_encoding(root_action_lucky_elem, BT_CTF_STRING_ENCODING_UTF8);
749 assert(ret == 0);
750 root_action_lucky = bt_ctf_field_type_sequence_create(root_action_lucky_elem, "stream.packet.context.placid");
751 assert(root_action_lucky);
752 ret = bt_ctf_field_type_structure_add_field(root_action, root_action_lucky, "lucky");
753 assert(ret == 0);
754 root_action_dream = bt_ctf_field_type_string_create();
755 assert(root_action_dream);
756 ret = bt_ctf_field_type_string_set_encoding(root_action_dream, BT_CTF_STRING_ENCODING_UTF8);
757 assert(ret == 0);
758 ret = bt_ctf_field_type_structure_add_field(root_action, root_action_dream, "dream");
759 assert(ret == 0);
760 root_action_grandiose_elem = bt_ctf_field_type_integer_create(3);
761 assert(root_action_grandiose_elem);
762 ret = bt_ctf_field_type_integer_set_signed(root_action_grandiose_elem, 0);
763 assert(ret == 0);
764 ret = bt_ctf_field_type_integer_set_base(root_action_grandiose_elem, 10);
765 assert(ret == 0);
766 ret = bt_ctf_field_type_integer_set_encoding(root_action_grandiose_elem, BT_CTF_STRING_ENCODING_NONE);
767 assert(ret == 0);
768 ret = bt_ctf_field_type_set_byte_order(root_action_grandiose_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
769 assert(ret == 0);
770 ret = bt_ctf_field_type_set_alignment(root_action_grandiose_elem, 1);
771 assert(ret == 0);
772 root_action_grandiose = bt_ctf_field_type_sequence_create(root_action_grandiose_elem, "trace.packet.header.serious");
773 assert(root_action_grandiose);
774 ret = bt_ctf_field_type_structure_add_field(root_action, root_action_grandiose, "grandiose");
775 assert(ret == 0);
776 ret = bt_ctf_field_type_structure_add_field(root, root_action, "action");
777 assert(ret == 0);
778 root_stiff_elem = bt_ctf_field_type_string_create();
779 assert(root_stiff_elem);
780 ret = bt_ctf_field_type_string_set_encoding(root_stiff_elem, BT_CTF_STRING_ENCODING_UTF8);
781 assert(ret == 0);
782 root_stiff = bt_ctf_field_type_sequence_create(root_stiff_elem, "clover.whole.RED");
783 assert(root_stiff);
784 ret = bt_ctf_field_type_structure_add_field(root, root_stiff, "stiff");
785 assert(ret == 0);
786 root_fruit = bt_ctf_field_type_structure_create();
787 assert(root_fruit);
788 ret = bt_ctf_field_type_set_alignment(root_fruit, 1);
789 assert(ret == 0);
790 root_fruit_apple_elem = bt_ctf_field_type_integer_create(5);
791 assert(root_fruit_apple_elem);
792 ret = bt_ctf_field_type_integer_set_signed(root_fruit_apple_elem, 0);
793 assert(ret == 0);
794 ret = bt_ctf_field_type_integer_set_base(root_fruit_apple_elem, 10);
795 assert(ret == 0);
796 ret = bt_ctf_field_type_integer_set_encoding(root_fruit_apple_elem, BT_CTF_STRING_ENCODING_NONE);
797 assert(ret == 0);
798 ret = bt_ctf_field_type_set_byte_order(root_fruit_apple_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
799 assert(ret == 0);
800 ret = bt_ctf_field_type_set_alignment(root_fruit_apple_elem, 1);
801 assert(ret == 0);
802 root_fruit_apple = bt_ctf_field_type_sequence_create(root_fruit_apple_elem, "action.special");
803 assert(root_fruit_apple);
804 ret = bt_ctf_field_type_structure_add_field(root_fruit, root_fruit_apple, "apple");
805 assert(ret == 0);
806 ret = bt_ctf_field_type_structure_add_field(root, root_fruit, "fruit");
807 assert(ret == 0);
808
809 BT_PUT(root_id);
810 BT_PUT(root_timestamp);
811 BT_PUT(root_action);
812 BT_PUT(root_action_special);
813 BT_PUT(root_action_lucky);
814 BT_PUT(root_action_lucky_elem);
815 BT_PUT(root_action_dream);
816 BT_PUT(root_action_grandiose);
817 BT_PUT(root_action_grandiose_elem);
818 BT_PUT(root_stiff);
819 BT_PUT(root_stiff_elem);
820 BT_PUT(root_fruit);
821 BT_PUT(root_fruit_apple);
822 BT_PUT(root_fruit_apple_elem);
823
824 return root;
825 }
826
827 static
828 struct bt_ctf_field_type *get_good_stream_event_context_type(void)
829 {
830 /*
831 Generated by bt-ctfirtg using the following input:
832
833 class: struct
834 fields:
835 face:
836 class: struct
837 fields:
838 branch:
839 class: array
840 length: serious
841 element-type:
842 class: string
843 income:
844 class: array
845 length: magic
846 element-type:
847 class: string
848 magic:
849 class: int
850 size: 23
851 lucky:
852 class: array
853 length: magic
854 element-type:
855 class: string
856 cats:
857 class: int
858 size: 5
859 dream:
860 class: array
861 length: stream.packet.context.placid
862 element-type:
863 class: array
864 length: trace.packet.header.iron.dust
865 element-type:
866 class: array
867 length: stream.event.context.face.magic
868 element-type:
869 class: string
870 stream_id:
871 class: int
872 size: 9
873
874 */
875
876 struct bt_ctf_field_type *root = NULL;
877 struct bt_ctf_field_type *root_face = NULL;
878 struct bt_ctf_field_type *root_face_branch = NULL;
879 struct bt_ctf_field_type *root_face_branch_elem = NULL;
880 struct bt_ctf_field_type *root_face_income = NULL;
881 struct bt_ctf_field_type *root_face_income_elem = NULL;
882 struct bt_ctf_field_type *root_face_magic = NULL;
883 struct bt_ctf_field_type *root_face_lucky = NULL;
884 struct bt_ctf_field_type *root_face_lucky_elem = NULL;
885 struct bt_ctf_field_type *root_cats = NULL;
886 struct bt_ctf_field_type *root_dream = NULL;
887 struct bt_ctf_field_type *root_dream_elem = NULL;
888 struct bt_ctf_field_type *root_dream_elem_elem = NULL;
889 struct bt_ctf_field_type *root_dream_elem_elem_elem = NULL;
890 struct bt_ctf_field_type *root_stream_id = NULL;
891
892 int ret;
893 root = bt_ctf_field_type_structure_create();
894 assert(root);
895 ret = bt_ctf_field_type_set_alignment(root, 8);
896 assert(ret == 0);
897 root_face = bt_ctf_field_type_structure_create();
898 assert(root_face);
899 ret = bt_ctf_field_type_set_alignment(root_face, 8);
900 assert(ret == 0);
901 root_face_branch_elem = bt_ctf_field_type_string_create();
902 assert(root_face_branch_elem);
903 ret = bt_ctf_field_type_string_set_encoding(root_face_branch_elem, BT_CTF_STRING_ENCODING_UTF8);
904 assert(ret == 0);
905 root_face_branch = bt_ctf_field_type_sequence_create(root_face_branch_elem, "serious");
906 assert(root_face_branch);
907 ret = bt_ctf_field_type_structure_add_field(root_face, root_face_branch, "branch");
908 assert(ret == 0);
909 root_face_income_elem = bt_ctf_field_type_string_create();
910 assert(root_face_income_elem);
911 ret = bt_ctf_field_type_string_set_encoding(root_face_income_elem, BT_CTF_STRING_ENCODING_UTF8);
912 assert(ret == 0);
913 root_face_income = bt_ctf_field_type_sequence_create(root_face_income_elem, "magic");
914 assert(root_face_income);
915 ret = bt_ctf_field_type_structure_add_field(root_face, root_face_income, "income");
916 assert(ret == 0);
917 root_face_magic = bt_ctf_field_type_integer_create(23);
918 assert(root_face_magic);
919 ret = bt_ctf_field_type_integer_set_signed(root_face_magic, 0);
920 assert(ret == 0);
921 ret = bt_ctf_field_type_integer_set_base(root_face_magic, 10);
922 assert(ret == 0);
923 ret = bt_ctf_field_type_integer_set_encoding(root_face_magic, BT_CTF_STRING_ENCODING_NONE);
924 assert(ret == 0);
925 ret = bt_ctf_field_type_set_byte_order(root_face_magic, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
926 assert(ret == 0);
927 ret = bt_ctf_field_type_set_alignment(root_face_magic, 1);
928 assert(ret == 0);
929 ret = bt_ctf_field_type_structure_add_field(root_face, root_face_magic, "magic");
930 assert(ret == 0);
931 root_face_lucky_elem = bt_ctf_field_type_string_create();
932 assert(root_face_lucky_elem);
933 ret = bt_ctf_field_type_string_set_encoding(root_face_lucky_elem, BT_CTF_STRING_ENCODING_UTF8);
934 assert(ret == 0);
935 root_face_lucky = bt_ctf_field_type_sequence_create(root_face_lucky_elem, "magic");
936 assert(root_face_lucky);
937 ret = bt_ctf_field_type_structure_add_field(root_face, root_face_lucky, "lucky");
938 assert(ret == 0);
939 ret = bt_ctf_field_type_structure_add_field(root, root_face, "face");
940 assert(ret == 0);
941 root_cats = bt_ctf_field_type_integer_create(5);
942 assert(root_cats);
943 ret = bt_ctf_field_type_integer_set_signed(root_cats, 0);
944 assert(ret == 0);
945 ret = bt_ctf_field_type_integer_set_base(root_cats, 10);
946 assert(ret == 0);
947 ret = bt_ctf_field_type_integer_set_encoding(root_cats, BT_CTF_STRING_ENCODING_NONE);
948 assert(ret == 0);
949 ret = bt_ctf_field_type_set_byte_order(root_cats, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
950 assert(ret == 0);
951 ret = bt_ctf_field_type_set_alignment(root_cats, 1);
952 assert(ret == 0);
953 ret = bt_ctf_field_type_structure_add_field(root, root_cats, "cats");
954 assert(ret == 0);
955 root_dream_elem_elem_elem = bt_ctf_field_type_string_create();
956 assert(root_dream_elem_elem_elem);
957 ret = bt_ctf_field_type_string_set_encoding(root_dream_elem_elem_elem, BT_CTF_STRING_ENCODING_UTF8);
958 assert(ret == 0);
959 root_dream_elem_elem = bt_ctf_field_type_sequence_create(root_dream_elem_elem_elem, "stream.event.context.face.magic");
960 assert(root_dream_elem_elem);
961 root_dream_elem = bt_ctf_field_type_sequence_create(root_dream_elem_elem, "trace.packet.header.iron.dust");
962 assert(root_dream_elem);
963 root_dream = bt_ctf_field_type_sequence_create(root_dream_elem, "stream.packet.context.placid");
964 assert(root_dream);
965 ret = bt_ctf_field_type_structure_add_field(root, root_dream, "dream");
966 assert(ret == 0);
967 root_stream_id = bt_ctf_field_type_integer_create(9);
968 assert(root_stream_id);
969 ret = bt_ctf_field_type_integer_set_signed(root_stream_id, 0);
970 assert(ret == 0);
971 ret = bt_ctf_field_type_integer_set_base(root_stream_id, 10);
972 assert(ret == 0);
973 ret = bt_ctf_field_type_integer_set_encoding(root_stream_id, BT_CTF_STRING_ENCODING_NONE);
974 assert(ret == 0);
975 ret = bt_ctf_field_type_set_byte_order(root_stream_id, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
976 assert(ret == 0);
977 ret = bt_ctf_field_type_set_alignment(root_stream_id, 1);
978 assert(ret == 0);
979 ret = bt_ctf_field_type_structure_add_field(root, root_stream_id, "stream_id");
980 assert(ret == 0);
981
982 BT_PUT(root_face);
983 BT_PUT(root_face_branch);
984 BT_PUT(root_face_branch_elem);
985 BT_PUT(root_face_income);
986 BT_PUT(root_face_income_elem);
987 BT_PUT(root_face_magic);
988 BT_PUT(root_face_lucky);
989 BT_PUT(root_face_lucky_elem);
990 BT_PUT(root_cats);
991 BT_PUT(root_dream);
992 BT_PUT(root_dream_elem);
993 BT_PUT(root_dream_elem_elem);
994 BT_PUT(root_dream_elem_elem_elem);
995 BT_PUT(root_stream_id);
996
997 return root;
998 }
999
1000 static
1001 struct bt_ctf_field_type *get_good_event_context_type(void)
1002 {
1003 /*
1004 Generated by bt-ctfirtg using the following input:
1005
1006 class: struct
1007 fields:
1008 film:
1009 class: int
1010 size: 19
1011 berry:
1012 class: struct
1013 fields:
1014 pine:
1015 class: array
1016 length: stream_id
1017 element-type:
1018 class: string
1019 porter:
1020 class: array
1021 length: face.magic
1022 element-type:
1023 class: string
1024 mice:
1025 class: array
1026 length: action.special
1027 element-type:
1028 class: string
1029 third:
1030 class: int
1031 size: 18
1032 guard:
1033 class: array
1034 length: clover.oval
1035 element-type:
1036 class: string
1037 one:
1038 class: array
1039 length: iron.fire.word
1040 element-type:
1041 class: string
1042 cats:
1043 class: int
1044 size: 55
1045 loud:
1046 class: struct
1047 fields:
1048 toys:
1049 class: array
1050 length: trace.packet.header.iron.fire.word
1051 element-type:
1052 class: string
1053 spoon:
1054 class: array
1055 length: stream.packet.context.clover.oval
1056 element-type:
1057 class: string
1058 turkey:
1059 class: array
1060 length: stream.event.header.action.special
1061 element-type:
1062 class: string
1063 inform:
1064 class: array
1065 length: stream.event.context.face.magic
1066 element-type:
1067 class: string
1068 odd:
1069 class: array
1070 length: berry.third
1071 element-type:
1072 class: string
1073 amuck:
1074 class: array
1075 length: event.context.film
1076 element-type:
1077 class: string
1078
1079 */
1080
1081 struct bt_ctf_field_type *root = NULL;
1082 struct bt_ctf_field_type *root_film = NULL;
1083 struct bt_ctf_field_type *root_berry = NULL;
1084 struct bt_ctf_field_type *root_berry_pine = NULL;
1085 struct bt_ctf_field_type *root_berry_pine_elem = NULL;
1086 struct bt_ctf_field_type *root_berry_porter = NULL;
1087 struct bt_ctf_field_type *root_berry_porter_elem = NULL;
1088 struct bt_ctf_field_type *root_berry_mice = NULL;
1089 struct bt_ctf_field_type *root_berry_mice_elem = NULL;
1090 struct bt_ctf_field_type *root_berry_third = NULL;
1091 struct bt_ctf_field_type *root_berry_guard = NULL;
1092 struct bt_ctf_field_type *root_berry_guard_elem = NULL;
1093 struct bt_ctf_field_type *root_berry_one = NULL;
1094 struct bt_ctf_field_type *root_berry_one_elem = NULL;
1095 struct bt_ctf_field_type *root_cats = NULL;
1096 struct bt_ctf_field_type *root_loud = NULL;
1097 struct bt_ctf_field_type *root_loud_toys = NULL;
1098 struct bt_ctf_field_type *root_loud_toys_elem = NULL;
1099 struct bt_ctf_field_type *root_loud_spoon = NULL;
1100 struct bt_ctf_field_type *root_loud_spoon_elem = NULL;
1101 struct bt_ctf_field_type *root_loud_turkey = NULL;
1102 struct bt_ctf_field_type *root_loud_turkey_elem = NULL;
1103 struct bt_ctf_field_type *root_loud_inform = NULL;
1104 struct bt_ctf_field_type *root_loud_inform_elem = NULL;
1105 struct bt_ctf_field_type *root_loud_odd = NULL;
1106 struct bt_ctf_field_type *root_loud_odd_elem = NULL;
1107 struct bt_ctf_field_type *root_loud_amuck = NULL;
1108 struct bt_ctf_field_type *root_loud_amuck_elem = NULL;
1109
1110 int ret;
1111 root = bt_ctf_field_type_structure_create();
1112 assert(root);
1113 ret = bt_ctf_field_type_set_alignment(root, 8);
1114 assert(ret == 0);
1115 root_film = bt_ctf_field_type_integer_create(19);
1116 assert(root_film);
1117 ret = bt_ctf_field_type_integer_set_signed(root_film, 0);
1118 assert(ret == 0);
1119 ret = bt_ctf_field_type_integer_set_base(root_film, 10);
1120 assert(ret == 0);
1121 ret = bt_ctf_field_type_integer_set_encoding(root_film, BT_CTF_STRING_ENCODING_NONE);
1122 assert(ret == 0);
1123 ret = bt_ctf_field_type_set_byte_order(root_film, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
1124 assert(ret == 0);
1125 ret = bt_ctf_field_type_set_alignment(root_film, 1);
1126 assert(ret == 0);
1127 ret = bt_ctf_field_type_structure_add_field(root, root_film, "film");
1128 assert(ret == 0);
1129 root_berry = bt_ctf_field_type_structure_create();
1130 assert(root_berry);
1131 ret = bt_ctf_field_type_set_alignment(root_berry, 8);
1132 assert(ret == 0);
1133 root_berry_pine_elem = bt_ctf_field_type_string_create();
1134 assert(root_berry_pine_elem);
1135 ret = bt_ctf_field_type_string_set_encoding(root_berry_pine_elem, BT_CTF_STRING_ENCODING_UTF8);
1136 assert(ret == 0);
1137 root_berry_pine = bt_ctf_field_type_sequence_create(root_berry_pine_elem, "stream_id");
1138 assert(root_berry_pine);
1139 ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_pine, "pine");
1140 assert(ret == 0);
1141 root_berry_porter_elem = bt_ctf_field_type_string_create();
1142 assert(root_berry_porter_elem);
1143 ret = bt_ctf_field_type_string_set_encoding(root_berry_porter_elem, BT_CTF_STRING_ENCODING_UTF8);
1144 assert(ret == 0);
1145 root_berry_porter = bt_ctf_field_type_sequence_create(root_berry_porter_elem, "face.magic");
1146 assert(root_berry_porter);
1147 ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_porter, "porter");
1148 assert(ret == 0);
1149 root_berry_mice_elem = bt_ctf_field_type_string_create();
1150 assert(root_berry_mice_elem);
1151 ret = bt_ctf_field_type_string_set_encoding(root_berry_mice_elem, BT_CTF_STRING_ENCODING_UTF8);
1152 assert(ret == 0);
1153 root_berry_mice = bt_ctf_field_type_sequence_create(root_berry_mice_elem, "action.special");
1154 assert(root_berry_mice);
1155 ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_mice, "mice");
1156 assert(ret == 0);
1157 root_berry_third = bt_ctf_field_type_integer_create(18);
1158 assert(root_berry_third);
1159 ret = bt_ctf_field_type_integer_set_signed(root_berry_third, 0);
1160 assert(ret == 0);
1161 ret = bt_ctf_field_type_integer_set_base(root_berry_third, 10);
1162 assert(ret == 0);
1163 ret = bt_ctf_field_type_integer_set_encoding(root_berry_third, BT_CTF_STRING_ENCODING_NONE);
1164 assert(ret == 0);
1165 ret = bt_ctf_field_type_set_byte_order(root_berry_third, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
1166 assert(ret == 0);
1167 ret = bt_ctf_field_type_set_alignment(root_berry_third, 1);
1168 assert(ret == 0);
1169 ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_third, "third");
1170 assert(ret == 0);
1171 root_berry_guard_elem = bt_ctf_field_type_string_create();
1172 assert(root_berry_guard_elem);
1173 ret = bt_ctf_field_type_string_set_encoding(root_berry_guard_elem, BT_CTF_STRING_ENCODING_UTF8);
1174 assert(ret == 0);
1175 root_berry_guard = bt_ctf_field_type_sequence_create(root_berry_guard_elem, "clover.oval");
1176 assert(root_berry_guard);
1177 ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_guard, "guard");
1178 assert(ret == 0);
1179 root_berry_one_elem = bt_ctf_field_type_string_create();
1180 assert(root_berry_one_elem);
1181 ret = bt_ctf_field_type_string_set_encoding(root_berry_one_elem, BT_CTF_STRING_ENCODING_UTF8);
1182 assert(ret == 0);
1183 root_berry_one = bt_ctf_field_type_sequence_create(root_berry_one_elem, "iron.fire.word");
1184 assert(root_berry_one);
1185 ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_one, "one");
1186 assert(ret == 0);
1187 ret = bt_ctf_field_type_structure_add_field(root, root_berry, "berry");
1188 assert(ret == 0);
1189 root_cats = bt_ctf_field_type_integer_create(55);
1190 assert(root_cats);
1191 ret = bt_ctf_field_type_integer_set_signed(root_cats, 0);
1192 assert(ret == 0);
1193 ret = bt_ctf_field_type_integer_set_base(root_cats, 10);
1194 assert(ret == 0);
1195 ret = bt_ctf_field_type_integer_set_encoding(root_cats, BT_CTF_STRING_ENCODING_NONE);
1196 assert(ret == 0);
1197 ret = bt_ctf_field_type_set_byte_order(root_cats, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
1198 assert(ret == 0);
1199 ret = bt_ctf_field_type_set_alignment(root_cats, 1);
1200 assert(ret == 0);
1201 ret = bt_ctf_field_type_structure_add_field(root, root_cats, "cats");
1202 assert(ret == 0);
1203 root_loud = bt_ctf_field_type_structure_create();
1204 assert(root_loud);
1205 ret = bt_ctf_field_type_set_alignment(root_loud, 8);
1206 assert(ret == 0);
1207 root_loud_toys_elem = bt_ctf_field_type_string_create();
1208 assert(root_loud_toys_elem);
1209 ret = bt_ctf_field_type_string_set_encoding(root_loud_toys_elem, BT_CTF_STRING_ENCODING_UTF8);
1210 assert(ret == 0);
1211 root_loud_toys = bt_ctf_field_type_sequence_create(root_loud_toys_elem, "trace.packet.header.iron.fire.word");
1212 assert(root_loud_toys);
1213 ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_toys, "toys");
1214 assert(ret == 0);
1215 root_loud_spoon_elem = bt_ctf_field_type_string_create();
1216 assert(root_loud_spoon_elem);
1217 ret = bt_ctf_field_type_string_set_encoding(root_loud_spoon_elem, BT_CTF_STRING_ENCODING_UTF8);
1218 assert(ret == 0);
1219 root_loud_spoon = bt_ctf_field_type_sequence_create(root_loud_spoon_elem, "stream.packet.context.clover.oval");
1220 assert(root_loud_spoon);
1221 ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_spoon, "spoon");
1222 assert(ret == 0);
1223 root_loud_turkey_elem = bt_ctf_field_type_string_create();
1224 assert(root_loud_turkey_elem);
1225 ret = bt_ctf_field_type_string_set_encoding(root_loud_turkey_elem, BT_CTF_STRING_ENCODING_UTF8);
1226 assert(ret == 0);
1227 root_loud_turkey = bt_ctf_field_type_sequence_create(root_loud_turkey_elem, "stream.event.header.action.special");
1228 assert(root_loud_turkey);
1229 ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_turkey, "turkey");
1230 assert(ret == 0);
1231 root_loud_inform_elem = bt_ctf_field_type_string_create();
1232 assert(root_loud_inform_elem);
1233 ret = bt_ctf_field_type_string_set_encoding(root_loud_inform_elem, BT_CTF_STRING_ENCODING_UTF8);
1234 assert(ret == 0);
1235 root_loud_inform = bt_ctf_field_type_sequence_create(root_loud_inform_elem, "stream.event.context.face.magic");
1236 assert(root_loud_inform);
1237 ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_inform, "inform");
1238 assert(ret == 0);
1239 root_loud_odd_elem = bt_ctf_field_type_string_create();
1240 assert(root_loud_odd_elem);
1241 ret = bt_ctf_field_type_string_set_encoding(root_loud_odd_elem, BT_CTF_STRING_ENCODING_UTF8);
1242 assert(ret == 0);
1243 root_loud_odd = bt_ctf_field_type_sequence_create(root_loud_odd_elem, "berry.third");
1244 assert(root_loud_odd);
1245 ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_odd, "odd");
1246 assert(ret == 0);
1247 root_loud_amuck_elem = bt_ctf_field_type_string_create();
1248 assert(root_loud_amuck_elem);
1249 ret = bt_ctf_field_type_string_set_encoding(root_loud_amuck_elem, BT_CTF_STRING_ENCODING_UTF8);
1250 assert(ret == 0);
1251 root_loud_amuck = bt_ctf_field_type_sequence_create(root_loud_amuck_elem, "event.context.film");
1252 assert(root_loud_amuck);
1253 ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_amuck, "amuck");
1254 assert(ret == 0);
1255 ret = bt_ctf_field_type_structure_add_field(root, root_loud, "loud");
1256 assert(ret == 0);
1257
1258 BT_PUT(root_film);
1259 BT_PUT(root_berry);
1260 BT_PUT(root_berry_pine);
1261 BT_PUT(root_berry_pine_elem);
1262 BT_PUT(root_berry_porter);
1263 BT_PUT(root_berry_porter_elem);
1264 BT_PUT(root_berry_mice);
1265 BT_PUT(root_berry_mice_elem);
1266 BT_PUT(root_berry_third);
1267 BT_PUT(root_berry_guard);
1268 BT_PUT(root_berry_guard_elem);
1269 BT_PUT(root_berry_one);
1270 BT_PUT(root_berry_one_elem);
1271 BT_PUT(root_cats);
1272 BT_PUT(root_loud);
1273 BT_PUT(root_loud_toys);
1274 BT_PUT(root_loud_toys_elem);
1275 BT_PUT(root_loud_spoon);
1276 BT_PUT(root_loud_spoon_elem);
1277 BT_PUT(root_loud_turkey);
1278 BT_PUT(root_loud_turkey_elem);
1279 BT_PUT(root_loud_inform);
1280 BT_PUT(root_loud_inform_elem);
1281 BT_PUT(root_loud_odd);
1282 BT_PUT(root_loud_odd_elem);
1283 BT_PUT(root_loud_amuck);
1284 BT_PUT(root_loud_amuck_elem);
1285
1286 return root;
1287 }
1288
1289 static
1290 struct bt_ctf_field_type *get_good_event_payload_type(void)
1291 {
1292 /*
1293 Generated by bt-ctfirtg using the following input:
1294
1295 class: struct
1296 fields:
1297 splendid:
1298 class: int
1299 size: 12
1300 relative:
1301 class: struct
1302 fields:
1303 equal:
1304 class: array
1305 length: splendid
1306 element-type:
1307 class: string
1308 amuck:
1309 class: array
1310 length: cats
1311 element-type:
1312 class: string
1313 push:
1314 class: array
1315 length: berry.third
1316 element-type:
1317 class: string
1318 brick:
1319 class: array
1320 length: face.magic
1321 element-type:
1322 class: string
1323 amuck:
1324 class: array
1325 length: id
1326 element-type:
1327 class: string
1328 crush:
1329 class: array
1330 length: serious
1331 element-type:
1332 class: string
1333 canvas:
1334 class: array
1335 length: iron.dust
1336 element-type:
1337 class: string
1338 absolute:
1339 class: struct
1340 fields:
1341 equal:
1342 class: array
1343 length: event.fields.splendid
1344 element-type:
1345 class: string
1346 amuck:
1347 class: array
1348 length: event.context.cats
1349 element-type:
1350 class: string
1351 push:
1352 class: array
1353 length: event.context.berry.third
1354 element-type:
1355 class: string
1356 brick:
1357 class: array
1358 length: stream.event.context.face.magic
1359 element-type:
1360 class: string
1361 amuck:
1362 class: array
1363 length: stream.event.header.id
1364 element-type:
1365 class: string
1366 crush:
1367 class: array
1368 length: stream.packet.context.serious
1369 element-type:
1370 class: string
1371 canvas:
1372 class: array
1373 length: trace.packet.header.iron.dust
1374 element-type:
1375 class: string
1376
1377 */
1378
1379 struct bt_ctf_field_type *root = NULL;
1380 struct bt_ctf_field_type *root_splendid = NULL;
1381 struct bt_ctf_field_type *root_relative = NULL;
1382 struct bt_ctf_field_type *root_relative_equal = NULL;
1383 struct bt_ctf_field_type *root_relative_equal_elem = NULL;
1384 struct bt_ctf_field_type *root_relative_amuck = NULL;
1385 struct bt_ctf_field_type *root_relative_amuck_elem = NULL;
1386 struct bt_ctf_field_type *root_relative_push = NULL;
1387 struct bt_ctf_field_type *root_relative_push_elem = NULL;
1388 struct bt_ctf_field_type *root_relative_brick = NULL;
1389 struct bt_ctf_field_type *root_relative_brick_elem = NULL;
1390 struct bt_ctf_field_type *root_relative_crush = NULL;
1391 struct bt_ctf_field_type *root_relative_crush_elem = NULL;
1392 struct bt_ctf_field_type *root_relative_canvas = NULL;
1393 struct bt_ctf_field_type *root_relative_canvas_elem = NULL;
1394 struct bt_ctf_field_type *root_absolute = NULL;
1395 struct bt_ctf_field_type *root_absolute_equal = NULL;
1396 struct bt_ctf_field_type *root_absolute_equal_elem = NULL;
1397 struct bt_ctf_field_type *root_absolute_amuck = NULL;
1398 struct bt_ctf_field_type *root_absolute_amuck_elem = NULL;
1399 struct bt_ctf_field_type *root_absolute_push = NULL;
1400 struct bt_ctf_field_type *root_absolute_push_elem = NULL;
1401 struct bt_ctf_field_type *root_absolute_brick = NULL;
1402 struct bt_ctf_field_type *root_absolute_brick_elem = NULL;
1403 struct bt_ctf_field_type *root_absolute_crush = NULL;
1404 struct bt_ctf_field_type *root_absolute_crush_elem = NULL;
1405 struct bt_ctf_field_type *root_absolute_canvas = NULL;
1406 struct bt_ctf_field_type *root_absolute_canvas_elem = NULL;
1407
1408 int ret;
1409 root = bt_ctf_field_type_structure_create();
1410 assert(root);
1411 ret = bt_ctf_field_type_set_alignment(root, 8);
1412 assert(ret == 0);
1413 root_splendid = bt_ctf_field_type_integer_create(12);
1414 assert(root_splendid);
1415 ret = bt_ctf_field_type_integer_set_signed(root_splendid, 0);
1416 assert(ret == 0);
1417 ret = bt_ctf_field_type_integer_set_base(root_splendid, 10);
1418 assert(ret == 0);
1419 ret = bt_ctf_field_type_integer_set_encoding(root_splendid, BT_CTF_STRING_ENCODING_NONE);
1420 assert(ret == 0);
1421 ret = bt_ctf_field_type_set_byte_order(root_splendid, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
1422 assert(ret == 0);
1423 ret = bt_ctf_field_type_set_alignment(root_splendid, 1);
1424 assert(ret == 0);
1425 ret = bt_ctf_field_type_structure_add_field(root, root_splendid, "splendid");
1426 assert(ret == 0);
1427 root_relative = bt_ctf_field_type_structure_create();
1428 assert(root_relative);
1429 ret = bt_ctf_field_type_set_alignment(root_relative, 8);
1430 assert(ret == 0);
1431 root_relative_equal_elem = bt_ctf_field_type_string_create();
1432 assert(root_relative_equal_elem);
1433 ret = bt_ctf_field_type_string_set_encoding(root_relative_equal_elem, BT_CTF_STRING_ENCODING_UTF8);
1434 assert(ret == 0);
1435 root_relative_equal = bt_ctf_field_type_sequence_create(root_relative_equal_elem, "splendid");
1436 assert(root_relative_equal);
1437 ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_equal, "equal");
1438 assert(ret == 0);
1439 root_relative_amuck_elem = bt_ctf_field_type_string_create();
1440 assert(root_relative_amuck_elem);
1441 ret = bt_ctf_field_type_string_set_encoding(root_relative_amuck_elem, BT_CTF_STRING_ENCODING_UTF8);
1442 assert(ret == 0);
1443 root_relative_amuck = bt_ctf_field_type_sequence_create(root_relative_amuck_elem, "id");
1444 assert(root_relative_amuck);
1445 ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_amuck, "amuck");
1446 assert(ret == 0);
1447 root_relative_push_elem = bt_ctf_field_type_string_create();
1448 assert(root_relative_push_elem);
1449 ret = bt_ctf_field_type_string_set_encoding(root_relative_push_elem, BT_CTF_STRING_ENCODING_UTF8);
1450 assert(ret == 0);
1451 root_relative_push = bt_ctf_field_type_sequence_create(root_relative_push_elem, "berry.third");
1452 assert(root_relative_push);
1453 ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_push, "push");
1454 assert(ret == 0);
1455 root_relative_brick_elem = bt_ctf_field_type_string_create();
1456 assert(root_relative_brick_elem);
1457 ret = bt_ctf_field_type_string_set_encoding(root_relative_brick_elem, BT_CTF_STRING_ENCODING_UTF8);
1458 assert(ret == 0);
1459 root_relative_brick = bt_ctf_field_type_sequence_create(root_relative_brick_elem, "face.magic");
1460 assert(root_relative_brick);
1461 ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_brick, "brick");
1462 assert(ret == 0);
1463 root_relative_crush_elem = bt_ctf_field_type_string_create();
1464 assert(root_relative_crush_elem);
1465 ret = bt_ctf_field_type_string_set_encoding(root_relative_crush_elem, BT_CTF_STRING_ENCODING_UTF8);
1466 assert(ret == 0);
1467 root_relative_crush = bt_ctf_field_type_sequence_create(root_relative_crush_elem, "serious");
1468 assert(root_relative_crush);
1469 ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_crush, "crush");
1470 assert(ret == 0);
1471 root_relative_canvas_elem = bt_ctf_field_type_string_create();
1472 assert(root_relative_canvas_elem);
1473 ret = bt_ctf_field_type_string_set_encoding(root_relative_canvas_elem, BT_CTF_STRING_ENCODING_UTF8);
1474 assert(ret == 0);
1475 root_relative_canvas = bt_ctf_field_type_sequence_create(root_relative_canvas_elem, "iron.dust");
1476 assert(root_relative_canvas);
1477 ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_canvas, "canvas");
1478 assert(ret == 0);
1479 ret = bt_ctf_field_type_structure_add_field(root, root_relative, "relative");
1480 assert(ret == 0);
1481 root_absolute = bt_ctf_field_type_structure_create();
1482 assert(root_absolute);
1483 ret = bt_ctf_field_type_set_alignment(root_absolute, 8);
1484 assert(ret == 0);
1485 root_absolute_equal_elem = bt_ctf_field_type_string_create();
1486 assert(root_absolute_equal_elem);
1487 ret = bt_ctf_field_type_string_set_encoding(root_absolute_equal_elem, BT_CTF_STRING_ENCODING_UTF8);
1488 assert(ret == 0);
1489 root_absolute_equal = bt_ctf_field_type_sequence_create(root_absolute_equal_elem, "event.fields.splendid");
1490 assert(root_absolute_equal);
1491 ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_equal, "equal");
1492 assert(ret == 0);
1493 root_absolute_amuck_elem = bt_ctf_field_type_string_create();
1494 assert(root_absolute_amuck_elem);
1495 ret = bt_ctf_field_type_string_set_encoding(root_absolute_amuck_elem, BT_CTF_STRING_ENCODING_UTF8);
1496 assert(ret == 0);
1497 root_absolute_amuck = bt_ctf_field_type_sequence_create(root_absolute_amuck_elem, "stream.event.header.id");
1498 assert(root_absolute_amuck);
1499 ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_amuck, "amuck");
1500 assert(ret == 0);
1501 root_absolute_push_elem = bt_ctf_field_type_string_create();
1502 assert(root_absolute_push_elem);
1503 ret = bt_ctf_field_type_string_set_encoding(root_absolute_push_elem, BT_CTF_STRING_ENCODING_UTF8);
1504 assert(ret == 0);
1505 root_absolute_push = bt_ctf_field_type_sequence_create(root_absolute_push_elem, "event.context.berry.third");
1506 assert(root_absolute_push);
1507 ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_push, "push");
1508 assert(ret == 0);
1509 root_absolute_brick_elem = bt_ctf_field_type_string_create();
1510 assert(root_absolute_brick_elem);
1511 ret = bt_ctf_field_type_string_set_encoding(root_absolute_brick_elem, BT_CTF_STRING_ENCODING_UTF8);
1512 assert(ret == 0);
1513 root_absolute_brick = bt_ctf_field_type_sequence_create(root_absolute_brick_elem, "stream.event.context.face.magic");
1514 assert(root_absolute_brick);
1515 ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_brick, "brick");
1516 assert(ret == 0);
1517 root_absolute_crush_elem = bt_ctf_field_type_string_create();
1518 assert(root_absolute_crush_elem);
1519 ret = bt_ctf_field_type_string_set_encoding(root_absolute_crush_elem, BT_CTF_STRING_ENCODING_UTF8);
1520 assert(ret == 0);
1521 root_absolute_crush = bt_ctf_field_type_sequence_create(root_absolute_crush_elem, "stream.packet.context.serious");
1522 assert(root_absolute_crush);
1523 ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_crush, "crush");
1524 assert(ret == 0);
1525 root_absolute_canvas_elem = bt_ctf_field_type_string_create();
1526 assert(root_absolute_canvas_elem);
1527 ret = bt_ctf_field_type_string_set_encoding(root_absolute_canvas_elem, BT_CTF_STRING_ENCODING_UTF8);
1528 assert(ret == 0);
1529 root_absolute_canvas = bt_ctf_field_type_sequence_create(root_absolute_canvas_elem, "trace.packet.header.iron.dust");
1530 assert(root_absolute_canvas);
1531 ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_canvas, "canvas");
1532 assert(ret == 0);
1533 ret = bt_ctf_field_type_structure_add_field(root, root_absolute, "absolute");
1534 assert(ret == 0);
1535
1536 BT_PUT(root_splendid);
1537 BT_PUT(root_relative);
1538 BT_PUT(root_relative_equal);
1539 BT_PUT(root_relative_equal_elem);
1540 BT_PUT(root_relative_amuck);
1541 BT_PUT(root_relative_amuck_elem);
1542 BT_PUT(root_relative_push);
1543 BT_PUT(root_relative_push_elem);
1544 BT_PUT(root_relative_brick);
1545 BT_PUT(root_relative_brick_elem);
1546 BT_PUT(root_relative_crush);
1547 BT_PUT(root_relative_crush_elem);
1548 BT_PUT(root_relative_canvas);
1549 BT_PUT(root_relative_canvas_elem);
1550 BT_PUT(root_absolute);
1551 BT_PUT(root_absolute_equal);
1552 BT_PUT(root_absolute_equal_elem);
1553 BT_PUT(root_absolute_amuck);
1554 BT_PUT(root_absolute_amuck_elem);
1555 BT_PUT(root_absolute_push);
1556 BT_PUT(root_absolute_push_elem);
1557 BT_PUT(root_absolute_brick);
1558 BT_PUT(root_absolute_brick_elem);
1559 BT_PUT(root_absolute_crush);
1560 BT_PUT(root_absolute_crush_elem);
1561 BT_PUT(root_absolute_canvas);
1562 BT_PUT(root_absolute_canvas_elem);
1563
1564 return root;
1565 }
1566
1567 static
1568 struct bt_ctf_field_type *get_child_ft(struct bt_ctf_field_type *parent_ft,
1569 const char *name)
1570 {
1571 struct bt_ctf_field_type *ft = NULL;
1572
1573 switch (bt_ctf_field_type_get_type_id(parent_ft)) {
1574 case CTF_TYPE_STRUCT:
1575 ft = bt_ctf_field_type_structure_get_field_type_by_name(
1576 parent_ft, name);
1577 break;
1578
1579 case CTF_TYPE_VARIANT:
1580 ft = bt_ctf_field_type_variant_get_field_type_by_name(
1581 parent_ft, name);
1582 break;
1583
1584 case CTF_TYPE_ARRAY:
1585 ft = bt_ctf_field_type_array_get_element_type(parent_ft);
1586 break;
1587
1588 case CTF_TYPE_SEQUENCE:
1589 ft = bt_ctf_field_type_sequence_get_element_type(parent_ft);
1590 break;
1591
1592 case CTF_TYPE_ENUM:
1593 ft = bt_ctf_field_type_enumeration_get_container_type(
1594 parent_ft);
1595 break;
1596
1597 default:
1598 break;
1599 }
1600
1601 assert(ft);
1602
1603 return ft;
1604 }
1605
1606 static
1607 struct bt_ctf_field_type *get_ft(struct bt_ctf_field_type *root_ft, ...)
1608 {
1609 struct bt_ctf_field_type *child_ft = NULL;
1610 struct bt_ctf_field_type *ft = root_ft;
1611 va_list ap;
1612
1613 va_start(ap, root_ft);
1614 bt_get(ft);
1615
1616 while (true) {
1617 const char *field_name = va_arg(ap, const char *);
1618
1619 if (field_name == NULL) {
1620 break;
1621 }
1622
1623 child_ft = get_child_ft(ft, field_name);
1624
1625 if (!child_ft) {
1626 BT_PUT(ft);
1627 goto end;
1628 }
1629
1630 BT_MOVE(ft, child_ft);
1631 }
1632
1633 end:
1634 va_end(ap);
1635
1636 return ft;
1637 }
1638
1639 #define FIELD_PATH_END -2
1640
1641 static
1642 int validate_field_path(struct bt_ctf_field_type *field_type, int int_root, ...)
1643 {
1644 enum bt_ctf_scope root = int_root;
1645 int ret = 0;
1646 int len;
1647 int expected_index;
1648 int actual_index;
1649 int i = 0;
1650 struct bt_ctf_field_path *field_path = NULL;
1651 va_list ap;
1652
1653 va_start(ap, int_root);
1654 if (bt_ctf_field_type_is_sequence(field_type)) {
1655 field_path = bt_ctf_field_type_sequence_get_length_field_path(
1656 field_type);
1657 } else if (bt_ctf_field_type_is_variant(field_type)) {
1658 field_path = bt_ctf_field_type_variant_get_tag_field_path(
1659 field_type);
1660 }
1661
1662 if (!field_path) {
1663 ret = -1;
1664 goto end;
1665 }
1666
1667 if (bt_ctf_field_path_get_root_scope(field_path) != root) {
1668 ret = -1;
1669 goto end;
1670 }
1671
1672 len = bt_ctf_field_path_get_index_count(field_path);
1673
1674 while (true) {
1675 expected_index = va_arg(ap, int);
1676
1677 if (expected_index == FIELD_PATH_END) {
1678 break;
1679 }
1680
1681 if (i == len) {
1682 break;
1683 }
1684
1685 actual_index = bt_ctf_field_path_get_index(field_path, i);
1686
1687 if (actual_index == INT_MIN) {
1688 ret = -1;
1689 goto end;
1690 }
1691
1692 i++;
1693 }
1694
1695 if (i != len || expected_index != FIELD_PATH_END) {
1696 ret = -1;
1697 }
1698
1699 end:
1700 BT_PUT(field_path);
1701 va_end(ap);
1702
1703 return ret;
1704 }
1705
1706 static
1707 void validate_test_pass(struct bt_ctf_trace *trace)
1708 {
1709 struct bt_ctf_stream_class *sc;
1710 struct bt_ctf_event_class *ec;
1711 struct bt_ctf_field_type *ph;
1712 struct bt_ctf_field_type *pc;
1713 struct bt_ctf_field_type *eh;
1714 struct bt_ctf_field_type *sec;
1715 struct bt_ctf_field_type *ectx;
1716 struct bt_ctf_field_type *ep;
1717 struct bt_ctf_field_type *ft_src = NULL;
1718 struct bt_ctf_field_type *ft_target = NULL;
1719 struct bt_ctf_field_type *ft_tag = NULL;
1720
1721 sc = bt_ctf_trace_get_stream_class_by_index(trace, 0);
1722 assert(sc);
1723 ec = bt_ctf_stream_class_get_event_class_by_index(sc, 0);
1724 assert(ec);
1725
1726 ph = bt_ctf_trace_get_packet_header_type(trace);
1727 ok(ph, "Trace packet header still exists after successful validation");
1728 pc = bt_ctf_stream_class_get_packet_context_type(sc);
1729 ok(pc, "Stream packet context still exists after successful validation");
1730 eh = bt_ctf_stream_class_get_event_header_type(sc);
1731 ok(eh, "Stream event header still exists after successful validation");
1732 sec = bt_ctf_stream_class_get_event_context_type(sc);
1733 ok(sec, "Stream event context still exists after successful validation");
1734 ectx = bt_ctf_event_class_get_context_type(ec);
1735 ok(ectx, "Event context still exists after successful validation");
1736 ep = bt_ctf_event_class_get_payload_type(ec);
1737 ok(ep, "Event payload still exists after successful validation");
1738
1739 /* trace.packet.header.iron.fire.keen */
1740 ft_src = get_ft(ph, "iron", "fire", "keen", NULL);
1741 ok(!validate_field_path(ft_src, BT_CTF_SCOPE_TRACE_PACKET_HEADER,
1742 3, 3, 0, FIELD_PATH_END),
1743 "trace.packet.header.iron.fire.keen has the correct field path");
1744 BT_PUT(ft_src);
1745
1746 /* trace.packet.header.iron.fire.keen.[element] */
1747 ft_src = get_ft(ph, "iron", "fire", "keen", "", NULL);
1748 ok(!validate_field_path(ft_src,
1749 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 2, FIELD_PATH_END),
1750 "trace.packet.header.iron.fire.keen.[element] has the correct field path");
1751 ft_target = get_ft(ph, "iron", "parallel", NULL);
1752 ft_tag = bt_ctf_field_type_variant_get_tag_type(ft_src);
1753 ok(ft_tag == ft_target,
1754 "trace.packet.header.iron.fire.keen.[element] has the correct tag type");
1755 BT_PUT(ft_src);
1756 BT_PUT(ft_target);
1757 BT_PUT(ft_tag);
1758
1759 /* trace.packet.header.iron.fire.keen.[element].BLUE */
1760 ft_src = get_ft(ph, "iron", "fire", "keen", "", "BLUE", NULL);
1761 ok(!validate_field_path(ft_src,
1762 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 0, FIELD_PATH_END),
1763 "trace.packet.header.iron.fire.keen.[element].BLUE has the correct field path");
1764 BT_PUT(ft_src);
1765
1766 /* trace.packet.header.iron.report */
1767 ft_src = get_ft(ph, "iron", "report", NULL);
1768 ok(!validate_field_path(ft_src,
1769 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 1, FIELD_PATH_END),
1770 "trace.packet.header.iron.report has the correct field path");
1771 BT_PUT(ft_src);
1772
1773 /* trace.packet.header.iron.group */
1774 ft_src = get_ft(ph, "iron", "group", NULL);
1775 ok(!validate_field_path(ft_src,
1776 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 2, FIELD_PATH_END),
1777 "trace.packet.header.iron.group has the correct field path");
1778 BT_PUT(ft_src);
1779
1780 /* stream.packet.context.naive.[element] */
1781 ft_src = get_ft(pc, "naive", "", NULL);
1782 ok(!validate_field_path(ft_src,
1783 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 0, FIELD_PATH_END),
1784 "stream.packet.context.naive.[element] has the correct field path");
1785 BT_PUT(ft_src);
1786
1787 /* stream.packet.context.clover.whole */
1788 ft_src = get_ft(pc, "clover", "whole", NULL);
1789 ok(!validate_field_path(ft_src,
1790 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 2, FIELD_PATH_END),
1791 "stream.packet.context.clover.whole has the correct field path");
1792 ft_target = get_ft(ph, "iron", "parallel", NULL);
1793 ft_tag = bt_ctf_field_type_variant_get_tag_type(ft_src);
1794 ok(ft_tag == ft_target,
1795 "stream.packet.context.clover.whole has the correct tag type");
1796 BT_PUT(ft_src);
1797 BT_PUT(ft_target);
1798 BT_PUT(ft_tag);
1799
1800 /* stream.packet.context.clover.whole.BLUE */
1801 ft_src = get_ft(pc, "clover", "whole", "BLUE", NULL);
1802 ok(!validate_field_path(ft_src,
1803 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 3, 0, FIELD_PATH_END),
1804 "stream.packet.context.clover.whole.BLUE has the correct field path");
1805 BT_PUT(ft_src);
1806
1807 /* stream.packet.context.clover.egg */
1808 ft_src = get_ft(pc, "clover", "egg", NULL);
1809 ok(!validate_field_path(ft_src,
1810 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 4, 0, FIELD_PATH_END),
1811 "stream.packet.context.clover.egg has the correct field path");
1812 BT_PUT(ft_src);
1813
1814 /* stream.packet.context.clover.useful */
1815 ft_src = get_ft(pc, "clover", "useful", NULL);
1816 ok(!validate_field_path(ft_src,
1817 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 2, FIELD_PATH_END),
1818 "stream.packet.context.clover.useful has the correct field path");
1819 BT_PUT(ft_src);
1820
1821 /* stream.event.header.action.lucky */
1822 ft_src = get_ft(eh, "action", "lucky", NULL);
1823 ok(!validate_field_path(ft_src,
1824 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 0, FIELD_PATH_END),
1825 "stream.event.header.action.lucky has the correct field path");
1826 BT_PUT(ft_src);
1827
1828 /* stream.event.header.stiff */
1829 ft_src = get_ft(eh, "stiff", NULL);
1830 ok(!validate_field_path(ft_src,
1831 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 4, 1, 1, FIELD_PATH_END),
1832 "stream.event.header.stiff has the correct field path");
1833 BT_PUT(ft_src);
1834
1835 /* stream.event.header.fruit.apple */
1836 ft_src = get_ft(eh, "fruit", "apple", NULL);
1837 ok(!validate_field_path(ft_src,
1838 BT_CTF_SCOPE_STREAM_EVENT_HEADER, 2, 0, FIELD_PATH_END),
1839 "stream.event.header.fruit.apple has the correct field path");
1840 BT_PUT(ft_src);
1841
1842 /* stream.event.context.face.branch */
1843 ft_src = get_ft(sec, "face", "branch", NULL);
1844 ok(!validate_field_path(ft_src,
1845 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 2, FIELD_PATH_END),
1846 "stream.event.context.face.branch has the correct field path");
1847 BT_PUT(ft_src);
1848
1849 /* stream.event.context.face.income */
1850 ft_src = get_ft(sec, "face", "income", NULL);
1851 ok(!validate_field_path(ft_src,
1852 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 0, FIELD_PATH_END),
1853 "stream.event.context.face.income has the correct field path");
1854 BT_PUT(ft_src);
1855
1856 /* stream.event.context.face.lucky */
1857 ft_src = get_ft(sec, "face", "lucky", NULL);
1858 ok(!validate_field_path(ft_src,
1859 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, 0, 2, FIELD_PATH_END),
1860 "stream.event.context.face.lucky has the correct field path");
1861 BT_PUT(ft_src);
1862
1863 /* stream.event.context.dream */
1864 ft_src = get_ft(sec, "dream", NULL);
1865 ok(!validate_field_path(ft_src,
1866 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 0, FIELD_PATH_END),
1867 "stream.event.context.dream has the correct field path");
1868 BT_PUT(ft_src);
1869
1870 /* stream.event.context.dream.[element] */
1871 ft_src = get_ft(sec, "dream", "", NULL);
1872 ok(!validate_field_path(ft_src,
1873 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 1, FIELD_PATH_END),
1874 "stream.event.context.dream.[element] has the correct field path");
1875 BT_PUT(ft_src);
1876
1877 /* stream.event.context.dream.[element].[element] */
1878 ft_src = get_ft(sec, "dream", "", "", NULL);
1879 ok(!validate_field_path(ft_src,
1880 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, 0, 2, FIELD_PATH_END),
1881 "stream.event.context.dream.[element].[element] has the correct field path");
1882 BT_PUT(ft_src);
1883
1884 /* event.context.berry.porter */
1885 ft_src = get_ft(ectx, "berry", "porter", NULL);
1886 ok(!validate_field_path(ft_src,
1887 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, 0, 2, FIELD_PATH_END),
1888 "event.context.berry.porter has the correct field path");
1889 BT_PUT(ft_src);
1890
1891 /* event.context.berry.porter */
1892 ft_src = get_ft(ectx, "berry", "porter", NULL);
1893 ok(!validate_field_path(ft_src,
1894 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, 0, 2, FIELD_PATH_END),
1895 "event.context.berry.porter has the correct field path");
1896 BT_PUT(ft_src);
1897
1898 /* event.context.berry.mice */
1899 ft_src = get_ft(ectx, "berry", "mice", NULL);
1900 ok(!validate_field_path(ft_src,
1901 BT_CTF_SCOPE_STREAM_EVENT_HEADER, 2, 0, FIELD_PATH_END),
1902 "event.context.berry.mice has the correct field path");
1903 BT_PUT(ft_src);
1904
1905 /* event.context.berry.guard */
1906 ft_src = get_ft(ectx, "berry", "guard", NULL);
1907 ok(!validate_field_path(ft_src,
1908 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 4, 0, FIELD_PATH_END),
1909 "event.context.berry.guard has the correct field path");
1910 BT_PUT(ft_src);
1911
1912 /* event.context.berry.one */
1913 ft_src = get_ft(ectx, "berry", "one", NULL);
1914 ok(!validate_field_path(ft_src,
1915 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 3, 0, FIELD_PATH_END),
1916 "event.context.berry.one has the correct field path");
1917 BT_PUT(ft_src);
1918
1919 /* event.context.loud.toys */
1920 ft_src = get_ft(ectx, "loud", "toys", NULL);
1921 ok(!validate_field_path(ft_src,
1922 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 3, 0, FIELD_PATH_END),
1923 "event.context.loud.toys has the correct field path");
1924 BT_PUT(ft_src);
1925
1926 /* event.context.loud.spoon */
1927 ft_src = get_ft(ectx, "loud", "spoon", NULL);
1928 ok(!validate_field_path(ft_src,
1929 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 4, 0, FIELD_PATH_END),
1930 "event.context.loud.spoon has the correct field path");
1931 BT_PUT(ft_src);
1932
1933 /* event.context.loud.turkey */
1934 ft_src = get_ft(ectx, "loud", "turkey", NULL);
1935 ok(!validate_field_path(ft_src,
1936 BT_CTF_SCOPE_STREAM_EVENT_HEADER, 2, 0, FIELD_PATH_END),
1937 "event.context.loud.turkey has the correct field path");
1938 BT_PUT(ft_src);
1939
1940 /* event.context.loud.inform */
1941 ft_src = get_ft(ectx, "loud", "inform", NULL);
1942 ok(!validate_field_path(ft_src,
1943 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, 0, 2, FIELD_PATH_END),
1944 "event.context.loud.inform has the correct field path");
1945 BT_PUT(ft_src);
1946
1947 /* event.context.loud.odd */
1948 ft_src = get_ft(ectx, "loud", "odd", NULL);
1949 ok(!validate_field_path(ft_src,
1950 BT_CTF_SCOPE_EVENT_CONTEXT, 1, 3, FIELD_PATH_END),
1951 "event.context.loud.odd has the correct field path");
1952 BT_PUT(ft_src);
1953
1954 /* event.context.loud.amuck */
1955 ft_src = get_ft(ectx, "loud", "amuck", NULL);
1956 ok(!validate_field_path(ft_src,
1957 BT_CTF_SCOPE_EVENT_CONTEXT, 0, FIELD_PATH_END),
1958 "event.context.loud.amuck has the correct field path");
1959 BT_PUT(ft_src);
1960
1961 /* event.fields.relative.equal */
1962 ft_src = get_ft(ep, "relative", "equal", NULL);
1963 ok(!validate_field_path(ft_src,
1964 BT_CTF_SCOPE_EVENT_FIELDS, 0, FIELD_PATH_END),
1965 "event.fields.relative.equal has the correct field path");
1966 BT_PUT(ft_src);
1967
1968 /* event.fields.relative.amuck */
1969 ft_src = get_ft(ep, "relative", "amuck", NULL);
1970 ok(!validate_field_path(ft_src,
1971 BT_CTF_SCOPE_STREAM_EVENT_HEADER, 0, FIELD_PATH_END),
1972 "event.fields.relative.amuck has the correct field path");
1973 BT_PUT(ft_src);
1974
1975 /* event.fields.relative.push */
1976 ft_src = get_ft(ep, "relative", "push", NULL);
1977 ok(!validate_field_path(ft_src,
1978 BT_CTF_SCOPE_EVENT_CONTEXT, 1, 3, FIELD_PATH_END),
1979 "event.fields.relative.push has the correct field path");
1980 BT_PUT(ft_src);
1981
1982 /* event.fields.relative.brick */
1983 ft_src = get_ft(ep, "relative", "brick", NULL);
1984 ok(!validate_field_path(ft_src,
1985 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, 0, 2, FIELD_PATH_END),
1986 "event.fields.relative.brick has the correct field path");
1987 BT_PUT(ft_src);
1988
1989 /* event.fields.relative.crush */
1990 ft_src = get_ft(ep, "relative", "crush", NULL);
1991 ok(!validate_field_path(ft_src,
1992 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 2, FIELD_PATH_END),
1993 "event.fields.relative.crush has the correct field path");
1994 BT_PUT(ft_src);
1995
1996 /* event.fields.relative.canvas */
1997 ft_src = get_ft(ep, "relative", "canvas", NULL);
1998 ok(!validate_field_path(ft_src,
1999 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 1, FIELD_PATH_END),
2000 "event.fields.relative.canvas has the correct field path");
2001 BT_PUT(ft_src);
2002
2003 /* event.fields.absolute.equal */
2004 ft_src = get_ft(ep, "absolute", "equal", NULL);
2005 ok(!validate_field_path(ft_src,
2006 BT_CTF_SCOPE_EVENT_FIELDS, 0, FIELD_PATH_END),
2007 "event.fields.absolute.equal has the correct field path");
2008 BT_PUT(ft_src);
2009
2010 /* event.fields.absolute.amuck */
2011 ft_src = get_ft(ep, "absolute", "amuck", NULL);
2012 ok(!validate_field_path(ft_src,
2013 BT_CTF_SCOPE_STREAM_EVENT_HEADER, 0, FIELD_PATH_END),
2014 "event.fields.absolute.amuck has the correct field path");
2015 BT_PUT(ft_src);
2016
2017 /* event.fields.absolute.push */
2018 ft_src = get_ft(ep, "absolute", "push", NULL);
2019 ok(!validate_field_path(ft_src,
2020 BT_CTF_SCOPE_EVENT_CONTEXT, 1, 3, FIELD_PATH_END),
2021 "event.fields.absolute.push has the correct field path");
2022 BT_PUT(ft_src);
2023
2024 /* event.fields.absolute.brick */
2025 ft_src = get_ft(ep, "absolute", "brick", NULL);
2026 ok(!validate_field_path(ft_src,
2027 BT_CTF_SCOPE_STREAM_EVENT_CONTEXT, 0, 2, FIELD_PATH_END),
2028 "event.fields.absolute.brick has the correct field path");
2029 BT_PUT(ft_src);
2030
2031 /* event.fields.absolute.crush */
2032 ft_src = get_ft(ep, "absolute", "crush", NULL);
2033 ok(!validate_field_path(ft_src,
2034 BT_CTF_SCOPE_STREAM_PACKET_CONTEXT, 2, FIELD_PATH_END),
2035 "event.fields.absolute.crush has the correct field path");
2036 BT_PUT(ft_src);
2037
2038 /* event.fields.absolute.canvas */
2039 ft_src = get_ft(ep, "absolute", "canvas", NULL);
2040 ok(!validate_field_path(ft_src,
2041 BT_CTF_SCOPE_TRACE_PACKET_HEADER, 3, 1, FIELD_PATH_END),
2042 "event.fields.absolute.canvas has the correct field path");
2043 BT_PUT(ft_src);
2044
2045 BT_PUT(ft_src);
2046 BT_PUT(ft_target);
2047 BT_PUT(ph);
2048 BT_PUT(pc);
2049 BT_PUT(eh);
2050 BT_PUT(sec);
2051 BT_PUT(ectx);
2052 BT_PUT(ep);
2053 BT_PUT(sc);
2054 BT_PUT(ec);
2055 }
2056
2057 static
2058 void test_pass(void)
2059 {
2060 int ret;
2061 struct bt_ctf_trace *trace;
2062 struct bt_ctf_stream_class *sc;
2063 struct bt_ctf_event_class *ec;
2064 struct bt_ctf_field_type *ph;
2065 struct bt_ctf_field_type *pc;
2066 struct bt_ctf_field_type *eh;
2067 struct bt_ctf_field_type *sec;
2068 struct bt_ctf_field_type *ectx;
2069 struct bt_ctf_field_type *ep;
2070
2071 trace = bt_ctf_trace_create();
2072 assert(trace);
2073 ret = bt_ctf_trace_set_native_byte_order(trace,
2074 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2075 assert(ret == 0);
2076 sc = bt_ctf_stream_class_create("nice_piece_of_stream_class");
2077 assert(sc);
2078 ec = bt_ctf_event_class_create("oh_what_an_event_class");
2079 assert(ec);
2080
2081 ph = get_good_packet_header_type();
2082 assert(ph);
2083 pc = get_good_packet_context_type();
2084 assert(pc);
2085 eh = get_good_event_header_type();
2086 assert(eh);
2087 sec = get_good_stream_event_context_type();
2088 assert(sec);
2089 ectx = get_good_event_context_type();
2090 assert(ec);
2091 ep = get_good_event_payload_type();
2092 assert(ep);
2093
2094 ret = bt_ctf_trace_set_packet_header_type(trace, ph);
2095 assert(ret == 0);
2096 ret = bt_ctf_stream_class_set_packet_context_type(sc, pc);
2097 assert(ret == 0);
2098 ret = bt_ctf_stream_class_set_event_header_type(sc, eh);
2099 assert(ret == 0);
2100 ret = bt_ctf_stream_class_set_event_context_type(sc, sec);
2101 assert(ret == 0);
2102 ret = bt_ctf_event_class_set_context_type(ec, ectx);
2103 assert(ret == 0);
2104 ret = bt_ctf_event_class_set_payload_type(ec, ep);
2105 assert(ret == 0);
2106
2107 ret = bt_ctf_stream_class_add_event_class(sc, ec);
2108 assert(ret == 0);
2109
2110 /* Validation happens here */
2111 ret = bt_ctf_trace_add_stream_class(trace, sc);
2112 ok(ret == 0, "Valid type system is considered valid");
2113
2114 validate_test_pass(trace);
2115
2116 BT_PUT(ph);
2117 BT_PUT(pc);
2118 BT_PUT(eh);
2119 BT_PUT(sec);
2120 BT_PUT(ectx);
2121 BT_PUT(ep);
2122 BT_PUT(trace);
2123 BT_PUT(sc);
2124 BT_PUT(ec);
2125 }
2126
2127 static
2128 struct bt_ctf_event *create_event_with_context_and_payload(
2129 struct bt_ctf_field_type *ectx, struct bt_ctf_field_type *ep)
2130 {
2131 int ret;
2132 struct bt_ctf_stream_class *sc;
2133 struct bt_ctf_event_class *ec;
2134 struct bt_ctf_event *event;
2135
2136 sc = bt_ctf_stream_class_create("sc");
2137 assert(sc);
2138 ec = bt_ctf_event_class_create("ec");
2139 assert(ec);
2140
2141 if (ectx) {
2142 ret = bt_ctf_event_class_set_context_type(ec, ectx);
2143 assert(ret == 0);
2144 }
2145
2146 if (ep) {
2147 ret = bt_ctf_event_class_set_payload_type(ec, ep);
2148 assert(ret == 0);
2149 }
2150
2151 ret = bt_ctf_stream_class_add_event_class(sc, ec);
2152 assert(ret == 0);
2153
2154 /* Validation happens here */
2155 event = bt_ctf_event_create(ec);
2156
2157 BT_PUT(ec);
2158 BT_PUT(sc);
2159
2160 return event;
2161 }
2162
2163
2164 static
2165 struct bt_ctf_field_type *test_fail_unavailable_root_get_event_payload(void)
2166 {
2167 /*
2168 Generated by bt-ctfirtg using the following input:
2169
2170 class: struct
2171 fields:
2172 a:
2173 class: int
2174 size: 32
2175 b:
2176 class: array
2177 length: stream.event.context.lol
2178 element-type:
2179 class: string
2180 c:
2181 class: string
2182
2183 */
2184
2185 struct bt_ctf_field_type *root = NULL;
2186 struct bt_ctf_field_type *root_a = NULL;
2187 struct bt_ctf_field_type *root_b = NULL;
2188 struct bt_ctf_field_type *root_b_elem = NULL;
2189 struct bt_ctf_field_type *root_c = NULL;
2190
2191 int ret;
2192 root = bt_ctf_field_type_structure_create();
2193 assert(root);
2194 ret = bt_ctf_field_type_set_alignment(root, 8);
2195 assert(ret == 0);
2196 root_a = bt_ctf_field_type_integer_create(32);
2197 assert(root_a);
2198 ret = bt_ctf_field_type_integer_set_signed(root_a, 0);
2199 assert(ret == 0);
2200 ret = bt_ctf_field_type_integer_set_base(root_a, 10);
2201 assert(ret == 0);
2202 ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE);
2203 assert(ret == 0);
2204 ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2205 assert(ret == 0);
2206 ret = bt_ctf_field_type_set_alignment(root_a, 8);
2207 assert(ret == 0);
2208 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2209 assert(ret == 0);
2210 root_b_elem = bt_ctf_field_type_string_create();
2211 assert(root_b_elem);
2212 ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8);
2213 assert(ret == 0);
2214 root_b = bt_ctf_field_type_sequence_create(root_b_elem, "stream.event.context.lol");
2215 assert(root_b);
2216 ret = bt_ctf_field_type_structure_add_field(root, root_b, "b");
2217 assert(ret == 0);
2218 root_c = bt_ctf_field_type_string_create();
2219 assert(root_c);
2220 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2221 assert(ret == 0);
2222 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2223 assert(ret == 0);
2224
2225 BT_PUT(root_a);
2226 BT_PUT(root_b);
2227 BT_PUT(root_b_elem);
2228 BT_PUT(root_c);
2229
2230 return root;
2231 }
2232
2233 static
2234 void test_fail_unavailable_root(void)
2235 {
2236 struct bt_ctf_field_type *ep;
2237 struct bt_ctf_event *event;
2238
2239 ep = test_fail_unavailable_root_get_event_payload();
2240 assert(ep);
2241 event = create_event_with_context_and_payload(NULL, ep);
2242 ok(!event, "Sequence FT with length in unavailable root is invalid");
2243
2244 BT_PUT(ep);
2245 BT_PUT(event);
2246 }
2247
2248 static
2249 struct bt_ctf_field_type *test_fail_target_is_root_get_event_payload(void)
2250 {
2251 /*
2252 Generated by bt-ctfirtg using the following input:
2253
2254 class: struct
2255 fields:
2256 a:
2257 class: int
2258 size: 32
2259 b:
2260 class: array
2261 length: event.fields
2262 element-type:
2263 class: string
2264 c:
2265 class: string
2266
2267 */
2268
2269 struct bt_ctf_field_type *root = NULL;
2270 struct bt_ctf_field_type *root_a = NULL;
2271 struct bt_ctf_field_type *root_b = NULL;
2272 struct bt_ctf_field_type *root_b_elem = NULL;
2273 struct bt_ctf_field_type *root_c = NULL;
2274
2275 int ret;
2276 root = bt_ctf_field_type_structure_create();
2277 assert(root);
2278 ret = bt_ctf_field_type_set_alignment(root, 8);
2279 assert(ret == 0);
2280 root_a = bt_ctf_field_type_integer_create(32);
2281 assert(root_a);
2282 ret = bt_ctf_field_type_integer_set_signed(root_a, 0);
2283 assert(ret == 0);
2284 ret = bt_ctf_field_type_integer_set_base(root_a, 10);
2285 assert(ret == 0);
2286 ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE);
2287 assert(ret == 0);
2288 ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2289 assert(ret == 0);
2290 ret = bt_ctf_field_type_set_alignment(root_a, 8);
2291 assert(ret == 0);
2292 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2293 assert(ret == 0);
2294 root_b_elem = bt_ctf_field_type_string_create();
2295 assert(root_b_elem);
2296 ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8);
2297 assert(ret == 0);
2298 root_b = bt_ctf_field_type_sequence_create(root_b_elem, "event.fields");
2299 assert(root_b);
2300 ret = bt_ctf_field_type_structure_add_field(root, root_b, "b");
2301 assert(ret == 0);
2302 root_c = bt_ctf_field_type_string_create();
2303 assert(root_c);
2304 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2305 assert(ret == 0);
2306 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2307 assert(ret == 0);
2308
2309 BT_PUT(root_a);
2310 BT_PUT(root_b);
2311 BT_PUT(root_b_elem);
2312 BT_PUT(root_c);
2313
2314 return root;
2315 }
2316
2317 static
2318 void test_fail_target_is_root(void)
2319 {
2320 struct bt_ctf_field_type *ep;
2321 struct bt_ctf_event *event;
2322
2323 ep = test_fail_target_is_root_get_event_payload();
2324 assert(ep);
2325 event = create_event_with_context_and_payload(NULL, ep);
2326 ok(!event, "Sequence FT with root as its length is invalid");
2327
2328 BT_PUT(ep);
2329 BT_PUT(event);
2330 }
2331
2332 static
2333 struct bt_ctf_field_type *test_fail_target_is_after_source_get_ep(void)
2334 {
2335 /*
2336 Generated by bt-ctfirtg using the following input:
2337
2338 class: struct
2339 fields:
2340 a:
2341 class: int
2342 size: 32
2343 b:
2344 class: array
2345 length: d
2346 element-type:
2347 class: string
2348 c:
2349 class: string
2350 d:
2351 class: int
2352 size: 17
2353
2354 */
2355
2356 struct bt_ctf_field_type *root = NULL;
2357 struct bt_ctf_field_type *root_a = NULL;
2358 struct bt_ctf_field_type *root_b = NULL;
2359 struct bt_ctf_field_type *root_b_elem = NULL;
2360 struct bt_ctf_field_type *root_c = NULL;
2361 struct bt_ctf_field_type *root_d = NULL;
2362
2363 int ret;
2364 root = bt_ctf_field_type_structure_create();
2365 assert(root);
2366 ret = bt_ctf_field_type_set_alignment(root, 8);
2367 assert(ret == 0);
2368 root_a = bt_ctf_field_type_integer_create(32);
2369 assert(root_a);
2370 ret = bt_ctf_field_type_integer_set_signed(root_a, 0);
2371 assert(ret == 0);
2372 ret = bt_ctf_field_type_integer_set_base(root_a, 10);
2373 assert(ret == 0);
2374 ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE);
2375 assert(ret == 0);
2376 ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2377 assert(ret == 0);
2378 ret = bt_ctf_field_type_set_alignment(root_a, 8);
2379 assert(ret == 0);
2380 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2381 assert(ret == 0);
2382 root_b_elem = bt_ctf_field_type_string_create();
2383 assert(root_b_elem);
2384 ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8);
2385 assert(ret == 0);
2386 root_b = bt_ctf_field_type_sequence_create(root_b_elem, "d");
2387 assert(root_b);
2388 ret = bt_ctf_field_type_structure_add_field(root, root_b, "b");
2389 assert(ret == 0);
2390 root_c = bt_ctf_field_type_string_create();
2391 assert(root_c);
2392 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2393 assert(ret == 0);
2394 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2395 assert(ret == 0);
2396 root_d = bt_ctf_field_type_integer_create(17);
2397 assert(root_d);
2398 ret = bt_ctf_field_type_integer_set_signed(root_d, 0);
2399 assert(ret == 0);
2400 ret = bt_ctf_field_type_integer_set_base(root_d, 10);
2401 assert(ret == 0);
2402 ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE);
2403 assert(ret == 0);
2404 ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2405 assert(ret == 0);
2406 ret = bt_ctf_field_type_set_alignment(root_d, 1);
2407 assert(ret == 0);
2408 ret = bt_ctf_field_type_structure_add_field(root, root_d, "d");
2409 assert(ret == 0);
2410
2411 BT_PUT(root_a);
2412 BT_PUT(root_b);
2413 BT_PUT(root_b_elem);
2414 BT_PUT(root_c);
2415 BT_PUT(root_d);
2416
2417 return root;
2418 }
2419
2420 static
2421 void test_fail_target_is_after_source(void)
2422 {
2423 struct bt_ctf_field_type *ep;
2424 struct bt_ctf_event *event;
2425
2426 ep = test_fail_target_is_after_source_get_ep();
2427 assert(ep);
2428 event = create_event_with_context_and_payload(NULL, ep);
2429 ok(!event, "Sequence FT with length after it is invalid");
2430
2431 BT_PUT(ep);
2432 BT_PUT(event);
2433 }
2434
2435 static
2436 struct bt_ctf_field_type *test_fail_target_is_ancestor_of_source_get_ep(void)
2437 {
2438 /*
2439 Generated by bt-ctfirtg using the following input:
2440
2441 class: struct
2442 fields:
2443 a:
2444 class: int
2445 size: 32
2446 z:
2447 class: struct
2448 fields:
2449 b:
2450 class: array
2451 length: z
2452 element-type:
2453 class: string
2454 c:
2455 class: string
2456 d:
2457 class: int
2458 size: 17
2459
2460 */
2461
2462 struct bt_ctf_field_type *root = NULL;
2463 struct bt_ctf_field_type *root_a = NULL;
2464 struct bt_ctf_field_type *root_z = NULL;
2465 struct bt_ctf_field_type *root_z_b = NULL;
2466 struct bt_ctf_field_type *root_z_b_elem = NULL;
2467 struct bt_ctf_field_type *root_c = NULL;
2468 struct bt_ctf_field_type *root_d = NULL;
2469
2470 int ret;
2471 root = bt_ctf_field_type_structure_create();
2472 assert(root);
2473 ret = bt_ctf_field_type_set_alignment(root, 8);
2474 assert(ret == 0);
2475 root_a = bt_ctf_field_type_integer_create(32);
2476 assert(root_a);
2477 ret = bt_ctf_field_type_integer_set_signed(root_a, 0);
2478 assert(ret == 0);
2479 ret = bt_ctf_field_type_integer_set_base(root_a, 10);
2480 assert(ret == 0);
2481 ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE);
2482 assert(ret == 0);
2483 ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2484 assert(ret == 0);
2485 ret = bt_ctf_field_type_set_alignment(root_a, 8);
2486 assert(ret == 0);
2487 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2488 assert(ret == 0);
2489 root_z = bt_ctf_field_type_structure_create();
2490 assert(root_z);
2491 ret = bt_ctf_field_type_set_alignment(root_z, 8);
2492 assert(ret == 0);
2493 root_z_b_elem = bt_ctf_field_type_string_create();
2494 assert(root_z_b_elem);
2495 ret = bt_ctf_field_type_string_set_encoding(root_z_b_elem, BT_CTF_STRING_ENCODING_UTF8);
2496 assert(ret == 0);
2497 root_z_b = bt_ctf_field_type_sequence_create(root_z_b_elem, "z");
2498 assert(root_z_b);
2499 ret = bt_ctf_field_type_structure_add_field(root_z, root_z_b, "b");
2500 assert(ret == 0);
2501 ret = bt_ctf_field_type_structure_add_field(root, root_z, "z");
2502 assert(ret == 0);
2503 root_c = bt_ctf_field_type_string_create();
2504 assert(root_c);
2505 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2506 assert(ret == 0);
2507 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2508 assert(ret == 0);
2509 root_d = bt_ctf_field_type_integer_create(17);
2510 assert(root_d);
2511 ret = bt_ctf_field_type_integer_set_signed(root_d, 0);
2512 assert(ret == 0);
2513 ret = bt_ctf_field_type_integer_set_base(root_d, 10);
2514 assert(ret == 0);
2515 ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE);
2516 assert(ret == 0);
2517 ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2518 assert(ret == 0);
2519 ret = bt_ctf_field_type_set_alignment(root_d, 1);
2520 assert(ret == 0);
2521 ret = bt_ctf_field_type_structure_add_field(root, root_d, "d");
2522 assert(ret == 0);
2523
2524 BT_PUT(root_a);
2525 BT_PUT(root_z);
2526 BT_PUT(root_z_b);
2527 BT_PUT(root_z_b_elem);
2528 BT_PUT(root_c);
2529 BT_PUT(root_d);
2530
2531 return root;
2532 }
2533
2534 static
2535 void test_fail_target_is_ancestor_of_source(void)
2536 {
2537 struct bt_ctf_field_type *ep;
2538 struct bt_ctf_event *event;
2539
2540 ep = test_fail_target_is_ancestor_of_source_get_ep();
2541 assert(ep);
2542 event = create_event_with_context_and_payload(NULL, ep);
2543 ok(!event, "Sequence FT with ancestor as its length is invalid");
2544
2545 BT_PUT(ep);
2546 BT_PUT(event);
2547 }
2548
2549 static
2550 struct bt_ctf_field_type *test_fail_target_is_source_get_event_payload(void)
2551 {
2552 /*
2553 Generated by bt-ctfirtg using the following input:
2554
2555 class: struct
2556 fields:
2557 a:
2558 class: int
2559 size: 32
2560 b:
2561 class: array
2562 length: event.fields.b
2563 element-type:
2564 class: string
2565 c:
2566 class: string
2567 d:
2568 class: int
2569 size: 17
2570
2571 */
2572
2573 struct bt_ctf_field_type *root = NULL;
2574 struct bt_ctf_field_type *root_a = NULL;
2575 struct bt_ctf_field_type *root_b = NULL;
2576 struct bt_ctf_field_type *root_b_elem = NULL;
2577 struct bt_ctf_field_type *root_c = NULL;
2578 struct bt_ctf_field_type *root_d = NULL;
2579
2580 int ret;
2581 root = bt_ctf_field_type_structure_create();
2582 assert(root);
2583 ret = bt_ctf_field_type_set_alignment(root, 8);
2584 assert(ret == 0);
2585 root_a = bt_ctf_field_type_integer_create(32);
2586 assert(root_a);
2587 ret = bt_ctf_field_type_integer_set_signed(root_a, 0);
2588 assert(ret == 0);
2589 ret = bt_ctf_field_type_integer_set_base(root_a, 10);
2590 assert(ret == 0);
2591 ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE);
2592 assert(ret == 0);
2593 ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2594 assert(ret == 0);
2595 ret = bt_ctf_field_type_set_alignment(root_a, 8);
2596 assert(ret == 0);
2597 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2598 assert(ret == 0);
2599 root_b_elem = bt_ctf_field_type_string_create();
2600 assert(root_b_elem);
2601 ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8);
2602 assert(ret == 0);
2603 root_b = bt_ctf_field_type_sequence_create(root_b_elem, "event.fields.b");
2604 assert(root_b);
2605 ret = bt_ctf_field_type_structure_add_field(root, root_b, "b");
2606 assert(ret == 0);
2607 root_c = bt_ctf_field_type_string_create();
2608 assert(root_c);
2609 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2610 assert(ret == 0);
2611 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2612 assert(ret == 0);
2613 root_d = bt_ctf_field_type_integer_create(17);
2614 assert(root_d);
2615 ret = bt_ctf_field_type_integer_set_signed(root_d, 0);
2616 assert(ret == 0);
2617 ret = bt_ctf_field_type_integer_set_base(root_d, 10);
2618 assert(ret == 0);
2619 ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE);
2620 assert(ret == 0);
2621 ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2622 assert(ret == 0);
2623 ret = bt_ctf_field_type_set_alignment(root_d, 1);
2624 assert(ret == 0);
2625 ret = bt_ctf_field_type_structure_add_field(root, root_d, "d");
2626 assert(ret == 0);
2627
2628 BT_PUT(root_a);
2629 BT_PUT(root_b);
2630 BT_PUT(root_b_elem);
2631 BT_PUT(root_c);
2632 BT_PUT(root_d);
2633
2634 return root;
2635 }
2636
2637 static
2638 void test_fail_target_is_source(void)
2639 {
2640 struct bt_ctf_field_type *ep;
2641 struct bt_ctf_event *event;
2642
2643 ep = test_fail_target_is_source_get_event_payload();
2644 assert(ep);
2645 event = create_event_with_context_and_payload(NULL, ep);
2646 ok(!event, "Sequence FT with itself as its length is invalid");
2647
2648 BT_PUT(ep);
2649 BT_PUT(event);
2650 }
2651
2652 static
2653 struct bt_ctf_field_type *test_fail_variant_tag_is_not_enum_get_ep(void)
2654 {
2655 /*
2656 Generated by bt-ctfirtg using the following input:
2657
2658 class: struct
2659 fields:
2660 a:
2661 class: int
2662 size: 32
2663 b:
2664 class: variant
2665 tag: a
2666 types:
2667 HELLO:
2668 class: string
2669 c:
2670 class: string
2671 d:
2672 class: int
2673 size: 17
2674
2675 */
2676
2677 struct bt_ctf_field_type *root = NULL;
2678 struct bt_ctf_field_type *root_a = NULL;
2679 struct bt_ctf_field_type *root_b = NULL;
2680 struct bt_ctf_field_type *root_b_HELLO = NULL;
2681 struct bt_ctf_field_type *root_c = NULL;
2682 struct bt_ctf_field_type *root_d = NULL;
2683
2684 int ret;
2685 root = bt_ctf_field_type_structure_create();
2686 assert(root);
2687 ret = bt_ctf_field_type_set_alignment(root, 8);
2688 assert(ret == 0);
2689 root_a = bt_ctf_field_type_integer_create(32);
2690 assert(root_a);
2691 ret = bt_ctf_field_type_integer_set_signed(root_a, 0);
2692 assert(ret == 0);
2693 ret = bt_ctf_field_type_integer_set_base(root_a, 10);
2694 assert(ret == 0);
2695 ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE);
2696 assert(ret == 0);
2697 ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2698 assert(ret == 0);
2699 ret = bt_ctf_field_type_set_alignment(root_a, 8);
2700 assert(ret == 0);
2701 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2702 assert(ret == 0);
2703 root_b = bt_ctf_field_type_variant_create(NULL, "a");
2704 assert(root_b);
2705 root_b_HELLO = bt_ctf_field_type_string_create();
2706 assert(root_b_HELLO);
2707 ret = bt_ctf_field_type_string_set_encoding(root_b_HELLO, BT_CTF_STRING_ENCODING_UTF8);
2708 assert(ret == 0);
2709 ret = bt_ctf_field_type_variant_add_field(root_b, root_b_HELLO, "HELLO");
2710 assert(ret == 0);
2711 ret = bt_ctf_field_type_structure_add_field(root, root_b, "b");
2712 assert(ret == 0);
2713 root_c = bt_ctf_field_type_string_create();
2714 assert(root_c);
2715 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2716 assert(ret == 0);
2717 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2718 assert(ret == 0);
2719 root_d = bt_ctf_field_type_integer_create(17);
2720 assert(root_d);
2721 ret = bt_ctf_field_type_integer_set_signed(root_d, 0);
2722 assert(ret == 0);
2723 ret = bt_ctf_field_type_integer_set_base(root_d, 10);
2724 assert(ret == 0);
2725 ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE);
2726 assert(ret == 0);
2727 ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2728 assert(ret == 0);
2729 ret = bt_ctf_field_type_set_alignment(root_d, 1);
2730 assert(ret == 0);
2731 ret = bt_ctf_field_type_structure_add_field(root, root_d, "d");
2732 assert(ret == 0);
2733
2734 BT_PUT(root_a);
2735 BT_PUT(root_b);
2736 BT_PUT(root_b_HELLO);
2737 BT_PUT(root_c);
2738 BT_PUT(root_d);
2739
2740 return root;
2741 }
2742
2743 static
2744 void test_fail_variant_tag_is_not_enum(void)
2745 {
2746 struct bt_ctf_field_type *ep;
2747 struct bt_ctf_event *event;
2748
2749 ep = test_fail_variant_tag_is_not_enum_get_ep();
2750 assert(ep);
2751 event = create_event_with_context_and_payload(NULL, ep);
2752 ok(!event, "Variant FT with non-enum FT as its tag FT is invalid");
2753
2754 BT_PUT(ep);
2755 BT_PUT(event);
2756 }
2757
2758 static
2759 struct bt_ctf_field_type *test_fail_variant_tag_mismatch_mappings_get_ep(void)
2760 {
2761 /*
2762 Generated by bt-ctfirtg using the following input:
2763
2764 class: struct
2765 fields:
2766 a:
2767 class: enum
2768 value-type:
2769 class: int
2770 size: 16
2771 members:
2772 - GLASS
2773 - OF
2774 - WATER
2775 b:
2776 class: variant
2777 tag: a
2778 types:
2779 GLASS:
2780 class: string
2781 OF:
2782 class: int
2783 size: 2
2784 c:
2785 class: string
2786
2787 */
2788
2789 struct bt_ctf_field_type *root = NULL;
2790 struct bt_ctf_field_type *root_a = NULL;
2791 struct bt_ctf_field_type *root_a_int = NULL;
2792 struct bt_ctf_field_type *root_b = NULL;
2793 struct bt_ctf_field_type *root_b_GLASS = NULL;
2794 struct bt_ctf_field_type *root_b_OF = NULL;
2795 struct bt_ctf_field_type *root_c = NULL;
2796
2797 int ret;
2798 root = bt_ctf_field_type_structure_create();
2799 assert(root);
2800 ret = bt_ctf_field_type_set_alignment(root, 8);
2801 assert(ret == 0);
2802 root_a_int = bt_ctf_field_type_integer_create(16);
2803 assert(root_a_int);
2804 ret = bt_ctf_field_type_integer_set_signed(root_a_int, 0);
2805 assert(ret == 0);
2806 ret = bt_ctf_field_type_integer_set_base(root_a_int, 10);
2807 assert(ret == 0);
2808 ret = bt_ctf_field_type_integer_set_encoding(root_a_int, BT_CTF_STRING_ENCODING_NONE);
2809 assert(ret == 0);
2810 ret = bt_ctf_field_type_set_byte_order(root_a_int, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2811 assert(ret == 0);
2812 ret = bt_ctf_field_type_set_alignment(root_a_int, 8);
2813 assert(ret == 0);
2814 root_a = bt_ctf_field_type_enumeration_create(root_a_int);
2815 assert(root_a);
2816 ret = bt_ctf_field_type_enumeration_add_mapping(root_a, "GLASS", 0, 0);
2817 assert(ret == 0);
2818 ret = bt_ctf_field_type_enumeration_add_mapping(root_a, "OF", 1, 1);
2819 assert(ret == 0);
2820 ret = bt_ctf_field_type_enumeration_add_mapping(root_a, "WATER", 2, 2);
2821 assert(ret == 0);
2822 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2823 assert(ret == 0);
2824 root_b = bt_ctf_field_type_variant_create(NULL, "a");
2825 assert(root_b);
2826 root_b_GLASS = bt_ctf_field_type_string_create();
2827 assert(root_b_GLASS);
2828 ret = bt_ctf_field_type_string_set_encoding(root_b_GLASS, BT_CTF_STRING_ENCODING_UTF8);
2829 assert(ret == 0);
2830 ret = bt_ctf_field_type_variant_add_field(root_b, root_b_GLASS, "GLASS");
2831 assert(ret == 0);
2832 root_b_OF = bt_ctf_field_type_integer_create(2);
2833 assert(root_b_OF);
2834 ret = bt_ctf_field_type_integer_set_signed(root_b_OF, 0);
2835 assert(ret == 0);
2836 ret = bt_ctf_field_type_integer_set_base(root_b_OF, 10);
2837 assert(ret == 0);
2838 ret = bt_ctf_field_type_integer_set_encoding(root_b_OF, BT_CTF_STRING_ENCODING_NONE);
2839 assert(ret == 0);
2840 ret = bt_ctf_field_type_set_byte_order(root_b_OF, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
2841 assert(ret == 0);
2842 ret = bt_ctf_field_type_set_alignment(root_b_OF, 1);
2843 assert(ret == 0);
2844 ret = bt_ctf_field_type_variant_add_field(root_b, root_b_OF, "OF");
2845 assert(ret == 0);
2846 ret = bt_ctf_field_type_structure_add_field(root, root_b, "b");
2847 assert(ret == 0);
2848 root_c = bt_ctf_field_type_string_create();
2849 assert(root_c);
2850 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2851 assert(ret == 0);
2852 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2853 assert(ret == 0);
2854
2855 BT_PUT(root_a);
2856 BT_PUT(root_a_int);
2857 BT_PUT(root_b);
2858 BT_PUT(root_b_GLASS);
2859 BT_PUT(root_b_OF);
2860 BT_PUT(root_c);
2861
2862 return root;
2863 }
2864
2865 static
2866 void test_fail_variant_tag_mismatch_mappings(void)
2867 {
2868 struct bt_ctf_field_type *ep;
2869 struct bt_ctf_event *event;
2870
2871 ep = test_fail_variant_tag_mismatch_mappings_get_ep();
2872 assert(ep);
2873 event = create_event_with_context_and_payload(NULL, ep);
2874 ok(!event, "Variant FT with mismatching tag FT is invalid");
2875
2876 BT_PUT(ep);
2877 BT_PUT(event);
2878 }
2879
2880 static
2881 struct bt_ctf_field_type *test_fail_sequence_tag_is_not_int_get_ep(void)
2882 {
2883 /*
2884 Generated by bt-ctfirtg using the following input:
2885
2886 class: struct
2887 fields:
2888 a:
2889 class: string
2890 b:
2891 class: array
2892 length: a
2893 element-type:
2894 class: string
2895 c:
2896 class: string
2897
2898 */
2899
2900 struct bt_ctf_field_type *root = NULL;
2901 struct bt_ctf_field_type *root_a = NULL;
2902 struct bt_ctf_field_type *root_b = NULL;
2903 struct bt_ctf_field_type *root_b_elem = NULL;
2904 struct bt_ctf_field_type *root_c = NULL;
2905
2906 int ret;
2907 root = bt_ctf_field_type_structure_create();
2908 assert(root);
2909 ret = bt_ctf_field_type_set_alignment(root, 8);
2910 assert(ret == 0);
2911 root_a = bt_ctf_field_type_string_create();
2912 assert(root_a);
2913 ret = bt_ctf_field_type_string_set_encoding(root_a, BT_CTF_STRING_ENCODING_UTF8);
2914 assert(ret == 0);
2915 ret = bt_ctf_field_type_structure_add_field(root, root_a, "a");
2916 assert(ret == 0);
2917 root_b_elem = bt_ctf_field_type_string_create();
2918 assert(root_b_elem);
2919 ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8);
2920 assert(ret == 0);
2921 root_b = bt_ctf_field_type_sequence_create(root_b_elem, "a");
2922 assert(root_b);
2923 ret = bt_ctf_field_type_structure_add_field(root, root_b, "b");
2924 assert(ret == 0);
2925 root_c = bt_ctf_field_type_string_create();
2926 assert(root_c);
2927 ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8);
2928 assert(ret == 0);
2929 ret = bt_ctf_field_type_structure_add_field(root, root_c, "c");
2930 assert(ret == 0);
2931
2932 BT_PUT(root_a);
2933 BT_PUT(root_b);
2934 BT_PUT(root_b_elem);
2935 BT_PUT(root_c);
2936
2937 return root;
2938 }
2939
2940 static
2941 void test_fail_sequence_tag_is_not_int(void)
2942 {
2943 struct bt_ctf_field_type *ep;
2944 struct bt_ctf_event *event;
2945
2946 ep = test_fail_sequence_tag_is_not_int_get_ep();
2947 assert(ep);
2948 event = create_event_with_context_and_payload(NULL, ep);
2949 ok(!event, "Sequence FT with non-enum length FT is invalid");
2950
2951 BT_PUT(ep);
2952 BT_PUT(event);
2953 }
2954
2955 static
2956 void test_fail(void)
2957 {
2958 test_fail_unavailable_root();
2959 test_fail_target_is_root();
2960 test_fail_target_is_after_source();
2961 test_fail_target_is_ancestor_of_source();
2962 test_fail_target_is_source();
2963 test_fail_variant_tag_is_not_enum();
2964 test_fail_variant_tag_mismatch_mappings();
2965 test_fail_sequence_tag_is_not_int();
2966 }
2967
2968 int main(void)
2969 {
2970 plan_no_plan();
2971
2972 test_pass();
2973 test_fail();
2974
2975 return 0;
2976 }
This page took 0.168818 seconds and 5 git commands to generate.