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 ok(!bt_ctf_field_type_structure_add_field(event_context_type
, uint_12_type
,
485 "event_specific_context"),
486 "Add event specific context field");
487 ok(bt_ctf_event_class_get_context_type(NULL
) == NULL
,
488 "bt_ctf_event_class_get_context_type handles NULL correctly");
489 ok(bt_ctf_event_class_get_context_type(simple_event_class
) == NULL
,
490 "bt_ctf_event_class_get_context_type returns NULL when no event context type is set");
491 ok(bt_ctf_event_class_set_context_type(simple_event_class
, NULL
) < 0,
492 "bt_ctf_event_class_set_context_type handles a NULL context type correctly");
493 ok(bt_ctf_event_class_set_context_type(NULL
, event_context_type
) < 0,
494 "bt_ctf_event_class_set_context_type handles a NULL event class correctly");
495 ok(!bt_ctf_event_class_set_context_type(simple_event_class
, event_context_type
),
496 "Set an event class' context type successfully");
497 returned_type
= bt_ctf_event_class_get_context_type(simple_event_class
);
498 ok(returned_type
== event_context_type
,
499 "bt_ctf_event_class_get_context_type returns the appropriate type");
500 bt_ctf_field_type_put(returned_type
);
502 simple_event
= bt_ctf_event_create(simple_event_class
);
504 "Instantiate an event containing a single integer field");
506 ok(bt_ctf_event_get_clock(NULL
) == NULL
,
507 "bt_ctf_event_get_clock handles NULL correctly");
508 ret_clock
= bt_ctf_event_get_clock(simple_event
);
509 ok(ret_clock
== clock
,
510 "bt_ctf_event_get_clock returns a correct clock");
511 bt_ctf_clock_put(clock
);
513 integer_field
= bt_ctf_field_create(uint_12_type
);
514 bt_ctf_field_unsigned_integer_set_value(integer_field
, 42);
515 ok(bt_ctf_event_set_payload(simple_event
, "integer_field",
516 integer_field
) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
518 float_field
= bt_ctf_event_get_payload(simple_event
, "float_field");
519 ok(bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
520 "bt_ctf_field_floating_point_get_value fails on an unset float field");
521 bt_ctf_field_floating_point_set_value(float_field
, double_test_value
);
522 ok(bt_ctf_field_floating_point_get_value(NULL
, &ret_double
),
523 "bt_ctf_field_floating_point_get_value properly handles a NULL field");
524 ok(bt_ctf_field_floating_point_get_value(float_field
, NULL
),
525 "bt_ctf_field_floating_point_get_value properly handles a NULL return value pointer");
526 ok(!bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
527 "bt_ctf_field_floating_point_get_value returns a double value");
528 ok(fabs(ret_double
- double_test_value
) <= DBL_EPSILON
,
529 "bt_ctf_field_floating_point_get_value returns a correct value");
531 enum_field
= bt_ctf_field_create(enum_type
);
532 ret_char
= bt_ctf_field_enumeration_get_mapping_name(NULL
);
533 ok(!ret_char
, "bt_ctf_field_enumeration_get_mapping_name handles NULL correctly");
534 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field
);
535 ok(!ret_char
, "bt_ctf_field_enumeration_get_mapping_name returns NULL if the enumeration's container field is unset");
536 enum_container_field
= bt_ctf_field_enumeration_get_container(
538 ok(bt_ctf_field_signed_integer_set_value(
539 enum_container_field
, -42) == 0,
540 "Set signed enumeration container value");
541 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field
);
542 ok(!strcmp(ret_char
, mapping_name_negative_test
),
543 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an signed container");
544 bt_ctf_event_set_payload(simple_event
, "enum_field", enum_field
);
546 enum_field_unsigned
= bt_ctf_field_create(enum_type_unsigned
);
547 enum_container_field_unsigned
= bt_ctf_field_enumeration_get_container(
548 enum_field_unsigned
);
549 ok(bt_ctf_field_unsigned_integer_set_value(
550 enum_container_field_unsigned
, 42) == 0,
551 "Set unsigned enumeration container value");
552 bt_ctf_event_set_payload(simple_event
, "enum_field_unsigned",
553 enum_field_unsigned
);
554 ret_char
= bt_ctf_field_enumeration_get_mapping_name(enum_field_unsigned
);
555 ok(!strcmp(ret_char
, mapping_name_test
),
556 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an unsigned container");
558 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0, "Set clock time");
560 /* Populate stream event context */
561 stream_event_context
= bt_ctf_stream_get_event_context(stream
);
562 stream_event_context_field
= bt_ctf_field_structure_get_field(
563 stream_event_context
, "common_event_context");
564 bt_ctf_field_unsigned_integer_set_value(stream_event_context_field
, 42);
566 /* Populate the event's context */
567 ok(bt_ctf_event_get_event_context(NULL
) == NULL
,
568 "bt_ctf_event_get_event_context handles NULL correctly");
569 event_context
= bt_ctf_event_get_event_context(simple_event
);
571 "bt_ctf_event_get_event_context returns a field");
572 returned_type
= bt_ctf_field_get_type(event_context
);
573 ok(returned_type
== event_context_type
,
574 "bt_ctf_event_get_event_context returns a field of the appropriate type");
575 event_context_field
= bt_ctf_field_structure_get_field(event_context
,
576 "event_specific_context");
577 ok(!bt_ctf_field_unsigned_integer_set_value(event_context_field
, 1234),
578 "Successfully set an event context's value");
579 ok(bt_ctf_event_set_event_context(NULL
, event_context
) < 0,
580 "bt_ctf_event_set_event_context handles a NULL event correctly");
581 ok(bt_ctf_event_set_event_context(simple_event
, NULL
) < 0,
582 "bt_ctf_event_set_event_context handles a NULL event context correctly");
583 ok(bt_ctf_event_set_event_context(simple_event
, event_context_field
) < 0,
584 "bt_ctf_event_set_event_context rejects a context of the wrong type");
585 ok(!bt_ctf_event_set_event_context(simple_event
, event_context
),
586 "Set an event context successfully");
588 ok(bt_ctf_stream_append_event(stream
, simple_event
) == 0,
589 "Append simple event to trace stream");
591 ok(bt_ctf_stream_get_packet_context(NULL
) == NULL
,
592 "bt_ctf_stream_get_packet_context handles NULL correctly");
593 packet_context
= bt_ctf_stream_get_packet_context(stream
);
595 "bt_ctf_stream_get_packet_context returns a packet context");
597 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
599 ok(packet_context_field
,
600 "Packet context contains the default packet_size field.");
601 bt_ctf_field_put(packet_context_field
);
602 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
603 "custom_packet_context_field");
604 ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 8) == 0,
605 "Custom packet context field value successfully set.");
607 ok(bt_ctf_stream_set_packet_context(NULL
, packet_context_field
) < 0,
608 "bt_ctf_stream_set_packet_context handles a NULL stream correctly");
609 ok(bt_ctf_stream_set_packet_context(stream
, NULL
) < 0,
610 "bt_ctf_stream_set_packet_context handles a NULL packet context correctly");
611 ok(bt_ctf_stream_set_packet_context(stream
, packet_context
) == 0,
612 "Successfully set a stream's packet context");
614 ok(bt_ctf_stream_flush(stream
) == 0,
615 "Flush trace stream with one event");
617 bt_ctf_event_class_put(simple_event_class
);
618 bt_ctf_event_put(simple_event
);
619 bt_ctf_field_type_put(uint_12_type
);
620 bt_ctf_field_type_put(int_64_type
);
621 bt_ctf_field_type_put(float_type
);
622 bt_ctf_field_type_put(enum_type
);
623 bt_ctf_field_type_put(enum_type_unsigned
);
624 bt_ctf_field_type_put(returned_type
);
625 bt_ctf_field_type_put(event_context_type
);
626 bt_ctf_field_put(integer_field
);
627 bt_ctf_field_put(float_field
);
628 bt_ctf_field_put(enum_field
);
629 bt_ctf_field_put(enum_field_unsigned
);
630 bt_ctf_field_put(enum_container_field
);
631 bt_ctf_field_put(enum_container_field_unsigned
);
632 bt_ctf_field_put(packet_context
);
633 bt_ctf_field_put(packet_context_field
);
634 bt_ctf_field_put(stream_event_context
);
635 bt_ctf_field_put(stream_event_context_field
);
636 bt_ctf_field_put(event_context
);
637 bt_ctf_field_put(event_context_field
);
640 void append_complex_event(struct bt_ctf_stream_class
*stream_class
,
641 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
644 const char *complex_test_event_string
= "Complex Test Event";
645 const char *test_string
= "Test string";
646 struct bt_ctf_field_type
*uint_35_type
=
647 bt_ctf_field_type_integer_create(35);
648 struct bt_ctf_field_type
*int_16_type
=
649 bt_ctf_field_type_integer_create(16);
650 struct bt_ctf_field_type
*uint_3_type
=
651 bt_ctf_field_type_integer_create(3);
652 struct bt_ctf_field_type
*enum_variant_type
=
653 bt_ctf_field_type_enumeration_create(uint_3_type
);
654 struct bt_ctf_field_type
*variant_type
=
655 bt_ctf_field_type_variant_create(enum_variant_type
,
657 struct bt_ctf_field_type
*string_type
=
658 bt_ctf_field_type_string_create();
659 struct bt_ctf_field_type
*sequence_type
;
660 struct bt_ctf_field_type
*array_type
;
661 struct bt_ctf_field_type
*inner_structure_type
=
662 bt_ctf_field_type_structure_create();
663 struct bt_ctf_field_type
*complex_structure_type
=
664 bt_ctf_field_type_structure_create();
665 struct bt_ctf_field_type
*ret_field_type
;
666 struct bt_ctf_event_class
*event_class
;
667 struct bt_ctf_event
*event
;
668 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
669 *inner_structure_field
, *complex_structure_field
,
670 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
671 *variant_field
, *an_array_field
, *ret_field
;
672 uint64_t ret_unsigned_int
;
673 int64_t ret_signed_int
;
674 const char *ret_string
;
675 struct bt_ctf_stream_class
*ret_stream_class
;
676 struct bt_ctf_event_class
*ret_event_class
;
677 struct bt_ctf_field
*packet_context
, *packet_context_field
;
679 bt_ctf_field_type_set_alignment(int_16_type
, 32);
680 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
681 bt_ctf_field_type_integer_set_base(uint_35_type
,
682 BT_CTF_INTEGER_BASE_HEXADECIMAL
);
684 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
685 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
688 ok(bt_ctf_field_type_array_get_element_type(NULL
) == NULL
,
689 "bt_ctf_field_type_array_get_element_type handles NULL correctly");
690 ret_field_type
= bt_ctf_field_type_array_get_element_type(
692 ok(ret_field_type
== int_16_type
,
693 "bt_ctf_field_type_array_get_element_type returns the correct type");
694 bt_ctf_field_type_put(ret_field_type
);
696 ok(bt_ctf_field_type_array_get_length(NULL
) < 0,
697 "bt_ctf_field_type_array_get_length handles NULL correctly");
698 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
699 "bt_ctf_field_type_array_get_length returns the correct length");
701 bt_ctf_field_type_structure_add_field(inner_structure_type
,
702 uint_35_type
, "seq_len");
703 bt_ctf_field_type_structure_add_field(inner_structure_type
,
704 sequence_type
, "a_sequence");
705 bt_ctf_field_type_structure_add_field(inner_structure_type
,
706 array_type
, "an_array");
708 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
710 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
712 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
713 "UINT35_TYPE", 2, 7);
715 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL
,
717 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly");
718 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
719 enum_variant_type
, NULL
) < 0,
720 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly");
721 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
722 enum_variant_type
, "INT16_TYPE") == 1,
723 "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index");
725 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL
, 1) < 0,
726 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly");
727 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, -42) < 0,
728 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly");
729 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type
, 5) == 2,
730 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index");
732 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
733 "An unknown entry"), "Reject a variant field based on an unknown tag value");
734 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
735 "UINT3_TYPE") == 0, "Add a field to a variant");
736 bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
738 bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
741 ok(bt_ctf_field_type_variant_get_tag_type(NULL
) == NULL
,
742 "bt_ctf_field_type_variant_get_tag_type handles NULL correctly");
743 ret_field_type
= bt_ctf_field_type_variant_get_tag_type(variant_type
);
744 ok(ret_field_type
== enum_variant_type
,
745 "bt_ctf_field_type_variant_get_tag_type returns a correct tag type");
746 bt_ctf_field_type_put(ret_field_type
);
748 ok(bt_ctf_field_type_variant_get_tag_name(NULL
) == NULL
,
749 "bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
750 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
751 ok(!strcmp(ret_string
, "variant_selector"),
752 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
753 ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL
,
754 "INT16_TYPE") == NULL
,
755 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
756 ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type
,
758 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
759 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
760 variant_type
, "INT16_TYPE");
761 ok(ret_field_type
== int_16_type
,
762 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
763 bt_ctf_field_type_put(ret_field_type
);
765 ok(bt_ctf_field_type_variant_get_field_count(NULL
) < 0,
766 "bt_ctf_field_type_variant_get_field_count handles NULL correctly");
767 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
768 "bt_ctf_field_type_variant_get_field_count returns the correct count");
770 ok(bt_ctf_field_type_variant_get_field(NULL
, &ret_string
, &ret_field_type
, 0) < 0,
771 "bt_ctf_field_type_variant_get_field handles a NULL type correctly");
772 ok(bt_ctf_field_type_variant_get_field(variant_type
, NULL
, &ret_field_type
, 0) < 0,
773 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
774 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, NULL
, 0) < 0,
775 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
776 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 200) < 0,
777 "bt_ctf_field_type_variant_get_field handles an invalid index correctly");
778 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
779 "bt_ctf_field_type_variant_get_field returns a field");
780 ok(!strcmp("INT16_TYPE", ret_string
),
781 "bt_ctf_field_type_variant_get_field returns a correct field name");
782 ok(ret_field_type
== int_16_type
,
783 "bt_ctf_field_type_variant_get_field returns a correct field type");
784 bt_ctf_field_type_put(ret_field_type
);
786 bt_ctf_field_type_structure_add_field(complex_structure_type
,
787 enum_variant_type
, "variant_selector");
788 bt_ctf_field_type_structure_add_field(complex_structure_type
,
789 string_type
, "a_string");
790 bt_ctf_field_type_structure_add_field(complex_structure_type
,
791 variant_type
, "variant_value");
792 bt_ctf_field_type_structure_add_field(complex_structure_type
,
793 inner_structure_type
, "inner_structure");
795 ok(bt_ctf_event_class_create("clock") == NULL
,
796 "Reject creation of an event class with an illegal name");
797 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
798 ok(event_class
, "Create an event class");
799 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
800 "Reject addition of a field with an empty name to an event");
801 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
802 "Reject addition of a field with a NULL type to an event");
803 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
805 "Reject addition of a type with an illegal name to an event");
806 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
808 "Add field of type unsigned integer to an event");
809 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
810 "int_16") == 0, "Add field of type signed integer to an event");
811 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
812 "complex_structure") == 0,
813 "Add composite structure to an event");
815 ok(bt_ctf_event_class_get_name(NULL
) == NULL
,
816 "bt_ctf_event_class_get_name handles NULL correctly");
817 ret_string
= bt_ctf_event_class_get_name(event_class
);
818 ok(!strcmp(ret_string
, complex_test_event_string
),
819 "bt_ctf_event_class_get_name returns a correct name");
820 ok(bt_ctf_event_class_get_id(event_class
) < 0,
821 "bt_ctf_event_class_get_id returns a negative value when not set");
822 ok(bt_ctf_event_class_get_id(NULL
) < 0,
823 "bt_ctf_event_class_get_id handles NULL correctly");
824 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
825 "bt_ctf_event_class_set_id handles NULL correctly");
826 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
827 "Set an event class' id");
828 ok(bt_ctf_event_class_get_id(event_class
) == 42,
829 "bt_ctf_event_class_get_id returns the correct value");
831 /* Add event class to the stream class */
832 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
833 "Reject addition of NULL event class to a stream class");
834 ok(bt_ctf_stream_class_add_event_class(stream_class
,
835 event_class
) == 0, "Add an event class to stream class");
837 ok(bt_ctf_event_class_get_stream_class(NULL
) == NULL
,
838 "bt_ctf_event_class_get_stream_class handles NULL correctly");
839 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
840 ok(ret_stream_class
== stream_class
,
841 "bt_ctf_event_class_get_stream_class returns the correct stream class");
842 bt_ctf_stream_class_put(ret_stream_class
);
844 ok(bt_ctf_event_class_get_field_count(NULL
) < 0,
845 "bt_ctf_event_class_get_field_count handles NULL correctly");
846 ok(bt_ctf_event_class_get_field_count(event_class
) == 3,
847 "bt_ctf_event_class_get_field_count returns a correct value");
849 ok(bt_ctf_event_class_get_field(NULL
, &ret_string
,
850 &ret_field_type
, 0) < 0,
851 "bt_ctf_event_class_get_field handles a NULL event class correctly");
852 ok(bt_ctf_event_class_get_field(event_class
, NULL
,
853 &ret_field_type
, 0) < 0,
854 "bt_ctf_event_class_get_field handles a NULL field name correctly");
855 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
857 "bt_ctf_event_class_get_field handles a NULL field type correctly");
858 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
859 &ret_field_type
, 42) < 0,
860 "bt_ctf_event_class_get_field handles an invalid index correctly");
861 ok(bt_ctf_event_class_get_field(event_class
, &ret_string
,
862 &ret_field_type
, 0) == 0,
863 "bt_ctf_event_class_get_field returns a field");
864 ok(ret_field_type
== uint_35_type
,
865 "bt_ctf_event_class_get_field returns a correct field type");
866 bt_ctf_field_type_put(ret_field_type
);
867 ok(!strcmp(ret_string
, "uint_35"),
868 "bt_ctf_event_class_get_field returns a correct field name");
869 ok(bt_ctf_event_class_get_field_by_name(NULL
, "") == NULL
,
870 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
871 ok(bt_ctf_event_class_get_field_by_name(event_class
, NULL
) == NULL
,
872 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
873 ok(bt_ctf_event_class_get_field_by_name(event_class
, "truie") == NULL
,
874 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
875 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
876 "complex_structure");
877 ok(ret_field_type
== complex_structure_type
,
878 "bt_ctf_event_class_get_field_by_name returns a correct field type");
879 bt_ctf_field_type_put(ret_field_type
);
881 event
= bt_ctf_event_create(event_class
);
882 ok(event
, "Instanciate a complex event");
884 ok(bt_ctf_event_get_class(NULL
) == NULL
,
885 "bt_ctf_event_get_class handles NULL correctly");
886 ret_event_class
= bt_ctf_event_get_class(event
);
887 ok(ret_event_class
== event_class
,
888 "bt_ctf_event_get_class returns the correct event class");
889 bt_ctf_event_class_put(ret_event_class
);
891 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
892 if (!uint_35_field
) {
893 printf("uint_35_field is NULL\n");
896 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
897 bt_ctf_field_unsigned_integer_set_value(uint_35_field
, 0x0DDF00D);
898 ok(bt_ctf_field_unsigned_integer_get_value(NULL
, &ret_unsigned_int
) < 0,
899 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
900 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
, NULL
) < 0,
901 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
902 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
,
903 &ret_unsigned_int
) == 0,
904 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
905 ok(ret_unsigned_int
== 0x0DDF00D,
906 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
907 ok(bt_ctf_field_signed_integer_get_value(uint_35_field
,
908 &ret_signed_int
) < 0,
909 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
910 bt_ctf_field_put(uint_35_field
);
912 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
913 bt_ctf_field_signed_integer_set_value(int_16_field
, -12345);
914 ok(bt_ctf_field_signed_integer_get_value(NULL
, &ret_signed_int
) < 0,
915 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
916 ok(bt_ctf_field_signed_integer_get_value(int_16_field
, NULL
) < 0,
917 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
918 ok(bt_ctf_field_signed_integer_get_value(int_16_field
,
919 &ret_signed_int
) == 0,
920 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
921 ok(ret_signed_int
== -12345,
922 "bt_ctf_field_signed_integer_get_value returns the correct value");
923 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field
,
924 &ret_unsigned_int
) < 0,
925 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
926 bt_ctf_field_put(int_16_field
);
928 complex_structure_field
= bt_ctf_event_get_payload(event
,
929 "complex_structure");
931 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 0) == NULL
,
932 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
933 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 9) == NULL
,
934 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
935 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
936 complex_structure_field
, 3);
937 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
938 bt_ctf_field_put(inner_structure_field
);
939 ok(ret_field_type
== inner_structure_type
,
940 "bt_ctf_field_structure_get_field_by_index returns a correct field");
941 bt_ctf_field_type_put(ret_field_type
);
943 inner_structure_field
= bt_ctf_field_structure_get_field(
944 complex_structure_field
, "inner_structure");
945 a_string_field
= bt_ctf_field_structure_get_field(
946 complex_structure_field
, "a_string");
947 enum_variant_field
= bt_ctf_field_structure_get_field(
948 complex_structure_field
, "variant_selector");
949 variant_field
= bt_ctf_field_structure_get_field(
950 complex_structure_field
, "variant_value");
951 uint_35_field
= bt_ctf_field_structure_get_field(
952 inner_structure_field
, "seq_len");
953 a_sequence_field
= bt_ctf_field_structure_get_field(
954 inner_structure_field
, "a_sequence");
955 an_array_field
= bt_ctf_field_structure_get_field(
956 inner_structure_field
, "an_array");
958 enum_container_field
= bt_ctf_field_enumeration_get_container(
960 bt_ctf_field_unsigned_integer_set_value(enum_container_field
, 1);
961 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
963 bt_ctf_field_signed_integer_set_value(int_16_field
, -200);
964 bt_ctf_field_put(int_16_field
);
965 ok(!bt_ctf_field_string_get_value(a_string_field
),
966 "bt_ctf_field_string_get_value returns NULL on an unset field");
967 bt_ctf_field_string_set_value(a_string_field
,
969 ok(!bt_ctf_field_string_get_value(NULL
),
970 "bt_ctf_field_string_get_value correctly handles NULL");
971 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
972 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
973 ok(ret_string
? !strcmp(ret_string
, test_string
) : 0,
974 "bt_ctf_field_string_get_value returns a correct value");
975 bt_ctf_field_unsigned_integer_set_value(uint_35_field
,
976 SEQUENCE_TEST_LENGTH
);
978 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL
,
979 enum_container_field
) == NULL
,
980 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
981 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type
,
983 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
984 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
985 variant_type
, enum_variant_field
);
986 ok(ret_field_type
== int_16_type
,
987 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
989 ok(bt_ctf_field_sequence_get_length(a_sequence_field
) == NULL
,
990 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
991 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
992 uint_35_field
) == 0, "Set a sequence field's length");
993 ret_field
= bt_ctf_field_sequence_get_length(a_sequence_field
);
994 ok(ret_field
== uint_35_field
,
995 "bt_ctf_field_sequence_get_length returns the correct length field");
996 ok(bt_ctf_field_sequence_get_length(NULL
) == NULL
,
997 "bt_ctf_field_sequence_get_length properly handles NULL");
999 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
1000 int_16_field
= bt_ctf_field_sequence_get_field(
1001 a_sequence_field
, i
);
1002 bt_ctf_field_signed_integer_set_value(int_16_field
, 4 - i
);
1003 bt_ctf_field_put(int_16_field
);
1006 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
1007 int_16_field
= bt_ctf_field_array_get_field(
1009 bt_ctf_field_signed_integer_set_value(int_16_field
, i
);
1010 bt_ctf_field_put(int_16_field
);
1013 bt_ctf_clock_set_time(clock
, ++current_time
);
1014 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
1015 "Append a complex event to a stream");
1018 * Populate the custom packet context field with a dummy value
1019 * otherwise flush will fail.
1021 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1022 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1023 "custom_packet_context_field");
1024 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 1);
1026 ok(bt_ctf_stream_flush(stream
) == 0,
1027 "Flush a stream containing a complex event");
1029 bt_ctf_field_put(uint_35_field
);
1030 bt_ctf_field_put(a_string_field
);
1031 bt_ctf_field_put(inner_structure_field
);
1032 bt_ctf_field_put(complex_structure_field
);
1033 bt_ctf_field_put(a_sequence_field
);
1034 bt_ctf_field_put(an_array_field
);
1035 bt_ctf_field_put(enum_variant_field
);
1036 bt_ctf_field_put(enum_container_field
);
1037 bt_ctf_field_put(variant_field
);
1038 bt_ctf_field_put(ret_field
);
1039 bt_ctf_field_put(packet_context_field
);
1040 bt_ctf_field_put(packet_context
);
1041 bt_ctf_field_type_put(uint_35_type
);
1042 bt_ctf_field_type_put(int_16_type
);
1043 bt_ctf_field_type_put(string_type
);
1044 bt_ctf_field_type_put(sequence_type
);
1045 bt_ctf_field_type_put(array_type
);
1046 bt_ctf_field_type_put(inner_structure_type
);
1047 bt_ctf_field_type_put(complex_structure_type
);
1048 bt_ctf_field_type_put(uint_3_type
);
1049 bt_ctf_field_type_put(enum_variant_type
);
1050 bt_ctf_field_type_put(variant_type
);
1051 bt_ctf_field_type_put(ret_field_type
);
1052 bt_ctf_event_class_put(event_class
);
1053 bt_ctf_event_put(event
);
1056 void type_field_tests()
1058 struct bt_ctf_field
*uint_12
;
1059 struct bt_ctf_field
*int_16
;
1060 struct bt_ctf_field
*string
;
1061 struct bt_ctf_field
*enumeration
;
1062 struct bt_ctf_field_type
*composite_structure_type
;
1063 struct bt_ctf_field_type
*structure_seq_type
;
1064 struct bt_ctf_field_type
*string_type
;
1065 struct bt_ctf_field_type
*sequence_type
;
1066 struct bt_ctf_field_type
*uint_8_type
;
1067 struct bt_ctf_field_type
*int_16_type
;
1068 struct bt_ctf_field_type
*uint_12_type
=
1069 bt_ctf_field_type_integer_create(12);
1070 struct bt_ctf_field_type
*enumeration_type
;
1071 struct bt_ctf_field_type
*enumeration_sequence_type
;
1072 struct bt_ctf_field_type
*enumeration_array_type
;
1073 struct bt_ctf_field_type
*returned_type
;
1074 const char *ret_string
;
1076 returned_type
= bt_ctf_field_get_type(NULL
);
1077 ok(!returned_type
, "bt_ctf_field_get_type handles NULL correctly");
1079 ok(uint_12_type
, "Create an unsigned integer type");
1080 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1081 BT_CTF_INTEGER_BASE_BINARY
) == 0,
1082 "Set integer type's base as binary");
1083 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1084 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
1085 "Set integer type's base as decimal");
1086 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1087 BT_CTF_INTEGER_BASE_UNKNOWN
),
1088 "Reject integer type's base set as unknown");
1089 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1090 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
1091 "Set integer type's base as octal");
1092 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1093 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
1094 "Set integer type's base as hexadecimal");
1095 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
1096 "Reject unknown integer base value");
1097 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
1098 "Set integer type signedness to signed");
1099 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
1100 "Set integer type signedness to unsigned");
1101 ok(bt_ctf_field_type_integer_get_size(NULL
) < 0,
1102 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1103 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
1104 "bt_ctf_field_type_integer_get_size returns a correct value");
1105 ok(bt_ctf_field_type_integer_get_signed(NULL
) < 0,
1106 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1107 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
1108 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1110 ok(bt_ctf_field_type_set_byte_order(NULL
,
1111 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
1112 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1113 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1114 (enum bt_ctf_byte_order
) 42) < 0,
1115 "bt_ctf_field_type_set_byte_order rejects invalid values");
1116 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1117 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
1118 "Set an integer's byte order to little endian");
1119 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1120 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1121 "Set an integer's byte order to big endian");
1122 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
1123 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1124 "bt_ctf_field_type_get_byte_order returns a correct value");
1125 ok(bt_ctf_field_type_get_byte_order(NULL
) ==
1126 BT_CTF_BYTE_ORDER_UNKNOWN
,
1127 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1129 ok(bt_ctf_field_type_get_type_id(NULL
) ==
1131 "bt_ctf_field_type_get_type_id handles NULL correctly");
1132 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
1134 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1136 ok(bt_ctf_field_type_integer_get_base(NULL
) ==
1137 BT_CTF_INTEGER_BASE_UNKNOWN
,
1138 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1139 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
1140 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
1141 "bt_ctf_field_type_integer_get_base returns a correct value");
1143 ok(bt_ctf_field_type_integer_set_encoding(NULL
, CTF_STRING_ASCII
) < 0,
1144 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1145 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1146 (enum ctf_string_encoding
) 123) < 0,
1147 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1148 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1149 CTF_STRING_UTF8
) == 0,
1150 "Set integer type encoding to UTF8");
1151 ok(bt_ctf_field_type_integer_get_encoding(NULL
) == CTF_STRING_UNKNOWN
,
1152 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1153 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) == CTF_STRING_UTF8
,
1154 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1156 int_16_type
= bt_ctf_field_type_integer_create(16);
1157 bt_ctf_field_type_integer_set_signed(int_16_type
, 1);
1158 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
1159 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1160 uint_8_type
= bt_ctf_field_type_integer_create(8);
1162 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
1163 ok(sequence_type
, "Create a sequence of int16_t type");
1164 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
1166 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1168 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL
) == NULL
,
1169 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1170 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
1172 ok(!strcmp(ret_string
, "seq_len"),
1173 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1174 ok(bt_ctf_field_type_sequence_get_element_type(NULL
) == NULL
,
1175 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1176 returned_type
= bt_ctf_field_type_sequence_get_element_type(
1178 ok(returned_type
== int_16_type
,
1179 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
1180 bt_ctf_field_type_put(returned_type
);
1182 string_type
= bt_ctf_field_type_string_create();
1183 ok(string_type
, "Create a string type");
1184 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1186 "Reject invalid \"None\" string encoding");
1187 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1189 "Reject invalid string encoding");
1190 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1191 CTF_STRING_ASCII
) == 0,
1192 "Set string encoding to ASCII");
1194 ok(bt_ctf_field_type_string_get_encoding(NULL
) ==
1196 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
1197 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
1199 "bt_ctf_field_type_string_get_encoding returns the correct value");
1201 structure_seq_type
= bt_ctf_field_type_structure_create();
1202 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
1204 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
1205 ok(structure_seq_type
, "Create a structure type");
1206 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1207 uint_8_type
, "seq_len") == 0,
1208 "Add a uint8_t type to a structure");
1209 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1210 sequence_type
, "a_sequence") == 0,
1211 "Add a sequence type to a structure");
1213 ok(bt_ctf_field_type_structure_get_field_count(NULL
) < 0,
1214 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
1215 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
1216 "bt_ctf_field_type_structure_get_field_count returns a correct value");
1218 ok(bt_ctf_field_type_structure_get_field(NULL
,
1219 &ret_string
, &returned_type
, 1) < 0,
1220 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
1221 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1222 NULL
, &returned_type
, 1) < 0,
1223 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
1224 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1225 &ret_string
, NULL
, 1) < 0,
1226 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
1227 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1228 &ret_string
, &returned_type
, 10) < 0,
1229 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
1230 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1231 &ret_string
, &returned_type
, 1) == 0,
1232 "bt_ctf_field_type_structure_get_field returns a field");
1233 ok(!strcmp(ret_string
, "a_sequence"),
1234 "bt_ctf_field_type_structure_get_field returns a correct field name");
1235 ok(returned_type
== sequence_type
,
1236 "bt_ctf_field_type_structure_get_field returns a correct field type");
1237 bt_ctf_field_type_put(returned_type
);
1239 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL
, "a_sequence") == NULL
,
1240 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
1241 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type
, NULL
) == NULL
,
1242 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1243 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1244 structure_seq_type
, "a_sequence");
1245 ok(returned_type
== sequence_type
,
1246 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
1247 bt_ctf_field_type_put(returned_type
);
1249 composite_structure_type
= bt_ctf_field_type_structure_create();
1250 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1251 string_type
, "a_string") == 0,
1252 "Add a string type to a structure");
1253 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1254 structure_seq_type
, "inner_structure") == 0,
1255 "Add a structure type to a structure");
1257 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1258 NULL
, "a_sequence") == NULL
,
1259 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
1260 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1261 structure_seq_type
, NULL
) == NULL
,
1262 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1263 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1264 structure_seq_type
, "a_sequence");
1265 ok(returned_type
== sequence_type
,
1266 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1267 bt_ctf_field_type_put(returned_type
);
1269 int_16
= bt_ctf_field_create(int_16_type
);
1270 ok(int_16
, "Instanciate a signed 16-bit integer");
1271 uint_12
= bt_ctf_field_create(uint_12_type
);
1272 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1273 returned_type
= bt_ctf_field_get_type(int_16
);
1274 ok(returned_type
== int_16_type
,
1275 "bt_ctf_field_get_type returns the correct type");
1277 /* Can't modify types after instanciating them */
1278 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1279 BT_CTF_INTEGER_BASE_DECIMAL
),
1280 "Check an integer type' base can't be modified after instanciation");
1281 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1282 "Check an integer type's signedness can't be modified after instanciation");
1284 /* Check signed property is checked */
1285 ok(bt_ctf_field_signed_integer_set_value(uint_12
, -52),
1286 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
1287 ok(bt_ctf_field_unsigned_integer_set_value(int_16
, 42),
1288 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
1290 /* Check overflows are properly tested for */
1291 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32768) == 0,
1292 "Check -32768 is allowed for a signed 16-bit integer");
1293 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32767) == 0,
1294 "Check 32767 is allowed for a signed 16-bit integer");
1295 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32768),
1296 "Check 32768 is not allowed for a signed 16-bit integer");
1297 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32769),
1298 "Check -32769 is not allowed for a signed 16-bit integer");
1299 ok(bt_ctf_field_signed_integer_set_value(int_16
, -42) == 0,
1300 "Check -42 is allowed for a signed 16-bit integer");
1302 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4095) == 0,
1303 "Check 4095 is allowed for an unsigned 12-bit integer");
1304 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4096),
1305 "Check 4096 is not allowed for a unsigned 12-bit integer");
1306 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 0) == 0,
1307 "Check 0 is allowed for an unsigned 12-bit integer");
1309 string
= bt_ctf_field_create(string_type
);
1310 ok(string
, "Instanciate a string field");
1311 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1312 "Set a string's value");
1314 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1315 ok(enumeration_type
,
1316 "Create an enumeration type with an unsigned 12-bit integer as container");
1317 enumeration_sequence_type
= bt_ctf_field_type_sequence_create(
1318 enumeration_type
, "count");
1319 ok(!enumeration_sequence_type
,
1320 "Check enumeration types are validated when creating a sequence");
1321 enumeration_array_type
= bt_ctf_field_type_array_create(
1322 enumeration_type
, 10);
1323 ok(!enumeration_array_type
,
1324 "Check enumeration types are validated when creating an array");
1325 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1326 enumeration_type
, "enumeration"),
1327 "Check enumeration types are validated when adding them as structure members");
1328 enumeration
= bt_ctf_field_create(enumeration_type
);
1330 "Check enumeration types are validated before instantiation");
1332 bt_ctf_field_put(string
);
1333 bt_ctf_field_put(uint_12
);
1334 bt_ctf_field_put(int_16
);
1335 bt_ctf_field_put(enumeration
);
1336 bt_ctf_field_type_put(composite_structure_type
);
1337 bt_ctf_field_type_put(structure_seq_type
);
1338 bt_ctf_field_type_put(string_type
);
1339 bt_ctf_field_type_put(sequence_type
);
1340 bt_ctf_field_type_put(uint_8_type
);
1341 bt_ctf_field_type_put(int_16_type
);
1342 bt_ctf_field_type_put(uint_12_type
);
1343 bt_ctf_field_type_put(enumeration_type
);
1344 bt_ctf_field_type_put(enumeration_sequence_type
);
1345 bt_ctf_field_type_put(enumeration_array_type
);
1346 bt_ctf_field_type_put(returned_type
);
1349 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
1350 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
1353 * Append enough events to force the underlying packet to be resized.
1354 * Also tests that a new event can be declared after a stream has been
1355 * instantiated and used/flushed.
1359 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
1361 struct bt_ctf_field_type
*integer_type
=
1362 bt_ctf_field_type_integer_create(17);
1363 struct bt_ctf_field_type
*string_type
=
1364 bt_ctf_field_type_string_create();
1365 struct bt_ctf_event
*event
= NULL
;
1366 struct bt_ctf_field
*ret_field
= NULL
;
1367 struct bt_ctf_field_type
*ret_field_type
= NULL
;
1368 uint64_t ret_uint64
;
1369 int events_appended
= 0;
1370 struct bt_ctf_field
*packet_context
= NULL
,
1371 *packet_context_field
= NULL
, *event_context
= NULL
;
1373 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
1375 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
1377 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
1378 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
1383 event
= bt_ctf_event_create(event_class
);
1384 ret_field
= bt_ctf_event_get_payload_by_index(event
, 0);
1385 ret_field_type
= bt_ctf_field_get_type(ret_field
);
1386 ok(ret_field_type
== integer_type
,
1387 "bt_ctf_event_get_payload_by_index returns a correct field");
1388 bt_ctf_field_type_put(ret_field_type
);
1389 bt_ctf_field_put(ret_field
);
1391 ok(bt_ctf_event_get_payload_by_index(NULL
, 0) == NULL
,
1392 "bt_ctf_event_get_payload_by_index handles NULL correctly");
1393 ok(bt_ctf_event_get_payload_by_index(event
, 4) == NULL
,
1394 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
1395 bt_ctf_event_put(event
);
1397 ok(bt_ctf_stream_get_event_context(NULL
) == NULL
,
1398 "bt_ctf_stream_get_event_context handles NULL correctly");
1399 event_context
= bt_ctf_stream_get_event_context(stream
);
1401 "bt_ctf_stream_get_event_context returns a stream event context");
1402 ok(bt_ctf_stream_set_event_context(NULL
, event_context
) < 0,
1403 "bt_ctf_stream_set_event_context handles a NULL stream correctly");
1404 ok(bt_ctf_stream_set_event_context(stream
, NULL
) < 0,
1405 "bt_ctf_stream_set_event_context handles a NULL stream event context correctly");
1406 ok(!bt_ctf_stream_set_event_context(stream
, event_context
),
1407 "bt_ctf_stream_set_event_context correctly set a stream event context");
1408 ret_field
= bt_ctf_field_create(integer_type
);
1409 ok(bt_ctf_stream_set_event_context(stream
, ret_field
) < 0,
1410 "bt_ctf_stream_set_event_context rejects an event context of incorrect type");
1411 bt_ctf_field_put(ret_field
);
1413 for (i
= 0; i
< PACKET_RESIZE_TEST_LENGTH
; i
++) {
1414 event
= bt_ctf_event_create(event_class
);
1415 struct bt_ctf_field
*integer
=
1416 bt_ctf_field_create(integer_type
);
1417 struct bt_ctf_field
*string
=
1418 bt_ctf_field_create(string_type
);
1420 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
1421 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
1422 ret
|= bt_ctf_event_set_payload(event
, "field_1",
1424 bt_ctf_field_put(integer
);
1425 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
1426 ret
|= bt_ctf_event_set_payload(event
, "a_string",
1428 bt_ctf_field_put(string
);
1430 /* Populate stream event context */
1431 integer
= bt_ctf_field_structure_get_field(event_context
,
1432 "common_event_context");
1433 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
,
1435 bt_ctf_field_put(integer
);
1437 ret
|= bt_ctf_stream_append_event(stream
, event
);
1438 bt_ctf_event_put(event
);
1445 events_appended
= !!(i
== PACKET_RESIZE_TEST_LENGTH
);
1446 ok(bt_ctf_stream_get_discarded_events_count(NULL
, &ret_uint64
) < 0,
1447 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
1448 ok(bt_ctf_stream_get_discarded_events_count(stream
, NULL
) < 0,
1449 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
1450 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1451 ok(ret
== 0 && ret_uint64
== 0,
1452 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1453 bt_ctf_stream_append_discarded_events(stream
, 1000);
1454 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1455 ok(ret
== 0 && ret_uint64
== 1000,
1456 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1459 ok(events_appended
, "Append 100 000 events to a stream");
1462 * Populate the custom packet context field with a dummy value
1463 * otherwise flush will fail.
1465 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1466 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1467 "custom_packet_context_field");
1468 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 2);
1470 ok(bt_ctf_stream_flush(stream
) == 0,
1471 "Flush a stream that forces a packet resize");
1472 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
1473 ok(ret
== 0 && ret_uint64
== 1000,
1474 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1475 bt_ctf_field_type_put(integer_type
);
1476 bt_ctf_field_type_put(string_type
);
1477 bt_ctf_field_put(packet_context
);
1478 bt_ctf_field_put(packet_context_field
);
1479 bt_ctf_field_put(event_context
);
1480 bt_ctf_event_class_put(event_class
);
1483 int main(int argc
, char **argv
)
1485 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
1486 char metadata_path
[sizeof(trace_path
) + 9];
1487 const char *clock_name
= "test_clock";
1488 const char *clock_description
= "This is a test clock";
1489 const char *returned_clock_name
;
1490 const char *returned_clock_description
;
1491 const uint64_t frequency
= 1123456789;
1492 const uint64_t offset_s
= 1351530929945824323;
1493 const uint64_t offset
= 1234567;
1494 const uint64_t precision
= 10;
1495 const int is_absolute
= 0xFF;
1496 char *metadata_string
;
1497 struct bt_ctf_writer
*writer
;
1498 struct utsname name
;
1499 char hostname
[BABELTRACE_HOST_NAME_MAX
];
1500 struct bt_ctf_clock
*clock
, *ret_clock
;
1501 struct bt_ctf_stream_class
*stream_class
;
1502 struct bt_ctf_stream
*stream1
;
1503 const char *ret_string
;
1504 const unsigned char *ret_uuid
;
1505 unsigned char tmp_uuid
[16] = { 0 };
1506 struct bt_ctf_field_type
*packet_context_type
,
1507 *packet_context_field_type
,
1509 *stream_event_context_type
,
1511 struct bt_ctf_trace
*trace
;
1515 printf("Usage: tests-ctf-writer path_to_ctf_parser_test path_to_babeltrace\n");
1521 if (!mkdtemp(trace_path
)) {
1525 strcpy(metadata_path
, trace_path
);
1526 strcat(metadata_path
+ sizeof(trace_path
) - 1, "/metadata");
1528 writer
= bt_ctf_writer_create(trace_path
);
1529 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
1531 /* Add environment context to the trace */
1532 ret
= gethostname(hostname
, sizeof(hostname
));
1536 ok(bt_ctf_writer_add_environment_field(writer
, "host", hostname
) == 0,
1537 "Add host (%s) environment field to writer instance",
1539 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
1541 "bt_ctf_writer_add_environment_field error with NULL writer");
1542 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
1544 "bt_ctf_writer_add_environment_field error with NULL field name");
1545 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
1547 "bt_ctf_writer_add_environment_field error with NULL field value");
1554 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
1555 == 0, "Add sysname (%s) environment field to writer instance",
1557 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
1558 name
.nodename
) == 0,
1559 "Add nodename (%s) environment field to writer instance",
1561 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
1562 == 0, "Add release (%s) environment field to writer instance",
1564 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
1565 == 0, "Add version (%s) environment field to writer instance",
1567 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
1568 == 0, "Add machine (%s) environment field to writer istance",
1571 /* Define a clock and add it to the trace */
1572 ok(bt_ctf_clock_create("signed") == NULL
,
1573 "Illegal clock name rejected");
1574 ok(bt_ctf_clock_create(NULL
) == NULL
, "NULL clock name rejected");
1575 clock
= bt_ctf_clock_create(clock_name
);
1576 ok(clock
, "Clock created sucessfully");
1577 returned_clock_name
= bt_ctf_clock_get_name(clock
);
1578 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
1579 ok(returned_clock_name
? !strcmp(returned_clock_name
, clock_name
) : 0,
1580 "Returned clock name is valid");
1582 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1583 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
1584 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
1585 "Clock description set successfully");
1587 returned_clock_description
= bt_ctf_clock_get_description(clock
);
1588 ok(returned_clock_description
,
1589 "bt_ctf_clock_get_description returns a description.");
1590 ok(returned_clock_description
?
1591 !strcmp(returned_clock_description
, clock_description
) : 0,
1592 "Returned clock description is valid");
1594 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
1595 "bt_ctf_clock_get_frequency returns the correct default frequency");
1596 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
1597 "Set clock frequency");
1598 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
1599 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
1601 ok(bt_ctf_clock_get_offset_s(clock
) == DEFAULT_CLOCK_OFFSET_S
,
1602 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
1603 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
1604 "Set clock offset (seconds)");
1605 ok(bt_ctf_clock_get_offset_s(clock
) == offset_s
,
1606 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
1608 ok(bt_ctf_clock_get_offset(clock
) == DEFAULT_CLOCK_OFFSET
,
1609 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks)");
1610 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
1611 ok(bt_ctf_clock_get_offset(clock
) == offset
,
1612 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks) once it is set");
1614 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
1615 "bt_ctf_clock_get_precision returns the correct default precision");
1616 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
1617 "Set clock precision");
1618 ok(bt_ctf_clock_get_precision(clock
) == precision
,
1619 "bt_ctf_clock_get_precision returns the correct precision once it is set");
1621 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
1622 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
1623 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
1624 "Set clock absolute property");
1625 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
1626 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
1628 ok(bt_ctf_clock_get_time(clock
) == DEFAULT_CLOCK_TIME
,
1629 "bt_ctf_clock_get_time returns the correct default time");
1630 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
1632 ok(bt_ctf_clock_get_time(clock
) == current_time
,
1633 "bt_ctf_clock_get_time returns the correct time once it is set");
1635 ok(bt_ctf_writer_add_clock(writer
, clock
) == 0,
1636 "Add clock to writer instance");
1637 ok(bt_ctf_writer_add_clock(writer
, clock
),
1638 "Verify a clock can't be added twice to a writer instance");
1640 ok(!bt_ctf_writer_get_trace(NULL
),
1641 "bt_ctf_writer_get_trace correctly handles NULL");
1642 trace
= bt_ctf_writer_get_trace(writer
);
1644 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1645 ok(bt_ctf_trace_get_clock_count(NULL
) < 0,
1646 "bt_ctf_trace_get_clock_count correctly handles NULL");
1647 ok(bt_ctf_trace_get_clock_count(trace
) == 1,
1648 "bt_ctf_trace_get_clock_count returns the correct number of clocks");
1649 ok(!bt_ctf_trace_get_clock(NULL
, 0),
1650 "bt_ctf_trace_get_clock correctly handles NULL");
1651 ok(!bt_ctf_trace_get_clock(trace
, -1),
1652 "bt_ctf_trace_get_clock correctly handles negative indexes");
1653 ok(!bt_ctf_trace_get_clock(trace
, 1),
1654 "bt_ctf_trace_get_clock correctly handles out of bound accesses");
1655 ret_clock
= bt_ctf_trace_get_clock(trace
, 0);
1656 ok(ret_clock
== clock
,
1657 "bt_ctf_trace_get_clock returns the right clock instance");
1658 bt_ctf_clock_put(ret_clock
);
1660 ok(!bt_ctf_clock_get_name(NULL
),
1661 "bt_ctf_clock_get_name correctly handles NULL");
1662 ok(!bt_ctf_clock_get_description(NULL
),
1663 "bt_ctf_clock_get_description correctly handles NULL");
1664 ok(bt_ctf_clock_get_frequency(NULL
) == -1ULL,
1665 "bt_ctf_clock_get_frequency correctly handles NULL");
1666 ok(bt_ctf_clock_get_precision(NULL
) == -1ULL,
1667 "bt_ctf_clock_get_precision correctly handles NULL");
1668 ok(bt_ctf_clock_get_offset_s(NULL
) == -1ULL,
1669 "bt_ctf_clock_get_offset_s correctly handles NULL");
1670 ok(bt_ctf_clock_get_offset(NULL
) == -1ULL,
1671 "bt_ctf_clock_get_offset correctly handles NULL");
1672 ok(bt_ctf_clock_get_is_absolute(NULL
) < 0,
1673 "bt_ctf_clock_get_is_absolute correctly handles NULL");
1674 ok(bt_ctf_clock_get_time(NULL
) == -1ULL,
1675 "bt_ctf_clock_get_time correctly handles NULL");
1677 ok(bt_ctf_clock_set_description(NULL
, NULL
) < 0,
1678 "bt_ctf_clock_set_description correctly handles NULL clock");
1679 ok(bt_ctf_clock_set_frequency(NULL
, frequency
) < 0,
1680 "bt_ctf_clock_set_frequency correctly handles NULL clock");
1681 ok(bt_ctf_clock_set_precision(NULL
, precision
) < 0,
1682 "bt_ctf_clock_get_precision correctly handles NULL clock");
1683 ok(bt_ctf_clock_set_offset_s(NULL
, offset_s
) < 0,
1684 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
1685 ok(bt_ctf_clock_set_offset(NULL
, offset
) < 0,
1686 "bt_ctf_clock_set_offset correctly handles NULL clock");
1687 ok(bt_ctf_clock_set_is_absolute(NULL
, is_absolute
) < 0,
1688 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
1689 ok(bt_ctf_clock_set_time(NULL
, current_time
) < 0,
1690 "bt_ctf_clock_set_time correctly handles NULL clock");
1691 ok(bt_ctf_clock_get_uuid(NULL
) == NULL
,
1692 "bt_ctf_clock_get_uuid correctly handles NULL clock");
1693 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1695 "bt_ctf_clock_get_uuid returns a UUID");
1697 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
1698 /* Slightly modify UUID */
1699 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
1702 ok(bt_ctf_clock_set_uuid(NULL
, tmp_uuid
) < 0,
1703 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
1704 ok(bt_ctf_clock_set_uuid(clock
, NULL
) < 0,
1705 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
1706 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
1707 "bt_ctf_clock_set_uuid sets a new uuid succesfully");
1708 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
1710 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
1711 ok(uuid_match(ret_uuid
, tmp_uuid
),
1712 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
1714 /* Define a stream class */
1715 stream_class
= bt_ctf_stream_class_create("test_stream");
1717 ok(bt_ctf_stream_class_get_name(NULL
) == NULL
,
1718 "bt_ctf_stream_class_get_name handles NULL correctly");
1719 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
1720 ok(!strcmp(ret_string
, "test_stream"),
1721 "bt_ctf_stream_class_get_name returns a correct stream class name");
1723 ok(bt_ctf_stream_class_get_clock(stream_class
) == NULL
,
1724 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
1725 ok(bt_ctf_stream_class_get_clock(NULL
) == NULL
,
1726 "bt_ctf_stream_class_get_clock handles NULL correctly");
1728 ok(stream_class
, "Create stream class");
1729 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
1730 "Set a stream class' clock");
1731 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
1732 ok(ret_clock
== clock
,
1733 "bt_ctf_stream_class_get_clock returns a correct clock");
1734 bt_ctf_clock_put(ret_clock
);
1736 /* Test the event fields and event types APIs */
1739 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
1740 "bt_ctf_stream_class_get_id returns an error when no id is set");
1741 ok(bt_ctf_stream_class_get_id(NULL
) < 0,
1742 "bt_ctf_stream_class_get_id handles NULL correctly");
1743 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
1744 "bt_ctf_stream_class_set_id handles NULL correctly");
1745 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
1746 "Set an stream class' id");
1747 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
1748 "bt_ctf_stream_class_get_id returns the correct value");
1750 /* Create a "uint5_t" equivalent custom packet context field */
1751 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
1753 ok(bt_ctf_stream_class_get_packet_context_type(NULL
) == NULL
,
1754 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
1756 /* Add a custom field to the stream class' packet context */
1757 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
1758 ok(packet_context_type
,
1759 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
1760 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == CTF_TYPE_STRUCT
,
1761 "Packet context is a structure");
1763 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
1764 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
1765 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
),
1766 "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly");
1768 integer_type
= bt_ctf_field_type_integer_create(32);
1769 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
1771 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
1772 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1773 packet_context_field_type
, "custom_packet_context_field");
1774 ok(ret
== 0, "Packet context field added successfully");
1776 /* Define a stream event context containing a my_integer field. */
1777 ok(bt_ctf_stream_class_get_event_context_type(NULL
) == NULL
,
1778 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
1779 ok(bt_ctf_stream_class_get_event_context_type(
1780 stream_class
) == NULL
,
1781 "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set.");
1782 stream_event_context_type
= bt_ctf_field_type_structure_create();
1783 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1784 integer_type
, "common_event_context");
1786 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
1787 stream_event_context_type
) < 0,
1788 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
1789 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
1791 "bt_ctf_stream_class_set_event_context_type handles a NULL event_context correctly");
1792 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
1794 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
1796 ok(bt_ctf_stream_class_set_event_context_type(
1797 stream_class
, stream_event_context_type
) == 0,
1798 "Set a new stream event context type");
1799 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
1801 ok(ret_field_type
== stream_event_context_type
,
1802 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
1804 /* Instantiate a stream and append events */
1805 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
1806 ok(stream1
, "Instanciate a stream class from writer");
1809 * Try to modify the packet context type after a stream has been
1812 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
1813 packet_context_field_type
, "should_fail");
1815 "Packet context type can't be modified once a stream class has been instanciated");
1818 * Try to modify the stream event context type after a stream has been
1821 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
1822 integer_type
, "should_fail");
1824 "Stream event context type can't be modified once a stream class has been instanciated");
1826 /* Should fail after instanciating a stream (frozen) */
1827 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
1828 "Changes to a stream class that was already instantiated fail");
1830 append_simple_event(stream_class
, stream1
, clock
);
1832 packet_resize_test(stream_class
, stream1
, clock
);
1834 append_complex_event(stream_class
, stream1
, clock
);
1836 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
1837 ok(metadata_string
, "Get metadata string");
1839 bt_ctf_writer_flush_metadata(writer
);
1840 validate_metadata(argv
[1], metadata_path
);
1841 validate_trace(argv
[2], trace_path
);
1843 bt_ctf_clock_put(clock
);
1844 bt_ctf_stream_class_put(stream_class
);
1845 bt_ctf_writer_put(writer
);
1846 bt_ctf_stream_put(stream1
);
1847 bt_ctf_field_type_put(packet_context_type
);
1848 bt_ctf_field_type_put(packet_context_field_type
);
1849 bt_ctf_field_type_put(integer_type
);
1850 bt_ctf_field_type_put(stream_event_context_type
);
1851 bt_ctf_field_type_put(ret_field_type
);
1852 bt_ctf_trace_put(trace
);
1853 free(metadata_string
);
1855 /* Remove all trace files and delete temporary trace directory */
1856 DIR *trace_dir
= opendir(trace_path
);
1858 perror("# opendir");
1862 struct dirent
*entry
;
1863 while ((entry
= readdir(trace_dir
))) {
1864 if (entry
->d_type
== DT_REG
) {
1865 //unlinkat(dirfd(trace_dir), entry->d_name, 0);
1870 closedir(trace_dir
);