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