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"
32 #define METADATA_LINE_SIZE 512
33 #define SEQUENCE_TEST_LENGTH 10
34 #define ARRAY_TEST_LENGTH 5
35 #define PACKET_RESIZE_TEST_DEF_LENGTH 100000
37 #define DEFAULT_CLOCK_FREQ 1000000000
38 #define DEFAULT_CLOCK_PRECISION 1
39 #define DEFAULT_CLOCK_OFFSET 0
40 #define DEFAULT_CLOCK_OFFSET_S 0
41 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
42 #define DEFAULT_CLOCK_TIME 0
43 #define DEFAULT_CLOCK_VALUE 0
48 char sysname
[BABELTRACE_HOST_NAME_MAX
];
49 char nodename
[BABELTRACE_HOST_NAME_MAX
];
50 char release
[BABELTRACE_HOST_NAME_MAX
];
51 char version
[BABELTRACE_HOST_NAME_MAX
];
52 char machine
[BABELTRACE_HOST_NAME_MAX
];
55 static int64_t current_time
= 42;
56 static unsigned int packet_resize_test_length
= PACKET_RESIZE_TEST_DEF_LENGTH
;
58 /* Return 1 if uuids match, zero if different. */
60 int uuid_match(const uint8_t *uuid_a
, const uint8_t *uuid_b
)
65 if (!uuid_a
|| !uuid_b
) {
69 for (i
= 0; i
< 16; i
++) {
70 if (uuid_a
[i
] != uuid_b
[i
]) {
81 void validate_trace(char *parser_path
, char *trace_path
)
85 const char *argv
[] = {parser_path
, trace_path
, "-o", "dummy", NULL
};
87 if (!parser_path
|| !trace_path
) {
92 if (!g_spawn_sync(NULL
,
95 G_SPAWN_STDOUT_TO_DEV_NULL
,
102 diag("Failed to spawn babeltrace.");
107 /* Replace by g_spawn_check_exit_status when we require glib >= 2.34 */
109 ret
= WIFEXITED(exit_status
) ? WEXITSTATUS(exit_status
) : -1;
115 diag("Babeltrace returned an error.");
120 ok(ret
== 0, "Babeltrace could read the resulting trace");
124 void append_simple_event(struct bt_ctf_stream_class
*stream_class
,
125 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
127 /* Create and add a simple event class */
128 struct bt_ctf_event_class
*simple_event_class
=
129 bt_ctf_event_class_create("Simple Event");
130 struct bt_ctf_field_type
*uint_12_type
=
131 bt_ctf_field_type_integer_create(12);
132 struct bt_ctf_field_type
*int_64_type
=
133 bt_ctf_field_type_integer_create(64);
134 struct bt_ctf_field_type
*float_type
=
135 bt_ctf_field_type_floating_point_create();
136 struct bt_ctf_field_type
*enum_type
;
137 struct bt_ctf_field_type
*enum_type_unsigned
=
138 bt_ctf_field_type_enumeration_create(uint_12_type
);
139 struct bt_ctf_field_type
*event_context_type
=
140 bt_ctf_field_type_structure_create();
141 struct bt_ctf_field_type
*event_payload_type
= NULL
;
142 struct bt_ctf_field_type
*returned_type
;
143 struct bt_ctf_event
*simple_event
;
144 struct bt_ctf_field
*integer_field
;
145 struct bt_ctf_field
*float_field
;
146 struct bt_ctf_field
*enum_field
;
147 struct bt_ctf_field
*enum_field_unsigned
;
148 struct bt_ctf_field
*enum_container_field
;
149 const char *mapping_name_test
= "truie";
150 const double double_test_value
= 3.1415;
151 struct bt_ctf_field
*enum_container_field_unsigned
;
152 const char *mapping_name_negative_test
= "negative_value";
153 const char *ret_char
;
155 int64_t ret_range_start_int64_t
, ret_range_end_int64_t
;
156 uint64_t ret_range_start_uint64_t
, ret_range_end_uint64_t
;
157 struct bt_ctf_event_class
*ret_event_class
;
158 struct bt_ctf_field
*packet_context
;
159 struct bt_ctf_field
*packet_context_field
;
160 struct bt_ctf_field
*stream_event_context
;
161 struct bt_ctf_field
*stream_event_context_field
;
162 struct bt_ctf_field
*event_context
;
163 struct bt_ctf_field
*event_context_field
;
164 struct bt_ctf_field_type
*ep_integer_field_type
= NULL
;
165 struct bt_ctf_field_type
*ep_enum_field_type
= NULL
;
166 struct bt_ctf_field_type
*ep_enum_field_unsigned_type
= NULL
;
167 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
170 ok(uint_12_type
, "Create an unsigned integer type");
172 ok(!bt_ctf_field_type_integer_set_signed(int_64_type
, 1),
173 "Set signed 64 bit integer signedness to true");
174 ok(int_64_type
, "Create a signed integer type");
175 enum_type
= bt_ctf_field_type_enumeration_create(int_64_type
);
177 returned_type
= bt_ctf_field_type_enumeration_get_container_field_type(enum_type
);
178 ok(returned_type
== int_64_type
, "bt_ctf_field_type_enumeration_get_container_field_type returns the right type");
179 ok(!bt_ctf_field_type_enumeration_create(enum_type
),
180 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
181 bt_ctf_object_put_ref(returned_type
);
183 bt_ctf_field_type_set_alignment(float_type
, 32);
184 ok(bt_ctf_field_type_get_alignment(float_type
) == 32,
185 "bt_ctf_field_type_get_alignment returns a correct value");
187 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type
, 11) == 0,
188 "Set a floating point type's exponent digit count");
189 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type
, 53) == 0,
190 "Set a floating point type's mantissa digit count");
192 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type
) == 11,
193 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
194 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type
) == 53,
195 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
197 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
198 mapping_name_negative_test
, -12345, 0) == 0,
199 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
200 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
201 "escaping; \"test\"", 1, 1) == 0,
202 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
203 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
204 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
205 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
206 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
207 "event clock int float", 5, 22) == 0,
208 "Accept enumeration mapping strings containing reserved keywords");
209 bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
211 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
212 43, 51) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts duplicate mapping names");
213 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, "something",
214 -500, -400) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts overlapping enum entries");
215 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
216 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
217 bt_ctf_field_type_enumeration_add_mapping(enum_type
, "another entry", -42000, -13000);
219 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type
,
220 "enum_field") == 0, "Add signed enumeration field to event");
222 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, NULL
,
223 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
224 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL string correctly");
225 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, &ret_char
,
226 NULL
, &ret_range_end_int64_t
) == 0,
227 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL start correctly");
228 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 0, &ret_char
,
229 &ret_range_start_int64_t
, NULL
) == 0,
230 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index handles a NULL end correctly");
231 /* Assumes entries are sorted by range_start values. */
232 ok(bt_ctf_field_type_enumeration_signed_get_mapping_by_index(enum_type
, 6, &ret_char
,
233 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
234 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a value");
235 ok(strcmp(ret_char
, mapping_name_test
) == 0,
236 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping name");
237 ok(ret_range_start_int64_t
== 42,
238 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping start");
239 ok(ret_range_end_int64_t
== 42,
240 "bt_ctf_field_type_enumeration_signed_get_mapping_by_index returns a correct mapping end");
242 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
243 "escaping; \"test\"", 0, 0) == 0,
244 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing quotes");
245 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
246 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
247 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing special characters");
248 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
,
249 "event clock int float", 5, 22) == 0,
250 "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts enumeration mapping strings containing reserved keywords");
251 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
252 42, 42) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts single-value ranges");
253 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
254 43, 51) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts duplicate mapping names");
255 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, "something",
256 7, 8) == 0, "bt_ctf_field_type_enumeration_unsigned_add_mapping accepts overlapping enum entries");
257 ok(bt_ctf_field_type_enumeration_unsigned_add_mapping(enum_type_unsigned
, mapping_name_test
,
258 55, 54), "bt_ctf_field_type_enumeration_unsigned_add_mapping rejects mapping where end < start");
259 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type_unsigned
,
260 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
262 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned
) == 6,
263 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
265 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, NULL
,
266 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
267 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL string correctly");
268 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, &ret_char
,
269 NULL
, &ret_range_end_uint64_t
) == 0,
270 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL start correctly");
271 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 0, &ret_char
,
272 &ret_range_start_uint64_t
, NULL
) == 0,
273 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index handles a NULL end correctly");
274 ok(bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(enum_type_unsigned
, 4, &ret_char
,
275 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
276 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a value");
277 ok(strcmp(ret_char
, mapping_name_test
) == 0,
278 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping name");
279 ok(ret_range_start_uint64_t
== 42,
280 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping start");
281 ok(ret_range_end_uint64_t
== 42,
282 "bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index returns a correct mapping end");
284 bt_ctf_event_class_add_field(simple_event_class
, uint_12_type
,
286 bt_ctf_event_class_add_field(simple_event_class
, float_type
,
289 ret
= bt_ctf_event_class_set_id(simple_event_class
, 13);
292 /* Set an event context type which will contain a single integer. */
293 ok(!bt_ctf_field_type_structure_add_field(event_context_type
, uint_12_type
,
294 "event_specific_context"),
295 "Add event specific context field");
297 ok(bt_ctf_event_class_set_context_field_type(NULL
, event_context_type
) < 0,
298 "bt_ctf_event_class_set_context_field_type handles a NULL event class correctly");
299 ok(!bt_ctf_event_class_set_context_field_type(simple_event_class
, event_context_type
),
300 "Set an event class' context type successfully");
301 returned_type
= bt_ctf_event_class_get_context_field_type(simple_event_class
);
302 ok(returned_type
== event_context_type
,
303 "bt_ctf_event_class_get_context_field_type returns the appropriate type");
304 bt_ctf_object_put_ref(returned_type
);
306 ok(!bt_ctf_stream_class_add_event_class(stream_class
, simple_event_class
),
307 "Adding simple event class to stream class");
310 * bt_ctf_stream_class_add_event_class() copies the field types
311 * of simple_event_class, so we retrieve the new ones to create
312 * the appropriate fields.
314 BT_CTF_OBJECT_PUT_REF_AND_RESET(event_context_type
);
315 BT_CTF_OBJECT_PUT_REF_AND_RESET(event_payload_type
);
316 event_payload_type
= bt_ctf_event_class_get_payload_field_type(
318 BT_ASSERT(event_payload_type
);
319 event_context_type
= bt_ctf_event_class_get_context_field_type(
321 BT_ASSERT(event_context_type
);
322 ep_integer_field_type
=
323 bt_ctf_field_type_structure_get_field_type_by_name(
324 event_payload_type
, "integer_field");
325 BT_ASSERT(ep_integer_field_type
);
327 bt_ctf_field_type_structure_get_field_type_by_name(
328 event_payload_type
, "enum_field");
329 BT_ASSERT(ep_enum_field_type
);
330 ep_enum_field_unsigned_type
=
331 bt_ctf_field_type_structure_get_field_type_by_name(
332 event_payload_type
, "enum_field_unsigned");
333 BT_ASSERT(ep_enum_field_unsigned_type
);
335 ok(bt_ctf_stream_class_get_event_class_count(stream_class
) == 1,
336 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
337 ret_event_class
= bt_ctf_stream_class_get_event_class_by_index(stream_class
, 0);
338 ok(ret_event_class
== simple_event_class
,
339 "bt_ctf_stream_class_get_event_class returns the correct event class");
340 bt_ctf_object_put_ref(ret_event_class
);
341 ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class
, 2),
342 "bt_ctf_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
344 bt_ctf_stream_class_get_event_class_by_id(stream_class
, 13);
345 ok(ret_event_class
== simple_event_class
,
346 "bt_ctf_stream_class_get_event_class_by_id returns a correct event class");
347 bt_ctf_object_put_ref(ret_event_class
);
349 simple_event
= bt_ctf_event_create(simple_event_class
);
351 "Instantiate an event containing a single integer field");
353 integer_field
= bt_ctf_field_create(ep_integer_field_type
);
354 bt_ctf_field_integer_unsigned_set_value(integer_field
, 42);
355 ok(bt_ctf_event_set_payload(simple_event
, "integer_field",
356 integer_field
) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
358 float_field
= bt_ctf_event_get_payload(simple_event
, "float_field");
359 bt_ctf_field_floating_point_set_value(float_field
, double_test_value
);
360 ok(!bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
361 "bt_ctf_field_floating_point_get_value returns a double value");
362 ok(fabs(ret_double
- double_test_value
) <= DBL_EPSILON
,
363 "bt_ctf_field_floating_point_get_value returns a correct value");
365 enum_field
= bt_ctf_field_create(ep_enum_field_type
);
366 BT_ASSERT(enum_field
);
368 enum_container_field
= bt_ctf_field_enumeration_get_container(enum_field
);
369 ok(bt_ctf_field_integer_signed_set_value(
370 enum_container_field
, -42) == 0,
371 "Set signed enumeration container value");
372 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field", enum_field
);
374 BT_CTF_OBJECT_PUT_REF_AND_RESET(iter
);
376 enum_field_unsigned
= bt_ctf_field_create(ep_enum_field_unsigned_type
);
377 BT_ASSERT(enum_field_unsigned
);
378 enum_container_field_unsigned
= bt_ctf_field_enumeration_get_container(
379 enum_field_unsigned
);
380 ok(bt_ctf_field_integer_unsigned_set_value(
381 enum_container_field_unsigned
, 42) == 0,
382 "Set unsigned enumeration container value");
383 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field_unsigned",
384 enum_field_unsigned
);
387 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0, "Set clock time");
389 /* Populate stream event context */
390 stream_event_context
=
391 bt_ctf_event_get_stream_event_context(simple_event
);
392 BT_ASSERT(stream_event_context
);
393 stream_event_context_field
= bt_ctf_field_structure_get_field_by_name(
394 stream_event_context
, "common_event_context");
395 bt_ctf_field_integer_unsigned_set_value(stream_event_context_field
, 42);
397 /* Populate the event's context */
398 event_context
= bt_ctf_event_get_context(simple_event
);
400 "bt_ctf_event_get_context returns a field");
401 returned_type
= bt_ctf_field_get_type(event_context
);
402 ok(returned_type
== event_context_type
,
403 "bt_ctf_event_get_context returns a field of the appropriate type");
404 event_context_field
= bt_ctf_field_structure_get_field_by_name(event_context
,
405 "event_specific_context");
406 ok(!bt_ctf_field_integer_unsigned_set_value(event_context_field
, 1234),
407 "Successfully set an event context's value");
408 ok(!bt_ctf_event_set_context(simple_event
, event_context
),
409 "Set an event context successfully");
411 ok(bt_ctf_stream_append_event(stream
, simple_event
) == 0,
412 "Append simple event to trace stream");
414 packet_context
= bt_ctf_stream_get_packet_context(stream
);
416 "bt_ctf_stream_get_packet_context returns a packet context");
418 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
420 ok(packet_context_field
,
421 "Packet context contains the default packet_size field.");
422 bt_ctf_object_put_ref(packet_context_field
);
423 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
424 "custom_packet_context_field");
425 ok(bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 8) == 0,
426 "Custom packet context field value successfully set.");
428 ok(bt_ctf_stream_set_packet_context(stream
, packet_context
) == 0,
429 "Successfully set a stream's packet context");
431 ok(bt_ctf_stream_flush(stream
) == 0,
432 "Flush trace stream with one event");
434 bt_ctf_object_put_ref(simple_event_class
);
435 bt_ctf_object_put_ref(simple_event
);
436 bt_ctf_object_put_ref(uint_12_type
);
437 bt_ctf_object_put_ref(int_64_type
);
438 bt_ctf_object_put_ref(float_type
);
439 bt_ctf_object_put_ref(enum_type
);
440 bt_ctf_object_put_ref(enum_type_unsigned
);
441 bt_ctf_object_put_ref(returned_type
);
442 bt_ctf_object_put_ref(event_context_type
);
443 bt_ctf_object_put_ref(integer_field
);
444 bt_ctf_object_put_ref(float_field
);
445 bt_ctf_object_put_ref(enum_field
);
446 bt_ctf_object_put_ref(enum_field_unsigned
);
447 bt_ctf_object_put_ref(enum_container_field
);
448 bt_ctf_object_put_ref(enum_container_field_unsigned
);
449 bt_ctf_object_put_ref(packet_context
);
450 bt_ctf_object_put_ref(packet_context_field
);
451 bt_ctf_object_put_ref(stream_event_context
);
452 bt_ctf_object_put_ref(stream_event_context_field
);
453 bt_ctf_object_put_ref(event_context
);
454 bt_ctf_object_put_ref(event_context_field
);
455 bt_ctf_object_put_ref(event_payload_type
);
456 bt_ctf_object_put_ref(ep_integer_field_type
);
457 bt_ctf_object_put_ref(ep_enum_field_type
);
458 bt_ctf_object_put_ref(ep_enum_field_unsigned_type
);
459 bt_ctf_object_put_ref(iter
);
463 void append_complex_event(struct bt_ctf_stream_class
*stream_class
,
464 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
467 struct event_class_attrs_counts
;
468 const char *complex_test_event_string
= "Complex Test Event";
469 const char *test_string_1
= "Test ";
470 const char *test_string_2
= "string ";
471 const char *test_string_3
= "abcdefghi";
472 const char *test_string_4
= "abcd\0efg\0hi";
473 const char *test_string_cat
= "Test string abcdeefg";
474 struct bt_ctf_field_type
*uint_35_type
=
475 bt_ctf_field_type_integer_create(35);
476 struct bt_ctf_field_type
*int_16_type
=
477 bt_ctf_field_type_integer_create(16);
478 struct bt_ctf_field_type
*uint_3_type
=
479 bt_ctf_field_type_integer_create(3);
480 struct bt_ctf_field_type
*enum_variant_type
=
481 bt_ctf_field_type_enumeration_create(uint_3_type
);
482 struct bt_ctf_field_type
*variant_type
=
483 bt_ctf_field_type_variant_create(enum_variant_type
,
485 struct bt_ctf_field_type
*string_type
=
486 bt_ctf_field_type_string_create();
487 struct bt_ctf_field_type
*sequence_type
;
488 struct bt_ctf_field_type
*array_type
;
489 struct bt_ctf_field_type
*inner_structure_type
=
490 bt_ctf_field_type_structure_create();
491 struct bt_ctf_field_type
*complex_structure_type
=
492 bt_ctf_field_type_structure_create();
493 struct bt_ctf_field_type
*ret_field_type
;
494 struct bt_ctf_event_class
*event_class
;
495 struct bt_ctf_event
*event
;
496 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
497 *inner_structure_field
, *complex_structure_field
,
498 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
499 *variant_field
, *an_array_field
, *stream_event_ctx_field
,
500 *stream_event_ctx_int_field
;
501 uint64_t ret_unsigned_int
;
502 int64_t ret_signed_int
;
503 const char *ret_string
;
504 struct bt_ctf_stream_class
*ret_stream_class
;
505 struct bt_ctf_event_class
*ret_event_class
;
506 struct bt_ctf_field
*packet_context
, *packet_context_field
;
508 ok(bt_ctf_field_type_set_alignment(int_16_type
, 0),
509 "bt_ctf_field_type_set_alignment handles 0-alignment correctly");
510 ok(bt_ctf_field_type_set_alignment(int_16_type
, 3),
511 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (3)");
512 ok(bt_ctf_field_type_set_alignment(int_16_type
, 24),
513 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (24)");
514 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 4),
515 "bt_ctf_field_type_set_alignment handles correct alignment correctly (4)");
516 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 32),
517 "Set alignment of signed 16 bit integer to 32");
518 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
519 "Set integer signedness to true");
520 ok(!bt_ctf_field_type_integer_set_base(uint_35_type
,
521 BT_CTF_INTEGER_BASE_HEXADECIMAL
),
522 "Set signed 16 bit integer base to hexadecimal");
524 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
525 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
528 ret_field_type
= bt_ctf_field_type_array_get_element_field_type(
530 ok(ret_field_type
== int_16_type
,
531 "bt_ctf_field_type_array_get_element_field_type returns the correct type");
532 bt_ctf_object_put_ref(ret_field_type
);
534 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
535 "bt_ctf_field_type_array_get_length returns the correct length");
537 ok(bt_ctf_field_type_structure_add_field(inner_structure_type
,
538 inner_structure_type
, "yes"), "Cannot add self to structure");
539 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
540 uint_35_type
, "seq_len"), "Add seq_len field to inner structure");
541 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
542 sequence_type
, "a_sequence"), "Add a_sequence field to inner structure");
543 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
544 array_type
, "an_array"), "Add an_array field to inner structure");
546 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
548 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
550 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
551 "UINT35_TYPE", 2, 7);
553 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
554 "An unknown entry"), "Reject a variant field based on an unknown tag value");
555 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
556 "UINT3_TYPE") == 0, "Add a field to a variant");
557 ok(!bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
558 "INT16_TYPE"), "Add INT16_TYPE field to variant");
559 ok(!bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
560 "UINT35_TYPE"), "Add UINT35_TYPE field to variant");
562 ret_field_type
= bt_ctf_field_type_variant_get_tag_field_type(variant_type
);
563 ok(ret_field_type
== enum_variant_type
,
564 "bt_ctf_field_type_variant_get_tag_field_type returns a correct tag type");
565 bt_ctf_object_put_ref(ret_field_type
);
567 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
568 ok(ret_string
? strcmp(ret_string
, "variant_selector") == 0 : 0,
569 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
570 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
571 variant_type
, "INT16_TYPE");
572 ok(ret_field_type
== int_16_type
,
573 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
574 bt_ctf_object_put_ref(ret_field_type
);
576 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
577 "bt_ctf_field_type_variant_get_field_count returns the correct count");
579 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, NULL
, &ret_field_type
, 0) == 0,
580 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
581 bt_ctf_object_put_ref(ret_field_type
);
582 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, &ret_string
, NULL
, 0) == 0,
583 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
584 ok(bt_ctf_field_type_variant_get_field_by_index(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
585 "bt_ctf_field_type_variant_get_field returns a field");
586 ok(strcmp("INT16_TYPE", ret_string
) == 0,
587 "bt_ctf_field_type_variant_get_field returns a correct field name");
588 ok(ret_field_type
== int_16_type
,
589 "bt_ctf_field_type_variant_get_field returns a correct field type");
590 bt_ctf_object_put_ref(ret_field_type
);
592 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
593 enum_variant_type
, "variant_selector"),
594 "Add variant_selector field to complex structure");
595 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
596 string_type
, "string"), "Add `string` field to complex structure");
597 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
598 variant_type
, "variant_value"),
599 "Add variant_value field to complex structure");
600 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
601 inner_structure_type
, "inner_structure"),
602 "Add inner_structure field to complex structure");
604 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
605 ok(event_class
, "Create an event class");
606 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
607 "Reject addition of a field with an empty name to an event");
608 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
609 "Reject addition of a field with a NULL type to an event");
610 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
612 "Reject addition of a type with an illegal name to an event");
613 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
615 "Add field of type unsigned integer to an event");
616 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
617 "int_16") == 0, "Add field of type signed integer to an event");
618 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
619 "complex_structure") == 0,
620 "Add composite structure to an event");
622 ret_string
= bt_ctf_event_class_get_name(event_class
);
623 ok(strcmp(ret_string
, complex_test_event_string
) == 0,
624 "bt_ctf_event_class_get_name returns a correct name");
625 ok(bt_ctf_event_class_get_id(event_class
) < 0,
626 "bt_ctf_event_class_get_id returns a negative value when not set");
627 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
628 "bt_ctf_event_class_set_id handles NULL correctly");
629 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
630 "Set an event class' id");
631 ok(bt_ctf_event_class_get_id(event_class
) == 42,
632 "bt_ctf_event_class_get_id returns the correct value");
634 /* Test event class attributes */
635 ok(bt_ctf_event_class_get_log_level(event_class
) == BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
,
636 "event class has the expected initial log level");
637 ok(!bt_ctf_event_class_get_emf_uri(event_class
),
638 "as expected, event class has no initial EMF URI");
639 ok(bt_ctf_event_class_set_log_level(NULL
, BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
),
640 "bt_ctf_event_class_set_log_level handles a NULL event class correctly");
641 ok(bt_ctf_event_class_set_log_level(event_class
, BT_CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN
),
642 "bt_ctf_event_class_set_log_level handles an unknown log level correctly");
643 ok(!bt_ctf_event_class_set_log_level(event_class
, BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
),
644 "bt_ctf_event_class_set_log_level succeeds with a valid log level");
645 ok(bt_ctf_event_class_get_log_level(event_class
) == BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO
,
646 "bt_ctf_event_class_get_log_level returns the expected log level");
647 ok(bt_ctf_event_class_set_emf_uri(NULL
, "https://babeltrace.org/"),
648 "bt_ctf_event_class_set_emf_uri handles a NULL event class correctly");
649 ok(!bt_ctf_event_class_set_emf_uri(event_class
, "https://babeltrace.org/"),
650 "bt_ctf_event_class_set_emf_uri succeeds with a valid EMF URI");
651 ok(strcmp(bt_ctf_event_class_get_emf_uri(event_class
), "https://babeltrace.org/") == 0,
652 "bt_ctf_event_class_get_emf_uri returns the expected EMF URI");
653 ok(!bt_ctf_event_class_set_emf_uri(event_class
, NULL
),
654 "bt_ctf_event_class_set_emf_uri succeeds with NULL (to reset)");
655 ok(!bt_ctf_event_class_get_emf_uri(event_class
),
656 "as expected, event class has no EMF URI after reset");
658 /* Add event class to the stream class */
659 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
660 "Reject addition of NULL event class to a stream class");
661 ok(bt_ctf_stream_class_add_event_class(stream_class
,
662 event_class
) == 0, "Add an event class to stream class");
664 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
665 ok(ret_stream_class
== stream_class
,
666 "bt_ctf_event_class_get_stream_class returns the correct stream class");
667 bt_ctf_object_put_ref(ret_stream_class
);
669 ok(!bt_ctf_event_class_get_field_by_name(event_class
, "truie"),
670 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
671 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
672 "complex_structure");
673 bt_ctf_object_put_ref(ret_field_type
);
675 event
= bt_ctf_event_create(event_class
);
676 ok(event
, "Instanciate a complex event");
678 ret_event_class
= bt_ctf_event_get_class(event
);
679 ok(ret_event_class
== event_class
,
680 "bt_ctf_event_get_class returns the correct event class");
681 bt_ctf_object_put_ref(ret_event_class
);
683 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
684 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
685 bt_ctf_field_integer_unsigned_set_value(uint_35_field
, 0x0DDF00D);
686 ok(bt_ctf_field_integer_unsigned_get_value(uint_35_field
,
687 &ret_unsigned_int
) == 0,
688 "bt_ctf_field_integer_unsigned_get_value succeeds after setting a value");
689 ok(ret_unsigned_int
== 0x0DDF00D,
690 "bt_ctf_field_integer_unsigned_get_value returns the correct value");
691 bt_ctf_object_put_ref(uint_35_field
);
693 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
694 bt_ctf_field_integer_signed_set_value(int_16_field
, -12345);
695 ok(bt_ctf_field_integer_signed_get_value(int_16_field
,
696 &ret_signed_int
) == 0,
697 "bt_ctf_field_integer_signed_get_value succeeds after setting a value");
698 ok(ret_signed_int
== -12345,
699 "bt_ctf_field_integer_signed_get_value returns the correct value");
700 bt_ctf_object_put_ref(int_16_field
);
702 complex_structure_field
= bt_ctf_event_get_payload(event
,
703 "complex_structure");
705 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
706 complex_structure_field
, 3);
707 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
708 bt_ctf_object_put_ref(inner_structure_field
);
709 bt_ctf_object_put_ref(ret_field_type
);
711 inner_structure_field
= bt_ctf_field_structure_get_field_by_name(
712 complex_structure_field
, "inner_structure");
713 a_string_field
= bt_ctf_field_structure_get_field_by_name(
714 complex_structure_field
, "string");
715 enum_variant_field
= bt_ctf_field_structure_get_field_by_name(
716 complex_structure_field
, "variant_selector");
717 variant_field
= bt_ctf_field_structure_get_field_by_name(
718 complex_structure_field
, "variant_value");
719 uint_35_field
= bt_ctf_field_structure_get_field_by_name(
720 inner_structure_field
, "seq_len");
721 a_sequence_field
= bt_ctf_field_structure_get_field_by_name(
722 inner_structure_field
, "a_sequence");
723 an_array_field
= bt_ctf_field_structure_get_field_by_name(
724 inner_structure_field
, "an_array");
726 enum_container_field
= bt_ctf_field_enumeration_get_container(
728 bt_ctf_field_integer_unsigned_set_value(enum_container_field
, 1);
729 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
731 bt_ctf_field_integer_signed_set_value(int_16_field
, -200);
732 bt_ctf_object_put_ref(int_16_field
);
733 bt_ctf_field_string_set_value(a_string_field
,
735 ok(!bt_ctf_field_string_append(a_string_field
, test_string_2
),
736 "bt_ctf_field_string_append succeeds");
737 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 5),
738 "bt_ctf_field_string_append_len succeeds (append 5 characters)");
739 ok(!bt_ctf_field_string_append_len(a_string_field
, &test_string_4
[5], 3),
740 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
741 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 0),
742 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
744 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
745 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
746 ok(ret_string
? strcmp(ret_string
, test_string_cat
) == 0 : 0,
747 "bt_ctf_field_string_get_value returns a correct value");
748 bt_ctf_field_integer_unsigned_set_value(uint_35_field
,
749 SEQUENCE_TEST_LENGTH
);
751 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
752 variant_type
, enum_variant_field
);
753 ok(ret_field_type
== int_16_type
,
754 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
756 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
757 uint_35_field
) == 0, "Set a sequence field's length");
759 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
760 int_16_field
= bt_ctf_field_sequence_get_field(
761 a_sequence_field
, i
);
762 bt_ctf_field_integer_signed_set_value(int_16_field
, 4 - i
);
763 bt_ctf_object_put_ref(int_16_field
);
766 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
767 int_16_field
= bt_ctf_field_array_get_field(
769 bt_ctf_field_integer_signed_set_value(int_16_field
, i
);
770 bt_ctf_object_put_ref(int_16_field
);
773 stream_event_ctx_field
= bt_ctf_event_get_stream_event_context(event
);
774 BT_ASSERT(stream_event_ctx_field
);
775 stream_event_ctx_int_field
= bt_ctf_field_structure_get_field_by_name(
776 stream_event_ctx_field
, "common_event_context");
777 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_field
);
778 bt_ctf_field_integer_unsigned_set_value(stream_event_ctx_int_field
, 17);
779 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_ctx_int_field
);
781 bt_ctf_clock_set_time(clock
, ++current_time
);
782 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
783 "Append a complex event to a stream");
786 * Populate the custom packet context field with a dummy value
787 * otherwise flush will fail.
789 packet_context
= bt_ctf_stream_get_packet_context(stream
);
790 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
791 "custom_packet_context_field");
792 bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 1);
794 ok(bt_ctf_stream_flush(stream
) == 0,
795 "Flush a stream containing a complex event");
797 bt_ctf_object_put_ref(uint_35_field
);
798 bt_ctf_object_put_ref(a_string_field
);
799 bt_ctf_object_put_ref(inner_structure_field
);
800 bt_ctf_object_put_ref(complex_structure_field
);
801 bt_ctf_object_put_ref(a_sequence_field
);
802 bt_ctf_object_put_ref(an_array_field
);
803 bt_ctf_object_put_ref(enum_variant_field
);
804 bt_ctf_object_put_ref(enum_container_field
);
805 bt_ctf_object_put_ref(variant_field
);
806 bt_ctf_object_put_ref(packet_context_field
);
807 bt_ctf_object_put_ref(packet_context
);
808 bt_ctf_object_put_ref(uint_35_type
);
809 bt_ctf_object_put_ref(int_16_type
);
810 bt_ctf_object_put_ref(string_type
);
811 bt_ctf_object_put_ref(sequence_type
);
812 bt_ctf_object_put_ref(array_type
);
813 bt_ctf_object_put_ref(inner_structure_type
);
814 bt_ctf_object_put_ref(complex_structure_type
);
815 bt_ctf_object_put_ref(uint_3_type
);
816 bt_ctf_object_put_ref(enum_variant_type
);
817 bt_ctf_object_put_ref(variant_type
);
818 bt_ctf_object_put_ref(ret_field_type
);
819 bt_ctf_object_put_ref(event_class
);
820 bt_ctf_object_put_ref(event
);
824 void type_field_tests(void)
826 struct bt_ctf_field
*uint_12
;
827 struct bt_ctf_field
*int_16
;
828 struct bt_ctf_field
*string
;
829 struct bt_ctf_field_type
*composite_structure_type
;
830 struct bt_ctf_field_type
*structure_seq_type
;
831 struct bt_ctf_field_type
*string_type
;
832 struct bt_ctf_field_type
*sequence_type
;
833 struct bt_ctf_field_type
*uint_8_type
;
834 struct bt_ctf_field_type
*int_16_type
;
835 struct bt_ctf_field_type
*uint_12_type
=
836 bt_ctf_field_type_integer_create(12);
837 struct bt_ctf_field_type
*enumeration_type
;
838 struct bt_ctf_field_type
*returned_type
;
839 const char *ret_string
;
841 ok(uint_12_type
, "Create an unsigned integer type");
842 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
843 BT_CTF_INTEGER_BASE_BINARY
) == 0,
844 "Set integer type's base as binary");
845 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
846 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
847 "Set integer type's base as decimal");
848 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
849 BT_CTF_INTEGER_BASE_UNKNOWN
),
850 "Reject integer type's base set as unknown");
851 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
852 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
853 "Set integer type's base as octal");
854 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
855 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
856 "Set integer type's base as hexadecimal");
857 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
858 "Reject unknown integer base value");
859 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
860 "Set integer type signedness to signed");
861 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
862 "Set integer type signedness to unsigned");
863 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
864 "bt_ctf_field_type_integer_get_size returns a correct value");
865 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
866 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
868 ok(bt_ctf_field_type_set_byte_order(NULL
,
869 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
870 "bt_ctf_field_type_set_byte_order handles NULL correctly");
871 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
872 (enum bt_ctf_byte_order
) 42) < 0,
873 "bt_ctf_field_type_set_byte_order rejects invalid values");
874 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
875 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
876 "Set an integer's byte order to little endian");
877 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
878 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
879 "Set an integer's byte order to big endian");
880 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
881 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
882 "bt_ctf_field_type_get_byte_order returns a correct value");
884 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
885 BT_CTF_FIELD_TYPE_ID_INTEGER
,
886 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
888 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
889 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
890 "bt_ctf_field_type_integer_get_base returns a correct value");
892 ok(bt_ctf_field_type_integer_set_encoding(NULL
,
893 BT_CTF_STRING_ENCODING_ASCII
) < 0,
894 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
895 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
896 (enum bt_ctf_string_encoding
) 123) < 0,
897 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
898 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
899 BT_CTF_STRING_ENCODING_UTF8
) == 0,
900 "Set integer type encoding to UTF8");
901 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) ==
902 BT_CTF_STRING_ENCODING_UTF8
,
903 "bt_ctf_field_type_integer_get_encoding returns a correct value");
905 int_16_type
= bt_ctf_field_type_integer_create(16);
906 BT_ASSERT(int_16_type
);
907 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
908 "Set signedness of 16 bit integer to true");
909 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
910 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
911 uint_8_type
= bt_ctf_field_type_integer_create(8);
913 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
914 ok(sequence_type
, "Create a sequence of int16_t type");
915 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
916 BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
917 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
919 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
921 ok(strcmp(ret_string
, "seq_len") == 0,
922 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
923 returned_type
= bt_ctf_field_type_sequence_get_element_field_type(
925 ok(returned_type
== int_16_type
,
926 "bt_ctf_field_type_sequence_get_element_field_type returns the correct type");
927 bt_ctf_object_put_ref(returned_type
);
929 string_type
= bt_ctf_field_type_string_create();
930 ok(string_type
, "Create a string type");
931 ok(bt_ctf_field_type_string_set_encoding(string_type
,
932 BT_CTF_STRING_ENCODING_NONE
),
933 "Reject invalid \"None\" string encoding");
934 ok(bt_ctf_field_type_string_set_encoding(string_type
,
936 "Reject invalid string encoding");
937 ok(bt_ctf_field_type_string_set_encoding(string_type
,
938 BT_CTF_STRING_ENCODING_ASCII
) == 0,
939 "Set string encoding to ASCII");
941 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
942 BT_CTF_STRING_ENCODING_ASCII
,
943 "bt_ctf_field_type_string_get_encoding returns the correct value");
945 structure_seq_type
= bt_ctf_field_type_structure_create();
946 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
947 BT_CTF_FIELD_TYPE_ID_STRUCT
,
948 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
949 ok(structure_seq_type
, "Create a structure type");
950 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
951 uint_8_type
, "seq_len") == 0,
952 "Add a uint8_t type to a structure");
953 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
954 sequence_type
, "a_sequence") == 0,
955 "Add a sequence type to a structure");
957 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
958 "bt_ctf_field_type_structure_get_field_count returns a correct value");
960 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
961 NULL
, &returned_type
, 1) == 0,
962 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
963 bt_ctf_object_put_ref(returned_type
);
964 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
965 &ret_string
, NULL
, 1) == 0,
966 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
967 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
968 &ret_string
, &returned_type
, 1) == 0,
969 "bt_ctf_field_type_structure_get_field returns a field");
970 ok(strcmp(ret_string
, "a_sequence") == 0,
971 "bt_ctf_field_type_structure_get_field returns a correct field name");
972 ok(returned_type
== sequence_type
,
973 "bt_ctf_field_type_structure_get_field returns a correct field type");
974 bt_ctf_object_put_ref(returned_type
);
976 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
977 structure_seq_type
, "a_sequence");
978 ok(returned_type
== sequence_type
,
979 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
980 bt_ctf_object_put_ref(returned_type
);
982 composite_structure_type
= bt_ctf_field_type_structure_create();
983 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
984 string_type
, "a_string") == 0,
985 "Add a string type to a structure");
986 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
987 structure_seq_type
, "inner_structure") == 0,
988 "Add a structure type to a structure");
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 a correct type");
994 bt_ctf_object_put_ref(returned_type
);
996 int_16
= bt_ctf_field_create(int_16_type
);
997 ok(int_16
, "Instanciate a signed 16-bit integer");
998 uint_12
= bt_ctf_field_create(uint_12_type
);
999 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1000 returned_type
= bt_ctf_field_get_type(int_16
);
1001 ok(returned_type
== int_16_type
,
1002 "bt_ctf_field_get_type returns the correct type");
1004 /* Can't modify types after instanciating them */
1005 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1006 BT_CTF_INTEGER_BASE_DECIMAL
),
1007 "Check an integer type' base can't be modified after instanciation");
1008 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1009 "Check an integer type's signedness can't be modified after instanciation");
1011 /* Check overflows are properly tested for */
1012 ok(bt_ctf_field_integer_signed_set_value(int_16
, -32768) == 0,
1013 "Check -32768 is allowed for a signed 16-bit integer");
1014 ok(bt_ctf_field_integer_signed_set_value(int_16
, 32767) == 0,
1015 "Check 32767 is allowed for a signed 16-bit integer");
1016 ok(bt_ctf_field_integer_signed_set_value(int_16
, -42) == 0,
1017 "Check -42 is allowed for a signed 16-bit integer");
1019 ok(bt_ctf_field_integer_unsigned_set_value(uint_12
, 4095) == 0,
1020 "Check 4095 is allowed for an unsigned 12-bit integer");
1021 ok(bt_ctf_field_integer_unsigned_set_value(uint_12
, 0) == 0,
1022 "Check 0 is allowed for an unsigned 12-bit integer");
1024 string
= bt_ctf_field_create(string_type
);
1025 ok(string
, "Instanciate a string field");
1026 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1027 "Set a string's value");
1029 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1030 ok(enumeration_type
,
1031 "Create an enumeration type with an unsigned 12-bit integer as container");
1033 bt_ctf_object_put_ref(string
);
1034 bt_ctf_object_put_ref(uint_12
);
1035 bt_ctf_object_put_ref(int_16
);
1036 bt_ctf_object_put_ref(composite_structure_type
);
1037 bt_ctf_object_put_ref(structure_seq_type
);
1038 bt_ctf_object_put_ref(string_type
);
1039 bt_ctf_object_put_ref(sequence_type
);
1040 bt_ctf_object_put_ref(uint_8_type
);
1041 bt_ctf_object_put_ref(int_16_type
);
1042 bt_ctf_object_put_ref(uint_12_type
);
1043 bt_ctf_object_put_ref(enumeration_type
);
1044 bt_ctf_object_put_ref(returned_type
);
1048 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
1049 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
1052 * Append enough events to force the underlying packet to be resized.
1053 * Also tests that a new event can be declared after a stream has been
1054 * instantiated and used/flushed.
1058 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
1060 struct bt_ctf_field_type
*integer_type
=
1061 bt_ctf_field_type_integer_create(17);
1062 struct bt_ctf_field_type
*string_type
=
1063 bt_ctf_field_type_string_create();
1064 struct bt_ctf_event
*event
= NULL
;
1065 struct bt_ctf_field
*ret_field
= NULL
;
1066 struct bt_ctf_field_type
*ret_field_type
= NULL
;
1067 uint64_t ret_uint64
;
1068 int events_appended
= 0;
1069 struct bt_ctf_field
*packet_context
= NULL
,
1070 *packet_context_field
= NULL
, *stream_event_context
= NULL
;
1071 struct bt_ctf_field_type
*ep_field_1_type
= NULL
;
1072 struct bt_ctf_field_type
*ep_a_string_type
= NULL
;
1073 struct bt_ctf_field_type
*ep_type
= NULL
;
1075 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
1077 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
1079 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1080 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
1086 * bt_ctf_stream_class_add_event_class() copies the field types
1087 * of event_class, so we retrieve the new ones to create the
1088 * appropriate fields.
1090 ep_type
= bt_ctf_event_class_get_payload_field_type(event_class
);
1092 ep_field_1_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1093 ep_type
, "field_1");
1094 BT_ASSERT(ep_field_1_type
);
1095 ep_a_string_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1096 ep_type
, "a_string");
1097 BT_ASSERT(ep_a_string_type
);
1099 event
= bt_ctf_event_create(event_class
);
1100 ret_field
= bt_ctf_event_get_payload(event
, 0);
1101 ret_field_type
= bt_ctf_field_get_type(ret_field
);
1102 bt_ctf_object_put_ref(ret_field_type
);
1103 bt_ctf_object_put_ref(ret_field
);
1104 bt_ctf_object_put_ref(event
);
1106 for (i
= 0; i
< packet_resize_test_length
; i
++) {
1107 event
= bt_ctf_event_create(event_class
);
1108 struct bt_ctf_field
*integer
=
1109 bt_ctf_field_create(ep_field_1_type
);
1110 struct bt_ctf_field
*string
=
1111 bt_ctf_field_create(ep_a_string_type
);
1113 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
1114 ret
|= bt_ctf_field_integer_unsigned_set_value(integer
, i
);
1115 ret
|= bt_ctf_event_set_payload(event
, "field_1",
1117 bt_ctf_object_put_ref(integer
);
1118 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
1119 ret
|= bt_ctf_event_set_payload(event
, "a_string",
1121 bt_ctf_object_put_ref(string
);
1123 /* Populate stream event context */
1124 stream_event_context
=
1125 bt_ctf_event_get_stream_event_context(event
);
1126 integer
= bt_ctf_field_structure_get_field_by_name(stream_event_context
,
1127 "common_event_context");
1128 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_context
);
1129 ret
|= bt_ctf_field_integer_unsigned_set_value(integer
,
1131 bt_ctf_object_put_ref(integer
);
1133 ret
|= bt_ctf_stream_append_event(stream
, event
);
1134 bt_ctf_object_put_ref(event
);
1141 events_appended
= !!(i
== packet_resize_test_length
);
1142 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1143 ok(ret
== 0 && ret_uint64
== 0,
1144 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1145 bt_ctf_stream_append_discarded_events(stream
, 1000);
1146 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1147 ok(ret
== 0 && ret_uint64
== 1000,
1148 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1151 ok(events_appended
, "Append 100 000 events to a stream");
1154 * Populate the custom packet context field with a dummy value
1155 * otherwise flush will fail.
1157 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1158 packet_context_field
= bt_ctf_field_structure_get_field_by_name(packet_context
,
1159 "custom_packet_context_field");
1160 bt_ctf_field_integer_unsigned_set_value(packet_context_field
, 2);
1162 ok(bt_ctf_stream_flush(stream
) == 0,
1163 "Flush a stream that forces a packet resize");
1164 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1165 ok(ret
== 0 && ret_uint64
== 1000,
1166 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1167 bt_ctf_object_put_ref(integer_type
);
1168 bt_ctf_object_put_ref(string_type
);
1169 bt_ctf_object_put_ref(packet_context
);
1170 bt_ctf_object_put_ref(packet_context_field
);
1171 bt_ctf_object_put_ref(stream_event_context
);
1172 bt_ctf_object_put_ref(event_class
);
1173 bt_ctf_object_put_ref(ep_field_1_type
);
1174 bt_ctf_object_put_ref(ep_a_string_type
);
1175 bt_ctf_object_put_ref(ep_type
);
1179 void test_empty_stream(struct bt_ctf_writer
*writer
)
1182 struct bt_ctf_trace
*trace
= NULL
, *ret_trace
= NULL
;
1183 struct bt_ctf_stream_class
*stream_class
= NULL
;
1184 struct bt_ctf_stream
*stream
= NULL
;
1186 trace
= bt_ctf_writer_get_trace(writer
);
1188 diag("Failed to get trace from writer");
1193 stream_class
= bt_ctf_stream_class_create("empty_stream");
1194 if (!stream_class
) {
1195 diag("Failed to create stream class");
1200 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
1201 BT_ASSERT(ret
== 0);
1202 ret
= bt_ctf_stream_class_set_event_header_type(stream_class
, NULL
);
1203 BT_ASSERT(ret
== 0);
1205 ok(!bt_ctf_stream_class_get_trace(stream_class
),
1206 "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned");
1208 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1210 diag("Failed to create writer stream");
1215 ret_trace
= bt_ctf_stream_class_get_trace(stream_class
);
1216 ok(ret_trace
== trace
,
1217 "bt_ctf_stream_class_get_trace returns the correct trace after a stream has been created");
1220 "Created a stream class with default attributes and an empty stream");
1221 bt_ctf_object_put_ref(trace
);
1222 bt_ctf_object_put_ref(ret_trace
);
1223 bt_ctf_object_put_ref(stream
);
1224 bt_ctf_object_put_ref(stream_class
);
1228 void test_custom_event_header_stream(struct bt_ctf_writer
*writer
,
1229 struct bt_ctf_clock
*clock
)
1232 struct bt_ctf_stream_class
*stream_class
= NULL
;
1233 struct bt_ctf_stream
*stream
= NULL
;
1234 struct bt_ctf_field_type
*integer_type
= NULL
,
1235 *sequence_type
= NULL
, *event_header_type
= NULL
;
1236 struct bt_ctf_field
*integer
= NULL
, *sequence
= NULL
,
1237 *event_header
= NULL
, *packet_header
= NULL
;
1238 struct bt_ctf_event_class
*event_class
= NULL
;
1239 struct bt_ctf_event
*event
= NULL
;
1241 stream_class
= bt_ctf_stream_class_create("custom_event_header_stream");
1242 if (!stream_class
) {
1243 fail("Failed to create stream class");
1247 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1249 fail("Failed to set stream class clock");
1254 * Customize event header to add an "seq_len" integer member
1255 * which will be used as the length of a sequence in an event of this
1258 event_header_type
= bt_ctf_stream_class_get_event_header_type(
1260 if (!event_header_type
) {
1261 fail("Failed to get event header type");
1265 integer_type
= bt_ctf_field_type_integer_create(13);
1266 if (!integer_type
) {
1267 fail("Failed to create length integer type");
1271 ret
= bt_ctf_field_type_structure_add_field(event_header_type
,
1272 integer_type
, "seq_len");
1274 fail("Failed to add a new field to stream event header");
1278 event_class
= bt_ctf_event_class_create("sequence_event");
1280 fail("Failed to create event class");
1285 * This event's payload will contain a sequence which references
1286 * stream.event.header.seq_len as its length field.
1288 sequence_type
= bt_ctf_field_type_sequence_create(integer_type
,
1289 "stream.event.header.seq_len");
1290 if (!sequence_type
) {
1291 fail("Failed to create a sequence");
1295 ret
= bt_ctf_event_class_add_field(event_class
, sequence_type
,
1298 fail("Failed to add a sequence to an event class");
1302 ret
= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1304 fail("Failed to add event class to stream class");
1308 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1310 fail("Failed to create stream")
1315 * We have defined a custom packet header field. We have to populate it
1318 packet_header
= bt_ctf_stream_get_packet_header(stream
);
1319 if (!packet_header
) {
1320 fail("Failed to get stream packet header");
1324 integer
= bt_ctf_field_structure_get_field_by_name(packet_header
,
1325 "custom_trace_packet_header_field");
1327 fail("Failed to retrieve custom_trace_packet_header_field");
1331 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 3487);
1333 fail("Failed to set custom_trace_packet_header_field value");
1336 bt_ctf_object_put_ref(integer
);
1338 event
= bt_ctf_event_create(event_class
);
1340 fail("Failed to create event");
1344 event_header
= bt_ctf_event_get_header(event
);
1345 if (!event_header
) {
1346 fail("Failed to get event header");
1350 integer
= bt_ctf_field_structure_get_field_by_name(event_header
,
1353 fail("Failed to get seq_len field from event header");
1357 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 2);
1359 fail("Failed to set seq_len value in event header");
1363 /* Populate both sequence integer fields */
1364 sequence
= bt_ctf_event_get_payload(event
, "some_sequence");
1366 fail("Failed to retrieve sequence from event");
1370 ret
= bt_ctf_field_sequence_set_length(sequence
, integer
);
1372 fail("Failed to set sequence length");
1375 bt_ctf_object_put_ref(integer
);
1377 for (i
= 0; i
< 2; i
++) {
1378 integer
= bt_ctf_field_sequence_get_field(sequence
, i
);
1380 fail("Failed to retrieve sequence element");
1384 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, i
);
1386 fail("Failed to set sequence element value");
1390 bt_ctf_object_put_ref(integer
);
1394 ret
= bt_ctf_stream_append_event(stream
, event
);
1396 fail("Failed to append event to stream");
1400 ret
= bt_ctf_stream_flush(stream
);
1402 fail("Failed to flush custom_event_header stream");
1405 bt_ctf_object_put_ref(stream
);
1406 bt_ctf_object_put_ref(stream_class
);
1407 bt_ctf_object_put_ref(event_class
);
1408 bt_ctf_object_put_ref(event
);
1409 bt_ctf_object_put_ref(integer
);
1410 bt_ctf_object_put_ref(sequence
);
1411 bt_ctf_object_put_ref(event_header
);
1412 bt_ctf_object_put_ref(packet_header
);
1413 bt_ctf_object_put_ref(sequence_type
);
1414 bt_ctf_object_put_ref(integer_type
);
1415 bt_ctf_object_put_ref(event_header_type
);
1419 void test_instanciate_event_before_stream(struct bt_ctf_writer
*writer
,
1420 struct bt_ctf_clock
*clock
)
1423 struct bt_ctf_stream_class
*stream_class
= NULL
;
1424 struct bt_ctf_stream
*stream
= NULL
,
1426 struct bt_ctf_event_class
*event_class
= NULL
;
1427 struct bt_ctf_event
*event
= NULL
;
1428 struct bt_ctf_field_type
*integer_type
= NULL
;
1429 struct bt_ctf_field
*payload_field
= NULL
;
1430 struct bt_ctf_field
*integer
= NULL
;
1432 stream_class
= bt_ctf_stream_class_create("event_before_stream_test");
1433 if (!stream_class
) {
1434 diag("Failed to create stream class");
1439 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1441 diag("Failed to set stream class clock");
1445 event_class
= bt_ctf_event_class_create("some_event_class_name");
1446 integer_type
= bt_ctf_field_type_integer_create(32);
1447 if (!integer_type
) {
1448 diag("Failed to create integer field type");
1453 ret
= bt_ctf_event_class_add_field(event_class
, integer_type
,
1456 diag("Failed to add field to event class");
1460 ret
= bt_ctf_stream_class_add_event_class(stream_class
,
1463 diag("Failed to add event class to stream class");
1466 event
= bt_ctf_event_create(event_class
);
1468 diag("Failed to create event");
1473 payload_field
= bt_ctf_event_get_payload_field(event
);
1474 if (!payload_field
) {
1475 diag("Failed to get event's payload field");
1480 integer
= bt_ctf_field_structure_get_field_by_index(payload_field
, 0);
1482 diag("Failed to get integer field payload from event");
1487 ret
= bt_ctf_field_integer_unsigned_set_value(integer
, 1234);
1489 diag("Failed to set integer field value");
1493 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1495 diag("Failed to create writer stream");
1500 ret
= bt_ctf_stream_append_event(stream
, event
);
1502 diag("Failed to append event to stream");
1506 ret_stream
= bt_ctf_event_get_stream(event
);
1507 ok(ret_stream
== stream
,
1508 "bt_ctf_event_get_stream returns an event's stream after it has been appended");
1511 "Create an event before instanciating its associated stream");
1512 bt_ctf_object_put_ref(stream
);
1513 bt_ctf_object_put_ref(ret_stream
);
1514 bt_ctf_object_put_ref(stream_class
);
1515 bt_ctf_object_put_ref(event_class
);
1516 bt_ctf_object_put_ref(event
);
1517 bt_ctf_object_put_ref(integer_type
);
1518 bt_ctf_object_put_ref(integer
);
1519 bt_ctf_object_put_ref(payload_field
);
1523 void append_existing_event_class(struct bt_ctf_stream_class
*stream_class
)
1526 struct bt_ctf_event_class
*event_class
;
1528 event_class
= bt_ctf_event_class_create("Simple Event");
1529 BT_ASSERT(event_class
);
1530 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
) == 0,
1531 "two event classes with the same name may cohabit within the same stream class");
1532 bt_ctf_object_put_ref(event_class
);
1534 event_class
= bt_ctf_event_class_create("different name, ok");
1535 BT_ASSERT(event_class
);
1536 ret
= bt_ctf_event_class_set_id(event_class
, 13);
1537 BT_ASSERT(ret
== 0);
1538 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
1539 "two event classes with the same ID cannot cohabit within the same stream class");
1540 bt_ctf_object_put_ref(event_class
);
1544 void test_clock_utils(void)
1547 struct bt_ctf_clock
*clock
= NULL
;
1549 clock
= bt_ctf_clock_create("water");
1551 ret
= bt_ctf_clock_set_offset_s(clock
, 1234);
1553 ret
= bt_ctf_clock_set_offset(clock
, 1000);
1555 ret
= bt_ctf_clock_set_frequency(clock
, 1000000000);
1557 ret
= bt_ctf_clock_set_frequency(clock
, 1534);
1560 BT_CTF_OBJECT_PUT_REF_AND_RESET(clock
);
1563 int main(int argc
, char **argv
)
1565 const char *env_resize_length
;
1567 gchar
*metadata_path
;
1568 const char *clock_name
= "test_clock";
1569 const char *clock_description
= "This is a test clock";
1570 const char *returned_clock_name
;
1571 const char *returned_clock_description
;
1572 const uint64_t frequency
= 1123456789;
1573 const int64_t offset_s
= 13515309;
1574 const int64_t offset
= 1234567;
1575 int64_t get_offset_s
,
1577 const uint64_t precision
= 10;
1578 const int is_absolute
= 0xFF;
1579 char *metadata_string
;
1580 struct bt_ctf_writer
*writer
;
1581 struct bt_utsname name
= {"GNU/Linux", "testhost", "4.4.0-87-generic",
1582 "#110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017", "x86_64"};
1583 struct bt_ctf_clock
*clock
, *ret_clock
;
1584 struct bt_ctf_stream_class
*stream_class
, *ret_stream_class
;
1585 struct bt_ctf_stream
*stream1
;
1586 struct bt_ctf_stream
*stream
;
1587 const char *ret_string
;
1588 const uint8_t *ret_uuid
;
1589 bt_uuid_t tmp_uuid
= { 0 };
1590 struct bt_ctf_field_type
*packet_context_type
,
1591 *packet_context_field_type
,
1592 *packet_header_type
,
1593 *packet_header_field_type
,
1595 *stream_event_context_type
,
1597 *event_header_field_type
;
1598 struct bt_ctf_field
*packet_header
, *packet_header_field
;
1599 struct bt_ctf_trace
*trace
;
1603 printf("Usage: tests-ctf-writer path_to_babeltrace\n");
1607 env_resize_length
= getenv("PACKET_RESIZE_TEST_LENGTH");
1608 if (env_resize_length
) {
1609 packet_resize_test_length
=
1610 (unsigned int) atoi(env_resize_length
);
1613 plan_tests(NR_TESTS
);
1615 trace_path
= g_build_filename(g_get_tmp_dir(), "ctfwriter_XXXXXX", NULL
);
1616 if (!bt_mkdtemp(trace_path
)) {
1620 metadata_path
= g_build_filename(trace_path
, "metadata", NULL
);
1622 writer
= bt_ctf_writer_create(trace_path
);
1623 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
1625 ok(!bt_ctf_writer_get_trace(NULL
),
1626 "bt_ctf_writer_get_trace correctly handles NULL");
1627 trace
= bt_ctf_writer_get_trace(writer
);
1628 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
),
1629 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NATIVE");
1630 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_UNSPECIFIED
),
1631 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_UNSPECIFIED");
1633 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1634 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1635 "Set a trace's byte order to big endian");
1636 ok(bt_ctf_trace_get_native_byte_order(trace
) == BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1637 "bt_ctf_trace_get_native_byte_order returns a correct endianness");
1639 /* Add environment context to the trace */
1640 ok(bt_ctf_writer_add_environment_field(writer
, "host", name
.nodename
) == 0,
1641 "Add host (%s) environment field to writer instance",
1643 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
1645 "bt_ctf_writer_add_environment_field error with NULL writer");
1646 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
1648 "bt_ctf_writer_add_environment_field error with NULL field name");
1649 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
1651 "bt_ctf_writer_add_environment_field error with NULL field value");
1653 /* Test bt_ctf_trace_set_environment_field_integer */
1654 ok(bt_ctf_trace_set_environment_field_integer(NULL
, "test_env_int",
1656 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
1657 ok(bt_ctf_trace_set_environment_field_integer(trace
, NULL
, -194875),
1658 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
1659 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1661 "bt_ctf_trace_set_environment_field_integer succeeds");
1663 /* Test bt_ctf_trace_set_environment_field_string */
1664 ok(bt_ctf_trace_set_environment_field_string(NULL
, "test_env_str",
1666 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
1667 ok(bt_ctf_trace_set_environment_field_string(trace
, NULL
, "yeah"),
1668 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
1669 ok(bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1671 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
1672 ok(!bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1674 "bt_ctf_trace_set_environment_field_string succeeds");
1676 /* Test environment field replacement */
1677 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1679 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
1681 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
1682 == 0, "Add sysname (%s) environment field to writer instance",
1684 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
1685 name
.nodename
) == 0,
1686 "Add nodename (%s) environment field to writer instance",
1688 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
1689 == 0, "Add release (%s) environment field to writer instance",
1691 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
1692 == 0, "Add version (%s) environment field to writer instance",
1694 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
1695 == 0, "Add machine (%s) environment field to writer istance",
1698 /* Define a clock and add it to the trace */
1699 ok(!bt_ctf_clock_create("signed"),
1700 "Illegal clock name rejected");
1701 clock
= bt_ctf_clock_create(clock_name
);
1702 ok(clock
, "Clock created sucessfully");
1703 returned_clock_name
= bt_ctf_clock_get_name(clock
);
1704 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
1705 ok(returned_clock_name
? strcmp(returned_clock_name
, clock_name
) == 0 : 0,
1706 "Returned clock name is valid");
1708 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1709 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
1710 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
1711 "Clock description set successfully");
1713 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1714 ok(returned_clock_description
,
1715 "bt_ctf_clock_get_description returns a description.");
1716 ok(returned_clock_description
?
1717 strcmp(returned_clock_description
, clock_description
) == 0 : 0,
1718 "Returned clock description is valid");
1720 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
1721 "bt_ctf_clock_get_frequency returns the correct default frequency");
1722 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
1723 "Set clock frequency");
1724 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
1725 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
1727 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
1728 "bt_ctf_clock_get_offset_s succeeds");
1729 ok(get_offset_s
== DEFAULT_CLOCK_OFFSET_S
,
1730 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
1731 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
1732 "Set clock offset (seconds)");
1733 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
1734 "bt_ctf_clock_get_offset_s succeeds");
1735 ok(get_offset_s
== offset_s
,
1736 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
1738 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
1739 "bt_ctf_clock_get_offset succeeds");
1740 ok(get_offset
== DEFAULT_CLOCK_OFFSET
,
1741 "bt_ctf_clock_get_offset returns the correct default offset (in ticks)");
1742 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
1743 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
1744 "bt_ctf_clock_get_offset succeeds");
1745 ok(get_offset
== offset
,
1746 "bt_ctf_clock_get_offset returns the correct default offset (in ticks) once it is set");
1748 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
1749 "bt_ctf_clock_get_precision returns the correct default precision");
1750 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
1751 "Set clock precision");
1752 ok(bt_ctf_clock_get_precision(clock
) == precision
,
1753 "bt_ctf_clock_get_precision returns the correct precision once it is set");
1755 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
1756 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
1757 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
1758 "Set clock absolute property");
1759 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
1760 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
1761 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
1763 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1765 "bt_ctf_clock_get_uuid returns a UUID");
1767 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
1768 /* Slightly modify UUID */
1769 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
1772 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
1773 "bt_ctf_clock_set_uuid sets a new uuid successfully");
1774 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1776 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
1777 ok(uuid_match(ret_uuid
, tmp_uuid
),
1778 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
1780 /* Define a stream class */
1781 stream_class
= bt_ctf_stream_class_create("test_stream");
1782 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
1783 ok(ret_string
&& strcmp(ret_string
, "test_stream") == 0,
1784 "bt_ctf_stream_class_get_name returns a correct stream class name");
1786 ok(!bt_ctf_stream_class_get_clock(stream_class
),
1787 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
1788 ok(!bt_ctf_stream_class_get_clock(NULL
),
1789 "bt_ctf_stream_class_get_clock handles NULL correctly");
1791 ok(stream_class
, "Create stream class");
1792 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
1793 "Set a stream class' clock");
1794 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
1795 ok(ret_clock
== clock
,
1796 "bt_ctf_stream_class_get_clock returns a correct clock");
1797 bt_ctf_object_put_ref(ret_clock
);
1799 /* Test the event fields and event types APIs */
1802 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
1803 "bt_ctf_stream_class_get_id returns an error when no id is set");
1804 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
1805 "bt_ctf_stream_class_set_id handles NULL correctly");
1806 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
1807 "Set an stream class' id");
1808 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
1809 "bt_ctf_stream_class_get_id returns the correct value");
1811 /* Validate default event header fields */
1812 ret_field_type
= bt_ctf_stream_class_get_event_header_type(
1815 "bt_ctf_stream_class_get_event_header_type returns an event header type");
1816 ok(bt_ctf_field_type_get_type_id(ret_field_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1817 "Default event header type is a structure");
1818 event_header_field_type
=
1819 bt_ctf_field_type_structure_get_field_type_by_name(
1820 ret_field_type
, "id");
1821 ok(event_header_field_type
,
1822 "Default event header type contains an \"id\" field");
1823 ok(bt_ctf_field_type_get_type_id(
1824 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
1825 "Default event header \"id\" field is an integer");
1826 bt_ctf_object_put_ref(event_header_field_type
);
1827 event_header_field_type
=
1828 bt_ctf_field_type_structure_get_field_type_by_name(
1829 ret_field_type
, "timestamp");
1830 ok(event_header_field_type
,
1831 "Default event header type contains a \"timestamp\" field");
1832 ok(bt_ctf_field_type_get_type_id(
1833 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
1834 "Default event header \"timestamp\" field is an integer");
1835 bt_ctf_object_put_ref(event_header_field_type
);
1836 bt_ctf_object_put_ref(ret_field_type
);
1838 /* Add a custom trace packet header field */
1839 packet_header_type
= bt_ctf_trace_get_packet_header_field_type(trace
);
1840 ok(packet_header_type
,
1841 "bt_ctf_trace_get_packet_header_field_type returns a packet header");
1842 ok(bt_ctf_field_type_get_type_id(packet_header_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1843 "bt_ctf_trace_get_packet_header_field_type returns a packet header of type struct");
1844 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1845 packet_header_type
, "magic");
1846 ok(ret_field_type
, "Default packet header type contains a \"magic\" field");
1847 bt_ctf_object_put_ref(ret_field_type
);
1848 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1849 packet_header_type
, "uuid");
1850 ok(ret_field_type
, "Default packet header type contains a \"uuid\" field");
1851 bt_ctf_object_put_ref(ret_field_type
);
1852 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1853 packet_header_type
, "stream_id");
1854 ok(ret_field_type
, "Default packet header type contains a \"stream_id\" field");
1855 bt_ctf_object_put_ref(ret_field_type
);
1857 packet_header_field_type
= bt_ctf_field_type_integer_create(22);
1858 ok(!bt_ctf_field_type_structure_add_field(packet_header_type
,
1859 packet_header_field_type
, "custom_trace_packet_header_field"),
1860 "Added a custom trace packet header field successfully");
1862 ok(bt_ctf_trace_set_packet_header_field_type(NULL
, packet_header_type
) < 0,
1863 "bt_ctf_trace_set_packet_header_field_type handles a NULL trace correctly");
1864 ok(!bt_ctf_trace_set_packet_header_field_type(trace
, packet_header_type
),
1865 "Set a trace packet_header_type successfully");
1867 /* Add a custom field to the stream class' packet context */
1868 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
1869 ok(packet_context_type
,
1870 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
1871 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
1872 "Packet context is a structure");
1874 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
1875 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
1877 integer_type
= bt_ctf_field_type_integer_create(32);
1879 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
1881 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
1883 /* Create a "uint5_t" equivalent custom packet context field */
1884 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
1886 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1887 packet_context_field_type
, "custom_packet_context_field");
1888 ok(ret
== 0, "Packet context field added successfully");
1890 /* Define a stream event context containing a my_integer field. */
1891 stream_event_context_type
= bt_ctf_field_type_structure_create();
1892 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1893 integer_type
, "common_event_context");
1895 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
1896 stream_event_context_type
) < 0,
1897 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
1898 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
1900 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
1902 ok(bt_ctf_stream_class_set_event_context_type(
1903 stream_class
, stream_event_context_type
) == 0,
1904 "Set a new stream event context type");
1906 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
1908 ok(ret_field_type
== stream_event_context_type
,
1909 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
1910 bt_ctf_object_put_ref(ret_field_type
);
1913 /* Instantiate a stream and append events */
1914 ret
= bt_ctf_writer_add_clock(writer
, clock
);
1915 BT_ASSERT(ret
== 0);
1917 ok(bt_ctf_trace_get_stream_count(trace
) == 0,
1918 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (0)");
1919 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
1920 ok(stream1
, "Instanciate a stream class from writer");
1921 ok(bt_ctf_trace_get_stream_count(trace
) == 1,
1922 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (1)");
1923 stream
= bt_ctf_trace_get_stream_by_index(trace
, 0);
1924 ok(stream
== stream1
,
1925 "bt_ctf_trace_get_stream_by_index() succeeds and returns the correct value");
1926 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream
);
1929 * Creating a stream through a writer adds the given stream
1930 * class to the writer's trace, thus registering the stream
1931 * class's clock to the trace.
1934 ret_stream_class
= bt_ctf_stream_get_class(stream1
);
1935 ok(ret_stream_class
,
1936 "bt_ctf_stream_get_class returns a stream class");
1937 ok(ret_stream_class
== stream_class
,
1938 "Returned stream class is of the correct type");
1941 * Packet header, packet context, event header, and stream
1942 * event context types were copied for the resolving
1945 BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_header_type
);
1946 BT_CTF_OBJECT_PUT_REF_AND_RESET(packet_context_type
);
1947 BT_CTF_OBJECT_PUT_REF_AND_RESET(stream_event_context_type
);
1948 packet_header_type
= bt_ctf_trace_get_packet_header_field_type(trace
);
1949 BT_ASSERT(packet_header_type
);
1950 packet_context_type
=
1951 bt_ctf_stream_class_get_packet_context_type(stream_class
);
1952 BT_ASSERT(packet_context_type
);
1953 stream_event_context_type
=
1954 bt_ctf_stream_class_get_event_context_type(stream_class
);
1955 BT_ASSERT(stream_event_context_type
);
1958 * Try to modify the packet context type after a stream has been
1961 ret
= bt_ctf_field_type_structure_add_field(packet_header_type
,
1962 packet_header_field_type
, "should_fail");
1964 "Trace packet header type can't be modified once a stream has been instanciated");
1967 * Try to modify the packet context type after a stream has been
1970 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1971 packet_context_field_type
, "should_fail");
1973 "Packet context type can't be modified once a stream has been instanciated");
1976 * Try to modify the stream event context type after a stream has been
1979 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1980 integer_type
, "should_fail");
1982 "Stream event context type can't be modified once a stream has been instanciated");
1984 /* Should fail after instanciating a stream (frozen) */
1985 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
1986 "Changes to a stream class that was already instantiated fail");
1988 /* Populate the custom packet header field only once for all tests */
1989 ok(!bt_ctf_stream_get_packet_header(NULL
),
1990 "bt_ctf_stream_get_packet_header handles NULL correctly");
1991 packet_header
= bt_ctf_stream_get_packet_header(stream1
);
1993 "bt_ctf_stream_get_packet_header returns a packet header");
1994 ret_field_type
= bt_ctf_field_get_type(packet_header
);
1995 ok(ret_field_type
== packet_header_type
,
1996 "Stream returns a packet header of the appropriate type");
1997 bt_ctf_object_put_ref(ret_field_type
);
1998 packet_header_field
= bt_ctf_field_structure_get_field_by_name(packet_header
,
1999 "custom_trace_packet_header_field");
2000 ok(packet_header_field
,
2001 "Packet header structure contains a custom field with the appropriate name");
2002 ret_field_type
= bt_ctf_field_get_type(packet_header_field
);
2003 ok(!bt_ctf_field_integer_unsigned_set_value(packet_header_field
,
2004 54321), "Set custom packet header value successfully");
2005 ok(bt_ctf_stream_set_packet_header(stream1
, NULL
) < 0,
2006 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
2007 ok(bt_ctf_stream_set_packet_header(NULL
, packet_header
) < 0,
2008 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
2009 ok(bt_ctf_stream_set_packet_header(stream1
, packet_header_field
) < 0,
2010 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
2011 ok(!bt_ctf_stream_set_packet_header(stream1
, packet_header
),
2012 "Successfully set a stream's packet header");
2014 ok(bt_ctf_writer_add_environment_field(writer
, "new_field", "test") == 0,
2015 "Add environment field to writer after stream creation");
2019 test_instanciate_event_before_stream(writer
, clock
);
2021 append_simple_event(stream_class
, stream1
, clock
);
2023 packet_resize_test(stream_class
, stream1
, clock
);
2025 append_complex_event(stream_class
, stream1
, clock
);
2027 append_existing_event_class(stream_class
);
2029 test_empty_stream(writer
);
2031 test_custom_event_header_stream(writer
, clock
);
2033 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
2034 ok(metadata_string
, "Get metadata string");
2036 bt_ctf_writer_flush_metadata(writer
);
2038 bt_ctf_object_put_ref(clock
);
2039 bt_ctf_object_put_ref(ret_stream_class
);
2040 bt_ctf_object_put_ref(writer
);
2041 bt_ctf_object_put_ref(stream1
);
2042 bt_ctf_object_put_ref(packet_context_type
);
2043 bt_ctf_object_put_ref(packet_context_field_type
);
2044 bt_ctf_object_put_ref(integer_type
);
2045 bt_ctf_object_put_ref(stream_event_context_type
);
2046 bt_ctf_object_put_ref(ret_field_type
);
2047 bt_ctf_object_put_ref(packet_header_type
);
2048 bt_ctf_object_put_ref(packet_header_field_type
);
2049 bt_ctf_object_put_ref(packet_header
);
2050 bt_ctf_object_put_ref(packet_header_field
);
2051 bt_ctf_object_put_ref(trace
);
2052 free(metadata_string
);
2053 bt_ctf_object_put_ref(stream_class
);
2055 validate_trace(argv
[1], trace_path
);
2057 recursive_rmdir(trace_path
);
2059 g_free(metadata_path
);
2061 return exit_status();