2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2013-2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 #include <babeltrace2-ctf-writer/writer.h>
8 #include <babeltrace2-ctf-writer/clock.h>
9 #include <babeltrace2-ctf-writer/clock-class.h>
10 #include <babeltrace2-ctf-writer/stream.h>
11 #include <babeltrace2-ctf-writer/event.h>
12 #include <babeltrace2-ctf-writer/event-types.h>
13 #include <babeltrace2-ctf-writer/event-fields.h>
14 #include <babeltrace2-ctf-writer/stream-class.h>
15 #include <babeltrace2-ctf-writer/trace.h>
16 #include <babeltrace2/babeltrace.h>
19 #include "compat/stdlib.h"
21 #include "compat/limits.h"
22 #include "compat/stdio.h"
24 #include "common/assert.h"
25 #include "common/uuid.h"
33 /* Required for WIFEXITED and WEXITSTATUS */
37 #define METADATA_LINE_SIZE 512
38 #define SEQUENCE_TEST_LENGTH 10
39 #define ARRAY_TEST_LENGTH 5
40 #define PACKET_RESIZE_TEST_DEF_LENGTH 100000
42 #define DEFAULT_CLOCK_FREQ 1000000000
43 #define DEFAULT_CLOCK_PRECISION 1
44 #define DEFAULT_CLOCK_OFFSET 0
45 #define DEFAULT_CLOCK_OFFSET_S 0
46 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
47 #define DEFAULT_CLOCK_TIME 0
48 #define DEFAULT_CLOCK_VALUE 0
53 char sysname
[BABELTRACE_HOST_NAME_MAX
];
54 char nodename
[BABELTRACE_HOST_NAME_MAX
];
55 char release
[BABELTRACE_HOST_NAME_MAX
];
56 char version
[BABELTRACE_HOST_NAME_MAX
];
57 char machine
[BABELTRACE_HOST_NAME_MAX
];
60 static int64_t current_time
= 42;
61 static unsigned int packet_resize_test_length
= PACKET_RESIZE_TEST_DEF_LENGTH
;
63 /* Return 1 if uuids match, zero if different. */
65 int uuid_match(const uint8_t *uuid_a
, const uint8_t *uuid_b
)
70 if (!uuid_a
|| !uuid_b
) {
74 for (i
= 0; i
< 16; i
++) {
75 if (uuid_a
[i
] != uuid_b
[i
]) {
86 void validate_trace(char *parser_path
, char *trace_path
)
90 const char *argv
[] = {parser_path
, trace_path
, "-o", "dummy", NULL
};
92 if (!parser_path
|| !trace_path
) {
97 if (!g_spawn_sync(NULL
,
100 G_SPAWN_STDOUT_TO_DEV_NULL
,
107 diag("Failed to spawn babeltrace.");
112 /* Replace by g_spawn_check_exit_status when we require glib >= 2.34 */
114 ret
= WIFEXITED(exit_status
) ? WEXITSTATUS(exit_status
) : -1;
120 diag("Babeltrace returned an error.");
125 ok(ret
== 0, "Babeltrace could read the resulting trace");
129 void append_simple_event(struct bt_ctf_stream_class
*stream_class
,
130 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
132 /* Create and add a simple event class */
133 struct bt_ctf_event_class
*simple_event_class
=
134 bt_ctf_event_class_create("Simple Event");
135 struct bt_ctf_field_type
*uint_12_type
=
136 bt_ctf_field_type_integer_create(12);
137 struct bt_ctf_field_type
*int_64_type
=
138 bt_ctf_field_type_integer_create(64);
139 struct bt_ctf_field_type
*float_type
=
140 bt_ctf_field_type_floating_point_create();
141 struct bt_ctf_field_type
*enum_type
;
142 struct bt_ctf_field_type
*enum_type_unsigned
=
143 bt_ctf_field_type_enumeration_create(uint_12_type
);
144 struct bt_ctf_field_type
*event_context_type
=
145 bt_ctf_field_type_structure_create();
146 struct bt_ctf_field_type
*event_payload_type
= NULL
;
147 struct bt_ctf_field_type
*returned_type
;
148 struct bt_ctf_event
*simple_event
;
149 struct bt_ctf_field
*integer_field
;
150 struct bt_ctf_field
*float_field
;
151 struct bt_ctf_field
*enum_field
;
152 struct bt_ctf_field
*enum_field_unsigned
;
153 struct bt_ctf_field
*enum_container_field
;
154 const char *mapping_name_test
= "truie";
155 const double double_test_value
= 3.1415;
156 struct bt_ctf_field
*enum_container_field_unsigned
;
157 const char *mapping_name_negative_test
= "negative_value";
158 const char *ret_char
;
160 int64_t ret_range_start_int64_t
, ret_range_end_int64_t
;
161 uint64_t ret_range_start_uint64_t
, ret_range_end_uint64_t
;
162 struct bt_ctf_event_class
*ret_event_class
;
163 struct bt_ctf_field
*packet_context
;
164 struct bt_ctf_field
*packet_context_field
;
165 struct bt_ctf_field
*stream_event_context
;
166 struct bt_ctf_field
*stream_event_context_field
;
167 struct bt_ctf_field
*event_context
;
168 struct bt_ctf_field
*event_context_field
;
169 struct bt_ctf_field_type
*ep_integer_field_type
= NULL
;
170 struct bt_ctf_field_type
*ep_enum_field_type
= NULL
;
171 struct bt_ctf_field_type
*ep_enum_field_unsigned_type
= NULL
;
172 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
175 ok(uint_12_type
, "Create an unsigned integer type");
177 ok(!bt_ctf_field_type_integer_set_signed(int_64_type
, 1),
178 "Set signed 64 bit integer signedness to true");
179 ok(int_64_type
, "Create a signed integer type");
180 enum_type
= bt_ctf_field_type_enumeration_create(int_64_type
);
182 returned_type
= bt_ctf_field_type_enumeration_get_container_field_type(enum_type
);
183 ok(returned_type
== int_64_type
, "bt_ctf_field_type_enumeration_get_container_field_type returns the right type");
184 ok(!bt_ctf_field_type_enumeration_create(enum_type
),
185 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
186 bt_ctf_object_put_ref(returned_type
);
188 bt_ctf_field_type_set_alignment(float_type
, 32);
189 ok(bt_ctf_field_type_get_alignment(float_type
) == 32,
190 "bt_ctf_field_type_get_alignment returns a correct value");
192 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type
, 11) == 0,
193 "Set a floating point type's exponent digit count");
194 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type
, 53) == 0,
195 "Set a floating point type's mantissa digit count");
197 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type
) == 11,
198 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
199 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type
) == 53,
200 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
202 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
203 mapping_name_negative_test
, -12345, 0) == 0,
204 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
205 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
206 "escaping; \"test\"", 1, 1) == 0,
207 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
208 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
209 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
210 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
211 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
212 "event clock int float", 5, 22) == 0,
213 "Accept enumeration mapping strings containing reserved keywords");
214 bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
216 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
217 43, 51) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts duplicate mapping names");
218 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, "something",
219 -500, -400) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts overlapping enum entries");
220 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
221 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
222 bt_ctf_field_type_enumeration_add_mapping(enum_type
, "another entry", -42000, -13000);
224 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type
,
225 "enum_field") == 0, "Add signed enumeration field to event");
227 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, NULL
,
228 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
229 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL string correctly");
230 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, &ret_char
,
231 NULL
, &ret_range_end_int64_t
) == 0,
232 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL start correctly");
233 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, &ret_char
,
234 &ret_range_start_int64_t
, NULL
) == 0,
235 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL end correctly");
236 /* Assumes entries are sorted by range_start values. */
237 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 6, &ret_char
,
238 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
239 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a value");
240 ok(strcmp(ret_char
, mapping_name_test
) == 0,
241 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping name");
242 ok(ret_range_start_int64_t
== 42,
243 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping start");
244 ok(ret_range_end_int64_t
== 42,
245 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping end");
247 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
248 "escaping; \"test\"", 0, 0) == 0,
249 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing quotes");
250 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
251 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
252 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing special characters");
253 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
254 "event clock int float", 5, 22) == 0,
255 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing reserved keywords");
256 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
257 42, 42) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts single-value ranges");
258 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
259 43, 51) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts duplicate mapping names");
260 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, "something",
261 7, 8) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts overlapping enum entries");
262 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
263 55, 54), "bt_ctf_field_type_enumeration_unsigned_add_mapping rejects mapping where end < start");
264 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type_unsigned
,
265 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
267 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned
) == 6,
268 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
270 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, NULL
,
271 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
272 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL string correctly");
273 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, &ret_char
,
274 NULL
, &ret_range_end_uint64_t
) == 0,
275 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL start correctly");
276 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, &ret_char
,
277 &ret_range_start_uint64_t
, NULL
) == 0,
278 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL end correctly");
279 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 4, &ret_char
,
280 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
281 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a value");
282 ok(strcmp(ret_char
, mapping_name_test
) == 0,
283 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping name");
284 ok(ret_range_start_uint64_t
== 42,
285 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping start");
286 ok(ret_range_end_uint64_t
== 42,
287 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping end");
289 bt_ctf_event_class_add_field(simple_event_class
, uint_12_type
,
291 bt_ctf_event_class_add_field(simple_event_class
, float_type
,
294 ret
= bt_ctf_event_class_set_id(simple_event_class
, 13);
297 /* Set an event context type which will contain a single integer. */
298 ok(!bt_ctf_field_type_structure_add_field(event_context_type
, uint_12_type
,
299 "event_specific_context"),
300 "Add event specific context field");
302 ok(bt_ctf_event_class_set_context_field_type(NULL
, event_context_type
) < 0,
303 "bt_ctf_event_class_set_context_field_type handles a NULL event class correctly");
304 ok(!bt_ctf_event_class_set_context_field_type(simple_event_class
, event_context_type
),
305 "Set an event class' context type successfully");
306 returned_type
= bt_ctf_event_class_get_context_field_type(simple_event_class
);
307 ok(returned_type
== event_context_type
,
308 "bt_ctf_event_class_get_context_field_type returns the appropriate type");
309 bt_ctf_object_put_ref(returned_type
);
311 ok(!bt_ctf_stream_class_add_event_class(stream_class
, simple_event_class
),
312 "Adding simple event class to stream class");
315 * bt_ctf_stream_class_add_event_class() copies the field types
316 * of simple_event_class, so we retrieve the new ones to create
317 * the appropriate fields.
319 BT_CTF_OBJECT_PUT_REF_AND_RESET(event_context_type
);
320 BT_CTF_OBJECT_PUT_REF_AND_RESET(event_payload_type
);
321 event_payload_type
= bt_ctf_event_class_get_payload_field_type(
323 BT_ASSERT(event_payload_type
);
324 event_context_type
= bt_ctf_event_class_get_context_field_type(
326 BT_ASSERT(event_context_type
);
327 ep_integer_field_type
=
328 bt_ctf_field_type_structure_get_field_type_by_name(
329 event_payload_type
, "integer_field");
330 BT_ASSERT(ep_integer_field_type
);
332 bt_ctf_field_type_structure_get_field_type_by_name(
333 event_payload_type
, "enum_field");
334 BT_ASSERT(ep_enum_field_type
);
335 ep_enum_field_unsigned_type
=
336 bt_ctf_field_type_structure_get_field_type_by_name(
337 event_payload_type
, "enum_field_unsigned");
338 BT_ASSERT(ep_enum_field_unsigned_type
);
340 ok(bt_ctf_stream_class_get_event_class_count(stream_class
) == 1,
341 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
342 ret_event_class
= bt_ctf_stream_class_get_event_class_by_index(stream_class
, 0);
343 ok(ret_event_class
== simple_event_class
,
344 "bt_ctf_stream_class_get_event_class returns the correct event class");
345 bt_ctf_object_put_ref(ret_event_class
);
346 ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class
, 2),
347 "bt_ctf_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
349 bt_ctf_stream_class_get_event_class_by_id(stream_class
, 13);
350 ok(ret_event_class
== simple_event_class
,
351 "bt_ctf_stream_class_get_event_class_by_id returns a correct event class");
352 bt_ctf_object_put_ref(ret_event_class
);
354 simple_event
= bt_ctf_event_create(simple_event_class
);
356 "Instantiate an event containing a single integer field");
358 integer_field
= bt_ctf_field_create(ep_integer_field_type
);
359 bt_ctf_field_integer_unsigned_set_value(integer_field
, 42);
360 ok(bt_ctf_event_set_payload(simple_event
, "integer_field",
361 integer_field
) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
363 float_field
= bt_ctf_event_get_payload(simple_event
, "float_field");
364 bt_ctf_field_floating_point_set_value(float_field
, double_test_value
);
365 ok(!bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
366 "bt_ctf_field_floating_point_get_value returns a double value");
367 ok(fabs(ret_double
- double_test_value
) <= DBL_EPSILON
,
368 "bt_ctf_field_floating_point_get_value returns a correct value");
370 enum_field
= bt_ctf_field_create(ep_enum_field_type
);
371 BT_ASSERT(enum_field
);
373 enum_container_field
= bt_ctf_field_enumeration_get_container(enum_field
);
374 ok(bt_ctf_field_integer_signed_set_value(
375 enum_container_field
, -42) == 0,
376 "Set signed enumeration container value");
377 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field", enum_field
);
379 BT_CTF_OBJECT_PUT_REF_AND_RESET(iter
);
381 enum_field_unsigned
= bt_ctf_field_create(ep_enum_field_unsigned_type
);
382 BT_ASSERT(enum_field_unsigned
);
383 enum_container_field_unsigned
= bt_ctf_field_enumeration_get_container(
384 enum_field_unsigned
);
385 ok(bt_ctf_field_integer_unsigned_set_value(
386 enum_container_field_unsigned
, 42) == 0,
387 "Set unsigned enumeration container value");
388 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field_unsigned",
389 enum_field_unsigned
);
392 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0, "Set clock time");
394 /* Populate stream event context */
395 stream_event_context
=
396 bt_ctf_event_get_stream_event_context(simple_event
);
397 BT_ASSERT(stream_event_context
);
398 stream_event_context_field
= bt_ctf_field_structure_get_field_by_name(
399 stream_event_context
, "common_event_context");
400 bt_ctf_field_integer_unsigned_set_value(stream_event_context_field
, 42);
402 /* Populate the event's context */
403 event_context
= bt_ctf_event_get_context(simple_event
);
405 "bt_ctf_event_get_context returns a field");
406 returned_type
= bt_ctf_field_get_type(event_context
);
407 ok(returned_type
== event_context_type
,
408 "bt_ctf_event_get_context returns a field of the appropriate type");
409 event_context_field
= bt_ctf_field_structure_get_field_by_name(event_context
,
410 "event_specific_context");
411 ok(!bt_ctf_field_integer_unsigned_set_value(event_context_field
, 1234),
412 "Successfully set an event context's value");
413 ok(!bt_ctf_event_set_context(simple_event
, event_context
),
414 "Set an event context successfully");
416 ok(bt_ctf_stream_append_event(stream
, simple_event
) == 0,
417 "Append simple event to trace stream");
419 packet_context
= bt_ctf_stream_get_packet_context(stream
);
421 "bt_ctf_stream_get_packet_context returns a packet context");
423 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
425 ok(packet_context_field
,
426 "Packet context contains the default packet_size field.");
427 bt_ctf_object_put_ref(packet_context_field
);
428 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
429 "custom_packet_context_field");
430 ok(bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 8) == 0,
431 "Custom packet context field value successfully set.");
433 ok(bt_ctf_stream_set_packet_context(stream
, packet_context
) == 0,
434 "Successfully set a stream's packet context");
436 ok(bt_ctf_stream_flush(stream
) == 0,
437 "Flush trace stream with one event");
439 bt_ctf_object_put_ref(simple_event_class
);
440 bt_ctf_object_put_ref(simple_event
);
441 bt_ctf_object_put_ref(uint_12_type
);
442 bt_ctf_object_put_ref(int_64_type
);
443 bt_ctf_object_put_ref(float_type
);
444 bt_ctf_object_put_ref(enum_type
);
445 bt_ctf_object_put_ref(enum_type_unsigned
);
446 bt_ctf_object_put_ref(returned_type
);
447 bt_ctf_object_put_ref(event_context_type
);
448 bt_ctf_object_put_ref(integer_field
);
449 bt_ctf_object_put_ref(float_field
);
450 bt_ctf_object_put_ref(enum_field
);
451 bt_ctf_object_put_ref(enum_field_unsigned
);
452 bt_ctf_object_put_ref(enum_container_field
);
453 bt_ctf_object_put_ref(enum_container_field_unsigned
);
454 bt_ctf_object_put_ref(packet_context
);
455 bt_ctf_object_put_ref(packet_context_field
);
456 bt_ctf_object_put_ref(stream_event_context
);
457 bt_ctf_object_put_ref(stream_event_context_field
);
458 bt_ctf_object_put_ref(event_context
);
459 bt_ctf_object_put_ref(event_context_field
);
460 bt_ctf_object_put_ref(event_payload_type
);
461 bt_ctf_object_put_ref(ep_integer_field_type
);
462 bt_ctf_object_put_ref(ep_enum_field_type
);
463 bt_ctf_object_put_ref(ep_enum_field_unsigned_type
);
464 bt_ctf_object_put_ref(iter
);
468 void append_complex_event(struct bt_ctf_stream_class
*stream_class
,
469 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
472 struct event_class_attrs_counts
;
473 const char *complex_test_event_string
= "Complex Test Event";
474 const char *test_string_1
= "Test ";
475 const char *test_string_2
= "string ";
476 const char *test_string_3
= "abcdefghi";
477 const char *test_string_4
= "abcd\0efg\0hi";
478 const char *test_string_cat
= "Test string abcdeefg";
479 struct bt_ctf_field_type
*uint_35_type
=
480 bt_ctf_field_type_integer_create(35);
481 struct bt_ctf_field_type
*int_16_type
=
482 bt_ctf_field_type_integer_create(16);
483 struct bt_ctf_field_type
*uint_3_type
=
484 bt_ctf_field_type_integer_create(3);
485 struct bt_ctf_field_type
*enum_variant_type
=
486 bt_ctf_field_type_enumeration_create(uint_3_type
);
487 struct bt_ctf_field_type
*variant_type
=
488 bt_ctf_field_type_variant_create(enum_variant_type
,
490 struct bt_ctf_field_type
*string_type
=
491 bt_ctf_field_type_string_create();
492 struct bt_ctf_field_type
*sequence_type
;
493 struct bt_ctf_field_type
*array_type
;
494 struct bt_ctf_field_type
*inner_structure_type
=
495 bt_ctf_field_type_structure_create();
496 struct bt_ctf_field_type
*complex_structure_type
=
497 bt_ctf_field_type_structure_create();
498 struct bt_ctf_field_type
*ret_field_type
;
499 struct bt_ctf_event_class
*event_class
;
500 struct bt_ctf_event
*event
;
501 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
502 *inner_structure_field
, *complex_structure_field
,
503 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
504 *variant_field
, *an_array_field
, *stream_event_ctx_field
,
505 *stream_event_ctx_int_field
;
506 uint64_t ret_unsigned_int
;
507 int64_t ret_signed_int
;
508 const char *ret_string
;
509 struct bt_ctf_stream_class
*ret_stream_class
;
510 struct bt_ctf_event_class
*ret_event_class
;
511 struct bt_ctf_field
*packet_context
, *packet_context_field
;
513 ok(bt_ctf_field_type_set_alignment(int_16_type
, 0),
514 "bt_ctf_field_type_set_alignment handles 0-alignment correctly");
515 ok(bt_ctf_field_type_set_alignment(int_16_type
, 3),
516 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (3)");
517 ok(bt_ctf_field_type_set_alignment(int_16_type
, 24),
518 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (24)");
519 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 4),
520 "bt_ctf_field_type_set_alignment handles correct alignment correctly (4)");
521 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 32),
522 "Set alignment of signed 16 bit integer to 32");
523 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
524 "Set integer signedness to true");
525 ok(!bt_ctf_field_type_integer_set_base(uint_35_type
,
526 BT_CTF_INTEGER_BASE_HEXADECIMAL
),
527 "Set signed 16 bit integer base to hexadecimal");
529 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
530 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
533 ret_field_type
= bt_ctf_field_type_array_get_element_field_type(
535 ok(ret_field_type
== int_16_type
,
536 "bt_ctf_field_type_array_get_element_field_type returns the correct type");
537 bt_ctf_object_put_ref(ret_field_type
);
539 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
540 "bt_ctf_field_type_array_get_length returns the correct length");
542 ok(bt_ctf_field_type_structure_add_field(inner_structure_type
,
543 inner_structure_type
, "yes"), "Cannot add self to structure");
544 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
545 uint_35_type
, "seq_len"), "Add seq_len field to inner structure");
546 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
547 sequence_type
, "a_sequence"), "Add a_sequence field to inner structure");
548 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
549 array_type
, "an_array"), "Add an_array field to inner structure");
551 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
553 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
555 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
556 "UINT35_TYPE", 2, 7);
558 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
559 "An unknown entry"), "Reject a variant field based on an unknown tag value");
560 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
561 "UINT3_TYPE") == 0, "Add a field to a variant");
562 ok(!bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
563 "INT16_TYPE"), "Add INT16_TYPE field to variant");
564 ok(!bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
565 "UINT35_TYPE"), "Add UINT35_TYPE field to variant");
567 ret_field_type
= bt_ctf_field_type_variant_get_tag_field_type(variant_type
);
568 ok(ret_field_type
== enum_variant_type
,
569 "bt_ctf_field_type_variant_get_tag_field_type returns a correct tag type");
570 bt_ctf_object_put_ref(ret_field_type
);
572 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
573 ok(ret_string
? strcmp(ret_string
, "variant_selector") == 0 : 0,
574 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
575 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
576 variant_type
, "INT16_TYPE");
577 ok(ret_field_type
== int_16_type
,
578 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
579 bt_ctf_object_put_ref(ret_field_type
);
581 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
582 "bt_ctf_field_type_variant_get_field_count returns the correct count");
584 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, NULL
, &ret_field_type
, 0) == 0,
585 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
586 bt_ctf_object_put_ref(ret_field_type
);
587 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, &ret_string
, NULL
, 0) == 0,
588 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
589 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
590 "bt_ctf_field_type_variant_get_field returns a field");
591 ok(strcmp("INT16_TYPE", ret_string
) == 0,
592 "bt_ctf_field_type_variant_get_field returns a correct field name");
593 ok(ret_field_type
== int_16_type
,
594 "bt_ctf_field_type_variant_get_field returns a correct field type");
595 bt_ctf_object_put_ref(ret_field_type
);
597 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
598 enum_variant_type
, "variant_selector"),
599 "Add variant_selector field to complex structure");
600 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
601 string_type
, "string"), "Add `string` field to complex structure");
602 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
603 variant_type
, "variant_value"),
604 "Add variant_value field to complex structure");
605 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
606 inner_structure_type
, "inner_structure"),
607 "Add inner_structure field to complex structure");
609 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
610 ok(event_class
, "Create an event class");
611 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
612 "Reject addition of a field with an empty name to an event");
613 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
614 "Reject addition of a field with a NULL type to an event");
615 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
617 "Reject addition of a type with an illegal name to an event");
618 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
620 "Add field of type unsigned integer to an event");
621 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
622 "int_16") == 0, "Add field of type signed integer to an event");
623 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
624 "complex_structure") == 0,
625 "Add composite structure to an event");
627 ret_string
= bt_ctf_event_class_get_name(event_class
);
628 ok(strcmp(ret_string
, complex_test_event_string
) == 0,
629 "bt_ctf_event_class_get_name returns a correct name");
630 ok(bt_ctf_event_class_get_id(event_class
) < 0,
631 "bt_ctf_event_class_get_id returns a negative value when not set");
632 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
633 "bt_ctf_event_class_set_id handles NULL correctly");
634 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
635 "Set an event class' id");
636 ok(bt_ctf_event_class_get_id(event_class
) == 42,
637 "bt_ctf_event_class_get_id returns the correct value");
639 /* Test event class attributes */
640 ok(bt_ctf_event_class_get_log_level(event_class
) == BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
,
641 "event class has the expected initial log level");
642 ok(!bt_ctf_event_class_get_emf_uri(event_class
),
643 "as expected, event class has no initial EMF URI");
644 ok(bt_ctf_event_class_set_log_level(NULL
, BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
),
645 "bt_ctf_event_class_set_log_level handles a NULL event class correctly");
646 ok(bt_ctf_event_class_set_log_level(event_class
, BT_CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN
),
647 "bt_ctf_event_class_set_log_level handles an unknown log level correctly");
648 ok(!bt_ctf_event_class_set_log_level(event_class
, BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
),
649 "bt_ctf_event_class_set_log_level succeeds with a valid log level");
650 ok(bt_ctf_event_class_get_log_level(event_class
) == BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
,
651 "bt_ctf_event_class_get_log_level returns the expected log level");
652 ok(bt_ctf_event_class_set_emf_uri(NULL
, "https://babeltrace.org/"),
653 "bt_ctf_event_class_set_emf_uri handles a NULL event class correctly");
654 ok(!bt_ctf_event_class_set_emf_uri(event_class
, "https://babeltrace.org/"),
655 "bt_ctf_event_class_set_emf_uri succeeds with a valid EMF URI");
656 ok(strcmp(bt_ctf_event_class_get_emf_uri(event_class
), "https://babeltrace.org/") == 0,
657 "bt_ctf_event_class_get_emf_uri returns the expected EMF URI");
658 ok(!bt_ctf_event_class_set_emf_uri(event_class
, NULL
),
659 "bt_ctf_event_class_set_emf_uri succeeds with NULL (to reset)");
660 ok(!bt_ctf_event_class_get_emf_uri(event_class
),
661 "as expected, event class has no EMF URI after reset");
663 /* Add event class to the stream class */
664 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
665 "Reject addition of NULL event class to a stream class");
666 ok(bt_ctf_stream_class_add_event_class(stream_class
,
667 event_class
) == 0, "Add an event class to stream class");
669 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
670 ok(ret_stream_class
== stream_class
,
671 "bt_ctf_event_class_get_stream_class returns the correct stream class");
672 bt_ctf_object_put_ref(ret_stream_class
);
674 ok(!bt_ctf_event_class_get_field_by_name(event_class
, "truie"),
675 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
676 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
677 "complex_structure");
678 bt_ctf_object_put_ref(ret_field_type
);
680 event
= bt_ctf_event_create(event_class
);
681 ok(event
, "Instanciate a complex event");
683 ret_event_class
= bt_ctf_event_get_class(event
);
684 ok(ret_event_class
== event_class
,
685 "bt_ctf_event_get_class returns the correct event class");
686 bt_ctf_object_put_ref(ret_event_class
);
688 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
689 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
690 bt_ctf_field_integer_unsigned_set_value(uint_35_field
, 0x0DDF00D);
691 ok(bt_ctf_field_integer_unsigned_get_value(uint_35_field
,
692 &ret_unsigned_int
) == 0,
693 "bt_ctf_field_integer_unsigned_get_value succeeds after setting a value");
694 ok(ret_unsigned_int
== 0x0DDF00D,
695 "bt_ctf_field_integer_unsigned_get_value returns the correct value");
696 bt_ctf_object_put_ref(uint_35_field
);
698 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
699 bt_ctf_field_integer_signed_set_value(int_16_field
, -12345);
700 ok(bt_ctf_field_integer_signed_get_value(int_16_field
,
701 &ret_signed_int
) == 0,
702 "bt_ctf_field_integer_signed_get_value succeeds after setting a value");
703 ok(ret_signed_int
== -12345,
704 "bt_ctf_field_integer_signed_get_value returns the correct value");
705 bt_ctf_object_put_ref(int_16_field
);
707 complex_structure_field
= bt_ctf_event_get_payload(event
,
708 "complex_structure");
710 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
711 complex_structure_field
, 3);
712 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
713 bt_ctf_object_put_ref(inner_structure_field
);
714 bt_ctf_object_put_ref(ret_field_type
);
716 inner_structure_field
= bt_ctf_field_structure_get_field_by_name(
717 complex_structure_field
, "inner_structure");
718 a_string_field
= bt_ctf_field_structure_get_field_by_name(
719 complex_structure_field
, "string");
720 enum_variant_field
= bt_ctf_field_structure_get_field_by_name(
721 complex_structure_field
, "variant_selector");
722 variant_field
= bt_ctf_field_structure_get_field_by_name(
723 complex_structure_field
, "variant_value");
724 uint_35_field
= bt_ctf_field_structure_get_field_by_name(
725 inner_structure_field
, "seq_len");
726 a_sequence_field
= bt_ctf_field_structure_get_field_by_name(
727 inner_structure_field
, "a_sequence");
728 an_array_field
= bt_ctf_field_structure_get_field_by_name(
729 inner_structure_field
, "an_array");
731 enum_container_field
= bt_ctf_field_enumeration_get_container(
733 bt_ctf_field_integer_unsigned_set_value(enum_container_field
, 1);
734 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
736 bt_ctf_field_integer_signed_set_value(int_16_field
, -200);
737 bt_ctf_object_put_ref(int_16_field
);
738 bt_ctf_field_string_set_value(a_string_field
,
740 ok(!bt_ctf_field_string_append(a_string_field
, test_string_2
),
741 "bt_ctf_field_string_append succeeds");
742 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 5),
743 "bt_ctf_field_string_append_len succeeds (append 5 characters)");
744 ok(!bt_ctf_field_string_append_len(a_string_field
, &test_string_4
[5], 3),
745 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
746 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 0),
747 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
749 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
750 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
751 ok(ret_string
? strcmp(ret_string
, test_string_cat
) == 0 : 0,
752 "bt_ctf_field_string_get_value returns a correct value");
753 bt_ctf_field_integer_unsigned_set_value(uint_35_field
,
754 SEQUENCE_TEST_LENGTH
);
756 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
757 variant_type
, enum_variant_field
);
758 ok(ret_field_type
== int_16_type
,
759 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
761 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
762 uint_35_field
) == 0, "Set a sequence field's length");
764 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
765 int_16_field
= bt_ctf_field_sequence_get_field(
766 a_sequence_field
, i
);
767 bt_ctf_field_integer_signed_set_value(int_16_field
, 4 - i
);
768 bt_ctf_object_put_ref(int_16_field
);
771 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
772 int_16_field
= bt_ctf_field_array_get_field(
774 bt_ctf_field_integer_signed_set_value(int_16_field
, i
);
775 bt_ctf_object_put_ref(int_16_field
);
778 stream_event_ctx_field
= bt_ctf_event_get_stream_event_context(event
);
779 BT_ASSERT(stream_event_ctx_field
);
780 stream_event_ctx_int_field
= bt_ctf_field_structure_get_field_by_name(
781 stream_event_ctx_field
, "common_event_context");
782 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_field
);
783 bt_ctf_field_integer_unsigned_set_value(stream_event_ctx_int_field
, 17);
784 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_int_field
);
786 bt_ctf_clock_set_time(clock
, ++current_time
);
787 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
788 "Append a complex event to a stream");
791 * Populate the custom packet context field with a dummy value
792 * otherwise flush will fail.
794 packet_context
= bt_ctf_stream_get_packet_context(stream
);
795 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
796 "custom_packet_context_field");
797 bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 1);
799 ok(bt_ctf_stream_flush(stream
) == 0,
800 "Flush a stream containing a complex event");
802 bt_ctf_object_put_ref(uint_35_field
);
803 bt_ctf_object_put_ref(a_string_field
);
804 bt_ctf_object_put_ref(inner_structure_field
);
805 bt_ctf_object_put_ref(complex_structure_field
);
806 bt_ctf_object_put_ref(a_sequence_field
);
807 bt_ctf_object_put_ref(an_array_field
);
808 bt_ctf_object_put_ref(enum_variant_field
);
809 bt_ctf_object_put_ref(enum_container_field
);
810 bt_ctf_object_put_ref(variant_field
);
811 bt_ctf_object_put_ref(packet_context_field
);
812 bt_ctf_object_put_ref(packet_context
);
813 bt_ctf_object_put_ref(uint_35_type
);
814 bt_ctf_object_put_ref(int_16_type
);
815 bt_ctf_object_put_ref(string_type
);
816 bt_ctf_object_put_ref(sequence_type
);
817 bt_ctf_object_put_ref(array_type
);
818 bt_ctf_object_put_ref(inner_structure_type
);
819 bt_ctf_object_put_ref(complex_structure_type
);
820 bt_ctf_object_put_ref(uint_3_type
);
821 bt_ctf_object_put_ref(enum_variant_type
);
822 bt_ctf_object_put_ref(variant_type
);
823 bt_ctf_object_put_ref(ret_field_type
);
824 bt_ctf_object_put_ref(event_class
);
825 bt_ctf_object_put_ref(event
);
829 void type_field_tests(void)
831 struct bt_ctf_field
*uint_12
;
832 struct bt_ctf_field
*int_16
;
833 struct bt_ctf_field
*string
;
834 struct bt_ctf_field_type
*composite_structure_type
;
835 struct bt_ctf_field_type
*structure_seq_type
;
836 struct bt_ctf_field_type
*string_type
;
837 struct bt_ctf_field_type
*sequence_type
;
838 struct bt_ctf_field_type
*uint_8_type
;
839 struct bt_ctf_field_type
*int_16_type
;
840 struct bt_ctf_field_type
*uint_12_type
=
841 bt_ctf_field_type_integer_create(12);
842 struct bt_ctf_field_type
*enumeration_type
;
843 struct bt_ctf_field_type
*returned_type
;
844 const char *ret_string
;
846 ok(uint_12_type
, "Create an unsigned integer type");
847 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
848 BT_CTF_INTEGER_BASE_BINARY
) == 0,
849 "Set integer type's base as binary");
850 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
851 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
852 "Set integer type's base as decimal");
853 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
854 BT_CTF_INTEGER_BASE_UNKNOWN
),
855 "Reject integer type's base set as unknown");
856 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
857 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
858 "Set integer type's base as octal");
859 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
860 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
861 "Set integer type's base as hexadecimal");
862 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
863 "Reject unknown integer base value");
864 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
865 "Set integer type signedness to signed");
866 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
867 "Set integer type signedness to unsigned");
868 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
869 "bt_ctf_field_type_integer_get_size returns a correct value");
870 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
871 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
873 ok(bt_ctf_field_type_set_byte_order(NULL
,
874 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
875 "bt_ctf_field_type_set_byte_order handles NULL correctly");
876 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
877 (enum bt_ctf_byte_order
) 42) < 0,
878 "bt_ctf_field_type_set_byte_order rejects invalid values");
879 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
880 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
881 "Set an integer's byte order to little endian");
882 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
883 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
884 "Set an integer's byte order to big endian");
885 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
886 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
887 "bt_ctf_field_type_get_byte_order returns a correct value");
889 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
890 BT_CTF_FIELD_TYPE_ID_INTEGER
,
891 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
893 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
894 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
895 "bt_ctf_field_type_integer_get_base returns a correct value");
897 ok(bt_ctf_field_type_integer_set_encoding(NULL
,
898 BT_CTF_STRING_ENCODING_ASCII
) < 0,
899 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
900 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
901 (enum bt_ctf_string_encoding
) 123) < 0,
902 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
903 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
904 BT_CTF_STRING_ENCODING_UTF8
) == 0,
905 "Set integer type encoding to UTF8");
906 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) ==
907 BT_CTF_STRING_ENCODING_UTF8
,
908 "bt_ctf_field_type_integer_get_encoding returns a correct value");
910 int_16_type
= bt_ctf_field_type_integer_create(16);
911 BT_ASSERT(int_16_type
);
912 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
913 "Set signedness of 16 bit integer to true");
914 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
915 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
916 uint_8_type
= bt_ctf_field_type_integer_create(8);
918 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
919 ok(sequence_type
, "Create a sequence of int16_t type");
920 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
921 BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
922 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
924 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
926 ok(strcmp(ret_string
, "seq_len") == 0,
927 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
928 returned_type
= bt_ctf_field_type_sequence_get_element_field_type(
930 ok(returned_type
== int_16_type
,
931 "bt_ctf_field_type_sequence_get_element_field_type returns the correct type");
932 bt_ctf_object_put_ref(returned_type
);
934 string_type
= bt_ctf_field_type_string_create();
935 ok(string_type
, "Create a string type");
936 ok(bt_ctf_field_type_string_set_encoding(string_type
,
937 BT_CTF_STRING_ENCODING_NONE
),
938 "Reject invalid \"None\" string encoding");
939 ok(bt_ctf_field_type_string_set_encoding(string_type
,
941 "Reject invalid string encoding");
942 ok(bt_ctf_field_type_string_set_encoding(string_type
,
943 BT_CTF_STRING_ENCODING_ASCII
) == 0,
944 "Set string encoding to ASCII");
946 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
947 BT_CTF_STRING_ENCODING_ASCII
,
948 "bt_ctf_field_type_string_get_encoding returns the correct value");
950 structure_seq_type
= bt_ctf_field_type_structure_create();
951 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
952 BT_CTF_FIELD_TYPE_ID_STRUCT
,
953 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
954 ok(structure_seq_type
, "Create a structure type");
955 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
956 uint_8_type
, "seq_len") == 0,
957 "Add a uint8_t type to a structure");
958 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
959 sequence_type
, "a_sequence") == 0,
960 "Add a sequence type to a structure");
962 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
963 "bt_ctf_field_type_structure_get_field_count returns a correct value");
965 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
966 NULL
, &returned_type
, 1) == 0,
967 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
968 bt_ctf_object_put_ref(returned_type
);
969 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
970 &ret_string
, NULL
, 1) == 0,
971 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
972 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
973 &ret_string
, &returned_type
, 1) == 0,
974 "bt_ctf_field_type_structure_get_field returns a field");
975 ok(strcmp(ret_string
, "a_sequence") == 0,
976 "bt_ctf_field_type_structure_get_field returns a correct field name");
977 ok(returned_type
== sequence_type
,
978 "bt_ctf_field_type_structure_get_field returns a correct field type");
979 bt_ctf_object_put_ref(returned_type
);
981 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
982 structure_seq_type
, "a_sequence");
983 ok(returned_type
== sequence_type
,
984 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
985 bt_ctf_object_put_ref(returned_type
);
987 composite_structure_type
= bt_ctf_field_type_structure_create();
988 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
989 string_type
, "a_string") == 0,
990 "Add a string type to a structure");
991 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
992 structure_seq_type
, "inner_structure") == 0,
993 "Add a structure type to a structure");
995 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
996 structure_seq_type
, "a_sequence");
997 ok(returned_type
== sequence_type
,
998 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
999 bt_ctf_object_put_ref(returned_type
);
1001 int_16
= bt_ctf_field_create(int_16_type
);
1002 ok(int_16
, "Instanciate a signed 16-bit integer");
1003 uint_12
= bt_ctf_field_create(uint_12_type
);
1004 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1005 returned_type
= bt_ctf_field_get_type(int_16
);
1006 ok(returned_type
== int_16_type
,
1007 "bt_ctf_field_get_type returns the correct type");
1009 /* Can't modify types after instanciating them */
1010 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1011 BT_CTF_INTEGER_BASE_DECIMAL
),
1012 "Check an integer type' base can't be modified after instanciation");
1013 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1014 "Check an integer type's signedness can't be modified after instanciation");
1016 /* Check overflows are properly tested for */
1017 ok(bt_ctf_field_integer_signed_set_value(int_16
, -32768) == 0,
1018 "Check -32768 is allowed for a signed 16-bit integer");
1019 ok(bt_ctf_field_integer_signed_set_value(int_16
, 32767) == 0,
1020 "Check 32767 is allowed for a signed 16-bit integer");
1021 ok(bt_ctf_field_integer_signed_set_value(int_16
, -42) == 0,
1022 "Check -42 is allowed for a signed 16-bit integer");
1024 ok(bt_ctf_field_integer_unsigned_set_value(uint_12
, 4095) == 0,
1025 "Check 4095 is allowed for an unsigned 12-bit integer");
1026 ok(bt_ctf_field_integer_unsigned_set_value(uint_12
, 0) == 0,
1027 "Check 0 is allowed for an unsigned 12-bit integer");
1029 string
= bt_ctf_field_create(string_type
);
1030 ok(string
, "Instanciate a string field");
1031 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1032 "Set a string's value");
1034 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1035 ok(enumeration_type
,
1036 "Create an enumeration type with an unsigned 12-bit integer as container");
1038 bt_ctf_object_put_ref(string
);
1039 bt_ctf_object_put_ref(uint_12
);
1040 bt_ctf_object_put_ref(int_16
);
1041 bt_ctf_object_put_ref(composite_structure_type
);
1042 bt_ctf_object_put_ref(structure_seq_type
);
1043 bt_ctf_object_put_ref(string_type
);
1044 bt_ctf_object_put_ref(sequence_type
);
1045 bt_ctf_object_put_ref(uint_8_type
);
1046 bt_ctf_object_put_ref(int_16_type
);
1047 bt_ctf_object_put_ref(uint_12_type
);
1048 bt_ctf_object_put_ref(enumeration_type
);
1049 bt_ctf_object_put_ref(returned_type
);
1053 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
1054 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
1057 * Append enough events to force the underlying packet to be resized.
1058 * Also tests that a new event can be declared after a stream has been
1059 * instantiated and used/flushed.
1063 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
1065 struct bt_ctf_field_type
*integer_type
=
1066 bt_ctf_field_type_integer_create(17);
1067 struct bt_ctf_field_type
*string_type
=
1068 bt_ctf_field_type_string_create();
1069 struct bt_ctf_event
*event
= NULL
;
1070 struct bt_ctf_field
*ret_field
= NULL
;
1071 struct bt_ctf_field_type
*ret_field_type
= NULL
;
1072 uint64_t ret_uint64
;
1073 int events_appended
= 0;
1074 struct bt_ctf_field
*packet_context
= NULL
,
1075 *packet_context_field
= NULL
, *stream_event_context
= NULL
;
1076 struct bt_ctf_field_type
*ep_field_1_type
= NULL
;
1077 struct bt_ctf_field_type
*ep_a_string_type
= NULL
;
1078 struct bt_ctf_field_type
*ep_type
= NULL
;
1080 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
1082 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
1084 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1085 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
1091 * bt_ctf_stream_class_add_event_class() copies the field types
1092 * of event_class, so we retrieve the new ones to create the
1093 * appropriate fields.
1095 ep_type
= bt_ctf_event_class_get_payload_field_type(event_class
);
1097 ep_field_1_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1098 ep_type
, "field_1");
1099 BT_ASSERT(ep_field_1_type
);
1100 ep_a_string_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1101 ep_type
, "a_string");
1102 BT_ASSERT(ep_a_string_type
);
1104 event
= bt_ctf_event_create(event_class
);
1105 ret_field
= bt_ctf_event_get_payload(event
, 0);
1106 ret_field_type
= bt_ctf_field_get_type(ret_field
);
1107 bt_ctf_object_put_ref(ret_field_type
);
1108 bt_ctf_object_put_ref(ret_field
);
1109 bt_ctf_object_put_ref(event
);
1111 for (i
= 0; i
< packet_resize_test_length
; i
++) {
1112 event
= bt_ctf_event_create(event_class
);
1113 struct bt_ctf_field
*integer
=
1114 bt_ctf_field_create(ep_field_1_type
);
1115 struct bt_ctf_field
*string
=
1116 bt_ctf_field_create(ep_a_string_type
);
1118 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
1119 ret
|= bt_ctf_field_integer_unsigned_set_value(integer
, i
);
1120 ret
|= bt_ctf_event_set_payload(event
, "field_1",
1122 bt_ctf_object_put_ref(integer
);
1123 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
1124 ret
|= bt_ctf_event_set_payload(event
, "a_string",
1126 bt_ctf_object_put_ref(string
);
1128 /* Populate stream event context */
1129 stream_event_context
=
1130 bt_ctf_event_get_stream_event_context(event
);
1131 integer
= bt_ctf_field_structure_get_field_by_name(stream_event_context
,
1132 "common_event_context");
1133 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_context
);
1134 ret
|= bt_ctf_field_integer_unsigned_set_value(integer
,
1136 bt_ctf_object_put_ref(integer
);
1138 ret
|= bt_ctf_stream_append_event(stream
, event
);
1139 bt_ctf_object_put_ref(event
);
1146 events_appended
= !!(i
== packet_resize_test_length
);
1147 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1148 ok(ret
== 0 && ret_uint64
== 0,
1149 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1150 bt_ctf_stream_append_discarded_events(stream
, 1000);
1151 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1152 ok(ret
== 0 && ret_uint64
== 1000,
1153 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1156 ok(events_appended
, "Append 100 000 events to a stream");
1159 * Populate the custom packet context field with a dummy value
1160 * otherwise flush will fail.
1162 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1163 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
1164 "custom_packet_context_field");
1165 bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 2);
1167 ok(bt_ctf_stream_flush(stream
) == 0,
1168 "Flush a stream that forces a packet resize");
1169 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1170 ok(ret
== 0 && ret_uint64
== 1000,
1171 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1172 bt_ctf_object_put_ref(integer_type
);
1173 bt_ctf_object_put_ref(string_type
);
1174 bt_ctf_object_put_ref(packet_context
);
1175 bt_ctf_object_put_ref(packet_context_field
);
1176 bt_ctf_object_put_ref(stream_event_context
);
1177 bt_ctf_object_put_ref(event_class
);
1178 bt_ctf_object_put_ref(ep_field_1_type
);
1179 bt_ctf_object_put_ref(ep_a_string_type
);
1180 bt_ctf_object_put_ref(ep_type
);
1184 void test_empty_stream(struct bt_ctf_writer
*writer
)
1187 struct bt_ctf_trace
*trace
= NULL
, *ret_trace
= NULL
;
1188 struct bt_ctf_stream_class
*stream_class
= NULL
;
1189 struct bt_ctf_stream
*stream
= NULL
;
1191 trace
= bt_ctf_writer_get_trace(writer
);
1193 diag("Failed to get trace from writer");
1198 stream_class
= bt_ctf_stream_class_create("empty_stream");
1199 if (!stream_class
) {
1200 diag("Failed to create stream class");
1205 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
1206 BT_ASSERT(ret
== 0);
1207 ret
= bt_ctf_stream_class_set_event_header_type(stream_class
, NULL
);
1208 BT_ASSERT(ret
== 0);
1210 ok(!bt_ctf_stream_class_get_trace(stream_class
),
1211 "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned");
1213 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1215 diag("Failed to create writer stream");
1220 ret_trace
= bt_ctf_stream_class_get_trace(stream_class
);
1221 ok(ret_trace
== trace
,
1222 "bt_ctf_stream_class_get_trace returns the correct trace after a stream has been created");
1225 "Created a stream class with default attributes and an empty stream");
1226 bt_ctf_object_put_ref(trace
);
1227 bt_ctf_object_put_ref(ret_trace
);
1228 bt_ctf_object_put_ref(stream
);
1229 bt_ctf_object_put_ref(stream_class
);
1233 void test_custom_event_header_stream(struct bt_ctf_writer
*writer
,
1234 struct bt_ctf_clock
*clock
)
1237 struct bt_ctf_stream_class
*stream_class
= NULL
;
1238 struct bt_ctf_stream
*stream
= NULL
;
1239 struct bt_ctf_field_type
*integer_type
= NULL
,
1240 *sequence_type
= NULL
, *event_header_type
= NULL
;
1241 struct bt_ctf_field
*integer
= NULL
, *sequence
= NULL
,
1242 *event_header
= NULL
, *packet_header
= NULL
;
1243 struct bt_ctf_event_class
*event_class
= NULL
;
1244 struct bt_ctf_event
*event
= NULL
;
1246 stream_class
= bt_ctf_stream_class_create("custom_event_header_stream");
1247 if (!stream_class
) {
1248 fail("Failed to create stream class");
1252 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1254 fail("Failed to set stream class clock");
1259 * Customize event header to add an "seq_len" integer member
1260 * which will be used as the length of a sequence in an event of this
1263 event_header_type
= bt_ctf_stream_class_get_event_header_type(
1265 if (!event_header_type
) {
1266 fail("Failed to get event header type");
1270 integer_type
= bt_ctf_field_type_integer_create(13);
1271 if (!integer_type
) {
1272 fail("Failed to create length integer type");
1276 ret
= bt_ctf_field_type_structure_add_field(event_header_type
,
1277 integer_type
, "seq_len");
1279 fail("Failed to add a new field to stream event header");
1283 event_class
= bt_ctf_event_class_create("sequence_event");
1285 fail("Failed to create event class");
1290 * This event's payload will contain a sequence which references
1291 * stream.event.header.seq_len as its length field.
1293 sequence_type
= bt_ctf_field_type_sequence_create(integer_type
,
1294 "stream.event.header.seq_len");
1295 if (!sequence_type
) {
1296 fail("Failed to create a sequence");
1300 ret
= bt_ctf_event_class_add_field(event_class
, sequence_type
,
1303 fail("Failed to add a sequence to an event class");
1307 ret
= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1309 fail("Failed to add event class to stream class");
1313 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1315 fail("Failed to create stream")
1320 * We have defined a custom packet header field. We have to populate it
1323 packet_header
= bt_ctf_stream_get_packet_header(stream
);
1324 if (!packet_header
) {
1325 fail("Failed to get stream packet header");
1329 integer
= bt_ctf_field_structure_get_field_by_name(packet_header
,
1330 "custom_trace_packet_header_field");
1332 fail("Failed to retrieve custom_trace_packet_header_field");
1336 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 3487);
1338 fail("Failed to set custom_trace_packet_header_field value");
1341 bt_ctf_object_put_ref(integer
);
1343 event
= bt_ctf_event_create(event_class
);
1345 fail("Failed to create event");
1349 event_header
= bt_ctf_event_get_header(event
);
1350 if (!event_header
) {
1351 fail("Failed to get event header");
1355 integer
= bt_ctf_field_structure_get_field_by_name(event_header
,
1358 fail("Failed to get seq_len field from event header");
1362 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 2);
1364 fail("Failed to set seq_len value in event header");
1368 /* Populate both sequence integer fields */
1369 sequence
= bt_ctf_event_get_payload(event
, "some_sequence");
1371 fail("Failed to retrieve sequence from event");
1375 ret
= bt_ctf_field_sequence_set_length(sequence
, integer
);
1377 fail("Failed to set sequence length");
1380 bt_ctf_object_put_ref(integer
);
1382 for (i
= 0; i
< 2; i
++) {
1383 integer
= bt_ctf_field_sequence_get_field(sequence
, i
);
1385 fail("Failed to retrieve sequence element");
1389 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, i
);
1391 fail("Failed to set sequence element value");
1395 bt_ctf_object_put_ref(integer
);
1399 ret
= bt_ctf_stream_append_event(stream
, event
);
1401 fail("Failed to append event to stream");
1405 ret
= bt_ctf_stream_flush(stream
);
1407 fail("Failed to flush custom_event_header stream");
1410 bt_ctf_object_put_ref(stream
);
1411 bt_ctf_object_put_ref(stream_class
);
1412 bt_ctf_object_put_ref(event_class
);
1413 bt_ctf_object_put_ref(event
);
1414 bt_ctf_object_put_ref(integer
);
1415 bt_ctf_object_put_ref(sequence
);
1416 bt_ctf_object_put_ref(event_header
);
1417 bt_ctf_object_put_ref(packet_header
);
1418 bt_ctf_object_put_ref(sequence_type
);
1419 bt_ctf_object_put_ref(integer_type
);
1420 bt_ctf_object_put_ref(event_header_type
);
1424 void test_instanciate_event_before_stream(struct bt_ctf_writer
*writer
,
1425 struct bt_ctf_clock
*clock
)
1428 struct bt_ctf_stream_class
*stream_class
= NULL
;
1429 struct bt_ctf_stream
*stream
= NULL
,
1431 struct bt_ctf_event_class
*event_class
= NULL
;
1432 struct bt_ctf_event
*event
= NULL
;
1433 struct bt_ctf_field_type
*integer_type
= NULL
;
1434 struct bt_ctf_field
*payload_field
= NULL
;
1435 struct bt_ctf_field
*integer
= NULL
;
1437 stream_class
= bt_ctf_stream_class_create("event_before_stream_test");
1438 if (!stream_class
) {
1439 diag("Failed to create stream class");
1444 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1446 diag("Failed to set stream class clock");
1450 event_class
= bt_ctf_event_class_create("some_event_class_name");
1451 integer_type
= bt_ctf_field_type_integer_create(32);
1452 if (!integer_type
) {
1453 diag("Failed to create integer field type");
1458 ret
= bt_ctf_event_class_add_field(event_class
, integer_type
,
1461 diag("Failed to add field to event class");
1465 ret
= bt_ctf_stream_class_add_event_class(stream_class
,
1468 diag("Failed to add event class to stream class");
1471 event
= bt_ctf_event_create(event_class
);
1473 diag("Failed to create event");
1478 payload_field
= bt_ctf_event_get_payload_field(event
);
1479 if (!payload_field
) {
1480 diag("Failed to get event's payload field");
1485 integer
= bt_ctf_field_structure_get_field_by_index(payload_field
, 0);
1487 diag("Failed to get integer field payload from event");
1492 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 1234);
1494 diag("Failed to set integer field value");
1498 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1500 diag("Failed to create writer stream");
1505 ret
= bt_ctf_stream_append_event(stream
, event
);
1507 diag("Failed to append event to stream");
1511 ret_stream
= bt_ctf_event_get_stream(event
);
1512 ok(ret_stream
== stream
,
1513 "bt_ctf_event_get_stream returns an event's stream after it has been appended");
1516 "Create an event before instanciating its associated stream");
1517 bt_ctf_object_put_ref(stream
);
1518 bt_ctf_object_put_ref(ret_stream
);
1519 bt_ctf_object_put_ref(stream_class
);
1520 bt_ctf_object_put_ref(event_class
);
1521 bt_ctf_object_put_ref(event
);
1522 bt_ctf_object_put_ref(integer_type
);
1523 bt_ctf_object_put_ref(integer
);
1524 bt_ctf_object_put_ref(payload_field
);
1528 void append_existing_event_class(struct bt_ctf_stream_class
*stream_class
)
1531 struct bt_ctf_event_class
*event_class
;
1533 event_class
= bt_ctf_event_class_create("Simple Event");
1534 BT_ASSERT(event_class
);
1535 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
) == 0,
1536 "two event classes with the same name may cohabit within the same stream class");
1537 bt_ctf_object_put_ref(event_class
);
1539 event_class
= bt_ctf_event_class_create("different name, ok");
1540 BT_ASSERT(event_class
);
1541 ret
= bt_ctf_event_class_set_id(event_class
, 13);
1542 BT_ASSERT(ret
== 0);
1543 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
1544 "two event classes with the same ID cannot cohabit within the same stream class");
1545 bt_ctf_object_put_ref(event_class
);
1549 void test_clock_utils(void)
1552 struct bt_ctf_clock
*clock
= NULL
;
1554 clock
= bt_ctf_clock_create("water");
1556 ret
= bt_ctf_clock_set_offset_s(clock
, 1234);
1558 ret
= bt_ctf_clock_set_offset(clock
, 1000);
1560 ret
= bt_ctf_clock_set_frequency(clock
, 1000000000);
1562 ret
= bt_ctf_clock_set_frequency(clock
, 1534);
1565 BT_CTF_OBJECT_PUT_REF_AND_RESET(clock
);
1568 int main(int argc
, char **argv
)
1570 const char *env_resize_length
;
1572 gchar
*metadata_path
;
1573 const char *clock_name
= "test_clock";
1574 const char *clock_description
= "This is a test clock";
1575 const char *returned_clock_name
;
1576 const char *returned_clock_description
;
1577 const uint64_t frequency
= 1123456789;
1578 const int64_t offset_s
= 13515309;
1579 const int64_t offset
= 1234567;
1580 int64_t get_offset_s
,
1582 const uint64_t precision
= 10;
1583 const int is_absolute
= 0xFF;
1584 char *metadata_string
;
1585 struct bt_ctf_writer
*writer
;
1586 struct bt_utsname name
= {"GNU/Linux", "testhost", "4.4.0-87-generic",
1587 "#110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017", "x86_64"};
1588 struct bt_ctf_clock
*clock
, *ret_clock
;
1589 struct bt_ctf_stream_class
*stream_class
, *ret_stream_class
;
1590 struct bt_ctf_stream
*stream1
;
1591 struct bt_ctf_stream
*stream
;
1592 const char *ret_string
;
1593 const uint8_t *ret_uuid
;
1594 bt_uuid_t tmp_uuid
= { 0 };
1595 struct bt_ctf_field_type
*packet_context_type
,
1596 *packet_context_field_type
,
1597 *packet_header_type
,
1598 *packet_header_field_type
,
1600 *stream_event_context_type
,
1602 *event_header_field_type
;
1603 struct bt_ctf_field
*packet_header
, *packet_header_field
;
1604 struct bt_ctf_trace
*trace
;
1608 printf("Usage: tests-ctf-writer path_to_babeltrace\n");
1612 env_resize_length
= getenv("PACKET_RESIZE_TEST_LENGTH");
1613 if (env_resize_length
) {
1614 packet_resize_test_length
=
1615 (unsigned int) atoi(env_resize_length
);
1618 plan_tests(NR_TESTS
);
1620 trace_path
= g_build_filename(g_get_tmp_dir(), "ctfwriter_XXXXXX", NULL
);
1621 if (!bt_mkdtemp(trace_path
)) {
1625 metadata_path
= g_build_filename(trace_path
, "metadata", NULL
);
1627 writer
= bt_ctf_writer_create(trace_path
);
1628 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
1630 ok(!bt_ctf_writer_get_trace(NULL
),
1631 "bt_ctf_writer_get_trace correctly handles NULL");
1632 trace
= bt_ctf_writer_get_trace(writer
);
1633 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
),
1634 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NATIVE");
1635 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_UNSPECIFIED
),
1636 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_UNSPECIFIED");
1638 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1639 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1640 "Set a trace's byte order to big endian");
1641 ok(bt_ctf_trace_get_native_byte_order(trace
) == BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1642 "bt_ctf_trace_get_native_byte_order returns a correct endianness");
1644 /* Add environment context to the trace */
1645 ok(bt_ctf_writer_add_environment_field(writer
, "host", name
.nodename
) == 0,
1646 "Add host (%s) environment field to writer instance",
1648 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
1650 "bt_ctf_writer_add_environment_field error with NULL writer");
1651 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
1653 "bt_ctf_writer_add_environment_field error with NULL field name");
1654 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
1656 "bt_ctf_writer_add_environment_field error with NULL field value");
1658 /* Test bt_ctf_trace_set_environment_field_integer */
1659 ok(bt_ctf_trace_set_environment_field_integer(NULL
, "test_env_int",
1661 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
1662 ok(bt_ctf_trace_set_environment_field_integer(trace
, NULL
, -194875),
1663 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
1664 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1666 "bt_ctf_trace_set_environment_field_integer succeeds");
1668 /* Test bt_ctf_trace_set_environment_field_string */
1669 ok(bt_ctf_trace_set_environment_field_string(NULL
, "test_env_str",
1671 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
1672 ok(bt_ctf_trace_set_environment_field_string(trace
, NULL
, "yeah"),
1673 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
1674 ok(bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1676 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
1677 ok(!bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1679 "bt_ctf_trace_set_environment_field_string succeeds");
1681 /* Test environment field replacement */
1682 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1684 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
1686 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
1687 == 0, "Add sysname (%s) environment field to writer instance",
1689 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
1690 name
.nodename
) == 0,
1691 "Add nodename (%s) environment field to writer instance",
1693 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
1694 == 0, "Add release (%s) environment field to writer instance",
1696 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
1697 == 0, "Add version (%s) environment field to writer instance",
1699 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
1700 == 0, "Add machine (%s) environment field to writer istance",
1703 /* Define a clock and add it to the trace */
1704 ok(!bt_ctf_clock_create("signed"),
1705 "Illegal clock name rejected");
1706 clock
= bt_ctf_clock_create(clock_name
);
1707 ok(clock
, "Clock created sucessfully");
1708 returned_clock_name
= bt_ctf_clock_get_name(clock
);
1709 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
1710 ok(returned_clock_name
? strcmp(returned_clock_name
, clock_name
) == 0 : 0,
1711 "Returned clock name is valid");
1713 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1714 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
1715 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
1716 "Clock description set successfully");
1718 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1719 ok(returned_clock_description
,
1720 "bt_ctf_clock_get_description returns a description.");
1721 ok(returned_clock_description
?
1722 strcmp(returned_clock_description
, clock_description
) == 0 : 0,
1723 "Returned clock description is valid");
1725 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
1726 "bt_ctf_clock_get_frequency returns the correct default frequency");
1727 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
1728 "Set clock frequency");
1729 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
1730 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
1732 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
1733 "bt_ctf_clock_get_offset_s succeeds");
1734 ok(get_offset_s
== DEFAULT_CLOCK_OFFSET_S
,
1735 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
1736 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
1737 "Set clock offset (seconds)");
1738 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
1739 "bt_ctf_clock_get_offset_s succeeds");
1740 ok(get_offset_s
== offset_s
,
1741 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
1743 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
1744 "bt_ctf_clock_get_offset succeeds");
1745 ok(get_offset
== DEFAULT_CLOCK_OFFSET
,
1746 "bt_ctf_clock_get_offset returns the correct default offset (in ticks)");
1747 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
1748 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
1749 "bt_ctf_clock_get_offset succeeds");
1750 ok(get_offset
== offset
,
1751 "bt_ctf_clock_get_offset returns the correct default offset (in ticks) once it is set");
1753 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
1754 "bt_ctf_clock_get_precision returns the correct default precision");
1755 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
1756 "Set clock precision");
1757 ok(bt_ctf_clock_get_precision(clock
) == precision
,
1758 "bt_ctf_clock_get_precision returns the correct precision once it is set");
1760 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
1761 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
1762 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
1763 "Set clock absolute property");
1764 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
1765 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
1766 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
1768 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1770 "bt_ctf_clock_get_uuid returns a UUID");
1772 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
1773 /* Slightly modify UUID */
1774 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
1777 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
1778 "bt_ctf_clock_set_uuid sets a new uuid successfully");
1779 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1781 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
1782 ok(uuid_match(ret_uuid
, tmp_uuid
),
1783 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
1785 /* Define a stream class */
1786 stream_class
= bt_ctf_stream_class_create("test_stream");
1787 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
1788 ok(ret_string
&& strcmp(ret_string
, "test_stream") == 0,
1789 "bt_ctf_stream_class_get_name returns a correct stream class name");
1791 ok(!bt_ctf_stream_class_get_clock(stream_class
),
1792 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
1793 ok(!bt_ctf_stream_class_get_clock(NULL
),
1794 "bt_ctf_stream_class_get_clock handles NULL correctly");
1796 ok(stream_class
, "Create stream class");
1797 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
1798 "Set a stream class' clock");
1799 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
1800 ok(ret_clock
== clock
,
1801 "bt_ctf_stream_class_get_clock returns a correct clock");
1802 bt_ctf_object_put_ref(ret_clock
);
1804 /* Test the event fields and event types APIs */
1807 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
1808 "bt_ctf_stream_class_get_id returns an error when no id is set");
1809 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
1810 "bt_ctf_stream_class_set_id handles NULL correctly");
1811 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
1812 "Set an stream class' id");
1813 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
1814 "bt_ctf_stream_class_get_id returns the correct value");
1816 /* Validate default event header fields */
1817 ret_field_type
= bt_ctf_stream_class_get_event_header_type(
1820 "bt_ctf_stream_class_get_event_header_type returns an event header type");
1821 ok(bt_ctf_field_type_get_type_id(ret_field_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1822 "Default event header type is a structure");
1823 event_header_field_type
=
1824 bt_ctf_field_type_structure_get_field_type_by_name(
1825 ret_field_type
, "id");
1826 ok(event_header_field_type
,
1827 "Default event header type contains an \"id\" field");
1828 ok(bt_ctf_field_type_get_type_id(
1829 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
1830 "Default event header \"id\" field is an integer");
1831 bt_ctf_object_put_ref(event_header_field_type
);
1832 event_header_field_type
=
1833 bt_ctf_field_type_structure_get_field_type_by_name(
1834 ret_field_type
, "timestamp");
1835 ok(event_header_field_type
,
1836 "Default event header type contains a \"timestamp\" field");
1837 ok(bt_ctf_field_type_get_type_id(
1838 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
1839 "Default event header \"timestamp\" field is an integer");
1840 bt_ctf_object_put_ref(event_header_field_type
);
1841 bt_ctf_object_put_ref(ret_field_type
);
1843 /* Add a custom trace packet header field */
1844 packet_header_type
= bt_ctf_trace_get_packet_header_field_type(trace
);
1845 ok(packet_header_type
,
1846 "bt_ctf_trace_get_packet_header_field_type returns a packet header");
1847 ok(bt_ctf_field_type_get_type_id(packet_header_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1848 "bt_ctf_trace_get_packet_header_field_type returns a packet header of type struct");
1849 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1850 packet_header_type
, "magic");
1851 ok(ret_field_type
, "Default packet header type contains a \"magic\" field");
1852 bt_ctf_object_put_ref(ret_field_type
);
1853 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1854 packet_header_type
, "uuid");
1855 ok(ret_field_type
, "Default packet header type contains a \"uuid\" field");
1856 bt_ctf_object_put_ref(ret_field_type
);
1857 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1858 packet_header_type
, "stream_id");
1859 ok(ret_field_type
, "Default packet header type contains a \"stream_id\" field");
1860 bt_ctf_object_put_ref(ret_field_type
);
1862 packet_header_field_type
= bt_ctf_field_type_integer_create(22);
1863 ok(!bt_ctf_field_type_structure_add_field(packet_header_type
,
1864 packet_header_field_type
, "custom_trace_packet_header_field"),
1865 "Added a custom trace packet header field successfully");
1867 ok(bt_ctf_trace_set_packet_header_field_type(NULL
, packet_header_type
) < 0,
1868 "bt_ctf_trace_set_packet_header_field_type handles a NULL trace correctly");
1869 ok(!bt_ctf_trace_set_packet_header_field_type(trace
, packet_header_type
),
1870 "Set a trace packet_header_type successfully");
1872 /* Add a custom field to the stream class' packet context */
1873 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
1874 ok(packet_context_type
,
1875 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
1876 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1877 "Packet context is a structure");
1879 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
1880 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
1882 integer_type
= bt_ctf_field_type_integer_create(32);
1884 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
1886 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
1888 /* Create a "uint5_t" equivalent custom packet context field */
1889 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
1891 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1892 packet_context_field_type
, "custom_packet_context_field");
1893 ok(ret
== 0, "Packet context field added successfully");
1895 /* Define a stream event context containing a my_integer field. */
1896 stream_event_context_type
= bt_ctf_field_type_structure_create();
1897 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1898 integer_type
, "common_event_context");
1900 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
1901 stream_event_context_type
) < 0,
1902 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
1903 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
1905 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
1907 ok(bt_ctf_stream_class_set_event_context_type(
1908 stream_class
, stream_event_context_type
) == 0,
1909 "Set a new stream event context type");
1911 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
1913 ok(ret_field_type
== stream_event_context_type
,
1914 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
1915 bt_ctf_object_put_ref(ret_field_type
);
1918 /* Instantiate a stream and append events */
1919 ret
= bt_ctf_writer_add_clock(writer
, clock
);
1920 BT_ASSERT(ret
== 0);
1922 ok(bt_ctf_trace_get_stream_count(trace
) == 0,
1923 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (0)");
1924 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
1925 ok(stream1
, "Instanciate a stream class from writer");
1926 ok(bt_ctf_trace_get_stream_count(trace
) == 1,
1927 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (1)");
1928 stream
= bt_ctf_trace_get_stream_by_index(trace
, 0);
1929 ok(stream
== stream1
,
1930 "bt_ctf_trace_get_stream_by_index() succeeds and returns the correct value");
1931 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream
);
1934 * Creating a stream through a writer adds the given stream
1935 * class to the writer's trace, thus registering the stream
1936 * class's clock to the trace.
1939 ret_stream_class
= bt_ctf_stream_get_class(stream1
);
1940 ok(ret_stream_class
,
1941 "bt_ctf_stream_get_class returns a stream class");
1942 ok(ret_stream_class
== stream_class
,
1943 "Returned stream class is of the correct type");
1946 * Packet header, packet context, event header, and stream
1947 * event context types were copied for the resolving
1950 BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_header_type
);
1951 BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_context_type
);
1952 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_context_type
);
1953 packet_header_type
= bt_ctf_trace_get_packet_header_field_type(trace
);
1954 BT_ASSERT(packet_header_type
);
1955 packet_context_type
=
1956 bt_ctf_stream_class_get_packet_context_type(stream_class
);
1957 BT_ASSERT(packet_context_type
);
1958 stream_event_context_type
=
1959 bt_ctf_stream_class_get_event_context_type(stream_class
);
1960 BT_ASSERT(stream_event_context_type
);
1963 * Try to modify the packet context type after a stream has been
1966 ret
= bt_ctf_field_type_structure_add_field(packet_header_type
,
1967 packet_header_field_type
, "should_fail");
1969 "Trace packet header type can't be modified once a stream has been instanciated");
1972 * Try to modify the packet context type after a stream has been
1975 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1976 packet_context_field_type
, "should_fail");
1978 "Packet context type can't be modified once a stream has been instanciated");
1981 * Try to modify the stream event context type after a stream has been
1984 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1985 integer_type
, "should_fail");
1987 "Stream event context type can't be modified once a stream has been instanciated");
1989 /* Should fail after instanciating a stream (frozen) */
1990 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
1991 "Changes to a stream class that was already instantiated fail");
1993 /* Populate the custom packet header field only once for all tests */
1994 ok(!bt_ctf_stream_get_packet_header(NULL
),
1995 "bt_ctf_stream_get_packet_header handles NULL correctly");
1996 packet_header
= bt_ctf_stream_get_packet_header(stream1
);
1998 "bt_ctf_stream_get_packet_header returns a packet header");
1999 ret_field_type
= bt_ctf_field_get_type(packet_header
);
2000 ok(ret_field_type
== packet_header_type
,
2001 "Stream returns a packet header of the appropriate type");
2002 bt_ctf_object_put_ref(ret_field_type
);
2003 packet_header_field
= bt_ctf_field_structure_get_field_by_name(packet_header
,
2004 "custom_trace_packet_header_field");
2005 ok(packet_header_field
,
2006 "Packet header structure contains a custom field with the appropriate name");
2007 ret_field_type
= bt_ctf_field_get_type(packet_header_field
);
2008 ok(!bt_ctf_field_integer_unsigned_set_value(packet_header_field
,
2009 54321), "Set custom packet header value successfully");
2010 ok(bt_ctf_stream_set_packet_header(stream1
, NULL
) < 0,
2011 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
2012 ok(bt_ctf_stream_set_packet_header(NULL
, packet_header
) < 0,
2013 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
2014 ok(bt_ctf_stream_set_packet_header(stream1
, packet_header_field
) < 0,
2015 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
2016 ok(!bt_ctf_stream_set_packet_header(stream1
, packet_header
),
2017 "Successfully set a stream's packet header");
2019 ok(bt_ctf_writer_add_environment_field(writer
, "new_field", "test") == 0,
2020 "Add environment field to writer after stream creation");
2024 test_instanciate_event_before_stream(writer
, clock
);
2026 append_simple_event(stream_class
, stream1
, clock
);
2028 packet_resize_test(stream_class
, stream1
, clock
);
2030 append_complex_event(stream_class
, stream1
, clock
);
2032 append_existing_event_class(stream_class
);
2034 test_empty_stream(writer
);
2036 test_custom_event_header_stream(writer
, clock
);
2038 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
2039 ok(metadata_string
, "Get metadata string");
2041 bt_ctf_writer_flush_metadata(writer
);
2043 bt_ctf_object_put_ref(clock
);
2044 bt_ctf_object_put_ref(ret_stream_class
);
2045 bt_ctf_object_put_ref(writer
);
2046 bt_ctf_object_put_ref(stream1
);
2047 bt_ctf_object_put_ref(packet_context_type
);
2048 bt_ctf_object_put_ref(packet_context_field_type
);
2049 bt_ctf_object_put_ref(integer_type
);
2050 bt_ctf_object_put_ref(stream_event_context_type
);
2051 bt_ctf_object_put_ref(ret_field_type
);
2052 bt_ctf_object_put_ref(packet_header_type
);
2053 bt_ctf_object_put_ref(packet_header_field_type
);
2054 bt_ctf_object_put_ref(packet_header
);
2055 bt_ctf_object_put_ref(packet_header_field
);
2056 bt_ctf_object_put_ref(trace
);
2057 free(metadata_string
);
2058 bt_ctf_object_put_ref(stream_class
);
2060 validate_trace(argv
[1], trace_path
);
2062 recursive_rmdir(trace_path
);
2064 g_free(metadata_path
);
2066 return exit_status();