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(ret_char
&& !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_1
= "Test ";
671 const char *test_string_2
= "string";
672 const char *test_string_cat
= "Test string";
673 struct bt_ctf_field_type
*uint_35_type
=
674 bt_ctf_field_type_integer_create(35);
675 struct bt_ctf_field_type
*int_16_type
=
676 bt_ctf_field_type_integer_create(16);
677 struct bt_ctf_field_type
*uint_3_type
=
678 bt_ctf_field_type_integer_create(3);
679 struct bt_ctf_field_type
*enum_variant_type
=
680 bt_ctf_field_type_enumeration_create(uint_3_type
);
681 struct bt_ctf_field_type
*variant_type
=
682 bt_ctf_field_type_variant_create(enum_variant_type
,
684 struct bt_ctf_field_type
*string_type
=
685 bt_ctf_field_type_string_create();
686 struct bt_ctf_field_type
*sequence_type
;
687 struct bt_ctf_field_type
*array_type
;
688 struct bt_ctf_field_type
*inner_structure_type
=
689 bt_ctf_field_type_structure_create();
690 struct bt_ctf_field_type
*complex_structure_type
=
691 bt_ctf_field_type_structure_create();
692 struct bt_ctf_field_type
*ret_field_type
;
693 struct bt_ctf_event_class
*event_class
;
694 struct bt_ctf_event
*event
;
695 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
696 *inner_structure_field
, *complex_structure_field
,
697 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
698 *variant_field
, *an_array_field
, *ret_field
;
699 uint64_t ret_unsigned_int
;
700 int64_t ret_signed_int
;
701 const char *ret_string
;
702 struct bt_ctf_stream_class
*ret_stream_class
;
703 struct bt_ctf_event_class
*ret_event_class
;
704 struct bt_ctf_field
*packet_context
, *packet_context_field
;
705 struct bt_object
*obj
;
707 bt_ctf_field_type_set_alignment(int_16_type
, 32);
708 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
709 bt_ctf_field_type_integer_set_base(uint_35_type
,
710 BT_CTF_INTEGER_BASE_HEXADECIMAL
);
712 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
713 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
716 ok(bt_ctf_field_type_array_get_element_type(NULL
) == NULL
,
717 "bt_ctf_field_type_array_get_element_type handles NULL correctly");
718 ret_field_type
= bt_ctf_field_type_array_get_element_type(
720 ok(ret_field_type
== int_16_type
,
721 "bt_ctf_field_type_array_get_element_type returns the correct type");
722 bt_ctf_field_type_put(ret_field_type
);
724 ok(bt_ctf_field_type_array_get_length(NULL
) < 0,
725 "bt_ctf_field_type_array_get_length handles NULL correctly");
726 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
727 "bt_ctf_field_type_array_get_length returns the correct length");
729 bt_ctf_field_type_structure_add_field(inner_structure_type
,
730 uint_35_type
, "seq_len");
731 bt_ctf_field_type_structure_add_field(inner_structure_type
,
732 sequence_type
, "a_sequence");
733 bt_ctf_field_type_structure_add_field(inner_structure_type
,
734 array_type
, "an_array");
736 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
738 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
740 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
741 "UINT35_TYPE", 2, 7);
743 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL
,
745 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly");
746 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
747 enum_variant_type
, NULL
) < 0,
748 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly");
749 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
750 enum_variant_type
, "INT16_TYPE") == 1,
751 "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index");
753 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL
, 1) < 0,
754 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly");
755 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, -42) < 0,
756 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly");
757 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, 5) == 2,
758 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index");
760 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
761 "An unknown entry"), "Reject a variant field based on an unknown tag value");
762 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
763 "UINT3_TYPE") == 0, "Add a field to a variant");
764 bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
766 bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
769 ok(bt_ctf_field_type_variant_get_tag_type(NULL
) == NULL
,
770 "bt_ctf_field_type_variant_get_tag_type handles NULL correctly");
771 ret_field_type
= bt_ctf_field_type_variant_get_tag_type(variant_type
);
772 ok(ret_field_type
== enum_variant_type
,
773 "bt_ctf_field_type_variant_get_tag_type returns a correct tag type");
774 bt_ctf_field_type_put(ret_field_type
);
776 ok(bt_ctf_field_type_variant_get_tag_name(NULL
) == NULL
,
777 "bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
778 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
779 ok(!strcmp(ret_string
, "variant_selector"),
780 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
781 ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL
,
782 "INT16_TYPE") == NULL
,
783 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
784 ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type
,
786 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
787 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
788 variant_type
, "INT16_TYPE");
789 ok(ret_field_type
== int_16_type
,
790 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
791 bt_ctf_field_type_put(ret_field_type
);
793 ok(bt_ctf_field_type_variant_get_field_count(NULL
) < 0,
794 "bt_ctf_field_type_variant_get_field_count handles NULL correctly");
795 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
796 "bt_ctf_field_type_variant_get_field_count returns the correct count");
798 ok(bt_ctf_field_type_variant_get_field(NULL
, &ret_string
, &ret_field_type
, 0) < 0,
799 "bt_ctf_field_type_variant_get_field handles a NULL type correctly");
800 ok(bt_ctf_field_type_variant_get_field(variant_type
, NULL
, &ret_field_type
, 0) < 0,
801 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
802 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, NULL
, 0) < 0,
803 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
804 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 200) < 0,
805 "bt_ctf_field_type_variant_get_field handles an invalid index correctly");
806 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
807 "bt_ctf_field_type_variant_get_field returns a field");
808 ok(!strcmp("INT16_TYPE", ret_string
),
809 "bt_ctf_field_type_variant_get_field returns a correct field name");
810 ok(ret_field_type
== int_16_type
,
811 "bt_ctf_field_type_variant_get_field returns a correct field type");
812 bt_ctf_field_type_put(ret_field_type
);
814 bt_ctf_field_type_structure_add_field(complex_structure_type
,
815 enum_variant_type
, "variant_selector");
816 bt_ctf_field_type_structure_add_field(complex_structure_type
,
817 string_type
, "a_string");
818 bt_ctf_field_type_structure_add_field(complex_structure_type
,
819 variant_type
, "variant_value");
820 bt_ctf_field_type_structure_add_field(complex_structure_type
,
821 inner_structure_type
, "inner_structure");
823 ok(bt_ctf_event_class_create("clock") == NULL
,
824 "Reject creation of an event class with an illegal name");
825 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
826 ok(event_class
, "Create an event class");
827 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
828 "Reject addition of a field with an empty name to an event");
829 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
830 "Reject addition of a field with a NULL type to an event");
831 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
833 "Reject addition of a type with an illegal name to an event");
834 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
836 "Add field of type unsigned integer to an event");
837 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
838 "int_16") == 0, "Add field of type signed integer to an event");
839 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
840 "complex_structure") == 0,
841 "Add composite structure to an event");
843 ok(bt_ctf_event_class_get_name(NULL
) == NULL
,
844 "bt_ctf_event_class_get_name handles NULL correctly");
845 ret_string
= bt_ctf_event_class_get_name(event_class
);
846 ok(!strcmp(ret_string
, complex_test_event_string
),
847 "bt_ctf_event_class_get_name returns a correct name");
848 ok(bt_ctf_event_class_get_id(event_class
) < 0,
849 "bt_ctf_event_class_get_id returns a negative value when not set");
850 ok(bt_ctf_event_class_get_id(NULL
) < 0,
851 "bt_ctf_event_class_get_id handles NULL correctly");
852 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
853 "bt_ctf_event_class_set_id handles NULL correctly");
854 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
855 "Set an event class' id");
856 ok(bt_ctf_event_class_get_id(event_class
) == 42,
857 "bt_ctf_event_class_get_id returns the correct value");
859 /* Test event class attributes */
860 assert(obj
= bt_object_integer_create_init(15));
861 ok(bt_ctf_event_class_set_attribute(NULL
, "id", obj
),
862 "bt_ctf_event_class_set_attribute handles a NULL event class correctly");
863 ok(bt_ctf_event_class_set_attribute(event_class
, NULL
, obj
),
864 "bt_ctf_event_class_set_attribute handles a NULL name correctly");
865 ok(bt_ctf_event_class_set_attribute(event_class
, "id", NULL
),
866 "bt_ctf_event_class_set_attribute handles a NULL value correctly");
867 assert(!bt_object_integer_set(obj
, -3));
868 ok(bt_ctf_event_class_set_attribute(event_class
, "id", obj
),
869 "bt_ctf_event_class_set_attribute fails with a negative \"id\" attribute");
870 assert(!bt_object_integer_set(obj
, 11));
871 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
872 ok(!ret
&& bt_ctf_event_class_get_id(event_class
) == 11,
873 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"id\" attribute");
874 ret
= bt_ctf_event_class_set_attribute(event_class
, "name", obj
);
875 ret
&= bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
);
877 "bt_ctf_event_class_set_attribute cannot set \"name\" or \"model.emf.uri\" to an integer value");
880 obj
= bt_object_integer_create_init(5);
882 ok(!bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
),
883 "bt_ctf_event_class_set_attribute succeeds in setting the \"loglevel\" attribute");
885 ok(!bt_ctf_event_class_get_attribute_value_by_name(NULL
, "loglevel"),
886 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL event class correctly");
887 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, NULL
),
888 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL name correctly");
889 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, "meow"),
890 "bt_ctf_event_class_get_attribute_value_by_name fails with a non-existing attribute name");
891 obj
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
894 ret
= bt_object_integer_get(obj
, &int64_value
);
895 ok(obj
&& !ret
&& int64_value
== 5,
896 "bt_ctf_event_class_get_attribute_value_by_name returns the correct value");
899 assert(obj
= bt_object_string_create_init("nu name"));
900 assert(!bt_ctf_event_class_set_attribute(event_class
, "name", obj
));
901 ret_string
= bt_ctf_event_class_get_name(event_class
);
902 ok(!strcmp(ret_string
, "nu name"),
903 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"name\" attribute");
904 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
905 ret
&= bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
);
907 "bt_ctf_event_class_set_attribute cannot set \"id\" or \"loglevel\" to a string value");
909 obj
= bt_object_string_create_init("http://kernel.org/");
911 assert(!bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
));
914 ok(bt_ctf_event_class_get_attribute_count(NULL
),
915 "bt_ctf_event_class_get_attribute_count handles a NULL event class");
916 ok(bt_ctf_event_class_get_attribute_count(event_class
) == 4,
917 "bt_ctf_event_class_get_attribute_count returns the correct count");
918 ok(!bt_ctf_event_class_get_attribute_name(NULL
, 0),
919 "bt_ctf_event_class_get_attribute_name handles a NULL event class correctly");
920 ok(!bt_ctf_event_class_get_attribute_name(event_class
, 4),
921 "bt_ctf_event_class_get_attribute_name handles a too large index correctly");
922 ok(!bt_ctf_event_class_get_attribute_value(NULL
, 0),
923 "bt_ctf_event_class_get_attribute_value handles a NULL event class correctly");
924 ok(!bt_ctf_event_class_get_attribute_value(event_class
, 4),
925 "bt_ctf_event_class_get_attribute_value handles a too large index correctly");
927 memset(&attrs_count
, 0, sizeof(attrs_count
));
929 for (i
= 0; i
< 4; ++i
) {
930 ret_string
= bt_ctf_event_class_get_attribute_name(event_class
,
932 obj
= bt_ctf_event_class_get_attribute_value(event_class
, i
);
933 assert(ret_string
&& obj
);
935 if (!strcmp(ret_string
, "id")) {
937 ok(bt_object_is_integer(obj
),
938 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
940 } else if (!strcmp(ret_string
, "name")) {
942 ok(bt_object_is_string(obj
),
943 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
945 } else if (!strcmp(ret_string
, "loglevel")) {
946 attrs_count
.loglevel
++;
947 ok(bt_object_is_integer(obj
),
948 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
950 } else if (!strcmp(ret_string
, "model.emf.uri")) {
951 attrs_count
.modelemfuri
++;
952 ok(bt_object_is_string(obj
),
953 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
956 attrs_count
.unknown
++;
962 ok(attrs_count
.unknown
== 0, "event class has no unknown attributes");
963 ok(attrs_count
.id
== 1 && attrs_count
.name
== 1 &&
964 attrs_count
.loglevel
== 1 && attrs_count
.modelemfuri
== 1,
965 "event class has one instance of each known attribute");
967 /* Add event class to the stream class */
968 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
969 "Reject addition of NULL event class to a stream class");
970 ok(bt_ctf_stream_class_add_event_class(stream_class
,
971 event_class
) == 0, "Add an event class to stream class");
973 ok(bt_ctf_event_class_get_stream_class(NULL
) == NULL
,
974 "bt_ctf_event_class_get_stream_class handles NULL correctly");
975 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
976 ok(ret_stream_class
== stream_class
,
977 "bt_ctf_event_class_get_stream_class returns the correct stream class");
978 bt_ctf_stream_class_put(ret_stream_class
);
980 ok(bt_ctf_event_class_get_field_count(NULL
) < 0,
981 "bt_ctf_event_class_get_field_count handles NULL correctly");
982 ok(bt_ctf_event_class_get_field_count(event_class
) == 3,
983 "bt_ctf_event_class_get_field_count returns a correct value");
985 ok(bt_ctf_event_class_get_field(NULL
, &ret_string
,
986 &ret_field_type
, 0) < 0,
987 "bt_ctf_event_class_get_field handles a NULL event class correctly");
988 ok(bt_ctf_event_class_get_field(event_class
, NULL
,
989 &ret_field_type
, 0) < 0,
990 "bt_ctf_event_class_get_field handles a NULL field name correctly");
991 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
993 "bt_ctf_event_class_get_field handles a NULL field type correctly");
994 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
995 &ret_field_type
, 42) < 0,
996 "bt_ctf_event_class_get_field handles an invalid index correctly");
997 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
998 &ret_field_type
, 0) == 0,
999 "bt_ctf_event_class_get_field returns a field");
1000 ok(ret_field_type
== uint_35_type
,
1001 "bt_ctf_event_class_get_field returns a correct field type");
1002 bt_ctf_field_type_put(ret_field_type
);
1003 ok(!strcmp(ret_string
, "uint_35"),
1004 "bt_ctf_event_class_get_field returns a correct field name");
1005 ok(bt_ctf_event_class_get_field_by_name(NULL
, "") == NULL
,
1006 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
1007 ok(bt_ctf_event_class_get_field_by_name(event_class
, NULL
) == NULL
,
1008 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
1009 ok(bt_ctf_event_class_get_field_by_name(event_class
, "truie") == NULL
,
1010 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
1011 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
1012 "complex_structure");
1013 ok(ret_field_type
== complex_structure_type
,
1014 "bt_ctf_event_class_get_field_by_name returns a correct field type");
1015 bt_ctf_field_type_put(ret_field_type
);
1017 event
= bt_ctf_event_create(event_class
);
1018 ok(event
, "Instanciate a complex event");
1020 ok(bt_ctf_event_get_class(NULL
) == NULL
,
1021 "bt_ctf_event_get_class handles NULL correctly");
1022 ret_event_class
= bt_ctf_event_get_class(event
);
1023 ok(ret_event_class
== event_class
,
1024 "bt_ctf_event_get_class returns the correct event class");
1025 bt_ctf_event_class_put(ret_event_class
);
1027 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
1028 if (!uint_35_field
) {
1029 printf("uint_35_field is NULL\n");
1032 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
1033 bt_ctf_field_unsigned_integer_set_value(uint_35_field
, 0x0DDF00D);
1034 ok(bt_ctf_field_unsigned_integer_get_value(NULL
, &ret_unsigned_int
) < 0,
1035 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
1036 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
, NULL
) < 0,
1037 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
1038 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
,
1039 &ret_unsigned_int
) == 0,
1040 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
1041 ok(ret_unsigned_int
== 0x0DDF00D,
1042 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
1043 ok(bt_ctf_field_signed_integer_get_value(uint_35_field
,
1044 &ret_signed_int
) < 0,
1045 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
1046 bt_ctf_field_put(uint_35_field
);
1048 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
1049 bt_ctf_field_signed_integer_set_value(int_16_field
, -12345);
1050 ok(bt_ctf_field_signed_integer_get_value(NULL
, &ret_signed_int
) < 0,
1051 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
1052 ok(bt_ctf_field_signed_integer_get_value(int_16_field
, NULL
) < 0,
1053 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
1054 ok(bt_ctf_field_signed_integer_get_value(int_16_field
,
1055 &ret_signed_int
) == 0,
1056 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
1057 ok(ret_signed_int
== -12345,
1058 "bt_ctf_field_signed_integer_get_value returns the correct value");
1059 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field
,
1060 &ret_unsigned_int
) < 0,
1061 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
1062 bt_ctf_field_put(int_16_field
);
1064 complex_structure_field
= bt_ctf_event_get_payload(event
,
1065 "complex_structure");
1067 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 0) == NULL
,
1068 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
1069 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 9) == NULL
,
1070 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
1071 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
1072 complex_structure_field
, 3);
1073 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
1074 bt_ctf_field_put(inner_structure_field
);
1075 ok(ret_field_type
== inner_structure_type
,
1076 "bt_ctf_field_structure_get_field_by_index returns a correct field");
1077 bt_ctf_field_type_put(ret_field_type
);
1079 inner_structure_field
= bt_ctf_field_structure_get_field(
1080 complex_structure_field
, "inner_structure");
1081 a_string_field
= bt_ctf_field_structure_get_field(
1082 complex_structure_field
, "a_string");
1083 enum_variant_field
= bt_ctf_field_structure_get_field(
1084 complex_structure_field
, "variant_selector");
1085 variant_field
= bt_ctf_field_structure_get_field(
1086 complex_structure_field
, "variant_value");
1087 uint_35_field
= bt_ctf_field_structure_get_field(
1088 inner_structure_field
, "seq_len");
1089 a_sequence_field
= bt_ctf_field_structure_get_field(
1090 inner_structure_field
, "a_sequence");
1091 an_array_field
= bt_ctf_field_structure_get_field(
1092 inner_structure_field
, "an_array");
1094 enum_container_field
= bt_ctf_field_enumeration_get_container(
1095 enum_variant_field
);
1096 bt_ctf_field_unsigned_integer_set_value(enum_container_field
, 1);
1097 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
1098 enum_variant_field
);
1099 bt_ctf_field_signed_integer_set_value(int_16_field
, -200);
1100 bt_ctf_field_put(int_16_field
);
1101 ok(!bt_ctf_field_string_get_value(a_string_field
),
1102 "bt_ctf_field_string_get_value returns NULL on an unset field");
1103 bt_ctf_field_string_set_value(a_string_field
,
1105 ok(!bt_ctf_field_string_get_value(NULL
),
1106 "bt_ctf_field_string_get_value correctly handles NULL");
1107 ok(bt_ctf_field_string_append(NULL
, "yeah"),
1108 "bt_ctf_field_string_append correctly handles a NULL string field");
1109 ok(bt_ctf_field_string_append(a_string_field
, NULL
),
1110 "bt_ctf_field_string_append correctly handles a NULL string value");
1111 ok(!bt_ctf_field_string_append(a_string_field
, test_string_2
),
1112 "bt_ctf_field_string_append succeeds");
1113 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
1114 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
1115 ok(ret_string
? !strcmp(ret_string
, test_string_cat
) : 0,
1116 "bt_ctf_field_string_get_value returns a correct value");
1117 bt_ctf_field_unsigned_integer_set_value(uint_35_field
,
1118 SEQUENCE_TEST_LENGTH
);
1120 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL
,
1121 enum_container_field
) == NULL
,
1122 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
1123 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type
,
1125 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
1126 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
1127 variant_type
, enum_variant_field
);
1128 ok(ret_field_type
== int_16_type
,
1129 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
1131 ok(bt_ctf_field_sequence_get_length(a_sequence_field
) == NULL
,
1132 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
1133 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
1134 uint_35_field
) == 0, "Set a sequence field's length");
1135 ret_field
= bt_ctf_field_sequence_get_length(a_sequence_field
);
1136 ok(ret_field
== uint_35_field
,
1137 "bt_ctf_field_sequence_get_length returns the correct length field");
1138 ok(bt_ctf_field_sequence_get_length(NULL
) == NULL
,
1139 "bt_ctf_field_sequence_get_length properly handles NULL");
1141 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
1142 int_16_field
= bt_ctf_field_sequence_get_field(
1143 a_sequence_field
, i
);
1144 bt_ctf_field_signed_integer_set_value(int_16_field
, 4 - i
);
1145 bt_ctf_field_put(int_16_field
);
1148 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
1149 int_16_field
= bt_ctf_field_array_get_field(
1151 bt_ctf_field_signed_integer_set_value(int_16_field
, i
);
1152 bt_ctf_field_put(int_16_field
);
1155 bt_ctf_clock_set_time(clock
, ++current_time
);
1156 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
1157 "Append a complex event to a stream");
1160 * Populate the custom packet context field with a dummy value
1161 * otherwise flush will fail.
1163 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1164 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1165 "custom_packet_context_field");
1166 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 1);
1168 ok(bt_ctf_stream_flush(stream
) == 0,
1169 "Flush a stream containing a complex event");
1171 bt_ctf_field_put(uint_35_field
);
1172 bt_ctf_field_put(a_string_field
);
1173 bt_ctf_field_put(inner_structure_field
);
1174 bt_ctf_field_put(complex_structure_field
);
1175 bt_ctf_field_put(a_sequence_field
);
1176 bt_ctf_field_put(an_array_field
);
1177 bt_ctf_field_put(enum_variant_field
);
1178 bt_ctf_field_put(enum_container_field
);
1179 bt_ctf_field_put(variant_field
);
1180 bt_ctf_field_put(ret_field
);
1181 bt_ctf_field_put(packet_context_field
);
1182 bt_ctf_field_put(packet_context
);
1183 bt_ctf_field_type_put(uint_35_type
);
1184 bt_ctf_field_type_put(int_16_type
);
1185 bt_ctf_field_type_put(string_type
);
1186 bt_ctf_field_type_put(sequence_type
);
1187 bt_ctf_field_type_put(array_type
);
1188 bt_ctf_field_type_put(inner_structure_type
);
1189 bt_ctf_field_type_put(complex_structure_type
);
1190 bt_ctf_field_type_put(uint_3_type
);
1191 bt_ctf_field_type_put(enum_variant_type
);
1192 bt_ctf_field_type_put(variant_type
);
1193 bt_ctf_field_type_put(ret_field_type
);
1194 bt_ctf_event_class_put(event_class
);
1195 bt_ctf_event_put(event
);
1198 void type_field_tests()
1200 struct bt_ctf_field
*uint_12
;
1201 struct bt_ctf_field
*int_16
;
1202 struct bt_ctf_field
*string
;
1203 struct bt_ctf_field
*enumeration
;
1204 struct bt_ctf_field_type
*composite_structure_type
;
1205 struct bt_ctf_field_type
*structure_seq_type
;
1206 struct bt_ctf_field_type
*string_type
;
1207 struct bt_ctf_field_type
*sequence_type
;
1208 struct bt_ctf_field_type
*uint_8_type
;
1209 struct bt_ctf_field_type
*int_16_type
;
1210 struct bt_ctf_field_type
*uint_12_type
=
1211 bt_ctf_field_type_integer_create(12);
1212 struct bt_ctf_field_type
*enumeration_type
;
1213 struct bt_ctf_field_type
*enumeration_sequence_type
;
1214 struct bt_ctf_field_type
*enumeration_array_type
;
1215 struct bt_ctf_field_type
*returned_type
;
1216 const char *ret_string
;
1218 returned_type
= bt_ctf_field_get_type(NULL
);
1219 ok(!returned_type
, "bt_ctf_field_get_type handles NULL correctly");
1221 ok(uint_12_type
, "Create an unsigned integer type");
1222 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1223 BT_CTF_INTEGER_BASE_BINARY
) == 0,
1224 "Set integer type's base as binary");
1225 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1226 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
1227 "Set integer type's base as decimal");
1228 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1229 BT_CTF_INTEGER_BASE_UNKNOWN
),
1230 "Reject integer type's base set as unknown");
1231 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1232 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
1233 "Set integer type's base as octal");
1234 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1235 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
1236 "Set integer type's base as hexadecimal");
1237 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
1238 "Reject unknown integer base value");
1239 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
1240 "Set integer type signedness to signed");
1241 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
1242 "Set integer type signedness to unsigned");
1243 ok(bt_ctf_field_type_integer_get_size(NULL
) < 0,
1244 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1245 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
1246 "bt_ctf_field_type_integer_get_size returns a correct value");
1247 ok(bt_ctf_field_type_integer_get_signed(NULL
) < 0,
1248 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1249 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
1250 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1252 ok(bt_ctf_field_type_set_byte_order(NULL
,
1253 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
1254 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1255 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1256 (enum bt_ctf_byte_order
) 42) < 0,
1257 "bt_ctf_field_type_set_byte_order rejects invalid values");
1258 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1259 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
1260 "Set an integer's byte order to little endian");
1261 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1262 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1263 "Set an integer's byte order to big endian");
1264 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
1265 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1266 "bt_ctf_field_type_get_byte_order returns a correct value");
1267 ok(bt_ctf_field_type_get_byte_order(NULL
) ==
1268 BT_CTF_BYTE_ORDER_UNKNOWN
,
1269 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1271 ok(bt_ctf_field_type_get_type_id(NULL
) ==
1273 "bt_ctf_field_type_get_type_id handles NULL correctly");
1274 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
1276 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1278 ok(bt_ctf_field_type_integer_get_base(NULL
) ==
1279 BT_CTF_INTEGER_BASE_UNKNOWN
,
1280 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1281 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
1282 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
1283 "bt_ctf_field_type_integer_get_base returns a correct value");
1285 ok(bt_ctf_field_type_integer_set_encoding(NULL
, CTF_STRING_ASCII
) < 0,
1286 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1287 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1288 (enum ctf_string_encoding
) 123) < 0,
1289 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1290 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1291 CTF_STRING_UTF8
) == 0,
1292 "Set integer type encoding to UTF8");
1293 ok(bt_ctf_field_type_integer_get_encoding(NULL
) == CTF_STRING_UNKNOWN
,
1294 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1295 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) == CTF_STRING_UTF8
,
1296 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1298 int_16_type
= bt_ctf_field_type_integer_create(16);
1299 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
1300 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
1301 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1302 uint_8_type
= bt_ctf_field_type_integer_create(8);
1304 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
1305 ok(sequence_type
, "Create a sequence of int16_t type");
1306 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
1308 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1310 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL
) == NULL
,
1311 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1312 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
1314 ok(!strcmp(ret_string
, "seq_len"),
1315 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1316 ok(bt_ctf_field_type_sequence_get_element_type(NULL
) == NULL
,
1317 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1318 returned_type
= bt_ctf_field_type_sequence_get_element_type(
1320 ok(returned_type
== int_16_type
,
1321 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
1322 bt_ctf_field_type_put(returned_type
);
1324 string_type
= bt_ctf_field_type_string_create();
1325 ok(string_type
, "Create a string type");
1326 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1328 "Reject invalid \"None\" string encoding");
1329 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1331 "Reject invalid string encoding");
1332 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1333 CTF_STRING_ASCII
) == 0,
1334 "Set string encoding to ASCII");
1336 ok(bt_ctf_field_type_string_get_encoding(NULL
) ==
1338 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
1339 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
1341 "bt_ctf_field_type_string_get_encoding returns the correct value");
1343 structure_seq_type
= bt_ctf_field_type_structure_create();
1344 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
1346 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
1347 ok(structure_seq_type
, "Create a structure type");
1348 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1349 uint_8_type
, "seq_len") == 0,
1350 "Add a uint8_t type to a structure");
1351 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1352 sequence_type
, "a_sequence") == 0,
1353 "Add a sequence type to a structure");
1355 ok(bt_ctf_field_type_structure_get_field_count(NULL
) < 0,
1356 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
1357 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
1358 "bt_ctf_field_type_structure_get_field_count returns a correct value");
1360 ok(bt_ctf_field_type_structure_get_field(NULL
,
1361 &ret_string
, &returned_type
, 1) < 0,
1362 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
1363 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1364 NULL
, &returned_type
, 1) < 0,
1365 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
1366 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1367 &ret_string
, NULL
, 1) < 0,
1368 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
1369 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1370 &ret_string
, &returned_type
, 10) < 0,
1371 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
1372 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1373 &ret_string
, &returned_type
, 1) == 0,
1374 "bt_ctf_field_type_structure_get_field returns a field");
1375 ok(!strcmp(ret_string
, "a_sequence"),
1376 "bt_ctf_field_type_structure_get_field returns a correct field name");
1377 ok(returned_type
== sequence_type
,
1378 "bt_ctf_field_type_structure_get_field returns a correct field type");
1379 bt_ctf_field_type_put(returned_type
);
1381 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL
, "a_sequence") == NULL
,
1382 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
1383 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type
, NULL
) == NULL
,
1384 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1385 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1386 structure_seq_type
, "a_sequence");
1387 ok(returned_type
== sequence_type
,
1388 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
1389 bt_ctf_field_type_put(returned_type
);
1391 composite_structure_type
= bt_ctf_field_type_structure_create();
1392 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1393 string_type
, "a_string") == 0,
1394 "Add a string type to a structure");
1395 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1396 structure_seq_type
, "inner_structure") == 0,
1397 "Add a structure type to a structure");
1399 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1400 NULL
, "a_sequence") == NULL
,
1401 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
1402 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1403 structure_seq_type
, NULL
) == NULL
,
1404 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1405 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1406 structure_seq_type
, "a_sequence");
1407 ok(returned_type
== sequence_type
,
1408 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1409 bt_ctf_field_type_put(returned_type
);
1411 int_16
= bt_ctf_field_create(int_16_type
);
1412 ok(int_16
, "Instanciate a signed 16-bit integer");
1413 uint_12
= bt_ctf_field_create(uint_12_type
);
1414 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1415 returned_type
= bt_ctf_field_get_type(int_16
);
1416 ok(returned_type
== int_16_type
,
1417 "bt_ctf_field_get_type returns the correct type");
1419 /* Can't modify types after instanciating them */
1420 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1421 BT_CTF_INTEGER_BASE_DECIMAL
),
1422 "Check an integer type' base can't be modified after instanciation");
1423 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1424 "Check an integer type's signedness can't be modified after instanciation");
1426 /* Check signed property is checked */
1427 ok(bt_ctf_field_signed_integer_set_value(uint_12
, -52),
1428 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
1429 ok(bt_ctf_field_unsigned_integer_set_value(int_16
, 42),
1430 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
1432 /* Check overflows are properly tested for */
1433 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32768) == 0,
1434 "Check -32768 is allowed for a signed 16-bit integer");
1435 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32767) == 0,
1436 "Check 32767 is allowed for a signed 16-bit integer");
1437 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32768),
1438 "Check 32768 is not allowed for a signed 16-bit integer");
1439 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32769),
1440 "Check -32769 is not allowed for a signed 16-bit integer");
1441 ok(bt_ctf_field_signed_integer_set_value(int_16
, -42) == 0,
1442 "Check -42 is allowed for a signed 16-bit integer");
1444 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4095) == 0,
1445 "Check 4095 is allowed for an unsigned 12-bit integer");
1446 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4096),
1447 "Check 4096 is not allowed for a unsigned 12-bit integer");
1448 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 0) == 0,
1449 "Check 0 is allowed for an unsigned 12-bit integer");
1451 string
= bt_ctf_field_create(string_type
);
1452 ok(string
, "Instanciate a string field");
1453 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1454 "Set a string's value");
1456 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1457 ok(enumeration_type
,
1458 "Create an enumeration type with an unsigned 12-bit integer as container");
1459 enumeration_sequence_type
= bt_ctf_field_type_sequence_create(
1460 enumeration_type
, "count");
1461 ok(!enumeration_sequence_type
,
1462 "Check enumeration types are validated when creating a sequence");
1463 enumeration_array_type
= bt_ctf_field_type_array_create(
1464 enumeration_type
, 10);
1465 ok(!enumeration_array_type
,
1466 "Check enumeration types are validated when creating an array");
1467 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1468 enumeration_type
, "enumeration"),
1469 "Check enumeration types are validated when adding them as structure members");
1470 enumeration
= bt_ctf_field_create(enumeration_type
);
1472 "Check enumeration types are validated before instantiation");
1474 bt_ctf_field_put(string
);
1475 bt_ctf_field_put(uint_12
);
1476 bt_ctf_field_put(int_16
);
1477 bt_ctf_field_put(enumeration
);
1478 bt_ctf_field_type_put(composite_structure_type
);
1479 bt_ctf_field_type_put(structure_seq_type
);
1480 bt_ctf_field_type_put(string_type
);
1481 bt_ctf_field_type_put(sequence_type
);
1482 bt_ctf_field_type_put(uint_8_type
);
1483 bt_ctf_field_type_put(int_16_type
);
1484 bt_ctf_field_type_put(uint_12_type
);
1485 bt_ctf_field_type_put(enumeration_type
);
1486 bt_ctf_field_type_put(enumeration_sequence_type
);
1487 bt_ctf_field_type_put(enumeration_array_type
);
1488 bt_ctf_field_type_put(returned_type
);
1491 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
1492 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
1495 * Append enough events to force the underlying packet to be resized.
1496 * Also tests that a new event can be declared after a stream has been
1497 * instantiated and used/flushed.
1501 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
1503 struct bt_ctf_field_type
*integer_type
=
1504 bt_ctf_field_type_integer_create(17);
1505 struct bt_ctf_field_type
*string_type
=
1506 bt_ctf_field_type_string_create();
1507 struct bt_ctf_event
*event
= NULL
;
1508 struct bt_ctf_field
*ret_field
= NULL
;
1509 struct bt_ctf_field_type
*ret_field_type
= NULL
;
1510 uint64_t ret_uint64
;
1511 int events_appended
= 0;
1512 struct bt_ctf_field
*packet_context
= NULL
,
1513 *packet_context_field
= NULL
, *event_context
= NULL
;
1515 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
1517 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
1519 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1520 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
1525 event
= bt_ctf_event_create(event_class
);
1526 ret_field
= bt_ctf_event_get_payload_by_index(event
, 0);
1527 ret_field_type
= bt_ctf_field_get_type(ret_field
);
1528 ok(ret_field_type
== integer_type
,
1529 "bt_ctf_event_get_payload_by_index returns a correct field");
1530 bt_ctf_field_type_put(ret_field_type
);
1531 bt_ctf_field_put(ret_field
);
1533 ok(bt_ctf_event_get_payload_by_index(NULL
, 0) == NULL
,
1534 "bt_ctf_event_get_payload_by_index handles NULL correctly");
1535 ok(bt_ctf_event_get_payload_by_index(event
, 4) == NULL
,
1536 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
1537 bt_ctf_event_put(event
);
1539 ok(bt_ctf_stream_get_event_context(NULL
) == NULL
,
1540 "bt_ctf_stream_get_event_context handles NULL correctly");
1541 event_context
= bt_ctf_stream_get_event_context(stream
);
1543 "bt_ctf_stream_get_event_context returns a stream event context");
1544 ok(bt_ctf_stream_set_event_context(NULL
, event_context
) < 0,
1545 "bt_ctf_stream_set_event_context handles a NULL stream correctly");
1546 ok(bt_ctf_stream_set_event_context(stream
, NULL
) < 0,
1547 "bt_ctf_stream_set_event_context handles a NULL stream event context correctly");
1548 ok(!bt_ctf_stream_set_event_context(stream
, event_context
),
1549 "bt_ctf_stream_set_event_context correctly set a stream event context");
1550 ret_field
= bt_ctf_field_create(integer_type
);
1551 ok(bt_ctf_stream_set_event_context(stream
, ret_field
) < 0,
1552 "bt_ctf_stream_set_event_context rejects an event context of incorrect type");
1553 bt_ctf_field_put(ret_field
);
1555 for (i
= 0; i
< PACKET_RESIZE_TEST_LENGTH
; i
++) {
1556 event
= bt_ctf_event_create(event_class
);
1557 struct bt_ctf_field
*integer
=
1558 bt_ctf_field_create(integer_type
);
1559 struct bt_ctf_field
*string
=
1560 bt_ctf_field_create(string_type
);
1562 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
1563 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
1564 ret
|= bt_ctf_event_set_payload(event
, "field_1",
1566 bt_ctf_field_put(integer
);
1567 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
1568 ret
|= bt_ctf_event_set_payload(event
, "a_string",
1570 bt_ctf_field_put(string
);
1572 /* Populate stream event context */
1573 integer
= bt_ctf_field_structure_get_field(event_context
,
1574 "common_event_context");
1575 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
,
1577 bt_ctf_field_put(integer
);
1579 ret
|= bt_ctf_stream_append_event(stream
, event
);
1580 bt_ctf_event_put(event
);
1587 events_appended
= !!(i
== PACKET_RESIZE_TEST_LENGTH
);
1588 ok(bt_ctf_stream_get_discarded_events_count(NULL
, &ret_uint64
) < 0,
1589 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
1590 ok(bt_ctf_stream_get_discarded_events_count(stream
, NULL
) < 0,
1591 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
1592 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1593 ok(ret
== 0 && ret_uint64
== 0,
1594 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1595 bt_ctf_stream_append_discarded_events(stream
, 1000);
1596 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1597 ok(ret
== 0 && ret_uint64
== 1000,
1598 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1601 ok(events_appended
, "Append 100 000 events to a stream");
1604 * Populate the custom packet context field with a dummy value
1605 * otherwise flush will fail.
1607 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1608 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1609 "custom_packet_context_field");
1610 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 2);
1612 ok(bt_ctf_stream_flush(stream
) == 0,
1613 "Flush a stream that forces a packet resize");
1614 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1615 ok(ret
== 0 && ret_uint64
== 1000,
1616 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1617 bt_ctf_field_type_put(integer_type
);
1618 bt_ctf_field_type_put(string_type
);
1619 bt_ctf_field_put(packet_context
);
1620 bt_ctf_field_put(packet_context_field
);
1621 bt_ctf_field_put(event_context
);
1622 bt_ctf_event_class_put(event_class
);
1625 void test_empty_stream(struct bt_ctf_writer
*writer
)
1628 struct bt_ctf_trace
*trace
= NULL
, *ret_trace
= NULL
;
1629 struct bt_ctf_stream_class
*stream_class
= NULL
;
1630 struct bt_ctf_stream
*stream
= NULL
;
1632 trace
= bt_ctf_writer_get_trace(writer
);
1634 diag("Failed to get trace from writer");
1639 stream_class
= bt_ctf_stream_class_create("empty_stream");
1640 if (!stream_class
) {
1641 diag("Failed to create stream class");
1646 ok(bt_ctf_stream_class_get_trace(NULL
) == NULL
,
1647 "bt_ctf_stream_class_get_trace handles NULL correctly");
1648 ok(bt_ctf_stream_class_get_trace(stream_class
) == NULL
,
1649 "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned");
1651 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1653 diag("Failed to create writer stream");
1658 ret_trace
= bt_ctf_stream_class_get_trace(stream_class
);
1659 ok(ret_trace
== trace
,
1660 "bt_ctf_stream_class_get_trace returns the correct trace after a stream has been created");
1663 "Created a stream class with default attributes and an empty stream");
1664 bt_ctf_trace_put(trace
);
1665 bt_ctf_trace_put(ret_trace
);
1666 bt_ctf_stream_put(stream
);
1667 bt_ctf_stream_class_put(stream_class
);
1670 void test_instanciate_event_before_stream(struct bt_ctf_writer
*writer
)
1673 struct bt_ctf_trace
*trace
= NULL
;
1674 struct bt_ctf_clock
*clock
= NULL
;
1675 struct bt_ctf_stream_class
*stream_class
= NULL
;
1676 struct bt_ctf_stream
*stream
= NULL
,
1678 struct bt_ctf_event_class
*event_class
= NULL
;
1679 struct bt_ctf_event
*event
= NULL
;
1680 struct bt_ctf_field_type
*integer_type
= NULL
;
1681 struct bt_ctf_field
*integer
= NULL
;
1683 trace
= bt_ctf_writer_get_trace(writer
);
1685 diag("Failed to get trace from writer");
1690 clock
= bt_ctf_trace_get_clock(trace
, 0);
1692 diag("Failed to get clock from trace");
1697 stream_class
= bt_ctf_stream_class_create("event_before_stream_test");
1698 if (!stream_class
) {
1699 diag("Failed to create stream class");
1704 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
1706 diag("Failed to set stream class clock");
1710 event_class
= bt_ctf_event_class_create("some_event_class_name");
1711 integer_type
= bt_ctf_field_type_integer_create(32);
1712 if (!integer_type
) {
1713 diag("Failed to create integer field type");
1718 ret
= bt_ctf_event_class_add_field(event_class
, integer_type
,
1721 diag("Failed to add field to event class");
1725 ret
= bt_ctf_stream_class_add_event_class(stream_class
,
1728 diag("Failed to add event class to stream class");
1731 event
= bt_ctf_event_create(event_class
);
1733 diag("Failed to create event");
1738 integer
= bt_ctf_event_get_payload_by_index(event
, 0);
1740 diag("Failed to get integer field payload from event");
1745 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 1234);
1747 diag("Failed to set integer field value");
1751 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
1753 diag("Failed to create writer stream");
1758 ok(bt_ctf_event_get_stream(NULL
) == NULL
,
1759 "bt_ctf_event_get_stream handles NULL correctly");
1760 ok(bt_ctf_event_get_stream(event
) == NULL
,
1761 "bt_ctf_event_get_stream returns NULL on event which has not yet been appended to a stream");
1763 ret
= bt_ctf_stream_append_event(stream
, event
);
1765 diag("Failed to append event to stream");
1769 ret_stream
= bt_ctf_event_get_stream(event
);
1770 ok(ret_stream
== stream
,
1771 "bt_ctf_event_get_stream returns an event's stream after it has been appended");
1774 "Create an event before instanciating its associated stream");
1775 bt_ctf_trace_put(trace
);
1776 bt_ctf_stream_put(stream
);
1777 bt_ctf_stream_put(ret_stream
);
1778 bt_ctf_stream_class_put(stream_class
);
1779 bt_ctf_event_class_put(event_class
);
1780 bt_ctf_event_put(event
);
1781 bt_ctf_field_type_put(integer_type
);
1782 bt_ctf_field_put(integer
);
1783 bt_ctf_clock_put(clock
);
1786 void append_existing_event_class(struct bt_ctf_stream_class
*stream_class
)
1788 struct bt_ctf_event_class
*event_class
;
1790 assert(event_class
= bt_ctf_event_class_create("Simple Event"));
1791 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
1792 "two event classes with the same name cannot cohabit within the same stream class");
1793 bt_ctf_event_class_put(event_class
);
1795 event_class
= bt_ctf_event_class_create("different name, ok");
1796 assert(event_class
);
1797 assert(!bt_ctf_event_class_set_id(event_class
, 11));
1798 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
1799 "two event classes with the same ID cannot cohabit within the same stream class");
1800 bt_ctf_event_class_put(event_class
);
1803 int main(int argc
, char **argv
)
1805 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
1806 char metadata_path
[sizeof(trace_path
) + 9];
1807 const char *clock_name
= "test_clock";
1808 const char *clock_description
= "This is a test clock";
1809 const char *returned_clock_name
;
1810 const char *returned_clock_description
;
1811 const uint64_t frequency
= 1123456789;
1812 const uint64_t offset_s
= 1351530929945824323;
1813 const uint64_t offset
= 1234567;
1814 const uint64_t precision
= 10;
1815 const int is_absolute
= 0xFF;
1816 char *metadata_string
;
1817 struct bt_ctf_writer
*writer
;
1818 struct utsname name
;
1819 char hostname
[BABELTRACE_HOST_NAME_MAX
];
1820 struct bt_ctf_clock
*clock
, *ret_clock
;
1821 struct bt_ctf_stream_class
*stream_class
, *ret_stream_class
;
1822 struct bt_ctf_stream
*stream1
;
1823 const char *ret_string
;
1824 const unsigned char *ret_uuid
;
1825 unsigned char tmp_uuid
[16] = { 0 };
1826 struct bt_ctf_field_type
*packet_context_type
,
1827 *packet_context_field_type
,
1828 *packet_header_type
,
1829 *packet_header_field_type
,
1831 *stream_event_context_type
,
1833 *event_header_field_type
;
1834 struct bt_ctf_field
*packet_header
, *packet_header_field
;
1835 struct bt_ctf_trace
*trace
;
1837 int64_t ret_int64_t
;
1838 struct bt_object
*obj
;
1841 printf("Usage: tests-ctf-writer path_to_ctf_parser_test path_to_babeltrace\n");
1847 if (!mkdtemp(trace_path
)) {
1851 strcpy(metadata_path
, trace_path
);
1852 strcat(metadata_path
+ sizeof(trace_path
) - 1, "/metadata");
1854 writer
= bt_ctf_writer_create(trace_path
);
1855 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
1857 ok(!bt_ctf_writer_get_trace(NULL
),
1858 "bt_ctf_writer_get_trace correctly handles NULL");
1859 trace
= bt_ctf_writer_get_trace(writer
);
1861 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1862 ok(bt_ctf_trace_set_byte_order(trace
, BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1863 "Set a trace's byte order to big endian");
1864 ok(bt_ctf_trace_get_byte_order(trace
) == BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1865 "bt_ctf_trace_get_byte_order returns a correct endianness");
1867 /* Add environment context to the trace */
1868 ret
= gethostname(hostname
, sizeof(hostname
));
1872 ok(bt_ctf_writer_add_environment_field(writer
, "host", hostname
) == 0,
1873 "Add host (%s) environment field to writer instance",
1875 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
1877 "bt_ctf_writer_add_environment_field error with NULL writer");
1878 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
1880 "bt_ctf_writer_add_environment_field error with NULL field name");
1881 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
1883 "bt_ctf_writer_add_environment_field error with NULL field value");
1885 /* Test bt_ctf_trace_set_environment_field with an integer object */
1886 obj
= bt_object_integer_create_init(23);
1888 ok(bt_ctf_trace_set_environment_field(NULL
, "test_env_int_obj", obj
),
1889 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
1890 ok(bt_ctf_trace_set_environment_field(trace
, NULL
, obj
),
1891 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
1892 ok(bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", NULL
),
1893 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
1894 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", obj
),
1895 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
1898 /* Test bt_ctf_trace_set_environment_field with a string object */
1899 obj
= bt_object_string_create_init("the value");
1901 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_str_obj", obj
),
1902 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
1905 /* Test bt_ctf_trace_set_environment_field_integer */
1906 ok(bt_ctf_trace_set_environment_field_integer(NULL
, "test_env_int",
1908 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
1909 ok(bt_ctf_trace_set_environment_field_integer(trace
, NULL
, -194875),
1910 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
1911 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1913 "bt_ctf_trace_set_environment_field_integer succeeds");
1915 /* Test bt_ctf_trace_set_environment_field_string */
1916 ok(bt_ctf_trace_set_environment_field_string(NULL
, "test_env_str",
1918 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
1919 ok(bt_ctf_trace_set_environment_field_string(trace
, NULL
, "yeah"),
1920 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
1921 ok(bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1923 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
1924 ok(!bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
1926 "bt_ctf_trace_set_environment_field_string succeeds");
1928 /* Test bt_ctf_trace_get_environment_field_count */
1929 ok(bt_ctf_trace_get_environment_field_count(NULL
) < 0,
1930 "bt_ctf_trace_get_environment_field_count handles a NULL trace correctly");
1931 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
1932 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
1934 /* Test bt_ctf_trace_get_environment_field_name */
1935 ok(bt_ctf_trace_get_environment_field_name(NULL
, 0) == NULL
,
1936 "bt_ctf_trace_get_environment_field_name handles a NULL trace correctly");
1937 ok(bt_ctf_trace_get_environment_field_name(trace
, -1) == NULL
,
1938 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (negative)");
1939 ok(bt_ctf_trace_get_environment_field_name(trace
, 5) == NULL
,
1940 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (too large)");
1941 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 0);
1942 ok(ret_string
&& !strcmp(ret_string
, "host"),
1943 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1944 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 1);
1945 ok(ret_string
&& !strcmp(ret_string
, "test_env_int_obj"),
1946 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1947 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 2);
1948 ok(ret_string
&& !strcmp(ret_string
, "test_env_str_obj"),
1949 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1950 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 3);
1951 ok(ret_string
&& !strcmp(ret_string
, "test_env_int"),
1952 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1953 ret_string
= bt_ctf_trace_get_environment_field_name(trace
, 4);
1954 ok(ret_string
&& !strcmp(ret_string
, "test_env_str"),
1955 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1957 /* Test bt_ctf_trace_get_environment_field_value */
1958 ok(bt_ctf_trace_get_environment_field_value(NULL
, 0) == NULL
,
1959 "bt_ctf_trace_get_environment_field_value handles a NULL trace correctly");
1960 ok(bt_ctf_trace_get_environment_field_value(trace
, -1) == NULL
,
1961 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (negative)");
1962 ok(bt_ctf_trace_get_environment_field_value(trace
, 5) == NULL
,
1963 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (too large)");
1964 obj
= bt_ctf_trace_get_environment_field_value(trace
, 1);
1965 ret
= bt_object_integer_get(obj
, &ret_int64_t
);
1966 ok(!ret
&& ret_int64_t
== 23,
1967 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
1969 obj
= bt_ctf_trace_get_environment_field_value(trace
, 2);
1970 ret
= bt_object_string_get(obj
, &ret_string
);
1971 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "the value"),
1972 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
1975 /* Test bt_ctf_trace_get_environment_field_value_by_name */
1976 ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL
,
1978 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL trace correctly");
1979 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, NULL
),
1980 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL name correctly");
1981 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, "oh oh"),
1982 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
1983 obj
= bt_ctf_trace_get_environment_field_value_by_name(trace
,
1985 ret
= bt_object_string_get(obj
, &ret_string
);
1986 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "oh yeah"),
1987 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
1990 /* Test environment field replacement */
1991 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
1993 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
1994 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
1995 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
1996 obj
= bt_ctf_trace_get_environment_field_value(trace
, 3);
1997 ret
= bt_object_integer_get(obj
, &ret_int64_t
);
1998 ok(!ret
&& ret_int64_t
== 654321,
1999 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
2007 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
2008 == 0, "Add sysname (%s) environment field to writer instance",
2010 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
2011 name
.nodename
) == 0,
2012 "Add nodename (%s) environment field to writer instance",
2014 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
2015 == 0, "Add release (%s) environment field to writer instance",
2017 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
2018 == 0, "Add version (%s) environment field to writer instance",
2020 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
2021 == 0, "Add machine (%s) environment field to writer istance",
2024 /* Define a clock and add it to the trace */
2025 ok(bt_ctf_clock_create("signed") == NULL
,
2026 "Illegal clock name rejected");
2027 ok(bt_ctf_clock_create(NULL
) == NULL
, "NULL clock name rejected");
2028 clock
= bt_ctf_clock_create(clock_name
);
2029 ok(clock
, "Clock created sucessfully");
2030 returned_clock_name
= bt_ctf_clock_get_name(clock
);
2031 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
2032 ok(returned_clock_name
? !strcmp(returned_clock_name
, clock_name
) : 0,
2033 "Returned clock name is valid");
2035 returned_clock_description
= bt_ctf_clock_get_description(clock
);
2036 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
2037 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
2038 "Clock description set successfully");
2040 returned_clock_description
= bt_ctf_clock_get_description(clock
);
2041 ok(returned_clock_description
,
2042 "bt_ctf_clock_get_description returns a description.");
2043 ok(returned_clock_description
?
2044 !strcmp(returned_clock_description
, clock_description
) : 0,
2045 "Returned clock description is valid");
2047 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
2048 "bt_ctf_clock_get_frequency returns the correct default frequency");
2049 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
2050 "Set clock frequency");
2051 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
2052 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
2054 ok(bt_ctf_clock_get_offset_s(clock
) == DEFAULT_CLOCK_OFFSET_S
,
2055 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
2056 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
2057 "Set clock offset (seconds)");
2058 ok(bt_ctf_clock_get_offset_s(clock
) == offset_s
,
2059 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
2061 ok(bt_ctf_clock_get_offset(clock
) == DEFAULT_CLOCK_OFFSET
,
2062 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks)");
2063 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
2064 ok(bt_ctf_clock_get_offset(clock
) == offset
,
2065 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks) once it is set");
2067 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
2068 "bt_ctf_clock_get_precision returns the correct default precision");
2069 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
2070 "Set clock precision");
2071 ok(bt_ctf_clock_get_precision(clock
) == precision
,
2072 "bt_ctf_clock_get_precision returns the correct precision once it is set");
2074 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
2075 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
2076 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
2077 "Set clock absolute property");
2078 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
2079 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
2081 ok(bt_ctf_clock_get_time(clock
) == DEFAULT_CLOCK_TIME
,
2082 "bt_ctf_clock_get_time returns the correct default time");
2083 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
2085 ok(bt_ctf_clock_get_time(clock
) == current_time
,
2086 "bt_ctf_clock_get_time returns the correct time once it is set");
2088 ok(bt_ctf_writer_add_clock(writer
, clock
) == 0,
2089 "Add clock to writer instance");
2090 ok(bt_ctf_writer_add_clock(writer
, clock
),
2091 "Verify a clock can't be added twice to a writer instance");
2093 ok(bt_ctf_trace_get_clock_count(NULL
) < 0,
2094 "bt_ctf_trace_get_clock_count correctly handles NULL");
2095 ok(bt_ctf_trace_get_clock_count(trace
) == 1,
2096 "bt_ctf_trace_get_clock_count returns the correct number of clocks");
2097 ok(!bt_ctf_trace_get_clock(NULL
, 0),
2098 "bt_ctf_trace_get_clock correctly handles NULL");
2099 ok(!bt_ctf_trace_get_clock(trace
, -1),
2100 "bt_ctf_trace_get_clock correctly handles negative indexes");
2101 ok(!bt_ctf_trace_get_clock(trace
, 1),
2102 "bt_ctf_trace_get_clock correctly handles out of bound accesses");
2103 ret_clock
= bt_ctf_trace_get_clock(trace
, 0);
2104 ok(ret_clock
== clock
,
2105 "bt_ctf_trace_get_clock returns the right clock instance");
2106 bt_ctf_clock_put(ret_clock
);
2107 ok(!bt_ctf_trace_get_clock_by_name(trace
, NULL
),
2108 "bt_ctf_trace_get_clock_by_name correctly handles NULL (trace)");
2109 ok(!bt_ctf_trace_get_clock_by_name(NULL
, clock_name
),
2110 "bt_ctf_trace_get_clock_by_name correctly handles NULL (clock name)");
2111 ok(!bt_ctf_trace_get_clock_by_name(NULL
, NULL
),
2112 "bt_ctf_trace_get_clock_by_name correctly handles NULL (both)");
2113 ret_clock
= bt_ctf_trace_get_clock_by_name(trace
, clock_name
);
2114 ok(ret_clock
== clock
,
2115 "bt_ctf_trace_get_clock_by_name returns the right clock instance");
2116 bt_ctf_clock_put(ret_clock
);
2117 ok(!bt_ctf_trace_get_clock_by_name(trace
, "random"),
2118 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
2120 ok(!bt_ctf_clock_get_name(NULL
),
2121 "bt_ctf_clock_get_name correctly handles NULL");
2122 ok(!bt_ctf_clock_get_description(NULL
),
2123 "bt_ctf_clock_get_description correctly handles NULL");
2124 ok(bt_ctf_clock_get_frequency(NULL
) == -1ULL,
2125 "bt_ctf_clock_get_frequency correctly handles NULL");
2126 ok(bt_ctf_clock_get_precision(NULL
) == -1ULL,
2127 "bt_ctf_clock_get_precision correctly handles NULL");
2128 ok(bt_ctf_clock_get_offset_s(NULL
) == -1ULL,
2129 "bt_ctf_clock_get_offset_s correctly handles NULL");
2130 ok(bt_ctf_clock_get_offset(NULL
) == -1ULL,
2131 "bt_ctf_clock_get_offset correctly handles NULL");
2132 ok(bt_ctf_clock_get_is_absolute(NULL
) < 0,
2133 "bt_ctf_clock_get_is_absolute correctly handles NULL");
2134 ok(bt_ctf_clock_get_time(NULL
) == -1ULL,
2135 "bt_ctf_clock_get_time correctly handles NULL");
2137 ok(bt_ctf_clock_set_description(NULL
, NULL
) < 0,
2138 "bt_ctf_clock_set_description correctly handles NULL clock");
2139 ok(bt_ctf_clock_set_frequency(NULL
, frequency
) < 0,
2140 "bt_ctf_clock_set_frequency correctly handles NULL clock");
2141 ok(bt_ctf_clock_set_precision(NULL
, precision
) < 0,
2142 "bt_ctf_clock_get_precision correctly handles NULL clock");
2143 ok(bt_ctf_clock_set_offset_s(NULL
, offset_s
) < 0,
2144 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
2145 ok(bt_ctf_clock_set_offset(NULL
, offset
) < 0,
2146 "bt_ctf_clock_set_offset correctly handles NULL clock");
2147 ok(bt_ctf_clock_set_is_absolute(NULL
, is_absolute
) < 0,
2148 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
2149 ok(bt_ctf_clock_set_time(NULL
, current_time
) < 0,
2150 "bt_ctf_clock_set_time correctly handles NULL clock");
2151 ok(bt_ctf_clock_get_uuid(NULL
) == NULL
,
2152 "bt_ctf_clock_get_uuid correctly handles NULL clock");
2153 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
2155 "bt_ctf_clock_get_uuid returns a UUID");
2157 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
2158 /* Slightly modify UUID */
2159 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
2162 ok(bt_ctf_clock_set_uuid(NULL
, tmp_uuid
) < 0,
2163 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
2164 ok(bt_ctf_clock_set_uuid(clock
, NULL
) < 0,
2165 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
2166 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
2167 "bt_ctf_clock_set_uuid sets a new uuid succesfully");
2168 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
2170 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
2171 ok(uuid_match(ret_uuid
, tmp_uuid
),
2172 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
2174 /* Define a stream class */
2175 stream_class
= bt_ctf_stream_class_create("test_stream");
2177 ok(bt_ctf_stream_class_get_name(NULL
) == NULL
,
2178 "bt_ctf_stream_class_get_name handles NULL correctly");
2179 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
2180 ok(ret_string
&& !strcmp(ret_string
, "test_stream"),
2181 "bt_ctf_stream_class_get_name returns a correct stream class name");
2183 ok(bt_ctf_stream_class_get_clock(stream_class
) == NULL
,
2184 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
2185 ok(bt_ctf_stream_class_get_clock(NULL
) == NULL
,
2186 "bt_ctf_stream_class_get_clock handles NULL correctly");
2188 ok(stream_class
, "Create stream class");
2189 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
2190 "Set a stream class' clock");
2191 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
2192 ok(ret_clock
== clock
,
2193 "bt_ctf_stream_class_get_clock returns a correct clock");
2194 bt_ctf_clock_put(ret_clock
);
2196 /* Test the event fields and event types APIs */
2199 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
2200 "bt_ctf_stream_class_get_id returns an error when no id is set");
2201 ok(bt_ctf_stream_class_get_id(NULL
) < 0,
2202 "bt_ctf_stream_class_get_id handles NULL correctly");
2203 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
2204 "bt_ctf_stream_class_set_id handles NULL correctly");
2205 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
2206 "Set an stream class' id");
2207 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
2208 "bt_ctf_stream_class_get_id returns the correct value");
2210 /* Validate default event header fields */
2211 ok(bt_ctf_stream_class_get_event_header_type(NULL
) == NULL
,
2212 "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
2213 ret_field_type
= bt_ctf_stream_class_get_event_header_type(
2216 "bt_ctf_stream_class_get_event_header_type returns an event header type");
2217 ok(bt_ctf_field_type_get_type_id(ret_field_type
) == CTF_TYPE_STRUCT
,
2218 "Default event header type is a structure");
2219 event_header_field_type
=
2220 bt_ctf_field_type_structure_get_field_type_by_name(
2221 ret_field_type
, "id");
2222 ok(event_header_field_type
,
2223 "Default event header type contains an \"id\" field");
2224 ok(bt_ctf_field_type_get_type_id(
2225 event_header_field_type
) == CTF_TYPE_INTEGER
,
2226 "Default event header \"id\" field is an integer");
2227 bt_ctf_field_type_put(event_header_field_type
);
2228 event_header_field_type
=
2229 bt_ctf_field_type_structure_get_field_type_by_name(
2230 ret_field_type
, "timestamp");
2231 ok(event_header_field_type
,
2232 "Default event header type contains a \"timestamp\" field");
2233 ok(bt_ctf_field_type_get_type_id(
2234 event_header_field_type
) == CTF_TYPE_INTEGER
,
2235 "Default event header \"timestamp\" field is an integer");
2236 bt_ctf_field_type_put(event_header_field_type
);
2237 bt_ctf_field_type_put(ret_field_type
);
2239 /* Add a custom trace packet header field */
2240 ok(bt_ctf_trace_get_packet_header_type(NULL
) == NULL
,
2241 "bt_ctf_trace_get_packet_header_type handles NULL correctly");
2242 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
2243 ok(packet_header_type
,
2244 "bt_ctf_trace_get_packet_header_type returns a packet header");
2245 ok(bt_ctf_field_type_get_type_id(packet_header_type
) == CTF_TYPE_STRUCT
,
2246 "bt_ctf_trace_get_packet_header_type returns a packet header of type struct");
2247 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2248 packet_header_type
, "magic");
2249 ok(ret_field_type
, "Default packet header type contains a \"magic\" field");
2250 bt_ctf_field_type_put(ret_field_type
);
2251 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2252 packet_header_type
, "uuid");
2253 ok(ret_field_type
, "Default packet header type contains a \"uuid\" field");
2254 bt_ctf_field_type_put(ret_field_type
);
2255 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2256 packet_header_type
, "stream_id");
2257 ok(ret_field_type
, "Default packet header type contains a \"stream_id\" field");
2258 bt_ctf_field_type_put(ret_field_type
);
2260 packet_header_field_type
= bt_ctf_field_type_integer_create(22);
2261 ok(!bt_ctf_field_type_structure_add_field(packet_header_type
,
2262 packet_header_field_type
, "custom_trace_packet_header_field"),
2263 "Added a custom trace packet header field successfully");
2265 ok(bt_ctf_trace_set_packet_header_type(NULL
, packet_header_type
) < 0,
2266 "bt_ctf_trace_set_packet_header_type handles a NULL trace correctly");
2267 ok(bt_ctf_trace_set_packet_header_type(trace
, NULL
) < 0,
2268 "bt_ctf_trace_set_packet_header_type handles a NULL packet_header_type correctly");
2269 ok(!bt_ctf_trace_set_packet_header_type(trace
, packet_header_type
),
2270 "Set a trace packet_header_type successfully");
2272 ok(bt_ctf_stream_class_get_packet_context_type(NULL
) == NULL
,
2273 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
2275 /* Add a custom field to the stream class' packet context */
2276 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
2277 ok(packet_context_type
,
2278 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
2279 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == CTF_TYPE_STRUCT
,
2280 "Packet context is a structure");
2282 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
2283 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
2284 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
),
2285 "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly");
2287 integer_type
= bt_ctf_field_type_integer_create(32);
2288 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
2290 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
2291 /* Create a "uint5_t" equivalent custom packet context field */
2292 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
2294 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
2295 packet_context_field_type
, "custom_packet_context_field");
2296 ok(ret
== 0, "Packet context field added successfully");
2298 /* Define a stream event context containing a my_integer field. */
2299 ok(bt_ctf_stream_class_get_event_context_type(NULL
) == NULL
,
2300 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
2301 ok(bt_ctf_stream_class_get_event_context_type(
2302 stream_class
) == NULL
,
2303 "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set.");
2304 stream_event_context_type
= bt_ctf_field_type_structure_create();
2305 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
2306 integer_type
, "common_event_context");
2308 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
2309 stream_event_context_type
) < 0,
2310 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
2311 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
2313 "bt_ctf_stream_class_set_event_context_type handles a NULL event_context correctly");
2314 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
2316 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
2318 ok(bt_ctf_stream_class_set_event_context_type(
2319 stream_class
, stream_event_context_type
) == 0,
2320 "Set a new stream event context type");
2321 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
2323 ok(ret_field_type
== stream_event_context_type
,
2324 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
2325 bt_ctf_field_type_put(ret_field_type
);
2327 /* Instantiate a stream and append events */
2328 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
2329 ok(stream1
, "Instanciate a stream class from writer");
2331 ok(bt_ctf_stream_get_class(NULL
) == NULL
,
2332 "bt_ctf_stream_get_class correctly handles NULL");
2333 ret_stream_class
= bt_ctf_stream_get_class(stream1
);
2334 ok(ret_stream_class
,
2335 "bt_ctf_stream_get_class returns a stream class");
2336 ok(ret_stream_class
== stream_class
,
2337 "Returned stream class is of the correct type");
2340 * Try to modify the packet context type after a stream has been
2343 ret
= bt_ctf_field_type_structure_add_field(packet_header_type
,
2344 packet_header_field_type
, "should_fail");
2346 "Trace packet header type can't be modified once a stream has been instanciated");
2349 * Try to modify the packet context type after a stream has been
2352 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
2353 packet_context_field_type
, "should_fail");
2355 "Packet context type can't be modified once a stream has been instanciated");
2358 * Try to modify the stream event context type after a stream has been
2361 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
2362 integer_type
, "should_fail");
2364 "Stream event context type can't be modified once a stream has been instanciated");
2366 /* Should fail after instanciating a stream (frozen) */
2367 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
2368 "Changes to a stream class that was already instantiated fail");
2370 /* Populate the custom packet header field only once for all tests */
2371 ok(bt_ctf_stream_get_packet_header(NULL
) == NULL
,
2372 "bt_ctf_stream_get_packet_header handles NULL correctly");
2373 packet_header
= bt_ctf_stream_get_packet_header(stream1
);
2375 "bt_ctf_stream_get_packet_header returns a packet header");
2376 ret_field_type
= bt_ctf_field_get_type(packet_header
);
2377 ok(ret_field_type
== packet_header_type
,
2378 "Stream returns a packet header of the appropriate type");
2379 bt_ctf_field_type_put(ret_field_type
);
2380 packet_header_field
= bt_ctf_field_structure_get_field(packet_header
,
2381 "custom_trace_packet_header_field");
2382 ok(packet_header_field
,
2383 "Packet header structure contains a custom field with the appropriate name");
2384 ret_field_type
= bt_ctf_field_get_type(packet_header_field
);
2385 ok(ret_field_type
== packet_header_field_type
,
2386 "Custom packet header field is of the expected type");
2387 ok(!bt_ctf_field_unsigned_integer_set_value(packet_header_field
,
2388 54321), "Set custom packet header value successfully");
2389 ok(bt_ctf_stream_set_packet_header(stream1
, NULL
) < 0,
2390 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
2391 ok(bt_ctf_stream_set_packet_header(NULL
, packet_header
) < 0,
2392 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
2393 ok(bt_ctf_stream_set_packet_header(stream1
, packet_header_field
) < 0,
2394 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
2395 ok(!bt_ctf_stream_set_packet_header(stream1
, packet_header
),
2396 "Successfully set a stream's packet header");
2398 ok(bt_ctf_writer_add_environment_field(writer
, "new_field", "test") == 0,
2399 "Add environment field to writer after stream creation");
2401 test_instanciate_event_before_stream(writer
);
2403 append_simple_event(stream_class
, stream1
, clock
);
2405 packet_resize_test(stream_class
, stream1
, clock
);
2407 append_complex_event(stream_class
, stream1
, clock
);
2409 append_existing_event_class(stream_class
);
2411 test_empty_stream(writer
);
2413 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
2414 ok(metadata_string
, "Get metadata string");
2416 bt_ctf_writer_flush_metadata(writer
);
2417 validate_metadata(argv
[1], metadata_path
);
2418 validate_trace(argv
[2], trace_path
);
2420 bt_ctf_clock_put(clock
);
2421 bt_ctf_stream_class_put(ret_stream_class
);
2422 bt_ctf_writer_put(writer
);
2423 bt_ctf_stream_put(stream1
);
2424 bt_ctf_field_type_put(packet_context_type
);
2425 bt_ctf_field_type_put(packet_context_field_type
);
2426 bt_ctf_field_type_put(integer_type
);
2427 bt_ctf_field_type_put(stream_event_context_type
);
2428 bt_ctf_field_type_put(ret_field_type
);
2429 bt_ctf_field_type_put(packet_header_type
);
2430 bt_ctf_field_type_put(packet_header_field_type
);
2431 bt_ctf_field_put(packet_header
);
2432 bt_ctf_field_put(packet_header_field
);
2433 bt_ctf_trace_put(trace
);
2434 free(metadata_string
);
2436 ok(bt_ctf_stream_class_get_trace(stream_class
) == NULL
,
2437 "bt_ctf_stream_class_get_trace returns NULL after its trace has been reclaimed");
2438 bt_ctf_stream_class_put(stream_class
);
2440 /* Remove all trace files and delete temporary trace directory */
2441 DIR *trace_dir
= opendir(trace_path
);
2443 perror("# opendir");
2447 struct dirent
*entry
;
2448 while ((entry
= readdir(trace_dir
))) {
2449 if (entry
->d_type
== DT_REG
) {
2450 unlinkat(dirfd(trace_dir
), entry
->d_name
, 0);
2455 closedir(trace_dir
);