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