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