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