6 * Copyright 2013 - 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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.
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.
22 #include <babeltrace/ctf-writer/writer.h>
23 #include <babeltrace/ctf-writer/clock.h>
24 #include <babeltrace/ctf-writer/stream.h>
25 #include <babeltrace/ctf-writer/event.h>
26 #include <babeltrace/ctf-writer/event-types.h>
27 #include <babeltrace/ctf-writer/event-fields.h>
28 #include <babeltrace/ctf-writer/stream-class.h>
29 #include <babeltrace/ctf-writer/trace.h>
30 #include <babeltrace/ref.h>
31 #include <babeltrace/ctf/events.h>
32 #include <babeltrace/values.h>
35 #include <babeltrace/compat/stdlib-internal.h>
37 #include <babeltrace/compat/limits-internal.h>
38 #include <babeltrace/compat/stdio-internal.h>
47 #define METADATA_LINE_SIZE 512
48 #define SEQUENCE_TEST_LENGTH 10
49 #define ARRAY_TEST_LENGTH 5
50 #define PACKET_RESIZE_TEST_DEF_LENGTH 100000
52 #define DEFAULT_CLOCK_FREQ 1000000000
53 #define DEFAULT_CLOCK_PRECISION 1
54 #define DEFAULT_CLOCK_OFFSET 0
55 #define DEFAULT_CLOCK_OFFSET_S 0
56 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
57 #define DEFAULT_CLOCK_TIME 0
58 #define DEFAULT_CLOCK_VALUE 0
63 char sysname
[BABELTRACE_HOST_NAME_MAX
];
64 char nodename
[BABELTRACE_HOST_NAME_MAX
];
65 char release
[BABELTRACE_HOST_NAME_MAX
];
66 char version
[BABELTRACE_HOST_NAME_MAX
];
67 char machine
[BABELTRACE_HOST_NAME_MAX
];
70 static int64_t current_time
= 42;
71 static unsigned int packet_resize_test_length
= PACKET_RESIZE_TEST_DEF_LENGTH
;
73 /* Return 1 if uuids match, zero if different. */
75 int uuid_match(const unsigned char *uuid_a
, const unsigned char *uuid_b
)
80 if (!uuid_a
|| !uuid_b
) {
84 for (i
= 0; i
< 16; i
++) {
85 if (uuid_a
[i
] != uuid_b
[i
]) {
96 void validate_trace(char *parser_path
, char *trace_path
)
100 char *argv
[] = {parser_path
, trace_path
, "-o", "dummy", NULL
};
102 if (!parser_path
|| !trace_path
) {
107 if (!g_spawn_sync(NULL
,
110 G_SPAWN_STDOUT_TO_DEV_NULL
,
117 diag("Failed to spawn babeltrace.");
122 /* Replace by g_spawn_check_exit_status when we require glib >= 2.34 */
124 ret
= WIFEXITED(exit_status
) ? WEXITSTATUS(exit_status
) : -1;
130 diag("Babeltrace returned an error.");
135 ok(ret
== 0, "Babeltrace could read the resulting trace");
139 void append_simple_event(struct bt_ctf_stream_class
*stream_class
,
140 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
142 /* Create and add a simple event class */
143 struct bt_ctf_event_class
*simple_event_class
=
144 bt_ctf_event_class_create("Simple Event");
145 struct bt_ctf_field_type
*uint_12_type
=
146 bt_ctf_field_type_integer_create(12);
147 struct bt_ctf_field_type
*int_64_type
=
148 bt_ctf_field_type_integer_create(64);
149 struct bt_ctf_field_type
*float_type
=
150 bt_ctf_field_type_floating_point_create();
151 struct bt_ctf_field_type
*enum_type
;
152 struct bt_ctf_field_type
*enum_type_unsigned
=
153 bt_ctf_field_type_enumeration_create(uint_12_type
);
154 struct bt_ctf_field_type
*event_context_type
=
155 bt_ctf_field_type_structure_create();
156 struct bt_ctf_field_type
*event_payload_type
= NULL
;
157 struct bt_ctf_field_type
*returned_type
;
158 struct bt_ctf_event
*simple_event
;
159 struct bt_ctf_field
*integer_field
;
160 struct bt_ctf_field
*float_field
;
161 struct bt_ctf_field
*enum_field
;
162 struct bt_ctf_field
*enum_field_unsigned
;
163 struct bt_ctf_field
*enum_container_field
;
164 const char *mapping_name_test
= "truie";
165 const double double_test_value
= 3.1415;
166 struct bt_ctf_field
*enum_container_field_unsigned
;
167 const char *mapping_name_negative_test
= "negative_value";
168 const char *ret_char
;
170 int64_t ret_range_start_int64_t
, ret_range_end_int64_t
;
171 uint64_t ret_range_start_uint64_t
, ret_range_end_uint64_t
;
172 struct bt_ctf_event_class
*ret_event_class
;
173 struct bt_ctf_field
*packet_context
;
174 struct bt_ctf_field
*packet_context_field
;
175 struct bt_ctf_field
*stream_event_context
;
176 struct bt_ctf_field
*stream_event_context_field
;
177 struct bt_ctf_field
*event_context
;
178 struct bt_ctf_field
*event_context_field
;
179 struct bt_ctf_field_type
*ep_integer_field_type
= NULL
;
180 struct bt_ctf_field_type
*ep_enum_field_type
= NULL
;
181 struct bt_ctf_field_type
*ep_enum_field_unsigned_type
= NULL
;
182 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
185 ok(uint_12_type
, "Create an unsigned integer type");
187 ok(!bt_ctf_field_type_integer_set_signed(int_64_type
, 1),
188 "Set signed 64 bit integer signedness to true");
189 ok(int_64_type
, "Create a signed integer type");
190 enum_type
= bt_ctf_field_type_enumeration_create(int_64_type
);
192 returned_type
= bt_ctf_field_type_enumeration_get_container_field_type(enum_type
);
193 ok(returned_type
== int_64_type
, "bt_ctf_field_type_enumeration_get_container_field_type returns the right type");
194 ok(!bt_ctf_field_type_enumeration_create(enum_type
),
195 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
196 bt_put(returned_type
);
198 bt_ctf_field_type_set_alignment(float_type
, 32);
199 ok(bt_ctf_field_type_get_alignment(float_type
) == 32,
200 "bt_ctf_field_type_get_alignment returns a correct value");
202 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type
, 11) == 0,
203 "Set a floating point type's exponent digit count");
204 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type
, 53) == 0,
205 "Set a floating point type's mantissa digit count");
207 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type
) == 11,
208 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
209 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type
) == 53,
210 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
212 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
213 mapping_name_negative_test
, -12345, 0) == 0,
214 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
215 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
216 "escaping; \"test\"", 1, 1) == 0,
217 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
218 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
219 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
220 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
221 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
222 "event clock int float", 5, 22) == 0,
223 "Accept enumeration mapping strings containing reserved keywords");
224 bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
226 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
227 43, 51) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts duplicate mapping names");
228 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, "something",
229 -500, -400) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts overlapping enum entries");
230 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
231 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
232 bt_ctf_field_type_enumeration_add_mapping(enum_type
, "another entry", -42000, -13000);
234 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type
,
235 "enum_field") == 0, "Add signed enumeration field to event");
237 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, NULL
,
238 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
239 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL string correctly");
240 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, &ret_char
,
241 NULL
, &ret_range_end_int64_t
) == 0,
242 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL start correctly");
243 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, &ret_char
,
244 &ret_range_start_int64_t
, NULL
) == 0,
245 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL end correctly");
246 /* Assumes entries are sorted by range_start values. */
247 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 6, &ret_char
,
248 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
249 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a value");
250 ok(!strcmp(ret_char
, mapping_name_test
),
251 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping name");
252 ok(ret_range_start_int64_t
== 42,
253 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping start");
254 ok(ret_range_end_int64_t
== 42,
255 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping end");
257 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
258 "escaping; \"test\"", 0, 0) == 0,
259 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing quotes");
260 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
261 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
262 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing special characters");
263 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
264 "event clock int float", 5, 22) == 0,
265 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing reserved keywords");
266 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
267 42, 42) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts single-value ranges");
268 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
269 43, 51) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts duplicate mapping names");
270 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, "something",
271 7, 8) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts overlapping enum entries");
272 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
273 55, 54), "bt_ctf_field_type_enumeration_unsigned_add_mapping rejects mapping where end < start");
274 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type_unsigned
,
275 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
277 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned
) == 6,
278 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
280 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, NULL
,
281 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
282 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL string correctly");
283 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, &ret_char
,
284 NULL
, &ret_range_end_uint64_t
) == 0,
285 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL start correctly");
286 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, &ret_char
,
287 &ret_range_start_uint64_t
, NULL
) == 0,
288 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL end correctly");
289 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 4, &ret_char
,
290 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
291 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a value");
292 ok(!strcmp(ret_char
, mapping_name_test
),
293 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping name");
294 ok(ret_range_start_uint64_t
== 42,
295 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping start");
296 ok(ret_range_end_uint64_t
== 42,
297 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping end");
299 bt_ctf_event_class_add_field(simple_event_class
, uint_12_type
,
301 bt_ctf_event_class_add_field(simple_event_class
, float_type
,
304 assert(!bt_ctf_event_class_set_id(simple_event_class
, 13));
306 /* Set an event context type which will contain a single integer. */
307 ok(!bt_ctf_field_type_structure_add_field(event_context_type
, uint_12_type
,
308 "event_specific_context"),
309 "Add event specific context field");
311 ok(bt_ctf_event_class_set_context_field_type(NULL
, event_context_type
) < 0,
312 "bt_ctf_event_class_set_context_field_type handles a NULL event class correctly");
313 ok(!bt_ctf_event_class_set_context_field_type(simple_event_class
, event_context_type
),
314 "Set an event class' context type successfully");
315 returned_type
= bt_ctf_event_class_get_context_field_type(simple_event_class
);
316 ok(returned_type
== event_context_type
,
317 "bt_ctf_event_class_get_context_field_type returns the appropriate type");
318 bt_put(returned_type
);
320 ok(!bt_ctf_stream_class_add_event_class(stream_class
, simple_event_class
),
321 "Adding simple event class to stream class");
324 * bt_ctf_stream_class_add_event_class() copies the field types
325 * of simple_event_class, so we retrieve the new ones to create
326 * the appropriate fields.
328 BT_PUT(event_context_type
);
329 BT_PUT(event_payload_type
);
330 event_payload_type
= bt_ctf_event_class_get_payload_field_type(
332 assert(event_payload_type
);
333 event_context_type
= bt_ctf_event_class_get_context_field_type(
335 assert(event_context_type
);
336 ep_integer_field_type
=
337 bt_ctf_field_type_structure_get_field_type_by_name(
338 event_payload_type
, "integer_field");
339 assert(ep_integer_field_type
);
341 bt_ctf_field_type_structure_get_field_type_by_name(
342 event_payload_type
, "enum_field");
343 assert(ep_enum_field_type
);
344 ep_enum_field_unsigned_type
=
345 bt_ctf_field_type_structure_get_field_type_by_name(
346 event_payload_type
, "enum_field_unsigned");
347 assert(ep_enum_field_unsigned_type
);
349 ok(bt_ctf_stream_class_get_event_class_count(stream_class
) == 1,
350 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
351 ret_event_class
= bt_ctf_stream_class_get_event_class_by_index(stream_class
, 0);
352 ok(ret_event_class
== simple_event_class
,
353 "bt_ctf_stream_class_get_event_class returns the correct event class");
354 bt_put(ret_event_class
);
355 ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class
, 2),
356 "bt_ctf_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
358 bt_ctf_stream_class_get_event_class_by_id(stream_class
, 13);
359 ok(ret_event_class
== simple_event_class
,
360 "bt_ctf_stream_class_get_event_class_by_id returns a correct event class");
361 bt_put(ret_event_class
);
363 simple_event
= bt_ctf_event_create(simple_event_class
);
365 "Instantiate an event containing a single integer field");
367 integer_field
= bt_ctf_field_create(ep_integer_field_type
);
368 bt_ctf_field_integer_unsigned_set_value(integer_field
, 42);
369 ok(bt_ctf_event_set_payload(simple_event
, "integer_field",
370 integer_field
) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
372 float_field
= bt_ctf_event_get_payload(simple_event
, "float_field");
373 bt_ctf_field_floating_point_set_value(float_field
, double_test_value
);
374 ok(!bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
375 "bt_ctf_field_floating_point_get_value returns a double value");
376 ok(fabs(ret_double
- double_test_value
) <= DBL_EPSILON
,
377 "bt_ctf_field_floating_point_get_value returns a correct value");
379 enum_field
= bt_ctf_field_create(ep_enum_field_type
);
382 enum_container_field
= bt_ctf_field_enumeration_get_container(enum_field
);
383 ok(bt_ctf_field_integer_signed_set_value(
384 enum_container_field
, -42) == 0,
385 "Set signed enumeration container value");
386 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field", enum_field
);
390 enum_field_unsigned
= bt_ctf_field_create(ep_enum_field_unsigned_type
);
391 assert(enum_field_unsigned
);
392 enum_container_field_unsigned
= bt_ctf_field_enumeration_get_container(
393 enum_field_unsigned
);
394 ok(bt_ctf_field_integer_unsigned_set_value(
395 enum_container_field_unsigned
, 42) == 0,
396 "Set unsigned enumeration container value");
397 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field_unsigned",
398 enum_field_unsigned
);
401 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0, "Set clock time");
403 /* Populate stream event context */
404 stream_event_context
=
405 bt_ctf_event_get_stream_event_context(simple_event
);
406 assert(stream_event_context
);
407 stream_event_context_field
= bt_ctf_field_structure_get_field_by_name(
408 stream_event_context
, "common_event_context");
409 bt_ctf_field_integer_unsigned_set_value(stream_event_context_field
, 42);
411 /* Populate the event's context */
412 event_context
= bt_ctf_event_get_context(simple_event
);
414 "bt_ctf_event_get_context returns a field");
415 returned_type
= bt_ctf_field_get_type(event_context
);
416 ok(returned_type
== event_context_type
,
417 "bt_ctf_event_get_context returns a field of the appropriate type");
418 event_context_field
= bt_ctf_field_structure_get_field_by_name(event_context
,
419 "event_specific_context");
420 ok(!bt_ctf_field_integer_unsigned_set_value(event_context_field
, 1234),
421 "Successfully set an event context's value");
422 ok(!bt_ctf_event_set_context(simple_event
, event_context
),
423 "Set an event context successfully");
425 ok(bt_ctf_stream_append_event(stream
, simple_event
) == 0,
426 "Append simple event to trace stream");
428 packet_context
= bt_ctf_stream_get_packet_context(stream
);
430 "bt_ctf_stream_get_packet_context returns a packet context");
432 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
434 ok(packet_context_field
,
435 "Packet context contains the default packet_size field.");
436 bt_put(packet_context_field
);
437 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
438 "custom_packet_context_field");
439 ok(bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 8) == 0,
440 "Custom packet context field value successfully set.");
442 ok(bt_ctf_stream_set_packet_context(stream
, packet_context
) == 0,
443 "Successfully set a stream's packet context");
445 ok(bt_ctf_stream_flush(stream
) == 0,
446 "Flush trace stream with one event");
448 bt_put(simple_event_class
);
449 bt_put(simple_event
);
450 bt_put(uint_12_type
);
454 bt_put(enum_type_unsigned
);
455 bt_put(returned_type
);
456 bt_put(event_context_type
);
457 bt_put(integer_field
);
460 bt_put(enum_field_unsigned
);
461 bt_put(enum_container_field
);
462 bt_put(enum_container_field_unsigned
);
463 bt_put(packet_context
);
464 bt_put(packet_context_field
);
465 bt_put(stream_event_context
);
466 bt_put(stream_event_context_field
);
467 bt_put(event_context
);
468 bt_put(event_context_field
);
469 bt_put(event_payload_type
);
470 bt_put(ep_integer_field_type
);
471 bt_put(ep_enum_field_type
);
472 bt_put(ep_enum_field_unsigned_type
);
477 void append_complex_event(struct bt_ctf_stream_class
*stream_class
,
478 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
481 struct event_class_attrs_counts
;
482 const char *complex_test_event_string
= "Complex Test Event";
483 const char *test_string_1
= "Test ";
484 const char *test_string_2
= "string ";
485 const char *test_string_3
= "abcdefghi";
486 const char *test_string_4
= "abcd\0efg\0hi";
487 const char *test_string_cat
= "Test string abcdeefg";
488 struct bt_ctf_field_type
*uint_35_type
=
489 bt_ctf_field_type_integer_create(35);
490 struct bt_ctf_field_type
*int_16_type
=
491 bt_ctf_field_type_integer_create(16);
492 struct bt_ctf_field_type
*uint_3_type
=
493 bt_ctf_field_type_integer_create(3);
494 struct bt_ctf_field_type
*enum_variant_type
=
495 bt_ctf_field_type_enumeration_create(uint_3_type
);
496 struct bt_ctf_field_type
*variant_type
=
497 bt_ctf_field_type_variant_create(enum_variant_type
,
499 struct bt_ctf_field_type
*string_type
=
500 bt_ctf_field_type_string_create();
501 struct bt_ctf_field_type
*sequence_type
;
502 struct bt_ctf_field_type
*array_type
;
503 struct bt_ctf_field_type
*inner_structure_type
=
504 bt_ctf_field_type_structure_create();
505 struct bt_ctf_field_type
*complex_structure_type
=
506 bt_ctf_field_type_structure_create();
507 struct bt_ctf_field_type
*ret_field_type
;
508 struct bt_ctf_event_class
*event_class
;
509 struct bt_ctf_event
*event
;
510 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
511 *inner_structure_field
, *complex_structure_field
,
512 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
513 *variant_field
, *an_array_field
, *stream_event_ctx_field
,
514 *stream_event_ctx_int_field
;
515 uint64_t ret_unsigned_int
;
516 int64_t ret_signed_int
;
517 const char *ret_string
;
518 struct bt_ctf_stream_class
*ret_stream_class
;
519 struct bt_ctf_event_class
*ret_event_class
;
520 struct bt_ctf_field
*packet_context
, *packet_context_field
;
522 ok(bt_ctf_field_type_set_alignment(int_16_type
, 0),
523 "bt_ctf_field_type_set_alignment handles 0-alignment correctly");
524 ok(bt_ctf_field_type_set_alignment(int_16_type
, 3),
525 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (3)");
526 ok(bt_ctf_field_type_set_alignment(int_16_type
, 24),
527 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (24)");
528 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 4),
529 "bt_ctf_field_type_set_alignment handles correct alignment correctly (4)");
530 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 32),
531 "Set alignment of signed 16 bit integer to 32");
532 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
533 "Set integer signedness to true");
534 ok(!bt_ctf_field_type_integer_set_base(uint_35_type
,
535 BT_CTF_INTEGER_BASE_HEXADECIMAL
),
536 "Set signed 16 bit integer base to hexadecimal");
538 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
539 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
542 ret_field_type
= bt_ctf_field_type_array_get_element_field_type(
544 ok(ret_field_type
== int_16_type
,
545 "bt_ctf_field_type_array_get_element_field_type returns the correct type");
546 bt_put(ret_field_type
);
548 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
549 "bt_ctf_field_type_array_get_length returns the correct length");
551 ok(bt_ctf_field_type_structure_add_field(inner_structure_type
,
552 inner_structure_type
, "yes"), "Cannot add self to structure");
553 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
554 uint_35_type
, "seq_len"), "Add seq_len field to inner structure");
555 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
556 sequence_type
, "a_sequence"), "Add a_sequence field to inner structure");
557 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
558 array_type
, "an_array"), "Add an_array field to inner structure");
560 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
562 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
564 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
565 "UINT35_TYPE", 2, 7);
567 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
568 "An unknown entry"), "Reject a variant field based on an unknown tag value");
569 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
570 "UINT3_TYPE") == 0, "Add a field to a variant");
571 ok(!bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
572 "INT16_TYPE"), "Add INT16_TYPE field to variant");
573 ok(!bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
574 "UINT35_TYPE"), "Add UINT35_TYPE field to variant");
576 ret_field_type
= bt_ctf_field_type_variant_get_tag_field_type(variant_type
);
577 ok(ret_field_type
== enum_variant_type
,
578 "bt_ctf_field_type_variant_get_tag_field_type returns a correct tag type");
579 bt_put(ret_field_type
);
581 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
582 ok(ret_string
? !strcmp(ret_string
, "variant_selector") : 0,
583 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
584 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
585 variant_type
, "INT16_TYPE");
586 ok(ret_field_type
== int_16_type
,
587 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
588 bt_put(ret_field_type
);
590 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
591 "bt_ctf_field_type_variant_get_field_count returns the correct count");
593 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, NULL
, &ret_field_type
, 0) == 0,
594 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
595 bt_put(ret_field_type
);
596 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, &ret_string
, NULL
, 0) == 0,
597 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
598 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
599 "bt_ctf_field_type_variant_get_field returns a field");
600 ok(!strcmp("INT16_TYPE", ret_string
),
601 "bt_ctf_field_type_variant_get_field returns a correct field name");
602 ok(ret_field_type
== int_16_type
,
603 "bt_ctf_field_type_variant_get_field returns a correct field type");
604 bt_put(ret_field_type
);
606 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
607 enum_variant_type
, "variant_selector"),
608 "Add variant_selector field to complex structure");
609 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
610 string_type
, "string"), "Add `string` field to complex structure");
611 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
612 variant_type
, "variant_value"),
613 "Add variant_value field to complex structure");
614 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
615 inner_structure_type
, "inner_structure"),
616 "Add inner_structure field to complex structure");
618 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
619 ok(event_class
, "Create an event class");
620 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
621 "Reject addition of a field with an empty name to an event");
622 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
623 "Reject addition of a field with a NULL type to an event");
624 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
626 "Reject addition of a type with an illegal name to an event");
627 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
629 "Add field of type unsigned integer to an event");
630 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
631 "int_16") == 0, "Add field of type signed integer to an event");
632 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
633 "complex_structure") == 0,
634 "Add composite structure to an event");
636 ret_string
= bt_ctf_event_class_get_name(event_class
);
637 ok(!strcmp(ret_string
, complex_test_event_string
),
638 "bt_ctf_event_class_get_name returns a correct name");
639 ok(bt_ctf_event_class_get_id(event_class
) < 0,
640 "bt_ctf_event_class_get_id returns a negative value when not set");
641 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
642 "bt_ctf_event_class_set_id handles NULL correctly");
643 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
644 "Set an event class' id");
645 ok(bt_ctf_event_class_get_id(event_class
) == 42,
646 "bt_ctf_event_class_get_id returns the correct value");
648 /* Test event class attributes */
649 ok(bt_ctf_event_class_get_log_level(event_class
) == BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
,
650 "event class has the expected initial log level");
651 ok(!bt_ctf_event_class_get_emf_uri(event_class
),
652 "as expected, event class has no initial EMF URI");
653 ok(bt_ctf_event_class_set_log_level(NULL
, BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
),
654 "bt_ctf_event_class_set_log_level handles a NULL event class correctly");
655 ok(bt_ctf_event_class_set_log_level(event_class
, BT_CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN
),
656 "bt_ctf_event_class_set_log_level handles an unknown log level correctly");
657 ok(!bt_ctf_event_class_set_log_level(event_class
, BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
),
658 "bt_ctf_event_class_set_log_level succeeds with a valid log level");
659 ok(bt_ctf_event_class_get_log_level(event_class
) == BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
,
660 "bt_ctf_event_class_get_log_level returns the expected log level");
661 ok(bt_ctf_event_class_set_emf_uri(NULL
, "http://diamon.org/babeltrace/"),
662 "bt_ctf_event_class_set_emf_uri handles a NULL event class correctly");
663 ok(!bt_ctf_event_class_set_emf_uri(event_class
, "http://diamon.org/babeltrace/"),
664 "bt_ctf_event_class_set_emf_uri succeeds with a valid EMF URI");
665 ok(strcmp(bt_ctf_event_class_get_emf_uri(event_class
), "http://diamon.org/babeltrace/") == 0,
666 "bt_ctf_event_class_get_emf_uri returns the expected EMF URI");
667 ok(!bt_ctf_event_class_set_emf_uri(event_class
, NULL
),
668 "bt_ctf_event_class_set_emf_uri succeeds with NULL (to reset)");
669 ok(!bt_ctf_event_class_get_emf_uri(event_class
),
670 "as expected, event class has no EMF URI after reset");
672 /* Add event class to the stream class */
673 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
674 "Reject addition of NULL event class to a stream class");
675 ok(bt_ctf_stream_class_add_event_class(stream_class
,
676 event_class
) == 0, "Add an event class to stream class");
678 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
679 ok(ret_stream_class
== stream_class
,
680 "bt_ctf_event_class_get_stream_class returns the correct stream class");
681 bt_put(ret_stream_class
);
683 ok(bt_ctf_event_class_get_field_by_name(event_class
, "truie") == NULL
,
684 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
685 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
686 "complex_structure");
687 bt_put(ret_field_type
);
689 event
= bt_ctf_event_create(event_class
);
690 ok(event
, "Instanciate a complex event");
692 ret_event_class
= bt_ctf_event_get_class(event
);
693 ok(ret_event_class
== event_class
,
694 "bt_ctf_event_get_class returns the correct event class");
695 bt_put(ret_event_class
);
697 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
698 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
699 bt_ctf_field_integer_unsigned_set_value(uint_35_field
, 0x0DDF00D);
700 ok(bt_ctf_field_integer_unsigned_get_value(uint_35_field
,
701 &ret_unsigned_int
) == 0,
702 "bt_ctf_field_integer_unsigned_get_value succeeds after setting a value");
703 ok(ret_unsigned_int
== 0x0DDF00D,
704 "bt_ctf_field_integer_unsigned_get_value returns the correct value");
705 bt_put(uint_35_field
);
707 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
708 bt_ctf_field_integer_signed_set_value(int_16_field
, -12345);
709 ok(bt_ctf_field_integer_signed_get_value(int_16_field
,
710 &ret_signed_int
) == 0,
711 "bt_ctf_field_integer_signed_get_value succeeds after setting a value");
712 ok(ret_signed_int
== -12345,
713 "bt_ctf_field_integer_signed_get_value returns the correct value");
714 bt_put(int_16_field
);
716 complex_structure_field
= bt_ctf_event_get_payload(event
,
717 "complex_structure");
719 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
720 complex_structure_field
, 3);
721 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
722 bt_put(inner_structure_field
);
723 bt_put(ret_field_type
);
725 inner_structure_field
= bt_ctf_field_structure_get_field_by_name(
726 complex_structure_field
, "inner_structure");
727 a_string_field
= bt_ctf_field_structure_get_field_by_name(
728 complex_structure_field
, "string");
729 enum_variant_field
= bt_ctf_field_structure_get_field_by_name(
730 complex_structure_field
, "variant_selector");
731 variant_field
= bt_ctf_field_structure_get_field_by_name(
732 complex_structure_field
, "variant_value");
733 uint_35_field
= bt_ctf_field_structure_get_field_by_name(
734 inner_structure_field
, "seq_len");
735 a_sequence_field
= bt_ctf_field_structure_get_field_by_name(
736 inner_structure_field
, "a_sequence");
737 an_array_field
= bt_ctf_field_structure_get_field_by_name(
738 inner_structure_field
, "an_array");
740 enum_container_field
= bt_ctf_field_enumeration_get_container(
742 bt_ctf_field_integer_unsigned_set_value(enum_container_field
, 1);
743 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
745 bt_ctf_field_integer_signed_set_value(int_16_field
, -200);
746 bt_put(int_16_field
);
747 bt_ctf_field_string_set_value(a_string_field
,
749 ok(!bt_ctf_field_string_append(a_string_field
, test_string_2
),
750 "bt_ctf_field_string_append succeeds");
751 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 5),
752 "bt_ctf_field_string_append_len succeeds (append 5 characters)");
753 ok(!bt_ctf_field_string_append_len(a_string_field
, &test_string_4
[5], 3),
754 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
755 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 0),
756 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
758 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
759 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
760 ok(ret_string
? !strcmp(ret_string
, test_string_cat
) : 0,
761 "bt_ctf_field_string_get_value returns a correct value");
762 bt_ctf_field_integer_unsigned_set_value(uint_35_field
,
763 SEQUENCE_TEST_LENGTH
);
765 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
766 variant_type
, enum_variant_field
);
767 ok(ret_field_type
== int_16_type
,
768 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
770 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
771 uint_35_field
) == 0, "Set a sequence field's length");
773 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
774 int_16_field
= bt_ctf_field_sequence_get_field(
775 a_sequence_field
, i
);
776 bt_ctf_field_integer_signed_set_value(int_16_field
, 4 - i
);
777 bt_put(int_16_field
);
780 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
781 int_16_field
= bt_ctf_field_array_get_field(
783 bt_ctf_field_integer_signed_set_value(int_16_field
, i
);
784 bt_put(int_16_field
);
787 stream_event_ctx_field
= bt_ctf_event_get_stream_event_context(event
);
788 assert(stream_event_ctx_field
);
789 stream_event_ctx_int_field
= bt_ctf_field_structure_get_field_by_name(
790 stream_event_ctx_field
, "common_event_context");
791 BT_PUT(stream_event_ctx_field
);
792 bt_ctf_field_integer_unsigned_set_value(stream_event_ctx_int_field
, 17);
793 BT_PUT(stream_event_ctx_int_field
);
795 bt_ctf_clock_set_time(clock
, ++current_time
);
796 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
797 "Append a complex event to a stream");
800 * Populate the custom packet context field with a dummy value
801 * otherwise flush will fail.
803 packet_context
= bt_ctf_stream_get_packet_context(stream
);
804 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
805 "custom_packet_context_field");
806 bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 1);
808 ok(bt_ctf_stream_flush(stream
) == 0,
809 "Flush a stream containing a complex event");
811 bt_put(uint_35_field
);
812 bt_put(a_string_field
);
813 bt_put(inner_structure_field
);
814 bt_put(complex_structure_field
);
815 bt_put(a_sequence_field
);
816 bt_put(an_array_field
);
817 bt_put(enum_variant_field
);
818 bt_put(enum_container_field
);
819 bt_put(variant_field
);
820 bt_put(packet_context_field
);
821 bt_put(packet_context
);
822 bt_put(uint_35_type
);
825 bt_put(sequence_type
);
827 bt_put(inner_structure_type
);
828 bt_put(complex_structure_type
);
830 bt_put(enum_variant_type
);
831 bt_put(variant_type
);
832 bt_put(ret_field_type
);
838 void type_field_tests()
840 struct bt_ctf_field
*uint_12
;
841 struct bt_ctf_field
*int_16
;
842 struct bt_ctf_field
*string
;
843 struct bt_ctf_field_type
*composite_structure_type
;
844 struct bt_ctf_field_type
*structure_seq_type
;
845 struct bt_ctf_field_type
*string_type
;
846 struct bt_ctf_field_type
*sequence_type
;
847 struct bt_ctf_field_type
*uint_8_type
;
848 struct bt_ctf_field_type
*int_16_type
;
849 struct bt_ctf_field_type
*uint_12_type
=
850 bt_ctf_field_type_integer_create(12);
851 struct bt_ctf_field_type
*enumeration_type
;
852 struct bt_ctf_field_type
*returned_type
;
853 const char *ret_string
;
855 ok(uint_12_type
, "Create an unsigned integer type");
856 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
857 BT_CTF_INTEGER_BASE_BINARY
) == 0,
858 "Set integer type's base as binary");
859 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
860 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
861 "Set integer type's base as decimal");
862 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
863 BT_CTF_INTEGER_BASE_UNKNOWN
),
864 "Reject integer type's base set as unknown");
865 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
866 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
867 "Set integer type's base as octal");
868 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
869 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
870 "Set integer type's base as hexadecimal");
871 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
872 "Reject unknown integer base value");
873 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
874 "Set integer type signedness to signed");
875 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
876 "Set integer type signedness to unsigned");
877 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
878 "bt_ctf_field_type_integer_get_size returns a correct value");
879 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
880 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
882 ok(bt_ctf_field_type_set_byte_order(NULL
,
883 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
884 "bt_ctf_field_type_set_byte_order handles NULL correctly");
885 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
886 (enum bt_ctf_byte_order
) 42) < 0,
887 "bt_ctf_field_type_set_byte_order rejects invalid values");
888 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
889 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
890 "Set an integer's byte order to little endian");
891 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
892 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
893 "Set an integer's byte order to big endian");
894 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
895 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
896 "bt_ctf_field_type_get_byte_order returns a correct value");
898 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
899 BT_CTF_FIELD_TYPE_ID_INTEGER
,
900 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
902 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
903 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
904 "bt_ctf_field_type_integer_get_base returns a correct value");
906 ok(bt_ctf_field_type_integer_set_encoding(NULL
,
907 BT_CTF_STRING_ENCODING_ASCII
) < 0,
908 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
909 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
910 (enum bt_ctf_string_encoding
) 123) < 0,
911 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
912 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
913 BT_CTF_STRING_ENCODING_UTF8
) == 0,
914 "Set integer type encoding to UTF8");
915 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) ==
916 BT_CTF_STRING_ENCODING_UTF8
,
917 "bt_ctf_field_type_integer_get_encoding returns a correct value");
919 int_16_type
= bt_ctf_field_type_integer_create(16);
921 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
922 "Set signedness of 16 bit integer to true");
923 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
924 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
925 uint_8_type
= bt_ctf_field_type_integer_create(8);
927 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
928 ok(sequence_type
, "Create a sequence of int16_t type");
929 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
930 BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
931 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
933 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
935 ok(!strcmp(ret_string
, "seq_len"),
936 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
937 returned_type
= bt_ctf_field_type_sequence_get_element_field_type(
939 ok(returned_type
== int_16_type
,
940 "bt_ctf_field_type_sequence_get_element_field_type returns the correct type");
941 bt_put(returned_type
);
943 string_type
= bt_ctf_field_type_string_create();
944 ok(string_type
, "Create a string type");
945 ok(bt_ctf_field_type_string_set_encoding(string_type
,
946 BT_CTF_STRING_ENCODING_NONE
),
947 "Reject invalid \"None\" string encoding");
948 ok(bt_ctf_field_type_string_set_encoding(string_type
,
950 "Reject invalid string encoding");
951 ok(bt_ctf_field_type_string_set_encoding(string_type
,
952 BT_CTF_STRING_ENCODING_ASCII
) == 0,
953 "Set string encoding to ASCII");
955 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
956 BT_CTF_STRING_ENCODING_ASCII
,
957 "bt_ctf_field_type_string_get_encoding returns the correct value");
959 structure_seq_type
= bt_ctf_field_type_structure_create();
960 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
961 BT_CTF_FIELD_TYPE_ID_STRUCT
,
962 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
963 ok(structure_seq_type
, "Create a structure type");
964 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
965 uint_8_type
, "seq_len") == 0,
966 "Add a uint8_t type to a structure");
967 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
968 sequence_type
, "a_sequence") == 0,
969 "Add a sequence type to a structure");
971 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
972 "bt_ctf_field_type_structure_get_field_count returns a correct value");
974 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
975 NULL
, &returned_type
, 1) == 0,
976 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
977 bt_put(returned_type
);
978 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
979 &ret_string
, NULL
, 1) == 0,
980 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
981 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
982 &ret_string
, &returned_type
, 1) == 0,
983 "bt_ctf_field_type_structure_get_field returns a field");
984 ok(!strcmp(ret_string
, "a_sequence"),
985 "bt_ctf_field_type_structure_get_field returns a correct field name");
986 ok(returned_type
== sequence_type
,
987 "bt_ctf_field_type_structure_get_field returns a correct field type");
988 bt_put(returned_type
);
990 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
991 structure_seq_type
, "a_sequence");
992 ok(returned_type
== sequence_type
,
993 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
994 bt_put(returned_type
);
996 composite_structure_type
= bt_ctf_field_type_structure_create();
997 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
998 string_type
, "a_string") == 0,
999 "Add a string type to a structure");
1000 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1001 structure_seq_type
, "inner_structure") == 0,
1002 "Add a structure type to a structure");
1004 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1005 structure_seq_type
, "a_sequence");
1006 ok(returned_type
== sequence_type
,
1007 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1008 bt_put(returned_type
);
1010 int_16
= bt_ctf_field_create(int_16_type
);
1011 ok(int_16
, "Instanciate a signed 16-bit integer");
1012 uint_12
= bt_ctf_field_create(uint_12_type
);
1013 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1014 returned_type
= bt_ctf_field_get_type(int_16
);
1015 ok(returned_type
== int_16_type
,
1016 "bt_ctf_field_get_type returns the correct type");
1018 /* Can't modify types after instanciating them */
1019 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1020 BT_CTF_INTEGER_BASE_DECIMAL
),
1021 "Check an integer type' base can't be modified after instanciation");
1022 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1023 "Check an integer type's signedness can't be modified after instanciation");
1025 /* Check overflows are properly tested for */
1026 ok(bt_ctf_field_integer_signed_set_value(int_16
, -32768) == 0,
1027 "Check -32768 is allowed for a signed 16-bit integer");
1028 ok(bt_ctf_field_integer_signed_set_value(int_16
, 32767) == 0,
1029 "Check 32767 is allowed for a signed 16-bit integer");
1030 ok(bt_ctf_field_integer_signed_set_value(int_16
, -42) == 0,
1031 "Check -42 is allowed for a signed 16-bit integer");
1033 ok(bt_ctf_field_integer_unsigned_set_value(uint_12
, 4095) == 0,
1034 "Check 4095 is allowed for an unsigned 12-bit integer");
1035 ok(bt_ctf_field_integer_unsigned_set_value(uint_12
, 0) == 0,
1036 "Check 0 is allowed for an unsigned 12-bit integer");
1038 string
= bt_ctf_field_create(string_type
);
1039 ok(string
, "Instanciate a string field");
1040 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1041 "Set a string's value");
1043 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1044 ok(enumeration_type
,
1045 "Create an enumeration type with an unsigned 12-bit integer as container");
1050 bt_put(composite_structure_type
);
1051 bt_put(structure_seq_type
);
1052 bt_put(string_type
);
1053 bt_put(sequence_type
);
1054 bt_put(uint_8_type
);
1055 bt_put(int_16_type
);
1056 bt_put(uint_12_type
);
1057 bt_put(enumeration_type
);
1058 bt_put(returned_type
);
1062 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
1063 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
1066 * Append enough events to force the underlying packet to be resized.
1067 * Also tests that a new event can be declared after a stream has been
1068 * instantiated and used/flushed.
1072 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
1074 struct bt_ctf_field_type
*integer_type
=
1075 bt_ctf_field_type_integer_create(17);
1076 struct bt_ctf_field_type
*string_type
=
1077 bt_ctf_field_type_string_create();
1078 struct bt_ctf_event
*event
= NULL
;
1079 struct bt_ctf_field
*ret_field
= NULL
;
1080 struct bt_ctf_field_type
*ret_field_type
= NULL
;
1081 uint64_t ret_uint64
;
1082 int events_appended
= 0;
1083 struct bt_ctf_field
*packet_context
= NULL
,
1084 *packet_context_field
= NULL
, *stream_event_context
= NULL
;
1085 struct bt_ctf_field_type
*ep_field_1_type
= NULL
;
1086 struct bt_ctf_field_type
*ep_a_string_type
= NULL
;
1087 struct bt_ctf_field_type
*ep_type
= NULL
;
1089 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
1091 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
1093 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1094 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
1100 * bt_ctf_stream_class_add_event_class() copies the field types
1101 * of event_class, so we retrieve the new ones to create the
1102 * appropriate fields.
1104 ep_type
= bt_ctf_event_class_get_payload_field_type(event_class
);
1106 ep_field_1_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1107 ep_type
, "field_1");
1108 assert(ep_field_1_type
);
1109 ep_a_string_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1110 ep_type
, "a_string");
1111 assert(ep_a_string_type
);
1113 event
= bt_ctf_event_create(event_class
);
1114 ret_field
= bt_ctf_event_get_payload(event
, 0);
1115 ret_field_type
= bt_ctf_field_get_type(ret_field
);
1116 bt_put(ret_field_type
);
1120 for (i
= 0; i
< packet_resize_test_length
; i
++) {
1121 event
= bt_ctf_event_create(event_class
);
1122 struct bt_ctf_field
*integer
=
1123 bt_ctf_field_create(ep_field_1_type
);
1124 struct bt_ctf_field
*string
=
1125 bt_ctf_field_create(ep_a_string_type
);
1127 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
1128 ret
|= bt_ctf_field_integer_unsigned_set_value(integer
, i
);
1129 ret
|= bt_ctf_event_set_payload(event
, "field_1",
1132 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
1133 ret
|= bt_ctf_event_set_payload(event
, "a_string",
1137 /* Populate stream event context */
1138 stream_event_context
=
1139 bt_ctf_event_get_stream_event_context(event
);
1140 integer
= bt_ctf_field_structure_get_field_by_name(stream_event_context
,
1141 "common_event_context");
1142 BT_PUT(stream_event_context
);
1143 ret
|= bt_ctf_field_integer_unsigned_set_value(integer
,
1147 ret
|= bt_ctf_stream_append_event(stream
, event
);
1155 events_appended
= !!(i
== packet_resize_test_length
);
1156 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1157 ok(ret
== 0 && ret_uint64
== 0,
1158 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1159 bt_ctf_stream_append_discarded_events(stream
, 1000);
1160 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1161 ok(ret
== 0 && ret_uint64
== 1000,
1162 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1165 ok(events_appended
, "Append 100 000 events to a stream");
1168 * Populate the custom packet context field with a dummy value
1169 * otherwise flush will fail.
1171 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1172 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
1173 "custom_packet_context_field");
1174 bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 2);
1176 ok(bt_ctf_stream_flush(stream
) == 0,
1177 "Flush a stream that forces a packet resize");
1178 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1179 ok(ret
== 0 && ret_uint64
== 1000,
1180 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1181 bt_put(integer_type
);
1182 bt_put(string_type
);
1183 bt_put(packet_context
);
1184 bt_put(packet_context_field
);
1185 bt_put(stream_event_context
);
1186 bt_put(event_class
);
1187 bt_put(ep_field_1_type
);
1188 bt_put(ep_a_string_type
);
1193 void test_empty_stream(struct bt_ctf_writer
*writer
)
1196 struct bt_ctf_trace
*trace
= NULL
, *ret_trace
= NULL
;
1197 struct bt_ctf_stream_class
*stream_class
= NULL
;
1198 struct bt_ctf_stream
*stream
= NULL
;
1200 trace
= bt_ctf_writer_get_trace(writer
);
1202 diag("Failed to get trace from writer");
1207 stream_class
= bt_ctf_stream_class_create("empty_stream");
1208 if (!stream_class
) {
1209 diag("Failed to create stream class");
1214 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
1216 ret
= bt_ctf_stream_class_set_event_header_type(stream_class
, NULL
);
1219 ok(bt_ctf_stream_class_get_trace(stream_class
) == NULL
,
1220 "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned");
1222 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1224 diag("Failed to create writer stream");
1229 ret_trace
= bt_ctf_stream_class_get_trace(stream_class
);
1230 ok(ret_trace
== trace
,
1231 "bt_ctf_stream_class_get_trace returns the correct trace after a stream has been created");
1234 "Created a stream class with default attributes and an empty stream");
1238 bt_put(stream_class
);
1242 void test_custom_event_header_stream(struct bt_ctf_writer
*writer
,
1243 struct bt_ctf_clock
*clock
)
1246 struct bt_ctf_stream_class
*stream_class
= NULL
;
1247 struct bt_ctf_stream
*stream
= NULL
;
1248 struct bt_ctf_field_type
*integer_type
= NULL
,
1249 *sequence_type
= NULL
, *event_header_type
= NULL
;
1250 struct bt_ctf_field
*integer
= NULL
, *sequence
= NULL
,
1251 *event_header
= NULL
, *packet_header
= NULL
;
1252 struct bt_ctf_event_class
*event_class
= NULL
;
1253 struct bt_ctf_event
*event
= NULL
;
1255 stream_class
= bt_ctf_stream_class_create("custom_event_header_stream");
1256 if (!stream_class
) {
1257 fail("Failed to create stream class");
1261 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1263 fail("Failed to set stream class clock");
1268 * Customize event header to add an "seq_len" integer member
1269 * which will be used as the length of a sequence in an event of this
1272 event_header_type
= bt_ctf_stream_class_get_event_header_type(
1274 if (!event_header_type
) {
1275 fail("Failed to get event header type");
1279 integer_type
= bt_ctf_field_type_integer_create(13);
1280 if (!integer_type
) {
1281 fail("Failed to create length integer type");
1285 ret
= bt_ctf_field_type_structure_add_field(event_header_type
,
1286 integer_type
, "seq_len");
1288 fail("Failed to add a new field to stream event header");
1292 event_class
= bt_ctf_event_class_create("sequence_event");
1294 fail("Failed to create event class");
1299 * This event's payload will contain a sequence which references
1300 * stream.event.header.seq_len as its length field.
1302 sequence_type
= bt_ctf_field_type_sequence_create(integer_type
,
1303 "stream.event.header.seq_len");
1304 if (!sequence_type
) {
1305 fail("Failed to create a sequence");
1309 ret
= bt_ctf_event_class_add_field(event_class
, sequence_type
,
1312 fail("Failed to add a sequence to an event class");
1316 ret
= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1318 fail("Failed to add event class to stream class");
1322 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1324 fail("Failed to create stream")
1329 * We have defined a custom packet header field. We have to populate it
1332 packet_header
= bt_ctf_stream_get_packet_header(stream
);
1333 if (!packet_header
) {
1334 fail("Failed to get stream packet header");
1338 integer
= bt_ctf_field_structure_get_field_by_name(packet_header
,
1339 "custom_trace_packet_header_field");
1341 fail("Failed to retrieve custom_trace_packet_header_field");
1345 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 3487);
1347 fail("Failed to set custom_trace_packet_header_field value");
1352 event
= bt_ctf_event_create(event_class
);
1354 fail("Failed to create event");
1358 event_header
= bt_ctf_event_get_header(event
);
1359 if (!event_header
) {
1360 fail("Failed to get event header");
1364 integer
= bt_ctf_field_structure_get_field_by_name(event_header
,
1367 fail("Failed to get seq_len field from event header");
1371 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 2);
1373 fail("Failed to set seq_len value in event header");
1377 /* Populate both sequence integer fields */
1378 sequence
= bt_ctf_event_get_payload(event
, "some_sequence");
1380 fail("Failed to retrieve sequence from event");
1384 ret
= bt_ctf_field_sequence_set_length(sequence
, integer
);
1386 fail("Failed to set sequence length");
1391 for (i
= 0; i
< 2; i
++) {
1392 integer
= bt_ctf_field_sequence_get_field(sequence
, i
);
1394 fail("Failed to retrieve sequence element");
1398 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, i
);
1400 fail("Failed to set sequence element value");
1408 ret
= bt_ctf_stream_append_event(stream
, event
);
1410 fail("Failed to append event to stream");
1414 ret
= bt_ctf_stream_flush(stream
);
1416 fail("Failed to flush custom_event_header stream");
1420 bt_put(stream_class
);
1421 bt_put(event_class
);
1425 bt_put(event_header
);
1426 bt_put(packet_header
);
1427 bt_put(sequence_type
);
1428 bt_put(integer_type
);
1429 bt_put(event_header_type
);
1433 void test_instanciate_event_before_stream(struct bt_ctf_writer
*writer
,
1434 struct bt_ctf_clock
*clock
)
1437 struct bt_ctf_stream_class
*stream_class
= NULL
;
1438 struct bt_ctf_stream
*stream
= NULL
,
1440 struct bt_ctf_event_class
*event_class
= NULL
;
1441 struct bt_ctf_event
*event
= NULL
;
1442 struct bt_ctf_field_type
*integer_type
= NULL
;
1443 struct bt_ctf_field
*payload_field
= NULL
;
1444 struct bt_ctf_field
*integer
= NULL
;
1446 stream_class
= bt_ctf_stream_class_create("event_before_stream_test");
1447 if (!stream_class
) {
1448 diag("Failed to create stream class");
1453 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1455 diag("Failed to set stream class clock");
1459 event_class
= bt_ctf_event_class_create("some_event_class_name");
1460 integer_type
= bt_ctf_field_type_integer_create(32);
1461 if (!integer_type
) {
1462 diag("Failed to create integer field type");
1467 ret
= bt_ctf_event_class_add_field(event_class
, integer_type
,
1470 diag("Failed to add field to event class");
1474 ret
= bt_ctf_stream_class_add_event_class(stream_class
,
1477 diag("Failed to add event class to stream class");
1480 event
= bt_ctf_event_create(event_class
);
1482 diag("Failed to create event");
1487 payload_field
= bt_ctf_event_get_payload_field(event
);
1488 if (!payload_field
) {
1489 diag("Failed to get event's payload field");
1494 integer
= bt_ctf_field_structure_get_field_by_index(payload_field
, 0);
1496 diag("Failed to get integer field payload from event");
1501 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 1234);
1503 diag("Failed to set integer field value");
1507 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1509 diag("Failed to create writer stream");
1514 ret
= bt_ctf_stream_append_event(stream
, event
);
1516 diag("Failed to append event to stream");
1520 ret_stream
= bt_ctf_event_get_stream(event
);
1521 ok(ret_stream
== stream
,
1522 "bt_ctf_event_get_stream returns an event's stream after it has been appended");
1525 "Create an event before instanciating its associated stream");
1528 bt_put(stream_class
);
1529 bt_put(event_class
);
1531 bt_put(integer_type
);
1533 bt_put(payload_field
);
1537 void append_existing_event_class(struct bt_ctf_stream_class
*stream_class
)
1539 struct bt_ctf_event_class
*event_class
;
1541 event_class
= bt_ctf_event_class_create("Simple Event");
1542 assert(event_class
);
1543 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
) == 0,
1544 "two event classes with the same name may cohabit within the same stream class");
1545 bt_put(event_class
);
1547 event_class
= bt_ctf_event_class_create("different name, ok");
1548 assert(event_class
);
1549 assert(!bt_ctf_event_class_set_id(event_class
, 13));
1550 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
1551 "two event classes with the same ID cannot cohabit within the same stream class");
1552 bt_put(event_class
);
1556 void test_clock_utils(void)
1559 struct bt_ctf_clock
*clock
= NULL
;
1561 clock
= bt_ctf_clock_create("water");
1563 ret
= bt_ctf_clock_set_offset_s(clock
, 1234);
1565 ret
= bt_ctf_clock_set_offset(clock
, 1000);
1567 ret
= bt_ctf_clock_set_frequency(clock
, 1000000000);
1569 ret
= bt_ctf_clock_set_frequency(clock
, 1534);
1575 int main(int argc
, char **argv
)
1577 const char *env_resize_length
;
1579 gchar
*metadata_path
;
1580 const char *clock_name
= "test_clock";
1581 const char *clock_description
= "This is a test clock";
1582 const char *returned_clock_name
;
1583 const char *returned_clock_description
;
1584 const uint64_t frequency
= 1123456789;
1585 const int64_t offset_s
= 13515309;
1586 const int64_t offset
= 1234567;
1587 int64_t get_offset_s
,
1589 const uint64_t precision
= 10;
1590 const int is_absolute
= 0xFF;
1591 char *metadata_string
;
1592 struct bt_ctf_writer
*writer
;
1593 struct bt_utsname name
= {"GNU/Linux", "testhost", "4.4.0-87-generic",
1594 "#110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017", "x86_64"};
1595 struct bt_ctf_clock
*clock
, *ret_clock
;
1596 struct bt_ctf_clock_class
*ret_clock_class
;
1597 struct bt_ctf_stream_class
*stream_class
, *ret_stream_class
;
1598 struct bt_ctf_stream
*stream1
;
1599 struct bt_ctf_stream
*stream
;
1600 const char *ret_string
;
1601 const unsigned char *ret_uuid
;
1602 unsigned char tmp_uuid
[16] = { 0 };
1603 struct bt_ctf_field_type
*packet_context_type
,
1604 *packet_context_field_type
,
1605 *packet_header_type
,
1606 *packet_header_field_type
,
1608 *stream_event_context_type
,
1610 *event_header_field_type
;
1611 struct bt_ctf_field
*packet_header
, *packet_header_field
;
1612 struct bt_ctf_trace
*trace
;
1614 int64_t ret_int64_t
;
1615 struct bt_value
*obj
;
1618 printf("Usage: tests-ctf-writer path_to_babeltrace\n");
1622 env_resize_length
= getenv("PACKET_RESIZE_TEST_LENGTH");
1623 if (env_resize_length
) {
1624 packet_resize_test_length
=
1625 (unsigned int) atoi(env_resize_length
);
1628 plan_tests(NR_TESTS
);
1630 trace_path
= g_build_filename(g_get_tmp_dir(), "ctfwriter_XXXXXX", NULL
);
1631 if (!bt_mkdtemp(trace_path
)) {
1635 metadata_path
= g_build_filename(trace_path
, "metadata", NULL
);
1637 writer
= bt_ctf_writer_create(trace_path
);
1638 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
1640 ok(!bt_ctf_writer_get_trace(NULL
),
1641 "bt_ctf_writer_get_trace correctly handles NULL");
1642 trace
= bt_ctf_writer_get_trace(writer
);
1643 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
),
1644 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NATIVE");
1645 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_UNSPECIFIED
),
1646 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_UNSPECIFIED");
1648 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1649 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1650 "Set a trace's byte order to big endian");
1651 ok(bt_ctf_trace_get_native_byte_order(trace
) == BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1652 "bt_ctf_trace_get_native_byte_order returns a correct endianness");
1654 /* Add environment context to the trace */
1655 ok(bt_ctf_writer_add_environment_field(writer
, "host", name
.nodename
) == 0,
1656 "Add host (%s) environment field to writer instance",
1658 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
1660 "bt_ctf_writer_add_environment_field error with NULL writer");
1661 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
1663 "bt_ctf_writer_add_environment_field error with NULL field name");
1664 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
1666 "bt_ctf_writer_add_environment_field error with NULL field value");
1668 /* Test bt_ctf_trace_set_environment_field with an integer object */
1669 obj
= bt_value_integer_create_init(23);
1671 ok(bt_ctf_trace_set_environment_field(NULL
, "test_env_int_obj", obj
),
1672 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
1673 ok(bt_ctf_trace_set_environment_field(trace
, NULL
, obj
),
1674 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
1675 ok(bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", NULL
),
1676 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
1677 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", obj
),
1678 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
1681 /* Test bt_ctf_trace_set_environment_field with a string object */
1682 obj
= bt_value_string_create_init("the value");
1684 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_str_obj", obj
),
1685 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
1688 /* Test bt_ctf_trace_set_environment_field_integer */
1689 ok(bt_ctf_trace_set_environment_field_integer(NULL
, "test_env_int",
1691 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
1692 ok(bt_ctf_trace_set_environment_field_integer(trace
, NULL
, -194875),
1693 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
1694 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1696 "bt_ctf_trace_set_environment_field_integer succeeds");
1698 /* Test bt_ctf_trace_set_environment_field_string */
1699 ok(bt_ctf_trace_set_environment_field_string(NULL
, "test_env_str",
1701 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
1702 ok(bt_ctf_trace_set_environment_field_string(trace
, NULL
, "yeah"),
1703 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
1704 ok(bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1706 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
1707 ok(!bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1709 "bt_ctf_trace_set_environment_field_string succeeds");
1711 /* Test bt_ctf_trace_get_environment_field_count */
1712 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
1713 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
1715 /* Test bt_ctf_trace_get_environment_field_name */
1716 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 0);
1717 ok(ret_string
&& !strcmp(ret_string
, "host"),
1718 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1719 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 1);
1720 ok(ret_string
&& !strcmp(ret_string
, "test_env_int_obj"),
1721 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1722 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 2);
1723 ok(ret_string
&& !strcmp(ret_string
, "test_env_str_obj"),
1724 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1725 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 3);
1726 ok(ret_string
&& !strcmp(ret_string
, "test_env_int"),
1727 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1728 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 4);
1729 ok(ret_string
&& !strcmp(ret_string
, "test_env_str"),
1730 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1732 /* Test bt_ctf_trace_get_environment_field_value */
1733 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 1);
1734 ret
= bt_value_integer_get(obj
, &ret_int64_t
);
1735 ok(!ret
&& ret_int64_t
== 23,
1736 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
1738 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 2);
1739 ret
= bt_value_string_get(obj
, &ret_string
);
1740 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "the value"),
1741 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
1744 /* Test bt_ctf_trace_get_environment_field_value_by_name */
1745 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, "oh oh"),
1746 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
1747 obj
= bt_ctf_trace_get_environment_field_value_by_name(trace
,
1749 ret
= bt_value_string_get(obj
, &ret_string
);
1750 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "oh yeah"),
1751 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
1754 /* Test environment field replacement */
1755 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1757 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
1758 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
1759 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
1760 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 3);
1761 ret
= bt_value_integer_get(obj
, &ret_int64_t
);
1762 ok(!ret
&& ret_int64_t
== 654321,
1763 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
1766 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
1767 == 0, "Add sysname (%s) environment field to writer instance",
1769 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
1770 name
.nodename
) == 0,
1771 "Add nodename (%s) environment field to writer instance",
1773 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
1774 == 0, "Add release (%s) environment field to writer instance",
1776 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
1777 == 0, "Add version (%s) environment field to writer instance",
1779 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
1780 == 0, "Add machine (%s) environment field to writer istance",
1783 /* Define a clock and add it to the trace */
1784 ok(bt_ctf_clock_create("signed") == NULL
,
1785 "Illegal clock name rejected");
1786 clock
= bt_ctf_clock_create(clock_name
);
1787 ok(clock
, "Clock created sucessfully");
1788 returned_clock_name
= bt_ctf_clock_get_name(clock
);
1789 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
1790 ok(returned_clock_name
? !strcmp(returned_clock_name
, clock_name
) : 0,
1791 "Returned clock name is valid");
1793 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1794 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
1795 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
1796 "Clock description set successfully");
1798 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1799 ok(returned_clock_description
,
1800 "bt_ctf_clock_get_description returns a description.");
1801 ok(returned_clock_description
?
1802 !strcmp(returned_clock_description
, clock_description
) : 0,
1803 "Returned clock description is valid");
1805 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
1806 "bt_ctf_clock_get_frequency returns the correct default frequency");
1807 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
1808 "Set clock frequency");
1809 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
1810 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
1812 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
1813 "bt_ctf_clock_get_offset_s succeeds");
1814 ok(get_offset_s
== DEFAULT_CLOCK_OFFSET_S
,
1815 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
1816 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
1817 "Set clock offset (seconds)");
1818 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
1819 "bt_ctf_clock_get_offset_s succeeds");
1820 ok(get_offset_s
== offset_s
,
1821 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
1823 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
1824 "bt_ctf_clock_get_offset succeeds");
1825 ok(get_offset
== DEFAULT_CLOCK_OFFSET
,
1826 "bt_ctf_clock_get_offset returns the correct default offset (in ticks)");
1827 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
1828 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
1829 "bt_ctf_clock_get_offset succeeds");
1830 ok(get_offset
== offset
,
1831 "bt_ctf_clock_get_offset returns the correct default offset (in ticks) once it is set");
1833 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
1834 "bt_ctf_clock_get_precision returns the correct default precision");
1835 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
1836 "Set clock precision");
1837 ok(bt_ctf_clock_get_precision(clock
) == precision
,
1838 "bt_ctf_clock_get_precision returns the correct precision once it is set");
1840 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
1841 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
1842 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
1843 "Set clock absolute property");
1844 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
1845 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
1846 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
1848 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1850 "bt_ctf_clock_get_uuid returns a UUID");
1852 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
1853 /* Slightly modify UUID */
1854 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
1857 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
1858 "bt_ctf_clock_set_uuid sets a new uuid successfully");
1859 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1861 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
1862 ok(uuid_match(ret_uuid
, tmp_uuid
),
1863 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
1865 /* Define a stream class */
1866 stream_class
= bt_ctf_stream_class_create("test_stream");
1867 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
1868 ok(ret_string
&& !strcmp(ret_string
, "test_stream"),
1869 "bt_ctf_stream_class_get_name returns a correct stream class name");
1871 ok(bt_ctf_stream_class_get_clock(stream_class
) == NULL
,
1872 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
1873 ok(bt_ctf_stream_class_get_clock(NULL
) == NULL
,
1874 "bt_ctf_stream_class_get_clock handles NULL correctly");
1876 ok(stream_class
, "Create stream class");
1877 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
1878 "Set a stream class' clock");
1879 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
1880 ok(ret_clock
== clock
,
1881 "bt_ctf_stream_class_get_clock returns a correct clock");
1884 /* Test the event fields and event types APIs */
1887 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
1888 "bt_ctf_stream_class_get_id returns an error when no id is set");
1889 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
1890 "bt_ctf_stream_class_set_id handles NULL correctly");
1891 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
1892 "Set an stream class' id");
1893 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
1894 "bt_ctf_stream_class_get_id returns the correct value");
1896 /* Validate default event header fields */
1897 ret_field_type
= bt_ctf_stream_class_get_event_header_type(
1900 "bt_ctf_stream_class_get_event_header_type returns an event header type");
1901 ok(bt_ctf_field_type_get_type_id(ret_field_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1902 "Default event header type is a structure");
1903 event_header_field_type
=
1904 bt_ctf_field_type_structure_get_field_type_by_name(
1905 ret_field_type
, "id");
1906 ok(event_header_field_type
,
1907 "Default event header type contains an \"id\" field");
1908 ok(bt_ctf_field_type_get_type_id(
1909 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
1910 "Default event header \"id\" field is an integer");
1911 bt_put(event_header_field_type
);
1912 event_header_field_type
=
1913 bt_ctf_field_type_structure_get_field_type_by_name(
1914 ret_field_type
, "timestamp");
1915 ok(event_header_field_type
,
1916 "Default event header type contains a \"timestamp\" field");
1917 ok(bt_ctf_field_type_get_type_id(
1918 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
1919 "Default event header \"timestamp\" field is an integer");
1920 bt_put(event_header_field_type
);
1921 bt_put(ret_field_type
);
1923 /* Add a custom trace packet header field */
1924 packet_header_type
= bt_ctf_trace_get_packet_header_field_type(trace
);
1925 ok(packet_header_type
,
1926 "bt_ctf_trace_get_packet_header_field_type returns a packet header");
1927 ok(bt_ctf_field_type_get_type_id(packet_header_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1928 "bt_ctf_trace_get_packet_header_field_type returns a packet header of type struct");
1929 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1930 packet_header_type
, "magic");
1931 ok(ret_field_type
, "Default packet header type contains a \"magic\" field");
1932 bt_put(ret_field_type
);
1933 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1934 packet_header_type
, "uuid");
1935 ok(ret_field_type
, "Default packet header type contains a \"uuid\" field");
1936 bt_put(ret_field_type
);
1937 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1938 packet_header_type
, "stream_id");
1939 ok(ret_field_type
, "Default packet header type contains a \"stream_id\" field");
1940 bt_put(ret_field_type
);
1942 packet_header_field_type
= bt_ctf_field_type_integer_create(22);
1943 ok(!bt_ctf_field_type_structure_add_field(packet_header_type
,
1944 packet_header_field_type
, "custom_trace_packet_header_field"),
1945 "Added a custom trace packet header field successfully");
1947 ok(bt_ctf_trace_set_packet_header_field_type(NULL
, packet_header_type
) < 0,
1948 "bt_ctf_trace_set_packet_header_field_type handles a NULL trace correctly");
1949 ok(!bt_ctf_trace_set_packet_header_field_type(trace
, packet_header_type
),
1950 "Set a trace packet_header_type successfully");
1952 /* Add a custom field to the stream class' packet context */
1953 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
1954 ok(packet_context_type
,
1955 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
1956 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1957 "Packet context is a structure");
1959 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
1960 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
1962 integer_type
= bt_ctf_field_type_integer_create(32);
1964 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
1966 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
1968 /* Create a "uint5_t" equivalent custom packet context field */
1969 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
1971 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1972 packet_context_field_type
, "custom_packet_context_field");
1973 ok(ret
== 0, "Packet context field added successfully");
1975 /* Define a stream event context containing a my_integer field. */
1976 stream_event_context_type
= bt_ctf_field_type_structure_create();
1977 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1978 integer_type
, "common_event_context");
1980 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
1981 stream_event_context_type
) < 0,
1982 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
1983 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
1985 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
1987 ok(bt_ctf_stream_class_set_event_context_type(
1988 stream_class
, stream_event_context_type
) == 0,
1989 "Set a new stream event context type");
1991 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
1993 ok(ret_field_type
== stream_event_context_type
,
1994 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
1995 bt_put(ret_field_type
);
1998 /* Instantiate a stream and append events */
1999 ret
= bt_ctf_writer_add_clock(writer
, clock
);
2002 ok(bt_ctf_trace_get_stream_count(trace
) == 0,
2003 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (0)");
2004 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
2005 ok(stream1
, "Instanciate a stream class from writer");
2006 ok(bt_ctf_trace_get_stream_count(trace
) == 1,
2007 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (1)");
2008 stream
= bt_ctf_trace_get_stream_by_index(trace
, 0);
2009 ok(stream
== stream1
,
2010 "bt_ctf_trace_get_stream_by_index() succeeds and returns the correct value");
2014 * Creating a stream through a writer adds the given stream
2015 * class to the writer's trace, thus registering the stream
2016 * class's clock to the trace.
2018 ok(bt_ctf_trace_get_clock_class_count(trace
) == 1,
2019 "bt_ctf_trace_get_clock_class_count returns the correct number of clocks");
2020 ret_clock_class
= bt_ctf_trace_get_clock_class_by_index(trace
, 0);
2021 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class
),
2022 bt_ctf_clock_get_name(clock
)) == 0,
2023 "bt_ctf_trace_get_clock_class returns the right clock instance");
2024 bt_put(ret_clock_class
);
2025 ret_clock_class
= bt_ctf_trace_get_clock_class_by_name(trace
, clock_name
);
2026 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class
),
2027 bt_ctf_clock_get_name(clock
)) == 0,
2028 "bt_ctf_trace_get_clock_class returns the right clock instance");
2029 bt_put(ret_clock_class
);
2030 ok(!bt_ctf_trace_get_clock_class_by_name(trace
, "random"),
2031 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
2033 ret_stream_class
= bt_ctf_stream_get_class(stream1
);
2034 ok(ret_stream_class
,
2035 "bt_ctf_stream_get_class returns a stream class");
2036 ok(ret_stream_class
== stream_class
,
2037 "Returned stream class is of the correct type");
2040 * Packet header, packet context, event header, and stream
2041 * event context types were copied for the resolving
2044 BT_PUT(packet_header_type
);
2045 BT_PUT(packet_context_type
);
2046 BT_PUT(stream_event_context_type
);
2047 packet_header_type
= bt_ctf_trace_get_packet_header_field_type(trace
);
2048 assert(packet_header_type
);
2049 packet_context_type
=
2050 bt_ctf_stream_class_get_packet_context_type(stream_class
);
2051 assert(packet_context_type
);
2052 stream_event_context_type
=
2053 bt_ctf_stream_class_get_event_context_type(stream_class
);
2054 assert(stream_event_context_type
);
2057 * Try to modify the packet context type after a stream has been
2060 ret
= bt_ctf_field_type_structure_add_field(packet_header_type
,
2061 packet_header_field_type
, "should_fail");
2063 "Trace packet header type can't be modified once a stream has been instanciated");
2066 * Try to modify the packet context type after a stream has been
2069 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
2070 packet_context_field_type
, "should_fail");
2072 "Packet context type can't be modified once a stream has been instanciated");
2075 * Try to modify the stream event context type after a stream has been
2078 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
2079 integer_type
, "should_fail");
2081 "Stream event context type can't be modified once a stream has been instanciated");
2083 /* Should fail after instanciating a stream (frozen) */
2084 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
2085 "Changes to a stream class that was already instantiated fail");
2087 /* Populate the custom packet header field only once for all tests */
2088 ok(bt_ctf_stream_get_packet_header(NULL
) == NULL
,
2089 "bt_ctf_stream_get_packet_header handles NULL correctly");
2090 packet_header
= bt_ctf_stream_get_packet_header(stream1
);
2092 "bt_ctf_stream_get_packet_header returns a packet header");
2093 ret_field_type
= bt_ctf_field_get_type(packet_header
);
2094 ok(ret_field_type
== packet_header_type
,
2095 "Stream returns a packet header of the appropriate type");
2096 bt_put(ret_field_type
);
2097 packet_header_field
= bt_ctf_field_structure_get_field_by_name(packet_header
,
2098 "custom_trace_packet_header_field");
2099 ok(packet_header_field
,
2100 "Packet header structure contains a custom field with the appropriate name");
2101 ret_field_type
= bt_ctf_field_get_type(packet_header_field
);
2102 ok(!bt_ctf_field_integer_unsigned_set_value(packet_header_field
,
2103 54321), "Set custom packet header value successfully");
2104 ok(bt_ctf_stream_set_packet_header(stream1
, NULL
) < 0,
2105 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
2106 ok(bt_ctf_stream_set_packet_header(NULL
, packet_header
) < 0,
2107 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
2108 ok(bt_ctf_stream_set_packet_header(stream1
, packet_header_field
) < 0,
2109 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
2110 ok(!bt_ctf_stream_set_packet_header(stream1
, packet_header
),
2111 "Successfully set a stream's packet header");
2113 ok(bt_ctf_writer_add_environment_field(writer
, "new_field", "test") == 0,
2114 "Add environment field to writer after stream creation");
2118 test_instanciate_event_before_stream(writer
, clock
);
2120 append_simple_event(stream_class
, stream1
, clock
);
2122 packet_resize_test(stream_class
, stream1
, clock
);
2124 append_complex_event(stream_class
, stream1
, clock
);
2126 append_existing_event_class(stream_class
);
2128 test_empty_stream(writer
);
2130 test_custom_event_header_stream(writer
, clock
);
2132 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
2133 ok(metadata_string
, "Get metadata string");
2135 bt_ctf_writer_flush_metadata(writer
);
2138 bt_put(ret_stream_class
);
2141 bt_put(packet_context_type
);
2142 bt_put(packet_context_field_type
);
2143 bt_put(integer_type
);
2144 bt_put(stream_event_context_type
);
2145 bt_put(ret_field_type
);
2146 bt_put(packet_header_type
);
2147 bt_put(packet_header_field_type
);
2148 bt_put(packet_header
);
2149 bt_put(packet_header_field
);
2151 free(metadata_string
);
2152 bt_put(stream_class
);
2154 validate_trace(argv
[1], trace_path
);
2156 recursive_rmdir(trace_path
);
2158 g_free(metadata_path
);