ir: refactor FT validation and resolving
[babeltrace.git] / tests / lib / test_ctf_writer.c
1 /*
2 * test-ctf-writer.c
3 *
4 * CTF Writer test
5 *
6 * Copyright 2013 - 2015 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
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.
11 *
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.
16 *
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.
20 */
21
22 #include <babeltrace/ctf-writer/writer.h>
23 #include <babeltrace/ctf-writer/clock.h>
24 #include <babeltrace/ctf-writer/stream.h>
25 #include <babeltrace/ctf-writer/event.h>
26 #include <babeltrace/ctf-writer/event-types.h>
27 #include <babeltrace/ctf-writer/event-fields.h>
28 #include <babeltrace/ctf-ir/stream-class.h>
29 #include <babeltrace/ref.h>
30 #include <babeltrace/ctf/events.h>
31 #include <babeltrace/values.h>
32 #include <unistd.h>
33 #include <babeltrace/compat/stdlib.h>
34 #include <stdio.h>
35 #include <sys/utsname.h>
36 #include <babeltrace/compat/limits.h>
37 #include <babeltrace/compat/stdio.h>
38 #include <string.h>
39 #include <assert.h>
40 #include <sys/wait.h>
41 #include <fcntl.h>
42 #include <babeltrace/compat/dirent.h>
43 #include "tap/tap.h"
44 #include <math.h>
45 #include <float.h>
46 #include <sys/stat.h>
47
48 #define METADATA_LINE_SIZE 512
49 #define SEQUENCE_TEST_LENGTH 10
50 #define ARRAY_TEST_LENGTH 5
51 #define PACKET_RESIZE_TEST_LENGTH 100000
52
53 #define DEFAULT_CLOCK_FREQ 1000000000
54 #define DEFAULT_CLOCK_PRECISION 1
55 #define DEFAULT_CLOCK_OFFSET 0
56 #define DEFAULT_CLOCK_OFFSET_S 0
57 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
58 #define DEFAULT_CLOCK_TIME 0
59
60 #define NR_TESTS 594
61
62 static int64_t current_time = 42;
63
64 /* Return 1 if uuids match, zero if different. */
65 int uuid_match(const unsigned char *uuid_a, const unsigned char *uuid_b)
66 {
67 int ret = 0;
68 int i;
69
70 if (!uuid_a || !uuid_b) {
71 goto end;
72 }
73
74 for (i = 0; i < 16; i++) {
75 if (uuid_a[i] != uuid_b[i]) {
76 goto end;
77 }
78 }
79
80 ret = 1;
81 end:
82 return ret;
83 }
84
85 void validate_metadata(char *parser_path, char *metadata_path)
86 {
87 int ret = 0;
88 char parser_output_path[] = "/tmp/parser_output_XXXXXX";
89 int parser_output_fd = -1, metadata_fd = -1;
90
91 if (!metadata_path) {
92 ret = -1;
93 goto result;
94 }
95
96 parser_output_fd = mkstemp(parser_output_path);
97 metadata_fd = open(metadata_path, O_RDONLY);
98
99 unlink(parser_output_path);
100
101 if (parser_output_fd == -1 || metadata_fd == -1) {
102 diag("Failed create temporary files for metadata parsing.");
103 ret = -1;
104 goto result;
105 }
106
107 pid_t pid = fork();
108 if (pid) {
109 int status = 0;
110 waitpid(pid, &status, 0);
111 ret = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
112 } else {
113 /* ctf-parser-test expects a metadata string on stdin. */
114 ret = dup2(metadata_fd, STDIN_FILENO);
115 if (ret < 0) {
116 perror("# dup2 metadata_fd to STDIN");
117 goto result;
118 }
119
120 ret = dup2(parser_output_fd, STDOUT_FILENO);
121 if (ret < 0) {
122 perror("# dup2 parser_output_fd to STDOUT");
123 goto result;
124 }
125
126 ret = dup2(parser_output_fd, STDERR_FILENO);
127 if (ret < 0) {
128 perror("# dup2 parser_output_fd to STDERR");
129 goto result;
130 }
131
132 execl(parser_path, "ctf-parser-test", NULL);
133 perror("# Could not launch the ctf metadata parser process");
134 exit(-1);
135 }
136 result:
137 ok(ret == 0, "Metadata string is valid");
138
139 if (ret && metadata_fd >= 0 && parser_output_fd >= 0) {
140 char *line;
141 size_t len = METADATA_LINE_SIZE;
142 FILE *metadata_fp = NULL, *parser_output_fp = NULL;
143
144 metadata_fp = fdopen(metadata_fd, "r");
145 if (!metadata_fp) {
146 perror("fdopen on metadata_fd");
147 goto close_fp;
148 }
149 metadata_fd = -1;
150
151 parser_output_fp = fdopen(parser_output_fd, "r");
152 if (!parser_output_fp) {
153 perror("fdopen on parser_output_fd");
154 goto close_fp;
155 }
156 parser_output_fd = -1;
157
158 line = malloc(len);
159 if (!line) {
160 diag("malloc failure");
161 }
162
163 rewind(metadata_fp);
164
165 /* Output the metadata and parser output as diagnostic */
166 while (bt_getline(&line, &len, metadata_fp) > 0) {
167 fprintf(stderr, "# %s", line);
168 }
169
170 rewind(parser_output_fp);
171 while (bt_getline(&line, &len, parser_output_fp) > 0) {
172 fprintf(stderr, "# %s", line);
173 }
174
175 free(line);
176 close_fp:
177 if (metadata_fp) {
178 if (fclose(metadata_fp)) {
179 diag("fclose failure");
180 }
181 }
182 if (parser_output_fp) {
183 if (fclose(parser_output_fp)) {
184 diag("fclose failure");
185 }
186 }
187 }
188
189 if (parser_output_fd >= 0) {
190 if (close(parser_output_fd)) {
191 diag("close error");
192 }
193 }
194 if (metadata_fd >= 0) {
195 if (close(metadata_fd)) {
196 diag("close error");
197 }
198 }
199 }
200
201 void validate_trace(char *parser_path, char *trace_path)
202 {
203 int ret = 0;
204 char babeltrace_output_path[] = "/tmp/babeltrace_output_XXXXXX";
205 int babeltrace_output_fd = -1;
206
207 if (!trace_path) {
208 ret = -1;
209 goto result;
210 }
211
212 babeltrace_output_fd = mkstemp(babeltrace_output_path);
213 unlink(babeltrace_output_path);
214
215 if (babeltrace_output_fd == -1) {
216 diag("Failed to create a temporary file for trace parsing.");
217 ret = -1;
218 goto result;
219 }
220
221 pid_t pid = fork();
222 if (pid) {
223 int status = 0;
224 waitpid(pid, &status, 0);
225 ret = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
226 } else {
227 ret = dup2(babeltrace_output_fd, STDOUT_FILENO);
228 if (ret < 0) {
229 perror("# dup2 babeltrace_output_fd to STDOUT");
230 goto result;
231 }
232
233 ret = dup2(babeltrace_output_fd, STDERR_FILENO);
234 if (ret < 0) {
235 perror("# dup2 babeltrace_output_fd to STDERR");
236 goto result;
237 }
238
239 execl(parser_path, "babeltrace", trace_path, NULL);
240 perror("# Could not launch the babeltrace process");
241 exit(-1);
242 }
243 result:
244 ok(ret == 0, "Babeltrace could read the resulting trace");
245
246 if (ret && babeltrace_output_fd >= 0) {
247 char *line;
248 size_t len = METADATA_LINE_SIZE;
249 FILE *babeltrace_output_fp = NULL;
250
251 babeltrace_output_fp = fdopen(babeltrace_output_fd, "r");
252 if (!babeltrace_output_fp) {
253 perror("fdopen on babeltrace_output_fd");
254 goto close_fp;
255 }
256 babeltrace_output_fd = -1;
257
258 line = malloc(len);
259 if (!line) {
260 diag("malloc error");
261 }
262 rewind(babeltrace_output_fp);
263 while (bt_getline(&line, &len, babeltrace_output_fp) > 0) {
264 diag("%s", line);
265 }
266
267 free(line);
268 close_fp:
269 if (babeltrace_output_fp) {
270 if (fclose(babeltrace_output_fp)) {
271 diag("fclose error");
272 }
273 }
274 }
275
276 if (babeltrace_output_fd >= 0) {
277 if (close(babeltrace_output_fd)) {
278 diag("close error");
279 }
280 }
281 }
282
283 void event_copy_tests(struct bt_ctf_event *event)
284 {
285 struct bt_ctf_event *copy;
286 struct bt_ctf_event_class *orig_event_class;
287 struct bt_ctf_event_class *copy_event_class;
288 struct bt_ctf_stream *orig_stream;
289 struct bt_ctf_stream *copy_stream;
290 struct bt_ctf_field *orig_field;
291 struct bt_ctf_field *copy_field;
292
293 /* copy */
294 ok(!bt_ctf_event_copy(NULL),
295 "bt_ctf_event_copy handles NULL correctly");
296 copy = bt_ctf_event_copy(event);
297 ok(copy, "bt_ctf_event_copy returns a valid pointer");
298
299 /* validate event class */
300 orig_event_class = bt_ctf_event_get_class(event);
301 assert(orig_event_class);
302 copy_event_class = bt_ctf_event_get_class(copy);
303 ok(orig_event_class == copy_event_class,
304 "original and copied events share the same event class pointer");
305 bt_put(orig_event_class);
306 bt_put(copy_event_class);
307
308 /* validate stream */
309 orig_stream = bt_ctf_event_get_stream(event);
310 copy_stream = bt_ctf_event_get_stream(copy);
311
312 if (!orig_stream) {
313 ok(!copy_stream, "original and copied events have no stream");
314 } else {
315 ok(orig_stream == copy_stream,
316 "original and copied events share the same stream pointer");
317 }
318 bt_put(orig_stream);
319 bt_put(copy_stream);
320
321 /* header */
322 orig_field = bt_ctf_event_get_header(event);
323 copy_field = bt_ctf_event_get_header(copy);
324
325 if (!orig_field) {
326 ok(!copy_field, "original and copied events have no header");
327 } else {
328 ok(orig_field != copy_field,
329 "original and copied events headers are different pointers");
330 }
331
332 bt_put(orig_field);
333 bt_put(copy_field);
334
335 /* context */
336 orig_field = bt_ctf_event_get_event_context(event);
337 copy_field = bt_ctf_event_get_event_context(copy);
338
339 if (!orig_field) {
340 ok(!copy_field, "original and copied events have no context");
341 } else {
342 ok(orig_field != copy_field,
343 "original and copied events contexts are different pointers");
344 }
345
346 bt_put(orig_field);
347 bt_put(copy_field);
348
349 /* payload */
350 orig_field = bt_ctf_event_get_payload_field(event);
351 copy_field = bt_ctf_event_get_payload_field(copy);
352
353 if (!orig_field) {
354 ok(!copy_field, "original and copied events have no payload");
355 } else {
356 ok(orig_field != copy_field,
357 "original and copied events payloads are different pointers");
358 }
359
360 bt_put(orig_field);
361 bt_put(copy_field);
362
363 bt_put(copy);
364 }
365
366 void append_simple_event(struct bt_ctf_stream_class *stream_class,
367 struct bt_ctf_stream *stream, struct bt_ctf_clock *clock)
368 {
369 /* Create and add a simple event class */
370 struct bt_ctf_event_class *simple_event_class =
371 bt_ctf_event_class_create("Simple Event");
372 struct bt_ctf_field_type *uint_12_type =
373 bt_ctf_field_type_integer_create(12);
374 struct bt_ctf_field_type *int_64_type =
375 bt_ctf_field_type_integer_create(64);
376 struct bt_ctf_field_type *float_type =
377 bt_ctf_field_type_floating_point_create();
378 struct bt_ctf_field_type *enum_type;
379 struct bt_ctf_field_type *enum_type_unsigned =
380 bt_ctf_field_type_enumeration_create(uint_12_type);
381 struct bt_ctf_field_type *event_context_type =
382 bt_ctf_field_type_structure_create();
383 struct bt_ctf_field_type *event_payload_type = NULL;
384 struct bt_ctf_field_type *returned_type;
385 struct bt_ctf_event *simple_event;
386 struct bt_ctf_field *integer_field;
387 struct bt_ctf_field *float_field;
388 struct bt_ctf_field *enum_field;
389 struct bt_ctf_field *enum_field_unsigned;
390 struct bt_ctf_field *enum_container_field;
391 const char *mapping_name_test = "truie";
392 const double double_test_value = 3.1415;
393 struct bt_ctf_field *enum_container_field_unsigned;
394 const char *mapping_name_negative_test = "negative_value";
395 const char *ret_char;
396 double ret_double;
397 int64_t ret_range_start_int64_t, ret_range_end_int64_t;
398 uint64_t ret_range_start_uint64_t, ret_range_end_uint64_t;
399 struct bt_ctf_clock *ret_clock;
400 struct bt_ctf_event_class *ret_event_class;
401 struct bt_ctf_field *packet_context;
402 struct bt_ctf_field *packet_context_field;
403 struct bt_ctf_field *stream_event_context;
404 struct bt_ctf_field *stream_event_context_field;
405 struct bt_ctf_field *event_context;
406 struct bt_ctf_field *event_context_field;
407 struct bt_ctf_field_type *ep_integer_field_type = NULL;
408 struct bt_ctf_field_type *ep_enum_field_type = NULL;
409 struct bt_ctf_field_type *ep_enum_field_unsigned_type = NULL;
410 int ret;
411
412 ok(uint_12_type, "Create an unsigned integer type");
413
414 bt_ctf_field_type_integer_set_signed(int_64_type, 1);
415 ok(int_64_type, "Create a signed integer type");
416 enum_type = bt_ctf_field_type_enumeration_create(int_64_type);
417
418 returned_type = bt_ctf_field_type_enumeration_get_container_type(enum_type);
419 ok(returned_type == int_64_type, "bt_ctf_field_type_enumeration_get_container_type returns the right type");
420 ok(!bt_ctf_field_type_enumeration_get_container_type(NULL), "bt_ctf_field_type_enumeration_get_container_type handles NULL correctly");
421 ok(!bt_ctf_field_type_enumeration_create(enum_type),
422 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
423 bt_put(returned_type);
424
425 bt_ctf_field_type_set_alignment(float_type, 32);
426 ok(bt_ctf_field_type_get_alignment(NULL) < 0,
427 "bt_ctf_field_type_get_alignment handles NULL correctly");
428 ok(bt_ctf_field_type_get_alignment(float_type) == 32,
429 "bt_ctf_field_type_get_alignment returns a correct value");
430
431 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type, 11) == 0,
432 "Set a floating point type's exponent digit count");
433 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type, 53) == 0,
434 "Set a floating point type's mantissa digit count");
435
436 ok(bt_ctf_field_type_floating_point_get_exponent_digits(NULL) < 0,
437 "bt_ctf_field_type_floating_point_get_exponent_digits handles NULL properly");
438 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(NULL) < 0,
439 "bt_ctf_field_type_floating_point_get_mantissa_digits handles NULL properly");
440 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type) == 11,
441 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
442 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type) == 53,
443 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
444
445 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
446 mapping_name_negative_test, -12345, 0) == 0,
447 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
448 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
449 "escaping; \"test\"", 1, 1) == 0,
450 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
451 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
452 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
453 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
454 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
455 "event clock int float", 5, 22) == 0,
456 "Accept enumeration mapping strings containing reserved keywords");
457 bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test,
458 42, 42);
459 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test,
460 43, 51), "bt_ctf_field_type_enumeration_add_mapping rejects duplicate mapping names");
461 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, "something",
462 -500, -400), "bt_ctf_field_type_enumeration_add_mapping rejects overlapping enum entries");
463 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test,
464 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
465 bt_ctf_field_type_enumeration_add_mapping(enum_type, "another entry", -42000, -13000);
466
467 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(NULL, -42) < 0,
468 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles a NULL field type correctly");
469 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, 1000000) < 0,
470 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles invalid values correctly");
471 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, -55) == 1,
472 "bt_ctf_field_type_enumeration_get_mapping_index_by_value returns the correct index");
473
474 ok(bt_ctf_event_class_add_field(simple_event_class, enum_type,
475 "enum_field") == 0, "Add signed enumeration field to event");
476
477 ok(bt_ctf_field_type_enumeration_get_mapping(NULL, 0, &ret_char,
478 &ret_range_start_int64_t, &ret_range_end_int64_t) < 0,
479 "bt_ctf_field_type_enumeration_get_mapping handles a NULL enumeration correctly");
480 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, NULL,
481 &ret_range_start_int64_t, &ret_range_end_int64_t) < 0,
482 "bt_ctf_field_type_enumeration_get_mapping handles a NULL string correctly");
483 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, &ret_char,
484 NULL, &ret_range_end_int64_t) < 0,
485 "bt_ctf_field_type_enumeration_get_mapping handles a NULL start correctly");
486 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, &ret_char,
487 &ret_range_start_int64_t, NULL) < 0,
488 "bt_ctf_field_type_enumeration_get_mapping handles a NULL end correctly");
489 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 5, &ret_char,
490 &ret_range_start_int64_t, &ret_range_end_int64_t) == 0,
491 "bt_ctf_field_type_enumeration_get_mapping returns a value");
492 ok(!strcmp(ret_char, mapping_name_test),
493 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping name");
494 ok(ret_range_start_int64_t == 42,
495 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping start");
496 ok(ret_range_end_int64_t == 42,
497 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping end");
498
499 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned,
500 "escaping; \"test\"", 0, 0) == 0,
501 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing quotes");
502 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned,
503 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
504 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing special characters");
505 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned,
506 "event clock int float", 5, 22) == 0,
507 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing reserved keywords");
508 bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test,
509 42, 42);
510 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test,
511 43, 51), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects duplicate mapping names");
512 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, "something",
513 7, 8), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects overlapping enum entries");
514 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test,
515 55, 54), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects mapping where end < start");
516 ok(bt_ctf_event_class_add_field(simple_event_class, enum_type_unsigned,
517 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
518
519 ok(bt_ctf_field_type_enumeration_get_mapping_count(NULL) < 0,
520 "bt_ctf_field_type_enumeration_get_mapping_count handles NULL correctly");
521 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned) == 4,
522 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
523
524 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(NULL, 0, &ret_char,
525 &ret_range_start_uint64_t, &ret_range_end_uint64_t) < 0,
526 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL enumeration correctly");
527 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, NULL,
528 &ret_range_start_uint64_t, &ret_range_end_uint64_t) < 0,
529 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL string correctly");
530 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, &ret_char,
531 NULL, &ret_range_end_uint64_t) < 0,
532 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL start correctly");
533 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, &ret_char,
534 &ret_range_start_uint64_t, NULL) < 0,
535 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL end correctly");
536 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 3, &ret_char,
537 &ret_range_start_uint64_t, &ret_range_end_uint64_t) == 0,
538 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a value");
539 ok(!strcmp(ret_char, mapping_name_test),
540 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping name");
541 ok(ret_range_start_uint64_t == 42,
542 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping start");
543 ok(ret_range_end_uint64_t == 42,
544 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping end");
545
546 bt_ctf_event_class_add_field(simple_event_class, uint_12_type,
547 "integer_field");
548 bt_ctf_event_class_add_field(simple_event_class, float_type,
549 "float_field");
550
551 assert(!bt_ctf_event_class_set_id(simple_event_class, 13));
552
553 /* Set an event context type which will contain a single integer*/
554 ok(!bt_ctf_field_type_structure_add_field(event_context_type, uint_12_type,
555 "event_specific_context"),
556 "Add event specific context field");
557 ok(bt_ctf_event_class_get_context_type(NULL) == NULL,
558 "bt_ctf_event_class_get_context_type handles NULL correctly");
559 ok(bt_ctf_event_class_get_context_type(simple_event_class) == NULL,
560 "bt_ctf_event_class_get_context_type returns NULL when no event context type is set");
561
562 ok(bt_ctf_event_class_set_context_type(simple_event_class, NULL) < 0,
563 "bt_ctf_event_class_set_context_type handles a NULL context type correctly");
564 ok(bt_ctf_event_class_set_context_type(NULL, event_context_type) < 0,
565 "bt_ctf_event_class_set_context_type handles a NULL event class correctly");
566 ok(!bt_ctf_event_class_set_context_type(simple_event_class, event_context_type),
567 "Set an event class' context type successfully");
568 returned_type = bt_ctf_event_class_get_context_type(simple_event_class);
569 ok(returned_type == event_context_type,
570 "bt_ctf_event_class_get_context_type returns the appropriate type");
571 bt_put(returned_type);
572
573 bt_ctf_stream_class_add_event_class(stream_class, simple_event_class);
574
575 /*
576 * bt_ctf_stream_class_add_event_class() copies the field types
577 * of simple_event_class, so we retrieve the new ones to create
578 * the appropriate fields.
579 */
580 BT_PUT(event_context_type);
581 BT_PUT(event_payload_type);
582 event_payload_type = bt_ctf_event_class_get_payload_type(
583 simple_event_class);
584 assert(event_payload_type);
585 event_context_type = bt_ctf_event_class_get_context_type(
586 simple_event_class);
587 assert(event_context_type);
588 ep_integer_field_type =
589 bt_ctf_field_type_structure_get_field_type_by_name(
590 event_payload_type, "integer_field");
591 assert(ep_integer_field_type);
592 ep_enum_field_type =
593 bt_ctf_field_type_structure_get_field_type_by_name(
594 event_payload_type, "enum_field");
595 assert(ep_enum_field_type);
596 ep_enum_field_unsigned_type =
597 bt_ctf_field_type_structure_get_field_type_by_name(
598 event_payload_type, "enum_field_unsigned");
599 assert(ep_enum_field_unsigned_type);
600
601 ok(bt_ctf_stream_class_get_event_class_count(NULL) < 0,
602 "bt_ctf_stream_class_get_event_class_count handles NULL correctly");
603 ok(bt_ctf_stream_class_get_event_class_count(stream_class) == 1,
604 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
605 ok(bt_ctf_stream_class_get_event_class(NULL, 0) == NULL,
606 "bt_ctf_stream_class_get_event_class handles NULL correctly");
607 ok(bt_ctf_stream_class_get_event_class(stream_class, 8724) == NULL,
608 "bt_ctf_stream_class_get_event_class handles invalid indexes correctly");
609 ret_event_class = bt_ctf_stream_class_get_event_class(stream_class, 0);
610 ok(ret_event_class == simple_event_class,
611 "bt_ctf_stream_class_get_event_class returns the correct event class");
612 bt_put(ret_event_class);
613 ok(!bt_ctf_stream_class_get_event_class_by_id(NULL, 0),
614 "bt_ctf_stream_class_get_event_class_by_id handles NULL correctly");
615 ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class, 2),
616 "bt_ctf_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
617 ret_event_class =
618 bt_ctf_stream_class_get_event_class_by_id(stream_class, 13);
619 ok(ret_event_class == simple_event_class,
620 "bt_ctf_stream_class_get_event_class_by_id returns a correct event class");
621 bt_put(ret_event_class);
622
623 ok(bt_ctf_stream_class_get_event_class_by_name(NULL, "some event name") == NULL,
624 "bt_ctf_stream_class_get_event_class_by_name handles a NULL stream class correctly");
625 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, NULL) == NULL,
626 "bt_ctf_stream_class_get_event_class_by_name handles a NULL event class name correctly");
627 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, "some event name") == NULL,
628 "bt_ctf_stream_class_get_event_class_by_name handles non-existing event class names correctly");
629 ret_event_class = bt_ctf_stream_class_get_event_class_by_name(stream_class, "Simple Event");
630 ok(ret_event_class == simple_event_class,
631 "bt_ctf_stream_class_get_event_class_by_name returns a correct event class");
632 bt_put(ret_event_class);
633
634 simple_event = bt_ctf_event_create(simple_event_class);
635 ok(simple_event,
636 "Instantiate an event containing a single integer field");
637
638 ok(bt_ctf_event_get_clock(NULL) == NULL,
639 "bt_ctf_event_get_clock handles NULL correctly");
640 ret_clock = bt_ctf_event_get_clock(simple_event);
641 ok(ret_clock == clock,
642 "bt_ctf_event_get_clock returns a correct clock");
643 bt_put(clock);
644
645 integer_field = bt_ctf_field_create(ep_integer_field_type);
646 bt_ctf_field_unsigned_integer_set_value(integer_field, 42);
647 ok(bt_ctf_event_set_payload(simple_event, "integer_field",
648 integer_field) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
649
650 float_field = bt_ctf_event_get_payload(simple_event, "float_field");
651 ok(bt_ctf_field_floating_point_get_value(float_field, &ret_double),
652 "bt_ctf_field_floating_point_get_value fails on an unset float field");
653 bt_ctf_field_floating_point_set_value(float_field, double_test_value);
654 ok(bt_ctf_field_floating_point_get_value(NULL, &ret_double),
655 "bt_ctf_field_floating_point_get_value properly handles a NULL field");
656 ok(bt_ctf_field_floating_point_get_value(float_field, NULL),
657 "bt_ctf_field_floating_point_get_value properly handles a NULL return value pointer");
658 ok(!bt_ctf_field_floating_point_get_value(float_field, &ret_double),
659 "bt_ctf_field_floating_point_get_value returns a double value");
660 ok(fabs(ret_double - double_test_value) <= DBL_EPSILON,
661 "bt_ctf_field_floating_point_get_value returns a correct value");
662
663 enum_field = bt_ctf_field_create(ep_enum_field_type);
664 assert(enum_field);
665 ret_char = bt_ctf_field_enumeration_get_mapping_name(NULL);
666 ok(!ret_char, "bt_ctf_field_enumeration_get_mapping_name handles NULL correctly");
667 ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field);
668 ok(!ret_char, "bt_ctf_field_enumeration_get_mapping_name returns NULL if the enumeration's container field is unset");
669 enum_container_field = bt_ctf_field_enumeration_get_container(
670 enum_field);
671 ok(bt_ctf_field_signed_integer_set_value(
672 enum_container_field, -42) == 0,
673 "Set signed enumeration container value");
674 ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field);
675 ok(!strcmp(ret_char, mapping_name_negative_test),
676 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an signed container");
677 ret = bt_ctf_event_set_payload(simple_event, "enum_field", enum_field);
678 assert(!ret);
679
680 enum_field_unsigned = bt_ctf_field_create(ep_enum_field_unsigned_type);
681 assert(enum_field_unsigned);
682 enum_container_field_unsigned = bt_ctf_field_enumeration_get_container(
683 enum_field_unsigned);
684 ok(bt_ctf_field_unsigned_integer_set_value(
685 enum_container_field_unsigned, 42) == 0,
686 "Set unsigned enumeration container value");
687 ret = bt_ctf_event_set_payload(simple_event, "enum_field_unsigned",
688 enum_field_unsigned);
689 assert(!ret);
690 ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field_unsigned);
691 ok(ret_char && !strcmp(ret_char, mapping_name_test),
692 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an unsigned container");
693
694 ok(bt_ctf_clock_set_time(clock, current_time) == 0, "Set clock time");
695
696 /* Populate stream event context */
697 stream_event_context = bt_ctf_stream_get_event_context(stream);
698 stream_event_context_field = bt_ctf_field_structure_get_field(
699 stream_event_context, "common_event_context");
700 bt_ctf_field_unsigned_integer_set_value(stream_event_context_field, 42);
701
702 /* Populate the event's context */
703 ok(bt_ctf_event_get_event_context(NULL) == NULL,
704 "bt_ctf_event_get_event_context handles NULL correctly");
705 event_context = bt_ctf_event_get_event_context(simple_event);
706 ok(event_context,
707 "bt_ctf_event_get_event_context returns a field");
708 returned_type = bt_ctf_field_get_type(event_context);
709 ok(returned_type == event_context_type,
710 "bt_ctf_event_get_event_context returns a field of the appropriate type");
711 event_context_field = bt_ctf_field_structure_get_field(event_context,
712 "event_specific_context");
713 ok(!bt_ctf_field_unsigned_integer_set_value(event_context_field, 1234),
714 "Successfully set an event context's value");
715 ok(bt_ctf_event_set_event_context(NULL, event_context) < 0,
716 "bt_ctf_event_set_event_context handles a NULL event correctly");
717 ok(bt_ctf_event_set_event_context(simple_event, NULL) < 0,
718 "bt_ctf_event_set_event_context handles a NULL event context correctly");
719 ok(bt_ctf_event_set_event_context(simple_event, event_context_field) < 0,
720 "bt_ctf_event_set_event_context rejects a context of the wrong type");
721 ok(!bt_ctf_event_set_event_context(simple_event, event_context),
722 "Set an event context successfully");
723
724 event_copy_tests(simple_event);
725 ok(bt_ctf_stream_append_event(stream, simple_event) == 0,
726 "Append simple event to trace stream");
727
728 ok(bt_ctf_stream_get_packet_context(NULL) == NULL,
729 "bt_ctf_stream_get_packet_context handles NULL correctly");
730 packet_context = bt_ctf_stream_get_packet_context(stream);
731 ok(packet_context,
732 "bt_ctf_stream_get_packet_context returns a packet context");
733
734 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
735 "packet_size");
736 ok(packet_context_field,
737 "Packet context contains the default packet_size field.");
738 bt_put(packet_context_field);
739 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
740 "custom_packet_context_field");
741 ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field, 8) == 0,
742 "Custom packet context field value successfully set.");
743
744 ok(bt_ctf_stream_set_packet_context(NULL, packet_context_field) < 0,
745 "bt_ctf_stream_set_packet_context handles a NULL stream correctly");
746 ok(bt_ctf_stream_set_packet_context(stream, NULL) < 0,
747 "bt_ctf_stream_set_packet_context handles a NULL packet context correctly");
748 ok(bt_ctf_stream_set_packet_context(stream, packet_context) == 0,
749 "Successfully set a stream's packet context");
750
751 ok(bt_ctf_stream_flush(stream) == 0,
752 "Flush trace stream with one event");
753
754 bt_put(simple_event_class);
755 bt_put(simple_event);
756 bt_put(uint_12_type);
757 bt_put(int_64_type);
758 bt_put(float_type);
759 bt_put(enum_type);
760 bt_put(enum_type_unsigned);
761 bt_put(returned_type);
762 bt_put(event_context_type);
763 bt_put(integer_field);
764 bt_put(float_field);
765 bt_put(enum_field);
766 bt_put(enum_field_unsigned);
767 bt_put(enum_container_field);
768 bt_put(enum_container_field_unsigned);
769 bt_put(packet_context);
770 bt_put(packet_context_field);
771 bt_put(stream_event_context);
772 bt_put(stream_event_context_field);
773 bt_put(event_context);
774 bt_put(event_context_field);
775 bt_put(event_payload_type);
776 bt_put(ep_integer_field_type);
777 bt_put(ep_enum_field_type);
778 bt_put(ep_enum_field_unsigned_type);
779 }
780
781 void append_complex_event(struct bt_ctf_stream_class *stream_class,
782 struct bt_ctf_stream *stream, struct bt_ctf_clock *clock)
783 {
784 struct event_class_attrs_counts {
785 int id;
786 int name;
787 int loglevel;
788 int modelemfuri;
789 int unknown;
790 } attrs_count;
791
792 int i;
793 int ret;
794 int64_t int64_value;
795 struct event_class_attrs_counts ;
796 const char *complex_test_event_string = "Complex Test Event";
797 const char *test_string_1 = "Test ";
798 const char *test_string_2 = "string ";
799 const char *test_string_3 = "abcdefghi";
800 const char *test_string_4 = "abcd\0efg\0hi";
801 const char *test_string_cat = "Test string abcdeabcd";
802 struct bt_ctf_field_type *uint_35_type =
803 bt_ctf_field_type_integer_create(35);
804 struct bt_ctf_field_type *int_16_type =
805 bt_ctf_field_type_integer_create(16);
806 struct bt_ctf_field_type *uint_3_type =
807 bt_ctf_field_type_integer_create(3);
808 struct bt_ctf_field_type *enum_variant_type =
809 bt_ctf_field_type_enumeration_create(uint_3_type);
810 struct bt_ctf_field_type *variant_type =
811 bt_ctf_field_type_variant_create(enum_variant_type,
812 "variant_selector");
813 struct bt_ctf_field_type *string_type =
814 bt_ctf_field_type_string_create();
815 struct bt_ctf_field_type *sequence_type;
816 struct bt_ctf_field_type *array_type;
817 struct bt_ctf_field_type *inner_structure_type =
818 bt_ctf_field_type_structure_create();
819 struct bt_ctf_field_type *complex_structure_type =
820 bt_ctf_field_type_structure_create();
821 struct bt_ctf_field_type *ret_field_type;
822 struct bt_ctf_event_class *event_class;
823 struct bt_ctf_event *event;
824 struct bt_ctf_field *uint_35_field, *int_16_field, *a_string_field,
825 *inner_structure_field, *complex_structure_field,
826 *a_sequence_field, *enum_variant_field, *enum_container_field,
827 *variant_field, *an_array_field, *ret_field;
828 uint64_t ret_unsigned_int;
829 int64_t ret_signed_int;
830 const char *ret_string;
831 struct bt_ctf_stream_class *ret_stream_class;
832 struct bt_ctf_event_class *ret_event_class;
833 struct bt_ctf_field *packet_context, *packet_context_field;
834 struct bt_value *obj;
835
836 ok(bt_ctf_field_type_set_alignment(int_16_type, 0),
837 "bt_ctf_field_type_set_alignment handles 0-alignment correctly");
838 ok(bt_ctf_field_type_set_alignment(int_16_type, 3),
839 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (3)");
840 ok(bt_ctf_field_type_set_alignment(int_16_type, 24),
841 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (24)");
842 ok(!bt_ctf_field_type_set_alignment(int_16_type, 4),
843 "bt_ctf_field_type_set_alignment handles correct alignment correctly (4)");
844 bt_ctf_field_type_set_alignment(int_16_type, 32);
845 bt_ctf_field_type_integer_set_signed(int_16_type, 1);
846 bt_ctf_field_type_integer_set_base(uint_35_type,
847 BT_CTF_INTEGER_BASE_HEXADECIMAL);
848
849 array_type = bt_ctf_field_type_array_create(int_16_type, ARRAY_TEST_LENGTH);
850 sequence_type = bt_ctf_field_type_sequence_create(int_16_type,
851 "seq_len");
852
853 ok(bt_ctf_field_type_array_get_element_type(NULL) == NULL,
854 "bt_ctf_field_type_array_get_element_type handles NULL correctly");
855 ret_field_type = bt_ctf_field_type_array_get_element_type(
856 array_type);
857 ok(ret_field_type == int_16_type,
858 "bt_ctf_field_type_array_get_element_type returns the correct type");
859 bt_put(ret_field_type);
860
861 ok(bt_ctf_field_type_array_get_length(NULL) < 0,
862 "bt_ctf_field_type_array_get_length handles NULL correctly");
863 ok(bt_ctf_field_type_array_get_length(array_type) == ARRAY_TEST_LENGTH,
864 "bt_ctf_field_type_array_get_length returns the correct length");
865
866 bt_ctf_field_type_structure_add_field(inner_structure_type,
867 uint_35_type, "seq_len");
868 bt_ctf_field_type_structure_add_field(inner_structure_type,
869 sequence_type, "a_sequence");
870 bt_ctf_field_type_structure_add_field(inner_structure_type,
871 array_type, "an_array");
872
873 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type,
874 "UINT3_TYPE", 0, 0);
875 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type,
876 "INT16_TYPE", 1, 1);
877 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type,
878 "UINT35_TYPE", 2, 7);
879
880 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL,
881 "INT16_TYPE") < 0,
882 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly");
883 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
884 enum_variant_type, NULL) < 0,
885 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly");
886 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
887 enum_variant_type, "INT16_TYPE") == 1,
888 "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index");
889
890 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL, 1) < 0,
891 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly");
892 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, -42) < 0,
893 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly");
894 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, 5) == 2,
895 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index");
896
897 ok(bt_ctf_field_type_variant_add_field(variant_type, uint_3_type,
898 "An unknown entry"), "Reject a variant field based on an unknown tag value");
899 ok(bt_ctf_field_type_variant_add_field(variant_type, uint_3_type,
900 "UINT3_TYPE") == 0, "Add a field to a variant");
901 bt_ctf_field_type_variant_add_field(variant_type, int_16_type,
902 "INT16_TYPE");
903 bt_ctf_field_type_variant_add_field(variant_type, uint_35_type,
904 "UINT35_TYPE");
905
906 ok(bt_ctf_field_type_variant_get_tag_type(NULL) == NULL,
907 "bt_ctf_field_type_variant_get_tag_type handles NULL correctly");
908 ret_field_type = bt_ctf_field_type_variant_get_tag_type(variant_type);
909 ok(ret_field_type == enum_variant_type,
910 "bt_ctf_field_type_variant_get_tag_type returns a correct tag type");
911 bt_put(ret_field_type);
912
913 ok(bt_ctf_field_type_variant_get_tag_name(NULL) == NULL,
914 "bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
915 ret_string = bt_ctf_field_type_variant_get_tag_name(variant_type);
916 ok(ret_string ? !strcmp(ret_string, "variant_selector") : 0,
917 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
918 ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL,
919 "INT16_TYPE") == NULL,
920 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
921 ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type,
922 NULL) == NULL,
923 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
924 ret_field_type = bt_ctf_field_type_variant_get_field_type_by_name(
925 variant_type, "INT16_TYPE");
926 ok(ret_field_type == int_16_type,
927 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
928 bt_put(ret_field_type);
929
930 ok(bt_ctf_field_type_variant_get_field_count(NULL) < 0,
931 "bt_ctf_field_type_variant_get_field_count handles NULL correctly");
932 ok(bt_ctf_field_type_variant_get_field_count(variant_type) == 3,
933 "bt_ctf_field_type_variant_get_field_count returns the correct count");
934
935 ok(bt_ctf_field_type_variant_get_field(NULL, &ret_string, &ret_field_type, 0) < 0,
936 "bt_ctf_field_type_variant_get_field handles a NULL type correctly");
937 ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) == 0,
938 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
939 bt_put(ret_field_type);
940 ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) == 0,
941 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
942 ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 200) < 0,
943 "bt_ctf_field_type_variant_get_field handles an invalid index correctly");
944 ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 1) == 0,
945 "bt_ctf_field_type_variant_get_field returns a field");
946 ok(!strcmp("INT16_TYPE", ret_string),
947 "bt_ctf_field_type_variant_get_field returns a correct field name");
948 ok(ret_field_type == int_16_type,
949 "bt_ctf_field_type_variant_get_field returns a correct field type");
950 bt_put(ret_field_type);
951
952 bt_ctf_field_type_structure_add_field(complex_structure_type,
953 enum_variant_type, "variant_selector");
954 bt_ctf_field_type_structure_add_field(complex_structure_type,
955 string_type, "a_string");
956 bt_ctf_field_type_structure_add_field(complex_structure_type,
957 variant_type, "variant_value");
958 bt_ctf_field_type_structure_add_field(complex_structure_type,
959 inner_structure_type, "inner_structure");
960
961 ok(bt_ctf_event_class_create("clock") == NULL,
962 "Reject creation of an event class with an illegal name");
963 event_class = bt_ctf_event_class_create(complex_test_event_string);
964 ok(event_class, "Create an event class");
965 ok(bt_ctf_event_class_add_field(event_class, uint_35_type, ""),
966 "Reject addition of a field with an empty name to an event");
967 ok(bt_ctf_event_class_add_field(event_class, NULL, "an_integer"),
968 "Reject addition of a field with a NULL type to an event");
969 ok(bt_ctf_event_class_add_field(event_class, uint_35_type,
970 "int"),
971 "Reject addition of a type with an illegal name to an event");
972 ok(bt_ctf_event_class_add_field(event_class, uint_35_type,
973 "uint_35") == 0,
974 "Add field of type unsigned integer to an event");
975 ok(bt_ctf_event_class_add_field(event_class, int_16_type,
976 "int_16") == 0, "Add field of type signed integer to an event");
977 ok(bt_ctf_event_class_add_field(event_class, complex_structure_type,
978 "complex_structure") == 0,
979 "Add composite structure to an event");
980
981 ok(bt_ctf_event_class_get_name(NULL) == NULL,
982 "bt_ctf_event_class_get_name handles NULL correctly");
983 ret_string = bt_ctf_event_class_get_name(event_class);
984 ok(!strcmp(ret_string, complex_test_event_string),
985 "bt_ctf_event_class_get_name returns a correct name");
986 ok(bt_ctf_event_class_get_id(event_class) < 0,
987 "bt_ctf_event_class_get_id returns a negative value when not set");
988 ok(bt_ctf_event_class_get_id(NULL) < 0,
989 "bt_ctf_event_class_get_id handles NULL correctly");
990 ok(bt_ctf_event_class_set_id(NULL, 42) < 0,
991 "bt_ctf_event_class_set_id handles NULL correctly");
992 ok(bt_ctf_event_class_set_id(event_class, 42) == 0,
993 "Set an event class' id");
994 ok(bt_ctf_event_class_get_id(event_class) == 42,
995 "bt_ctf_event_class_get_id returns the correct value");
996
997 /* Test event class attributes */
998 obj = bt_value_integer_create_init(15);
999 assert(obj);
1000 ok(bt_ctf_event_class_set_attribute(NULL, "id", obj),
1001 "bt_ctf_event_class_set_attribute handles a NULL event class correctly");
1002 ok(bt_ctf_event_class_set_attribute(event_class, NULL, obj),
1003 "bt_ctf_event_class_set_attribute handles a NULL name correctly");
1004 ok(bt_ctf_event_class_set_attribute(event_class, "id", NULL),
1005 "bt_ctf_event_class_set_attribute handles a NULL value correctly");
1006 assert(!bt_value_integer_set(obj, -3));
1007 ok(bt_ctf_event_class_set_attribute(event_class, "id", obj),
1008 "bt_ctf_event_class_set_attribute fails with a negative \"id\" attribute");
1009 assert(!bt_value_integer_set(obj, 11));
1010 ret = bt_ctf_event_class_set_attribute(event_class, "id", obj);
1011 ok(!ret && bt_ctf_event_class_get_id(event_class) == 11,
1012 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"id\" attribute");
1013 ret = bt_ctf_event_class_set_attribute(event_class, "name", obj);
1014 ret &= bt_ctf_event_class_set_attribute(event_class, "model.emf.uri", obj);
1015 ok(ret,
1016 "bt_ctf_event_class_set_attribute cannot set \"name\" or \"model.emf.uri\" to an integer value");
1017 BT_PUT(obj);
1018
1019 obj = bt_value_integer_create_init(5);
1020 assert(obj);
1021 ok(!bt_ctf_event_class_set_attribute(event_class, "loglevel", obj),
1022 "bt_ctf_event_class_set_attribute succeeds in setting the \"loglevel\" attribute");
1023 BT_PUT(obj);
1024 ok(!bt_ctf_event_class_get_attribute_value_by_name(NULL, "loglevel"),
1025 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL event class correctly");
1026 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class, NULL),
1027 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL name correctly");
1028 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class, "meow"),
1029 "bt_ctf_event_class_get_attribute_value_by_name fails with a non-existing attribute name");
1030 obj = bt_ctf_event_class_get_attribute_value_by_name(event_class,
1031 "loglevel");
1032 int64_value = 0;
1033 ret = bt_value_integer_get(obj, &int64_value);
1034 ok(obj && !ret && int64_value == 5,
1035 "bt_ctf_event_class_get_attribute_value_by_name returns the correct value");
1036 BT_PUT(obj);
1037
1038 obj = bt_value_string_create_init("nu name");
1039 assert(obj);
1040 assert(!bt_ctf_event_class_set_attribute(event_class, "name", obj));
1041 ret_string = bt_ctf_event_class_get_name(event_class);
1042 ok(!strcmp(ret_string, "nu name"),
1043 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"name\" attribute");
1044 ret = bt_ctf_event_class_set_attribute(event_class, "id", obj);
1045 ret &= bt_ctf_event_class_set_attribute(event_class, "loglevel", obj);
1046 ok(ret,
1047 "bt_ctf_event_class_set_attribute cannot set \"id\" or \"loglevel\" to a string value");
1048 BT_PUT(obj);
1049 obj = bt_value_string_create_init("http://kernel.org/");
1050 assert(obj);
1051 assert(!bt_ctf_event_class_set_attribute(event_class, "model.emf.uri", obj));
1052 BT_PUT(obj);
1053
1054 ok(bt_ctf_event_class_get_attribute_count(NULL),
1055 "bt_ctf_event_class_get_attribute_count handles a NULL event class");
1056 ok(bt_ctf_event_class_get_attribute_count(event_class) == 4,
1057 "bt_ctf_event_class_get_attribute_count returns the correct count");
1058 ok(!bt_ctf_event_class_get_attribute_name(NULL, 0),
1059 "bt_ctf_event_class_get_attribute_name handles a NULL event class correctly");
1060 ok(!bt_ctf_event_class_get_attribute_name(event_class, 4),
1061 "bt_ctf_event_class_get_attribute_name handles a too large index correctly");
1062 ok(!bt_ctf_event_class_get_attribute_value(NULL, 0),
1063 "bt_ctf_event_class_get_attribute_value handles a NULL event class correctly");
1064 ok(!bt_ctf_event_class_get_attribute_value(event_class, 4),
1065 "bt_ctf_event_class_get_attribute_value handles a too large index correctly");
1066
1067 memset(&attrs_count, 0, sizeof(attrs_count));
1068
1069 for (i = 0; i < 4; ++i) {
1070 ret_string = bt_ctf_event_class_get_attribute_name(event_class,
1071 i);
1072 obj = bt_ctf_event_class_get_attribute_value(event_class, i);
1073 assert(ret_string && obj);
1074
1075 if (!strcmp(ret_string, "id")) {
1076 attrs_count.id++;
1077 ok(bt_value_is_integer(obj),
1078 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
1079 ret_string);
1080 } else if (!strcmp(ret_string, "name")) {
1081 attrs_count.name++;
1082 ok(bt_value_is_string(obj),
1083 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
1084 ret_string);
1085 } else if (!strcmp(ret_string, "loglevel")) {
1086 attrs_count.loglevel++;
1087 ok(bt_value_is_integer(obj),
1088 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
1089 ret_string);
1090 } else if (!strcmp(ret_string, "model.emf.uri")) {
1091 attrs_count.modelemfuri++;
1092 ok(bt_value_is_string(obj),
1093 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
1094 ret_string);
1095 } else {
1096 attrs_count.unknown++;
1097 }
1098
1099 BT_PUT(obj);
1100 }
1101
1102 ok(attrs_count.unknown == 0, "event class has no unknown attributes");
1103 ok(attrs_count.id == 1 && attrs_count.name == 1 &&
1104 attrs_count.loglevel == 1 && attrs_count.modelemfuri == 1,
1105 "event class has one instance of each known attribute");
1106
1107 /* Add event class to the stream class */
1108 ok(bt_ctf_stream_class_add_event_class(stream_class, NULL),
1109 "Reject addition of NULL event class to a stream class");
1110 ok(bt_ctf_stream_class_add_event_class(stream_class,
1111 event_class) == 0, "Add an event class to stream class");
1112
1113 ok(bt_ctf_event_class_get_stream_class(NULL) == NULL,
1114 "bt_ctf_event_class_get_stream_class handles NULL correctly");
1115 ret_stream_class = bt_ctf_event_class_get_stream_class(event_class);
1116 ok(ret_stream_class == stream_class,
1117 "bt_ctf_event_class_get_stream_class returns the correct stream class");
1118 bt_put(ret_stream_class);
1119
1120 ok(bt_ctf_event_class_get_field_count(NULL) < 0,
1121 "bt_ctf_event_class_get_field_count handles NULL correctly");
1122 ok(bt_ctf_event_class_get_field_count(event_class) == 3,
1123 "bt_ctf_event_class_get_field_count returns a correct value");
1124
1125 ok(bt_ctf_event_class_get_field(NULL, &ret_string,
1126 &ret_field_type, 0) < 0,
1127 "bt_ctf_event_class_get_field handles a NULL event class correctly");
1128 ok(bt_ctf_event_class_get_field(event_class, NULL,
1129 &ret_field_type, 0) == 0,
1130 "bt_ctf_event_class_get_field handles a NULL field name correctly");
1131 bt_put(ret_field_type);
1132 ok(bt_ctf_event_class_get_field(event_class, &ret_string,
1133 NULL, 0) == 0,
1134 "bt_ctf_event_class_get_field handles a NULL field type correctly");
1135 ok(bt_ctf_event_class_get_field(event_class, &ret_string,
1136 &ret_field_type, 42) < 0,
1137 "bt_ctf_event_class_get_field handles an invalid index correctly");
1138 ok(bt_ctf_event_class_get_field(event_class, &ret_string,
1139 &ret_field_type, 0) == 0,
1140 "bt_ctf_event_class_get_field returns a field");
1141 ok(bt_ctf_field_type_compare(ret_field_type, uint_35_type) == 0,
1142 "bt_ctf_event_class_get_field returns a correct field type");
1143 bt_put(ret_field_type);
1144 ok(!strcmp(ret_string, "uint_35"),
1145 "bt_ctf_event_class_get_field returns a correct field name");
1146 ok(bt_ctf_event_class_get_field_by_name(NULL, "") == NULL,
1147 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
1148 ok(bt_ctf_event_class_get_field_by_name(event_class, NULL) == NULL,
1149 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
1150 ok(bt_ctf_event_class_get_field_by_name(event_class, "truie") == NULL,
1151 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
1152 ret_field_type = bt_ctf_event_class_get_field_by_name(event_class,
1153 "complex_structure");
1154 ok(bt_ctf_field_type_compare(ret_field_type, complex_structure_type) == 0,
1155 "bt_ctf_event_class_get_field_by_name returns a correct field type");
1156 bt_put(ret_field_type);
1157
1158 event = bt_ctf_event_create(event_class);
1159 ok(event, "Instanciate a complex event");
1160
1161 ok(bt_ctf_event_get_class(NULL) == NULL,
1162 "bt_ctf_event_get_class handles NULL correctly");
1163 ret_event_class = bt_ctf_event_get_class(event);
1164 ok(ret_event_class == event_class,
1165 "bt_ctf_event_get_class returns the correct event class");
1166 bt_put(ret_event_class);
1167
1168 uint_35_field = bt_ctf_event_get_payload(event, "uint_35");
1169 if (!uint_35_field) {
1170 printf("uint_35_field is NULL\n");
1171 }
1172
1173 ok(uint_35_field, "Use bt_ctf_event_get_payload to get a field instance ");
1174 bt_ctf_field_unsigned_integer_set_value(uint_35_field, 0x0DDF00D);
1175 ok(bt_ctf_field_unsigned_integer_get_value(NULL, &ret_unsigned_int) < 0,
1176 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
1177 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field, NULL) < 0,
1178 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
1179 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field,
1180 &ret_unsigned_int) == 0,
1181 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
1182 ok(ret_unsigned_int == 0x0DDF00D,
1183 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
1184 ok(bt_ctf_field_signed_integer_get_value(uint_35_field,
1185 &ret_signed_int) < 0,
1186 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
1187 bt_put(uint_35_field);
1188
1189 int_16_field = bt_ctf_event_get_payload(event, "int_16");
1190 bt_ctf_field_signed_integer_set_value(int_16_field, -12345);
1191 ok(bt_ctf_field_signed_integer_get_value(NULL, &ret_signed_int) < 0,
1192 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
1193 ok(bt_ctf_field_signed_integer_get_value(int_16_field, NULL) < 0,
1194 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
1195 ok(bt_ctf_field_signed_integer_get_value(int_16_field,
1196 &ret_signed_int) == 0,
1197 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
1198 ok(ret_signed_int == -12345,
1199 "bt_ctf_field_signed_integer_get_value returns the correct value");
1200 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field,
1201 &ret_unsigned_int) < 0,
1202 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
1203 bt_put(int_16_field);
1204
1205 complex_structure_field = bt_ctf_event_get_payload(event,
1206 "complex_structure");
1207
1208 ok(bt_ctf_field_structure_get_field_by_index(NULL, 0) == NULL,
1209 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
1210 ok(bt_ctf_field_structure_get_field_by_index(NULL, 9) == NULL,
1211 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
1212 inner_structure_field = bt_ctf_field_structure_get_field_by_index(
1213 complex_structure_field, 3);
1214 ret_field_type = bt_ctf_field_get_type(inner_structure_field);
1215 bt_put(inner_structure_field);
1216 ok(bt_ctf_field_type_compare(ret_field_type, inner_structure_type) == 0,
1217 "bt_ctf_field_structure_get_field_by_index returns a correct field");
1218 bt_put(ret_field_type);
1219
1220 inner_structure_field = bt_ctf_field_structure_get_field(
1221 complex_structure_field, "inner_structure");
1222 a_string_field = bt_ctf_field_structure_get_field(
1223 complex_structure_field, "a_string");
1224 enum_variant_field = bt_ctf_field_structure_get_field(
1225 complex_structure_field, "variant_selector");
1226 variant_field = bt_ctf_field_structure_get_field(
1227 complex_structure_field, "variant_value");
1228 uint_35_field = bt_ctf_field_structure_get_field(
1229 inner_structure_field, "seq_len");
1230 a_sequence_field = bt_ctf_field_structure_get_field(
1231 inner_structure_field, "a_sequence");
1232 an_array_field = bt_ctf_field_structure_get_field(
1233 inner_structure_field, "an_array");
1234
1235 enum_container_field = bt_ctf_field_enumeration_get_container(
1236 enum_variant_field);
1237 bt_ctf_field_unsigned_integer_set_value(enum_container_field, 1);
1238 int_16_field = bt_ctf_field_variant_get_field(variant_field,
1239 enum_variant_field);
1240 bt_ctf_field_signed_integer_set_value(int_16_field, -200);
1241 bt_put(int_16_field);
1242 ok(!bt_ctf_field_string_get_value(a_string_field),
1243 "bt_ctf_field_string_get_value returns NULL on an unset field");
1244 bt_ctf_field_string_set_value(a_string_field,
1245 test_string_1);
1246 ok(!bt_ctf_field_string_get_value(NULL),
1247 "bt_ctf_field_string_get_value correctly handles NULL");
1248 ok(bt_ctf_field_string_append(NULL, "yeah"),
1249 "bt_ctf_field_string_append correctly handles a NULL string field");
1250 ok(bt_ctf_field_string_append(a_string_field, NULL),
1251 "bt_ctf_field_string_append correctly handles a NULL string value");
1252 ok(!bt_ctf_field_string_append(a_string_field, test_string_2),
1253 "bt_ctf_field_string_append succeeds");
1254 ok(bt_ctf_field_string_append_len(NULL, "oh noes", 3),
1255 "bt_ctf_field_string_append_len correctly handles a NULL string field");
1256 ok(bt_ctf_field_string_append_len(a_string_field, NULL, 3),
1257 "bt_ctf_field_string_append_len correctly handles a NULL string value");
1258 ok(!bt_ctf_field_string_append_len(a_string_field, test_string_3, 5),
1259 "bt_ctf_field_string_append_len succeeds (append 5 characters)");
1260 ok(!bt_ctf_field_string_append_len(a_string_field, test_string_4, 10),
1261 "bt_ctf_field_string_append_len succeeds (append 4 characters)");
1262 ok(!bt_ctf_field_string_append_len(a_string_field, &test_string_4[4], 3),
1263 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
1264 ok(!bt_ctf_field_string_append_len(a_string_field, test_string_3, 0),
1265 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
1266
1267 ret_string = bt_ctf_field_string_get_value(a_string_field);
1268 ok(ret_string, "bt_ctf_field_string_get_value returns a string");
1269 ok(ret_string ? !strcmp(ret_string, test_string_cat) : 0,
1270 "bt_ctf_field_string_get_value returns a correct value");
1271 bt_ctf_field_unsigned_integer_set_value(uint_35_field,
1272 SEQUENCE_TEST_LENGTH);
1273
1274 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL,
1275 enum_container_field) == NULL,
1276 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
1277 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type,
1278 NULL) == NULL,
1279 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
1280 ret_field_type = bt_ctf_field_type_variant_get_field_type_from_tag(
1281 variant_type, enum_variant_field);
1282 ok(ret_field_type == int_16_type,
1283 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
1284
1285 ok(bt_ctf_field_sequence_get_length(a_sequence_field) == NULL,
1286 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
1287 ok(bt_ctf_field_sequence_set_length(a_sequence_field,
1288 uint_35_field) == 0, "Set a sequence field's length");
1289 ret_field = bt_ctf_field_sequence_get_length(a_sequence_field);
1290 ok(ret_field == uint_35_field,
1291 "bt_ctf_field_sequence_get_length returns the correct length field");
1292 ok(bt_ctf_field_sequence_get_length(NULL) == NULL,
1293 "bt_ctf_field_sequence_get_length properly handles NULL");
1294
1295 for (i = 0; i < SEQUENCE_TEST_LENGTH; i++) {
1296 int_16_field = bt_ctf_field_sequence_get_field(
1297 a_sequence_field, i);
1298 bt_ctf_field_signed_integer_set_value(int_16_field, 4 - i);
1299 bt_put(int_16_field);
1300 }
1301
1302 for (i = 0; i < ARRAY_TEST_LENGTH; i++) {
1303 int_16_field = bt_ctf_field_array_get_field(
1304 an_array_field, i);
1305 bt_ctf_field_signed_integer_set_value(int_16_field, i);
1306 bt_put(int_16_field);
1307 }
1308
1309 bt_ctf_clock_set_time(clock, ++current_time);
1310 ok(bt_ctf_stream_append_event(stream, event) == 0,
1311 "Append a complex event to a stream");
1312
1313 /*
1314 * Populate the custom packet context field with a dummy value
1315 * otherwise flush will fail.
1316 */
1317 packet_context = bt_ctf_stream_get_packet_context(stream);
1318 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
1319 "custom_packet_context_field");
1320 bt_ctf_field_unsigned_integer_set_value(packet_context_field, 1);
1321
1322 ok(bt_ctf_stream_flush(stream) == 0,
1323 "Flush a stream containing a complex event");
1324
1325 bt_put(uint_35_field);
1326 bt_put(a_string_field);
1327 bt_put(inner_structure_field);
1328 bt_put(complex_structure_field);
1329 bt_put(a_sequence_field);
1330 bt_put(an_array_field);
1331 bt_put(enum_variant_field);
1332 bt_put(enum_container_field);
1333 bt_put(variant_field);
1334 bt_put(ret_field);
1335 bt_put(packet_context_field);
1336 bt_put(packet_context);
1337 bt_put(uint_35_type);
1338 bt_put(int_16_type);
1339 bt_put(string_type);
1340 bt_put(sequence_type);
1341 bt_put(array_type);
1342 bt_put(inner_structure_type);
1343 bt_put(complex_structure_type);
1344 bt_put(uint_3_type);
1345 bt_put(enum_variant_type);
1346 bt_put(variant_type);
1347 bt_put(ret_field_type);
1348 bt_put(event_class);
1349 bt_put(event);
1350 }
1351
1352 static void field_copy_tests_validate_same_type(struct bt_ctf_field *field,
1353 struct bt_ctf_field_type *expected_type, const char *name)
1354 {
1355 struct bt_ctf_field_type *copy_type;
1356
1357 copy_type = bt_ctf_field_get_type(field);
1358 ok(copy_type == expected_type,
1359 "bt_ctf_field_copy does not copy the type (%s)", name);
1360 bt_put(copy_type);
1361 }
1362
1363 static void field_copy_tests_validate_diff_ptrs(struct bt_ctf_field *field_a,
1364 struct bt_ctf_field *field_b, const char *name)
1365 {
1366 ok(field_a != field_b,
1367 "bt_ctf_field_copy creates different pointers (%s)", name);
1368 }
1369
1370 void field_copy_tests()
1371 {
1372 struct bt_ctf_field_type *len_type = NULL;
1373 struct bt_ctf_field_type *fp_type = NULL;
1374 struct bt_ctf_field_type *s_type = NULL;
1375 struct bt_ctf_field_type *e_int_type = NULL;
1376 struct bt_ctf_field_type *e_type = NULL;
1377 struct bt_ctf_field_type *v_type = NULL;
1378 struct bt_ctf_field_type *v_label1_type = NULL;
1379 struct bt_ctf_field_type *v_label1_array_type = NULL;
1380 struct bt_ctf_field_type *v_label2_type = NULL;
1381 struct bt_ctf_field_type *v_label2_seq_type = NULL;
1382 struct bt_ctf_field_type *strct_type = NULL;
1383 struct bt_ctf_field *len = NULL;
1384 struct bt_ctf_field *fp = NULL;
1385 struct bt_ctf_field *s = NULL;
1386 struct bt_ctf_field *e_int = NULL;
1387 struct bt_ctf_field *e = NULL;
1388 struct bt_ctf_field *v = NULL;
1389 struct bt_ctf_field *v_selected = NULL;
1390 struct bt_ctf_field *v_selected_cur = NULL;
1391 struct bt_ctf_field *v_selected_0 = NULL;
1392 struct bt_ctf_field *v_selected_1 = NULL;
1393 struct bt_ctf_field *v_selected_2 = NULL;
1394 struct bt_ctf_field *v_selected_3 = NULL;
1395 struct bt_ctf_field *v_selected_4 = NULL;
1396 struct bt_ctf_field *v_selected_5 = NULL;
1397 struct bt_ctf_field *v_selected_6 = NULL;
1398 struct bt_ctf_field *a = NULL;
1399 struct bt_ctf_field *a_0 = NULL;
1400 struct bt_ctf_field *a_1 = NULL;
1401 struct bt_ctf_field *a_2 = NULL;
1402 struct bt_ctf_field *a_3 = NULL;
1403 struct bt_ctf_field *a_4 = NULL;
1404 struct bt_ctf_field *strct = NULL;
1405 struct bt_ctf_field *len_copy = NULL;
1406 struct bt_ctf_field *fp_copy = NULL;
1407 struct bt_ctf_field *s_copy = NULL;
1408 struct bt_ctf_field *e_int_copy = NULL;
1409 struct bt_ctf_field *e_copy = NULL;
1410 struct bt_ctf_field *v_copy = NULL;
1411 struct bt_ctf_field *v_selected_copy = NULL;
1412 struct bt_ctf_field *v_selected_copy_len = NULL;
1413 struct bt_ctf_field *v_selected_0_copy = NULL;
1414 struct bt_ctf_field *v_selected_1_copy = NULL;
1415 struct bt_ctf_field *v_selected_2_copy = NULL;
1416 struct bt_ctf_field *v_selected_3_copy = NULL;
1417 struct bt_ctf_field *v_selected_4_copy = NULL;
1418 struct bt_ctf_field *v_selected_5_copy = NULL;
1419 struct bt_ctf_field *v_selected_6_copy = NULL;
1420 struct bt_ctf_field *a_copy = NULL;
1421 struct bt_ctf_field *a_0_copy = NULL;
1422 struct bt_ctf_field *a_1_copy = NULL;
1423 struct bt_ctf_field *a_2_copy = NULL;
1424 struct bt_ctf_field *a_3_copy = NULL;
1425 struct bt_ctf_field *a_4_copy = NULL;
1426 struct bt_ctf_field *strct_copy = NULL;
1427 uint64_t uint64_t_val;
1428 const char *str_val;
1429 double double_val;
1430 int ret;
1431
1432 /* create len type */
1433 len_type = bt_ctf_field_type_integer_create(32);
1434 assert(len_type);
1435
1436 /* create fp type */
1437 fp_type = bt_ctf_field_type_floating_point_create();
1438 assert(fp_type);
1439
1440 /* create s type */
1441 s_type = bt_ctf_field_type_string_create();
1442 assert(s_type);
1443
1444 /* create e_int type */
1445 e_int_type = bt_ctf_field_type_integer_create(8);
1446 assert(e_int_type);
1447
1448 /* create e type */
1449 e_type = bt_ctf_field_type_enumeration_create(e_int_type);
1450 assert(e_type);
1451 ret = bt_ctf_field_type_enumeration_add_mapping(e_type, "LABEL1",
1452 10, 15);
1453 assert(!ret);
1454 ret = bt_ctf_field_type_enumeration_add_mapping(e_type, "LABEL2",
1455 23, 23);
1456 assert(!ret);
1457
1458 /* create v_label1 type */
1459 v_label1_type = bt_ctf_field_type_string_create();
1460 assert(v_label1_type);
1461
1462 /* create v_label1_array type */
1463 v_label1_array_type = bt_ctf_field_type_array_create(v_label1_type, 5);
1464 assert(v_label1_array_type);
1465
1466 /* create v_label2 type */
1467 v_label2_type = bt_ctf_field_type_integer_create(16);
1468 assert(v_label2_type);
1469
1470 /* create v_label2_seq type */
1471 v_label2_seq_type = bt_ctf_field_type_sequence_create(v_label2_type,
1472 "len");
1473 assert(v_label2_seq_type);
1474
1475 /* create v type */
1476 v_type = bt_ctf_field_type_variant_create(e_type, "e");
1477 assert(v_type);
1478 ret = bt_ctf_field_type_variant_add_field(v_type, v_label1_array_type,
1479 "LABEL1");
1480 assert(!ret);
1481 ret = bt_ctf_field_type_variant_add_field(v_type, v_label2_seq_type,
1482 "LABEL2");
1483 assert(!ret);
1484
1485 /* create strct type */
1486 strct_type = bt_ctf_field_type_structure_create();
1487 assert(strct_type);
1488 ret = bt_ctf_field_type_structure_add_field(strct_type, len_type,
1489 "len");
1490 assert(!ret);
1491 ret = bt_ctf_field_type_structure_add_field(strct_type, fp_type, "fp");
1492 assert(!ret);
1493 ret = bt_ctf_field_type_structure_add_field(strct_type, s_type, "s");
1494 assert(!ret);
1495 ret = bt_ctf_field_type_structure_add_field(strct_type, e_type, "e");
1496 assert(!ret);
1497 ret = bt_ctf_field_type_structure_add_field(strct_type, v_type, "v");
1498 assert(!ret);
1499 ret = bt_ctf_field_type_structure_add_field(strct_type,
1500 v_label1_array_type, "a");
1501 assert(!ret);
1502
1503 /* create strct */
1504 strct = bt_ctf_field_create(strct_type);
1505 assert(strct);
1506
1507 /* get len field */
1508 len = bt_ctf_field_structure_get_field(strct, "len");
1509 assert(len);
1510
1511 /* get fp field */
1512 fp = bt_ctf_field_structure_get_field(strct, "fp");
1513 assert(fp);
1514
1515 /* get s field */
1516 s = bt_ctf_field_structure_get_field(strct, "s");
1517 assert(s);
1518
1519 /* get e field */
1520 e = bt_ctf_field_structure_get_field(strct, "e");
1521 assert(e);
1522
1523 /* get e_int (underlying integer) */
1524 e_int = bt_ctf_field_enumeration_get_container(e);
1525 assert(e_int);
1526
1527 /* get v field */
1528 v = bt_ctf_field_structure_get_field(strct, "v");
1529 assert(v);
1530
1531 /* get a field */
1532 a = bt_ctf_field_structure_get_field(strct, "a");
1533 assert(a);
1534
1535 /* set len field */
1536 ret = bt_ctf_field_unsigned_integer_set_value(len, 7);
1537 assert(!ret);
1538
1539 /* set fp field */
1540 ret = bt_ctf_field_floating_point_set_value(fp, 3.14);
1541 assert(!ret);
1542
1543 /* set s field */
1544 ret = bt_ctf_field_string_set_value(s, "btbt");
1545 assert(!ret);
1546
1547 /* set e field (LABEL2) */
1548 ret = bt_ctf_field_unsigned_integer_set_value(e_int, 23);
1549 assert(!ret);
1550
1551 /* set v field */
1552 v_selected = bt_ctf_field_variant_get_field(v, e);
1553 assert(v_selected);
1554 ok(!bt_ctf_field_variant_get_current_field(NULL),
1555 "bt_ctf_field_variant_get_current_field handles NULL correctly");
1556 v_selected_cur = bt_ctf_field_variant_get_current_field(v);
1557 ok(v_selected_cur == v_selected,
1558 "bt_ctf_field_variant_get_current_field returns the current field");
1559 bt_put(v_selected_cur);
1560
1561 /* set selected v field */
1562 ret = bt_ctf_field_sequence_set_length(v_selected, len);
1563 assert(!ret);
1564 v_selected_0 = bt_ctf_field_sequence_get_field(v_selected, 0);
1565 assert(v_selected_0);
1566 ret = bt_ctf_field_unsigned_integer_set_value(v_selected_0, 7);
1567 assert(!ret);
1568 v_selected_1 = bt_ctf_field_sequence_get_field(v_selected, 1);
1569 assert(v_selected_1);
1570 ret = bt_ctf_field_unsigned_integer_set_value(v_selected_1, 6);
1571 assert(!ret);
1572 v_selected_2 = bt_ctf_field_sequence_get_field(v_selected, 2);
1573 assert(v_selected_2);
1574 ret = bt_ctf_field_unsigned_integer_set_value(v_selected_2, 5);
1575 assert(!ret);
1576 v_selected_3 = bt_ctf_field_sequence_get_field(v_selected, 3);
1577 assert(v_selected_3);
1578 ret = bt_ctf_field_unsigned_integer_set_value(v_selected_3, 4);
1579 assert(!ret);
1580 v_selected_4 = bt_ctf_field_sequence_get_field(v_selected, 4);
1581 assert(v_selected_4);
1582 ret = bt_ctf_field_unsigned_integer_set_value(v_selected_4, 3);
1583 assert(!ret);
1584 v_selected_5 = bt_ctf_field_sequence_get_field(v_selected, 5);
1585 assert(v_selected_5);
1586 ret = bt_ctf_field_unsigned_integer_set_value(v_selected_5, 2);
1587 assert(!ret);
1588 v_selected_6 = bt_ctf_field_sequence_get_field(v_selected, 6);
1589 assert(v_selected_6);
1590 ret = bt_ctf_field_unsigned_integer_set_value(v_selected_6, 1);
1591 assert(!ret);
1592
1593 /* set a field */
1594 a_0 = bt_ctf_field_array_get_field(a, 0);
1595 assert(a_0);
1596 ret = bt_ctf_field_string_set_value(a_0, "a_0");
1597 assert(!ret);
1598 a_1 = bt_ctf_field_array_get_field(a, 1);
1599 assert(a_1);
1600 ret = bt_ctf_field_string_set_value(a_1, "a_1");
1601 assert(!ret);
1602 a_2 = bt_ctf_field_array_get_field(a, 2);
1603 assert(a_2);
1604 ret = bt_ctf_field_string_set_value(a_2, "a_2");
1605 assert(!ret);
1606 a_3 = bt_ctf_field_array_get_field(a, 3);
1607 assert(a_3);
1608 ret = bt_ctf_field_string_set_value(a_3, "a_3");
1609 assert(!ret);
1610 a_4 = bt_ctf_field_array_get_field(a, 4);
1611 assert(a_4);
1612 ret = bt_ctf_field_string_set_value(a_4, "a_4");
1613 assert(!ret);
1614
1615 /* create copy of strct */
1616 ok(!bt_ctf_field_copy(NULL),
1617 "bt_ctf_field_copy handles NULL correctly");
1618 strct_copy = bt_ctf_field_copy(strct);
1619 ok(strct_copy,
1620 "bt_ctf_field_copy returns a valid pointer");
1621
1622 /* get all copied fields */
1623 len_copy = bt_ctf_field_structure_get_field(strct_copy, "len");
1624 assert(len_copy);
1625 fp_copy = bt_ctf_field_structure_get_field(strct_copy, "fp");
1626 assert(fp_copy);
1627 s_copy = bt_ctf_field_structure_get_field(strct_copy, "s");
1628 assert(s_copy);
1629 e_copy = bt_ctf_field_structure_get_field(strct_copy, "e");
1630 assert(e_copy);
1631 e_int_copy = bt_ctf_field_enumeration_get_container(e_copy);
1632 assert(e_int_copy);
1633 v_copy = bt_ctf_field_structure_get_field(strct_copy, "v");
1634 assert(v_copy);
1635 v_selected_copy = bt_ctf_field_variant_get_field(v_copy, e_copy);
1636 assert(v_selected_copy);
1637 v_selected_0_copy = bt_ctf_field_sequence_get_field(v_selected_copy, 0);
1638 assert(v_selected_0_copy);
1639 v_selected_1_copy = bt_ctf_field_sequence_get_field(v_selected_copy, 1);
1640 assert(v_selected_1_copy);
1641 v_selected_2_copy = bt_ctf_field_sequence_get_field(v_selected_copy, 2);
1642 assert(v_selected_2_copy);
1643 v_selected_3_copy = bt_ctf_field_sequence_get_field(v_selected_copy, 3);
1644 assert(v_selected_3_copy);
1645 v_selected_4_copy = bt_ctf_field_sequence_get_field(v_selected_copy, 4);
1646 assert(v_selected_4_copy);
1647 v_selected_5_copy = bt_ctf_field_sequence_get_field(v_selected_copy, 5);
1648 assert(v_selected_5_copy);
1649 v_selected_6_copy = bt_ctf_field_sequence_get_field(v_selected_copy, 6);
1650 assert(v_selected_6_copy);
1651 ok(!bt_ctf_field_sequence_get_field(v_selected_copy, 7),
1652 "sequence field copy is not too large");
1653 a_copy = bt_ctf_field_structure_get_field(strct_copy, "a");
1654 assert(a_copy);
1655 a_0_copy = bt_ctf_field_array_get_field(a_copy, 0);
1656 assert(a_0_copy);
1657 a_1_copy = bt_ctf_field_array_get_field(a_copy, 1);
1658 assert(a_1_copy);
1659 a_2_copy = bt_ctf_field_array_get_field(a_copy, 2);
1660 assert(a_2_copy);
1661 a_3_copy = bt_ctf_field_array_get_field(a_copy, 3);
1662 assert(a_3_copy);
1663 a_4_copy = bt_ctf_field_array_get_field(a_copy, 4);
1664 assert(a_4_copy);
1665 ok(!bt_ctf_field_array_get_field(v_selected_copy, 5),
1666 "array field copy is not too large");
1667
1668 /* make sure copied fields are different pointers */
1669 field_copy_tests_validate_diff_ptrs(strct_copy, strct, "strct");
1670 field_copy_tests_validate_diff_ptrs(len_copy, len, "len");
1671 field_copy_tests_validate_diff_ptrs(fp_copy, fp, "fp");
1672 field_copy_tests_validate_diff_ptrs(s_copy, s, "s");
1673 field_copy_tests_validate_diff_ptrs(e_int_copy, e_int, "e_int");
1674 field_copy_tests_validate_diff_ptrs(e_copy, e, "e");
1675 field_copy_tests_validate_diff_ptrs(v_copy, v, "v");
1676 field_copy_tests_validate_diff_ptrs(v_selected_copy, v_selected,
1677 "v_selected");
1678 field_copy_tests_validate_diff_ptrs(v_selected_0_copy, v_selected_0,
1679 "v_selected_0");
1680 field_copy_tests_validate_diff_ptrs(v_selected_1_copy, v_selected_1,
1681 "v_selected_1");
1682 field_copy_tests_validate_diff_ptrs(v_selected_2_copy, v_selected_2,
1683 "v_selected_2");
1684 field_copy_tests_validate_diff_ptrs(v_selected_3_copy, v_selected_3,
1685 "v_selected_3");
1686 field_copy_tests_validate_diff_ptrs(v_selected_4_copy, v_selected_4,
1687 "v_selected_4");
1688 field_copy_tests_validate_diff_ptrs(v_selected_5_copy, v_selected_5,
1689 "v_selected_5");
1690 field_copy_tests_validate_diff_ptrs(v_selected_6_copy, v_selected_6,
1691 "v_selected_6");
1692 field_copy_tests_validate_diff_ptrs(a_copy, a, "a");
1693 field_copy_tests_validate_diff_ptrs(a_0_copy, a_0, "a_0");
1694 field_copy_tests_validate_diff_ptrs(a_1_copy, a_1, "a_1");
1695 field_copy_tests_validate_diff_ptrs(a_2_copy, a_2, "a_2");
1696 field_copy_tests_validate_diff_ptrs(a_3_copy, a_3, "a_3");
1697 field_copy_tests_validate_diff_ptrs(a_4_copy, a_4, "a_4");
1698
1699 /* make sure copied fields share the same types */
1700 field_copy_tests_validate_same_type(strct_copy, strct_type, "strct");
1701 field_copy_tests_validate_same_type(len_copy, len_type, "len");
1702 field_copy_tests_validate_same_type(fp_copy, fp_type, "fp");
1703 field_copy_tests_validate_same_type(e_int_copy, e_int_type, "e_int");
1704 field_copy_tests_validate_same_type(e_copy, e_type, "e");
1705 field_copy_tests_validate_same_type(v_copy, v_type, "v");
1706 field_copy_tests_validate_same_type(v_selected_copy, v_label2_seq_type,
1707 "v_selected");
1708 field_copy_tests_validate_same_type(v_selected_0_copy, v_label2_type,
1709 "v_selected_0");
1710 field_copy_tests_validate_same_type(v_selected_1_copy, v_label2_type,
1711 "v_selected_1");
1712 field_copy_tests_validate_same_type(v_selected_2_copy, v_label2_type,
1713 "v_selected_2");
1714 field_copy_tests_validate_same_type(v_selected_3_copy, v_label2_type,
1715 "v_selected_3");
1716 field_copy_tests_validate_same_type(v_selected_4_copy, v_label2_type,
1717 "v_selected_4");
1718 field_copy_tests_validate_same_type(v_selected_5_copy, v_label2_type,
1719 "v_selected_5");
1720 field_copy_tests_validate_same_type(v_selected_6_copy, v_label2_type,
1721 "v_selected_6");
1722 field_copy_tests_validate_same_type(a_copy, v_label1_array_type, "a");
1723 field_copy_tests_validate_same_type(a_0_copy, v_label1_type, "a_0");
1724 field_copy_tests_validate_same_type(a_1_copy, v_label1_type, "a_1");
1725 field_copy_tests_validate_same_type(a_2_copy, v_label1_type, "a_2");
1726 field_copy_tests_validate_same_type(a_3_copy, v_label1_type, "a_3");
1727 field_copy_tests_validate_same_type(a_4_copy, v_label1_type, "a_4");
1728
1729 /* validate len copy */
1730 ret = bt_ctf_field_unsigned_integer_get_value(len_copy, &uint64_t_val);
1731 assert(!ret);
1732 ok(uint64_t_val == 7,
1733 "bt_ctf_field_copy creates a valid integer field copy");
1734
1735 /* validate fp copy */
1736 ret = bt_ctf_field_floating_point_get_value(fp_copy, &double_val);
1737 assert(!ret);
1738 ok(double_val == 3.14,
1739 "bt_ctf_field_copy creates a valid floating point number field copy");
1740
1741 /* validate s copy */
1742 str_val = bt_ctf_field_string_get_value(s_copy);
1743 ok(str_val && !strcmp(str_val, "btbt"),
1744 "bt_ctf_field_copy creates a valid string field copy");
1745
1746 /* validate e_int copy */
1747 ret = bt_ctf_field_unsigned_integer_get_value(e_int_copy,
1748 &uint64_t_val);
1749 assert(!ret);
1750 ok(uint64_t_val == 23,
1751 "bt_ctf_field_copy creates a valid enum's integer field copy");
1752
1753 /* validate e copy */
1754 str_val = bt_ctf_field_enumeration_get_mapping_name(e_copy);
1755 ok(str_val && !strcmp(str_val, "LABEL2"),
1756 "bt_ctf_field_copy creates a valid enum field copy");
1757
1758 /* validate v_selected copy */
1759 v_selected_copy_len = bt_ctf_field_sequence_get_length(v_selected);
1760 assert(v_selected_copy_len);
1761 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_copy_len,
1762 &uint64_t_val);
1763 assert(!ret);
1764 ok(uint64_t_val == 7,
1765 "bt_ctf_field_copy creates a sequence field copy with the proper length");
1766 bt_put(v_selected_copy_len);
1767 v_selected_copy_len = NULL;
1768
1769 /* validate v_selected copy fields */
1770 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_0_copy,
1771 &uint64_t_val);
1772 assert(!ret);
1773 ok(uint64_t_val == 7,
1774 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_0)");
1775 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_1_copy,
1776 &uint64_t_val);
1777 assert(!ret);
1778 ok(uint64_t_val == 6,
1779 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_1)");
1780 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_2_copy,
1781 &uint64_t_val);
1782 assert(!ret);
1783 ok(uint64_t_val == 5,
1784 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_2)");
1785 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_3_copy,
1786 &uint64_t_val);
1787 assert(!ret);
1788 ok(uint64_t_val == 4,
1789 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_3)");
1790 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_4_copy,
1791 &uint64_t_val);
1792 assert(!ret);
1793 ok(uint64_t_val == 3,
1794 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_4)");
1795 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_5_copy,
1796 &uint64_t_val);
1797 assert(!ret);
1798 ok(uint64_t_val == 2,
1799 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_5)");
1800 ret = bt_ctf_field_unsigned_integer_get_value(v_selected_6_copy,
1801 &uint64_t_val);
1802 assert(!ret);
1803 ok(uint64_t_val == 1,
1804 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_6)");
1805
1806 /* validate a copy fields */
1807 str_val = bt_ctf_field_string_get_value(a_0_copy);
1808 ok(str_val && !strcmp(str_val, "a_0"),
1809 "bt_ctf_field_copy creates a valid array field element copy (a_0)");
1810 str_val = bt_ctf_field_string_get_value(a_1_copy);
1811 ok(str_val && !strcmp(str_val, "a_1"),
1812 "bt_ctf_field_copy creates a valid array field element copy (a_1)");
1813 str_val = bt_ctf_field_string_get_value(a_2_copy);
1814 ok(str_val && !strcmp(str_val, "a_2"),
1815 "bt_ctf_field_copy creates a valid array field element copy (a_2)");
1816 str_val = bt_ctf_field_string_get_value(a_3_copy);
1817 ok(str_val && !strcmp(str_val, "a_3"),
1818 "bt_ctf_field_copy creates a valid array field element copy (a_3)");
1819 str_val = bt_ctf_field_string_get_value(a_4_copy);
1820 ok(str_val && !strcmp(str_val, "a_4"),
1821 "bt_ctf_field_copy creates a valid array field element copy (a_4)");
1822
1823 /* put everything */
1824 bt_put(len_type);
1825 bt_put(fp_type);
1826 bt_put(s_type);
1827 bt_put(e_int_type);
1828 bt_put(e_type);
1829 bt_put(v_type);
1830 bt_put(v_label1_type);
1831 bt_put(v_label1_array_type);
1832 bt_put(v_label2_type);
1833 bt_put(v_label2_seq_type);
1834 bt_put(strct_type);
1835 bt_put(len);
1836 bt_put(fp);
1837 bt_put(s);
1838 bt_put(e_int);
1839 bt_put(e);
1840 bt_put(v);
1841 bt_put(v_selected);
1842 bt_put(v_selected_0);
1843 bt_put(v_selected_1);
1844 bt_put(v_selected_2);
1845 bt_put(v_selected_3);
1846 bt_put(v_selected_4);
1847 bt_put(v_selected_5);
1848 bt_put(v_selected_6);
1849 bt_put(a);
1850 bt_put(a_0);
1851 bt_put(a_1);
1852 bt_put(a_2);
1853 bt_put(a_3);
1854 bt_put(a_4);
1855 bt_put(strct);
1856 bt_put(len_copy);
1857 bt_put(fp_copy);
1858 bt_put(s_copy);
1859 bt_put(e_int_copy);
1860 bt_put(e_copy);
1861 bt_put(v_copy);
1862 bt_put(v_selected_copy);
1863 bt_put(v_selected_0_copy);
1864 bt_put(v_selected_1_copy);
1865 bt_put(v_selected_2_copy);
1866 bt_put(v_selected_3_copy);
1867 bt_put(v_selected_4_copy);
1868 bt_put(v_selected_5_copy);
1869 bt_put(v_selected_6_copy);
1870 bt_put(a_copy);
1871 bt_put(a_0_copy);
1872 bt_put(a_1_copy);
1873 bt_put(a_2_copy);
1874 bt_put(a_3_copy);
1875 bt_put(a_4_copy);
1876 bt_put(strct_copy);
1877 }
1878
1879 void type_field_tests()
1880 {
1881 struct bt_ctf_field *uint_12;
1882 struct bt_ctf_field *int_16;
1883 struct bt_ctf_field *string;
1884 struct bt_ctf_field *enumeration;
1885 struct bt_ctf_field_type *composite_structure_type;
1886 struct bt_ctf_field_type *structure_seq_type;
1887 struct bt_ctf_field_type *string_type;
1888 struct bt_ctf_field_type *sequence_type;
1889 struct bt_ctf_field_type *uint_8_type;
1890 struct bt_ctf_field_type *int_16_type;
1891 struct bt_ctf_field_type *uint_12_type =
1892 bt_ctf_field_type_integer_create(12);
1893 struct bt_ctf_field_type *enumeration_type;
1894 struct bt_ctf_field_type *returned_type;
1895 const char *ret_string;
1896
1897 returned_type = bt_ctf_field_get_type(NULL);
1898 ok(!returned_type, "bt_ctf_field_get_type handles NULL correctly");
1899
1900 ok(uint_12_type, "Create an unsigned integer type");
1901 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1902 BT_CTF_INTEGER_BASE_BINARY) == 0,
1903 "Set integer type's base as binary");
1904 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1905 BT_CTF_INTEGER_BASE_DECIMAL) == 0,
1906 "Set integer type's base as decimal");
1907 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1908 BT_CTF_INTEGER_BASE_UNKNOWN),
1909 "Reject integer type's base set as unknown");
1910 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1911 BT_CTF_INTEGER_BASE_OCTAL) == 0,
1912 "Set integer type's base as octal");
1913 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1914 BT_CTF_INTEGER_BASE_HEXADECIMAL) == 0,
1915 "Set integer type's base as hexadecimal");
1916 ok(bt_ctf_field_type_integer_set_base(uint_12_type, 457417),
1917 "Reject unknown integer base value");
1918 ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 952835) == 0,
1919 "Set integer type signedness to signed");
1920 ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0) == 0,
1921 "Set integer type signedness to unsigned");
1922 ok(bt_ctf_field_type_integer_get_size(NULL) < 0,
1923 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1924 ok(bt_ctf_field_type_integer_get_size(uint_12_type) == 12,
1925 "bt_ctf_field_type_integer_get_size returns a correct value");
1926 ok(bt_ctf_field_type_integer_get_signed(NULL) < 0,
1927 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1928 ok(bt_ctf_field_type_integer_get_signed(uint_12_type) == 0,
1929 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1930
1931 ok(bt_ctf_field_type_set_byte_order(NULL,
1932 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN) < 0,
1933 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1934 ok(bt_ctf_field_type_set_byte_order(uint_12_type,
1935 (enum bt_ctf_byte_order) 42) < 0,
1936 "bt_ctf_field_type_set_byte_order rejects invalid values");
1937 ok(bt_ctf_field_type_set_byte_order(uint_12_type,
1938 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN) == 0,
1939 "Set an integer's byte order to little endian");
1940 ok(bt_ctf_field_type_set_byte_order(uint_12_type,
1941 BT_CTF_BYTE_ORDER_BIG_ENDIAN) == 0,
1942 "Set an integer's byte order to big endian");
1943 ok(bt_ctf_field_type_get_byte_order(uint_12_type) ==
1944 BT_CTF_BYTE_ORDER_BIG_ENDIAN,
1945 "bt_ctf_field_type_get_byte_order returns a correct value");
1946 ok(bt_ctf_field_type_get_byte_order(NULL) ==
1947 BT_CTF_BYTE_ORDER_UNKNOWN,
1948 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1949
1950 ok(bt_ctf_field_type_get_type_id(NULL) ==
1951 CTF_TYPE_UNKNOWN,
1952 "bt_ctf_field_type_get_type_id handles NULL correctly");
1953 ok(bt_ctf_field_type_get_type_id(uint_12_type) ==
1954 CTF_TYPE_INTEGER,
1955 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1956
1957 ok(bt_ctf_field_type_integer_get_base(NULL) ==
1958 BT_CTF_INTEGER_BASE_UNKNOWN,
1959 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1960 ok(bt_ctf_field_type_integer_get_base(uint_12_type) ==
1961 BT_CTF_INTEGER_BASE_HEXADECIMAL,
1962 "bt_ctf_field_type_integer_get_base returns a correct value");
1963
1964 ok(bt_ctf_field_type_integer_set_encoding(NULL, CTF_STRING_ASCII) < 0,
1965 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1966 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type,
1967 (enum ctf_string_encoding) 123) < 0,
1968 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1969 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type,
1970 CTF_STRING_UTF8) == 0,
1971 "Set integer type encoding to UTF8");
1972 ok(bt_ctf_field_type_integer_get_encoding(NULL) == CTF_STRING_UNKNOWN,
1973 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1974 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type) == CTF_STRING_UTF8,
1975 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1976
1977 int_16_type = bt_ctf_field_type_integer_create(16);
1978 bt_ctf_field_type_integer_set_signed(int_16_type, 1);
1979 ok(bt_ctf_field_type_integer_get_signed(int_16_type) == 1,
1980 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1981 uint_8_type = bt_ctf_field_type_integer_create(8);
1982 sequence_type =
1983 bt_ctf_field_type_sequence_create(int_16_type, "seq_len");
1984 ok(sequence_type, "Create a sequence of int16_t type");
1985 ok(bt_ctf_field_type_get_type_id(sequence_type) ==
1986 CTF_TYPE_SEQUENCE,
1987 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1988
1989 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL) == NULL,
1990 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1991 ret_string = bt_ctf_field_type_sequence_get_length_field_name(
1992 sequence_type);
1993 ok(!strcmp(ret_string, "seq_len"),
1994 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1995 ok(bt_ctf_field_type_sequence_get_element_type(NULL) == NULL,
1996 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1997 returned_type = bt_ctf_field_type_sequence_get_element_type(
1998 sequence_type);
1999 ok(returned_type == int_16_type,
2000 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
2001 bt_put(returned_type);
2002
2003 string_type = bt_ctf_field_type_string_create();
2004 ok(string_type, "Create a string type");
2005 ok(bt_ctf_field_type_string_set_encoding(string_type,
2006 CTF_STRING_NONE),
2007 "Reject invalid \"None\" string encoding");
2008 ok(bt_ctf_field_type_string_set_encoding(string_type,
2009 42),
2010 "Reject invalid string encoding");
2011 ok(bt_ctf_field_type_string_set_encoding(string_type,
2012 CTF_STRING_ASCII) == 0,
2013 "Set string encoding to ASCII");
2014
2015 ok(bt_ctf_field_type_string_get_encoding(NULL) ==
2016 CTF_STRING_UNKNOWN,
2017 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
2018 ok(bt_ctf_field_type_string_get_encoding(string_type) ==
2019 CTF_STRING_ASCII,
2020 "bt_ctf_field_type_string_get_encoding returns the correct value");
2021
2022 structure_seq_type = bt_ctf_field_type_structure_create();
2023 ok(bt_ctf_field_type_get_type_id(structure_seq_type) ==
2024 CTF_TYPE_STRUCT,
2025 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
2026 ok(structure_seq_type, "Create a structure type");
2027 ok(bt_ctf_field_type_structure_add_field(structure_seq_type,
2028 uint_8_type, "seq_len") == 0,
2029 "Add a uint8_t type to a structure");
2030 ok(bt_ctf_field_type_structure_add_field(structure_seq_type,
2031 sequence_type, "a_sequence") == 0,
2032 "Add a sequence type to a structure");
2033
2034 ok(bt_ctf_field_type_structure_get_field_count(NULL) < 0,
2035 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
2036 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type) == 2,
2037 "bt_ctf_field_type_structure_get_field_count returns a correct value");
2038
2039 ok(bt_ctf_field_type_structure_get_field(NULL,
2040 &ret_string, &returned_type, 1) < 0,
2041 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
2042 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
2043 NULL, &returned_type, 1) == 0,
2044 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
2045 bt_put(returned_type);
2046 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
2047 &ret_string, NULL, 1) == 0,
2048 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
2049 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
2050 &ret_string, &returned_type, 10) < 0,
2051 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
2052 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
2053 &ret_string, &returned_type, 1) == 0,
2054 "bt_ctf_field_type_structure_get_field returns a field");
2055 ok(!strcmp(ret_string, "a_sequence"),
2056 "bt_ctf_field_type_structure_get_field returns a correct field name");
2057 ok(returned_type == sequence_type,
2058 "bt_ctf_field_type_structure_get_field returns a correct field type");
2059 bt_put(returned_type);
2060
2061 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL, "a_sequence") == NULL,
2062 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
2063 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type, NULL) == NULL,
2064 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
2065 returned_type = bt_ctf_field_type_structure_get_field_type_by_name(
2066 structure_seq_type, "a_sequence");
2067 ok(returned_type == sequence_type,
2068 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
2069 bt_put(returned_type);
2070
2071 composite_structure_type = bt_ctf_field_type_structure_create();
2072 ok(bt_ctf_field_type_structure_add_field(composite_structure_type,
2073 string_type, "a_string") == 0,
2074 "Add a string type to a structure");
2075 ok(bt_ctf_field_type_structure_add_field(composite_structure_type,
2076 structure_seq_type, "inner_structure") == 0,
2077 "Add a structure type to a structure");
2078
2079 ok(bt_ctf_field_type_structure_get_field_type_by_name(
2080 NULL, "a_sequence") == NULL,
2081 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
2082 ok(bt_ctf_field_type_structure_get_field_type_by_name(
2083 structure_seq_type, NULL) == NULL,
2084 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
2085 returned_type = bt_ctf_field_type_structure_get_field_type_by_name(
2086 structure_seq_type, "a_sequence");
2087 ok(returned_type == sequence_type,
2088 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
2089 bt_put(returned_type);
2090
2091 int_16 = bt_ctf_field_create(int_16_type);
2092 ok(int_16, "Instanciate a signed 16-bit integer");
2093 uint_12 = bt_ctf_field_create(uint_12_type);
2094 ok(uint_12, "Instanciate an unsigned 12-bit integer");
2095 returned_type = bt_ctf_field_get_type(int_16);
2096 ok(returned_type == int_16_type,
2097 "bt_ctf_field_get_type returns the correct type");
2098
2099 /* Can't modify types after instanciating them */
2100 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
2101 BT_CTF_INTEGER_BASE_DECIMAL),
2102 "Check an integer type' base can't be modified after instanciation");
2103 ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0),
2104 "Check an integer type's signedness can't be modified after instanciation");
2105
2106 /* Check signed property is checked */
2107 ok(bt_ctf_field_signed_integer_set_value(uint_12, -52),
2108 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
2109 ok(bt_ctf_field_unsigned_integer_set_value(int_16, 42),
2110 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
2111
2112 /* Check overflows are properly tested for */
2113 ok(bt_ctf_field_signed_integer_set_value(int_16, -32768) == 0,
2114 "Check -32768 is allowed for a signed 16-bit integer");
2115 ok(bt_ctf_field_signed_integer_set_value(int_16, 32767) == 0,
2116 "Check 32767 is allowed for a signed 16-bit integer");
2117 ok(bt_ctf_field_signed_integer_set_value(int_16, 32768),
2118 "Check 32768 is not allowed for a signed 16-bit integer");
2119 ok(bt_ctf_field_signed_integer_set_value(int_16, -32769),
2120 "Check -32769 is not allowed for a signed 16-bit integer");
2121 ok(bt_ctf_field_signed_integer_set_value(int_16, -42) == 0,
2122 "Check -42 is allowed for a signed 16-bit integer");
2123
2124 ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 4095) == 0,
2125 "Check 4095 is allowed for an unsigned 12-bit integer");
2126 ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 4096),
2127 "Check 4096 is not allowed for a unsigned 12-bit integer");
2128 ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 0) == 0,
2129 "Check 0 is allowed for an unsigned 12-bit integer");
2130
2131 string = bt_ctf_field_create(string_type);
2132 ok(string, "Instanciate a string field");
2133 ok(bt_ctf_field_string_set_value(string, "A value") == 0,
2134 "Set a string's value");
2135
2136 enumeration_type = bt_ctf_field_type_enumeration_create(uint_12_type);
2137 ok(enumeration_type,
2138 "Create an enumeration type with an unsigned 12-bit integer as container");
2139 enumeration = bt_ctf_field_create(enumeration_type);
2140 ok(!enumeration,
2141 "Check enumeration types are validated before instantiation");
2142
2143 bt_put(string);
2144 bt_put(uint_12);
2145 bt_put(int_16);
2146 bt_put(enumeration);
2147 bt_put(composite_structure_type);
2148 bt_put(structure_seq_type);
2149 bt_put(string_type);
2150 bt_put(sequence_type);
2151 bt_put(uint_8_type);
2152 bt_put(int_16_type);
2153 bt_put(uint_12_type);
2154 bt_put(enumeration_type);
2155 bt_put(returned_type);
2156 }
2157
2158 void packet_resize_test(struct bt_ctf_stream_class *stream_class,
2159 struct bt_ctf_stream *stream, struct bt_ctf_clock *clock)
2160 {
2161 /*
2162 * Append enough events to force the underlying packet to be resized.
2163 * Also tests that a new event can be declared after a stream has been
2164 * instantiated and used/flushed.
2165 */
2166 int ret = 0;
2167 int i;
2168 struct bt_ctf_event_class *event_class = bt_ctf_event_class_create(
2169 "Spammy_Event");
2170 struct bt_ctf_field_type *integer_type =
2171 bt_ctf_field_type_integer_create(17);
2172 struct bt_ctf_field_type *string_type =
2173 bt_ctf_field_type_string_create();
2174 struct bt_ctf_event *event = NULL;
2175 struct bt_ctf_field *ret_field = NULL;
2176 struct bt_ctf_field_type *ret_field_type = NULL;
2177 uint64_t ret_uint64;
2178 int events_appended = 0;
2179 struct bt_ctf_field *packet_context = NULL,
2180 *packet_context_field = NULL, *event_context = NULL;
2181 struct bt_ctf_field_type *ep_field_1_type = NULL;
2182 struct bt_ctf_field_type *ep_a_string_type = NULL;
2183 struct bt_ctf_field_type *ep_type = NULL;
2184
2185 ret |= bt_ctf_event_class_add_field(event_class, integer_type,
2186 "field_1");
2187 ret |= bt_ctf_event_class_add_field(event_class, string_type,
2188 "a_string");
2189 ret |= bt_ctf_stream_class_add_event_class(stream_class, event_class);
2190 ok(ret == 0, "Add a new event class to a stream class after writing an event");
2191 if (ret) {
2192 goto end;
2193 }
2194
2195 /*
2196 * bt_ctf_stream_class_add_event_class() copies the field types
2197 * of event_class, so we retrieve the new ones to create the
2198 * appropriate fields.
2199 */
2200 ep_type = bt_ctf_event_class_get_payload_type(event_class);
2201 assert(ep_type);
2202 ep_field_1_type = bt_ctf_field_type_structure_get_field_type_by_name(
2203 ep_type, "field_1");
2204 assert(ep_field_1_type);
2205 ep_a_string_type = bt_ctf_field_type_structure_get_field_type_by_name(
2206 ep_type, "a_string");
2207 assert(ep_a_string_type);
2208
2209 event = bt_ctf_event_create(event_class);
2210 ret_field = bt_ctf_event_get_payload_by_index(event, 0);
2211 ret_field_type = bt_ctf_field_get_type(ret_field);
2212 ok(bt_ctf_field_type_compare(ret_field_type, integer_type) == 0,
2213 "bt_ctf_event_get_payload_by_index returns a correct field");
2214 bt_put(ret_field_type);
2215 bt_put(ret_field);
2216
2217 ok(bt_ctf_event_get_payload_by_index(NULL, 0) == NULL,
2218 "bt_ctf_event_get_payload_by_index handles NULL correctly");
2219 ok(bt_ctf_event_get_payload_by_index(event, 4) == NULL,
2220 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
2221 bt_put(event);
2222
2223 ok(bt_ctf_stream_get_event_context(NULL) == NULL,
2224 "bt_ctf_stream_get_event_context handles NULL correctly");
2225 event_context = bt_ctf_stream_get_event_context(stream);
2226 ok(event_context,
2227 "bt_ctf_stream_get_event_context returns a stream event context");
2228 ok(bt_ctf_stream_set_event_context(NULL, event_context) < 0,
2229 "bt_ctf_stream_set_event_context handles a NULL stream correctly");
2230 ok(bt_ctf_stream_set_event_context(stream, NULL) < 0,
2231 "bt_ctf_stream_set_event_context handles a NULL stream event context correctly");
2232 ok(!bt_ctf_stream_set_event_context(stream, event_context),
2233 "bt_ctf_stream_set_event_context correctly set a stream event context");
2234 ret_field = bt_ctf_field_create(ep_field_1_type);
2235 ok(bt_ctf_stream_set_event_context(stream, ret_field) < 0,
2236 "bt_ctf_stream_set_event_context rejects an event context of incorrect type");
2237 bt_put(ret_field);
2238
2239 for (i = 0; i < PACKET_RESIZE_TEST_LENGTH; i++) {
2240 event = bt_ctf_event_create(event_class);
2241 struct bt_ctf_field *integer =
2242 bt_ctf_field_create(ep_field_1_type);
2243 struct bt_ctf_field *string =
2244 bt_ctf_field_create(ep_a_string_type);
2245
2246 ret |= bt_ctf_clock_set_time(clock, ++current_time);
2247 ret |= bt_ctf_field_unsigned_integer_set_value(integer, i);
2248 ret |= bt_ctf_event_set_payload(event, "field_1",
2249 integer);
2250 bt_put(integer);
2251 ret |= bt_ctf_field_string_set_value(string, "This is a test");
2252 ret |= bt_ctf_event_set_payload(event, "a_string",
2253 string);
2254 bt_put(string);
2255
2256 /* Populate stream event context */
2257 integer = bt_ctf_field_structure_get_field(event_context,
2258 "common_event_context");
2259 ret |= bt_ctf_field_unsigned_integer_set_value(integer,
2260 i % 42);
2261 bt_put(integer);
2262
2263 ret |= bt_ctf_stream_append_event(stream, event);
2264 bt_put(event);
2265
2266 if (ret) {
2267 break;
2268 }
2269 }
2270
2271 events_appended = !!(i == PACKET_RESIZE_TEST_LENGTH);
2272 ok(bt_ctf_stream_get_discarded_events_count(NULL, &ret_uint64) < 0,
2273 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
2274 ok(bt_ctf_stream_get_discarded_events_count(stream, NULL) < 0,
2275 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
2276 ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64);
2277 ok(ret == 0 && ret_uint64 == 0,
2278 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
2279 bt_ctf_stream_append_discarded_events(stream, 1000);
2280 ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64);
2281 ok(ret == 0 && ret_uint64 == 1000,
2282 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
2283
2284 end:
2285 ok(events_appended, "Append 100 000 events to a stream");
2286
2287 /*
2288 * Populate the custom packet context field with a dummy value
2289 * otherwise flush will fail.
2290 */
2291 packet_context = bt_ctf_stream_get_packet_context(stream);
2292 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
2293 "custom_packet_context_field");
2294 bt_ctf_field_unsigned_integer_set_value(packet_context_field, 2);
2295
2296 ok(bt_ctf_stream_flush(stream) == 0,
2297 "Flush a stream that forces a packet resize");
2298 ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64);
2299 ok(ret == 0 && ret_uint64 == 1000,
2300 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
2301 bt_put(integer_type);
2302 bt_put(string_type);
2303 bt_put(packet_context);
2304 bt_put(packet_context_field);
2305 bt_put(event_context);
2306 bt_put(event_class);
2307 bt_put(ep_field_1_type);
2308 bt_put(ep_a_string_type);
2309 bt_put(ep_type);
2310 }
2311
2312 void test_empty_stream(struct bt_ctf_writer *writer)
2313 {
2314 int ret = 0;
2315 struct bt_ctf_trace *trace = NULL, *ret_trace = NULL;
2316 struct bt_ctf_stream_class *stream_class = NULL;
2317 struct bt_ctf_stream *stream = NULL;
2318
2319 trace = bt_ctf_writer_get_trace(writer);
2320 if (!trace) {
2321 diag("Failed to get trace from writer");
2322 ret = -1;
2323 goto end;
2324 }
2325
2326 stream_class = bt_ctf_stream_class_create("empty_stream");
2327 if (!stream_class) {
2328 diag("Failed to create stream class");
2329 ret = -1;
2330 goto end;
2331 }
2332
2333 ok(bt_ctf_stream_class_get_trace(NULL) == NULL,
2334 "bt_ctf_stream_class_get_trace handles NULL correctly");
2335 ok(bt_ctf_stream_class_get_trace(stream_class) == NULL,
2336 "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned");
2337
2338 stream = bt_ctf_writer_create_stream(writer, stream_class);
2339 if (!stream) {
2340 diag("Failed to create writer stream");
2341 ret = -1;
2342 goto end;
2343 }
2344
2345 ret_trace = bt_ctf_stream_class_get_trace(stream_class);
2346 ok(ret_trace == trace,
2347 "bt_ctf_stream_class_get_trace returns the correct trace after a stream has been created");
2348 end:
2349 ok(ret == 0,
2350 "Created a stream class with default attributes and an empty stream");
2351 bt_put(trace);
2352 bt_put(ret_trace);
2353 bt_put(stream);
2354 bt_put(stream_class);
2355 }
2356
2357 void test_custom_event_header_stream(struct bt_ctf_writer *writer)
2358 {
2359 int i, ret;
2360 struct bt_ctf_trace *trace = NULL;
2361 struct bt_ctf_clock *clock = NULL;
2362 struct bt_ctf_stream_class *stream_class = NULL;
2363 struct bt_ctf_stream *stream = NULL;
2364 struct bt_ctf_field_type *integer_type = NULL,
2365 *sequence_type = NULL, *event_header_type = NULL;
2366 struct bt_ctf_field *integer = NULL, *sequence = NULL,
2367 *event_header = NULL, *packet_header = NULL;
2368 struct bt_ctf_event_class *event_class = NULL;
2369 struct bt_ctf_event *event = NULL;
2370
2371 trace = bt_ctf_writer_get_trace(writer);
2372 if (!trace) {
2373 fail("Failed to get trace from writer");
2374 goto end;
2375 }
2376
2377 clock = bt_ctf_trace_get_clock(trace, 0);
2378 if (!clock) {
2379 fail("Failed to get clock from trace");
2380 goto end;
2381 }
2382
2383 stream_class = bt_ctf_stream_class_create("custom_event_header_stream");
2384 if (!stream_class) {
2385 fail("Failed to create stream class");
2386 goto end;
2387 }
2388
2389 ret = bt_ctf_stream_class_set_clock(stream_class, clock);
2390 if (ret) {
2391 fail("Failed to set stream class clock");
2392 goto end;
2393 }
2394
2395 /*
2396 * Customize event header to add an "seq_len" integer member
2397 * which will be used as the length of a sequence in an event of this
2398 * stream.
2399 */
2400 event_header_type = bt_ctf_stream_class_get_event_header_type(
2401 stream_class);
2402 if (!event_header_type) {
2403 fail("Failed to get event header type");
2404 goto end;
2405 }
2406
2407 integer_type = bt_ctf_field_type_integer_create(13);
2408 if (!integer_type) {
2409 fail("Failed to create length integer type");
2410 goto end;
2411 }
2412
2413 ret = bt_ctf_field_type_structure_add_field(event_header_type,
2414 integer_type, "seq_len");
2415 if (ret) {
2416 fail("Failed to add a new field to stream event header");
2417 goto end;
2418 }
2419
2420 event_class = bt_ctf_event_class_create("sequence_event");
2421 if (!event_class) {
2422 fail("Failed to create event class");
2423 goto end;
2424 }
2425
2426 /*
2427 * This event's payload will contain a sequence which references
2428 * stream.event.header.seq_len as its length field.
2429 */
2430 sequence_type = bt_ctf_field_type_sequence_create(integer_type,
2431 "stream.event.header.seq_len");
2432 if (!sequence_type) {
2433 fail("Failed to create a sequence");
2434 goto end;
2435 }
2436
2437 ret = bt_ctf_event_class_add_field(event_class, sequence_type,
2438 "some_sequence");
2439 if (ret) {
2440 fail("Failed to add a sequence to an event class");
2441 goto end;
2442 }
2443
2444 ret = bt_ctf_stream_class_add_event_class(stream_class, event_class);
2445 if (ret) {
2446 fail("Failed to add event class to stream class");
2447 goto end;
2448 }
2449
2450 stream = bt_ctf_writer_create_stream(writer, stream_class);
2451 if (!stream) {
2452 fail("Failed to create stream")
2453 goto end;
2454 }
2455
2456 /*
2457 * We have defined a custom packet header field. We have to populate it
2458 * explicitly.
2459 */
2460 packet_header = bt_ctf_stream_get_packet_header(stream);
2461 if (!packet_header) {
2462 fail("Failed to get stream packet header");
2463 goto end;
2464 }
2465
2466 integer = bt_ctf_field_structure_get_field(packet_header,
2467 "custom_trace_packet_header_field");
2468 if (!integer) {
2469 fail("Failed to retrieve custom_trace_packet_header_field");
2470 goto end;
2471 }
2472
2473 ret = bt_ctf_field_unsigned_integer_set_value(integer, 3487);
2474 if (ret) {
2475 fail("Failed to set custom_trace_packet_header_field value");
2476 goto end;
2477 }
2478 bt_put(integer);
2479
2480 event = bt_ctf_event_create(event_class);
2481 if (!event) {
2482 fail("Failed to create event");
2483 goto end;
2484 }
2485
2486 event_header = bt_ctf_event_get_header(event);
2487 if (!event_header) {
2488 fail("Failed to get event header");
2489 goto end;
2490 }
2491
2492 integer = bt_ctf_field_structure_get_field(event_header,
2493 "seq_len");
2494 if (!integer) {
2495 fail("Failed to get seq_len field from event header");
2496 goto end;
2497 }
2498
2499 ret = bt_ctf_field_unsigned_integer_set_value(integer, 2);
2500 if (ret) {
2501 fail("Failed to set seq_len value in event header");
2502 goto end;
2503 }
2504
2505 /* Populate both sequence integer fields */
2506 sequence = bt_ctf_event_get_payload(event, "some_sequence");
2507 if (!sequence) {
2508 fail("Failed to retrieve sequence from event");
2509 goto end;
2510 }
2511
2512 ret = bt_ctf_field_sequence_set_length(sequence, integer);
2513 if (ret) {
2514 fail("Failed to set sequence length");
2515 goto end;
2516 }
2517 bt_put(integer);
2518
2519 for (i = 0; i < 2; i++) {
2520 integer = bt_ctf_field_sequence_get_field(sequence, i);
2521 if (ret) {
2522 fail("Failed to retrieve sequence element");
2523 goto end;
2524 }
2525
2526 ret = bt_ctf_field_unsigned_integer_set_value(integer, i);
2527 if (ret) {
2528 fail("Failed to set sequence element value");
2529 goto end;
2530 }
2531
2532 bt_put(integer);
2533 integer = NULL;
2534 }
2535
2536 ret = bt_ctf_stream_append_event(stream, event);
2537 if (ret) {
2538 fail("Failed to append event to stream");
2539 goto end;
2540 }
2541
2542 ret = bt_ctf_stream_flush(stream);
2543 if (ret) {
2544 fail("Failed to flush custom_event_header stream");
2545 }
2546 end:
2547 bt_put(clock);
2548 bt_put(trace);
2549 bt_put(stream);
2550 bt_put(stream_class);
2551 bt_put(event_class);
2552 bt_put(event);
2553 bt_put(integer);
2554 bt_put(sequence);
2555 bt_put(event_header);
2556 bt_put(packet_header);
2557 bt_put(sequence_type);
2558 bt_put(integer_type);
2559 bt_put(event_header_type);
2560 }
2561
2562 void test_instanciate_event_before_stream(struct bt_ctf_writer *writer)
2563 {
2564 int ret = 0;
2565 struct bt_ctf_trace *trace = NULL;
2566 struct bt_ctf_clock *clock = NULL;
2567 struct bt_ctf_stream_class *stream_class = NULL;
2568 struct bt_ctf_stream *stream = NULL,
2569 *ret_stream = NULL;
2570 struct bt_ctf_event_class *event_class = NULL;
2571 struct bt_ctf_event *event = NULL;
2572 struct bt_ctf_field_type *integer_type = NULL;
2573 struct bt_ctf_field *integer = NULL;
2574
2575 trace = bt_ctf_writer_get_trace(writer);
2576 if (!trace) {
2577 diag("Failed to get trace from writer");
2578 ret = -1;
2579 goto end;
2580 }
2581
2582 clock = bt_ctf_trace_get_clock(trace, 0);
2583 if (!clock) {
2584 diag("Failed to get clock from trace");
2585 ret = -1;
2586 goto end;
2587 }
2588
2589 stream_class = bt_ctf_stream_class_create("event_before_stream_test");
2590 if (!stream_class) {
2591 diag("Failed to create stream class");
2592 ret = -1;
2593 goto end;
2594 }
2595
2596 ret = bt_ctf_stream_class_set_clock(stream_class, clock);
2597 if (ret) {
2598 diag("Failed to set stream class clock");
2599 goto end;
2600 }
2601
2602 event_class = bt_ctf_event_class_create("some_event_class_name");
2603 integer_type = bt_ctf_field_type_integer_create(32);
2604 if (!integer_type) {
2605 diag("Failed to create integer field type");
2606 ret = -1;
2607 goto end;
2608 }
2609
2610 ret = bt_ctf_event_class_add_field(event_class, integer_type,
2611 "integer_field");
2612 if (ret) {
2613 diag("Failed to add field to event class");
2614 goto end;
2615 }
2616
2617 ret = bt_ctf_stream_class_add_event_class(stream_class,
2618 event_class);
2619 if (ret) {
2620 diag("Failed to add event class to stream class");
2621 }
2622
2623 event = bt_ctf_event_create(event_class);
2624 if (!event) {
2625 diag("Failed to create event");
2626 ret = -1;
2627 goto end;
2628 }
2629
2630 integer = bt_ctf_event_get_payload_by_index(event, 0);
2631 if (!integer) {
2632 diag("Failed to get integer field payload from event");
2633 ret = -1;
2634 goto end;
2635 }
2636
2637 ret = bt_ctf_field_unsigned_integer_set_value(integer, 1234);
2638 if (ret) {
2639 diag("Failed to set integer field value");
2640 goto end;
2641 }
2642
2643 stream = bt_ctf_writer_create_stream(writer, stream_class);
2644 if (!stream) {
2645 diag("Failed to create writer stream");
2646 ret = -1;
2647 goto end;
2648 }
2649
2650 ok(bt_ctf_event_get_stream(NULL) == NULL,
2651 "bt_ctf_event_get_stream handles NULL correctly");
2652 ok(bt_ctf_event_get_stream(event) == NULL,
2653 "bt_ctf_event_get_stream returns NULL on event which has not yet been appended to a stream");
2654
2655 ret = bt_ctf_stream_append_event(stream, event);
2656 if (ret) {
2657 diag("Failed to append event to stream");
2658 goto end;
2659 }
2660
2661 ret_stream = bt_ctf_event_get_stream(event);
2662 ok(ret_stream == stream,
2663 "bt_ctf_event_get_stream returns an event's stream after it has been appended");
2664 end:
2665 ok(ret == 0,
2666 "Create an event before instanciating its associated stream");
2667 bt_put(trace);
2668 bt_put(stream);
2669 bt_put(ret_stream);
2670 bt_put(stream_class);
2671 bt_put(event_class);
2672 bt_put(event);
2673 bt_put(integer_type);
2674 bt_put(integer);
2675 bt_put(clock);
2676 }
2677
2678 void append_existing_event_class(struct bt_ctf_stream_class *stream_class)
2679 {
2680 struct bt_ctf_event_class *event_class;
2681
2682 event_class = bt_ctf_event_class_create("Simple Event");
2683 assert(event_class);
2684 ok(bt_ctf_stream_class_add_event_class(stream_class, event_class),
2685 "two event classes with the same name cannot cohabit within the same stream class");
2686 bt_put(event_class);
2687
2688 event_class = bt_ctf_event_class_create("different name, ok");
2689 assert(event_class);
2690 assert(!bt_ctf_event_class_set_id(event_class, 11));
2691 ok(bt_ctf_stream_class_add_event_class(stream_class, event_class),
2692 "two event classes with the same ID cannot cohabit within the same stream class");
2693 bt_put(event_class);
2694 }
2695
2696 int main(int argc, char **argv)
2697 {
2698 char trace_path[] = "/tmp/ctfwriter_XXXXXX";
2699 char metadata_path[sizeof(trace_path) + 9];
2700 const char *clock_name = "test_clock";
2701 const char *clock_description = "This is a test clock";
2702 const char *returned_clock_name;
2703 const char *returned_clock_description;
2704 const uint64_t frequency = 1123456789;
2705 const int64_t offset_s = 1351530929945824323;
2706 const int64_t offset = 1234567;
2707 int64_t get_offset_s,
2708 get_offset,
2709 get_time;
2710 const uint64_t precision = 10;
2711 const int is_absolute = 0xFF;
2712 char *metadata_string;
2713 struct bt_ctf_writer *writer;
2714 struct utsname name;
2715 char hostname[BABELTRACE_HOST_NAME_MAX];
2716 struct bt_ctf_clock *clock, *ret_clock;
2717 struct bt_ctf_stream_class *stream_class, *ret_stream_class;
2718 struct bt_ctf_stream *stream1;
2719 const char *ret_string;
2720 const unsigned char *ret_uuid;
2721 unsigned char tmp_uuid[16] = { 0 };
2722 struct bt_ctf_field_type *packet_context_type,
2723 *packet_context_field_type,
2724 *packet_header_type,
2725 *packet_header_field_type,
2726 *integer_type,
2727 *stream_event_context_type,
2728 *ret_field_type,
2729 *event_header_field_type;
2730 struct bt_ctf_field *packet_header, *packet_header_field;
2731 struct bt_ctf_trace *trace;
2732 int ret;
2733 int64_t ret_int64_t;
2734 struct bt_value *obj;
2735
2736 if (argc < 3) {
2737 printf("Usage: tests-ctf-writer path_to_ctf_parser_test path_to_babeltrace\n");
2738 return -1;
2739 }
2740
2741 plan_tests(NR_TESTS);
2742
2743 if (!bt_mkdtemp(trace_path)) {
2744 perror("# perror");
2745 }
2746
2747 strcpy(metadata_path, trace_path);
2748 strcat(metadata_path + sizeof(trace_path) - 1, "/metadata");
2749
2750 writer = bt_ctf_writer_create(trace_path);
2751 ok(writer, "bt_ctf_create succeeds in creating trace with path");
2752
2753 ok(!bt_ctf_writer_get_trace(NULL),
2754 "bt_ctf_writer_get_trace correctly handles NULL");
2755 trace = bt_ctf_writer_get_trace(writer);
2756 ok(trace,
2757 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
2758 ok(bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_BIG_ENDIAN) == 0,
2759 "Set a trace's byte order to big endian");
2760 ok(bt_ctf_trace_get_byte_order(trace) == BT_CTF_BYTE_ORDER_BIG_ENDIAN,
2761 "bt_ctf_trace_get_byte_order returns a correct endianness");
2762
2763 /* Add environment context to the trace */
2764 ret = gethostname(hostname, sizeof(hostname));
2765 if (ret < 0) {
2766 return ret;
2767 }
2768 ok(bt_ctf_writer_add_environment_field(writer, "host", hostname) == 0,
2769 "Add host (%s) environment field to writer instance",
2770 hostname);
2771 ok(bt_ctf_writer_add_environment_field(NULL, "test_field",
2772 "test_value"),
2773 "bt_ctf_writer_add_environment_field error with NULL writer");
2774 ok(bt_ctf_writer_add_environment_field(writer, NULL,
2775 "test_value"),
2776 "bt_ctf_writer_add_environment_field error with NULL field name");
2777 ok(bt_ctf_writer_add_environment_field(writer, "test_field",
2778 NULL),
2779 "bt_ctf_writer_add_environment_field error with NULL field value");
2780
2781 /* Test bt_ctf_trace_set_environment_field with an integer object */
2782 obj = bt_value_integer_create_init(23);
2783 assert(obj);
2784 ok(bt_ctf_trace_set_environment_field(NULL, "test_env_int_obj", obj),
2785 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
2786 ok(bt_ctf_trace_set_environment_field(trace, NULL, obj),
2787 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
2788 ok(bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", NULL),
2789 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
2790 ok(!bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", obj),
2791 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
2792 BT_PUT(obj);
2793
2794 /* Test bt_ctf_trace_set_environment_field with a string object */
2795 obj = bt_value_string_create_init("the value");
2796 assert(obj);
2797 ok(!bt_ctf_trace_set_environment_field(trace, "test_env_str_obj", obj),
2798 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
2799 BT_PUT(obj);
2800
2801 /* Test bt_ctf_trace_set_environment_field_integer */
2802 ok(bt_ctf_trace_set_environment_field_integer(NULL, "test_env_int",
2803 -194875),
2804 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
2805 ok(bt_ctf_trace_set_environment_field_integer(trace, NULL, -194875),
2806 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
2807 ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int",
2808 -164973),
2809 "bt_ctf_trace_set_environment_field_integer succeeds");
2810
2811 /* Test bt_ctf_trace_set_environment_field_string */
2812 ok(bt_ctf_trace_set_environment_field_string(NULL, "test_env_str",
2813 "yeah"),
2814 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
2815 ok(bt_ctf_trace_set_environment_field_string(trace, NULL, "yeah"),
2816 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
2817 ok(bt_ctf_trace_set_environment_field_string(trace, "test_env_str",
2818 NULL),
2819 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
2820 ok(!bt_ctf_trace_set_environment_field_string(trace, "test_env_str",
2821 "oh yeah"),
2822 "bt_ctf_trace_set_environment_field_string succeeds");
2823
2824 /* Test bt_ctf_trace_get_environment_field_count */
2825 ok(bt_ctf_trace_get_environment_field_count(NULL) < 0,
2826 "bt_ctf_trace_get_environment_field_count handles a NULL trace correctly");
2827 ok(bt_ctf_trace_get_environment_field_count(trace) == 5,
2828 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
2829
2830 /* Test bt_ctf_trace_get_environment_field_name */
2831 ok(bt_ctf_trace_get_environment_field_name(NULL, 0) == NULL,
2832 "bt_ctf_trace_get_environment_field_name handles a NULL trace correctly");
2833 ok(bt_ctf_trace_get_environment_field_name(trace, -1) == NULL,
2834 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (negative)");
2835 ok(bt_ctf_trace_get_environment_field_name(trace, 5) == NULL,
2836 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (too large)");
2837 ret_string = bt_ctf_trace_get_environment_field_name(trace, 0);
2838 ok(ret_string && !strcmp(ret_string, "host"),
2839 "bt_ctf_trace_get_environment_field_name returns a correct field name");
2840 ret_string = bt_ctf_trace_get_environment_field_name(trace, 1);
2841 ok(ret_string && !strcmp(ret_string, "test_env_int_obj"),
2842 "bt_ctf_trace_get_environment_field_name returns a correct field name");
2843 ret_string = bt_ctf_trace_get_environment_field_name(trace, 2);
2844 ok(ret_string && !strcmp(ret_string, "test_env_str_obj"),
2845 "bt_ctf_trace_get_environment_field_name returns a correct field name");
2846 ret_string = bt_ctf_trace_get_environment_field_name(trace, 3);
2847 ok(ret_string && !strcmp(ret_string, "test_env_int"),
2848 "bt_ctf_trace_get_environment_field_name returns a correct field name");
2849 ret_string = bt_ctf_trace_get_environment_field_name(trace, 4);
2850 ok(ret_string && !strcmp(ret_string, "test_env_str"),
2851 "bt_ctf_trace_get_environment_field_name returns a correct field name");
2852
2853 /* Test bt_ctf_trace_get_environment_field_value */
2854 ok(bt_ctf_trace_get_environment_field_value(NULL, 0) == NULL,
2855 "bt_ctf_trace_get_environment_field_value handles a NULL trace correctly");
2856 ok(bt_ctf_trace_get_environment_field_value(trace, -1) == NULL,
2857 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (negative)");
2858 ok(bt_ctf_trace_get_environment_field_value(trace, 5) == NULL,
2859 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (too large)");
2860 obj = bt_ctf_trace_get_environment_field_value(trace, 1);
2861 ret = bt_value_integer_get(obj, &ret_int64_t);
2862 ok(!ret && ret_int64_t == 23,
2863 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
2864 BT_PUT(obj);
2865 obj = bt_ctf_trace_get_environment_field_value(trace, 2);
2866 ret = bt_value_string_get(obj, &ret_string);
2867 ok(!ret && ret_string && !strcmp(ret_string, "the value"),
2868 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
2869 BT_PUT(obj);
2870
2871 /* Test bt_ctf_trace_get_environment_field_value_by_name */
2872 ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL,
2873 "test_env_str"),
2874 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL trace correctly");
2875 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace, NULL),
2876 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL name correctly");
2877 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace, "oh oh"),
2878 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
2879 obj = bt_ctf_trace_get_environment_field_value_by_name(trace,
2880 "test_env_str");
2881 ret = bt_value_string_get(obj, &ret_string);
2882 ok(!ret && ret_string && !strcmp(ret_string, "oh yeah"),
2883 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
2884 BT_PUT(obj);
2885
2886 /* Test environment field replacement */
2887 ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int",
2888 654321),
2889 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
2890 ok(bt_ctf_trace_get_environment_field_count(trace) == 5,
2891 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
2892 obj = bt_ctf_trace_get_environment_field_value(trace, 3);
2893 ret = bt_value_integer_get(obj, &ret_int64_t);
2894 ok(!ret && ret_int64_t == 654321,
2895 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
2896 BT_PUT(obj);
2897
2898 /* On Solaris, uname() can return any positive value on success */
2899 if (uname(&name) < 0) {
2900 perror("uname");
2901 return -1;
2902 }
2903
2904 ok(bt_ctf_writer_add_environment_field(writer, "sysname", name.sysname)
2905 == 0, "Add sysname (%s) environment field to writer instance",
2906 name.sysname);
2907 ok(bt_ctf_writer_add_environment_field(writer, "nodename",
2908 name.nodename) == 0,
2909 "Add nodename (%s) environment field to writer instance",
2910 name.nodename);
2911 ok(bt_ctf_writer_add_environment_field(writer, "release", name.release)
2912 == 0, "Add release (%s) environment field to writer instance",
2913 name.release);
2914 ok(bt_ctf_writer_add_environment_field(writer, "version", name.version)
2915 == 0, "Add version (%s) environment field to writer instance",
2916 name.version);
2917 ok(bt_ctf_writer_add_environment_field(writer, "machine", name.machine)
2918 == 0, "Add machine (%s) environment field to writer istance",
2919 name.machine);
2920
2921 /* Define a clock and add it to the trace */
2922 ok(bt_ctf_clock_create("signed") == NULL,
2923 "Illegal clock name rejected");
2924 ok(bt_ctf_clock_create(NULL) == NULL, "NULL clock name rejected");
2925 clock = bt_ctf_clock_create(clock_name);
2926 ok(clock, "Clock created sucessfully");
2927 returned_clock_name = bt_ctf_clock_get_name(clock);
2928 ok(returned_clock_name, "bt_ctf_clock_get_name returns a clock name");
2929 ok(returned_clock_name ? !strcmp(returned_clock_name, clock_name) : 0,
2930 "Returned clock name is valid");
2931
2932 returned_clock_description = bt_ctf_clock_get_description(clock);
2933 ok(!returned_clock_description, "bt_ctf_clock_get_description returns NULL on an unset description");
2934 ok(bt_ctf_clock_set_description(clock, clock_description) == 0,
2935 "Clock description set successfully");
2936
2937 returned_clock_description = bt_ctf_clock_get_description(clock);
2938 ok(returned_clock_description,
2939 "bt_ctf_clock_get_description returns a description.");
2940 ok(returned_clock_description ?
2941 !strcmp(returned_clock_description, clock_description) : 0,
2942 "Returned clock description is valid");
2943
2944 ok(bt_ctf_clock_get_frequency(clock) == DEFAULT_CLOCK_FREQ,
2945 "bt_ctf_clock_get_frequency returns the correct default frequency");
2946 ok(bt_ctf_clock_set_frequency(clock, frequency) == 0,
2947 "Set clock frequency");
2948 ok(bt_ctf_clock_get_frequency(clock) == frequency,
2949 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
2950
2951 ok(bt_ctf_clock_get_offset_s(clock, &get_offset_s) == 0,
2952 "bt_ctf_clock_get_offset_s succeeds");
2953 ok(get_offset_s == DEFAULT_CLOCK_OFFSET_S,
2954 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
2955 ok(bt_ctf_clock_set_offset_s(clock, offset_s) == 0,
2956 "Set clock offset (seconds)");
2957 ok(bt_ctf_clock_get_offset_s(clock, &get_offset_s) == 0,
2958 "bt_ctf_clock_get_offset_s succeeds");
2959 ok(get_offset_s == offset_s,
2960 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
2961
2962 ok(bt_ctf_clock_get_offset(clock, &get_offset) == 0,
2963 "bt_ctf_clock_get_offset succeeds");
2964 ok(get_offset == DEFAULT_CLOCK_OFFSET,
2965 "bt_ctf_clock_get_offset returns the correct default offset (in ticks)");
2966 ok(bt_ctf_clock_set_offset(clock, offset) == 0, "Set clock offset");
2967 ok(bt_ctf_clock_get_offset(clock, &get_offset) == 0,
2968 "bt_ctf_clock_get_offset succeeds");
2969 ok(get_offset == offset,
2970 "bt_ctf_clock_get_offset returns the correct default offset (in ticks) once it is set");
2971
2972 ok(bt_ctf_clock_get_precision(clock) == DEFAULT_CLOCK_PRECISION,
2973 "bt_ctf_clock_get_precision returns the correct default precision");
2974 ok(bt_ctf_clock_set_precision(clock, precision) == 0,
2975 "Set clock precision");
2976 ok(bt_ctf_clock_get_precision(clock) == precision,
2977 "bt_ctf_clock_get_precision returns the correct precision once it is set");
2978
2979 ok(bt_ctf_clock_get_is_absolute(clock) == DEFAULT_CLOCK_IS_ABSOLUTE,
2980 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
2981 ok(bt_ctf_clock_set_is_absolute(clock, is_absolute) == 0,
2982 "Set clock absolute property");
2983 ok(bt_ctf_clock_get_is_absolute(clock) == !!is_absolute,
2984 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
2985
2986 ok(bt_ctf_clock_get_time(clock, &get_time) == 0,
2987 "bt_ctf_clock_get_time succeeds");
2988 ok(get_time == DEFAULT_CLOCK_TIME,
2989 "bt_ctf_clock_get_time returns the correct default time");
2990 ok(bt_ctf_clock_set_time(clock, current_time) == 0,
2991 "Set clock time");
2992 ok(bt_ctf_clock_get_time(clock, &get_time) == 0,
2993 "bt_ctf_clock_get_time succeeds");
2994 ok(get_time == current_time,
2995 "bt_ctf_clock_get_time returns the correct time once it is set");
2996
2997 ok(bt_ctf_writer_add_clock(writer, clock) == 0,
2998 "Add clock to writer instance");
2999 ok(bt_ctf_writer_add_clock(writer, clock),
3000 "Verify a clock can't be added twice to a writer instance");
3001
3002 ok(bt_ctf_trace_get_clock_count(NULL) < 0,
3003 "bt_ctf_trace_get_clock_count correctly handles NULL");
3004 ok(bt_ctf_trace_get_clock_count(trace) == 1,
3005 "bt_ctf_trace_get_clock_count returns the correct number of clocks");
3006 ok(!bt_ctf_trace_get_clock(NULL, 0),
3007 "bt_ctf_trace_get_clock correctly handles NULL");
3008 ok(!bt_ctf_trace_get_clock(trace, -1),
3009 "bt_ctf_trace_get_clock correctly handles negative indexes");
3010 ok(!bt_ctf_trace_get_clock(trace, 1),
3011 "bt_ctf_trace_get_clock correctly handles out of bound accesses");
3012 ret_clock = bt_ctf_trace_get_clock(trace, 0);
3013 ok(ret_clock == clock,
3014 "bt_ctf_trace_get_clock returns the right clock instance");
3015 bt_put(ret_clock);
3016 ok(!bt_ctf_trace_get_clock_by_name(trace, NULL),
3017 "bt_ctf_trace_get_clock_by_name correctly handles NULL (trace)");
3018 ok(!bt_ctf_trace_get_clock_by_name(NULL, clock_name),
3019 "bt_ctf_trace_get_clock_by_name correctly handles NULL (clock name)");
3020 ok(!bt_ctf_trace_get_clock_by_name(NULL, NULL),
3021 "bt_ctf_trace_get_clock_by_name correctly handles NULL (both)");
3022 ret_clock = bt_ctf_trace_get_clock_by_name(trace, clock_name);
3023 ok(ret_clock == clock,
3024 "bt_ctf_trace_get_clock_by_name returns the right clock instance");
3025 bt_put(ret_clock);
3026 ok(!bt_ctf_trace_get_clock_by_name(trace, "random"),
3027 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
3028
3029 ok(!bt_ctf_clock_get_name(NULL),
3030 "bt_ctf_clock_get_name correctly handles NULL");
3031 ok(!bt_ctf_clock_get_description(NULL),
3032 "bt_ctf_clock_get_description correctly handles NULL");
3033 ok(bt_ctf_clock_get_frequency(NULL) == -1ULL,
3034 "bt_ctf_clock_get_frequency correctly handles NULL");
3035 ok(bt_ctf_clock_get_precision(NULL) == -1ULL,
3036 "bt_ctf_clock_get_precision correctly handles NULL");
3037 ok(bt_ctf_clock_get_offset_s(NULL, &get_offset_s) < 0,
3038 "bt_ctf_clock_get_offset_s correctly handles NULL clock");
3039 ok(bt_ctf_clock_get_offset_s(clock, NULL) < 0,
3040 "bt_ctf_clock_get_offset_s correctly handles NULL output");
3041 ok(bt_ctf_clock_get_offset(NULL, &get_offset) < 0,
3042 "bt_ctf_clock_get_offset correctly handles NULL clock");
3043 ok(bt_ctf_clock_get_offset(clock, NULL) < 0,
3044 "bt_ctf_clock_get_offset correctly handles NULL output");
3045 ok(bt_ctf_clock_get_is_absolute(NULL) < 0,
3046 "bt_ctf_clock_get_is_absolute correctly handles NULL");
3047 ok(bt_ctf_clock_get_time(NULL, &get_time) < 0,
3048 "bt_ctf_clock_get_time correctly handles NULL clock");
3049 ok(bt_ctf_clock_get_time(clock, NULL) < 0,
3050 "bt_ctf_clock_get_time correctly handles NULL output");
3051
3052 ok(bt_ctf_clock_set_description(NULL, NULL) < 0,
3053 "bt_ctf_clock_set_description correctly handles NULL clock");
3054 ok(bt_ctf_clock_set_frequency(NULL, frequency) < 0,
3055 "bt_ctf_clock_set_frequency correctly handles NULL clock");
3056 ok(bt_ctf_clock_set_precision(NULL, precision) < 0,
3057 "bt_ctf_clock_get_precision correctly handles NULL clock");
3058 ok(bt_ctf_clock_set_offset_s(NULL, offset_s) < 0,
3059 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
3060 ok(bt_ctf_clock_set_offset(NULL, offset) < 0,
3061 "bt_ctf_clock_set_offset correctly handles NULL clock");
3062 ok(bt_ctf_clock_set_is_absolute(NULL, is_absolute) < 0,
3063 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
3064 ok(bt_ctf_clock_set_time(NULL, current_time) < 0,
3065 "bt_ctf_clock_set_time correctly handles NULL clock");
3066 ok(bt_ctf_clock_get_uuid(NULL) == NULL,
3067 "bt_ctf_clock_get_uuid correctly handles NULL clock");
3068 ret_uuid = bt_ctf_clock_get_uuid(clock);
3069 ok(ret_uuid,
3070 "bt_ctf_clock_get_uuid returns a UUID");
3071 if (ret_uuid) {
3072 memcpy(tmp_uuid, ret_uuid, sizeof(tmp_uuid));
3073 /* Slightly modify UUID */
3074 tmp_uuid[sizeof(tmp_uuid) - 1]++;
3075 }
3076
3077 ok(bt_ctf_clock_set_uuid(NULL, tmp_uuid) < 0,
3078 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
3079 ok(bt_ctf_clock_set_uuid(clock, NULL) < 0,
3080 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
3081 ok(bt_ctf_clock_set_uuid(clock, tmp_uuid) == 0,
3082 "bt_ctf_clock_set_uuid sets a new uuid succesfully");
3083 ret_uuid = bt_ctf_clock_get_uuid(clock);
3084 ok(ret_uuid,
3085 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
3086 ok(uuid_match(ret_uuid, tmp_uuid),
3087 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
3088
3089 /* Define a stream class */
3090 stream_class = bt_ctf_stream_class_create("test_stream");
3091
3092 ok(bt_ctf_stream_class_get_name(NULL) == NULL,
3093 "bt_ctf_stream_class_get_name handles NULL correctly");
3094 ret_string = bt_ctf_stream_class_get_name(stream_class);
3095 ok(ret_string && !strcmp(ret_string, "test_stream"),
3096 "bt_ctf_stream_class_get_name returns a correct stream class name");
3097
3098 ok(bt_ctf_stream_class_get_clock(stream_class) == NULL,
3099 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
3100 ok(bt_ctf_stream_class_get_clock(NULL) == NULL,
3101 "bt_ctf_stream_class_get_clock handles NULL correctly");
3102
3103 ok(stream_class, "Create stream class");
3104 ok(bt_ctf_stream_class_set_clock(stream_class, clock) == 0,
3105 "Set a stream class' clock");
3106 ret_clock = bt_ctf_stream_class_get_clock(stream_class);
3107 ok(ret_clock == clock,
3108 "bt_ctf_stream_class_get_clock returns a correct clock");
3109 bt_put(ret_clock);
3110
3111 /* Test the event fields and event types APIs */
3112 type_field_tests();
3113
3114 /* Test fields copying */
3115 field_copy_tests();
3116
3117 ok(bt_ctf_stream_class_get_id(stream_class) < 0,
3118 "bt_ctf_stream_class_get_id returns an error when no id is set");
3119 ok(bt_ctf_stream_class_get_id(NULL) < 0,
3120 "bt_ctf_stream_class_get_id handles NULL correctly");
3121 ok(bt_ctf_stream_class_set_id(NULL, 123) < 0,
3122 "bt_ctf_stream_class_set_id handles NULL correctly");
3123 ok(bt_ctf_stream_class_set_id(stream_class, 123) == 0,
3124 "Set an stream class' id");
3125 ok(bt_ctf_stream_class_get_id(stream_class) == 123,
3126 "bt_ctf_stream_class_get_id returns the correct value");
3127
3128 /* Validate default event header fields */
3129 ok(bt_ctf_stream_class_get_event_header_type(NULL) == NULL,
3130 "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
3131 ret_field_type = bt_ctf_stream_class_get_event_header_type(
3132 stream_class);
3133 ok(ret_field_type,
3134 "bt_ctf_stream_class_get_event_header_type returns an event header type");
3135 ok(bt_ctf_field_type_get_type_id(ret_field_type) == CTF_TYPE_STRUCT,
3136 "Default event header type is a structure");
3137 event_header_field_type =
3138 bt_ctf_field_type_structure_get_field_type_by_name(
3139 ret_field_type, "id");
3140 ok(event_header_field_type,
3141 "Default event header type contains an \"id\" field");
3142 ok(bt_ctf_field_type_get_type_id(
3143 event_header_field_type) == CTF_TYPE_INTEGER,
3144 "Default event header \"id\" field is an integer");
3145 bt_put(event_header_field_type);
3146 event_header_field_type =
3147 bt_ctf_field_type_structure_get_field_type_by_name(
3148 ret_field_type, "timestamp");
3149 ok(event_header_field_type,
3150 "Default event header type contains a \"timestamp\" field");
3151 ok(bt_ctf_field_type_get_type_id(
3152 event_header_field_type) == CTF_TYPE_INTEGER,
3153 "Default event header \"timestamp\" field is an integer");
3154 bt_put(event_header_field_type);
3155 bt_put(ret_field_type);
3156
3157 /* Add a custom trace packet header field */
3158 ok(bt_ctf_trace_get_packet_header_type(NULL) == NULL,
3159 "bt_ctf_trace_get_packet_header_type handles NULL correctly");
3160 packet_header_type = bt_ctf_trace_get_packet_header_type(trace);
3161 ok(packet_header_type,
3162 "bt_ctf_trace_get_packet_header_type returns a packet header");
3163 ok(bt_ctf_field_type_get_type_id(packet_header_type) == CTF_TYPE_STRUCT,
3164 "bt_ctf_trace_get_packet_header_type returns a packet header of type struct");
3165 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
3166 packet_header_type, "magic");
3167 ok(ret_field_type, "Default packet header type contains a \"magic\" field");
3168 bt_put(ret_field_type);
3169 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
3170 packet_header_type, "uuid");
3171 ok(ret_field_type, "Default packet header type contains a \"uuid\" field");
3172 bt_put(ret_field_type);
3173 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
3174 packet_header_type, "stream_id");
3175 ok(ret_field_type, "Default packet header type contains a \"stream_id\" field");
3176 bt_put(ret_field_type);
3177
3178 packet_header_field_type = bt_ctf_field_type_integer_create(22);
3179 ok(!bt_ctf_field_type_structure_add_field(packet_header_type,
3180 packet_header_field_type, "custom_trace_packet_header_field"),
3181 "Added a custom trace packet header field successfully");
3182
3183 ok(bt_ctf_trace_set_packet_header_type(NULL, packet_header_type) < 0,
3184 "bt_ctf_trace_set_packet_header_type handles a NULL trace correctly");
3185 ok(bt_ctf_trace_set_packet_header_type(trace, NULL) < 0,
3186 "bt_ctf_trace_set_packet_header_type handles a NULL packet_header_type correctly");
3187 ok(!bt_ctf_trace_set_packet_header_type(trace, packet_header_type),
3188 "Set a trace packet_header_type successfully");
3189
3190 ok(bt_ctf_stream_class_get_packet_context_type(NULL) == NULL,
3191 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
3192
3193 /* Add a custom field to the stream class' packet context */
3194 packet_context_type = bt_ctf_stream_class_get_packet_context_type(stream_class);
3195 ok(packet_context_type,
3196 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
3197 ok(bt_ctf_field_type_get_type_id(packet_context_type) == CTF_TYPE_STRUCT,
3198 "Packet context is a structure");
3199
3200 ok(bt_ctf_stream_class_set_packet_context_type(NULL, packet_context_type),
3201 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
3202 ok(bt_ctf_stream_class_set_packet_context_type(stream_class, NULL),
3203 "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly");
3204
3205 integer_type = bt_ctf_field_type_integer_create(32);
3206 ok(bt_ctf_stream_class_set_packet_context_type(stream_class,
3207 integer_type) < 0,
3208 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
3209 /* Create a "uint5_t" equivalent custom packet context field */
3210 packet_context_field_type = bt_ctf_field_type_integer_create(5);
3211
3212 ret = bt_ctf_field_type_structure_add_field(packet_context_type,
3213 packet_context_field_type, "custom_packet_context_field");
3214 ok(ret == 0, "Packet context field added successfully");
3215
3216 /* Define a stream event context containing a my_integer field. */
3217 ok(bt_ctf_stream_class_get_event_context_type(NULL) == NULL,
3218 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
3219 ok(bt_ctf_stream_class_get_event_context_type(
3220 stream_class) == NULL,
3221 "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set.");
3222 stream_event_context_type = bt_ctf_field_type_structure_create();
3223 bt_ctf_field_type_structure_add_field(stream_event_context_type,
3224 integer_type, "common_event_context");
3225
3226 ok(bt_ctf_stream_class_set_event_context_type(NULL,
3227 stream_event_context_type) < 0,
3228 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
3229 ok(bt_ctf_stream_class_set_event_context_type(stream_class,
3230 NULL) < 0,
3231 "bt_ctf_stream_class_set_event_context_type handles a NULL event_context correctly");
3232 ok(bt_ctf_stream_class_set_event_context_type(stream_class,
3233 integer_type) < 0,
3234 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
3235
3236 ok(bt_ctf_stream_class_set_event_context_type(
3237 stream_class, stream_event_context_type) == 0,
3238 "Set a new stream event context type");
3239 ret_field_type = bt_ctf_stream_class_get_event_context_type(
3240 stream_class);
3241 ok(ret_field_type == stream_event_context_type,
3242 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
3243 bt_put(ret_field_type);
3244
3245 /* Instantiate a stream and append events */
3246 stream1 = bt_ctf_writer_create_stream(writer, stream_class);
3247 ok(stream1, "Instanciate a stream class from writer");
3248
3249 ok(bt_ctf_stream_get_class(NULL) == NULL,
3250 "bt_ctf_stream_get_class correctly handles NULL");
3251 ret_stream_class = bt_ctf_stream_get_class(stream1);
3252 ok(ret_stream_class,
3253 "bt_ctf_stream_get_class returns a stream class");
3254 ok(ret_stream_class == stream_class,
3255 "Returned stream class is of the correct type");
3256
3257 /*
3258 * Packet header, packet context, event header, and stream
3259 * event context types were copied for the resolving
3260 * process
3261 */
3262 BT_PUT(packet_header_type);
3263 BT_PUT(packet_context_type);
3264 BT_PUT(stream_event_context_type);
3265 packet_header_type = bt_ctf_trace_get_packet_header_type(trace);
3266 assert(packet_header_type);
3267 packet_context_type =
3268 bt_ctf_stream_class_get_packet_context_type(stream_class);
3269 assert(packet_context_type);
3270 stream_event_context_type =
3271 bt_ctf_stream_class_get_event_context_type(stream_class);
3272 assert(stream_event_context_type);
3273
3274 /*
3275 * Try to modify the packet context type after a stream has been
3276 * created.
3277 */
3278 ret = bt_ctf_field_type_structure_add_field(packet_header_type,
3279 packet_header_field_type, "should_fail");
3280 ok(ret < 0,
3281 "Trace packet header type can't be modified once a stream has been instanciated");
3282
3283 /*
3284 * Try to modify the packet context type after a stream has been
3285 * created.
3286 */
3287 ret = bt_ctf_field_type_structure_add_field(packet_context_type,
3288 packet_context_field_type, "should_fail");
3289 ok(ret < 0,
3290 "Packet context type can't be modified once a stream has been instanciated");
3291
3292 /*
3293 * Try to modify the stream event context type after a stream has been
3294 * created.
3295 */
3296 ret = bt_ctf_field_type_structure_add_field(stream_event_context_type,
3297 integer_type, "should_fail");
3298 ok(ret < 0,
3299 "Stream event context type can't be modified once a stream has been instanciated");
3300
3301 /* Should fail after instanciating a stream (frozen) */
3302 ok(bt_ctf_stream_class_set_clock(stream_class, clock),
3303 "Changes to a stream class that was already instantiated fail");
3304
3305 /* Populate the custom packet header field only once for all tests */
3306 ok(bt_ctf_stream_get_packet_header(NULL) == NULL,
3307 "bt_ctf_stream_get_packet_header handles NULL correctly");
3308 packet_header = bt_ctf_stream_get_packet_header(stream1);
3309 ok(packet_header,
3310 "bt_ctf_stream_get_packet_header returns a packet header");
3311 ret_field_type = bt_ctf_field_get_type(packet_header);
3312 ok(ret_field_type == packet_header_type,
3313 "Stream returns a packet header of the appropriate type");
3314 bt_put(ret_field_type);
3315 packet_header_field = bt_ctf_field_structure_get_field(packet_header,
3316 "custom_trace_packet_header_field");
3317 ok(packet_header_field,
3318 "Packet header structure contains a custom field with the appropriate name");
3319 ret_field_type = bt_ctf_field_get_type(packet_header_field);
3320 ok(bt_ctf_field_type_compare(ret_field_type, packet_header_field_type) == 0,
3321 "Custom packet header field is of the expected type");
3322 ok(!bt_ctf_field_unsigned_integer_set_value(packet_header_field,
3323 54321), "Set custom packet header value successfully");
3324 ok(bt_ctf_stream_set_packet_header(stream1, NULL) < 0,
3325 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
3326 ok(bt_ctf_stream_set_packet_header(NULL, packet_header) < 0,
3327 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
3328 ok(bt_ctf_stream_set_packet_header(stream1, packet_header_field) < 0,
3329 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
3330 ok(!bt_ctf_stream_set_packet_header(stream1, packet_header),
3331 "Successfully set a stream's packet header");
3332
3333 ok(bt_ctf_writer_add_environment_field(writer, "new_field", "test") == 0,
3334 "Add environment field to writer after stream creation");
3335
3336 test_instanciate_event_before_stream(writer);
3337
3338 append_simple_event(stream_class, stream1, clock);
3339
3340 packet_resize_test(stream_class, stream1, clock);
3341
3342 append_complex_event(stream_class, stream1, clock);
3343
3344 append_existing_event_class(stream_class);
3345
3346 test_empty_stream(writer);
3347
3348 test_custom_event_header_stream(writer);
3349
3350 metadata_string = bt_ctf_writer_get_metadata_string(writer);
3351 ok(metadata_string, "Get metadata string");
3352
3353 bt_ctf_writer_flush_metadata(writer);
3354 validate_metadata(argv[1], metadata_path);
3355 validate_trace(argv[2], trace_path);
3356
3357 bt_put(clock);
3358 bt_put(ret_stream_class);
3359 bt_put(writer);
3360 bt_put(stream1);
3361 bt_put(packet_context_type);
3362 bt_put(packet_context_field_type);
3363 bt_put(integer_type);
3364 bt_put(stream_event_context_type);
3365 bt_put(ret_field_type);
3366 bt_put(packet_header_type);
3367 bt_put(packet_header_field_type);
3368 bt_put(packet_header);
3369 bt_put(packet_header_field);
3370 bt_put(trace);
3371 free(metadata_string);
3372 bt_put(stream_class);
3373
3374 /* Remove all trace files and delete temporary trace directory */
3375 DIR *trace_dir = opendir(trace_path);
3376 if (!trace_dir) {
3377 perror("# opendir");
3378 return -1;
3379 }
3380
3381 struct dirent *entry;
3382 while ((entry = readdir(trace_dir))) {
3383 struct stat st;
3384 char filename[PATH_MAX];
3385
3386 if (snprintf(filename, sizeof(filename), "%s/%s",
3387 trace_path, entry->d_name) <= 0) {
3388 continue;
3389 }
3390
3391 if (stat(entry->d_name, &st)) {
3392 continue;
3393 }
3394
3395 if (S_ISREG(st.st_mode)) {
3396 unlinkat(bt_dirfd(trace_dir), entry->d_name, 0);
3397 }
3398 }
3399
3400 rmdir(trace_path);
3401 closedir(trace_dir);
3402 return 0;
3403 }
This page took 0.192803 seconds and 5 git commands to generate.