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