6 * Copyright 2013 - 2015 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; under version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <babeltrace/ctf-writer/writer.h>
24 #include <babeltrace/ctf-writer/clock.h>
25 #include <babeltrace/ctf-writer/stream.h>
26 #include <babeltrace/ctf-writer/event.h>
27 #include <babeltrace/ctf-writer/event-types.h>
28 #include <babeltrace/ctf-writer/event-fields.h>
29 #include <babeltrace/ctf-ir/stream-class.h>
30 #include <babeltrace/ctf/events.h>
31 #include <babeltrace/objects.h>
35 #include <sys/utsname.h>
36 #include <babeltrace/compat/limits.h>
46 #define METADATA_LINE_SIZE 512
47 #define SEQUENCE_TEST_LENGTH 10
48 #define ARRAY_TEST_LENGTH 5
49 #define PACKET_RESIZE_TEST_LENGTH 100000
51 #define DEFAULT_CLOCK_FREQ 1000000000
52 #define DEFAULT_CLOCK_PRECISION 1
53 #define DEFAULT_CLOCK_OFFSET 0
54 #define DEFAULT_CLOCK_OFFSET_S 0
55 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
56 #define DEFAULT_CLOCK_TIME 0
58 static uint64_t current_time
= 42;
60 /* Return 1 if uuids match, zero if different. */
61 int uuid_match(const unsigned char *uuid_a
, const unsigned char *uuid_b
)
66 if (!uuid_a
|| !uuid_b
) {
70 for (i
= 0; i
< 16; i
++) {
71 if (uuid_a
[i
] != uuid_b
[i
]) {
81 void validate_metadata(char *parser_path
, char *metadata_path
)
84 char parser_output_path
[] = "/tmp/parser_output_XXXXXX";
85 int parser_output_fd
= -1, metadata_fd
= -1;
92 parser_output_fd
= mkstemp(parser_output_path
);
93 metadata_fd
= open(metadata_path
, O_RDONLY
);
95 unlink(parser_output_path
);
97 if (parser_output_fd
== -1 || metadata_fd
== -1) {
98 diag("Failed create temporary files for metadata parsing.");
106 waitpid(pid
, &status
, 0);
107 ret
= WIFEXITED(status
) ? WEXITSTATUS(status
) : -1;
109 /* ctf-parser-test expects a metadata string on stdin. */
110 ret
= dup2(metadata_fd
, STDIN_FILENO
);
112 perror("# dup2 metadata_fd to STDIN");
116 ret
= dup2(parser_output_fd
, STDOUT_FILENO
);
118 perror("# dup2 parser_output_fd to STDOUT");
122 ret
= dup2(parser_output_fd
, STDERR_FILENO
);
124 perror("# dup2 parser_output_fd to STDERR");
128 execl(parser_path
, "ctf-parser-test", NULL
);
129 perror("# Could not launch the ctf metadata parser process");
133 ok(ret
== 0, "Metadata string is valid");
135 if (ret
&& metadata_fd
>= 0 && parser_output_fd
>= 0) {
137 size_t len
= METADATA_LINE_SIZE
;
138 FILE *metadata_fp
= NULL
, *parser_output_fp
= NULL
;
140 metadata_fp
= fdopen(metadata_fd
, "r");
142 perror("fdopen on metadata_fd");
147 parser_output_fp
= fdopen(parser_output_fd
, "r");
148 if (!parser_output_fp
) {
149 perror("fdopen on parser_output_fd");
152 parser_output_fd
= -1;
156 diag("malloc failure");
161 /* Output the metadata and parser output as diagnostic */
162 while (getline(&line
, &len
, metadata_fp
) > 0) {
163 fprintf(stderr
, "# %s", line
);
166 rewind(parser_output_fp
);
167 while (getline(&line
, &len
, parser_output_fp
) > 0) {
168 fprintf(stderr
, "# %s", line
);
174 if (fclose(metadata_fp
)) {
175 diag("fclose failure");
178 if (parser_output_fp
) {
179 if (fclose(parser_output_fp
)) {
180 diag("fclose failure");
185 if (parser_output_fd
>= 0) {
186 if (close(parser_output_fd
)) {
190 if (metadata_fd
>= 0) {
191 if (close(metadata_fd
)) {
197 void validate_trace(char *parser_path
, char *trace_path
)
200 char babeltrace_output_path
[] = "/tmp/babeltrace_output_XXXXXX";
201 int babeltrace_output_fd
= -1;
208 babeltrace_output_fd
= mkstemp(babeltrace_output_path
);
209 unlink(babeltrace_output_path
);
211 if (babeltrace_output_fd
== -1) {
212 diag("Failed to create a temporary file for trace parsing.");
220 waitpid(pid
, &status
, 0);
221 ret
= WIFEXITED(status
) ? WEXITSTATUS(status
) : -1;
223 ret
= dup2(babeltrace_output_fd
, STDOUT_FILENO
);
225 perror("# dup2 babeltrace_output_fd to STDOUT");
229 ret
= dup2(babeltrace_output_fd
, STDERR_FILENO
);
231 perror("# dup2 babeltrace_output_fd to STDERR");
235 execl(parser_path
, "babeltrace", trace_path
, NULL
);
236 perror("# Could not launch the babeltrace process");
240 ok(ret
== 0, "Babeltrace could read the resulting trace");
242 if (ret
&& babeltrace_output_fd
>= 0) {
244 size_t len
= METADATA_LINE_SIZE
;
245 FILE *babeltrace_output_fp
= NULL
;
247 babeltrace_output_fp
= fdopen(babeltrace_output_fd
, "r");
248 if (!babeltrace_output_fp
) {
249 perror("fdopen on babeltrace_output_fd");
252 babeltrace_output_fd
= -1;
256 diag("malloc error");
258 rewind(babeltrace_output_fp
);
259 while (getline(&line
, &len
, babeltrace_output_fp
) > 0) {
265 if (babeltrace_output_fp
) {
266 if (fclose(babeltrace_output_fp
)) {
267 diag("fclose error");
272 if (babeltrace_output_fd
>= 0) {
273 if (close(babeltrace_output_fd
)) {
279 void append_simple_event(struct bt_ctf_stream_class
*stream_class
,
280 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
282 /* Create and add a simple event class */
283 struct bt_ctf_event_class
*simple_event_class
=
284 bt_ctf_event_class_create("Simple Event");
285 struct bt_ctf_field_type
*uint_12_type
=
286 bt_ctf_field_type_integer_create(12);
287 struct bt_ctf_field_type
*int_64_type
=
288 bt_ctf_field_type_integer_create(64);
289 struct bt_ctf_field_type
*float_type
=
290 bt_ctf_field_type_floating_point_create();
291 struct bt_ctf_field_type
*enum_type
;
292 struct bt_ctf_field_type
*enum_type_unsigned
=
293 bt_ctf_field_type_enumeration_create(uint_12_type
);
294 struct bt_ctf_field_type
*event_context_type
=
295 bt_ctf_field_type_structure_create();
296 struct bt_ctf_field_type
*returned_type
;
297 struct bt_ctf_event
*simple_event
;
298 struct bt_ctf_field
*integer_field
;
299 struct bt_ctf_field
*float_field
;
300 struct bt_ctf_field
*enum_field
;
301 struct bt_ctf_field
*enum_field_unsigned
;
302 struct bt_ctf_field
*enum_container_field
;
303 const char *mapping_name_test
= "truie";
304 const double double_test_value
= 3.1415;
305 struct bt_ctf_field
*enum_container_field_unsigned
;
306 const char *mapping_name_negative_test
= "negative_value";
307 const char *ret_char
;
309 int64_t ret_range_start_int64_t
, ret_range_end_int64_t
;
310 uint64_t ret_range_start_uint64_t
, ret_range_end_uint64_t
;
311 struct bt_ctf_clock
*ret_clock
;
312 struct bt_ctf_event_class
*ret_event_class
;
313 struct bt_ctf_field
*packet_context
;
314 struct bt_ctf_field
*packet_context_field
;
315 struct bt_ctf_field
*stream_event_context
;
316 struct bt_ctf_field
*stream_event_context_field
;
317 struct bt_ctf_field
*event_context
;
318 struct bt_ctf_field
*event_context_field
;
320 ok(uint_12_type
, "Create an unsigned integer type");
322 bt_ctf_field_type_integer_set_signed(int_64_type
, 1);
323 ok(int_64_type
, "Create a signed integer type");
324 enum_type
= bt_ctf_field_type_enumeration_create(int_64_type
);
326 returned_type
= bt_ctf_field_type_enumeration_get_container_type(enum_type
);
327 ok(returned_type
== int_64_type
, "bt_ctf_field_type_enumeration_get_container_type returns the right type");
328 ok(!bt_ctf_field_type_enumeration_get_container_type(NULL
), "bt_ctf_field_type_enumeration_get_container_type handles NULL correctly");
329 ok(!bt_ctf_field_type_enumeration_create(enum_type
),
330 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
331 bt_ctf_field_type_put(returned_type
);
333 bt_ctf_field_type_set_alignment(float_type
, 32);
334 ok(bt_ctf_field_type_get_alignment(NULL
) < 0,
335 "bt_ctf_field_type_get_alignment handles NULL correctly");
336 ok(bt_ctf_field_type_get_alignment(float_type
) == 32,
337 "bt_ctf_field_type_get_alignment returns a correct value");
339 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type
, 11) == 0,
340 "Set a floating point type's exponent digit count");
341 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type
, 53) == 0,
342 "Set a floating point type's mantissa digit count");
344 ok(bt_ctf_field_type_floating_point_get_exponent_digits(NULL
) < 0,
345 "bt_ctf_field_type_floating_point_get_exponent_digits handles NULL properly");
346 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(NULL
) < 0,
347 "bt_ctf_field_type_floating_point_get_mantissa_digits handles NULL properly");
348 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type
) == 11,
349 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
350 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type
) == 53,
351 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
353 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
354 mapping_name_negative_test
, -12345, 0) == 0,
355 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
356 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
357 "escaping; \"test\"", 1, 1) == 0,
358 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
359 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
360 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
361 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
362 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
363 "event clock int float", 5, 22) == 0,
364 "Accept enumeration mapping strings containing reserved keywords");
365 bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
367 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
368 43, 51), "bt_ctf_field_type_enumeration_add_mapping rejects duplicate mapping names");
369 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, "something",
370 -500, -400), "bt_ctf_field_type_enumeration_add_mapping rejects overlapping enum entries");
371 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
372 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
373 bt_ctf_field_type_enumeration_add_mapping(enum_type
, "another entry", -42000, -13000);
375 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(NULL
, -42) < 0,
376 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles a NULL field type correctly");
377 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type
, 1000000) < 0,
378 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles invalid values correctly");
379 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type
, -55) == 1,
380 "bt_ctf_field_type_enumeration_get_mapping_index_by_value returns the correct index");
382 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type
,
383 "enum_field") == 0, "Add signed enumeration field to event");
385 ok(bt_ctf_field_type_enumeration_get_mapping(NULL
, 0, &ret_char
,
386 &ret_range_start_int64_t
, &ret_range_end_int64_t
) < 0,
387 "bt_ctf_field_type_enumeration_get_mapping handles a NULL enumeration correctly");
388 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 0, NULL
,
389 &ret_range_start_int64_t
, &ret_range_end_int64_t
) < 0,
390 "bt_ctf_field_type_enumeration_get_mapping handles a NULL string correctly");
391 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 0, &ret_char
,
392 NULL
, &ret_range_end_int64_t
) < 0,
393 "bt_ctf_field_type_enumeration_get_mapping handles a NULL start correctly");
394 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 0, &ret_char
,
395 &ret_range_start_int64_t
, NULL
) < 0,
396 "bt_ctf_field_type_enumeration_get_mapping handles a NULL end correctly");
397 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 5, &ret_char
,
398 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
399 "bt_ctf_field_type_enumeration_get_mapping returns a value");
400 ok(!strcmp(ret_char
, mapping_name_test
),
401 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping name");
402 ok(ret_range_start_int64_t
== 42,
403 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping start");
404 ok(ret_range_end_int64_t
== 42,
405 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping end");
407 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
408 "escaping; \"test\"", 0, 0) == 0,
409 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing quotes");
410 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
411 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
412 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing special characters");
413 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
414 "event clock int float", 5, 22) == 0,
415 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing reserved keywords");
416 bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
418 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
419 43, 51), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects duplicate mapping names");
420 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, "something",
421 7, 8), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects overlapping enum entries");
422 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
423 55, 54), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects mapping where end < start");
424 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type_unsigned
,
425 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
427 ok(bt_ctf_field_type_enumeration_get_mapping_count(NULL
) < 0,
428 "bt_ctf_field_type_enumeration_get_mapping_count handles NULL correctly");
429 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned
) == 4,
430 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
432 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(NULL
, 0, &ret_char
,
433 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) < 0,
434 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL enumeration correctly");
435 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, NULL
,
436 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) < 0,
437 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL string correctly");
438 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, &ret_char
,
439 NULL
, &ret_range_end_uint64_t
) < 0,
440 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL start correctly");
441 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, &ret_char
,
442 &ret_range_start_uint64_t
, NULL
) < 0,
443 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL end correctly");
444 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 3, &ret_char
,
445 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
446 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a value");
447 ok(!strcmp(ret_char
, mapping_name_test
),
448 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping name");
449 ok(ret_range_start_uint64_t
== 42,
450 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping start");
451 ok(ret_range_end_uint64_t
== 42,
452 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping end");
454 bt_ctf_event_class_add_field(simple_event_class
, uint_12_type
,
456 bt_ctf_event_class_add_field(simple_event_class
, float_type
,
459 assert(!bt_ctf_event_class_set_id(simple_event_class
, 13));
461 /* Set an event context type which will contain a single integer*/
462 ok(!bt_ctf_field_type_structure_add_field(event_context_type
, uint_12_type
,
463 "event_specific_context"),
464 "Add event specific context field");
465 ok(bt_ctf_event_class_get_context_type(NULL
) == NULL
,
466 "bt_ctf_event_class_get_context_type handles NULL correctly");
467 ok(bt_ctf_event_class_get_context_type(simple_event_class
) == NULL
,
468 "bt_ctf_event_class_get_context_type returns NULL when no event context type is set");
470 ok(bt_ctf_event_class_set_context_type(simple_event_class
, NULL
) < 0,
471 "bt_ctf_event_class_set_context_type handles a NULL context type correctly");
472 ok(bt_ctf_event_class_set_context_type(NULL
, event_context_type
) < 0,
473 "bt_ctf_event_class_set_context_type handles a NULL event class correctly");
474 ok(!bt_ctf_event_class_set_context_type(simple_event_class
, event_context_type
),
475 "Set an event class' context type successfully");
476 returned_type
= bt_ctf_event_class_get_context_type(simple_event_class
);
477 ok(returned_type
== event_context_type
,
478 "bt_ctf_event_class_get_context_type returns the appropriate type");
479 bt_ctf_field_type_put(returned_type
);
481 bt_ctf_stream_class_add_event_class(stream_class
, simple_event_class
);
483 ok(bt_ctf_stream_class_get_event_class_count(NULL
) < 0,
484 "bt_ctf_stream_class_get_event_class_count handles NULL correctly");
485 ok(bt_ctf_stream_class_get_event_class_count(stream_class
) == 1,
486 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
487 ok(bt_ctf_stream_class_get_event_class(NULL
, 0) == NULL
,
488 "bt_ctf_stream_class_get_event_class handles NULL correctly");
489 ok(bt_ctf_stream_class_get_event_class(stream_class
, 8724) == NULL
,
490 "bt_ctf_stream_class_get_event_class handles invalid indexes correctly");
491 ret_event_class
= bt_ctf_stream_class_get_event_class(stream_class
, 0);
492 ok(ret_event_class
== simple_event_class
,
493 "bt_ctf_stream_class_get_event_class returns the correct event class");
494 bt_ctf_event_class_put(ret_event_class
);
495 ok(!bt_ctf_stream_class_get_event_class_by_id(NULL
, 0),
496 "bt_ctf_stream_class_get_event_class_by_id handles NULL correctly");
497 ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class
, 2),
498 "bt_ctf_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
500 bt_ctf_stream_class_get_event_class_by_id(stream_class
, 13);
501 ok(ret_event_class
== simple_event_class
,
502 "bt_ctf_stream_class_get_event_class_by_id returns a correct event class");
503 bt_ctf_event_class_put(ret_event_class
);
505 ok(bt_ctf_stream_class_get_event_class_by_name(NULL
, "some event name") == NULL
,
506 "bt_ctf_stream_class_get_event_class_by_name handles a NULL stream class correctly");
507 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class
, NULL
) == NULL
,
508 "bt_ctf_stream_class_get_event_class_by_name handles a NULL event class name correctly");
509 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class
, "some event name") == NULL
,
510 "bt_ctf_stream_class_get_event_class_by_name handles non-existing event class names correctly");
511 ret_event_class
= bt_ctf_stream_class_get_event_class_by_name(stream_class
, "Simple Event");
512 ok(ret_event_class
== simple_event_class
,
513 "bt_ctf_stream_class_get_event_class_by_name returns a correct event class");
514 bt_ctf_event_class_put(ret_event_class
);
516 simple_event
= bt_ctf_event_create(simple_event_class
);
518 "Instantiate an event containing a single integer field");
520 ok(bt_ctf_event_get_clock(NULL
) == NULL
,
521 "bt_ctf_event_get_clock handles NULL correctly");
522 ret_clock
= bt_ctf_event_get_clock(simple_event
);
523 ok(ret_clock
== clock
,
524 "bt_ctf_event_get_clock returns a correct clock");
525 bt_ctf_clock_put(clock
);
527 integer_field
= bt_ctf_field_create(uint_12_type
);
528 bt_ctf_field_unsigned_integer_set_value(integer_field
, 42);
529 ok(bt_ctf_event_set_payload(simple_event
, "integer_field",
530 integer_field
) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
532 float_field
= bt_ctf_event_get_payload(simple_event
, "float_field");
533 ok(bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
534 "bt_ctf_field_floating_point_get_value fails on an unset float field");
535 bt_ctf_field_floating_point_set_value(float_field
, double_test_value
);
536 ok(bt_ctf_field_floating_point_get_value(NULL
, &ret_double
),
537 "bt_ctf_field_floating_point_get_value properly handles a NULL field");
538 ok(bt_ctf_field_floating_point_get_value(float_field
, NULL
),
539 "bt_ctf_field_floating_point_get_value properly handles a NULL return value pointer");
540 ok(!bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
541 "bt_ctf_field_floating_point_get_value returns a double value");
542 ok(fabs(ret_double
- double_test_value
) <= DBL_EPSILON
,
543 "bt_ctf_field_floating_point_get_value returns a correct value");
545 enum_field
= bt_ctf_field_create(enum_type
);
546 ret_char
= bt_ctf_field_enumeration_get_mapping_name(NULL
);
547 ok(!ret_char
, "bt_ctf_field_enumeration_get_mapping_name handles NULL correctly");
548 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field
);
549 ok(!ret_char
, "bt_ctf_field_enumeration_get_mapping_name returns NULL if the enumeration's container field is unset");
550 enum_container_field
= bt_ctf_field_enumeration_get_container(
552 ok(bt_ctf_field_signed_integer_set_value(
553 enum_container_field
, -42) == 0,
554 "Set signed enumeration container value");
555 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field
);
556 ok(!strcmp(ret_char
, mapping_name_negative_test
),
557 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an signed container");
558 bt_ctf_event_set_payload(simple_event
, "enum_field", enum_field
);
560 enum_field_unsigned
= bt_ctf_field_create(enum_type_unsigned
);
561 enum_container_field_unsigned
= bt_ctf_field_enumeration_get_container(
562 enum_field_unsigned
);
563 ok(bt_ctf_field_unsigned_integer_set_value(
564 enum_container_field_unsigned
, 42) == 0,
565 "Set unsigned enumeration container value");
566 bt_ctf_event_set_payload(simple_event
, "enum_field_unsigned",
567 enum_field_unsigned
);
568 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field_unsigned
);
569 ok(!strcmp(ret_char
, mapping_name_test
),
570 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an unsigned container");
572 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0, "Set clock time");
574 /* Populate stream event context */
575 stream_event_context
= bt_ctf_stream_get_event_context(stream
);
576 stream_event_context_field
= bt_ctf_field_structure_get_field(
577 stream_event_context
, "common_event_context");
578 bt_ctf_field_unsigned_integer_set_value(stream_event_context_field
, 42);
580 /* Populate the event's context */
581 ok(bt_ctf_event_get_event_context(NULL
) == NULL
,
582 "bt_ctf_event_get_event_context handles NULL correctly");
583 event_context
= bt_ctf_event_get_event_context(simple_event
);
585 "bt_ctf_event_get_event_context returns a field");
586 returned_type
= bt_ctf_field_get_type(event_context
);
587 ok(returned_type
== event_context_type
,
588 "bt_ctf_event_get_event_context returns a field of the appropriate type");
589 event_context_field
= bt_ctf_field_structure_get_field(event_context
,
590 "event_specific_context");
591 ok(!bt_ctf_field_unsigned_integer_set_value(event_context_field
, 1234),
592 "Successfully set an event context's value");
593 ok(bt_ctf_event_set_event_context(NULL
, event_context
) < 0,
594 "bt_ctf_event_set_event_context handles a NULL event correctly");
595 ok(bt_ctf_event_set_event_context(simple_event
, NULL
) < 0,
596 "bt_ctf_event_set_event_context handles a NULL event context correctly");
597 ok(bt_ctf_event_set_event_context(simple_event
, event_context_field
) < 0,
598 "bt_ctf_event_set_event_context rejects a context of the wrong type");
599 ok(!bt_ctf_event_set_event_context(simple_event
, event_context
),
600 "Set an event context successfully");
602 ok(bt_ctf_stream_append_event(stream
, simple_event
) == 0,
603 "Append simple event to trace stream");
605 ok(bt_ctf_stream_get_packet_context(NULL
) == NULL
,
606 "bt_ctf_stream_get_packet_context handles NULL correctly");
607 packet_context
= bt_ctf_stream_get_packet_context(stream
);
609 "bt_ctf_stream_get_packet_context returns a packet context");
611 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
613 ok(packet_context_field
,
614 "Packet context contains the default packet_size field.");
615 bt_ctf_field_put(packet_context_field
);
616 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
617 "custom_packet_context_field");
618 ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 8) == 0,
619 "Custom packet context field value successfully set.");
621 ok(bt_ctf_stream_set_packet_context(NULL
, packet_context_field
) < 0,
622 "bt_ctf_stream_set_packet_context handles a NULL stream correctly");
623 ok(bt_ctf_stream_set_packet_context(stream
, NULL
) < 0,
624 "bt_ctf_stream_set_packet_context handles a NULL packet context correctly");
625 ok(bt_ctf_stream_set_packet_context(stream
, packet_context
) == 0,
626 "Successfully set a stream's packet context");
628 ok(bt_ctf_stream_flush(stream
) == 0,
629 "Flush trace stream with one event");
631 bt_ctf_event_class_put(simple_event_class
);
632 bt_ctf_event_put(simple_event
);
633 bt_ctf_field_type_put(uint_12_type
);
634 bt_ctf_field_type_put(int_64_type
);
635 bt_ctf_field_type_put(float_type
);
636 bt_ctf_field_type_put(enum_type
);
637 bt_ctf_field_type_put(enum_type_unsigned
);
638 bt_ctf_field_type_put(returned_type
);
639 bt_ctf_field_type_put(event_context_type
);
640 bt_ctf_field_put(integer_field
);
641 bt_ctf_field_put(float_field
);
642 bt_ctf_field_put(enum_field
);
643 bt_ctf_field_put(enum_field_unsigned
);
644 bt_ctf_field_put(enum_container_field
);
645 bt_ctf_field_put(enum_container_field_unsigned
);
646 bt_ctf_field_put(packet_context
);
647 bt_ctf_field_put(packet_context_field
);
648 bt_ctf_field_put(stream_event_context
);
649 bt_ctf_field_put(stream_event_context_field
);
650 bt_ctf_field_put(event_context
);
651 bt_ctf_field_put(event_context_field
);
654 void append_complex_event(struct bt_ctf_stream_class
*stream_class
,
655 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
657 struct event_class_attrs_counts
{
668 struct event_class_attrs_counts
;
669 const char *complex_test_event_string
= "Complex Test Event";
670 const char *test_string
= "Test string";
671 struct bt_ctf_field_type
*uint_35_type
=
672 bt_ctf_field_type_integer_create(35);
673 struct bt_ctf_field_type
*int_16_type
=
674 bt_ctf_field_type_integer_create(16);
675 struct bt_ctf_field_type
*uint_3_type
=
676 bt_ctf_field_type_integer_create(3);
677 struct bt_ctf_field_type
*enum_variant_type
=
678 bt_ctf_field_type_enumeration_create(uint_3_type
);
679 struct bt_ctf_field_type
*variant_type
=
680 bt_ctf_field_type_variant_create(enum_variant_type
,
682 struct bt_ctf_field_type
*string_type
=
683 bt_ctf_field_type_string_create();
684 struct bt_ctf_field_type
*sequence_type
;
685 struct bt_ctf_field_type
*array_type
;
686 struct bt_ctf_field_type
*inner_structure_type
=
687 bt_ctf_field_type_structure_create();
688 struct bt_ctf_field_type
*complex_structure_type
=
689 bt_ctf_field_type_structure_create();
690 struct bt_ctf_field_type
*ret_field_type
;
691 struct bt_ctf_event_class
*event_class
;
692 struct bt_ctf_event
*event
;
693 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
694 *inner_structure_field
, *complex_structure_field
,
695 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
696 *variant_field
, *an_array_field
, *ret_field
;
697 uint64_t ret_unsigned_int
;
698 int64_t ret_signed_int
;
699 const char *ret_string
;
700 struct bt_ctf_stream_class
*ret_stream_class
;
701 struct bt_ctf_event_class
*ret_event_class
;
702 struct bt_ctf_field
*packet_context
, *packet_context_field
;
703 struct bt_object
*obj
;
705 bt_ctf_field_type_set_alignment(int_16_type
, 32);
706 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
707 bt_ctf_field_type_integer_set_base(uint_35_type
,
708 BT_CTF_INTEGER_BASE_HEXADECIMAL
);
710 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
711 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
714 ok(bt_ctf_field_type_array_get_element_type(NULL
) == NULL
,
715 "bt_ctf_field_type_array_get_element_type handles NULL correctly");
716 ret_field_type
= bt_ctf_field_type_array_get_element_type(
718 ok(ret_field_type
== int_16_type
,
719 "bt_ctf_field_type_array_get_element_type returns the correct type");
720 bt_ctf_field_type_put(ret_field_type
);
722 ok(bt_ctf_field_type_array_get_length(NULL
) < 0,
723 "bt_ctf_field_type_array_get_length handles NULL correctly");
724 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
725 "bt_ctf_field_type_array_get_length returns the correct length");
727 bt_ctf_field_type_structure_add_field(inner_structure_type
,
728 uint_35_type
, "seq_len");
729 bt_ctf_field_type_structure_add_field(inner_structure_type
,
730 sequence_type
, "a_sequence");
731 bt_ctf_field_type_structure_add_field(inner_structure_type
,
732 array_type
, "an_array");
734 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
736 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
738 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
739 "UINT35_TYPE", 2, 7);
741 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL
,
743 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly");
744 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
745 enum_variant_type
, NULL
) < 0,
746 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly");
747 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
748 enum_variant_type
, "INT16_TYPE") == 1,
749 "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index");
751 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL
, 1) < 0,
752 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly");
753 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, -42) < 0,
754 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly");
755 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, 5) == 2,
756 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index");
758 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
759 "An unknown entry"), "Reject a variant field based on an unknown tag value");
760 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
761 "UINT3_TYPE") == 0, "Add a field to a variant");
762 bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
764 bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
767 ok(bt_ctf_field_type_variant_get_tag_type(NULL
) == NULL
,
768 "bt_ctf_field_type_variant_get_tag_type handles NULL correctly");
769 ret_field_type
= bt_ctf_field_type_variant_get_tag_type(variant_type
);
770 ok(ret_field_type
== enum_variant_type
,
771 "bt_ctf_field_type_variant_get_tag_type returns a correct tag type");
772 bt_ctf_field_type_put(ret_field_type
);
774 ok(bt_ctf_field_type_variant_get_tag_name(NULL
) == NULL
,
775 "bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
776 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
777 ok(!strcmp(ret_string
, "variant_selector"),
778 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
779 ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL
,
780 "INT16_TYPE") == NULL
,
781 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
782 ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type
,
784 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
785 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
786 variant_type
, "INT16_TYPE");
787 ok(ret_field_type
== int_16_type
,
788 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
789 bt_ctf_field_type_put(ret_field_type
);
791 ok(bt_ctf_field_type_variant_get_field_count(NULL
) < 0,
792 "bt_ctf_field_type_variant_get_field_count handles NULL correctly");
793 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
794 "bt_ctf_field_type_variant_get_field_count returns the correct count");
796 ok(bt_ctf_field_type_variant_get_field(NULL
, &ret_string
, &ret_field_type
, 0) < 0,
797 "bt_ctf_field_type_variant_get_field handles a NULL type correctly");
798 ok(bt_ctf_field_type_variant_get_field(variant_type
, NULL
, &ret_field_type
, 0) < 0,
799 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
800 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, NULL
, 0) < 0,
801 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
802 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 200) < 0,
803 "bt_ctf_field_type_variant_get_field handles an invalid index correctly");
804 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
805 "bt_ctf_field_type_variant_get_field returns a field");
806 ok(!strcmp("INT16_TYPE", ret_string
),
807 "bt_ctf_field_type_variant_get_field returns a correct field name");
808 ok(ret_field_type
== int_16_type
,
809 "bt_ctf_field_type_variant_get_field returns a correct field type");
810 bt_ctf_field_type_put(ret_field_type
);
812 bt_ctf_field_type_structure_add_field(complex_structure_type
,
813 enum_variant_type
, "variant_selector");
814 bt_ctf_field_type_structure_add_field(complex_structure_type
,
815 string_type
, "a_string");
816 bt_ctf_field_type_structure_add_field(complex_structure_type
,
817 variant_type
, "variant_value");
818 bt_ctf_field_type_structure_add_field(complex_structure_type
,
819 inner_structure_type
, "inner_structure");
821 ok(bt_ctf_event_class_create("clock") == NULL
,
822 "Reject creation of an event class with an illegal name");
823 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
824 ok(event_class
, "Create an event class");
825 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
826 "Reject addition of a field with an empty name to an event");
827 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
828 "Reject addition of a field with a NULL type to an event");
829 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
831 "Reject addition of a type with an illegal name to an event");
832 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
834 "Add field of type unsigned integer to an event");
835 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
836 "int_16") == 0, "Add field of type signed integer to an event");
837 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
838 "complex_structure") == 0,
839 "Add composite structure to an event");
841 ok(bt_ctf_event_class_get_name(NULL
) == NULL
,
842 "bt_ctf_event_class_get_name handles NULL correctly");
843 ret_string
= bt_ctf_event_class_get_name(event_class
);
844 ok(!strcmp(ret_string
, complex_test_event_string
),
845 "bt_ctf_event_class_get_name returns a correct name");
846 ok(bt_ctf_event_class_get_id(event_class
) < 0,
847 "bt_ctf_event_class_get_id returns a negative value when not set");
848 ok(bt_ctf_event_class_get_id(NULL
) < 0,
849 "bt_ctf_event_class_get_id handles NULL correctly");
850 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
851 "bt_ctf_event_class_set_id handles NULL correctly");
852 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
853 "Set an event class' id");
854 ok(bt_ctf_event_class_get_id(event_class
) == 42,
855 "bt_ctf_event_class_get_id returns the correct value");
857 /* Test event class attributes */
858 assert(obj
= bt_object_integer_create_init(15));
859 ok(bt_ctf_event_class_set_attribute(NULL
, "id", obj
),
860 "bt_ctf_event_class_set_attribute handles a NULL event class correctly");
861 ok(bt_ctf_event_class_set_attribute(event_class
, NULL
, obj
),
862 "bt_ctf_event_class_set_attribute handles a NULL name correctly");
863 ok(bt_ctf_event_class_set_attribute(event_class
, "id", NULL
),
864 "bt_ctf_event_class_set_attribute handles a NULL value correctly");
865 assert(!bt_object_integer_set(obj
, -3));
866 ok(bt_ctf_event_class_set_attribute(event_class
, "id", obj
),
867 "bt_ctf_event_class_set_attribute fails with a negative \"id\" attribute");
868 assert(!bt_object_integer_set(obj
, 11));
869 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
870 ok(!ret
&& bt_ctf_event_class_get_id(event_class
) == 11,
871 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"id\" attribute");
872 ret
= bt_ctf_event_class_set_attribute(event_class
, "name", obj
);
873 ret
&= bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
);
875 "bt_ctf_event_class_set_attribute cannot set \"name\" or \"model.emf.uri\" to an integer value");
878 assert(obj
= bt_object_integer_create_init(5));
879 ok(!bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
),
880 "bt_ctf_event_class_set_attribute succeeds in setting the \"loglevel\" attribute");
882 ok(!bt_ctf_event_class_get_attribute_value_by_name(NULL
, "loglevel"),
883 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL event class correctly");
884 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, NULL
),
885 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL name correctly");
886 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, "meow"),
887 "bt_ctf_event_class_get_attribute_value_by_name fails with a non-existing attribute name");
888 obj
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
891 ret
= bt_object_integer_get(obj
, &int64_value
);
892 ok(obj
&& !ret
&& int64_value
== 5,
893 "bt_ctf_event_class_get_attribute_value_by_name returns the correct value");
896 assert(obj
= bt_object_string_create_init("nu name"));
897 assert(!bt_ctf_event_class_set_attribute(event_class
, "name", obj
));
898 ret_string
= bt_ctf_event_class_get_name(event_class
);
899 ok(!strcmp(ret_string
, "nu name"),
900 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"name\" attribute");
901 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
902 ret
&= bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
);
904 "bt_ctf_event_class_set_attribute cannot set \"id\" or \"loglevel\" to a string value");
906 assert(obj
= bt_object_string_create_init("http://kernel.org/"));
907 assert(!bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
));
910 ok(bt_ctf_event_class_get_attribute_count(NULL
),
911 "bt_ctf_event_class_get_attribute_count handles a NULL event class");
912 ok(bt_ctf_event_class_get_attribute_count(event_class
) == 4,
913 "bt_ctf_event_class_get_attribute_count returns the correct count");
914 ok(!bt_ctf_event_class_get_attribute_name(NULL
, 0),
915 "bt_ctf_event_class_get_attribute_name handles a NULL event class correctly");
916 ok(!bt_ctf_event_class_get_attribute_name(event_class
, 4),
917 "bt_ctf_event_class_get_attribute_name handles a too large index correctly");
918 ok(!bt_ctf_event_class_get_attribute_value(NULL
, 0),
919 "bt_ctf_event_class_get_attribute_value handles a NULL event class correctly");
920 ok(!bt_ctf_event_class_get_attribute_value(event_class
, 4),
921 "bt_ctf_event_class_get_attribute_value handles a too large index correctly");
923 memset(&attrs_count
, 0, sizeof(attrs_count
));
925 for (i
= 0; i
< 4; ++i
) {
926 ret_string
= bt_ctf_event_class_get_attribute_name(event_class
,
928 obj
= bt_ctf_event_class_get_attribute_value(event_class
, i
);
929 assert(ret_string
&& obj
);
931 if (!strcmp(ret_string
, "id")) {
933 ok(bt_object_is_integer(obj
),
934 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
936 } else if (!strcmp(ret_string
, "name")) {
938 ok(bt_object_is_string(obj
),
939 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
941 } else if (!strcmp(ret_string
, "loglevel")) {
942 attrs_count
.loglevel
++;
943 ok(bt_object_is_integer(obj
),
944 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
946 } else if (!strcmp(ret_string
, "model.emf.uri")) {
947 attrs_count
.modelemfuri
++;
948 ok(bt_object_is_string(obj
),
949 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
952 attrs_count
.unknown
++;
958 ok(attrs_count
.unknown
== 0, "event class has no unknown attributes");
959 ok(attrs_count
.id
== 1 && attrs_count
.name
== 1 &&
960 attrs_count
.loglevel
== 1 && attrs_count
.modelemfuri
== 1,
961 "event class has one instance of each known attribute");
963 /* Add event class to the stream class */
964 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
965 "Reject addition of NULL event class to a stream class");
966 ok(bt_ctf_stream_class_add_event_class(stream_class
,
967 event_class
) == 0, "Add an event class to stream class");
969 ok(bt_ctf_event_class_get_stream_class(NULL
) == NULL
,
970 "bt_ctf_event_class_get_stream_class handles NULL correctly");
971 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
972 ok(ret_stream_class
== stream_class
,
973 "bt_ctf_event_class_get_stream_class returns the correct stream class");
974 bt_ctf_stream_class_put(ret_stream_class
);
976 ok(bt_ctf_event_class_get_field_count(NULL
) < 0,
977 "bt_ctf_event_class_get_field_count handles NULL correctly");
978 ok(bt_ctf_event_class_get_field_count(event_class
) == 3,
979 "bt_ctf_event_class_get_field_count returns a correct value");
981 ok(bt_ctf_event_class_get_field(NULL
, &ret_string
,
982 &ret_field_type
, 0) < 0,
983 "bt_ctf_event_class_get_field handles a NULL event class correctly");
984 ok(bt_ctf_event_class_get_field(event_class
, NULL
,
985 &ret_field_type
, 0) < 0,
986 "bt_ctf_event_class_get_field handles a NULL field name correctly");
987 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
989 "bt_ctf_event_class_get_field handles a NULL field type correctly");
990 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
991 &ret_field_type
, 42) < 0,
992 "bt_ctf_event_class_get_field handles an invalid index correctly");
993 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
994 &ret_field_type
, 0) == 0,
995 "bt_ctf_event_class_get_field returns a field");
996 ok(ret_field_type
== uint_35_type
,
997 "bt_ctf_event_class_get_field returns a correct field type");
998 bt_ctf_field_type_put(ret_field_type
);
999 ok(!strcmp(ret_string
, "uint_35"),
1000 "bt_ctf_event_class_get_field returns a correct field name");
1001 ok(bt_ctf_event_class_get_field_by_name(NULL
, "") == NULL
,
1002 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
1003 ok(bt_ctf_event_class_get_field_by_name(event_class
, NULL
) == NULL
,
1004 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
1005 ok(bt_ctf_event_class_get_field_by_name(event_class
, "truie") == NULL
,
1006 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
1007 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
1008 "complex_structure");
1009 ok(ret_field_type
== complex_structure_type
,
1010 "bt_ctf_event_class_get_field_by_name returns a correct field type");
1011 bt_ctf_field_type_put(ret_field_type
);
1013 event
= bt_ctf_event_create(event_class
);
1014 ok(event
, "Instanciate a complex event");
1016 ok(bt_ctf_event_get_class(NULL
) == NULL
,
1017 "bt_ctf_event_get_class handles NULL correctly");
1018 ret_event_class
= bt_ctf_event_get_class(event
);
1019 ok(ret_event_class
== event_class
,
1020 "bt_ctf_event_get_class returns the correct event class");
1021 bt_ctf_event_class_put(ret_event_class
);
1023 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
1024 if (!uint_35_field
) {
1025 printf("uint_35_field is NULL\n");
1028 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
1029 bt_ctf_field_unsigned_integer_set_value(uint_35_field
, 0x0DDF00D);
1030 ok(bt_ctf_field_unsigned_integer_get_value(NULL
, &ret_unsigned_int
) < 0,
1031 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
1032 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
, NULL
) < 0,
1033 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
1034 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
,
1035 &ret_unsigned_int
) == 0,
1036 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
1037 ok(ret_unsigned_int
== 0x0DDF00D,
1038 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
1039 ok(bt_ctf_field_signed_integer_get_value(uint_35_field
,
1040 &ret_signed_int
) < 0,
1041 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
1042 bt_ctf_field_put(uint_35_field
);
1044 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
1045 bt_ctf_field_signed_integer_set_value(int_16_field
, -12345);
1046 ok(bt_ctf_field_signed_integer_get_value(NULL
, &ret_signed_int
) < 0,
1047 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
1048 ok(bt_ctf_field_signed_integer_get_value(int_16_field
, NULL
) < 0,
1049 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
1050 ok(bt_ctf_field_signed_integer_get_value(int_16_field
,
1051 &ret_signed_int
) == 0,
1052 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
1053 ok(ret_signed_int
== -12345,
1054 "bt_ctf_field_signed_integer_get_value returns the correct value");
1055 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field
,
1056 &ret_unsigned_int
) < 0,
1057 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
1058 bt_ctf_field_put(int_16_field
);
1060 complex_structure_field
= bt_ctf_event_get_payload(event
,
1061 "complex_structure");
1063 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 0) == NULL
,
1064 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
1065 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 9) == NULL
,
1066 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
1067 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
1068 complex_structure_field
, 3);
1069 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
1070 bt_ctf_field_put(inner_structure_field
);
1071 ok(ret_field_type
== inner_structure_type
,
1072 "bt_ctf_field_structure_get_field_by_index returns a correct field");
1073 bt_ctf_field_type_put(ret_field_type
);
1075 inner_structure_field
= bt_ctf_field_structure_get_field(
1076 complex_structure_field
, "inner_structure");
1077 a_string_field
= bt_ctf_field_structure_get_field(
1078 complex_structure_field
, "a_string");
1079 enum_variant_field
= bt_ctf_field_structure_get_field(
1080 complex_structure_field
, "variant_selector");
1081 variant_field
= bt_ctf_field_structure_get_field(
1082 complex_structure_field
, "variant_value");
1083 uint_35_field
= bt_ctf_field_structure_get_field(
1084 inner_structure_field
, "seq_len");
1085 a_sequence_field
= bt_ctf_field_structure_get_field(
1086 inner_structure_field
, "a_sequence");
1087 an_array_field
= bt_ctf_field_structure_get_field(
1088 inner_structure_field
, "an_array");
1090 enum_container_field
= bt_ctf_field_enumeration_get_container(
1091 enum_variant_field
);
1092 bt_ctf_field_unsigned_integer_set_value(enum_container_field
, 1);
1093 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
1094 enum_variant_field
);
1095 bt_ctf_field_signed_integer_set_value(int_16_field
, -200);
1096 bt_ctf_field_put(int_16_field
);
1097 ok(!bt_ctf_field_string_get_value(a_string_field
),
1098 "bt_ctf_field_string_get_value returns NULL on an unset field");
1099 bt_ctf_field_string_set_value(a_string_field
,
1101 ok(!bt_ctf_field_string_get_value(NULL
),
1102 "bt_ctf_field_string_get_value correctly handles NULL");
1103 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
1104 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
1105 ok(ret_string
? !strcmp(ret_string
, test_string
) : 0,
1106 "bt_ctf_field_string_get_value returns a correct value");
1107 bt_ctf_field_unsigned_integer_set_value(uint_35_field
,
1108 SEQUENCE_TEST_LENGTH
);
1110 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL
,
1111 enum_container_field
) == NULL
,
1112 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
1113 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type
,
1115 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
1116 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
1117 variant_type
, enum_variant_field
);
1118 ok(ret_field_type
== int_16_type
,
1119 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
1121 ok(bt_ctf_field_sequence_get_length(a_sequence_field
) == NULL
,
1122 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
1123 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
1124 uint_35_field
) == 0, "Set a sequence field's length");
1125 ret_field
= bt_ctf_field_sequence_get_length(a_sequence_field
);
1126 ok(ret_field
== uint_35_field
,
1127 "bt_ctf_field_sequence_get_length returns the correct length field");
1128 ok(bt_ctf_field_sequence_get_length(NULL
) == NULL
,
1129 "bt_ctf_field_sequence_get_length properly handles NULL");
1131 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
1132 int_16_field
= bt_ctf_field_sequence_get_field(
1133 a_sequence_field
, i
);
1134 bt_ctf_field_signed_integer_set_value(int_16_field
, 4 - i
);
1135 bt_ctf_field_put(int_16_field
);
1138 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
1139 int_16_field
= bt_ctf_field_array_get_field(
1141 bt_ctf_field_signed_integer_set_value(int_16_field
, i
);
1142 bt_ctf_field_put(int_16_field
);
1145 bt_ctf_clock_set_time(clock
, ++current_time
);
1146 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
1147 "Append a complex event to a stream");
1150 * Populate the custom packet context field with a dummy value
1151 * otherwise flush will fail.
1153 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1154 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1155 "custom_packet_context_field");
1156 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 1);
1158 ok(bt_ctf_stream_flush(stream
) == 0,
1159 "Flush a stream containing a complex event");
1161 bt_ctf_field_put(uint_35_field
);
1162 bt_ctf_field_put(a_string_field
);
1163 bt_ctf_field_put(inner_structure_field
);
1164 bt_ctf_field_put(complex_structure_field
);
1165 bt_ctf_field_put(a_sequence_field
);
1166 bt_ctf_field_put(an_array_field
);
1167 bt_ctf_field_put(enum_variant_field
);
1168 bt_ctf_field_put(enum_container_field
);
1169 bt_ctf_field_put(variant_field
);
1170 bt_ctf_field_put(ret_field
);
1171 bt_ctf_field_put(packet_context_field
);
1172 bt_ctf_field_put(packet_context
);
1173 bt_ctf_field_type_put(uint_35_type
);
1174 bt_ctf_field_type_put(int_16_type
);
1175 bt_ctf_field_type_put(string_type
);
1176 bt_ctf_field_type_put(sequence_type
);
1177 bt_ctf_field_type_put(array_type
);
1178 bt_ctf_field_type_put(inner_structure_type
);
1179 bt_ctf_field_type_put(complex_structure_type
);
1180 bt_ctf_field_type_put(uint_3_type
);
1181 bt_ctf_field_type_put(enum_variant_type
);
1182 bt_ctf_field_type_put(variant_type
);
1183 bt_ctf_field_type_put(ret_field_type
);
1184 bt_ctf_event_class_put(event_class
);
1185 bt_ctf_event_put(event
);
1188 void type_field_tests()
1190 struct bt_ctf_field
*uint_12
;
1191 struct bt_ctf_field
*int_16
;
1192 struct bt_ctf_field
*string
;
1193 struct bt_ctf_field
*enumeration
;
1194 struct bt_ctf_field_type
*composite_structure_type
;
1195 struct bt_ctf_field_type
*structure_seq_type
;
1196 struct bt_ctf_field_type
*string_type
;
1197 struct bt_ctf_field_type
*sequence_type
;
1198 struct bt_ctf_field_type
*uint_8_type
;
1199 struct bt_ctf_field_type
*int_16_type
;
1200 struct bt_ctf_field_type
*uint_12_type
=
1201 bt_ctf_field_type_integer_create(12);
1202 struct bt_ctf_field_type
*enumeration_type
;
1203 struct bt_ctf_field_type
*enumeration_sequence_type
;
1204 struct bt_ctf_field_type
*enumeration_array_type
;
1205 struct bt_ctf_field_type
*returned_type
;
1206 const char *ret_string
;
1208 returned_type
= bt_ctf_field_get_type(NULL
);
1209 ok(!returned_type
, "bt_ctf_field_get_type handles NULL correctly");
1211 ok(uint_12_type
, "Create an unsigned integer type");
1212 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1213 BT_CTF_INTEGER_BASE_BINARY
) == 0,
1214 "Set integer type's base as binary");
1215 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1216 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
1217 "Set integer type's base as decimal");
1218 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1219 BT_CTF_INTEGER_BASE_UNKNOWN
),
1220 "Reject integer type's base set as unknown");
1221 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1222 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
1223 "Set integer type's base as octal");
1224 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1225 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
1226 "Set integer type's base as hexadecimal");
1227 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
1228 "Reject unknown integer base value");
1229 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
1230 "Set integer type signedness to signed");
1231 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
1232 "Set integer type signedness to unsigned");
1233 ok(bt_ctf_field_type_integer_get_size(NULL
) < 0,
1234 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1235 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
1236 "bt_ctf_field_type_integer_get_size returns a correct value");
1237 ok(bt_ctf_field_type_integer_get_signed(NULL
) < 0,
1238 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1239 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
1240 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1242 ok(bt_ctf_field_type_set_byte_order(NULL
,
1243 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
1244 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1245 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1246 (enum bt_ctf_byte_order
) 42) < 0,
1247 "bt_ctf_field_type_set_byte_order rejects invalid values");
1248 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1249 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
1250 "Set an integer's byte order to little endian");
1251 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1252 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1253 "Set an integer's byte order to big endian");
1254 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
1255 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1256 "bt_ctf_field_type_get_byte_order returns a correct value");
1257 ok(bt_ctf_field_type_get_byte_order(NULL
) ==
1258 BT_CTF_BYTE_ORDER_UNKNOWN
,
1259 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1261 ok(bt_ctf_field_type_get_type_id(NULL
) ==
1263 "bt_ctf_field_type_get_type_id handles NULL correctly");
1264 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
1266 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1268 ok(bt_ctf_field_type_integer_get_base(NULL
) ==
1269 BT_CTF_INTEGER_BASE_UNKNOWN
,
1270 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1271 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
1272 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
1273 "bt_ctf_field_type_integer_get_base returns a correct value");
1275 ok(bt_ctf_field_type_integer_set_encoding(NULL
, CTF_STRING_ASCII
) < 0,
1276 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1277 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1278 (enum ctf_string_encoding
) 123) < 0,
1279 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1280 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1281 CTF_STRING_UTF8
) == 0,
1282 "Set integer type encoding to UTF8");
1283 ok(bt_ctf_field_type_integer_get_encoding(NULL
) == CTF_STRING_UNKNOWN
,
1284 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1285 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) == CTF_STRING_UTF8
,
1286 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1288 int_16_type
= bt_ctf_field_type_integer_create(16);
1289 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
1290 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
1291 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1292 uint_8_type
= bt_ctf_field_type_integer_create(8);
1294 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
1295 ok(sequence_type
, "Create a sequence of int16_t type");
1296 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
1298 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1300 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL
) == NULL
,
1301 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1302 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
1304 ok(!strcmp(ret_string
, "seq_len"),
1305 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1306 ok(bt_ctf_field_type_sequence_get_element_type(NULL
) == NULL
,
1307 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1308 returned_type
= bt_ctf_field_type_sequence_get_element_type(
1310 ok(returned_type
== int_16_type
,
1311 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
1312 bt_ctf_field_type_put(returned_type
);
1314 string_type
= bt_ctf_field_type_string_create();
1315 ok(string_type
, "Create a string type");
1316 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1318 "Reject invalid \"None\" string encoding");
1319 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1321 "Reject invalid string encoding");
1322 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1323 CTF_STRING_ASCII
) == 0,
1324 "Set string encoding to ASCII");
1326 ok(bt_ctf_field_type_string_get_encoding(NULL
) ==
1328 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
1329 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
1331 "bt_ctf_field_type_string_get_encoding returns the correct value");
1333 structure_seq_type
= bt_ctf_field_type_structure_create();
1334 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
1336 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
1337 ok(structure_seq_type
, "Create a structure type");
1338 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1339 uint_8_type
, "seq_len") == 0,
1340 "Add a uint8_t type to a structure");
1341 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1342 sequence_type
, "a_sequence") == 0,
1343 "Add a sequence type to a structure");
1345 ok(bt_ctf_field_type_structure_get_field_count(NULL
) < 0,
1346 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
1347 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
1348 "bt_ctf_field_type_structure_get_field_count returns a correct value");
1350 ok(bt_ctf_field_type_structure_get_field(NULL
,
1351 &ret_string
, &returned_type
, 1) < 0,
1352 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
1353 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1354 NULL
, &returned_type
, 1) < 0,
1355 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
1356 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1357 &ret_string
, NULL
, 1) < 0,
1358 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
1359 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1360 &ret_string
, &returned_type
, 10) < 0,
1361 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
1362 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1363 &ret_string
, &returned_type
, 1) == 0,
1364 "bt_ctf_field_type_structure_get_field returns a field");
1365 ok(!strcmp(ret_string
, "a_sequence"),
1366 "bt_ctf_field_type_structure_get_field returns a correct field name");
1367 ok(returned_type
== sequence_type
,
1368 "bt_ctf_field_type_structure_get_field returns a correct field type");
1369 bt_ctf_field_type_put(returned_type
);
1371 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL
, "a_sequence") == NULL
,
1372 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
1373 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type
, NULL
) == NULL
,
1374 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1375 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1376 structure_seq_type
, "a_sequence");
1377 ok(returned_type
== sequence_type
,
1378 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
1379 bt_ctf_field_type_put(returned_type
);
1381 composite_structure_type
= bt_ctf_field_type_structure_create();
1382 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1383 string_type
, "a_string") == 0,
1384 "Add a string type to a structure");
1385 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1386 structure_seq_type
, "inner_structure") == 0,
1387 "Add a structure type to a structure");
1389 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1390 NULL
, "a_sequence") == NULL
,
1391 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
1392 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1393 structure_seq_type
, NULL
) == NULL
,
1394 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1395 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1396 structure_seq_type
, "a_sequence");
1397 ok(returned_type
== sequence_type
,
1398 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1399 bt_ctf_field_type_put(returned_type
);
1401 int_16
= bt_ctf_field_create(int_16_type
);
1402 ok(int_16
, "Instanciate a signed 16-bit integer");
1403 uint_12
= bt_ctf_field_create(uint_12_type
);
1404 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1405 returned_type
= bt_ctf_field_get_type(int_16
);
1406 ok(returned_type
== int_16_type
,
1407 "bt_ctf_field_get_type returns the correct type");
1409 /* Can't modify types after instanciating them */
1410 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1411 BT_CTF_INTEGER_BASE_DECIMAL
),
1412 "Check an integer type' base can't be modified after instanciation");
1413 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1414 "Check an integer type's signedness can't be modified after instanciation");
1416 /* Check signed property is checked */
1417 ok(bt_ctf_field_signed_integer_set_value(uint_12
, -52),
1418 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
1419 ok(bt_ctf_field_unsigned_integer_set_value(int_16
, 42),
1420 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
1422 /* Check overflows are properly tested for */
1423 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32768) == 0,
1424 "Check -32768 is allowed for a signed 16-bit integer");
1425 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32767) == 0,
1426 "Check 32767 is allowed for a signed 16-bit integer");
1427 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32768),
1428 "Check 32768 is not allowed for a signed 16-bit integer");
1429 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32769),
1430 "Check -32769 is not allowed for a signed 16-bit integer");
1431 ok(bt_ctf_field_signed_integer_set_value(int_16
, -42) == 0,
1432 "Check -42 is allowed for a signed 16-bit integer");
1434 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4095) == 0,
1435 "Check 4095 is allowed for an unsigned 12-bit integer");
1436 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4096),
1437 "Check 4096 is not allowed for a unsigned 12-bit integer");
1438 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 0) == 0,
1439 "Check 0 is allowed for an unsigned 12-bit integer");
1441 string
= bt_ctf_field_create(string_type
);
1442 ok(string
, "Instanciate a string field");
1443 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1444 "Set a string's value");
1446 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1447 ok(enumeration_type
,
1448 "Create an enumeration type with an unsigned 12-bit integer as container");
1449 enumeration_sequence_type
= bt_ctf_field_type_sequence_create(
1450 enumeration_type
, "count");
1451 ok(!enumeration_sequence_type
,
1452 "Check enumeration types are validated when creating a sequence");
1453 enumeration_array_type
= bt_ctf_field_type_array_create(
1454 enumeration_type
, 10);
1455 ok(!enumeration_array_type
,
1456 "Check enumeration types are validated when creating an array");
1457 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1458 enumeration_type
, "enumeration"),
1459 "Check enumeration types are validated when adding them as structure members");
1460 enumeration
= bt_ctf_field_create(enumeration_type
);
1462 "Check enumeration types are validated before instantiation");
1464 bt_ctf_field_put(string
);
1465 bt_ctf_field_put(uint_12
);
1466 bt_ctf_field_put(int_16
);
1467 bt_ctf_field_put(enumeration
);
1468 bt_ctf_field_type_put(composite_structure_type
);
1469 bt_ctf_field_type_put(structure_seq_type
);
1470 bt_ctf_field_type_put(string_type
);
1471 bt_ctf_field_type_put(sequence_type
);
1472 bt_ctf_field_type_put(uint_8_type
);
1473 bt_ctf_field_type_put(int_16_type
);
1474 bt_ctf_field_type_put(uint_12_type
);
1475 bt_ctf_field_type_put(enumeration_type
);
1476 bt_ctf_field_type_put(enumeration_sequence_type
);
1477 bt_ctf_field_type_put(enumeration_array_type
);
1478 bt_ctf_field_type_put(returned_type
);
1481 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
1482 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
1485 * Append enough events to force the underlying packet to be resized.
1486 * Also tests that a new event can be declared after a stream has been
1487 * instantiated and used/flushed.
1491 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
1493 struct bt_ctf_field_type
*integer_type
=
1494 bt_ctf_field_type_integer_create(17);
1495 struct bt_ctf_field_type
*string_type
=
1496 bt_ctf_field_type_string_create();
1497 struct bt_ctf_event
*event
= NULL
;
1498 struct bt_ctf_field
*ret_field
= NULL
;
1499 struct bt_ctf_field_type
*ret_field_type
= NULL
;
1500 uint64_t ret_uint64
;
1501 int events_appended
= 0;
1502 struct bt_ctf_field
*packet_context
= NULL
,
1503 *packet_context_field
= NULL
, *event_context
= NULL
;
1505 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
1507 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
1509 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1510 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
1515 event
= bt_ctf_event_create(event_class
);
1516 ret_field
= bt_ctf_event_get_payload_by_index(event
, 0);
1517 ret_field_type
= bt_ctf_field_get_type(ret_field
);
1518 ok(ret_field_type
== integer_type
,
1519 "bt_ctf_event_get_payload_by_index returns a correct field");
1520 bt_ctf_field_type_put(ret_field_type
);
1521 bt_ctf_field_put(ret_field
);
1523 ok(bt_ctf_event_get_payload_by_index(NULL
, 0) == NULL
,
1524 "bt_ctf_event_get_payload_by_index handles NULL correctly");
1525 ok(bt_ctf_event_get_payload_by_index(event
, 4) == NULL
,
1526 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
1527 bt_ctf_event_put(event
);
1529 ok(bt_ctf_stream_get_event_context(NULL
) == NULL
,
1530 "bt_ctf_stream_get_event_context handles NULL correctly");
1531 event_context
= bt_ctf_stream_get_event_context(stream
);
1533 "bt_ctf_stream_get_event_context returns a stream event context");
1534 ok(bt_ctf_stream_set_event_context(NULL
, event_context
) < 0,
1535 "bt_ctf_stream_set_event_context handles a NULL stream correctly");
1536 ok(bt_ctf_stream_set_event_context(stream
, NULL
) < 0,
1537 "bt_ctf_stream_set_event_context handles a NULL stream event context correctly");
1538 ok(!bt_ctf_stream_set_event_context(stream
, event_context
),
1539 "bt_ctf_stream_set_event_context correctly set a stream event context");
1540 ret_field
= bt_ctf_field_create(integer_type
);
1541 ok(bt_ctf_stream_set_event_context(stream
, ret_field
) < 0,
1542 "bt_ctf_stream_set_event_context rejects an event context of incorrect type");
1543 bt_ctf_field_put(ret_field
);
1545 for (i
= 0; i
< PACKET_RESIZE_TEST_LENGTH
; i
++) {
1546 event
= bt_ctf_event_create(event_class
);
1547 struct bt_ctf_field
*integer
=
1548 bt_ctf_field_create(integer_type
);
1549 struct bt_ctf_field
*string
=
1550 bt_ctf_field_create(string_type
);
1552 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
1553 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
1554 ret
|= bt_ctf_event_set_payload(event
, "field_1",
1556 bt_ctf_field_put(integer
);
1557 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
1558 ret
|= bt_ctf_event_set_payload(event
, "a_string",
1560 bt_ctf_field_put(string
);
1562 /* Populate stream event context */
1563 integer
= bt_ctf_field_structure_get_field(event_context
,
1564 "common_event_context");
1565 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
,
1567 bt_ctf_field_put(integer
);
1569 ret
|= bt_ctf_stream_append_event(stream
, event
);
1570 bt_ctf_event_put(event
);
1577 events_appended
= !!(i
== PACKET_RESIZE_TEST_LENGTH
);
1578 ok(bt_ctf_stream_get_discarded_events_count(NULL
, &ret_uint64
) < 0,
1579 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
1580 ok(bt_ctf_stream_get_discarded_events_count(stream
, NULL
) < 0,
1581 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
1582 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1583 ok(ret
== 0 && ret_uint64
== 0,
1584 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1585 bt_ctf_stream_append_discarded_events(stream
, 1000);
1586 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1587 ok(ret
== 0 && ret_uint64
== 1000,
1588 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1591 ok(events_appended
, "Append 100 000 events to a stream");
1594 * Populate the custom packet context field with a dummy value
1595 * otherwise flush will fail.
1597 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1598 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1599 "custom_packet_context_field");
1600 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 2);
1602 ok(bt_ctf_stream_flush(stream
) == 0,
1603 "Flush a stream that forces a packet resize");
1604 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1605 ok(ret
== 0 && ret_uint64
== 1000,
1606 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1607 bt_ctf_field_type_put(integer_type
);
1608 bt_ctf_field_type_put(string_type
);
1609 bt_ctf_field_put(packet_context
);
1610 bt_ctf_field_put(packet_context_field
);
1611 bt_ctf_field_put(event_context
);
1612 bt_ctf_event_class_put(event_class
);
1615 void test_empty_stream(struct bt_ctf_writer
*writer
)
1618 struct bt_ctf_trace
*trace
= NULL
;
1619 struct bt_ctf_stream_class
*stream_class
= NULL
;
1620 struct bt_ctf_stream
*stream
= NULL
;
1622 trace
= bt_ctf_writer_get_trace(writer
);
1624 diag("Failed to get trace from writer");
1629 stream_class
= bt_ctf_stream_class_create("empty_stream");
1630 if (!stream_class
) {
1631 diag("Failed to create stream class");
1636 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1638 diag("Failed to create writer stream");
1644 "Created a stream class with default attributes and an empty stream");
1645 bt_ctf_trace_put(trace
);
1646 bt_ctf_stream_put(stream
);
1647 bt_ctf_stream_class_put(stream_class
);
1650 void test_instanciate_event_before_stream(struct bt_ctf_writer
*writer
)
1653 struct bt_ctf_trace
*trace
= NULL
;
1654 struct bt_ctf_clock
*clock
= NULL
;
1655 struct bt_ctf_stream_class
*stream_class
= NULL
;
1656 struct bt_ctf_stream
*stream
= NULL
;
1657 struct bt_ctf_event_class
*event_class
= NULL
;
1658 struct bt_ctf_event
*event
= NULL
;
1659 struct bt_ctf_field_type
*integer_type
= NULL
;
1660 struct bt_ctf_field
*integer
= NULL
;
1662 trace
= bt_ctf_writer_get_trace(writer
);
1664 diag("Failed to get trace from writer");
1669 clock
= bt_ctf_trace_get_clock(trace
, 0);
1671 diag("Failed to get clock from trace");
1676 stream_class
= bt_ctf_stream_class_create("event_before_stream_test");
1677 if (!stream_class
) {
1678 diag("Failed to create stream class");
1683 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1685 diag("Failed to set stream class clock");
1689 event_class
= bt_ctf_event_class_create("some_event_class_name");
1690 integer_type
= bt_ctf_field_type_integer_create(32);
1691 if (!integer_type
) {
1692 diag("Failed to create integer field type");
1697 ret
= bt_ctf_event_class_add_field(event_class
, integer_type
,
1700 diag("Failed to add field to event class");
1704 ret
= bt_ctf_stream_class_add_event_class(stream_class
,
1707 diag("Failed to add event class to stream class");
1710 event
= bt_ctf_event_create(event_class
);
1712 diag("Failed to create event");
1717 integer
= bt_ctf_event_get_payload_by_index(event
, 0);
1719 diag("Failed to get integer field payload from event");
1724 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 1234);
1726 diag("Failed to set integer field value");
1730 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1732 diag("Failed to create writer stream");
1737 ret
= bt_ctf_stream_append_event(stream
, event
);
1739 diag("Failed to append event to stream");
1744 "Create an event before instanciating its associated stream");
1745 bt_ctf_trace_put(trace
);
1746 bt_ctf_stream_put(stream
);
1747 bt_ctf_stream_class_put(stream_class
);
1748 bt_ctf_event_class_put(event_class
);
1749 bt_ctf_event_put(event
);
1750 bt_ctf_field_type_put(integer_type
);
1751 bt_ctf_field_put(integer
);
1752 bt_ctf_clock_put(clock
);
1755 void append_existing_event_class(struct bt_ctf_stream_class
*stream_class
)
1757 struct bt_ctf_event_class
*event_class
;
1759 assert(event_class
= bt_ctf_event_class_create("Simple Event"));
1760 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
1761 "two event classes with the same name cannot cohabit within the same stream class");
1762 bt_ctf_event_class_put(event_class
);
1764 assert(event_class
= bt_ctf_event_class_create("different name, ok"));
1765 assert(!bt_ctf_event_class_set_id(event_class
, 11));
1766 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
1767 "two event classes with the same ID cannot cohabit within the same stream class");
1768 bt_ctf_event_class_put(event_class
);
1771 int main(int argc
, char **argv
)
1773 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
1774 char metadata_path
[sizeof(trace_path
) + 9];
1775 const char *clock_name
= "test_clock";
1776 const char *clock_description
= "This is a test clock";
1777 const char *returned_clock_name
;
1778 const char *returned_clock_description
;
1779 const uint64_t frequency
= 1123456789;
1780 const uint64_t offset_s
= 1351530929945824323;
1781 const uint64_t offset
= 1234567;
1782 const uint64_t precision
= 10;
1783 const int is_absolute
= 0xFF;
1784 char *metadata_string
;
1785 struct bt_ctf_writer
*writer
;
1786 struct utsname name
;
1787 char hostname
[BABELTRACE_HOST_NAME_MAX
];
1788 struct bt_ctf_clock
*clock
, *ret_clock
;
1789 struct bt_ctf_stream_class
*stream_class
, *ret_stream_class
;
1790 struct bt_ctf_stream
*stream1
;
1791 const char *ret_string
;
1792 const unsigned char *ret_uuid
;
1793 unsigned char tmp_uuid
[16] = { 0 };
1794 struct bt_ctf_field_type
*packet_context_type
,
1795 *packet_context_field_type
,
1796 *packet_header_type
,
1797 *packet_header_field_type
,
1799 *stream_event_context_type
,
1801 *event_header_field_type
;
1802 struct bt_ctf_field
*packet_header
, *packet_header_field
;
1803 struct bt_ctf_trace
*trace
;
1805 int64_t ret_int64_t
;
1806 struct bt_object
*obj
;
1809 printf("Usage: tests-ctf-writer path_to_ctf_parser_test path_to_babeltrace\n");
1815 if (!mkdtemp(trace_path
)) {
1819 strcpy(metadata_path
, trace_path
);
1820 strcat(metadata_path
+ sizeof(trace_path
) - 1, "/metadata");
1822 writer
= bt_ctf_writer_create(trace_path
);
1823 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
1825 ok(!bt_ctf_writer_get_trace(NULL
),
1826 "bt_ctf_writer_get_trace correctly handles NULL");
1827 trace
= bt_ctf_writer_get_trace(writer
);
1829 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1830 ok(bt_ctf_trace_set_byte_order(trace
, BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1831 "Set a trace's byte order to big endian");
1832 ok(bt_ctf_trace_get_byte_order(trace
) == BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1833 "bt_ctf_trace_get_byte_order returns a correct endianness");
1835 /* Add environment context to the trace */
1836 ret
= gethostname(hostname
, sizeof(hostname
));
1840 ok(bt_ctf_writer_add_environment_field(writer
, "host", hostname
) == 0,
1841 "Add host (%s) environment field to writer instance",
1843 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
1845 "bt_ctf_writer_add_environment_field error with NULL writer");
1846 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
1848 "bt_ctf_writer_add_environment_field error with NULL field name");
1849 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
1851 "bt_ctf_writer_add_environment_field error with NULL field value");
1853 /* Test bt_ctf_trace_set_environment_field with an integer object */
1854 obj
= bt_object_integer_create_init(23);
1856 ok(bt_ctf_trace_set_environment_field(NULL
, "test_env_int_obj", obj
),
1857 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
1858 ok(bt_ctf_trace_set_environment_field(trace
, NULL
, obj
),
1859 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
1860 ok(bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", NULL
),
1861 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
1862 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", obj
),
1863 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
1866 /* Test bt_ctf_trace_set_environment_field with a string object */
1867 obj
= bt_object_string_create_init("the value");
1869 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_str_obj", obj
),
1870 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
1873 /* Test bt_ctf_trace_set_environment_field_integer */
1874 ok(bt_ctf_trace_set_environment_field_integer(NULL
, "test_env_int",
1876 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
1877 ok(bt_ctf_trace_set_environment_field_integer(trace
, NULL
, -194875),
1878 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
1879 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1881 "bt_ctf_trace_set_environment_field_integer succeeds");
1883 /* Test bt_ctf_trace_set_environment_field_string */
1884 ok(bt_ctf_trace_set_environment_field_string(NULL
, "test_env_str",
1886 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
1887 ok(bt_ctf_trace_set_environment_field_string(trace
, NULL
, "yeah"),
1888 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
1889 ok(bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1891 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
1892 ok(!bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1894 "bt_ctf_trace_set_environment_field_string succeeds");
1896 /* Test bt_ctf_trace_get_environment_field_count */
1897 ok(bt_ctf_trace_get_environment_field_count(NULL
) < 0,
1898 "bt_ctf_trace_get_environment_field_count handles a NULL trace correctly");
1899 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
1900 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
1902 /* Test bt_ctf_trace_get_environment_field_name */
1903 ok(bt_ctf_trace_get_environment_field_name(NULL
, 0) == NULL
,
1904 "bt_ctf_trace_get_environment_field_name handles a NULL trace correctly");
1905 ok(bt_ctf_trace_get_environment_field_name(trace
, -1) == NULL
,
1906 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (negative)");
1907 ok(bt_ctf_trace_get_environment_field_name(trace
, 5) == NULL
,
1908 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (too large)");
1909 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 0);
1910 ok(ret_string
&& !strcmp(ret_string
, "host"),
1911 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1912 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 1);
1913 ok(ret_string
&& !strcmp(ret_string
, "test_env_int_obj"),
1914 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1915 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 2);
1916 ok(ret_string
&& !strcmp(ret_string
, "test_env_str_obj"),
1917 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1918 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 3);
1919 ok(ret_string
&& !strcmp(ret_string
, "test_env_int"),
1920 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1921 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 4);
1922 ok(ret_string
&& !strcmp(ret_string
, "test_env_str"),
1923 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1925 /* Test bt_ctf_trace_get_environment_field_value */
1926 ok(bt_ctf_trace_get_environment_field_value(NULL
, 0) == NULL
,
1927 "bt_ctf_trace_get_environment_field_value handles a NULL trace correctly");
1928 ok(bt_ctf_trace_get_environment_field_value(trace
, -1) == NULL
,
1929 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (negative)");
1930 ok(bt_ctf_trace_get_environment_field_value(trace
, 5) == NULL
,
1931 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (too large)");
1932 obj
= bt_ctf_trace_get_environment_field_value(trace
, 1);
1933 ret
= bt_object_integer_get(obj
, &ret_int64_t
);
1934 ok(!ret
&& ret_int64_t
== 23,
1935 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
1937 obj
= bt_ctf_trace_get_environment_field_value(trace
, 2);
1938 ret
= bt_object_string_get(obj
, &ret_string
);
1939 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "the value"),
1940 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
1943 /* Test bt_ctf_trace_get_environment_field_value_by_name */
1944 ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL
,
1946 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL trace correctly");
1947 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, NULL
),
1948 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL name correctly");
1949 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, "oh oh"),
1950 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
1951 obj
= bt_ctf_trace_get_environment_field_value_by_name(trace
,
1953 ret
= bt_object_string_get(obj
, &ret_string
);
1954 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "oh yeah"),
1955 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
1958 /* Test environment field replacement */
1959 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1961 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
1962 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
1963 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
1964 obj
= bt_ctf_trace_get_environment_field_value(trace
, 3);
1965 ret
= bt_object_integer_get(obj
, &ret_int64_t
);
1966 ok(!ret
&& ret_int64_t
== 654321,
1967 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
1975 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
1976 == 0, "Add sysname (%s) environment field to writer instance",
1978 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
1979 name
.nodename
) == 0,
1980 "Add nodename (%s) environment field to writer instance",
1982 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
1983 == 0, "Add release (%s) environment field to writer instance",
1985 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
1986 == 0, "Add version (%s) environment field to writer instance",
1988 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
1989 == 0, "Add machine (%s) environment field to writer istance",
1992 /* Define a clock and add it to the trace */
1993 ok(bt_ctf_clock_create("signed") == NULL
,
1994 "Illegal clock name rejected");
1995 ok(bt_ctf_clock_create(NULL
) == NULL
, "NULL clock name rejected");
1996 clock
= bt_ctf_clock_create(clock_name
);
1997 ok(clock
, "Clock created sucessfully");
1998 returned_clock_name
= bt_ctf_clock_get_name(clock
);
1999 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
2000 ok(returned_clock_name
? !strcmp(returned_clock_name
, clock_name
) : 0,
2001 "Returned clock name is valid");
2003 returned_clock_description
= bt_ctf_clock_get_description(clock
);
2004 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
2005 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
2006 "Clock description set successfully");
2008 returned_clock_description
= bt_ctf_clock_get_description(clock
);
2009 ok(returned_clock_description
,
2010 "bt_ctf_clock_get_description returns a description.");
2011 ok(returned_clock_description
?
2012 !strcmp(returned_clock_description
, clock_description
) : 0,
2013 "Returned clock description is valid");
2015 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
2016 "bt_ctf_clock_get_frequency returns the correct default frequency");
2017 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
2018 "Set clock frequency");
2019 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
2020 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
2022 ok(bt_ctf_clock_get_offset_s(clock
) == DEFAULT_CLOCK_OFFSET_S
,
2023 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
2024 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
2025 "Set clock offset (seconds)");
2026 ok(bt_ctf_clock_get_offset_s(clock
) == offset_s
,
2027 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
2029 ok(bt_ctf_clock_get_offset(clock
) == DEFAULT_CLOCK_OFFSET
,
2030 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks)");
2031 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
2032 ok(bt_ctf_clock_get_offset(clock
) == offset
,
2033 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks) once it is set");
2035 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
2036 "bt_ctf_clock_get_precision returns the correct default precision");
2037 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
2038 "Set clock precision");
2039 ok(bt_ctf_clock_get_precision(clock
) == precision
,
2040 "bt_ctf_clock_get_precision returns the correct precision once it is set");
2042 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
2043 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
2044 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
2045 "Set clock absolute property");
2046 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
2047 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
2049 ok(bt_ctf_clock_get_time(clock
) == DEFAULT_CLOCK_TIME
,
2050 "bt_ctf_clock_get_time returns the correct default time");
2051 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
2053 ok(bt_ctf_clock_get_time(clock
) == current_time
,
2054 "bt_ctf_clock_get_time returns the correct time once it is set");
2056 ok(bt_ctf_writer_add_clock(writer
, clock
) == 0,
2057 "Add clock to writer instance");
2058 ok(bt_ctf_writer_add_clock(writer
, clock
),
2059 "Verify a clock can't be added twice to a writer instance");
2061 ok(bt_ctf_trace_get_clock_count(NULL
) < 0,
2062 "bt_ctf_trace_get_clock_count correctly handles NULL");
2063 ok(bt_ctf_trace_get_clock_count(trace
) == 1,
2064 "bt_ctf_trace_get_clock_count returns the correct number of clocks");
2065 ok(!bt_ctf_trace_get_clock(NULL
, 0),
2066 "bt_ctf_trace_get_clock correctly handles NULL");
2067 ok(!bt_ctf_trace_get_clock(trace
, -1),
2068 "bt_ctf_trace_get_clock correctly handles negative indexes");
2069 ok(!bt_ctf_trace_get_clock(trace
, 1),
2070 "bt_ctf_trace_get_clock correctly handles out of bound accesses");
2071 ret_clock
= bt_ctf_trace_get_clock(trace
, 0);
2072 ok(ret_clock
== clock
,
2073 "bt_ctf_trace_get_clock returns the right clock instance");
2074 bt_ctf_clock_put(ret_clock
);
2075 ok(!bt_ctf_trace_get_clock_by_name(trace
, NULL
),
2076 "bt_ctf_trace_get_clock_by_name correctly handles NULL (trace)");
2077 ok(!bt_ctf_trace_get_clock_by_name(NULL
, clock_name
),
2078 "bt_ctf_trace_get_clock_by_name correctly handles NULL (clock name)");
2079 ok(!bt_ctf_trace_get_clock_by_name(NULL
, NULL
),
2080 "bt_ctf_trace_get_clock_by_name correctly handles NULL (both)");
2081 ret_clock
= bt_ctf_trace_get_clock_by_name(trace
, clock_name
);
2082 ok(ret_clock
== clock
,
2083 "bt_ctf_trace_get_clock_by_name returns the right clock instance");
2084 bt_ctf_clock_put(ret_clock
);
2085 ok(!bt_ctf_trace_get_clock_by_name(trace
, "random"),
2086 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
2088 ok(!bt_ctf_clock_get_name(NULL
),
2089 "bt_ctf_clock_get_name correctly handles NULL");
2090 ok(!bt_ctf_clock_get_description(NULL
),
2091 "bt_ctf_clock_get_description correctly handles NULL");
2092 ok(bt_ctf_clock_get_frequency(NULL
) == -1ULL,
2093 "bt_ctf_clock_get_frequency correctly handles NULL");
2094 ok(bt_ctf_clock_get_precision(NULL
) == -1ULL,
2095 "bt_ctf_clock_get_precision correctly handles NULL");
2096 ok(bt_ctf_clock_get_offset_s(NULL
) == -1ULL,
2097 "bt_ctf_clock_get_offset_s correctly handles NULL");
2098 ok(bt_ctf_clock_get_offset(NULL
) == -1ULL,
2099 "bt_ctf_clock_get_offset correctly handles NULL");
2100 ok(bt_ctf_clock_get_is_absolute(NULL
) < 0,
2101 "bt_ctf_clock_get_is_absolute correctly handles NULL");
2102 ok(bt_ctf_clock_get_time(NULL
) == -1ULL,
2103 "bt_ctf_clock_get_time correctly handles NULL");
2105 ok(bt_ctf_clock_set_description(NULL
, NULL
) < 0,
2106 "bt_ctf_clock_set_description correctly handles NULL clock");
2107 ok(bt_ctf_clock_set_frequency(NULL
, frequency
) < 0,
2108 "bt_ctf_clock_set_frequency correctly handles NULL clock");
2109 ok(bt_ctf_clock_set_precision(NULL
, precision
) < 0,
2110 "bt_ctf_clock_get_precision correctly handles NULL clock");
2111 ok(bt_ctf_clock_set_offset_s(NULL
, offset_s
) < 0,
2112 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
2113 ok(bt_ctf_clock_set_offset(NULL
, offset
) < 0,
2114 "bt_ctf_clock_set_offset correctly handles NULL clock");
2115 ok(bt_ctf_clock_set_is_absolute(NULL
, is_absolute
) < 0,
2116 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
2117 ok(bt_ctf_clock_set_time(NULL
, current_time
) < 0,
2118 "bt_ctf_clock_set_time correctly handles NULL clock");
2119 ok(bt_ctf_clock_get_uuid(NULL
) == NULL
,
2120 "bt_ctf_clock_get_uuid correctly handles NULL clock");
2121 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
2123 "bt_ctf_clock_get_uuid returns a UUID");
2125 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
2126 /* Slightly modify UUID */
2127 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
2130 ok(bt_ctf_clock_set_uuid(NULL
, tmp_uuid
) < 0,
2131 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
2132 ok(bt_ctf_clock_set_uuid(clock
, NULL
) < 0,
2133 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
2134 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
2135 "bt_ctf_clock_set_uuid sets a new uuid succesfully");
2136 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
2138 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
2139 ok(uuid_match(ret_uuid
, tmp_uuid
),
2140 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
2142 /* Define a stream class */
2143 stream_class
= bt_ctf_stream_class_create("test_stream");
2145 ok(bt_ctf_stream_class_get_name(NULL
) == NULL
,
2146 "bt_ctf_stream_class_get_name handles NULL correctly");
2147 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
2148 ok(ret_string
&& !strcmp(ret_string
, "test_stream"),
2149 "bt_ctf_stream_class_get_name returns a correct stream class name");
2151 ok(bt_ctf_stream_class_get_clock(stream_class
) == NULL
,
2152 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
2153 ok(bt_ctf_stream_class_get_clock(NULL
) == NULL
,
2154 "bt_ctf_stream_class_get_clock handles NULL correctly");
2156 ok(stream_class
, "Create stream class");
2157 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
2158 "Set a stream class' clock");
2159 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
2160 ok(ret_clock
== clock
,
2161 "bt_ctf_stream_class_get_clock returns a correct clock");
2162 bt_ctf_clock_put(ret_clock
);
2164 /* Test the event fields and event types APIs */
2167 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
2168 "bt_ctf_stream_class_get_id returns an error when no id is set");
2169 ok(bt_ctf_stream_class_get_id(NULL
) < 0,
2170 "bt_ctf_stream_class_get_id handles NULL correctly");
2171 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
2172 "bt_ctf_stream_class_set_id handles NULL correctly");
2173 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
2174 "Set an stream class' id");
2175 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
2176 "bt_ctf_stream_class_get_id returns the correct value");
2178 /* Validate default event header fields */
2179 ok(bt_ctf_stream_class_get_event_header_type(NULL
) == NULL
,
2180 "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
2181 ret_field_type
= bt_ctf_stream_class_get_event_header_type(
2184 "bt_ctf_stream_class_get_event_header_type returns an event header type");
2185 ok(bt_ctf_field_type_get_type_id(ret_field_type
) == CTF_TYPE_STRUCT
,
2186 "Default event header type is a structure");
2187 event_header_field_type
=
2188 bt_ctf_field_type_structure_get_field_type_by_name(
2189 ret_field_type
, "id");
2190 ok(event_header_field_type
,
2191 "Default event header type contains an \"id\" field");
2192 ok(bt_ctf_field_type_get_type_id(
2193 event_header_field_type
) == CTF_TYPE_INTEGER
,
2194 "Default event header \"id\" field is an integer");
2195 bt_ctf_field_type_put(event_header_field_type
);
2196 event_header_field_type
=
2197 bt_ctf_field_type_structure_get_field_type_by_name(
2198 ret_field_type
, "timestamp");
2199 ok(event_header_field_type
,
2200 "Default event header type contains a \"timestamp\" field");
2201 ok(bt_ctf_field_type_get_type_id(
2202 event_header_field_type
) == CTF_TYPE_INTEGER
,
2203 "Default event header \"timestamp\" field is an integer");
2204 bt_ctf_field_type_put(event_header_field_type
);
2205 bt_ctf_field_type_put(ret_field_type
);
2207 /* Add a custom trace packet header field */
2208 ok(bt_ctf_trace_get_packet_header_type(NULL
) == NULL
,
2209 "bt_ctf_trace_get_packet_header_type handles NULL correctly");
2210 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
2211 ok(packet_header_type
,
2212 "bt_ctf_trace_get_packet_header_type returns a packet header");
2213 ok(bt_ctf_field_type_get_type_id(packet_header_type
) == CTF_TYPE_STRUCT
,
2214 "bt_ctf_trace_get_packet_header_type returns a packet header of type struct");
2215 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2216 packet_header_type
, "magic");
2217 ok(ret_field_type
, "Default packet header type contains a \"magic\" field");
2218 bt_ctf_field_type_put(ret_field_type
);
2219 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2220 packet_header_type
, "uuid");
2221 ok(ret_field_type
, "Default packet header type contains a \"uuid\" field");
2222 bt_ctf_field_type_put(ret_field_type
);
2223 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2224 packet_header_type
, "stream_id");
2225 ok(ret_field_type
, "Default packet header type contains a \"stream_id\" field");
2226 bt_ctf_field_type_put(ret_field_type
);
2228 packet_header_field_type
= bt_ctf_field_type_integer_create(22);
2229 ok(!bt_ctf_field_type_structure_add_field(packet_header_type
,
2230 packet_header_field_type
, "custom_trace_packet_header_field"),
2231 "Added a custom trace packet header field successfully");
2233 ok(bt_ctf_trace_set_packet_header_type(NULL
, packet_header_type
) < 0,
2234 "bt_ctf_trace_set_packet_header_type handles a NULL trace correctly");
2235 ok(bt_ctf_trace_set_packet_header_type(trace
, NULL
) < 0,
2236 "bt_ctf_trace_set_packet_header_type handles a NULL packet_header_type correctly");
2237 ok(!bt_ctf_trace_set_packet_header_type(trace
, packet_header_type
),
2238 "Set a trace packet_header_type successfully");
2240 ok(bt_ctf_stream_class_get_packet_context_type(NULL
) == NULL
,
2241 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
2243 /* Add a custom field to the stream class' packet context */
2244 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
2245 ok(packet_context_type
,
2246 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
2247 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == CTF_TYPE_STRUCT
,
2248 "Packet context is a structure");
2250 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
2251 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
2252 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
),
2253 "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly");
2255 integer_type
= bt_ctf_field_type_integer_create(32);
2256 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
2258 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
2259 /* Create a "uint5_t" equivalent custom packet context field */
2260 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
2262 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
2263 packet_context_field_type
, "custom_packet_context_field");
2264 ok(ret
== 0, "Packet context field added successfully");
2266 /* Define a stream event context containing a my_integer field. */
2267 ok(bt_ctf_stream_class_get_event_context_type(NULL
) == NULL
,
2268 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
2269 ok(bt_ctf_stream_class_get_event_context_type(
2270 stream_class
) == NULL
,
2271 "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set.");
2272 stream_event_context_type
= bt_ctf_field_type_structure_create();
2273 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
2274 integer_type
, "common_event_context");
2276 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
2277 stream_event_context_type
) < 0,
2278 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
2279 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
2281 "bt_ctf_stream_class_set_event_context_type handles a NULL event_context correctly");
2282 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
2284 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
2286 ok(bt_ctf_stream_class_set_event_context_type(
2287 stream_class
, stream_event_context_type
) == 0,
2288 "Set a new stream event context type");
2289 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
2291 ok(ret_field_type
== stream_event_context_type
,
2292 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
2293 bt_ctf_field_type_put(ret_field_type
);
2295 /* Instantiate a stream and append events */
2296 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
2297 ok(stream1
, "Instanciate a stream class from writer");
2299 ok(bt_ctf_stream_get_class(NULL
) == NULL
,
2300 "bt_ctf_stream_get_class correctly handles NULL");
2301 ret_stream_class
= bt_ctf_stream_get_class(stream1
);
2302 ok(ret_stream_class
,
2303 "bt_ctf_stream_get_class returns a stream class");
2304 ok(ret_stream_class
== stream_class
,
2305 "Returned stream class is of the correct type");
2308 * Try to modify the packet context type after a stream has been
2311 ret
= bt_ctf_field_type_structure_add_field(packet_header_type
,
2312 packet_header_field_type
, "should_fail");
2314 "Trace packet header type can't be modified once a stream has been instanciated");
2317 * Try to modify the packet context type after a stream has been
2320 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
2321 packet_context_field_type
, "should_fail");
2323 "Packet context type can't be modified once a stream has been instanciated");
2326 * Try to modify the stream event context type after a stream has been
2329 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
2330 integer_type
, "should_fail");
2332 "Stream event context type can't be modified once a stream has been instanciated");
2334 /* Should fail after instanciating a stream (frozen) */
2335 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
2336 "Changes to a stream class that was already instantiated fail");
2338 /* Populate the custom packet header field only once for all tests */
2339 ok(bt_ctf_stream_get_packet_header(NULL
) == NULL
,
2340 "bt_ctf_stream_get_packet_header handles NULL correctly");
2341 packet_header
= bt_ctf_stream_get_packet_header(stream1
);
2343 "bt_ctf_stream_get_packet_header returns a packet header");
2344 ret_field_type
= bt_ctf_field_get_type(packet_header
);
2345 ok(ret_field_type
== packet_header_type
,
2346 "Stream returns a packet header of the appropriate type");
2347 bt_ctf_field_type_put(ret_field_type
);
2348 packet_header_field
= bt_ctf_field_structure_get_field(packet_header
,
2349 "custom_trace_packet_header_field");
2350 ok(packet_header_field
,
2351 "Packet header structure contains a custom field with the appropriate name");
2352 ret_field_type
= bt_ctf_field_get_type(packet_header_field
);
2353 ok(ret_field_type
== packet_header_field_type
,
2354 "Custom packet header field is of the expected type");
2355 ok(!bt_ctf_field_unsigned_integer_set_value(packet_header_field
,
2356 54321), "Set custom packet header value successfully");
2357 ok(bt_ctf_stream_set_packet_header(stream1
, NULL
) < 0,
2358 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
2359 ok(bt_ctf_stream_set_packet_header(NULL
, packet_header
) < 0,
2360 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
2361 ok(bt_ctf_stream_set_packet_header(stream1
, packet_header_field
) < 0,
2362 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
2363 ok(!bt_ctf_stream_set_packet_header(stream1
, packet_header
),
2364 "Successfully set a stream's packet header");
2366 test_instanciate_event_before_stream(writer
);
2368 append_simple_event(stream_class
, stream1
, clock
);
2370 packet_resize_test(stream_class
, stream1
, clock
);
2372 append_complex_event(stream_class
, stream1
, clock
);
2374 append_existing_event_class(stream_class
);
2376 test_empty_stream(writer
);
2378 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
2379 ok(metadata_string
, "Get metadata string");
2381 bt_ctf_writer_flush_metadata(writer
);
2382 validate_metadata(argv
[1], metadata_path
);
2383 validate_trace(argv
[2], trace_path
);
2385 bt_ctf_clock_put(clock
);
2386 bt_ctf_stream_class_put(stream_class
);
2387 bt_ctf_stream_class_put(ret_stream_class
);
2388 bt_ctf_writer_put(writer
);
2389 bt_ctf_stream_put(stream1
);
2390 bt_ctf_field_type_put(packet_context_type
);
2391 bt_ctf_field_type_put(packet_context_field_type
);
2392 bt_ctf_field_type_put(integer_type
);
2393 bt_ctf_field_type_put(stream_event_context_type
);
2394 bt_ctf_field_type_put(ret_field_type
);
2395 bt_ctf_field_type_put(packet_header_type
);
2396 bt_ctf_field_type_put(packet_header_field_type
);
2397 bt_ctf_field_put(packet_header
);
2398 bt_ctf_field_put(packet_header_field
);
2399 bt_ctf_trace_put(trace
);
2400 free(metadata_string
);
2402 /* Remove all trace files and delete temporary trace directory */
2403 DIR *trace_dir
= opendir(trace_path
);
2405 perror("# opendir");
2409 struct dirent
*entry
;
2410 while ((entry
= readdir(trace_dir
))) {
2411 if (entry
->d_type
== DT_REG
) {
2412 unlinkat(dirfd(trace_dir
), entry
->d_name
, 0);
2417 closedir(trace_dir
);