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