Commit | Line | Data |
---|---|---|
0b93f4ea PP |
1 | /* |
2 | * test_bt_ctf_field_type_validation.c | |
3 | * | |
4 | * Babeltrace CTF IR field type validation test | |
5 | * | |
6 | * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; under version 2 of the License. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along | |
18 | * with this program; if not, write to the Free Software Foundation, Inc., | |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 | */ | |
21 | ||
9d408fca | 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> | |
29 | #include <assert.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 | ||
36 | static | |
37 | struct bt_ctf_field_type *get_good_packet_header_type(void) | |
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 | ||
114 | struct bt_ctf_field_type *root = NULL; | |
115 | struct bt_ctf_field_type *root_magic = NULL; | |
116 | struct bt_ctf_field_type *root_uuid = NULL; | |
117 | struct bt_ctf_field_type *root_uuid_elem = NULL; | |
118 | struct bt_ctf_field_type *root_stream_id = NULL; | |
119 | struct bt_ctf_field_type *root_iron = NULL; | |
120 | struct bt_ctf_field_type *root_iron_listen = NULL; | |
121 | struct bt_ctf_field_type *root_iron_dust = NULL; | |
122 | struct bt_ctf_field_type *root_iron_parallel = NULL; | |
123 | struct bt_ctf_field_type *root_iron_parallel_int = NULL; | |
124 | struct bt_ctf_field_type *root_iron_fire = NULL; | |
125 | struct bt_ctf_field_type *root_iron_fire_word = NULL; | |
126 | struct bt_ctf_field_type *root_iron_fire_rabbit = NULL; | |
127 | struct bt_ctf_field_type *root_iron_fire_keen = NULL; | |
128 | struct bt_ctf_field_type *root_iron_fire_keen_elem = NULL; | |
129 | struct bt_ctf_field_type *root_iron_fire_keen_elem_RED = NULL; | |
130 | struct bt_ctf_field_type *root_iron_fire_keen_elem_BLUE = NULL; | |
131 | struct bt_ctf_field_type *root_iron_fire_keen_elem_BLUE_elem = NULL; | |
132 | struct bt_ctf_field_type *root_iron_fire_keen_elem_YELLOW = NULL; | |
133 | struct bt_ctf_field_type *root_iron_report = NULL; | |
134 | struct bt_ctf_field_type *root_iron_report_elem = NULL; | |
135 | struct bt_ctf_field_type *root_iron_group = NULL; | |
136 | struct bt_ctf_field_type *root_iron_group_elem = NULL; | |
137 | struct bt_ctf_field_type *root_serious = NULL; | |
138 | ||
139 | int ret; | |
140 | root = bt_ctf_field_type_structure_create(); | |
141 | assert(root); | |
142 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
143 | assert(ret == 0); | |
144 | root_magic = bt_ctf_field_type_integer_create(32); | |
145 | assert(root_magic); | |
146 | ret = bt_ctf_field_type_integer_set_signed(root_magic, 0); | |
147 | assert(ret == 0); | |
148 | ret = bt_ctf_field_type_integer_set_base(root_magic, 10); | |
149 | assert(ret == 0); | |
b28a86ad | 150 | ret = bt_ctf_field_type_integer_set_encoding(root_magic, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
151 | assert(ret == 0); |
152 | ret = bt_ctf_field_type_set_byte_order(root_magic, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
153 | assert(ret == 0); | |
154 | ret = bt_ctf_field_type_set_alignment(root_magic, 8); | |
155 | assert(ret == 0); | |
156 | ret = bt_ctf_field_type_structure_add_field(root, root_magic, "magic"); | |
157 | assert(ret == 0); | |
158 | root_uuid_elem = bt_ctf_field_type_integer_create(8); | |
159 | assert(root_uuid_elem); | |
160 | ret = bt_ctf_field_type_integer_set_signed(root_uuid_elem, 0); | |
161 | assert(ret == 0); | |
162 | ret = bt_ctf_field_type_integer_set_base(root_uuid_elem, 10); | |
163 | assert(ret == 0); | |
b28a86ad | 164 | ret = bt_ctf_field_type_integer_set_encoding(root_uuid_elem, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
165 | assert(ret == 0); |
166 | ret = bt_ctf_field_type_set_byte_order(root_uuid_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
167 | assert(ret == 0); | |
168 | ret = bt_ctf_field_type_set_alignment(root_uuid_elem, 8); | |
169 | assert(ret == 0); | |
170 | root_uuid = bt_ctf_field_type_array_create(root_uuid_elem, 16); | |
171 | assert(root_uuid); | |
172 | ret = bt_ctf_field_type_structure_add_field(root, root_uuid, "uuid"); | |
173 | assert(ret == 0); | |
174 | root_stream_id = bt_ctf_field_type_integer_create(32); | |
175 | assert(root_stream_id); | |
176 | ret = bt_ctf_field_type_integer_set_signed(root_stream_id, 0); | |
177 | assert(ret == 0); | |
178 | ret = bt_ctf_field_type_integer_set_base(root_stream_id, 10); | |
179 | assert(ret == 0); | |
b28a86ad | 180 | ret = bt_ctf_field_type_integer_set_encoding(root_stream_id, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
181 | assert(ret == 0); |
182 | ret = bt_ctf_field_type_set_byte_order(root_stream_id, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
183 | assert(ret == 0); | |
184 | ret = bt_ctf_field_type_set_alignment(root_stream_id, 8); | |
185 | assert(ret == 0); | |
186 | ret = bt_ctf_field_type_structure_add_field(root, root_stream_id, "stream_id"); | |
187 | assert(ret == 0); | |
188 | root_iron = bt_ctf_field_type_structure_create(); | |
189 | assert(root_iron); | |
190 | ret = bt_ctf_field_type_set_alignment(root_iron, 8); | |
191 | assert(ret == 0); | |
192 | root_iron_listen = bt_ctf_field_type_string_create(); | |
193 | assert(root_iron_listen); | |
b28a86ad | 194 | ret = bt_ctf_field_type_string_set_encoding(root_iron_listen, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
195 | assert(ret == 0); |
196 | ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_listen, "listen"); | |
197 | assert(ret == 0); | |
198 | root_iron_dust = bt_ctf_field_type_integer_create(23); | |
199 | assert(root_iron_dust); | |
200 | ret = bt_ctf_field_type_integer_set_signed(root_iron_dust, 0); | |
201 | assert(ret == 0); | |
202 | ret = bt_ctf_field_type_integer_set_base(root_iron_dust, 10); | |
203 | assert(ret == 0); | |
b28a86ad | 204 | ret = bt_ctf_field_type_integer_set_encoding(root_iron_dust, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
205 | assert(ret == 0); |
206 | ret = bt_ctf_field_type_set_byte_order(root_iron_dust, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
207 | assert(ret == 0); | |
208 | ret = bt_ctf_field_type_set_alignment(root_iron_dust, 1); | |
209 | assert(ret == 0); | |
210 | ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_dust, "dust"); | |
211 | assert(ret == 0); | |
212 | root_iron_parallel_int = bt_ctf_field_type_integer_create(10); | |
213 | assert(root_iron_parallel_int); | |
214 | ret = bt_ctf_field_type_integer_set_signed(root_iron_parallel_int, 0); | |
215 | assert(ret == 0); | |
216 | ret = bt_ctf_field_type_integer_set_base(root_iron_parallel_int, 10); | |
217 | assert(ret == 0); | |
b28a86ad | 218 | ret = bt_ctf_field_type_integer_set_encoding(root_iron_parallel_int, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
219 | assert(ret == 0); |
220 | ret = bt_ctf_field_type_set_byte_order(root_iron_parallel_int, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
221 | assert(ret == 0); | |
222 | ret = bt_ctf_field_type_set_alignment(root_iron_parallel_int, 1); | |
223 | assert(ret == 0); | |
224 | root_iron_parallel = bt_ctf_field_type_enumeration_create(root_iron_parallel_int); | |
225 | assert(root_iron_parallel); | |
226 | ret = bt_ctf_field_type_enumeration_add_mapping(root_iron_parallel, "RED", 0, 0); | |
227 | assert(ret == 0); | |
228 | ret = bt_ctf_field_type_enumeration_add_mapping(root_iron_parallel, "BLUE", 1, 1); | |
229 | assert(ret == 0); | |
230 | ret = bt_ctf_field_type_enumeration_add_mapping(root_iron_parallel, "YELLOW", 2, 2); | |
231 | assert(ret == 0); | |
232 | ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_parallel, "parallel"); | |
233 | assert(ret == 0); | |
234 | root_iron_fire = bt_ctf_field_type_structure_create(); | |
235 | assert(root_iron_fire); | |
236 | ret = bt_ctf_field_type_set_alignment(root_iron_fire, 8); | |
237 | assert(ret == 0); | |
238 | root_iron_fire_word = bt_ctf_field_type_integer_create(17); | |
239 | assert(root_iron_fire_word); | |
240 | ret = bt_ctf_field_type_integer_set_signed(root_iron_fire_word, 0); | |
241 | assert(ret == 0); | |
242 | ret = bt_ctf_field_type_integer_set_base(root_iron_fire_word, 10); | |
243 | assert(ret == 0); | |
b28a86ad | 244 | ret = bt_ctf_field_type_integer_set_encoding(root_iron_fire_word, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
245 | assert(ret == 0); |
246 | ret = bt_ctf_field_type_set_byte_order(root_iron_fire_word, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
247 | assert(ret == 0); | |
248 | ret = bt_ctf_field_type_set_alignment(root_iron_fire_word, 1); | |
249 | assert(ret == 0); | |
250 | ret = bt_ctf_field_type_structure_add_field(root_iron_fire, root_iron_fire_word, "word"); | |
251 | assert(ret == 0); | |
252 | root_iron_fire_rabbit = bt_ctf_field_type_string_create(); | |
253 | assert(root_iron_fire_rabbit); | |
b28a86ad | 254 | ret = bt_ctf_field_type_string_set_encoding(root_iron_fire_rabbit, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
255 | assert(ret == 0); |
256 | ret = bt_ctf_field_type_structure_add_field(root_iron_fire, root_iron_fire_rabbit, "rabbit"); | |
257 | assert(ret == 0); | |
258 | root_iron_fire_keen_elem = bt_ctf_field_type_variant_create(NULL, "iron.parallel"); | |
259 | assert(root_iron_fire_keen_elem); | |
260 | root_iron_fire_keen_elem_RED = bt_ctf_field_type_string_create(); | |
261 | assert(root_iron_fire_keen_elem_RED); | |
b28a86ad | 262 | ret = bt_ctf_field_type_string_set_encoding(root_iron_fire_keen_elem_RED, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
263 | assert(ret == 0); |
264 | ret = bt_ctf_field_type_variant_add_field(root_iron_fire_keen_elem, root_iron_fire_keen_elem_RED, "RED"); | |
265 | assert(ret == 0); | |
266 | root_iron_fire_keen_elem_BLUE_elem = bt_ctf_field_type_integer_create(5); | |
267 | assert(root_iron_fire_keen_elem_BLUE_elem); | |
268 | ret = bt_ctf_field_type_integer_set_signed(root_iron_fire_keen_elem_BLUE_elem, 0); | |
269 | assert(ret == 0); | |
270 | ret = bt_ctf_field_type_integer_set_base(root_iron_fire_keen_elem_BLUE_elem, 10); | |
271 | assert(ret == 0); | |
b28a86ad | 272 | ret = bt_ctf_field_type_integer_set_encoding(root_iron_fire_keen_elem_BLUE_elem, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
273 | assert(ret == 0); |
274 | ret = bt_ctf_field_type_set_byte_order(root_iron_fire_keen_elem_BLUE_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
275 | assert(ret == 0); | |
276 | ret = bt_ctf_field_type_set_alignment(root_iron_fire_keen_elem_BLUE_elem, 1); | |
277 | assert(ret == 0); | |
278 | root_iron_fire_keen_elem_BLUE = bt_ctf_field_type_sequence_create(root_iron_fire_keen_elem_BLUE_elem, "magic"); | |
279 | assert(root_iron_fire_keen_elem_BLUE); | |
280 | ret = bt_ctf_field_type_variant_add_field(root_iron_fire_keen_elem, root_iron_fire_keen_elem_BLUE, "BLUE"); | |
281 | assert(ret == 0); | |
282 | root_iron_fire_keen_elem_YELLOW = bt_ctf_field_type_structure_create(); | |
283 | assert(root_iron_fire_keen_elem_YELLOW); | |
284 | ret = bt_ctf_field_type_set_alignment(root_iron_fire_keen_elem_YELLOW, 1); | |
285 | assert(ret == 0); | |
286 | ret = bt_ctf_field_type_variant_add_field(root_iron_fire_keen_elem, root_iron_fire_keen_elem_YELLOW, "YELLOW"); | |
287 | assert(ret == 0); | |
288 | root_iron_fire_keen = bt_ctf_field_type_sequence_create(root_iron_fire_keen_elem, "word"); | |
289 | assert(root_iron_fire_keen); | |
290 | ret = bt_ctf_field_type_structure_add_field(root_iron_fire, root_iron_fire_keen, "keen"); | |
291 | assert(ret == 0); | |
292 | ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_fire, "fire"); | |
293 | assert(ret == 0); | |
294 | root_iron_report_elem = bt_ctf_field_type_string_create(); | |
295 | assert(root_iron_report_elem); | |
b28a86ad | 296 | ret = bt_ctf_field_type_string_set_encoding(root_iron_report_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
297 | assert(ret == 0); |
298 | root_iron_report = bt_ctf_field_type_sequence_create(root_iron_report_elem, "trace.packet.header.iron.dust"); | |
299 | assert(root_iron_report); | |
300 | ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_report, "report"); | |
301 | assert(ret == 0); | |
302 | root_iron_group_elem = bt_ctf_field_type_string_create(); | |
303 | assert(root_iron_group_elem); | |
b28a86ad | 304 | ret = bt_ctf_field_type_string_set_encoding(root_iron_group_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
305 | assert(ret == 0); |
306 | root_iron_group = bt_ctf_field_type_sequence_create(root_iron_group_elem, "trace.packet.header.stream_id"); | |
307 | assert(root_iron_group); | |
308 | ret = bt_ctf_field_type_structure_add_field(root_iron, root_iron_group, "group"); | |
309 | assert(ret == 0); | |
310 | ret = bt_ctf_field_type_structure_add_field(root, root_iron, "iron"); | |
311 | assert(ret == 0); | |
312 | root_serious = bt_ctf_field_type_integer_create(1); | |
313 | assert(root_serious); | |
314 | ret = bt_ctf_field_type_integer_set_signed(root_serious, 0); | |
315 | assert(ret == 0); | |
316 | ret = bt_ctf_field_type_integer_set_base(root_serious, 10); | |
317 | assert(ret == 0); | |
b28a86ad | 318 | ret = bt_ctf_field_type_integer_set_encoding(root_serious, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
319 | assert(ret == 0); |
320 | ret = bt_ctf_field_type_set_byte_order(root_serious, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
321 | assert(ret == 0); | |
322 | ret = bt_ctf_field_type_set_alignment(root_serious, 1); | |
323 | assert(ret == 0); | |
324 | ret = bt_ctf_field_type_structure_add_field(root, root_serious, "serious"); | |
325 | assert(ret == 0); | |
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 | ||
354 | static | |
355 | struct bt_ctf_field_type *get_good_packet_context_type(void) | |
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 | ||
423 | struct bt_ctf_field_type *root = NULL; | |
424 | struct bt_ctf_field_type *root_placid = NULL; | |
425 | struct bt_ctf_field_type *root_meow = NULL; | |
426 | struct bt_ctf_field_type *root_serious = NULL; | |
427 | struct bt_ctf_field_type *root_naive = NULL; | |
428 | struct bt_ctf_field_type *root_naive_elem = NULL; | |
429 | struct bt_ctf_field_type *root_naive_elem_elem = NULL; | |
430 | struct bt_ctf_field_type *root_clover = NULL; | |
431 | struct bt_ctf_field_type *root_clover_oval = NULL; | |
432 | struct bt_ctf_field_type *root_clover_whole = NULL; | |
433 | struct bt_ctf_field_type *root_clover_whole_BLUE = NULL; | |
434 | struct bt_ctf_field_type *root_clover_whole_BLUE_elem = NULL; | |
435 | struct bt_ctf_field_type *root_clover_whole_RED = NULL; | |
436 | struct bt_ctf_field_type *root_clover_whole_YELLOW = NULL; | |
437 | struct bt_ctf_field_type *root_clover_egg = NULL; | |
438 | struct bt_ctf_field_type *root_clover_egg_elem = NULL; | |
439 | struct bt_ctf_field_type *root_clover_square = NULL; | |
440 | struct bt_ctf_field_type *root_clover_square_int = NULL; | |
441 | struct bt_ctf_field_type *root_clover_useful = NULL; | |
442 | struct bt_ctf_field_type *root_clover_useful_elem = NULL; | |
443 | struct bt_ctf_field_type *root_tart = NULL; | |
444 | ||
445 | int ret; | |
446 | root = bt_ctf_field_type_structure_create(); | |
447 | assert(root); | |
448 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
449 | assert(ret == 0); | |
450 | root_placid = bt_ctf_field_type_integer_create(32); | |
451 | assert(root_placid); | |
452 | ret = bt_ctf_field_type_integer_set_signed(root_placid, 0); | |
453 | assert(ret == 0); | |
454 | ret = bt_ctf_field_type_integer_set_base(root_placid, 10); | |
455 | assert(ret == 0); | |
b28a86ad | 456 | ret = bt_ctf_field_type_integer_set_encoding(root_placid, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
457 | assert(ret == 0); |
458 | ret = bt_ctf_field_type_set_byte_order(root_placid, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
459 | assert(ret == 0); | |
460 | ret = bt_ctf_field_type_set_alignment(root_placid, 8); | |
461 | assert(ret == 0); | |
462 | ret = bt_ctf_field_type_structure_add_field(root, root_placid, "placid"); | |
463 | assert(ret == 0); | |
464 | root_meow = bt_ctf_field_type_string_create(); | |
465 | assert(root_meow); | |
b28a86ad | 466 | ret = bt_ctf_field_type_string_set_encoding(root_meow, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
467 | assert(ret == 0); |
468 | ret = bt_ctf_field_type_structure_add_field(root, root_meow, "meow"); | |
469 | assert(ret == 0); | |
470 | root_serious = bt_ctf_field_type_integer_create(11); | |
471 | assert(root_serious); | |
472 | ret = bt_ctf_field_type_integer_set_signed(root_serious, 0); | |
473 | assert(ret == 0); | |
474 | ret = bt_ctf_field_type_integer_set_base(root_serious, 10); | |
475 | assert(ret == 0); | |
b28a86ad | 476 | ret = bt_ctf_field_type_integer_set_encoding(root_serious, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
477 | assert(ret == 0); |
478 | ret = bt_ctf_field_type_set_byte_order(root_serious, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
479 | assert(ret == 0); | |
480 | ret = bt_ctf_field_type_set_alignment(root_serious, 1); | |
481 | assert(ret == 0); | |
482 | ret = bt_ctf_field_type_structure_add_field(root, root_serious, "serious"); | |
483 | assert(ret == 0); | |
484 | root_naive_elem_elem = bt_ctf_field_type_string_create(); | |
485 | assert(root_naive_elem_elem); | |
b28a86ad | 486 | ret = bt_ctf_field_type_string_set_encoding(root_naive_elem_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
487 | assert(ret == 0); |
488 | root_naive_elem = bt_ctf_field_type_sequence_create(root_naive_elem_elem, "placid"); | |
489 | assert(root_naive_elem); | |
490 | root_naive = bt_ctf_field_type_array_create(root_naive_elem, 17); | |
491 | assert(root_naive); | |
492 | ret = bt_ctf_field_type_structure_add_field(root, root_naive, "naive"); | |
493 | assert(ret == 0); | |
494 | root_clover = bt_ctf_field_type_structure_create(); | |
495 | assert(root_clover); | |
496 | ret = bt_ctf_field_type_set_alignment(root_clover, 1); | |
497 | assert(ret == 0); | |
498 | root_clover_oval = bt_ctf_field_type_integer_create(17); | |
499 | assert(root_clover_oval); | |
500 | ret = bt_ctf_field_type_integer_set_signed(root_clover_oval, 0); | |
501 | assert(ret == 0); | |
502 | ret = bt_ctf_field_type_integer_set_base(root_clover_oval, 10); | |
503 | assert(ret == 0); | |
b28a86ad | 504 | ret = bt_ctf_field_type_integer_set_encoding(root_clover_oval, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
505 | assert(ret == 0); |
506 | ret = bt_ctf_field_type_set_byte_order(root_clover_oval, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
507 | assert(ret == 0); | |
508 | ret = bt_ctf_field_type_set_alignment(root_clover_oval, 1); | |
509 | assert(ret == 0); | |
510 | ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_oval, "oval"); | |
511 | assert(ret == 0); | |
512 | root_clover_whole = bt_ctf_field_type_variant_create(NULL, "iron.parallel"); | |
513 | assert(root_clover_whole); | |
514 | root_clover_whole_BLUE_elem = bt_ctf_field_type_string_create(); | |
515 | assert(root_clover_whole_BLUE_elem); | |
b28a86ad | 516 | ret = bt_ctf_field_type_string_set_encoding(root_clover_whole_BLUE_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
517 | assert(ret == 0); |
518 | root_clover_whole_BLUE = bt_ctf_field_type_sequence_create(root_clover_whole_BLUE_elem, "trace.packet.header.iron.fire.word"); | |
519 | assert(root_clover_whole_BLUE); | |
520 | ret = bt_ctf_field_type_variant_add_field(root_clover_whole, root_clover_whole_BLUE, "BLUE"); | |
521 | assert(ret == 0); | |
522 | root_clover_whole_RED = bt_ctf_field_type_integer_create(44); | |
523 | assert(root_clover_whole_RED); | |
524 | ret = bt_ctf_field_type_integer_set_signed(root_clover_whole_RED, 0); | |
525 | assert(ret == 0); | |
526 | ret = bt_ctf_field_type_integer_set_base(root_clover_whole_RED, 10); | |
527 | assert(ret == 0); | |
b28a86ad | 528 | ret = bt_ctf_field_type_integer_set_encoding(root_clover_whole_RED, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
529 | assert(ret == 0); |
530 | ret = bt_ctf_field_type_set_byte_order(root_clover_whole_RED, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
531 | assert(ret == 0); | |
532 | ret = bt_ctf_field_type_set_alignment(root_clover_whole_RED, 1); | |
533 | assert(ret == 0); | |
534 | ret = bt_ctf_field_type_variant_add_field(root_clover_whole, root_clover_whole_RED, "RED"); | |
535 | assert(ret == 0); | |
536 | root_clover_whole_YELLOW = bt_ctf_field_type_string_create(); | |
537 | assert(root_clover_whole_YELLOW); | |
b28a86ad | 538 | ret = bt_ctf_field_type_string_set_encoding(root_clover_whole_YELLOW, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
539 | assert(ret == 0); |
540 | ret = bt_ctf_field_type_variant_add_field(root_clover_whole, root_clover_whole_YELLOW, "YELLOW"); | |
541 | assert(ret == 0); | |
542 | ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_whole, "whole"); | |
543 | assert(ret == 0); | |
544 | root_clover_egg_elem = bt_ctf_field_type_integer_create(55); | |
545 | assert(root_clover_egg_elem); | |
546 | ret = bt_ctf_field_type_integer_set_signed(root_clover_egg_elem, 0); | |
547 | assert(ret == 0); | |
548 | ret = bt_ctf_field_type_integer_set_base(root_clover_egg_elem, 10); | |
549 | assert(ret == 0); | |
b28a86ad | 550 | ret = bt_ctf_field_type_integer_set_encoding(root_clover_egg_elem, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
551 | assert(ret == 0); |
552 | ret = bt_ctf_field_type_set_byte_order(root_clover_egg_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
553 | assert(ret == 0); | |
554 | ret = bt_ctf_field_type_set_alignment(root_clover_egg_elem, 1); | |
555 | assert(ret == 0); | |
556 | root_clover_egg = bt_ctf_field_type_sequence_create(root_clover_egg_elem, "stream.packet.context.clover.oval"); | |
557 | assert(root_clover_egg); | |
558 | ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_egg, "egg"); | |
559 | assert(ret == 0); | |
560 | root_clover_square_int = bt_ctf_field_type_integer_create(12); | |
561 | assert(root_clover_square_int); | |
562 | ret = bt_ctf_field_type_integer_set_signed(root_clover_square_int, 0); | |
563 | assert(ret == 0); | |
564 | ret = bt_ctf_field_type_integer_set_base(root_clover_square_int, 10); | |
565 | assert(ret == 0); | |
b28a86ad | 566 | ret = bt_ctf_field_type_integer_set_encoding(root_clover_square_int, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
567 | assert(ret == 0); |
568 | ret = bt_ctf_field_type_set_byte_order(root_clover_square_int, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
569 | assert(ret == 0); | |
570 | ret = bt_ctf_field_type_set_alignment(root_clover_square_int, 1); | |
571 | assert(ret == 0); | |
572 | root_clover_square = bt_ctf_field_type_enumeration_create(root_clover_square_int); | |
573 | assert(root_clover_square); | |
574 | ret = bt_ctf_field_type_enumeration_add_mapping(root_clover_square, "YOUNG", 0, 0); | |
575 | assert(ret == 0); | |
576 | ret = bt_ctf_field_type_enumeration_add_mapping(root_clover_square, "OLD", 1, 1); | |
577 | assert(ret == 0); | |
578 | ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_square, "square"); | |
579 | assert(ret == 0); | |
580 | root_clover_useful_elem = bt_ctf_field_type_integer_create(2); | |
581 | assert(root_clover_useful_elem); | |
582 | ret = bt_ctf_field_type_integer_set_signed(root_clover_useful_elem, 0); | |
583 | assert(ret == 0); | |
584 | ret = bt_ctf_field_type_integer_set_base(root_clover_useful_elem, 10); | |
585 | assert(ret == 0); | |
b28a86ad | 586 | ret = bt_ctf_field_type_integer_set_encoding(root_clover_useful_elem, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
587 | assert(ret == 0); |
588 | ret = bt_ctf_field_type_set_byte_order(root_clover_useful_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
589 | assert(ret == 0); | |
590 | ret = bt_ctf_field_type_set_alignment(root_clover_useful_elem, 1); | |
591 | assert(ret == 0); | |
592 | root_clover_useful = bt_ctf_field_type_sequence_create(root_clover_useful_elem, "serious"); | |
593 | assert(root_clover_useful); | |
594 | ret = bt_ctf_field_type_structure_add_field(root_clover, root_clover_useful, "useful"); | |
595 | assert(ret == 0); | |
596 | ret = bt_ctf_field_type_structure_add_field(root, root_clover, "clover"); | |
597 | assert(ret == 0); | |
598 | root_tart = bt_ctf_field_type_string_create(); | |
599 | assert(root_tart); | |
b28a86ad | 600 | ret = bt_ctf_field_type_string_set_encoding(root_tart, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
601 | assert(ret == 0); |
602 | ret = bt_ctf_field_type_structure_add_field(root, root_tart, "tart"); | |
603 | assert(ret == 0); | |
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 | ||
630 | static | |
631 | struct bt_ctf_field_type *get_good_event_header_type(void) | |
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 | ||
680 | struct bt_ctf_field_type *root = NULL; | |
681 | struct bt_ctf_field_type *root_id = NULL; | |
682 | struct bt_ctf_field_type *root_timestamp = NULL; | |
683 | struct bt_ctf_field_type *root_action = NULL; | |
684 | struct bt_ctf_field_type *root_action_special = NULL; | |
685 | struct bt_ctf_field_type *root_action_lucky = NULL; | |
686 | struct bt_ctf_field_type *root_action_lucky_elem = NULL; | |
687 | struct bt_ctf_field_type *root_action_dream = NULL; | |
688 | struct bt_ctf_field_type *root_action_grandiose = NULL; | |
689 | struct bt_ctf_field_type *root_action_grandiose_elem = NULL; | |
690 | struct bt_ctf_field_type *root_stiff = NULL; | |
691 | struct bt_ctf_field_type *root_stiff_elem = NULL; | |
692 | struct bt_ctf_field_type *root_fruit = NULL; | |
693 | struct bt_ctf_field_type *root_fruit_apple = NULL; | |
694 | struct bt_ctf_field_type *root_fruit_apple_elem = NULL; | |
695 | ||
696 | int ret; | |
697 | root = bt_ctf_field_type_structure_create(); | |
698 | assert(root); | |
699 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
700 | assert(ret == 0); | |
701 | root_id = bt_ctf_field_type_integer_create(17); | |
702 | assert(root_id); | |
703 | ret = bt_ctf_field_type_integer_set_signed(root_id, 0); | |
704 | assert(ret == 0); | |
705 | ret = bt_ctf_field_type_integer_set_base(root_id, 10); | |
706 | assert(ret == 0); | |
b28a86ad | 707 | ret = bt_ctf_field_type_integer_set_encoding(root_id, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
708 | assert(ret == 0); |
709 | ret = bt_ctf_field_type_set_byte_order(root_id, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
710 | assert(ret == 0); | |
711 | ret = bt_ctf_field_type_set_alignment(root_id, 1); | |
712 | assert(ret == 0); | |
713 | ret = bt_ctf_field_type_structure_add_field(root, root_id, "id"); | |
714 | assert(ret == 0); | |
715 | root_timestamp = bt_ctf_field_type_integer_create(64); | |
716 | assert(root_timestamp); | |
717 | ret = bt_ctf_field_type_integer_set_signed(root_timestamp, 0); | |
718 | assert(ret == 0); | |
719 | ret = bt_ctf_field_type_integer_set_base(root_timestamp, 10); | |
720 | assert(ret == 0); | |
b28a86ad | 721 | ret = bt_ctf_field_type_integer_set_encoding(root_timestamp, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
722 | assert(ret == 0); |
723 | ret = bt_ctf_field_type_set_byte_order(root_timestamp, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
724 | assert(ret == 0); | |
725 | ret = bt_ctf_field_type_set_alignment(root_timestamp, 8); | |
726 | assert(ret == 0); | |
727 | ret = bt_ctf_field_type_structure_add_field(root, root_timestamp, "timestamp"); | |
728 | assert(ret == 0); | |
729 | root_action = bt_ctf_field_type_structure_create(); | |
730 | assert(root_action); | |
731 | ret = bt_ctf_field_type_set_alignment(root_action, 8); | |
732 | assert(ret == 0); | |
733 | root_action_special = bt_ctf_field_type_integer_create(17); | |
734 | assert(root_action_special); | |
735 | ret = bt_ctf_field_type_integer_set_signed(root_action_special, 0); | |
736 | assert(ret == 0); | |
737 | ret = bt_ctf_field_type_integer_set_base(root_action_special, 10); | |
738 | assert(ret == 0); | |
b28a86ad | 739 | ret = bt_ctf_field_type_integer_set_encoding(root_action_special, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
740 | assert(ret == 0); |
741 | ret = bt_ctf_field_type_set_byte_order(root_action_special, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
742 | assert(ret == 0); | |
743 | ret = bt_ctf_field_type_set_alignment(root_action_special, 1); | |
744 | assert(ret == 0); | |
745 | ret = bt_ctf_field_type_structure_add_field(root_action, root_action_special, "special"); | |
746 | assert(ret == 0); | |
747 | root_action_lucky_elem = bt_ctf_field_type_string_create(); | |
748 | assert(root_action_lucky_elem); | |
b28a86ad | 749 | ret = bt_ctf_field_type_string_set_encoding(root_action_lucky_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
750 | assert(ret == 0); |
751 | root_action_lucky = bt_ctf_field_type_sequence_create(root_action_lucky_elem, "stream.packet.context.placid"); | |
752 | assert(root_action_lucky); | |
753 | ret = bt_ctf_field_type_structure_add_field(root_action, root_action_lucky, "lucky"); | |
754 | assert(ret == 0); | |
755 | root_action_dream = bt_ctf_field_type_string_create(); | |
756 | assert(root_action_dream); | |
b28a86ad | 757 | ret = bt_ctf_field_type_string_set_encoding(root_action_dream, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
758 | assert(ret == 0); |
759 | ret = bt_ctf_field_type_structure_add_field(root_action, root_action_dream, "dream"); | |
760 | assert(ret == 0); | |
761 | root_action_grandiose_elem = bt_ctf_field_type_integer_create(3); | |
762 | assert(root_action_grandiose_elem); | |
763 | ret = bt_ctf_field_type_integer_set_signed(root_action_grandiose_elem, 0); | |
764 | assert(ret == 0); | |
765 | ret = bt_ctf_field_type_integer_set_base(root_action_grandiose_elem, 10); | |
766 | assert(ret == 0); | |
b28a86ad | 767 | ret = bt_ctf_field_type_integer_set_encoding(root_action_grandiose_elem, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
768 | assert(ret == 0); |
769 | ret = bt_ctf_field_type_set_byte_order(root_action_grandiose_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
770 | assert(ret == 0); | |
771 | ret = bt_ctf_field_type_set_alignment(root_action_grandiose_elem, 1); | |
772 | assert(ret == 0); | |
773 | root_action_grandiose = bt_ctf_field_type_sequence_create(root_action_grandiose_elem, "trace.packet.header.serious"); | |
774 | assert(root_action_grandiose); | |
775 | ret = bt_ctf_field_type_structure_add_field(root_action, root_action_grandiose, "grandiose"); | |
776 | assert(ret == 0); | |
777 | ret = bt_ctf_field_type_structure_add_field(root, root_action, "action"); | |
778 | assert(ret == 0); | |
779 | root_stiff_elem = bt_ctf_field_type_string_create(); | |
780 | assert(root_stiff_elem); | |
b28a86ad | 781 | ret = bt_ctf_field_type_string_set_encoding(root_stiff_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
782 | assert(ret == 0); |
783 | root_stiff = bt_ctf_field_type_sequence_create(root_stiff_elem, "clover.whole.RED"); | |
784 | assert(root_stiff); | |
785 | ret = bt_ctf_field_type_structure_add_field(root, root_stiff, "stiff"); | |
786 | assert(ret == 0); | |
787 | root_fruit = bt_ctf_field_type_structure_create(); | |
788 | assert(root_fruit); | |
789 | ret = bt_ctf_field_type_set_alignment(root_fruit, 1); | |
790 | assert(ret == 0); | |
791 | root_fruit_apple_elem = bt_ctf_field_type_integer_create(5); | |
792 | assert(root_fruit_apple_elem); | |
793 | ret = bt_ctf_field_type_integer_set_signed(root_fruit_apple_elem, 0); | |
794 | assert(ret == 0); | |
795 | ret = bt_ctf_field_type_integer_set_base(root_fruit_apple_elem, 10); | |
796 | assert(ret == 0); | |
b28a86ad | 797 | ret = bt_ctf_field_type_integer_set_encoding(root_fruit_apple_elem, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
798 | assert(ret == 0); |
799 | ret = bt_ctf_field_type_set_byte_order(root_fruit_apple_elem, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
800 | assert(ret == 0); | |
801 | ret = bt_ctf_field_type_set_alignment(root_fruit_apple_elem, 1); | |
802 | assert(ret == 0); | |
803 | root_fruit_apple = bt_ctf_field_type_sequence_create(root_fruit_apple_elem, "action.special"); | |
804 | assert(root_fruit_apple); | |
805 | ret = bt_ctf_field_type_structure_add_field(root_fruit, root_fruit_apple, "apple"); | |
806 | assert(ret == 0); | |
807 | ret = bt_ctf_field_type_structure_add_field(root, root_fruit, "fruit"); | |
808 | assert(ret == 0); | |
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 | ||
828 | static | |
829 | struct bt_ctf_field_type *get_good_stream_event_context_type(void) | |
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 | ||
877 | struct bt_ctf_field_type *root = NULL; | |
878 | struct bt_ctf_field_type *root_face = NULL; | |
879 | struct bt_ctf_field_type *root_face_branch = NULL; | |
880 | struct bt_ctf_field_type *root_face_branch_elem = NULL; | |
881 | struct bt_ctf_field_type *root_face_income = NULL; | |
882 | struct bt_ctf_field_type *root_face_income_elem = NULL; | |
883 | struct bt_ctf_field_type *root_face_magic = NULL; | |
884 | struct bt_ctf_field_type *root_face_lucky = NULL; | |
885 | struct bt_ctf_field_type *root_face_lucky_elem = NULL; | |
886 | struct bt_ctf_field_type *root_cats = NULL; | |
887 | struct bt_ctf_field_type *root_dream = NULL; | |
888 | struct bt_ctf_field_type *root_dream_elem = NULL; | |
889 | struct bt_ctf_field_type *root_dream_elem_elem = NULL; | |
890 | struct bt_ctf_field_type *root_dream_elem_elem_elem = NULL; | |
891 | struct bt_ctf_field_type *root_stream_id = NULL; | |
892 | ||
893 | int ret; | |
894 | root = bt_ctf_field_type_structure_create(); | |
895 | assert(root); | |
896 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
897 | assert(ret == 0); | |
898 | root_face = bt_ctf_field_type_structure_create(); | |
899 | assert(root_face); | |
900 | ret = bt_ctf_field_type_set_alignment(root_face, 8); | |
901 | assert(ret == 0); | |
902 | root_face_branch_elem = bt_ctf_field_type_string_create(); | |
903 | assert(root_face_branch_elem); | |
b28a86ad | 904 | ret = bt_ctf_field_type_string_set_encoding(root_face_branch_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
905 | assert(ret == 0); |
906 | root_face_branch = bt_ctf_field_type_sequence_create(root_face_branch_elem, "serious"); | |
907 | assert(root_face_branch); | |
908 | ret = bt_ctf_field_type_structure_add_field(root_face, root_face_branch, "branch"); | |
909 | assert(ret == 0); | |
910 | root_face_income_elem = bt_ctf_field_type_string_create(); | |
911 | assert(root_face_income_elem); | |
b28a86ad | 912 | ret = bt_ctf_field_type_string_set_encoding(root_face_income_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
913 | assert(ret == 0); |
914 | root_face_income = bt_ctf_field_type_sequence_create(root_face_income_elem, "magic"); | |
915 | assert(root_face_income); | |
916 | ret = bt_ctf_field_type_structure_add_field(root_face, root_face_income, "income"); | |
917 | assert(ret == 0); | |
918 | root_face_magic = bt_ctf_field_type_integer_create(23); | |
919 | assert(root_face_magic); | |
920 | ret = bt_ctf_field_type_integer_set_signed(root_face_magic, 0); | |
921 | assert(ret == 0); | |
922 | ret = bt_ctf_field_type_integer_set_base(root_face_magic, 10); | |
923 | assert(ret == 0); | |
b28a86ad | 924 | ret = bt_ctf_field_type_integer_set_encoding(root_face_magic, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
925 | assert(ret == 0); |
926 | ret = bt_ctf_field_type_set_byte_order(root_face_magic, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
927 | assert(ret == 0); | |
928 | ret = bt_ctf_field_type_set_alignment(root_face_magic, 1); | |
929 | assert(ret == 0); | |
930 | ret = bt_ctf_field_type_structure_add_field(root_face, root_face_magic, "magic"); | |
931 | assert(ret == 0); | |
932 | root_face_lucky_elem = bt_ctf_field_type_string_create(); | |
933 | assert(root_face_lucky_elem); | |
b28a86ad | 934 | ret = bt_ctf_field_type_string_set_encoding(root_face_lucky_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
935 | assert(ret == 0); |
936 | root_face_lucky = bt_ctf_field_type_sequence_create(root_face_lucky_elem, "magic"); | |
937 | assert(root_face_lucky); | |
938 | ret = bt_ctf_field_type_structure_add_field(root_face, root_face_lucky, "lucky"); | |
939 | assert(ret == 0); | |
940 | ret = bt_ctf_field_type_structure_add_field(root, root_face, "face"); | |
941 | assert(ret == 0); | |
942 | root_cats = bt_ctf_field_type_integer_create(5); | |
943 | assert(root_cats); | |
944 | ret = bt_ctf_field_type_integer_set_signed(root_cats, 0); | |
945 | assert(ret == 0); | |
946 | ret = bt_ctf_field_type_integer_set_base(root_cats, 10); | |
947 | assert(ret == 0); | |
b28a86ad | 948 | ret = bt_ctf_field_type_integer_set_encoding(root_cats, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
949 | assert(ret == 0); |
950 | ret = bt_ctf_field_type_set_byte_order(root_cats, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
951 | assert(ret == 0); | |
952 | ret = bt_ctf_field_type_set_alignment(root_cats, 1); | |
953 | assert(ret == 0); | |
954 | ret = bt_ctf_field_type_structure_add_field(root, root_cats, "cats"); | |
955 | assert(ret == 0); | |
956 | root_dream_elem_elem_elem = bt_ctf_field_type_string_create(); | |
957 | assert(root_dream_elem_elem_elem); | |
b28a86ad | 958 | ret = bt_ctf_field_type_string_set_encoding(root_dream_elem_elem_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
959 | assert(ret == 0); |
960 | root_dream_elem_elem = bt_ctf_field_type_sequence_create(root_dream_elem_elem_elem, "stream.event.context.face.magic"); | |
961 | assert(root_dream_elem_elem); | |
962 | root_dream_elem = bt_ctf_field_type_sequence_create(root_dream_elem_elem, "trace.packet.header.iron.dust"); | |
963 | assert(root_dream_elem); | |
964 | root_dream = bt_ctf_field_type_sequence_create(root_dream_elem, "stream.packet.context.placid"); | |
965 | assert(root_dream); | |
966 | ret = bt_ctf_field_type_structure_add_field(root, root_dream, "dream"); | |
967 | assert(ret == 0); | |
968 | root_stream_id = bt_ctf_field_type_integer_create(9); | |
969 | assert(root_stream_id); | |
970 | ret = bt_ctf_field_type_integer_set_signed(root_stream_id, 0); | |
971 | assert(ret == 0); | |
972 | ret = bt_ctf_field_type_integer_set_base(root_stream_id, 10); | |
973 | assert(ret == 0); | |
b28a86ad | 974 | ret = bt_ctf_field_type_integer_set_encoding(root_stream_id, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
975 | assert(ret == 0); |
976 | ret = bt_ctf_field_type_set_byte_order(root_stream_id, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
977 | assert(ret == 0); | |
978 | ret = bt_ctf_field_type_set_alignment(root_stream_id, 1); | |
979 | assert(ret == 0); | |
980 | ret = bt_ctf_field_type_structure_add_field(root, root_stream_id, "stream_id"); | |
981 | assert(ret == 0); | |
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 | ||
1001 | static | |
1002 | struct bt_ctf_field_type *get_good_event_context_type(void) | |
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 | ||
1082 | struct bt_ctf_field_type *root = NULL; | |
1083 | struct bt_ctf_field_type *root_film = NULL; | |
1084 | struct bt_ctf_field_type *root_berry = NULL; | |
1085 | struct bt_ctf_field_type *root_berry_pine = NULL; | |
1086 | struct bt_ctf_field_type *root_berry_pine_elem = NULL; | |
1087 | struct bt_ctf_field_type *root_berry_porter = NULL; | |
1088 | struct bt_ctf_field_type *root_berry_porter_elem = NULL; | |
1089 | struct bt_ctf_field_type *root_berry_mice = NULL; | |
1090 | struct bt_ctf_field_type *root_berry_mice_elem = NULL; | |
1091 | struct bt_ctf_field_type *root_berry_third = NULL; | |
1092 | struct bt_ctf_field_type *root_berry_guard = NULL; | |
1093 | struct bt_ctf_field_type *root_berry_guard_elem = NULL; | |
1094 | struct bt_ctf_field_type *root_berry_one = NULL; | |
1095 | struct bt_ctf_field_type *root_berry_one_elem = NULL; | |
1096 | struct bt_ctf_field_type *root_cats = NULL; | |
1097 | struct bt_ctf_field_type *root_loud = NULL; | |
1098 | struct bt_ctf_field_type *root_loud_toys = NULL; | |
1099 | struct bt_ctf_field_type *root_loud_toys_elem = NULL; | |
1100 | struct bt_ctf_field_type *root_loud_spoon = NULL; | |
1101 | struct bt_ctf_field_type *root_loud_spoon_elem = NULL; | |
1102 | struct bt_ctf_field_type *root_loud_turkey = NULL; | |
1103 | struct bt_ctf_field_type *root_loud_turkey_elem = NULL; | |
1104 | struct bt_ctf_field_type *root_loud_inform = NULL; | |
1105 | struct bt_ctf_field_type *root_loud_inform_elem = NULL; | |
1106 | struct bt_ctf_field_type *root_loud_odd = NULL; | |
1107 | struct bt_ctf_field_type *root_loud_odd_elem = NULL; | |
1108 | struct bt_ctf_field_type *root_loud_amuck = NULL; | |
1109 | struct bt_ctf_field_type *root_loud_amuck_elem = NULL; | |
1110 | ||
1111 | int ret; | |
1112 | root = bt_ctf_field_type_structure_create(); | |
1113 | assert(root); | |
1114 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
1115 | assert(ret == 0); | |
1116 | root_film = bt_ctf_field_type_integer_create(19); | |
1117 | assert(root_film); | |
1118 | ret = bt_ctf_field_type_integer_set_signed(root_film, 0); | |
1119 | assert(ret == 0); | |
1120 | ret = bt_ctf_field_type_integer_set_base(root_film, 10); | |
1121 | assert(ret == 0); | |
b28a86ad | 1122 | ret = bt_ctf_field_type_integer_set_encoding(root_film, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
1123 | assert(ret == 0); |
1124 | ret = bt_ctf_field_type_set_byte_order(root_film, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
1125 | assert(ret == 0); | |
1126 | ret = bt_ctf_field_type_set_alignment(root_film, 1); | |
1127 | assert(ret == 0); | |
1128 | ret = bt_ctf_field_type_structure_add_field(root, root_film, "film"); | |
1129 | assert(ret == 0); | |
1130 | root_berry = bt_ctf_field_type_structure_create(); | |
1131 | assert(root_berry); | |
1132 | ret = bt_ctf_field_type_set_alignment(root_berry, 8); | |
1133 | assert(ret == 0); | |
1134 | root_berry_pine_elem = bt_ctf_field_type_string_create(); | |
1135 | assert(root_berry_pine_elem); | |
b28a86ad | 1136 | ret = bt_ctf_field_type_string_set_encoding(root_berry_pine_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1137 | assert(ret == 0); |
1138 | root_berry_pine = bt_ctf_field_type_sequence_create(root_berry_pine_elem, "stream_id"); | |
1139 | assert(root_berry_pine); | |
1140 | ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_pine, "pine"); | |
1141 | assert(ret == 0); | |
1142 | root_berry_porter_elem = bt_ctf_field_type_string_create(); | |
1143 | assert(root_berry_porter_elem); | |
b28a86ad | 1144 | ret = bt_ctf_field_type_string_set_encoding(root_berry_porter_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1145 | assert(ret == 0); |
1146 | root_berry_porter = bt_ctf_field_type_sequence_create(root_berry_porter_elem, "face.magic"); | |
1147 | assert(root_berry_porter); | |
1148 | ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_porter, "porter"); | |
1149 | assert(ret == 0); | |
1150 | root_berry_mice_elem = bt_ctf_field_type_string_create(); | |
1151 | assert(root_berry_mice_elem); | |
b28a86ad | 1152 | ret = bt_ctf_field_type_string_set_encoding(root_berry_mice_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1153 | assert(ret == 0); |
1154 | root_berry_mice = bt_ctf_field_type_sequence_create(root_berry_mice_elem, "action.special"); | |
1155 | assert(root_berry_mice); | |
1156 | ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_mice, "mice"); | |
1157 | assert(ret == 0); | |
1158 | root_berry_third = bt_ctf_field_type_integer_create(18); | |
1159 | assert(root_berry_third); | |
1160 | ret = bt_ctf_field_type_integer_set_signed(root_berry_third, 0); | |
1161 | assert(ret == 0); | |
1162 | ret = bt_ctf_field_type_integer_set_base(root_berry_third, 10); | |
1163 | assert(ret == 0); | |
b28a86ad | 1164 | ret = bt_ctf_field_type_integer_set_encoding(root_berry_third, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
1165 | assert(ret == 0); |
1166 | ret = bt_ctf_field_type_set_byte_order(root_berry_third, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
1167 | assert(ret == 0); | |
1168 | ret = bt_ctf_field_type_set_alignment(root_berry_third, 1); | |
1169 | assert(ret == 0); | |
1170 | ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_third, "third"); | |
1171 | assert(ret == 0); | |
1172 | root_berry_guard_elem = bt_ctf_field_type_string_create(); | |
1173 | assert(root_berry_guard_elem); | |
b28a86ad | 1174 | ret = bt_ctf_field_type_string_set_encoding(root_berry_guard_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1175 | assert(ret == 0); |
1176 | root_berry_guard = bt_ctf_field_type_sequence_create(root_berry_guard_elem, "clover.oval"); | |
1177 | assert(root_berry_guard); | |
1178 | ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_guard, "guard"); | |
1179 | assert(ret == 0); | |
1180 | root_berry_one_elem = bt_ctf_field_type_string_create(); | |
1181 | assert(root_berry_one_elem); | |
b28a86ad | 1182 | ret = bt_ctf_field_type_string_set_encoding(root_berry_one_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1183 | assert(ret == 0); |
1184 | root_berry_one = bt_ctf_field_type_sequence_create(root_berry_one_elem, "iron.fire.word"); | |
1185 | assert(root_berry_one); | |
1186 | ret = bt_ctf_field_type_structure_add_field(root_berry, root_berry_one, "one"); | |
1187 | assert(ret == 0); | |
1188 | ret = bt_ctf_field_type_structure_add_field(root, root_berry, "berry"); | |
1189 | assert(ret == 0); | |
1190 | root_cats = bt_ctf_field_type_integer_create(55); | |
1191 | assert(root_cats); | |
1192 | ret = bt_ctf_field_type_integer_set_signed(root_cats, 0); | |
1193 | assert(ret == 0); | |
1194 | ret = bt_ctf_field_type_integer_set_base(root_cats, 10); | |
1195 | assert(ret == 0); | |
b28a86ad | 1196 | ret = bt_ctf_field_type_integer_set_encoding(root_cats, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
1197 | assert(ret == 0); |
1198 | ret = bt_ctf_field_type_set_byte_order(root_cats, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
1199 | assert(ret == 0); | |
1200 | ret = bt_ctf_field_type_set_alignment(root_cats, 1); | |
1201 | assert(ret == 0); | |
1202 | ret = bt_ctf_field_type_structure_add_field(root, root_cats, "cats"); | |
1203 | assert(ret == 0); | |
1204 | root_loud = bt_ctf_field_type_structure_create(); | |
1205 | assert(root_loud); | |
1206 | ret = bt_ctf_field_type_set_alignment(root_loud, 8); | |
1207 | assert(ret == 0); | |
1208 | root_loud_toys_elem = bt_ctf_field_type_string_create(); | |
1209 | assert(root_loud_toys_elem); | |
b28a86ad | 1210 | ret = bt_ctf_field_type_string_set_encoding(root_loud_toys_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1211 | assert(ret == 0); |
1212 | root_loud_toys = bt_ctf_field_type_sequence_create(root_loud_toys_elem, "trace.packet.header.iron.fire.word"); | |
1213 | assert(root_loud_toys); | |
1214 | ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_toys, "toys"); | |
1215 | assert(ret == 0); | |
1216 | root_loud_spoon_elem = bt_ctf_field_type_string_create(); | |
1217 | assert(root_loud_spoon_elem); | |
b28a86ad | 1218 | ret = bt_ctf_field_type_string_set_encoding(root_loud_spoon_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1219 | assert(ret == 0); |
1220 | root_loud_spoon = bt_ctf_field_type_sequence_create(root_loud_spoon_elem, "stream.packet.context.clover.oval"); | |
1221 | assert(root_loud_spoon); | |
1222 | ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_spoon, "spoon"); | |
1223 | assert(ret == 0); | |
1224 | root_loud_turkey_elem = bt_ctf_field_type_string_create(); | |
1225 | assert(root_loud_turkey_elem); | |
b28a86ad | 1226 | ret = bt_ctf_field_type_string_set_encoding(root_loud_turkey_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1227 | assert(ret == 0); |
1228 | root_loud_turkey = bt_ctf_field_type_sequence_create(root_loud_turkey_elem, "stream.event.header.action.special"); | |
1229 | assert(root_loud_turkey); | |
1230 | ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_turkey, "turkey"); | |
1231 | assert(ret == 0); | |
1232 | root_loud_inform_elem = bt_ctf_field_type_string_create(); | |
1233 | assert(root_loud_inform_elem); | |
b28a86ad | 1234 | ret = bt_ctf_field_type_string_set_encoding(root_loud_inform_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1235 | assert(ret == 0); |
1236 | root_loud_inform = bt_ctf_field_type_sequence_create(root_loud_inform_elem, "stream.event.context.face.magic"); | |
1237 | assert(root_loud_inform); | |
1238 | ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_inform, "inform"); | |
1239 | assert(ret == 0); | |
1240 | root_loud_odd_elem = bt_ctf_field_type_string_create(); | |
1241 | assert(root_loud_odd_elem); | |
b28a86ad | 1242 | ret = bt_ctf_field_type_string_set_encoding(root_loud_odd_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1243 | assert(ret == 0); |
1244 | root_loud_odd = bt_ctf_field_type_sequence_create(root_loud_odd_elem, "berry.third"); | |
1245 | assert(root_loud_odd); | |
1246 | ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_odd, "odd"); | |
1247 | assert(ret == 0); | |
1248 | root_loud_amuck_elem = bt_ctf_field_type_string_create(); | |
1249 | assert(root_loud_amuck_elem); | |
b28a86ad | 1250 | ret = bt_ctf_field_type_string_set_encoding(root_loud_amuck_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1251 | assert(ret == 0); |
1252 | root_loud_amuck = bt_ctf_field_type_sequence_create(root_loud_amuck_elem, "event.context.film"); | |
1253 | assert(root_loud_amuck); | |
1254 | ret = bt_ctf_field_type_structure_add_field(root_loud, root_loud_amuck, "amuck"); | |
1255 | assert(ret == 0); | |
1256 | ret = bt_ctf_field_type_structure_add_field(root, root_loud, "loud"); | |
1257 | assert(ret == 0); | |
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 | ||
1290 | static | |
1291 | struct bt_ctf_field_type *get_good_event_payload_type(void) | |
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 | ||
1380 | struct bt_ctf_field_type *root = NULL; | |
1381 | struct bt_ctf_field_type *root_splendid = NULL; | |
1382 | struct bt_ctf_field_type *root_relative = NULL; | |
1383 | struct bt_ctf_field_type *root_relative_equal = NULL; | |
1384 | struct bt_ctf_field_type *root_relative_equal_elem = NULL; | |
1385 | struct bt_ctf_field_type *root_relative_amuck = NULL; | |
1386 | struct bt_ctf_field_type *root_relative_amuck_elem = NULL; | |
1387 | struct bt_ctf_field_type *root_relative_push = NULL; | |
1388 | struct bt_ctf_field_type *root_relative_push_elem = NULL; | |
1389 | struct bt_ctf_field_type *root_relative_brick = NULL; | |
1390 | struct bt_ctf_field_type *root_relative_brick_elem = NULL; | |
1391 | struct bt_ctf_field_type *root_relative_crush = NULL; | |
1392 | struct bt_ctf_field_type *root_relative_crush_elem = NULL; | |
1393 | struct bt_ctf_field_type *root_relative_canvas = NULL; | |
1394 | struct bt_ctf_field_type *root_relative_canvas_elem = NULL; | |
1395 | struct bt_ctf_field_type *root_absolute = NULL; | |
1396 | struct bt_ctf_field_type *root_absolute_equal = NULL; | |
1397 | struct bt_ctf_field_type *root_absolute_equal_elem = NULL; | |
1398 | struct bt_ctf_field_type *root_absolute_amuck = NULL; | |
1399 | struct bt_ctf_field_type *root_absolute_amuck_elem = NULL; | |
1400 | struct bt_ctf_field_type *root_absolute_push = NULL; | |
1401 | struct bt_ctf_field_type *root_absolute_push_elem = NULL; | |
1402 | struct bt_ctf_field_type *root_absolute_brick = NULL; | |
1403 | struct bt_ctf_field_type *root_absolute_brick_elem = NULL; | |
1404 | struct bt_ctf_field_type *root_absolute_crush = NULL; | |
1405 | struct bt_ctf_field_type *root_absolute_crush_elem = NULL; | |
1406 | struct bt_ctf_field_type *root_absolute_canvas = NULL; | |
1407 | struct bt_ctf_field_type *root_absolute_canvas_elem = NULL; | |
1408 | ||
1409 | int ret; | |
1410 | root = bt_ctf_field_type_structure_create(); | |
1411 | assert(root); | |
1412 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
1413 | assert(ret == 0); | |
1414 | root_splendid = bt_ctf_field_type_integer_create(12); | |
1415 | assert(root_splendid); | |
1416 | ret = bt_ctf_field_type_integer_set_signed(root_splendid, 0); | |
1417 | assert(ret == 0); | |
1418 | ret = bt_ctf_field_type_integer_set_base(root_splendid, 10); | |
1419 | assert(ret == 0); | |
b28a86ad | 1420 | ret = bt_ctf_field_type_integer_set_encoding(root_splendid, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
1421 | assert(ret == 0); |
1422 | ret = bt_ctf_field_type_set_byte_order(root_splendid, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
1423 | assert(ret == 0); | |
1424 | ret = bt_ctf_field_type_set_alignment(root_splendid, 1); | |
1425 | assert(ret == 0); | |
1426 | ret = bt_ctf_field_type_structure_add_field(root, root_splendid, "splendid"); | |
1427 | assert(ret == 0); | |
1428 | root_relative = bt_ctf_field_type_structure_create(); | |
1429 | assert(root_relative); | |
1430 | ret = bt_ctf_field_type_set_alignment(root_relative, 8); | |
1431 | assert(ret == 0); | |
1432 | root_relative_equal_elem = bt_ctf_field_type_string_create(); | |
1433 | assert(root_relative_equal_elem); | |
b28a86ad | 1434 | ret = bt_ctf_field_type_string_set_encoding(root_relative_equal_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1435 | assert(ret == 0); |
1436 | root_relative_equal = bt_ctf_field_type_sequence_create(root_relative_equal_elem, "splendid"); | |
1437 | assert(root_relative_equal); | |
1438 | ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_equal, "equal"); | |
1439 | assert(ret == 0); | |
1440 | root_relative_amuck_elem = bt_ctf_field_type_string_create(); | |
1441 | assert(root_relative_amuck_elem); | |
b28a86ad | 1442 | ret = bt_ctf_field_type_string_set_encoding(root_relative_amuck_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1443 | assert(ret == 0); |
1444 | root_relative_amuck = bt_ctf_field_type_sequence_create(root_relative_amuck_elem, "id"); | |
1445 | assert(root_relative_amuck); | |
1446 | ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_amuck, "amuck"); | |
1447 | assert(ret == 0); | |
1448 | root_relative_push_elem = bt_ctf_field_type_string_create(); | |
1449 | assert(root_relative_push_elem); | |
b28a86ad | 1450 | ret = bt_ctf_field_type_string_set_encoding(root_relative_push_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1451 | assert(ret == 0); |
1452 | root_relative_push = bt_ctf_field_type_sequence_create(root_relative_push_elem, "berry.third"); | |
1453 | assert(root_relative_push); | |
1454 | ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_push, "push"); | |
1455 | assert(ret == 0); | |
1456 | root_relative_brick_elem = bt_ctf_field_type_string_create(); | |
1457 | assert(root_relative_brick_elem); | |
b28a86ad | 1458 | ret = bt_ctf_field_type_string_set_encoding(root_relative_brick_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1459 | assert(ret == 0); |
1460 | root_relative_brick = bt_ctf_field_type_sequence_create(root_relative_brick_elem, "face.magic"); | |
1461 | assert(root_relative_brick); | |
1462 | ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_brick, "brick"); | |
1463 | assert(ret == 0); | |
1464 | root_relative_crush_elem = bt_ctf_field_type_string_create(); | |
1465 | assert(root_relative_crush_elem); | |
b28a86ad | 1466 | ret = bt_ctf_field_type_string_set_encoding(root_relative_crush_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1467 | assert(ret == 0); |
1468 | root_relative_crush = bt_ctf_field_type_sequence_create(root_relative_crush_elem, "serious"); | |
1469 | assert(root_relative_crush); | |
1470 | ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_crush, "crush"); | |
1471 | assert(ret == 0); | |
1472 | root_relative_canvas_elem = bt_ctf_field_type_string_create(); | |
1473 | assert(root_relative_canvas_elem); | |
b28a86ad | 1474 | ret = bt_ctf_field_type_string_set_encoding(root_relative_canvas_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1475 | assert(ret == 0); |
1476 | root_relative_canvas = bt_ctf_field_type_sequence_create(root_relative_canvas_elem, "iron.dust"); | |
1477 | assert(root_relative_canvas); | |
1478 | ret = bt_ctf_field_type_structure_add_field(root_relative, root_relative_canvas, "canvas"); | |
1479 | assert(ret == 0); | |
1480 | ret = bt_ctf_field_type_structure_add_field(root, root_relative, "relative"); | |
1481 | assert(ret == 0); | |
1482 | root_absolute = bt_ctf_field_type_structure_create(); | |
1483 | assert(root_absolute); | |
1484 | ret = bt_ctf_field_type_set_alignment(root_absolute, 8); | |
1485 | assert(ret == 0); | |
1486 | root_absolute_equal_elem = bt_ctf_field_type_string_create(); | |
1487 | assert(root_absolute_equal_elem); | |
b28a86ad | 1488 | ret = bt_ctf_field_type_string_set_encoding(root_absolute_equal_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1489 | assert(ret == 0); |
1490 | root_absolute_equal = bt_ctf_field_type_sequence_create(root_absolute_equal_elem, "event.fields.splendid"); | |
1491 | assert(root_absolute_equal); | |
1492 | ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_equal, "equal"); | |
1493 | assert(ret == 0); | |
1494 | root_absolute_amuck_elem = bt_ctf_field_type_string_create(); | |
1495 | assert(root_absolute_amuck_elem); | |
b28a86ad | 1496 | ret = bt_ctf_field_type_string_set_encoding(root_absolute_amuck_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1497 | assert(ret == 0); |
1498 | root_absolute_amuck = bt_ctf_field_type_sequence_create(root_absolute_amuck_elem, "stream.event.header.id"); | |
1499 | assert(root_absolute_amuck); | |
1500 | ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_amuck, "amuck"); | |
1501 | assert(ret == 0); | |
1502 | root_absolute_push_elem = bt_ctf_field_type_string_create(); | |
1503 | assert(root_absolute_push_elem); | |
b28a86ad | 1504 | ret = bt_ctf_field_type_string_set_encoding(root_absolute_push_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1505 | assert(ret == 0); |
1506 | root_absolute_push = bt_ctf_field_type_sequence_create(root_absolute_push_elem, "event.context.berry.third"); | |
1507 | assert(root_absolute_push); | |
1508 | ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_push, "push"); | |
1509 | assert(ret == 0); | |
1510 | root_absolute_brick_elem = bt_ctf_field_type_string_create(); | |
1511 | assert(root_absolute_brick_elem); | |
b28a86ad | 1512 | ret = bt_ctf_field_type_string_set_encoding(root_absolute_brick_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1513 | assert(ret == 0); |
1514 | root_absolute_brick = bt_ctf_field_type_sequence_create(root_absolute_brick_elem, "stream.event.context.face.magic"); | |
1515 | assert(root_absolute_brick); | |
1516 | ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_brick, "brick"); | |
1517 | assert(ret == 0); | |
1518 | root_absolute_crush_elem = bt_ctf_field_type_string_create(); | |
1519 | assert(root_absolute_crush_elem); | |
b28a86ad | 1520 | ret = bt_ctf_field_type_string_set_encoding(root_absolute_crush_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1521 | assert(ret == 0); |
1522 | root_absolute_crush = bt_ctf_field_type_sequence_create(root_absolute_crush_elem, "stream.packet.context.serious"); | |
1523 | assert(root_absolute_crush); | |
1524 | ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_crush, "crush"); | |
1525 | assert(ret == 0); | |
1526 | root_absolute_canvas_elem = bt_ctf_field_type_string_create(); | |
1527 | assert(root_absolute_canvas_elem); | |
b28a86ad | 1528 | ret = bt_ctf_field_type_string_set_encoding(root_absolute_canvas_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
1529 | assert(ret == 0); |
1530 | root_absolute_canvas = bt_ctf_field_type_sequence_create(root_absolute_canvas_elem, "trace.packet.header.iron.dust"); | |
1531 | assert(root_absolute_canvas); | |
1532 | ret = bt_ctf_field_type_structure_add_field(root_absolute, root_absolute_canvas, "canvas"); | |
1533 | assert(ret == 0); | |
1534 | ret = bt_ctf_field_type_structure_add_field(root, root_absolute, "absolute"); | |
1535 | assert(ret == 0); | |
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 | ||
1568 | static | |
1569 | struct bt_ctf_field_type *get_child_ft(struct bt_ctf_field_type *parent_ft, | |
1570 | const char *name) | |
1571 | { | |
1572 | struct bt_ctf_field_type *ft = NULL; | |
1573 | ||
1574 | switch (bt_ctf_field_type_get_type_id(parent_ft)) { | |
1575 | case CTF_TYPE_STRUCT: | |
1576 | ft = bt_ctf_field_type_structure_get_field_type_by_name( | |
1577 | parent_ft, name); | |
1578 | break; | |
1579 | ||
1580 | case CTF_TYPE_VARIANT: | |
1581 | ft = bt_ctf_field_type_variant_get_field_type_by_name( | |
1582 | parent_ft, name); | |
1583 | break; | |
1584 | ||
1585 | case CTF_TYPE_ARRAY: | |
1586 | ft = bt_ctf_field_type_array_get_element_type(parent_ft); | |
1587 | break; | |
1588 | ||
1589 | case CTF_TYPE_SEQUENCE: | |
1590 | ft = bt_ctf_field_type_sequence_get_element_type(parent_ft); | |
1591 | break; | |
1592 | ||
1593 | case CTF_TYPE_ENUM: | |
1594 | ft = bt_ctf_field_type_enumeration_get_container_type( | |
1595 | parent_ft); | |
1596 | break; | |
1597 | ||
1598 | default: | |
1599 | break; | |
1600 | } | |
1601 | ||
1602 | assert(ft); | |
1603 | ||
1604 | return ft; | |
1605 | } | |
1606 | ||
1607 | static | |
1608 | struct bt_ctf_field_type *get_ft(struct bt_ctf_field_type *root_ft, ...) | |
1609 | { | |
1610 | struct bt_ctf_field_type *child_ft = NULL; | |
1611 | struct bt_ctf_field_type *ft = root_ft; | |
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 | ||
1634 | end: | |
1635 | va_end(ap); | |
1636 | ||
1637 | return ft; | |
1638 | } | |
1639 | ||
1640 | #define FIELD_PATH_END -2 | |
1641 | ||
1642 | static | |
b28a86ad | 1643 | int validate_field_path(struct bt_ctf_field_type *field_type, int int_root, ...) |
0b93f4ea | 1644 | { |
b28a86ad | 1645 | enum bt_ctf_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; | |
b011f6b0 | 1651 | struct bt_ctf_field_path *field_path = NULL; |
0b93f4ea PP |
1652 | va_list ap; |
1653 | ||
b28a86ad | 1654 | va_start(ap, int_root); |
0b93f4ea | 1655 | if (bt_ctf_field_type_is_sequence(field_type)) { |
b011f6b0 PP |
1656 | field_path = bt_ctf_field_type_sequence_get_length_field_path( |
1657 | field_type); | |
0b93f4ea | 1658 | } else if (bt_ctf_field_type_is_variant(field_type)) { |
b011f6b0 PP |
1659 | field_path = bt_ctf_field_type_variant_get_tag_field_path( |
1660 | field_type); | |
0b93f4ea PP |
1661 | } |
1662 | ||
1663 | if (!field_path) { | |
1664 | ret = -1; | |
1665 | goto end; | |
1666 | } | |
1667 | ||
b74f1a20 | 1668 | if (bt_ctf_field_path_get_root_scope(field_path) != root) { |
0b93f4ea PP |
1669 | ret = -1; |
1670 | goto end; | |
1671 | } | |
1672 | ||
b011f6b0 | 1673 | len = bt_ctf_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 | ||
b011f6b0 | 1686 | actual_index = bt_ctf_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 | ||
1700 | end: | |
b011f6b0 | 1701 | BT_PUT(field_path); |
0b93f4ea PP |
1702 | va_end(ap); |
1703 | ||
1704 | return ret; | |
1705 | } | |
1706 | ||
1707 | static | |
1708 | void validate_test_pass(struct bt_ctf_trace *trace) | |
1709 | { | |
1710 | struct bt_ctf_stream_class *sc; | |
1711 | struct bt_ctf_event_class *ec; | |
1712 | struct bt_ctf_field_type *ph; | |
1713 | struct bt_ctf_field_type *pc; | |
1714 | struct bt_ctf_field_type *eh; | |
1715 | struct bt_ctf_field_type *sec; | |
1716 | struct bt_ctf_field_type *ectx; | |
1717 | struct bt_ctf_field_type *ep; | |
1718 | struct bt_ctf_field_type *ft_src = NULL; | |
1719 | struct bt_ctf_field_type *ft_target = NULL; | |
1720 | struct bt_ctf_field_type *ft_tag = NULL; | |
1721 | ||
9ac68eb1 | 1722 | sc = bt_ctf_trace_get_stream_class_by_index(trace, 0); |
0b93f4ea | 1723 | assert(sc); |
9ac68eb1 | 1724 | ec = bt_ctf_stream_class_get_event_class_by_index(sc, 0); |
0b93f4ea PP |
1725 | assert(ec); |
1726 | ||
1727 | ph = bt_ctf_trace_get_packet_header_type(trace); | |
1728 | ok(ph, "Trace packet header still exists after successful validation"); | |
1729 | pc = bt_ctf_stream_class_get_packet_context_type(sc); | |
1730 | ok(pc, "Stream packet context still exists after successful validation"); | |
1731 | eh = bt_ctf_stream_class_get_event_header_type(sc); | |
1732 | ok(eh, "Stream event header still exists after successful validation"); | |
1733 | sec = bt_ctf_stream_class_get_event_context_type(sc); | |
1734 | ok(sec, "Stream event context still exists after successful validation"); | |
1735 | ectx = bt_ctf_event_class_get_context_type(ec); | |
1736 | ok(ectx, "Event context still exists after successful validation"); | |
1737 | ep = bt_ctf_event_class_get_payload_type(ec); | |
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); | |
46df6b28 | 1742 | ok(!validate_field_path(ft_src, BT_CTF_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, | |
46df6b28 | 1750 | BT_CTF_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); | |
1753 | ft_tag = bt_ctf_field_type_variant_get_tag_type(ft_src); | |
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, | |
46df6b28 | 1763 | BT_CTF_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, | |
46df6b28 | 1770 | BT_CTF_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, | |
46df6b28 | 1777 | BT_CTF_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, | |
46df6b28 | 1784 | BT_CTF_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, | |
46df6b28 | 1791 | BT_CTF_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); | |
1794 | ft_tag = bt_ctf_field_type_variant_get_tag_type(ft_src); | |
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, | |
46df6b28 | 1804 | BT_CTF_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, | |
46df6b28 | 1811 | BT_CTF_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, | |
46df6b28 | 1818 | BT_CTF_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, | |
46df6b28 | 1825 | BT_CTF_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, | |
46df6b28 | 1832 | BT_CTF_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, | |
46df6b28 | 1839 | BT_CTF_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, | |
46df6b28 | 1846 | BT_CTF_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, | |
46df6b28 | 1853 | BT_CTF_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, | |
46df6b28 | 1860 | BT_CTF_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, | |
46df6b28 | 1867 | BT_CTF_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, | |
46df6b28 | 1874 | BT_CTF_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, | |
46df6b28 | 1881 | BT_CTF_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, | |
46df6b28 | 1888 | BT_CTF_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, | |
46df6b28 | 1895 | BT_CTF_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, | |
46df6b28 | 1902 | BT_CTF_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, | |
46df6b28 | 1909 | BT_CTF_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, | |
46df6b28 | 1916 | BT_CTF_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, | |
46df6b28 | 1923 | BT_CTF_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, | |
46df6b28 | 1930 | BT_CTF_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, | |
46df6b28 | 1937 | BT_CTF_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, | |
46df6b28 | 1944 | BT_CTF_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, | |
46df6b28 | 1951 | BT_CTF_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, | |
46df6b28 | 1958 | BT_CTF_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, | |
46df6b28 | 1965 | BT_CTF_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, | |
46df6b28 | 1972 | BT_CTF_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, | |
46df6b28 | 1979 | BT_CTF_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, | |
46df6b28 | 1986 | BT_CTF_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, | |
46df6b28 | 1993 | BT_CTF_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, | |
46df6b28 | 2000 | BT_CTF_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, | |
46df6b28 | 2007 | BT_CTF_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, | |
46df6b28 | 2014 | BT_CTF_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, | |
46df6b28 | 2021 | BT_CTF_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, | |
46df6b28 | 2028 | BT_CTF_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, | |
46df6b28 | 2035 | BT_CTF_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, | |
46df6b28 | 2042 | BT_CTF_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 | ||
2058 | static | |
2059 | void test_pass(void) | |
2060 | { | |
2061 | int ret; | |
2062 | struct bt_ctf_trace *trace; | |
2063 | struct bt_ctf_stream_class *sc; | |
2064 | struct bt_ctf_event_class *ec; | |
2065 | struct bt_ctf_field_type *ph; | |
2066 | struct bt_ctf_field_type *pc; | |
2067 | struct bt_ctf_field_type *eh; | |
2068 | struct bt_ctf_field_type *sec; | |
2069 | struct bt_ctf_field_type *ectx; | |
2070 | struct bt_ctf_field_type *ep; | |
2071 | ||
2072 | trace = bt_ctf_trace_create(); | |
2073 | assert(trace); | |
2074 | sc = bt_ctf_stream_class_create("nice_piece_of_stream_class"); | |
2075 | assert(sc); | |
2076 | ec = bt_ctf_event_class_create("oh_what_an_event_class"); | |
2077 | assert(ec); | |
2078 | ||
2079 | ph = get_good_packet_header_type(); | |
2080 | assert(ph); | |
2081 | pc = get_good_packet_context_type(); | |
2082 | assert(pc); | |
2083 | eh = get_good_event_header_type(); | |
2084 | assert(eh); | |
2085 | sec = get_good_stream_event_context_type(); | |
2086 | assert(sec); | |
2087 | ectx = get_good_event_context_type(); | |
2088 | assert(ec); | |
2089 | ep = get_good_event_payload_type(); | |
2090 | assert(ep); | |
2091 | ||
2092 | ret = bt_ctf_trace_set_packet_header_type(trace, ph); | |
2093 | assert(ret == 0); | |
2094 | ret = bt_ctf_stream_class_set_packet_context_type(sc, pc); | |
2095 | assert(ret == 0); | |
2096 | ret = bt_ctf_stream_class_set_event_header_type(sc, eh); | |
2097 | assert(ret == 0); | |
2098 | ret = bt_ctf_stream_class_set_event_context_type(sc, sec); | |
2099 | assert(ret == 0); | |
2100 | ret = bt_ctf_event_class_set_context_type(ec, ectx); | |
2101 | assert(ret == 0); | |
2102 | ret = bt_ctf_event_class_set_payload_type(ec, ep); | |
2103 | assert(ret == 0); | |
2104 | ||
2105 | ret = bt_ctf_stream_class_add_event_class(sc, ec); | |
2106 | assert(ret == 0); | |
2107 | ||
2108 | /* Validation happens here */ | |
2109 | ret = bt_ctf_trace_add_stream_class(trace, sc); | |
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 | ||
2125 | static | |
2126 | struct bt_ctf_event *create_event_with_context_and_payload( | |
2127 | struct bt_ctf_field_type *ectx, struct bt_ctf_field_type *ep) | |
2128 | { | |
2129 | int ret; | |
2130 | struct bt_ctf_stream_class *sc; | |
2131 | struct bt_ctf_event_class *ec; | |
2132 | struct bt_ctf_event *event; | |
2133 | ||
2134 | sc = bt_ctf_stream_class_create("sc"); | |
2135 | assert(sc); | |
2136 | ec = bt_ctf_event_class_create("ec"); | |
2137 | assert(ec); | |
2138 | ||
2139 | if (ectx) { | |
2140 | ret = bt_ctf_event_class_set_context_type(ec, ectx); | |
2141 | assert(ret == 0); | |
2142 | } | |
2143 | ||
2144 | if (ep) { | |
2145 | ret = bt_ctf_event_class_set_payload_type(ec, ep); | |
2146 | assert(ret == 0); | |
2147 | } | |
2148 | ||
2149 | ret = bt_ctf_stream_class_add_event_class(sc, ec); | |
2150 | assert(ret == 0); | |
2151 | ||
2152 | /* Validation happens here */ | |
2153 | event = bt_ctf_event_create(ec); | |
2154 | ||
2155 | BT_PUT(ec); | |
2156 | BT_PUT(sc); | |
2157 | ||
2158 | return event; | |
2159 | } | |
2160 | ||
2161 | ||
2162 | static | |
2163 | struct bt_ctf_field_type *test_fail_unavailable_root_get_event_payload(void) | |
2164 | { | |
2165 | /* | |
2166 | Generated by bt-ctfirtg using the following input: | |
2167 | ||
2168 | class: struct | |
2169 | fields: | |
2170 | a: | |
2171 | class: int | |
2172 | size: 32 | |
2173 | b: | |
2174 | class: array | |
2175 | length: stream.event.context.lol | |
2176 | element-type: | |
2177 | class: string | |
2178 | c: | |
2179 | class: string | |
2180 | ||
2181 | */ | |
2182 | ||
2183 | struct bt_ctf_field_type *root = NULL; | |
2184 | struct bt_ctf_field_type *root_a = NULL; | |
2185 | struct bt_ctf_field_type *root_b = NULL; | |
2186 | struct bt_ctf_field_type *root_b_elem = NULL; | |
2187 | struct bt_ctf_field_type *root_c = NULL; | |
2188 | ||
2189 | int ret; | |
2190 | root = bt_ctf_field_type_structure_create(); | |
2191 | assert(root); | |
2192 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2193 | assert(ret == 0); | |
2194 | root_a = bt_ctf_field_type_integer_create(32); | |
2195 | assert(root_a); | |
2196 | ret = bt_ctf_field_type_integer_set_signed(root_a, 0); | |
2197 | assert(ret == 0); | |
2198 | ret = bt_ctf_field_type_integer_set_base(root_a, 10); | |
2199 | assert(ret == 0); | |
b28a86ad | 2200 | ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2201 | assert(ret == 0); |
2202 | ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2203 | assert(ret == 0); | |
2204 | ret = bt_ctf_field_type_set_alignment(root_a, 8); | |
2205 | assert(ret == 0); | |
2206 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2207 | assert(ret == 0); | |
2208 | root_b_elem = bt_ctf_field_type_string_create(); | |
2209 | assert(root_b_elem); | |
b28a86ad | 2210 | ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2211 | assert(ret == 0); |
2212 | root_b = bt_ctf_field_type_sequence_create(root_b_elem, "stream.event.context.lol"); | |
2213 | assert(root_b); | |
2214 | ret = bt_ctf_field_type_structure_add_field(root, root_b, "b"); | |
2215 | assert(ret == 0); | |
2216 | root_c = bt_ctf_field_type_string_create(); | |
2217 | assert(root_c); | |
b28a86ad | 2218 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2219 | assert(ret == 0); |
2220 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2221 | assert(ret == 0); | |
2222 | ||
2223 | BT_PUT(root_a); | |
2224 | BT_PUT(root_b); | |
2225 | BT_PUT(root_b_elem); | |
2226 | BT_PUT(root_c); | |
2227 | ||
2228 | return root; | |
2229 | } | |
2230 | ||
2231 | static | |
2232 | void test_fail_unavailable_root(void) | |
2233 | { | |
2234 | struct bt_ctf_field_type *ep; | |
2235 | struct bt_ctf_event *event; | |
2236 | ||
2237 | ep = test_fail_unavailable_root_get_event_payload(); | |
2238 | assert(ep); | |
2239 | event = create_event_with_context_and_payload(NULL, ep); | |
2240 | ok(!event, "Sequence FT with length in unavailable root is invalid"); | |
2241 | ||
2242 | BT_PUT(ep); | |
2243 | BT_PUT(event); | |
2244 | } | |
2245 | ||
2246 | static | |
2247 | struct bt_ctf_field_type *test_fail_target_is_root_get_event_payload(void) | |
2248 | { | |
2249 | /* | |
2250 | Generated by bt-ctfirtg using the following input: | |
2251 | ||
2252 | class: struct | |
2253 | fields: | |
2254 | a: | |
2255 | class: int | |
2256 | size: 32 | |
2257 | b: | |
2258 | class: array | |
2259 | length: event.fields | |
2260 | element-type: | |
2261 | class: string | |
2262 | c: | |
2263 | class: string | |
2264 | ||
2265 | */ | |
2266 | ||
2267 | struct bt_ctf_field_type *root = NULL; | |
2268 | struct bt_ctf_field_type *root_a = NULL; | |
2269 | struct bt_ctf_field_type *root_b = NULL; | |
2270 | struct bt_ctf_field_type *root_b_elem = NULL; | |
2271 | struct bt_ctf_field_type *root_c = NULL; | |
2272 | ||
2273 | int ret; | |
2274 | root = bt_ctf_field_type_structure_create(); | |
2275 | assert(root); | |
2276 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2277 | assert(ret == 0); | |
2278 | root_a = bt_ctf_field_type_integer_create(32); | |
2279 | assert(root_a); | |
2280 | ret = bt_ctf_field_type_integer_set_signed(root_a, 0); | |
2281 | assert(ret == 0); | |
2282 | ret = bt_ctf_field_type_integer_set_base(root_a, 10); | |
2283 | assert(ret == 0); | |
b28a86ad | 2284 | ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2285 | assert(ret == 0); |
2286 | ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2287 | assert(ret == 0); | |
2288 | ret = bt_ctf_field_type_set_alignment(root_a, 8); | |
2289 | assert(ret == 0); | |
2290 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2291 | assert(ret == 0); | |
2292 | root_b_elem = bt_ctf_field_type_string_create(); | |
2293 | assert(root_b_elem); | |
b28a86ad | 2294 | ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2295 | assert(ret == 0); |
2296 | root_b = bt_ctf_field_type_sequence_create(root_b_elem, "event.fields"); | |
2297 | assert(root_b); | |
2298 | ret = bt_ctf_field_type_structure_add_field(root, root_b, "b"); | |
2299 | assert(ret == 0); | |
2300 | root_c = bt_ctf_field_type_string_create(); | |
2301 | assert(root_c); | |
b28a86ad | 2302 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2303 | assert(ret == 0); |
2304 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2305 | assert(ret == 0); | |
2306 | ||
2307 | BT_PUT(root_a); | |
2308 | BT_PUT(root_b); | |
2309 | BT_PUT(root_b_elem); | |
2310 | BT_PUT(root_c); | |
2311 | ||
2312 | return root; | |
2313 | } | |
2314 | ||
2315 | static | |
2316 | void test_fail_target_is_root(void) | |
2317 | { | |
2318 | struct bt_ctf_field_type *ep; | |
2319 | struct bt_ctf_event *event; | |
2320 | ||
2321 | ep = test_fail_target_is_root_get_event_payload(); | |
2322 | assert(ep); | |
2323 | event = create_event_with_context_and_payload(NULL, ep); | |
2324 | ok(!event, "Sequence FT with root as its length is invalid"); | |
2325 | ||
2326 | BT_PUT(ep); | |
2327 | BT_PUT(event); | |
2328 | } | |
2329 | ||
2330 | static | |
2331 | struct bt_ctf_field_type *test_fail_target_is_after_source_get_ep(void) | |
2332 | { | |
2333 | /* | |
2334 | Generated by bt-ctfirtg using the following input: | |
2335 | ||
2336 | class: struct | |
2337 | fields: | |
2338 | a: | |
2339 | class: int | |
2340 | size: 32 | |
2341 | b: | |
2342 | class: array | |
2343 | length: d | |
2344 | element-type: | |
2345 | class: string | |
2346 | c: | |
2347 | class: string | |
2348 | d: | |
2349 | class: int | |
2350 | size: 17 | |
2351 | ||
2352 | */ | |
2353 | ||
2354 | struct bt_ctf_field_type *root = NULL; | |
2355 | struct bt_ctf_field_type *root_a = NULL; | |
2356 | struct bt_ctf_field_type *root_b = NULL; | |
2357 | struct bt_ctf_field_type *root_b_elem = NULL; | |
2358 | struct bt_ctf_field_type *root_c = NULL; | |
2359 | struct bt_ctf_field_type *root_d = NULL; | |
2360 | ||
2361 | int ret; | |
2362 | root = bt_ctf_field_type_structure_create(); | |
2363 | assert(root); | |
2364 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2365 | assert(ret == 0); | |
2366 | root_a = bt_ctf_field_type_integer_create(32); | |
2367 | assert(root_a); | |
2368 | ret = bt_ctf_field_type_integer_set_signed(root_a, 0); | |
2369 | assert(ret == 0); | |
2370 | ret = bt_ctf_field_type_integer_set_base(root_a, 10); | |
2371 | assert(ret == 0); | |
b28a86ad | 2372 | ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2373 | assert(ret == 0); |
2374 | ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2375 | assert(ret == 0); | |
2376 | ret = bt_ctf_field_type_set_alignment(root_a, 8); | |
2377 | assert(ret == 0); | |
2378 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2379 | assert(ret == 0); | |
2380 | root_b_elem = bt_ctf_field_type_string_create(); | |
2381 | assert(root_b_elem); | |
b28a86ad | 2382 | ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2383 | assert(ret == 0); |
2384 | root_b = bt_ctf_field_type_sequence_create(root_b_elem, "d"); | |
2385 | assert(root_b); | |
2386 | ret = bt_ctf_field_type_structure_add_field(root, root_b, "b"); | |
2387 | assert(ret == 0); | |
2388 | root_c = bt_ctf_field_type_string_create(); | |
2389 | assert(root_c); | |
b28a86ad | 2390 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2391 | assert(ret == 0); |
2392 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2393 | assert(ret == 0); | |
2394 | root_d = bt_ctf_field_type_integer_create(17); | |
2395 | assert(root_d); | |
2396 | ret = bt_ctf_field_type_integer_set_signed(root_d, 0); | |
2397 | assert(ret == 0); | |
2398 | ret = bt_ctf_field_type_integer_set_base(root_d, 10); | |
2399 | assert(ret == 0); | |
b28a86ad | 2400 | ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2401 | assert(ret == 0); |
2402 | ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2403 | assert(ret == 0); | |
2404 | ret = bt_ctf_field_type_set_alignment(root_d, 1); | |
2405 | assert(ret == 0); | |
2406 | ret = bt_ctf_field_type_structure_add_field(root, root_d, "d"); | |
2407 | assert(ret == 0); | |
2408 | ||
2409 | BT_PUT(root_a); | |
2410 | BT_PUT(root_b); | |
2411 | BT_PUT(root_b_elem); | |
2412 | BT_PUT(root_c); | |
2413 | BT_PUT(root_d); | |
2414 | ||
2415 | return root; | |
2416 | } | |
2417 | ||
2418 | static | |
2419 | void test_fail_target_is_after_source(void) | |
2420 | { | |
2421 | struct bt_ctf_field_type *ep; | |
2422 | struct bt_ctf_event *event; | |
2423 | ||
2424 | ep = test_fail_target_is_after_source_get_ep(); | |
2425 | assert(ep); | |
2426 | event = create_event_with_context_and_payload(NULL, ep); | |
2427 | ok(!event, "Sequence FT with length after it is invalid"); | |
2428 | ||
2429 | BT_PUT(ep); | |
2430 | BT_PUT(event); | |
2431 | } | |
2432 | ||
2433 | static | |
2434 | struct bt_ctf_field_type *test_fail_target_is_ancestor_of_source_get_ep(void) | |
2435 | { | |
2436 | /* | |
2437 | Generated by bt-ctfirtg using the following input: | |
2438 | ||
2439 | class: struct | |
2440 | fields: | |
2441 | a: | |
2442 | class: int | |
2443 | size: 32 | |
2444 | z: | |
2445 | class: struct | |
2446 | fields: | |
2447 | b: | |
2448 | class: array | |
2449 | length: z | |
2450 | element-type: | |
2451 | class: string | |
2452 | c: | |
2453 | class: string | |
2454 | d: | |
2455 | class: int | |
2456 | size: 17 | |
2457 | ||
2458 | */ | |
2459 | ||
2460 | struct bt_ctf_field_type *root = NULL; | |
2461 | struct bt_ctf_field_type *root_a = NULL; | |
2462 | struct bt_ctf_field_type *root_z = NULL; | |
2463 | struct bt_ctf_field_type *root_z_b = NULL; | |
2464 | struct bt_ctf_field_type *root_z_b_elem = NULL; | |
2465 | struct bt_ctf_field_type *root_c = NULL; | |
2466 | struct bt_ctf_field_type *root_d = NULL; | |
2467 | ||
2468 | int ret; | |
2469 | root = bt_ctf_field_type_structure_create(); | |
2470 | assert(root); | |
2471 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2472 | assert(ret == 0); | |
2473 | root_a = bt_ctf_field_type_integer_create(32); | |
2474 | assert(root_a); | |
2475 | ret = bt_ctf_field_type_integer_set_signed(root_a, 0); | |
2476 | assert(ret == 0); | |
2477 | ret = bt_ctf_field_type_integer_set_base(root_a, 10); | |
2478 | assert(ret == 0); | |
b28a86ad | 2479 | ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2480 | assert(ret == 0); |
2481 | ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2482 | assert(ret == 0); | |
2483 | ret = bt_ctf_field_type_set_alignment(root_a, 8); | |
2484 | assert(ret == 0); | |
2485 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2486 | assert(ret == 0); | |
2487 | root_z = bt_ctf_field_type_structure_create(); | |
2488 | assert(root_z); | |
2489 | ret = bt_ctf_field_type_set_alignment(root_z, 8); | |
2490 | assert(ret == 0); | |
2491 | root_z_b_elem = bt_ctf_field_type_string_create(); | |
2492 | assert(root_z_b_elem); | |
b28a86ad | 2493 | ret = bt_ctf_field_type_string_set_encoding(root_z_b_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2494 | assert(ret == 0); |
2495 | root_z_b = bt_ctf_field_type_sequence_create(root_z_b_elem, "z"); | |
2496 | assert(root_z_b); | |
2497 | ret = bt_ctf_field_type_structure_add_field(root_z, root_z_b, "b"); | |
2498 | assert(ret == 0); | |
2499 | ret = bt_ctf_field_type_structure_add_field(root, root_z, "z"); | |
2500 | assert(ret == 0); | |
2501 | root_c = bt_ctf_field_type_string_create(); | |
2502 | assert(root_c); | |
b28a86ad | 2503 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2504 | assert(ret == 0); |
2505 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2506 | assert(ret == 0); | |
2507 | root_d = bt_ctf_field_type_integer_create(17); | |
2508 | assert(root_d); | |
2509 | ret = bt_ctf_field_type_integer_set_signed(root_d, 0); | |
2510 | assert(ret == 0); | |
2511 | ret = bt_ctf_field_type_integer_set_base(root_d, 10); | |
2512 | assert(ret == 0); | |
b28a86ad | 2513 | ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2514 | assert(ret == 0); |
2515 | ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2516 | assert(ret == 0); | |
2517 | ret = bt_ctf_field_type_set_alignment(root_d, 1); | |
2518 | assert(ret == 0); | |
2519 | ret = bt_ctf_field_type_structure_add_field(root, root_d, "d"); | |
2520 | assert(ret == 0); | |
2521 | ||
2522 | BT_PUT(root_a); | |
2523 | BT_PUT(root_z); | |
2524 | BT_PUT(root_z_b); | |
2525 | BT_PUT(root_z_b_elem); | |
2526 | BT_PUT(root_c); | |
2527 | BT_PUT(root_d); | |
2528 | ||
2529 | return root; | |
2530 | } | |
2531 | ||
2532 | static | |
2533 | void test_fail_target_is_ancestor_of_source(void) | |
2534 | { | |
2535 | struct bt_ctf_field_type *ep; | |
2536 | struct bt_ctf_event *event; | |
2537 | ||
2538 | ep = test_fail_target_is_ancestor_of_source_get_ep(); | |
2539 | assert(ep); | |
2540 | event = create_event_with_context_and_payload(NULL, ep); | |
2541 | ok(!event, "Sequence FT with ancestor as its length is invalid"); | |
2542 | ||
2543 | BT_PUT(ep); | |
2544 | BT_PUT(event); | |
2545 | } | |
2546 | ||
2547 | static | |
2548 | struct bt_ctf_field_type *test_fail_target_is_source_get_event_payload(void) | |
2549 | { | |
2550 | /* | |
2551 | Generated by bt-ctfirtg using the following input: | |
2552 | ||
2553 | class: struct | |
2554 | fields: | |
2555 | a: | |
2556 | class: int | |
2557 | size: 32 | |
2558 | b: | |
2559 | class: array | |
2560 | length: event.fields.b | |
2561 | element-type: | |
2562 | class: string | |
2563 | c: | |
2564 | class: string | |
2565 | d: | |
2566 | class: int | |
2567 | size: 17 | |
2568 | ||
2569 | */ | |
2570 | ||
2571 | struct bt_ctf_field_type *root = NULL; | |
2572 | struct bt_ctf_field_type *root_a = NULL; | |
2573 | struct bt_ctf_field_type *root_b = NULL; | |
2574 | struct bt_ctf_field_type *root_b_elem = NULL; | |
2575 | struct bt_ctf_field_type *root_c = NULL; | |
2576 | struct bt_ctf_field_type *root_d = NULL; | |
2577 | ||
2578 | int ret; | |
2579 | root = bt_ctf_field_type_structure_create(); | |
2580 | assert(root); | |
2581 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2582 | assert(ret == 0); | |
2583 | root_a = bt_ctf_field_type_integer_create(32); | |
2584 | assert(root_a); | |
2585 | ret = bt_ctf_field_type_integer_set_signed(root_a, 0); | |
2586 | assert(ret == 0); | |
2587 | ret = bt_ctf_field_type_integer_set_base(root_a, 10); | |
2588 | assert(ret == 0); | |
b28a86ad | 2589 | ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2590 | assert(ret == 0); |
2591 | ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2592 | assert(ret == 0); | |
2593 | ret = bt_ctf_field_type_set_alignment(root_a, 8); | |
2594 | assert(ret == 0); | |
2595 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2596 | assert(ret == 0); | |
2597 | root_b_elem = bt_ctf_field_type_string_create(); | |
2598 | assert(root_b_elem); | |
b28a86ad | 2599 | ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2600 | assert(ret == 0); |
2601 | root_b = bt_ctf_field_type_sequence_create(root_b_elem, "event.fields.b"); | |
2602 | assert(root_b); | |
2603 | ret = bt_ctf_field_type_structure_add_field(root, root_b, "b"); | |
2604 | assert(ret == 0); | |
2605 | root_c = bt_ctf_field_type_string_create(); | |
2606 | assert(root_c); | |
b28a86ad | 2607 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2608 | assert(ret == 0); |
2609 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2610 | assert(ret == 0); | |
2611 | root_d = bt_ctf_field_type_integer_create(17); | |
2612 | assert(root_d); | |
2613 | ret = bt_ctf_field_type_integer_set_signed(root_d, 0); | |
2614 | assert(ret == 0); | |
2615 | ret = bt_ctf_field_type_integer_set_base(root_d, 10); | |
2616 | assert(ret == 0); | |
b28a86ad | 2617 | ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2618 | assert(ret == 0); |
2619 | ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2620 | assert(ret == 0); | |
2621 | ret = bt_ctf_field_type_set_alignment(root_d, 1); | |
2622 | assert(ret == 0); | |
2623 | ret = bt_ctf_field_type_structure_add_field(root, root_d, "d"); | |
2624 | assert(ret == 0); | |
2625 | ||
2626 | BT_PUT(root_a); | |
2627 | BT_PUT(root_b); | |
2628 | BT_PUT(root_b_elem); | |
2629 | BT_PUT(root_c); | |
2630 | BT_PUT(root_d); | |
2631 | ||
2632 | return root; | |
2633 | } | |
2634 | ||
2635 | static | |
2636 | void test_fail_target_is_source(void) | |
2637 | { | |
2638 | struct bt_ctf_field_type *ep; | |
2639 | struct bt_ctf_event *event; | |
2640 | ||
2641 | ep = test_fail_target_is_source_get_event_payload(); | |
2642 | assert(ep); | |
2643 | event = create_event_with_context_and_payload(NULL, ep); | |
2644 | ok(!event, "Sequence FT with itself as its length is invalid"); | |
2645 | ||
2646 | BT_PUT(ep); | |
2647 | BT_PUT(event); | |
2648 | } | |
2649 | ||
2650 | static | |
2651 | struct bt_ctf_field_type *test_fail_variant_tag_is_not_enum_get_ep(void) | |
2652 | { | |
2653 | /* | |
2654 | Generated by bt-ctfirtg using the following input: | |
2655 | ||
2656 | class: struct | |
2657 | fields: | |
2658 | a: | |
2659 | class: int | |
2660 | size: 32 | |
2661 | b: | |
2662 | class: variant | |
2663 | tag: a | |
2664 | types: | |
2665 | HELLO: | |
2666 | class: string | |
2667 | c: | |
2668 | class: string | |
2669 | d: | |
2670 | class: int | |
2671 | size: 17 | |
2672 | ||
2673 | */ | |
2674 | ||
2675 | struct bt_ctf_field_type *root = NULL; | |
2676 | struct bt_ctf_field_type *root_a = NULL; | |
2677 | struct bt_ctf_field_type *root_b = NULL; | |
2678 | struct bt_ctf_field_type *root_b_HELLO = NULL; | |
2679 | struct bt_ctf_field_type *root_c = NULL; | |
2680 | struct bt_ctf_field_type *root_d = NULL; | |
2681 | ||
2682 | int ret; | |
2683 | root = bt_ctf_field_type_structure_create(); | |
2684 | assert(root); | |
2685 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2686 | assert(ret == 0); | |
2687 | root_a = bt_ctf_field_type_integer_create(32); | |
2688 | assert(root_a); | |
2689 | ret = bt_ctf_field_type_integer_set_signed(root_a, 0); | |
2690 | assert(ret == 0); | |
2691 | ret = bt_ctf_field_type_integer_set_base(root_a, 10); | |
2692 | assert(ret == 0); | |
b28a86ad | 2693 | ret = bt_ctf_field_type_integer_set_encoding(root_a, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2694 | assert(ret == 0); |
2695 | ret = bt_ctf_field_type_set_byte_order(root_a, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2696 | assert(ret == 0); | |
2697 | ret = bt_ctf_field_type_set_alignment(root_a, 8); | |
2698 | assert(ret == 0); | |
2699 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2700 | assert(ret == 0); | |
2701 | root_b = bt_ctf_field_type_variant_create(NULL, "a"); | |
2702 | assert(root_b); | |
2703 | root_b_HELLO = bt_ctf_field_type_string_create(); | |
2704 | assert(root_b_HELLO); | |
b28a86ad | 2705 | ret = bt_ctf_field_type_string_set_encoding(root_b_HELLO, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2706 | assert(ret == 0); |
2707 | ret = bt_ctf_field_type_variant_add_field(root_b, root_b_HELLO, "HELLO"); | |
2708 | assert(ret == 0); | |
2709 | ret = bt_ctf_field_type_structure_add_field(root, root_b, "b"); | |
2710 | assert(ret == 0); | |
2711 | root_c = bt_ctf_field_type_string_create(); | |
2712 | assert(root_c); | |
b28a86ad | 2713 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2714 | assert(ret == 0); |
2715 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2716 | assert(ret == 0); | |
2717 | root_d = bt_ctf_field_type_integer_create(17); | |
2718 | assert(root_d); | |
2719 | ret = bt_ctf_field_type_integer_set_signed(root_d, 0); | |
2720 | assert(ret == 0); | |
2721 | ret = bt_ctf_field_type_integer_set_base(root_d, 10); | |
2722 | assert(ret == 0); | |
b28a86ad | 2723 | ret = bt_ctf_field_type_integer_set_encoding(root_d, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2724 | assert(ret == 0); |
2725 | ret = bt_ctf_field_type_set_byte_order(root_d, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2726 | assert(ret == 0); | |
2727 | ret = bt_ctf_field_type_set_alignment(root_d, 1); | |
2728 | assert(ret == 0); | |
2729 | ret = bt_ctf_field_type_structure_add_field(root, root_d, "d"); | |
2730 | assert(ret == 0); | |
2731 | ||
2732 | BT_PUT(root_a); | |
2733 | BT_PUT(root_b); | |
2734 | BT_PUT(root_b_HELLO); | |
2735 | BT_PUT(root_c); | |
2736 | BT_PUT(root_d); | |
2737 | ||
2738 | return root; | |
2739 | } | |
2740 | ||
2741 | static | |
2742 | void test_fail_variant_tag_is_not_enum(void) | |
2743 | { | |
2744 | struct bt_ctf_field_type *ep; | |
2745 | struct bt_ctf_event *event; | |
2746 | ||
2747 | ep = test_fail_variant_tag_is_not_enum_get_ep(); | |
2748 | assert(ep); | |
2749 | event = create_event_with_context_and_payload(NULL, ep); | |
2750 | ok(!event, "Variant FT with non-enum FT as its tag FT is invalid"); | |
2751 | ||
2752 | BT_PUT(ep); | |
2753 | BT_PUT(event); | |
2754 | } | |
2755 | ||
2756 | static | |
2757 | struct bt_ctf_field_type *test_fail_variant_tag_mismatch_mappings_get_ep(void) | |
2758 | { | |
2759 | /* | |
2760 | Generated by bt-ctfirtg using the following input: | |
2761 | ||
2762 | class: struct | |
2763 | fields: | |
2764 | a: | |
2765 | class: enum | |
2766 | value-type: | |
2767 | class: int | |
2768 | size: 16 | |
2769 | members: | |
2770 | - GLASS | |
2771 | - OF | |
2772 | - WATER | |
2773 | b: | |
2774 | class: variant | |
2775 | tag: a | |
2776 | types: | |
2777 | GLASS: | |
2778 | class: string | |
2779 | OF: | |
2780 | class: int | |
2781 | size: 2 | |
2782 | c: | |
2783 | class: string | |
2784 | ||
2785 | */ | |
2786 | ||
2787 | struct bt_ctf_field_type *root = NULL; | |
2788 | struct bt_ctf_field_type *root_a = NULL; | |
2789 | struct bt_ctf_field_type *root_a_int = NULL; | |
2790 | struct bt_ctf_field_type *root_b = NULL; | |
2791 | struct bt_ctf_field_type *root_b_GLASS = NULL; | |
2792 | struct bt_ctf_field_type *root_b_OF = NULL; | |
2793 | struct bt_ctf_field_type *root_c = NULL; | |
2794 | ||
2795 | int ret; | |
2796 | root = bt_ctf_field_type_structure_create(); | |
2797 | assert(root); | |
2798 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2799 | assert(ret == 0); | |
2800 | root_a_int = bt_ctf_field_type_integer_create(16); | |
2801 | assert(root_a_int); | |
2802 | ret = bt_ctf_field_type_integer_set_signed(root_a_int, 0); | |
2803 | assert(ret == 0); | |
2804 | ret = bt_ctf_field_type_integer_set_base(root_a_int, 10); | |
2805 | assert(ret == 0); | |
b28a86ad | 2806 | ret = bt_ctf_field_type_integer_set_encoding(root_a_int, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2807 | assert(ret == 0); |
2808 | ret = bt_ctf_field_type_set_byte_order(root_a_int, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2809 | assert(ret == 0); | |
2810 | ret = bt_ctf_field_type_set_alignment(root_a_int, 8); | |
2811 | assert(ret == 0); | |
2812 | root_a = bt_ctf_field_type_enumeration_create(root_a_int); | |
2813 | assert(root_a); | |
2814 | ret = bt_ctf_field_type_enumeration_add_mapping(root_a, "GLASS", 0, 0); | |
2815 | assert(ret == 0); | |
2816 | ret = bt_ctf_field_type_enumeration_add_mapping(root_a, "OF", 1, 1); | |
2817 | assert(ret == 0); | |
2818 | ret = bt_ctf_field_type_enumeration_add_mapping(root_a, "WATER", 2, 2); | |
2819 | assert(ret == 0); | |
2820 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2821 | assert(ret == 0); | |
2822 | root_b = bt_ctf_field_type_variant_create(NULL, "a"); | |
2823 | assert(root_b); | |
2824 | root_b_GLASS = bt_ctf_field_type_string_create(); | |
2825 | assert(root_b_GLASS); | |
b28a86ad | 2826 | ret = bt_ctf_field_type_string_set_encoding(root_b_GLASS, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2827 | assert(ret == 0); |
2828 | ret = bt_ctf_field_type_variant_add_field(root_b, root_b_GLASS, "GLASS"); | |
2829 | assert(ret == 0); | |
2830 | root_b_OF = bt_ctf_field_type_integer_create(2); | |
2831 | assert(root_b_OF); | |
2832 | ret = bt_ctf_field_type_integer_set_signed(root_b_OF, 0); | |
2833 | assert(ret == 0); | |
2834 | ret = bt_ctf_field_type_integer_set_base(root_b_OF, 10); | |
2835 | assert(ret == 0); | |
b28a86ad | 2836 | ret = bt_ctf_field_type_integer_set_encoding(root_b_OF, BT_CTF_STRING_ENCODING_NONE); |
0b93f4ea PP |
2837 | assert(ret == 0); |
2838 | ret = bt_ctf_field_type_set_byte_order(root_b_OF, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN); | |
2839 | assert(ret == 0); | |
2840 | ret = bt_ctf_field_type_set_alignment(root_b_OF, 1); | |
2841 | assert(ret == 0); | |
2842 | ret = bt_ctf_field_type_variant_add_field(root_b, root_b_OF, "OF"); | |
2843 | assert(ret == 0); | |
2844 | ret = bt_ctf_field_type_structure_add_field(root, root_b, "b"); | |
2845 | assert(ret == 0); | |
2846 | root_c = bt_ctf_field_type_string_create(); | |
2847 | assert(root_c); | |
b28a86ad | 2848 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2849 | assert(ret == 0); |
2850 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2851 | assert(ret == 0); | |
2852 | ||
2853 | BT_PUT(root_a); | |
2854 | BT_PUT(root_a_int); | |
2855 | BT_PUT(root_b); | |
2856 | BT_PUT(root_b_GLASS); | |
2857 | BT_PUT(root_b_OF); | |
2858 | BT_PUT(root_c); | |
2859 | ||
2860 | return root; | |
2861 | } | |
2862 | ||
2863 | static | |
2864 | void test_fail_variant_tag_mismatch_mappings(void) | |
2865 | { | |
2866 | struct bt_ctf_field_type *ep; | |
2867 | struct bt_ctf_event *event; | |
2868 | ||
2869 | ep = test_fail_variant_tag_mismatch_mappings_get_ep(); | |
2870 | assert(ep); | |
2871 | event = create_event_with_context_and_payload(NULL, ep); | |
2d4b0539 | 2872 | ok(event, "Variant FT with mismatching tag FT is valid"); |
0b93f4ea PP |
2873 | |
2874 | BT_PUT(ep); | |
2875 | BT_PUT(event); | |
2876 | } | |
2877 | ||
2878 | static | |
2879 | struct bt_ctf_field_type *test_fail_sequence_tag_is_not_int_get_ep(void) | |
2880 | { | |
2881 | /* | |
2882 | Generated by bt-ctfirtg using the following input: | |
2883 | ||
2884 | class: struct | |
2885 | fields: | |
2886 | a: | |
2887 | class: string | |
2888 | b: | |
2889 | class: array | |
2890 | length: a | |
2891 | element-type: | |
2892 | class: string | |
2893 | c: | |
2894 | class: string | |
2895 | ||
2896 | */ | |
2897 | ||
2898 | struct bt_ctf_field_type *root = NULL; | |
2899 | struct bt_ctf_field_type *root_a = NULL; | |
2900 | struct bt_ctf_field_type *root_b = NULL; | |
2901 | struct bt_ctf_field_type *root_b_elem = NULL; | |
2902 | struct bt_ctf_field_type *root_c = NULL; | |
2903 | ||
2904 | int ret; | |
2905 | root = bt_ctf_field_type_structure_create(); | |
2906 | assert(root); | |
2907 | ret = bt_ctf_field_type_set_alignment(root, 8); | |
2908 | assert(ret == 0); | |
2909 | root_a = bt_ctf_field_type_string_create(); | |
2910 | assert(root_a); | |
b28a86ad | 2911 | ret = bt_ctf_field_type_string_set_encoding(root_a, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2912 | assert(ret == 0); |
2913 | ret = bt_ctf_field_type_structure_add_field(root, root_a, "a"); | |
2914 | assert(ret == 0); | |
2915 | root_b_elem = bt_ctf_field_type_string_create(); | |
2916 | assert(root_b_elem); | |
b28a86ad | 2917 | ret = bt_ctf_field_type_string_set_encoding(root_b_elem, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2918 | assert(ret == 0); |
2919 | root_b = bt_ctf_field_type_sequence_create(root_b_elem, "a"); | |
2920 | assert(root_b); | |
2921 | ret = bt_ctf_field_type_structure_add_field(root, root_b, "b"); | |
2922 | assert(ret == 0); | |
2923 | root_c = bt_ctf_field_type_string_create(); | |
2924 | assert(root_c); | |
b28a86ad | 2925 | ret = bt_ctf_field_type_string_set_encoding(root_c, BT_CTF_STRING_ENCODING_UTF8); |
0b93f4ea PP |
2926 | assert(ret == 0); |
2927 | ret = bt_ctf_field_type_structure_add_field(root, root_c, "c"); | |
2928 | assert(ret == 0); | |
2929 | ||
2930 | BT_PUT(root_a); | |
2931 | BT_PUT(root_b); | |
2932 | BT_PUT(root_b_elem); | |
2933 | BT_PUT(root_c); | |
2934 | ||
2935 | return root; | |
2936 | } | |
2937 | ||
2938 | static | |
2939 | void test_fail_sequence_tag_is_not_int(void) | |
2940 | { | |
2941 | struct bt_ctf_field_type *ep; | |
2942 | struct bt_ctf_event *event; | |
2943 | ||
2944 | ep = test_fail_sequence_tag_is_not_int_get_ep(); | |
2945 | assert(ep); | |
2946 | event = create_event_with_context_and_payload(NULL, ep); | |
2947 | ok(!event, "Sequence FT with non-enum length FT is invalid"); | |
2948 | ||
2949 | BT_PUT(ep); | |
2950 | BT_PUT(event); | |
2951 | } | |
2952 | ||
2953 | static | |
2954 | void test_fail(void) | |
2955 | { | |
2956 | test_fail_unavailable_root(); | |
2957 | test_fail_target_is_root(); | |
2958 | test_fail_target_is_after_source(); | |
2959 | test_fail_target_is_ancestor_of_source(); | |
2960 | test_fail_target_is_source(); | |
2961 | test_fail_variant_tag_is_not_enum(); | |
2962 | test_fail_variant_tag_mismatch_mappings(); | |
2963 | test_fail_sequence_tag_is_not_int(); | |
2964 | } | |
2965 | ||
2966 | int main(void) | |
2967 | { | |
2968 | plan_no_plan(); | |
2969 | ||
2970 | test_pass(); | |
2971 | test_fail(); | |
2972 | ||
2973 | return 0; | |
2974 | } |