6 * Copyright 2013 - 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/events.h>
33 #include <sys/utsname.h>
34 #include <babeltrace/compat/limits.h>
44 #define METADATA_LINE_SIZE 512
45 #define SEQUENCE_TEST_LENGTH 10
46 #define ARRAY_TEST_LENGTH 5
47 #define PACKET_RESIZE_TEST_LENGTH 100000
49 #define DEFAULT_CLOCK_FREQ 1000000000
50 #define DEFAULT_CLOCK_PRECISION 1
51 #define DEFAULT_CLOCK_OFFSET 0
52 #define DEFAULT_CLOCK_OFFSET_S 0
53 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
54 #define DEFAULT_CLOCK_TIME 0
56 static uint64_t current_time
= 42;
58 /* Return 1 if uuids match, zero if different. */
59 int uuid_match(const unsigned char *uuid_a
, const unsigned char *uuid_b
)
64 if (!uuid_a
|| !uuid_b
) {
68 for (i
= 0; i
< 16; i
++) {
69 if (uuid_a
[i
] != uuid_b
[i
]) {
79 void validate_metadata(char *parser_path
, char *metadata_path
)
82 char parser_output_path
[] = "/tmp/parser_output_XXXXXX";
83 int parser_output_fd
= -1, metadata_fd
= -1;
90 parser_output_fd
= mkstemp(parser_output_path
);
91 metadata_fd
= open(metadata_path
, O_RDONLY
);
93 unlink(parser_output_path
);
95 if (parser_output_fd
== -1 || metadata_fd
== -1) {
96 diag("Failed create temporary files for metadata parsing.");
104 waitpid(pid
, &status
, 0);
105 ret
= WIFEXITED(status
) ? WEXITSTATUS(status
) : -1;
107 /* ctf-parser-test expects a metadata string on stdin. */
108 ret
= dup2(metadata_fd
, STDIN_FILENO
);
110 perror("# dup2 metadata_fd to STDIN");
114 ret
= dup2(parser_output_fd
, STDOUT_FILENO
);
116 perror("# dup2 parser_output_fd to STDOUT");
120 ret
= dup2(parser_output_fd
, STDERR_FILENO
);
122 perror("# dup2 parser_output_fd to STDERR");
126 execl(parser_path
, "ctf-parser-test", NULL
);
127 perror("# Could not launch the ctf metadata parser process");
131 ok(ret
== 0, "Metadata string is valid");
133 if (ret
&& metadata_fd
>= 0 && parser_output_fd
>= 0) {
135 size_t len
= METADATA_LINE_SIZE
;
136 FILE *metadata_fp
= NULL
, *parser_output_fp
= NULL
;
138 metadata_fp
= fdopen(metadata_fd
, "r");
140 perror("fdopen on metadata_fd");
145 parser_output_fp
= fdopen(parser_output_fd
, "r");
146 if (!parser_output_fp
) {
147 perror("fdopen on parser_output_fd");
150 parser_output_fd
= -1;
154 diag("malloc failure");
159 /* Output the metadata and parser output as diagnostic */
160 while (getline(&line
, &len
, metadata_fp
) > 0) {
164 rewind(parser_output_fp
);
165 while (getline(&line
, &len
, parser_output_fp
) > 0) {
172 if (fclose(metadata_fp
)) {
173 diag("fclose failure");
176 if (parser_output_fp
) {
177 if (fclose(parser_output_fp
)) {
178 diag("fclose failure");
183 if (parser_output_fd
>= 0) {
184 if (close(parser_output_fd
)) {
188 if (metadata_fd
>= 0) {
189 if (close(metadata_fd
)) {
195 void validate_trace(char *parser_path
, char *trace_path
)
198 char babeltrace_output_path
[] = "/tmp/babeltrace_output_XXXXXX";
199 int babeltrace_output_fd
= -1;
206 babeltrace_output_fd
= mkstemp(babeltrace_output_path
);
207 unlink(babeltrace_output_path
);
209 if (babeltrace_output_fd
== -1) {
210 diag("Failed to create a temporary file for trace parsing.");
218 waitpid(pid
, &status
, 0);
219 ret
= WIFEXITED(status
) ? WEXITSTATUS(status
) : -1;
221 ret
= dup2(babeltrace_output_fd
, STDOUT_FILENO
);
223 perror("# dup2 babeltrace_output_fd to STDOUT");
227 ret
= dup2(babeltrace_output_fd
, STDERR_FILENO
);
229 perror("# dup2 babeltrace_output_fd to STDERR");
233 execl(parser_path
, "babeltrace", trace_path
, NULL
);
234 perror("# Could not launch the babeltrace process");
238 ok(ret
== 0, "Babeltrace could read the resulting trace");
240 if (ret
&& babeltrace_output_fd
>= 0) {
242 size_t len
= METADATA_LINE_SIZE
;
243 FILE *babeltrace_output_fp
= NULL
;
245 babeltrace_output_fp
= fdopen(babeltrace_output_fd
, "r");
246 if (!babeltrace_output_fp
) {
247 perror("fdopen on babeltrace_output_fd");
250 babeltrace_output_fd
= -1;
254 diag("malloc error");
256 rewind(babeltrace_output_fp
);
257 while (getline(&line
, &len
, babeltrace_output_fp
) > 0) {
263 if (babeltrace_output_fp
) {
264 if (fclose(babeltrace_output_fp
)) {
265 diag("fclose error");
270 if (babeltrace_output_fd
>= 0) {
271 if (close(babeltrace_output_fd
)) {
277 void append_simple_event(struct bt_ctf_stream_class
*stream_class
,
278 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
280 /* Create and add a simple event class */
281 struct bt_ctf_event_class
*simple_event_class
=
282 bt_ctf_event_class_create("Simple Event");
283 struct bt_ctf_field_type
*uint_12_type
=
284 bt_ctf_field_type_integer_create(12);
285 struct bt_ctf_field_type
*int_64_type
=
286 bt_ctf_field_type_integer_create(64);
287 struct bt_ctf_field_type
*float_type
=
288 bt_ctf_field_type_floating_point_create();
289 struct bt_ctf_field_type
*enum_type
;
290 struct bt_ctf_field_type
*enum_type_unsigned
=
291 bt_ctf_field_type_enumeration_create(uint_12_type
);
292 struct bt_ctf_field_type
*event_context_type
=
293 bt_ctf_field_type_structure_create();
294 struct bt_ctf_field_type
*returned_type
;
295 struct bt_ctf_event
*simple_event
;
296 struct bt_ctf_field
*integer_field
;
297 struct bt_ctf_field
*float_field
;
298 struct bt_ctf_field
*enum_field
;
299 struct bt_ctf_field
*enum_field_unsigned
;
300 struct bt_ctf_field
*enum_container_field
;
301 const char *mapping_name_test
= "truie";
302 const double double_test_value
= 3.1415;
303 struct bt_ctf_field
*enum_container_field_unsigned
;
304 const char *mapping_name_negative_test
= "negative_value";
305 const char *ret_char
;
307 int64_t ret_range_start_int64_t
, ret_range_end_int64_t
;
308 uint64_t ret_range_start_uint64_t
, ret_range_end_uint64_t
;
309 struct bt_ctf_clock
*ret_clock
;
310 struct bt_ctf_event_class
*ret_event_class
;
311 struct bt_ctf_field
*packet_context
;
312 struct bt_ctf_field
*packet_context_field
;
313 struct bt_ctf_field
*stream_event_context
;
314 struct bt_ctf_field
*stream_event_context_field
;
315 struct bt_ctf_field
*event_context
;
316 struct bt_ctf_field
*event_context_field
;
318 ok(uint_12_type
, "Create an unsigned integer type");
320 bt_ctf_field_type_integer_set_signed(int_64_type
, 1);
321 ok(int_64_type
, "Create a signed integer type");
322 enum_type
= bt_ctf_field_type_enumeration_create(int_64_type
);
324 returned_type
= bt_ctf_field_type_enumeration_get_container_type(enum_type
);
325 ok(returned_type
== int_64_type
, "bt_ctf_field_type_enumeration_get_container_type returns the right type");
326 ok(!bt_ctf_field_type_enumeration_get_container_type(NULL
), "bt_ctf_field_type_enumeration_get_container_type handles NULL correctly");
327 ok(!bt_ctf_field_type_enumeration_create(enum_type
),
328 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
329 bt_ctf_field_type_put(returned_type
);
331 bt_ctf_field_type_set_alignment(float_type
, 32);
332 ok(bt_ctf_field_type_get_alignment(NULL
) < 0,
333 "bt_ctf_field_type_get_alignment handles NULL correctly");
334 ok(bt_ctf_field_type_get_alignment(float_type
) == 32,
335 "bt_ctf_field_type_get_alignment returns a correct value");
337 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type
, 11) == 0,
338 "Set a floating point type's exponent digit count");
339 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type
, 53) == 0,
340 "Set a floating point type's mantissa digit count");
342 ok(bt_ctf_field_type_floating_point_get_exponent_digits(NULL
) < 0,
343 "bt_ctf_field_type_floating_point_get_exponent_digits handles NULL properly");
344 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(NULL
) < 0,
345 "bt_ctf_field_type_floating_point_get_mantissa_digits handles NULL properly");
346 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type
) == 11,
347 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
348 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type
) == 53,
349 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
351 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
352 mapping_name_negative_test
, -12345, 0) == 0,
353 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
354 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
355 "escaping; \"test\"", 1, 1) == 0,
356 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
357 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
358 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
359 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
360 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
361 "event clock int float", 5, 22) == 0,
362 "Accept enumeration mapping strings containing reserved keywords");
363 bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
365 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
366 43, 51), "bt_ctf_field_type_enumeration_add_mapping rejects duplicate mapping names");
367 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, "something",
368 -500, -400), "bt_ctf_field_type_enumeration_add_mapping rejects overlapping enum entries");
369 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
370 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
371 bt_ctf_field_type_enumeration_add_mapping(enum_type
, "another entry", -42000, -13000);
373 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(NULL
, -42) < 0,
374 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles a NULL field type correctly");
375 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type
, 1000000) < 0,
376 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles invalid values correctly");
377 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type
, -55) == 1,
378 "bt_ctf_field_type_enumeration_get_mapping_index_by_value returns the correct index");
380 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type
,
381 "enum_field") == 0, "Add signed enumeration field to event");
383 ok(bt_ctf_field_type_enumeration_get_mapping(NULL
, 0, &ret_char
,
384 &ret_range_start_int64_t
, &ret_range_end_int64_t
) < 0,
385 "bt_ctf_field_type_enumeration_get_mapping handles a NULL enumeration correctly");
386 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 0, NULL
,
387 &ret_range_start_int64_t
, &ret_range_end_int64_t
) < 0,
388 "bt_ctf_field_type_enumeration_get_mapping handles a NULL string correctly");
389 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 0, &ret_char
,
390 NULL
, &ret_range_end_int64_t
) < 0,
391 "bt_ctf_field_type_enumeration_get_mapping handles a NULL start correctly");
392 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 0, &ret_char
,
393 &ret_range_start_int64_t
, NULL
) < 0,
394 "bt_ctf_field_type_enumeration_get_mapping handles a NULL end correctly");
395 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type
, 5, &ret_char
,
396 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
397 "bt_ctf_field_type_enumeration_get_mapping returns a value");
398 ok(!strcmp(ret_char
, mapping_name_test
),
399 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping name");
400 ok(ret_range_start_int64_t
== 42,
401 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping start");
402 ok(ret_range_end_int64_t
== 42,
403 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping end");
405 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
406 "escaping; \"test\"", 0, 0) == 0,
407 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing quotes");
408 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
409 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
410 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing special characters");
411 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
412 "event clock int float", 5, 22) == 0,
413 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing reserved keywords");
414 bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
416 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
417 43, 51), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects duplicate mapping names");
418 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, "something",
419 7, 8), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects overlapping enum entries");
420 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
421 55, 54), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects mapping where end < start");
422 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type_unsigned
,
423 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
425 ok(bt_ctf_field_type_enumeration_get_mapping_count(NULL
) < 0,
426 "bt_ctf_field_type_enumeration_get_mapping_count handles NULL correctly");
427 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned
) == 4,
428 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
430 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(NULL
, 0, &ret_char
,
431 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) < 0,
432 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL enumeration correctly");
433 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, NULL
,
434 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) < 0,
435 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL string correctly");
436 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, &ret_char
,
437 NULL
, &ret_range_end_uint64_t
) < 0,
438 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL start correctly");
439 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, &ret_char
,
440 &ret_range_start_uint64_t
, NULL
) < 0,
441 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL end correctly");
442 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 3, &ret_char
,
443 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
444 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a value");
445 ok(!strcmp(ret_char
, mapping_name_test
),
446 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping name");
447 ok(ret_range_start_uint64_t
== 42,
448 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping start");
449 ok(ret_range_end_uint64_t
== 42,
450 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping end");
452 bt_ctf_event_class_add_field(simple_event_class
, uint_12_type
,
454 bt_ctf_event_class_add_field(simple_event_class
, float_type
,
456 bt_ctf_stream_class_add_event_class(stream_class
,
459 ok(bt_ctf_stream_class_get_event_class_count(NULL
) < 0,
460 "bt_ctf_stream_class_get_event_class_count handles NULL correctly");
461 ok(bt_ctf_stream_class_get_event_class_count(stream_class
) == 1,
462 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
463 ok(bt_ctf_stream_class_get_event_class(NULL
, 0) == NULL
,
464 "bt_ctf_stream_class_get_event_class handles NULL correctly");
465 ok(bt_ctf_stream_class_get_event_class(stream_class
, 8724) == NULL
,
466 "bt_ctf_stream_class_get_event_class handles invalid indexes correctly");
467 ret_event_class
= bt_ctf_stream_class_get_event_class(stream_class
, 0);
468 ok(ret_event_class
== simple_event_class
,
469 "bt_ctf_stream_class_get_event_class returns the correct event class");
470 bt_ctf_event_class_put(ret_event_class
);
472 ok(bt_ctf_stream_class_get_event_class_by_name(NULL
, "some event name") == NULL
,
473 "bt_ctf_stream_class_get_event_class_by_name handles a NULL stream class correctly");
474 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class
, NULL
) == NULL
,
475 "bt_ctf_stream_class_get_event_class_by_name handles a NULL event class name correctly");
476 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class
, "some event name") == NULL
,
477 "bt_ctf_stream_class_get_event_class_by_name handles non-existing event class names correctly");
478 ret_event_class
= bt_ctf_stream_class_get_event_class_by_name(stream_class
, "Simple Event");
479 ok(ret_event_class
== simple_event_class
,
480 "bt_ctf_stream_class_get_event_class_by_name returns a correct event class");
481 bt_ctf_event_class_put(ret_event_class
);
483 /* Set an event context type which will contain a single integer*/
484 bt_ctf_field_type_structure_add_field(event_context_type
, uint_12_type
,
485 "event_specific_context");
486 ok(bt_ctf_event_class_get_context_type(NULL
) == NULL
,
487 "bt_ctf_event_class_get_context_type handles NULL correctly");
488 ok(bt_ctf_event_class_get_context_type(simple_event_class
) == NULL
,
489 "bt_ctf_event_class_get_context_type returns NULL when no event context type is set");
490 ok(bt_ctf_event_class_set_context_type(simple_event_class
, NULL
) < 0,
491 "bt_ctf_event_class_set_context_type handles a NULL context type correctly");
492 ok(bt_ctf_event_class_set_context_type(NULL
, event_context_type
) < 0,
493 "bt_ctf_event_class_set_context_type handles a NULL event class correctly");
494 ok(!bt_ctf_event_class_set_context_type(simple_event_class
, event_context_type
),
495 "Set an event class' context type successfully");
496 returned_type
= bt_ctf_event_class_get_context_type(simple_event_class
);
497 ok(returned_type
== event_context_type
,
498 "bt_ctf_event_class_get_context_type returns the appropriate type");
499 bt_ctf_field_type_put(returned_type
);
501 simple_event
= bt_ctf_event_create(simple_event_class
);
503 "Instantiate an event containing a single integer field");
505 ok(bt_ctf_event_get_clock(NULL
) == NULL
,
506 "bt_ctf_event_get_clock handles NULL correctly");
507 ret_clock
= bt_ctf_event_get_clock(simple_event
);
508 ok(ret_clock
== clock
,
509 "bt_ctf_event_get_clock returns a correct clock");
510 bt_ctf_clock_put(clock
);
512 integer_field
= bt_ctf_field_create(uint_12_type
);
513 bt_ctf_field_unsigned_integer_set_value(integer_field
, 42);
514 ok(bt_ctf_event_set_payload(simple_event
, "integer_field",
515 integer_field
) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
517 float_field
= bt_ctf_event_get_payload(simple_event
, "float_field");
518 ok(bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
519 "bt_ctf_field_floating_point_get_value fails on an unset float field");
520 bt_ctf_field_floating_point_set_value(float_field
, double_test_value
);
521 ok(bt_ctf_field_floating_point_get_value(NULL
, &ret_double
),
522 "bt_ctf_field_floating_point_get_value properly handles a NULL field");
523 ok(bt_ctf_field_floating_point_get_value(float_field
, NULL
),
524 "bt_ctf_field_floating_point_get_value properly handles a NULL return value pointer");
525 ok(!bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
526 "bt_ctf_field_floating_point_get_value returns a double value");
527 ok(fabs(ret_double
- double_test_value
) <= DBL_EPSILON
,
528 "bt_ctf_field_floating_point_get_value returns a correct value");
530 enum_field
= bt_ctf_field_create(enum_type
);
531 ret_char
= bt_ctf_field_enumeration_get_mapping_name(NULL
);
532 ok(!ret_char
, "bt_ctf_field_enumeration_get_mapping_name handles NULL correctly");
533 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field
);
534 ok(!ret_char
, "bt_ctf_field_enumeration_get_mapping_name returns NULL if the enumeration's container field is unset");
535 enum_container_field
= bt_ctf_field_enumeration_get_container(
537 ok(bt_ctf_field_signed_integer_set_value(
538 enum_container_field
, -42) == 0,
539 "Set signed enumeration container value");
540 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field
);
541 ok(!strcmp(ret_char
, mapping_name_negative_test
),
542 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an signed container");
543 bt_ctf_event_set_payload(simple_event
, "enum_field", enum_field
);
545 enum_field_unsigned
= bt_ctf_field_create(enum_type_unsigned
);
546 enum_container_field_unsigned
= bt_ctf_field_enumeration_get_container(
547 enum_field_unsigned
);
548 ok(bt_ctf_field_unsigned_integer_set_value(
549 enum_container_field_unsigned
, 42) == 0,
550 "Set unsigned enumeration container value");
551 bt_ctf_event_set_payload(simple_event
, "enum_field_unsigned",
552 enum_field_unsigned
);
553 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field_unsigned
);
554 ok(!strcmp(ret_char
, mapping_name_test
),
555 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an unsigned container");
557 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0, "Set clock time");
559 /* Populate stream event context */
560 stream_event_context
= bt_ctf_stream_get_event_context(stream
);
561 stream_event_context_field
= bt_ctf_field_structure_get_field(
562 stream_event_context
, "common_event_context");
563 bt_ctf_field_unsigned_integer_set_value(stream_event_context_field
, 42);
565 /* Populate the event's context */
566 ok(bt_ctf_event_get_event_context(NULL
) == NULL
,
567 "bt_ctf_event_get_event_context handles NULL correctly");
568 event_context
= bt_ctf_event_get_event_context(simple_event
);
570 "bt_ctf_event_get_event_context returns a field");
571 returned_type
= bt_ctf_field_get_type(event_context
);
572 ok(returned_type
== event_context_type
,
573 "bt_ctf_event_get_event_context returns a field of the appropriate type");
574 event_context_field
= bt_ctf_field_structure_get_field(event_context
,
575 "event_specific_context");
576 ok(!bt_ctf_field_unsigned_integer_set_value(event_context_field
, 1234),
577 "Successfully set an event context's value");
578 ok(bt_ctf_event_set_event_context(NULL
, event_context
) < 0,
579 "bt_ctf_event_set_event_context handles a NULL event correctly");
580 ok(bt_ctf_event_set_event_context(simple_event
, NULL
) < 0,
581 "bt_ctf_event_set_event_context handles a NULL event context correctly");
582 ok(bt_ctf_event_set_event_context(simple_event
, event_context_field
) < 0,
583 "bt_ctf_event_set_event_context rejects a context of the wrong type");
584 ok(!bt_ctf_event_set_event_context(simple_event
, event_context
),
585 "Set an event context successfully");
587 ok(bt_ctf_stream_append_event(stream
, simple_event
) == 0,
588 "Append simple event to trace stream");
590 ok(bt_ctf_stream_get_packet_context(NULL
) == NULL
,
591 "bt_ctf_stream_get_packet_context handles NULL correctly");
592 packet_context
= bt_ctf_stream_get_packet_context(stream
);
594 "bt_ctf_stream_get_packet_context returns a packet context");
596 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
598 ok(packet_context_field
,
599 "Packet context contains the default packet_size field.");
600 bt_ctf_field_put(packet_context_field
);
601 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
602 "custom_packet_context_field");
603 ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 8) == 0,
604 "Custom packet context field value successfully set.");
606 ok(bt_ctf_stream_set_packet_context(NULL
, packet_context_field
) < 0,
607 "bt_ctf_stream_set_packet_context handles a NULL stream correctly");
608 ok(bt_ctf_stream_set_packet_context(stream
, NULL
) < 0,
609 "bt_ctf_stream_set_packet_context handles a NULL packet context correctly");
610 ok(bt_ctf_stream_set_packet_context(stream
, packet_context
) == 0,
611 "Successfully set a stream's packet context");
613 ok(bt_ctf_stream_flush(stream
) == 0,
614 "Flush trace stream with one event");
616 bt_ctf_event_class_put(simple_event_class
);
617 bt_ctf_event_put(simple_event
);
618 bt_ctf_field_type_put(uint_12_type
);
619 bt_ctf_field_type_put(int_64_type
);
620 bt_ctf_field_type_put(float_type
);
621 bt_ctf_field_type_put(enum_type
);
622 bt_ctf_field_type_put(enum_type_unsigned
);
623 bt_ctf_field_type_put(returned_type
);
624 bt_ctf_field_type_put(event_context_type
);
625 bt_ctf_field_put(integer_field
);
626 bt_ctf_field_put(float_field
);
627 bt_ctf_field_put(enum_field
);
628 bt_ctf_field_put(enum_field_unsigned
);
629 bt_ctf_field_put(enum_container_field
);
630 bt_ctf_field_put(enum_container_field_unsigned
);
631 bt_ctf_field_put(packet_context
);
632 bt_ctf_field_put(packet_context_field
);
633 bt_ctf_field_put(stream_event_context
);
634 bt_ctf_field_put(stream_event_context_field
);
635 bt_ctf_field_put(event_context
);
636 bt_ctf_field_put(event_context_field
);
639 void append_complex_event(struct bt_ctf_stream_class
*stream_class
,
640 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
643 const char *complex_test_event_string
= "Complex Test Event";
644 const char *test_string
= "Test string";
645 struct bt_ctf_field_type
*uint_35_type
=
646 bt_ctf_field_type_integer_create(35);
647 struct bt_ctf_field_type
*int_16_type
=
648 bt_ctf_field_type_integer_create(16);
649 struct bt_ctf_field_type
*uint_3_type
=
650 bt_ctf_field_type_integer_create(3);
651 struct bt_ctf_field_type
*enum_variant_type
=
652 bt_ctf_field_type_enumeration_create(uint_3_type
);
653 struct bt_ctf_field_type
*variant_type
=
654 bt_ctf_field_type_variant_create(enum_variant_type
,
656 struct bt_ctf_field_type
*string_type
=
657 bt_ctf_field_type_string_create();
658 struct bt_ctf_field_type
*sequence_type
;
659 struct bt_ctf_field_type
*array_type
;
660 struct bt_ctf_field_type
*inner_structure_type
=
661 bt_ctf_field_type_structure_create();
662 struct bt_ctf_field_type
*complex_structure_type
=
663 bt_ctf_field_type_structure_create();
664 struct bt_ctf_field_type
*ret_field_type
;
665 struct bt_ctf_event_class
*event_class
;
666 struct bt_ctf_event
*event
;
667 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
668 *inner_structure_field
, *complex_structure_field
,
669 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
670 *variant_field
, *an_array_field
, *ret_field
;
671 uint64_t ret_unsigned_int
;
672 int64_t ret_signed_int
;
673 const char *ret_string
;
674 struct bt_ctf_stream_class
*ret_stream_class
;
675 struct bt_ctf_event_class
*ret_event_class
;
676 struct bt_ctf_field
*packet_context
, *packet_context_field
;
678 bt_ctf_field_type_set_alignment(int_16_type
, 32);
679 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
680 bt_ctf_field_type_integer_set_base(uint_35_type
,
681 BT_CTF_INTEGER_BASE_HEXADECIMAL
);
683 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
684 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
687 ok(bt_ctf_field_type_array_get_element_type(NULL
) == NULL
,
688 "bt_ctf_field_type_array_get_element_type handles NULL correctly");
689 ret_field_type
= bt_ctf_field_type_array_get_element_type(
691 ok(ret_field_type
== int_16_type
,
692 "bt_ctf_field_type_array_get_element_type returns the correct type");
693 bt_ctf_field_type_put(ret_field_type
);
695 ok(bt_ctf_field_type_array_get_length(NULL
) < 0,
696 "bt_ctf_field_type_array_get_length handles NULL correctly");
697 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
698 "bt_ctf_field_type_array_get_length returns the correct length");
700 bt_ctf_field_type_structure_add_field(inner_structure_type
,
701 uint_35_type
, "seq_len");
702 bt_ctf_field_type_structure_add_field(inner_structure_type
,
703 sequence_type
, "a_sequence");
704 bt_ctf_field_type_structure_add_field(inner_structure_type
,
705 array_type
, "an_array");
707 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
709 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
711 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
712 "UINT35_TYPE", 2, 7);
714 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL
,
716 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly");
717 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
718 enum_variant_type
, NULL
) < 0,
719 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly");
720 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
721 enum_variant_type
, "INT16_TYPE") == 1,
722 "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index");
724 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL
, 1) < 0,
725 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly");
726 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, -42) < 0,
727 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly");
728 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, 5) == 2,
729 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index");
731 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
732 "An unknown entry"), "Reject a variant field based on an unknown tag value");
733 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
734 "UINT3_TYPE") == 0, "Add a field to a variant");
735 bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
737 bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
740 ok(bt_ctf_field_type_variant_get_tag_type(NULL
) == NULL
,
741 "bt_ctf_field_type_variant_get_tag_type handles NULL correctly");
742 ret_field_type
= bt_ctf_field_type_variant_get_tag_type(variant_type
);
743 ok(ret_field_type
== enum_variant_type
,
744 "bt_ctf_field_type_variant_get_tag_type returns a correct tag type");
745 bt_ctf_field_type_put(ret_field_type
);
747 ok(bt_ctf_field_type_variant_get_tag_name(NULL
) == NULL
,
748 "bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
749 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
750 ok(!strcmp(ret_string
, "variant_selector"),
751 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
752 ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL
,
753 "INT16_TYPE") == NULL
,
754 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
755 ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type
,
757 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
758 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
759 variant_type
, "INT16_TYPE");
760 ok(ret_field_type
== int_16_type
,
761 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
762 bt_ctf_field_type_put(ret_field_type
);
764 ok(bt_ctf_field_type_variant_get_field_count(NULL
) < 0,
765 "bt_ctf_field_type_variant_get_field_count handles NULL correctly");
766 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
767 "bt_ctf_field_type_variant_get_field_count returns the correct count");
769 ok(bt_ctf_field_type_variant_get_field(NULL
, &ret_string
, &ret_field_type
, 0) < 0,
770 "bt_ctf_field_type_variant_get_field handles a NULL type correctly");
771 ok(bt_ctf_field_type_variant_get_field(variant_type
, NULL
, &ret_field_type
, 0) < 0,
772 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
773 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, NULL
, 0) < 0,
774 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
775 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 200) < 0,
776 "bt_ctf_field_type_variant_get_field handles an invalid index correctly");
777 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
778 "bt_ctf_field_type_variant_get_field returns a field");
779 ok(!strcmp("INT16_TYPE", ret_string
),
780 "bt_ctf_field_type_variant_get_field returns a correct field name");
781 ok(ret_field_type
== int_16_type
,
782 "bt_ctf_field_type_variant_get_field returns a correct field type");
783 bt_ctf_field_type_put(ret_field_type
);
785 bt_ctf_field_type_structure_add_field(complex_structure_type
,
786 enum_variant_type
, "variant_selector");
787 bt_ctf_field_type_structure_add_field(complex_structure_type
,
788 string_type
, "a_string");
789 bt_ctf_field_type_structure_add_field(complex_structure_type
,
790 variant_type
, "variant_value");
791 bt_ctf_field_type_structure_add_field(complex_structure_type
,
792 inner_structure_type
, "inner_structure");
794 ok(bt_ctf_event_class_create("clock") == NULL
,
795 "Reject creation of an event class with an illegal name");
796 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
797 ok(event_class
, "Create an event class");
798 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
799 "Reject addition of a field with an empty name to an event");
800 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
801 "Reject addition of a field with a NULL type to an event");
802 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
804 "Reject addition of a type with an illegal name to an event");
805 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
807 "Add field of type unsigned integer to an event");
808 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
809 "int_16") == 0, "Add field of type signed integer to an event");
810 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
811 "complex_structure") == 0,
812 "Add composite structure to an event");
814 ok(bt_ctf_event_class_get_name(NULL
) == NULL
,
815 "bt_ctf_event_class_get_name handles NULL correctly");
816 ret_string
= bt_ctf_event_class_get_name(event_class
);
817 ok(!strcmp(ret_string
, complex_test_event_string
),
818 "bt_ctf_event_class_get_name returns a correct name");
819 ok(bt_ctf_event_class_get_id(event_class
) < 0,
820 "bt_ctf_event_class_get_id returns a negative value when not set");
821 ok(bt_ctf_event_class_get_id(NULL
) < 0,
822 "bt_ctf_event_class_get_id handles NULL correctly");
823 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
824 "bt_ctf_event_class_set_id handles NULL correctly");
825 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
826 "Set an event class' id");
827 ok(bt_ctf_event_class_get_id(event_class
) == 42,
828 "bt_ctf_event_class_get_id returns the correct value");
830 /* Add event class to the stream class */
831 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
832 "Reject addition of NULL event class to a stream class");
833 ok(bt_ctf_stream_class_add_event_class(stream_class
,
834 event_class
) == 0, "Add an event class to stream class");
836 ok(bt_ctf_event_class_get_stream_class(NULL
) == NULL
,
837 "bt_ctf_event_class_get_stream_class handles NULL correctly");
838 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
839 ok(ret_stream_class
== stream_class
,
840 "bt_ctf_event_class_get_stream_class returns the correct stream class");
841 bt_ctf_stream_class_put(ret_stream_class
);
843 ok(bt_ctf_event_class_get_field_count(NULL
) < 0,
844 "bt_ctf_event_class_get_field_count handles NULL correctly");
845 ok(bt_ctf_event_class_get_field_count(event_class
) == 3,
846 "bt_ctf_event_class_get_field_count returns a correct value");
848 ok(bt_ctf_event_class_get_field(NULL
, &ret_string
,
849 &ret_field_type
, 0) < 0,
850 "bt_ctf_event_class_get_field handles a NULL event class correctly");
851 ok(bt_ctf_event_class_get_field(event_class
, NULL
,
852 &ret_field_type
, 0) < 0,
853 "bt_ctf_event_class_get_field handles a NULL field name correctly");
854 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
856 "bt_ctf_event_class_get_field handles a NULL field type correctly");
857 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
858 &ret_field_type
, 42) < 0,
859 "bt_ctf_event_class_get_field handles an invalid index correctly");
860 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
861 &ret_field_type
, 0) == 0,
862 "bt_ctf_event_class_get_field returns a field");
863 ok(ret_field_type
== uint_35_type
,
864 "bt_ctf_event_class_get_field returns a correct field type");
865 bt_ctf_field_type_put(ret_field_type
);
866 ok(!strcmp(ret_string
, "uint_35"),
867 "bt_ctf_event_class_get_field returns a correct field name");
868 ok(bt_ctf_event_class_get_field_by_name(NULL
, "") == NULL
,
869 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
870 ok(bt_ctf_event_class_get_field_by_name(event_class
, NULL
) == NULL
,
871 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
872 ok(bt_ctf_event_class_get_field_by_name(event_class
, "truie") == NULL
,
873 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
874 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
875 "complex_structure");
876 ok(ret_field_type
== complex_structure_type
,
877 "bt_ctf_event_class_get_field_by_name returns a correct field type");
878 bt_ctf_field_type_put(ret_field_type
);
880 event
= bt_ctf_event_create(event_class
);
881 ok(event
, "Instanciate a complex event");
883 ok(bt_ctf_event_get_class(NULL
) == NULL
,
884 "bt_ctf_event_get_class handles NULL correctly");
885 ret_event_class
= bt_ctf_event_get_class(event
);
886 ok(ret_event_class
== event_class
,
887 "bt_ctf_event_get_class returns the correct event class");
888 bt_ctf_event_class_put(ret_event_class
);
890 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
891 if (!uint_35_field
) {
892 printf("uint_35_field is NULL\n");
895 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
896 bt_ctf_field_unsigned_integer_set_value(uint_35_field
, 0x0DDF00D);
897 ok(bt_ctf_field_unsigned_integer_get_value(NULL
, &ret_unsigned_int
) < 0,
898 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
899 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
, NULL
) < 0,
900 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
901 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
,
902 &ret_unsigned_int
) == 0,
903 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
904 ok(ret_unsigned_int
== 0x0DDF00D,
905 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
906 ok(bt_ctf_field_signed_integer_get_value(uint_35_field
,
907 &ret_signed_int
) < 0,
908 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
909 bt_ctf_field_put(uint_35_field
);
911 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
912 bt_ctf_field_signed_integer_set_value(int_16_field
, -12345);
913 ok(bt_ctf_field_signed_integer_get_value(NULL
, &ret_signed_int
) < 0,
914 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
915 ok(bt_ctf_field_signed_integer_get_value(int_16_field
, NULL
) < 0,
916 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
917 ok(bt_ctf_field_signed_integer_get_value(int_16_field
,
918 &ret_signed_int
) == 0,
919 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
920 ok(ret_signed_int
== -12345,
921 "bt_ctf_field_signed_integer_get_value returns the correct value");
922 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field
,
923 &ret_unsigned_int
) < 0,
924 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
925 bt_ctf_field_put(int_16_field
);
927 complex_structure_field
= bt_ctf_event_get_payload(event
,
928 "complex_structure");
930 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 0) == NULL
,
931 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
932 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 9) == NULL
,
933 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
934 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
935 complex_structure_field
, 3);
936 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
937 bt_ctf_field_put(inner_structure_field
);
938 ok(ret_field_type
== inner_structure_type
,
939 "bt_ctf_field_structure_get_field_by_index returns a correct field");
940 bt_ctf_field_type_put(ret_field_type
);
942 inner_structure_field
= bt_ctf_field_structure_get_field(
943 complex_structure_field
, "inner_structure");
944 a_string_field
= bt_ctf_field_structure_get_field(
945 complex_structure_field
, "a_string");
946 enum_variant_field
= bt_ctf_field_structure_get_field(
947 complex_structure_field
, "variant_selector");
948 variant_field
= bt_ctf_field_structure_get_field(
949 complex_structure_field
, "variant_value");
950 uint_35_field
= bt_ctf_field_structure_get_field(
951 inner_structure_field
, "seq_len");
952 a_sequence_field
= bt_ctf_field_structure_get_field(
953 inner_structure_field
, "a_sequence");
954 an_array_field
= bt_ctf_field_structure_get_field(
955 inner_structure_field
, "an_array");
957 enum_container_field
= bt_ctf_field_enumeration_get_container(
959 bt_ctf_field_unsigned_integer_set_value(enum_container_field
, 1);
960 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
962 bt_ctf_field_signed_integer_set_value(int_16_field
, -200);
963 bt_ctf_field_put(int_16_field
);
964 ok(!bt_ctf_field_string_get_value(a_string_field
),
965 "bt_ctf_field_string_get_value returns NULL on an unset field");
966 bt_ctf_field_string_set_value(a_string_field
,
968 ok(!bt_ctf_field_string_get_value(NULL
),
969 "bt_ctf_field_string_get_value correctly handles NULL");
970 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
971 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
972 ok(ret_string
? !strcmp(ret_string
, test_string
) : 0,
973 "bt_ctf_field_string_get_value returns a correct value");
974 bt_ctf_field_unsigned_integer_set_value(uint_35_field
,
975 SEQUENCE_TEST_LENGTH
);
977 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL
,
978 enum_container_field
) == NULL
,
979 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
980 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type
,
982 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
983 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
984 variant_type
, enum_variant_field
);
985 ok(ret_field_type
== int_16_type
,
986 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
988 ok(bt_ctf_field_sequence_get_length(a_sequence_field
) == NULL
,
989 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
990 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
991 uint_35_field
) == 0, "Set a sequence field's length");
992 ret_field
= bt_ctf_field_sequence_get_length(a_sequence_field
);
993 ok(ret_field
== uint_35_field
,
994 "bt_ctf_field_sequence_get_length returns the correct length field");
995 ok(bt_ctf_field_sequence_get_length(NULL
) == NULL
,
996 "bt_ctf_field_sequence_get_length properly handles NULL");
998 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
999 int_16_field
= bt_ctf_field_sequence_get_field(
1000 a_sequence_field
, i
);
1001 bt_ctf_field_signed_integer_set_value(int_16_field
, 4 - i
);
1002 bt_ctf_field_put(int_16_field
);
1005 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
1006 int_16_field
= bt_ctf_field_array_get_field(
1008 bt_ctf_field_signed_integer_set_value(int_16_field
, i
);
1009 bt_ctf_field_put(int_16_field
);
1012 bt_ctf_clock_set_time(clock
, ++current_time
);
1013 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
1014 "Append a complex event to a stream");
1017 * Populate the custom packet context field with a dummy value
1018 * otherwise flush will fail.
1020 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1021 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1022 "custom_packet_context_field");
1023 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 1);
1025 ok(bt_ctf_stream_flush(stream
) == 0,
1026 "Flush a stream containing a complex event");
1028 bt_ctf_field_put(uint_35_field
);
1029 bt_ctf_field_put(a_string_field
);
1030 bt_ctf_field_put(inner_structure_field
);
1031 bt_ctf_field_put(complex_structure_field
);
1032 bt_ctf_field_put(a_sequence_field
);
1033 bt_ctf_field_put(an_array_field
);
1034 bt_ctf_field_put(enum_variant_field
);
1035 bt_ctf_field_put(enum_container_field
);
1036 bt_ctf_field_put(variant_field
);
1037 bt_ctf_field_put(ret_field
);
1038 bt_ctf_field_put(packet_context_field
);
1039 bt_ctf_field_put(packet_context
);
1040 bt_ctf_field_type_put(uint_35_type
);
1041 bt_ctf_field_type_put(int_16_type
);
1042 bt_ctf_field_type_put(string_type
);
1043 bt_ctf_field_type_put(sequence_type
);
1044 bt_ctf_field_type_put(array_type
);
1045 bt_ctf_field_type_put(inner_structure_type
);
1046 bt_ctf_field_type_put(complex_structure_type
);
1047 bt_ctf_field_type_put(uint_3_type
);
1048 bt_ctf_field_type_put(enum_variant_type
);
1049 bt_ctf_field_type_put(variant_type
);
1050 bt_ctf_field_type_put(ret_field_type
);
1051 bt_ctf_event_class_put(event_class
);
1052 bt_ctf_event_put(event
);
1055 void type_field_tests()
1057 struct bt_ctf_field
*uint_12
;
1058 struct bt_ctf_field
*int_16
;
1059 struct bt_ctf_field
*string
;
1060 struct bt_ctf_field
*enumeration
;
1061 struct bt_ctf_field_type
*composite_structure_type
;
1062 struct bt_ctf_field_type
*structure_seq_type
;
1063 struct bt_ctf_field_type
*string_type
;
1064 struct bt_ctf_field_type
*sequence_type
;
1065 struct bt_ctf_field_type
*uint_8_type
;
1066 struct bt_ctf_field_type
*int_16_type
;
1067 struct bt_ctf_field_type
*uint_12_type
=
1068 bt_ctf_field_type_integer_create(12);
1069 struct bt_ctf_field_type
*enumeration_type
;
1070 struct bt_ctf_field_type
*enumeration_sequence_type
;
1071 struct bt_ctf_field_type
*enumeration_array_type
;
1072 struct bt_ctf_field_type
*returned_type
;
1073 const char *ret_string
;
1075 returned_type
= bt_ctf_field_get_type(NULL
);
1076 ok(!returned_type
, "bt_ctf_field_get_type handles NULL correctly");
1078 ok(uint_12_type
, "Create an unsigned integer type");
1079 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1080 BT_CTF_INTEGER_BASE_BINARY
) == 0,
1081 "Set integer type's base as binary");
1082 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1083 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
1084 "Set integer type's base as decimal");
1085 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1086 BT_CTF_INTEGER_BASE_UNKNOWN
),
1087 "Reject integer type's base set as unknown");
1088 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1089 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
1090 "Set integer type's base as octal");
1091 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1092 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
1093 "Set integer type's base as hexadecimal");
1094 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
1095 "Reject unknown integer base value");
1096 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
1097 "Set integer type signedness to signed");
1098 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
1099 "Set integer type signedness to unsigned");
1100 ok(bt_ctf_field_type_integer_get_size(NULL
) < 0,
1101 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1102 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
1103 "bt_ctf_field_type_integer_get_size returns a correct value");
1104 ok(bt_ctf_field_type_integer_get_signed(NULL
) < 0,
1105 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1106 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
1107 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1109 ok(bt_ctf_field_type_set_byte_order(NULL
,
1110 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
1111 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1112 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1113 (enum bt_ctf_byte_order
) 42) < 0,
1114 "bt_ctf_field_type_set_byte_order rejects invalid values");
1115 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1116 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
1117 "Set an integer's byte order to little endian");
1118 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1119 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1120 "Set an integer's byte order to big endian");
1121 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
1122 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1123 "bt_ctf_field_type_get_byte_order returns a correct value");
1124 ok(bt_ctf_field_type_get_byte_order(NULL
) ==
1125 BT_CTF_BYTE_ORDER_UNKNOWN
,
1126 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1128 ok(bt_ctf_field_type_get_type_id(NULL
) ==
1130 "bt_ctf_field_type_get_type_id handles NULL correctly");
1131 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
1133 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1135 ok(bt_ctf_field_type_integer_get_base(NULL
) ==
1136 BT_CTF_INTEGER_BASE_UNKNOWN
,
1137 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1138 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
1139 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
1140 "bt_ctf_field_type_integer_get_base returns a correct value");
1142 ok(bt_ctf_field_type_integer_set_encoding(NULL
, CTF_STRING_ASCII
) < 0,
1143 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1144 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1145 (enum ctf_string_encoding
) 123) < 0,
1146 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1147 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1148 CTF_STRING_UTF8
) == 0,
1149 "Set integer type encoding to UTF8");
1150 ok(bt_ctf_field_type_integer_get_encoding(NULL
) == CTF_STRING_UNKNOWN
,
1151 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1152 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) == CTF_STRING_UTF8
,
1153 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1155 int_16_type
= bt_ctf_field_type_integer_create(16);
1156 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
1157 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
1158 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1159 uint_8_type
= bt_ctf_field_type_integer_create(8);
1161 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
1162 ok(sequence_type
, "Create a sequence of int16_t type");
1163 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
1165 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1167 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL
) == NULL
,
1168 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1169 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
1171 ok(!strcmp(ret_string
, "seq_len"),
1172 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1173 ok(bt_ctf_field_type_sequence_get_element_type(NULL
) == NULL
,
1174 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1175 returned_type
= bt_ctf_field_type_sequence_get_element_type(
1177 ok(returned_type
== int_16_type
,
1178 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
1179 bt_ctf_field_type_put(returned_type
);
1181 string_type
= bt_ctf_field_type_string_create();
1182 ok(string_type
, "Create a string type");
1183 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1185 "Reject invalid \"None\" string encoding");
1186 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1188 "Reject invalid string encoding");
1189 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1190 CTF_STRING_ASCII
) == 0,
1191 "Set string encoding to ASCII");
1193 ok(bt_ctf_field_type_string_get_encoding(NULL
) ==
1195 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
1196 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
1198 "bt_ctf_field_type_string_get_encoding returns the correct value");
1200 structure_seq_type
= bt_ctf_field_type_structure_create();
1201 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
1203 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
1204 ok(structure_seq_type
, "Create a structure type");
1205 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1206 uint_8_type
, "seq_len") == 0,
1207 "Add a uint8_t type to a structure");
1208 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1209 sequence_type
, "a_sequence") == 0,
1210 "Add a sequence type to a structure");
1212 ok(bt_ctf_field_type_structure_get_field_count(NULL
) < 0,
1213 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
1214 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
1215 "bt_ctf_field_type_structure_get_field_count returns a correct value");
1217 ok(bt_ctf_field_type_structure_get_field(NULL
,
1218 &ret_string
, &returned_type
, 1) < 0,
1219 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
1220 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1221 NULL
, &returned_type
, 1) < 0,
1222 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
1223 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1224 &ret_string
, NULL
, 1) < 0,
1225 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
1226 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1227 &ret_string
, &returned_type
, 10) < 0,
1228 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
1229 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1230 &ret_string
, &returned_type
, 1) == 0,
1231 "bt_ctf_field_type_structure_get_field returns a field");
1232 ok(!strcmp(ret_string
, "a_sequence"),
1233 "bt_ctf_field_type_structure_get_field returns a correct field name");
1234 ok(returned_type
== sequence_type
,
1235 "bt_ctf_field_type_structure_get_field returns a correct field type");
1236 bt_ctf_field_type_put(returned_type
);
1238 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL
, "a_sequence") == NULL
,
1239 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
1240 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type
, NULL
) == NULL
,
1241 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1242 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1243 structure_seq_type
, "a_sequence");
1244 ok(returned_type
== sequence_type
,
1245 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
1246 bt_ctf_field_type_put(returned_type
);
1248 composite_structure_type
= bt_ctf_field_type_structure_create();
1249 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1250 string_type
, "a_string") == 0,
1251 "Add a string type to a structure");
1252 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1253 structure_seq_type
, "inner_structure") == 0,
1254 "Add a structure type to a structure");
1256 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1257 NULL
, "a_sequence") == NULL
,
1258 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
1259 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1260 structure_seq_type
, NULL
) == NULL
,
1261 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1262 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1263 structure_seq_type
, "a_sequence");
1264 ok(returned_type
== sequence_type
,
1265 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1266 bt_ctf_field_type_put(returned_type
);
1268 int_16
= bt_ctf_field_create(int_16_type
);
1269 ok(int_16
, "Instanciate a signed 16-bit integer");
1270 uint_12
= bt_ctf_field_create(uint_12_type
);
1271 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1272 returned_type
= bt_ctf_field_get_type(int_16
);
1273 ok(returned_type
== int_16_type
,
1274 "bt_ctf_field_get_type returns the correct type");
1276 /* Can't modify types after instanciating them */
1277 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1278 BT_CTF_INTEGER_BASE_DECIMAL
),
1279 "Check an integer type' base can't be modified after instanciation");
1280 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1281 "Check an integer type's signedness can't be modified after instanciation");
1283 /* Check signed property is checked */
1284 ok(bt_ctf_field_signed_integer_set_value(uint_12
, -52),
1285 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
1286 ok(bt_ctf_field_unsigned_integer_set_value(int_16
, 42),
1287 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
1289 /* Check overflows are properly tested for */
1290 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32768) == 0,
1291 "Check -32768 is allowed for a signed 16-bit integer");
1292 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32767) == 0,
1293 "Check 32767 is allowed for a signed 16-bit integer");
1294 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32768),
1295 "Check 32768 is not allowed for a signed 16-bit integer");
1296 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32769),
1297 "Check -32769 is not allowed for a signed 16-bit integer");
1298 ok(bt_ctf_field_signed_integer_set_value(int_16
, -42) == 0,
1299 "Check -42 is allowed for a signed 16-bit integer");
1301 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4095) == 0,
1302 "Check 4095 is allowed for an unsigned 12-bit integer");
1303 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4096),
1304 "Check 4096 is not allowed for a unsigned 12-bit integer");
1305 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 0) == 0,
1306 "Check 0 is allowed for an unsigned 12-bit integer");
1308 string
= bt_ctf_field_create(string_type
);
1309 ok(string
, "Instanciate a string field");
1310 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1311 "Set a string's value");
1313 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1314 ok(enumeration_type
,
1315 "Create an enumeration type with an unsigned 12-bit integer as container");
1316 enumeration_sequence_type
= bt_ctf_field_type_sequence_create(
1317 enumeration_type
, "count");
1318 ok(!enumeration_sequence_type
,
1319 "Check enumeration types are validated when creating a sequence");
1320 enumeration_array_type
= bt_ctf_field_type_array_create(
1321 enumeration_type
, 10);
1322 ok(!enumeration_array_type
,
1323 "Check enumeration types are validated when creating an array");
1324 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1325 enumeration_type
, "enumeration"),
1326 "Check enumeration types are validated when adding them as structure members");
1327 enumeration
= bt_ctf_field_create(enumeration_type
);
1329 "Check enumeration types are validated before instantiation");
1331 bt_ctf_field_put(string
);
1332 bt_ctf_field_put(uint_12
);
1333 bt_ctf_field_put(int_16
);
1334 bt_ctf_field_put(enumeration
);
1335 bt_ctf_field_type_put(composite_structure_type
);
1336 bt_ctf_field_type_put(structure_seq_type
);
1337 bt_ctf_field_type_put(string_type
);
1338 bt_ctf_field_type_put(sequence_type
);
1339 bt_ctf_field_type_put(uint_8_type
);
1340 bt_ctf_field_type_put(int_16_type
);
1341 bt_ctf_field_type_put(uint_12_type
);
1342 bt_ctf_field_type_put(enumeration_type
);
1343 bt_ctf_field_type_put(enumeration_sequence_type
);
1344 bt_ctf_field_type_put(enumeration_array_type
);
1345 bt_ctf_field_type_put(returned_type
);
1348 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
1349 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
1352 * Append enough events to force the underlying packet to be resized.
1353 * Also tests that a new event can be declared after a stream has been
1354 * instantiated and used/flushed.
1358 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
1360 struct bt_ctf_field_type
*integer_type
=
1361 bt_ctf_field_type_integer_create(17);
1362 struct bt_ctf_field_type
*string_type
=
1363 bt_ctf_field_type_string_create();
1364 struct bt_ctf_event
*event
= NULL
;
1365 struct bt_ctf_field
*ret_field
= NULL
;
1366 struct bt_ctf_field_type
*ret_field_type
= NULL
;
1367 uint64_t ret_uint64
;
1368 int events_appended
= 0;
1369 struct bt_ctf_field
*packet_context
= NULL
,
1370 *packet_context_field
= NULL
, *event_context
= NULL
;
1372 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
1374 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
1376 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1377 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
1382 event
= bt_ctf_event_create(event_class
);
1383 ret_field
= bt_ctf_event_get_payload_by_index(event
, 0);
1384 ret_field_type
= bt_ctf_field_get_type(ret_field
);
1385 ok(ret_field_type
== integer_type
,
1386 "bt_ctf_event_get_payload_by_index returns a correct field");
1387 bt_ctf_field_type_put(ret_field_type
);
1388 bt_ctf_field_put(ret_field
);
1390 ok(bt_ctf_event_get_payload_by_index(NULL
, 0) == NULL
,
1391 "bt_ctf_event_get_payload_by_index handles NULL correctly");
1392 ok(bt_ctf_event_get_payload_by_index(event
, 4) == NULL
,
1393 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
1394 bt_ctf_event_put(event
);
1396 ok(bt_ctf_stream_get_event_context(NULL
) == NULL
,
1397 "bt_ctf_stream_get_event_context handles NULL correctly");
1398 event_context
= bt_ctf_stream_get_event_context(stream
);
1400 "bt_ctf_stream_get_event_context returns a stream event context");
1401 ok(bt_ctf_stream_set_event_context(NULL
, event_context
) < 0,
1402 "bt_ctf_stream_set_event_context handles a NULL stream correctly");
1403 ok(bt_ctf_stream_set_event_context(stream
, NULL
) < 0,
1404 "bt_ctf_stream_set_event_context handles a NULL stream event context correctly");
1405 ok(!bt_ctf_stream_set_event_context(stream
, event_context
),
1406 "bt_ctf_stream_set_event_context correctly set a stream event context");
1407 ret_field
= bt_ctf_field_create(integer_type
);
1408 ok(bt_ctf_stream_set_event_context(stream
, ret_field
) < 0,
1409 "bt_ctf_stream_set_event_context rejects an event context of incorrect type");
1410 bt_ctf_field_put(ret_field
);
1412 for (i
= 0; i
< PACKET_RESIZE_TEST_LENGTH
; i
++) {
1413 event
= bt_ctf_event_create(event_class
);
1414 struct bt_ctf_field
*integer
=
1415 bt_ctf_field_create(integer_type
);
1416 struct bt_ctf_field
*string
=
1417 bt_ctf_field_create(string_type
);
1419 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
1420 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
1421 ret
|= bt_ctf_event_set_payload(event
, "field_1",
1423 bt_ctf_field_put(integer
);
1424 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
1425 ret
|= bt_ctf_event_set_payload(event
, "a_string",
1427 bt_ctf_field_put(string
);
1429 /* Populate stream event context */
1430 integer
= bt_ctf_field_structure_get_field(event_context
,
1431 "common_event_context");
1432 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
,
1434 bt_ctf_field_put(integer
);
1436 ret
|= bt_ctf_stream_append_event(stream
, event
);
1437 bt_ctf_event_put(event
);
1444 events_appended
= !!(i
== PACKET_RESIZE_TEST_LENGTH
);
1445 ok(bt_ctf_stream_get_discarded_events_count(NULL
, &ret_uint64
) < 0,
1446 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
1447 ok(bt_ctf_stream_get_discarded_events_count(stream
, NULL
) < 0,
1448 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
1449 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1450 ok(ret
== 0 && ret_uint64
== 0,
1451 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1452 bt_ctf_stream_append_discarded_events(stream
, 1000);
1453 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1454 ok(ret
== 0 && ret_uint64
== 1000,
1455 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1458 ok(events_appended
, "Append 100 000 events to a stream");
1461 * Populate the custom packet context field with a dummy value
1462 * otherwise flush will fail.
1464 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1465 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1466 "custom_packet_context_field");
1467 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 2);
1469 ok(bt_ctf_stream_flush(stream
) == 0,
1470 "Flush a stream that forces a packet resize");
1471 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1472 ok(ret
== 0 && ret_uint64
== 1000,
1473 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1474 bt_ctf_field_type_put(integer_type
);
1475 bt_ctf_field_type_put(string_type
);
1476 bt_ctf_field_put(packet_context
);
1477 bt_ctf_field_put(packet_context_field
);
1478 bt_ctf_field_put(event_context
);
1479 bt_ctf_event_class_put(event_class
);
1482 int main(int argc
, char **argv
)
1484 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
1485 char metadata_path
[sizeof(trace_path
) + 9];
1486 const char *clock_name
= "test_clock";
1487 const char *clock_description
= "This is a test clock";
1488 const char *returned_clock_name
;
1489 const char *returned_clock_description
;
1490 const uint64_t frequency
= 1123456789;
1491 const uint64_t offset_s
= 1351530929945824323;
1492 const uint64_t offset
= 1234567;
1493 const uint64_t precision
= 10;
1494 const int is_absolute
= 0xFF;
1495 char *metadata_string
;
1496 struct bt_ctf_writer
*writer
;
1497 struct utsname name
;
1498 char hostname
[BABELTRACE_HOST_NAME_MAX
];
1499 struct bt_ctf_clock
*clock
, *ret_clock
;
1500 struct bt_ctf_stream_class
*stream_class
;
1501 struct bt_ctf_stream
*stream1
;
1502 const char *ret_string
;
1503 const unsigned char *ret_uuid
;
1504 unsigned char tmp_uuid
[16] = { 0 };
1505 struct bt_ctf_field_type
*packet_context_type
,
1506 *packet_context_field_type
,
1508 *stream_event_context_type
,
1510 struct bt_ctf_trace
*trace
;
1514 printf("Usage: tests-ctf-writer path_to_ctf_parser_test path_to_babeltrace\n");
1520 if (!mkdtemp(trace_path
)) {
1524 strcpy(metadata_path
, trace_path
);
1525 strcat(metadata_path
+ sizeof(trace_path
) - 1, "/metadata");
1527 writer
= bt_ctf_writer_create(trace_path
);
1528 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
1530 /* Add environment context to the trace */
1531 ret
= gethostname(hostname
, sizeof(hostname
));
1535 ok(bt_ctf_writer_add_environment_field(writer
, "host", hostname
) == 0,
1536 "Add host (%s) environment field to writer instance",
1538 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
1540 "bt_ctf_writer_add_environment_field error with NULL writer");
1541 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
1543 "bt_ctf_writer_add_environment_field error with NULL field name");
1544 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
1546 "bt_ctf_writer_add_environment_field error with NULL field value");
1553 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
1554 == 0, "Add sysname (%s) environment field to writer instance",
1556 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
1557 name
.nodename
) == 0,
1558 "Add nodename (%s) environment field to writer instance",
1560 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
1561 == 0, "Add release (%s) environment field to writer instance",
1563 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
1564 == 0, "Add version (%s) environment field to writer instance",
1566 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
1567 == 0, "Add machine (%s) environment field to writer istance",
1570 /* Define a clock and add it to the trace */
1571 ok(bt_ctf_clock_create("signed") == NULL
,
1572 "Illegal clock name rejected");
1573 ok(bt_ctf_clock_create(NULL
) == NULL
, "NULL clock name rejected");
1574 clock
= bt_ctf_clock_create(clock_name
);
1575 ok(clock
, "Clock created sucessfully");
1576 returned_clock_name
= bt_ctf_clock_get_name(clock
);
1577 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
1578 ok(returned_clock_name
? !strcmp(returned_clock_name
, clock_name
) : 0,
1579 "Returned clock name is valid");
1581 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1582 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
1583 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
1584 "Clock description set successfully");
1586 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1587 ok(returned_clock_description
,
1588 "bt_ctf_clock_get_description returns a description.");
1589 ok(returned_clock_description
?
1590 !strcmp(returned_clock_description
, clock_description
) : 0,
1591 "Returned clock description is valid");
1593 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
1594 "bt_ctf_clock_get_frequency returns the correct default frequency");
1595 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
1596 "Set clock frequency");
1597 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
1598 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
1600 ok(bt_ctf_clock_get_offset_s(clock
) == DEFAULT_CLOCK_OFFSET_S
,
1601 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
1602 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
1603 "Set clock offset (seconds)");
1604 ok(bt_ctf_clock_get_offset_s(clock
) == offset_s
,
1605 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
1607 ok(bt_ctf_clock_get_offset(clock
) == DEFAULT_CLOCK_OFFSET
,
1608 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks)");
1609 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
1610 ok(bt_ctf_clock_get_offset(clock
) == offset
,
1611 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks) once it is set");
1613 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
1614 "bt_ctf_clock_get_precision returns the correct default precision");
1615 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
1616 "Set clock precision");
1617 ok(bt_ctf_clock_get_precision(clock
) == precision
,
1618 "bt_ctf_clock_get_precision returns the correct precision once it is set");
1620 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
1621 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
1622 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
1623 "Set clock absolute property");
1624 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
1625 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
1627 ok(bt_ctf_clock_get_time(clock
) == DEFAULT_CLOCK_TIME
,
1628 "bt_ctf_clock_get_time returns the correct default time");
1629 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
1631 ok(bt_ctf_clock_get_time(clock
) == current_time
,
1632 "bt_ctf_clock_get_time returns the correct time once it is set");
1634 ok(bt_ctf_writer_add_clock(writer
, clock
) == 0,
1635 "Add clock to writer instance");
1636 ok(bt_ctf_writer_add_clock(writer
, clock
),
1637 "Verify a clock can't be added twice to a writer instance");
1639 ok(!bt_ctf_writer_get_trace(NULL
),
1640 "bt_ctf_writer_get_trace correctly handles NULL");
1641 trace
= bt_ctf_writer_get_trace(writer
);
1643 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1644 ok(bt_ctf_trace_get_clock_count(NULL
) < 0,
1645 "bt_ctf_trace_get_clock_count correctly handles NULL");
1646 ok(bt_ctf_trace_get_clock_count(trace
) == 1,
1647 "bt_ctf_trace_get_clock_count returns the correct number of clocks");
1648 ok(!bt_ctf_trace_get_clock(NULL
, 0),
1649 "bt_ctf_trace_get_clock correctly handles NULL");
1650 ok(!bt_ctf_trace_get_clock(trace
, -1),
1651 "bt_ctf_trace_get_clock correctly handles negative indexes");
1652 ok(!bt_ctf_trace_get_clock(trace
, 1),
1653 "bt_ctf_trace_get_clock correctly handles out of bound accesses");
1654 ret_clock
= bt_ctf_trace_get_clock(trace
, 0);
1655 ok(ret_clock
== clock
,
1656 "bt_ctf_trace_get_clock returns the right clock instance");
1657 bt_ctf_clock_put(ret_clock
);
1659 ok(!bt_ctf_clock_get_name(NULL
),
1660 "bt_ctf_clock_get_name correctly handles NULL");
1661 ok(!bt_ctf_clock_get_description(NULL
),
1662 "bt_ctf_clock_get_description correctly handles NULL");
1663 ok(bt_ctf_clock_get_frequency(NULL
) == -1ULL,
1664 "bt_ctf_clock_get_frequency correctly handles NULL");
1665 ok(bt_ctf_clock_get_precision(NULL
) == -1ULL,
1666 "bt_ctf_clock_get_precision correctly handles NULL");
1667 ok(bt_ctf_clock_get_offset_s(NULL
) == -1ULL,
1668 "bt_ctf_clock_get_offset_s correctly handles NULL");
1669 ok(bt_ctf_clock_get_offset(NULL
) == -1ULL,
1670 "bt_ctf_clock_get_offset correctly handles NULL");
1671 ok(bt_ctf_clock_get_is_absolute(NULL
) < 0,
1672 "bt_ctf_clock_get_is_absolute correctly handles NULL");
1673 ok(bt_ctf_clock_get_time(NULL
) == -1ULL,
1674 "bt_ctf_clock_get_time correctly handles NULL");
1676 ok(bt_ctf_clock_set_description(NULL
, NULL
) < 0,
1677 "bt_ctf_clock_set_description correctly handles NULL clock");
1678 ok(bt_ctf_clock_set_frequency(NULL
, frequency
) < 0,
1679 "bt_ctf_clock_set_frequency correctly handles NULL clock");
1680 ok(bt_ctf_clock_set_precision(NULL
, precision
) < 0,
1681 "bt_ctf_clock_get_precision correctly handles NULL clock");
1682 ok(bt_ctf_clock_set_offset_s(NULL
, offset_s
) < 0,
1683 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
1684 ok(bt_ctf_clock_set_offset(NULL
, offset
) < 0,
1685 "bt_ctf_clock_set_offset correctly handles NULL clock");
1686 ok(bt_ctf_clock_set_is_absolute(NULL
, is_absolute
) < 0,
1687 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
1688 ok(bt_ctf_clock_set_time(NULL
, current_time
) < 0,
1689 "bt_ctf_clock_set_time correctly handles NULL clock");
1690 ok(bt_ctf_clock_get_uuid(NULL
) == NULL
,
1691 "bt_ctf_clock_get_uuid correctly handles NULL clock");
1692 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1694 "bt_ctf_clock_get_uuid returns a UUID");
1696 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
1697 /* Slightly modify UUID */
1698 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
1701 ok(bt_ctf_clock_set_uuid(NULL
, tmp_uuid
) < 0,
1702 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
1703 ok(bt_ctf_clock_set_uuid(clock
, NULL
) < 0,
1704 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
1705 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
1706 "bt_ctf_clock_set_uuid sets a new uuid succesfully");
1707 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1709 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
1710 ok(uuid_match(ret_uuid
, tmp_uuid
),
1711 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
1713 /* Define a stream class */
1714 stream_class
= bt_ctf_stream_class_create("test_stream");
1716 ok(bt_ctf_stream_class_get_name(NULL
) == NULL
,
1717 "bt_ctf_stream_class_get_name handles NULL correctly");
1718 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
1719 ok(!strcmp(ret_string
, "test_stream"),
1720 "bt_ctf_stream_class_get_name returns a correct stream class name");
1722 ok(bt_ctf_stream_class_get_clock(stream_class
) == NULL
,
1723 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
1724 ok(bt_ctf_stream_class_get_clock(NULL
) == NULL
,
1725 "bt_ctf_stream_class_get_clock handles NULL correctly");
1727 ok(stream_class
, "Create stream class");
1728 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
1729 "Set a stream class' clock");
1730 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
1731 ok(ret_clock
== clock
,
1732 "bt_ctf_stream_class_get_clock returns a correct clock");
1733 bt_ctf_clock_put(ret_clock
);
1735 /* Test the event fields and event types APIs */
1738 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
1739 "bt_ctf_stream_class_get_id returns an error when no id is set");
1740 ok(bt_ctf_stream_class_get_id(NULL
) < 0,
1741 "bt_ctf_stream_class_get_id handles NULL correctly");
1742 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
1743 "bt_ctf_stream_class_set_id handles NULL correctly");
1744 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
1745 "Set an stream class' id");
1746 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
1747 "bt_ctf_stream_class_get_id returns the correct value");
1749 /* Create a "uint5_t" equivalent custom packet context field */
1750 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
1752 ok(bt_ctf_stream_class_get_packet_context_type(NULL
) == NULL
,
1753 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
1755 /* Add a custom field to the stream class' packet context */
1756 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
1757 ok(packet_context_type
,
1758 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
1759 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == CTF_TYPE_STRUCT
,
1760 "Packet context is a structure");
1762 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
1763 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
1764 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
),
1765 "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly");
1767 integer_type
= bt_ctf_field_type_integer_create(32);
1768 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
1770 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
1771 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1772 packet_context_field_type
, "custom_packet_context_field");
1773 ok(ret
== 0, "Packet context field added successfully");
1775 /* Define a stream event context containing a my_integer field. */
1776 ok(bt_ctf_stream_class_get_event_context_type(NULL
) == NULL
,
1777 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
1778 ok(bt_ctf_stream_class_get_event_context_type(
1779 stream_class
) == NULL
,
1780 "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set.");
1781 stream_event_context_type
= bt_ctf_field_type_structure_create();
1782 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1783 integer_type
, "common_event_context");
1785 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
1786 stream_event_context_type
) < 0,
1787 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
1788 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
1790 "bt_ctf_stream_class_set_event_context_type handles a NULL event_context correctly");
1791 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
1793 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
1795 ok(bt_ctf_stream_class_set_event_context_type(
1796 stream_class
, stream_event_context_type
) == 0,
1797 "Set a new stream event context type");
1798 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
1800 ok(ret_field_type
== stream_event_context_type
,
1801 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
1803 /* Instantiate a stream and append events */
1804 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
1805 ok(stream1
, "Instanciate a stream class from writer");
1808 * Try to modify the packet context type after a stream has been
1811 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1812 packet_context_field_type
, "should_fail");
1814 "Packet context type can't be modified once a stream class has been instanciated");
1817 * Try to modify the stream event context type after a stream has been
1820 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1821 integer_type
, "should_fail");
1823 "Stream event context type can't be modified once a stream class has been instanciated");
1825 /* Should fail after instanciating a stream (frozen) */
1826 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
1827 "Changes to a stream class that was already instantiated fail");
1829 append_simple_event(stream_class
, stream1
, clock
);
1831 packet_resize_test(stream_class
, stream1
, clock
);
1833 append_complex_event(stream_class
, stream1
, clock
);
1835 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
1836 ok(metadata_string
, "Get metadata string");
1838 bt_ctf_writer_flush_metadata(writer
);
1839 validate_metadata(argv
[1], metadata_path
);
1840 validate_trace(argv
[2], trace_path
);
1842 bt_ctf_clock_put(clock
);
1843 bt_ctf_stream_class_put(stream_class
);
1844 bt_ctf_writer_put(writer
);
1845 bt_ctf_stream_put(stream1
);
1846 bt_ctf_field_type_put(packet_context_type
);
1847 bt_ctf_field_type_put(packet_context_field_type
);
1848 bt_ctf_field_type_put(integer_type
);
1849 bt_ctf_field_type_put(stream_event_context_type
);
1850 bt_ctf_field_type_put(ret_field_type
);
1851 bt_ctf_trace_put(trace
);
1852 free(metadata_string
);
1854 /* Remove all trace files and delete temporary trace directory */
1855 DIR *trace_dir
= opendir(trace_path
);
1857 perror("# opendir");
1861 struct dirent
*entry
;
1862 while ((entry
= readdir(trace_dir
))) {
1863 if (entry
->d_type
== DT_REG
) {
1864 unlinkat(dirfd(trace_dir
), entry
->d_name
, 0);
1869 closedir(trace_dir
);