bfa300d4b7f95ea0d7cfa69d1cc165572a9ddb47
[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 #define _GNU_SOURCE
23 #include <babeltrace/ctf-writer/writer.h>
24 #include <babeltrace/ctf-writer/clock.h>
25 #include <babeltrace/ctf-writer/stream.h>
26 #include <babeltrace/ctf-writer/event.h>
27 #include <babeltrace/ctf-writer/event-types.h>
28 #include <babeltrace/ctf-writer/event-fields.h>
29 #include <babeltrace/ctf-ir/stream-class.h>
30 #include <babeltrace/ctf/events.h>
31 #include <babeltrace/objects.h>
32 #include <unistd.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <sys/utsname.h>
36 #include <babeltrace/compat/limits.h>
37 #include <string.h>
38 #include <assert.h>
39 #include <sys/wait.h>
40 #include <fcntl.h>
41 #include <dirent.h>
42 #include "tap/tap.h"
43 #include <math.h>
44 #include <float.h>
45
46 #define METADATA_LINE_SIZE 512
47 #define SEQUENCE_TEST_LENGTH 10
48 #define ARRAY_TEST_LENGTH 5
49 #define PACKET_RESIZE_TEST_LENGTH 100000
50
51 #define DEFAULT_CLOCK_FREQ 1000000000
52 #define DEFAULT_CLOCK_PRECISION 1
53 #define DEFAULT_CLOCK_OFFSET 0
54 #define DEFAULT_CLOCK_OFFSET_S 0
55 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
56 #define DEFAULT_CLOCK_TIME 0
57
58 static uint64_t current_time = 42;
59
60 /* Return 1 if uuids match, zero if different. */
61 int uuid_match(const unsigned char *uuid_a, const unsigned char *uuid_b)
62 {
63 int ret = 0;
64 int i;
65
66 if (!uuid_a || !uuid_b) {
67 goto end;
68 }
69
70 for (i = 0; i < 16; i++) {
71 if (uuid_a[i] != uuid_b[i]) {
72 goto end;
73 }
74 }
75
76 ret = 1;
77 end:
78 return ret;
79 }
80
81 void validate_metadata(char *parser_path, char *metadata_path)
82 {
83 int ret = 0;
84 char parser_output_path[] = "/tmp/parser_output_XXXXXX";
85 int parser_output_fd = -1, metadata_fd = -1;
86
87 if (!metadata_path) {
88 ret = -1;
89 goto result;
90 }
91
92 parser_output_fd = mkstemp(parser_output_path);
93 metadata_fd = open(metadata_path, O_RDONLY);
94
95 unlink(parser_output_path);
96
97 if (parser_output_fd == -1 || metadata_fd == -1) {
98 diag("Failed create temporary files for metadata parsing.");
99 ret = -1;
100 goto result;
101 }
102
103 pid_t pid = fork();
104 if (pid) {
105 int status = 0;
106 waitpid(pid, &status, 0);
107 ret = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
108 } else {
109 /* ctf-parser-test expects a metadata string on stdin. */
110 ret = dup2(metadata_fd, STDIN_FILENO);
111 if (ret < 0) {
112 perror("# dup2 metadata_fd to STDIN");
113 goto result;
114 }
115
116 ret = dup2(parser_output_fd, STDOUT_FILENO);
117 if (ret < 0) {
118 perror("# dup2 parser_output_fd to STDOUT");
119 goto result;
120 }
121
122 ret = dup2(parser_output_fd, STDERR_FILENO);
123 if (ret < 0) {
124 perror("# dup2 parser_output_fd to STDERR");
125 goto result;
126 }
127
128 execl(parser_path, "ctf-parser-test", NULL);
129 perror("# Could not launch the ctf metadata parser process");
130 exit(-1);
131 }
132 result:
133 ok(ret == 0, "Metadata string is valid");
134
135 if (ret && metadata_fd >= 0 && parser_output_fd >= 0) {
136 char *line;
137 size_t len = METADATA_LINE_SIZE;
138 FILE *metadata_fp = NULL, *parser_output_fp = NULL;
139
140 metadata_fp = fdopen(metadata_fd, "r");
141 if (!metadata_fp) {
142 perror("fdopen on metadata_fd");
143 goto close_fp;
144 }
145 metadata_fd = -1;
146
147 parser_output_fp = fdopen(parser_output_fd, "r");
148 if (!parser_output_fp) {
149 perror("fdopen on parser_output_fd");
150 goto close_fp;
151 }
152 parser_output_fd = -1;
153
154 line = malloc(len);
155 if (!line) {
156 diag("malloc failure");
157 }
158
159 rewind(metadata_fp);
160
161 /* Output the metadata and parser output as diagnostic */
162 while (getline(&line, &len, metadata_fp) > 0) {
163 fprintf(stderr, "# %s", line);
164 }
165
166 rewind(parser_output_fp);
167 while (getline(&line, &len, parser_output_fp) > 0) {
168 fprintf(stderr, "# %s", line);
169 }
170
171 free(line);
172 close_fp:
173 if (metadata_fp) {
174 if (fclose(metadata_fp)) {
175 diag("fclose failure");
176 }
177 }
178 if (parser_output_fp) {
179 if (fclose(parser_output_fp)) {
180 diag("fclose failure");
181 }
182 }
183 }
184
185 if (parser_output_fd >= 0) {
186 if (close(parser_output_fd)) {
187 diag("close error");
188 }
189 }
190 if (metadata_fd >= 0) {
191 if (close(metadata_fd)) {
192 diag("close error");
193 }
194 }
195 }
196
197 void validate_trace(char *parser_path, char *trace_path)
198 {
199 int ret = 0;
200 char babeltrace_output_path[] = "/tmp/babeltrace_output_XXXXXX";
201 int babeltrace_output_fd = -1;
202
203 if (!trace_path) {
204 ret = -1;
205 goto result;
206 }
207
208 babeltrace_output_fd = mkstemp(babeltrace_output_path);
209 unlink(babeltrace_output_path);
210
211 if (babeltrace_output_fd == -1) {
212 diag("Failed to create a temporary file for trace parsing.");
213 ret = -1;
214 goto result;
215 }
216
217 pid_t pid = fork();
218 if (pid) {
219 int status = 0;
220 waitpid(pid, &status, 0);
221 ret = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
222 } else {
223 ret = dup2(babeltrace_output_fd, STDOUT_FILENO);
224 if (ret < 0) {
225 perror("# dup2 babeltrace_output_fd to STDOUT");
226 goto result;
227 }
228
229 ret = dup2(babeltrace_output_fd, STDERR_FILENO);
230 if (ret < 0) {
231 perror("# dup2 babeltrace_output_fd to STDERR");
232 goto result;
233 }
234
235 execl(parser_path, "babeltrace", trace_path, NULL);
236 perror("# Could not launch the babeltrace process");
237 exit(-1);
238 }
239 result:
240 ok(ret == 0, "Babeltrace could read the resulting trace");
241
242 if (ret && babeltrace_output_fd >= 0) {
243 char *line;
244 size_t len = METADATA_LINE_SIZE;
245 FILE *babeltrace_output_fp = NULL;
246
247 babeltrace_output_fp = fdopen(babeltrace_output_fd, "r");
248 if (!babeltrace_output_fp) {
249 perror("fdopen on babeltrace_output_fd");
250 goto close_fp;
251 }
252 babeltrace_output_fd = -1;
253
254 line = malloc(len);
255 if (!line) {
256 diag("malloc error");
257 }
258 rewind(babeltrace_output_fp);
259 while (getline(&line, &len, babeltrace_output_fp) > 0) {
260 diag("%s", line);
261 }
262
263 free(line);
264 close_fp:
265 if (babeltrace_output_fp) {
266 if (fclose(babeltrace_output_fp)) {
267 diag("fclose error");
268 }
269 }
270 }
271
272 if (babeltrace_output_fd >= 0) {
273 if (close(babeltrace_output_fd)) {
274 diag("close error");
275 }
276 }
277 }
278
279 void append_simple_event(struct bt_ctf_stream_class *stream_class,
280 struct bt_ctf_stream *stream, struct bt_ctf_clock *clock)
281 {
282 /* Create and add a simple event class */
283 struct bt_ctf_event_class *simple_event_class =
284 bt_ctf_event_class_create("Simple Event");
285 struct bt_ctf_field_type *uint_12_type =
286 bt_ctf_field_type_integer_create(12);
287 struct bt_ctf_field_type *int_64_type =
288 bt_ctf_field_type_integer_create(64);
289 struct bt_ctf_field_type *float_type =
290 bt_ctf_field_type_floating_point_create();
291 struct bt_ctf_field_type *enum_type;
292 struct bt_ctf_field_type *enum_type_unsigned =
293 bt_ctf_field_type_enumeration_create(uint_12_type);
294 struct bt_ctf_field_type *event_context_type =
295 bt_ctf_field_type_structure_create();
296 struct bt_ctf_field_type *returned_type;
297 struct bt_ctf_event *simple_event;
298 struct bt_ctf_field *integer_field;
299 struct bt_ctf_field *float_field;
300 struct bt_ctf_field *enum_field;
301 struct bt_ctf_field *enum_field_unsigned;
302 struct bt_ctf_field *enum_container_field;
303 const char *mapping_name_test = "truie";
304 const double double_test_value = 3.1415;
305 struct bt_ctf_field *enum_container_field_unsigned;
306 const char *mapping_name_negative_test = "negative_value";
307 const char *ret_char;
308 double ret_double;
309 int64_t ret_range_start_int64_t, ret_range_end_int64_t;
310 uint64_t ret_range_start_uint64_t, ret_range_end_uint64_t;
311 struct bt_ctf_clock *ret_clock;
312 struct bt_ctf_event_class *ret_event_class;
313 struct bt_ctf_field *packet_context;
314 struct bt_ctf_field *packet_context_field;
315 struct bt_ctf_field *stream_event_context;
316 struct bt_ctf_field *stream_event_context_field;
317 struct bt_ctf_field *event_context;
318 struct bt_ctf_field *event_context_field;
319
320 ok(uint_12_type, "Create an unsigned integer type");
321
322 bt_ctf_field_type_integer_set_signed(int_64_type, 1);
323 ok(int_64_type, "Create a signed integer type");
324 enum_type = bt_ctf_field_type_enumeration_create(int_64_type);
325
326 returned_type = bt_ctf_field_type_enumeration_get_container_type(enum_type);
327 ok(returned_type == int_64_type, "bt_ctf_field_type_enumeration_get_container_type returns the right type");
328 ok(!bt_ctf_field_type_enumeration_get_container_type(NULL), "bt_ctf_field_type_enumeration_get_container_type handles NULL correctly");
329 ok(!bt_ctf_field_type_enumeration_create(enum_type),
330 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
331 bt_ctf_field_type_put(returned_type);
332
333 bt_ctf_field_type_set_alignment(float_type, 32);
334 ok(bt_ctf_field_type_get_alignment(NULL) < 0,
335 "bt_ctf_field_type_get_alignment handles NULL correctly");
336 ok(bt_ctf_field_type_get_alignment(float_type) == 32,
337 "bt_ctf_field_type_get_alignment returns a correct value");
338
339 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type, 11) == 0,
340 "Set a floating point type's exponent digit count");
341 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type, 53) == 0,
342 "Set a floating point type's mantissa digit count");
343
344 ok(bt_ctf_field_type_floating_point_get_exponent_digits(NULL) < 0,
345 "bt_ctf_field_type_floating_point_get_exponent_digits handles NULL properly");
346 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(NULL) < 0,
347 "bt_ctf_field_type_floating_point_get_mantissa_digits handles NULL properly");
348 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type) == 11,
349 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
350 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type) == 53,
351 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
352
353 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
354 mapping_name_negative_test, -12345, 0) == 0,
355 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
356 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
357 "escaping; \"test\"", 1, 1) == 0,
358 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
359 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
360 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
361 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
362 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type,
363 "event clock int float", 5, 22) == 0,
364 "Accept enumeration mapping strings containing reserved keywords");
365 bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test,
366 42, 42);
367 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test,
368 43, 51), "bt_ctf_field_type_enumeration_add_mapping rejects duplicate mapping names");
369 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, "something",
370 -500, -400), "bt_ctf_field_type_enumeration_add_mapping rejects overlapping enum entries");
371 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test,
372 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
373 bt_ctf_field_type_enumeration_add_mapping(enum_type, "another entry", -42000, -13000);
374
375 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(NULL, -42) < 0,
376 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles a NULL field type correctly");
377 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, 1000000) < 0,
378 "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles invalid values correctly");
379 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, -55) == 1,
380 "bt_ctf_field_type_enumeration_get_mapping_index_by_value returns the correct index");
381
382 ok(bt_ctf_event_class_add_field(simple_event_class, enum_type,
383 "enum_field") == 0, "Add signed enumeration field to event");
384
385 ok(bt_ctf_field_type_enumeration_get_mapping(NULL, 0, &ret_char,
386 &ret_range_start_int64_t, &ret_range_end_int64_t) < 0,
387 "bt_ctf_field_type_enumeration_get_mapping handles a NULL enumeration correctly");
388 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, NULL,
389 &ret_range_start_int64_t, &ret_range_end_int64_t) < 0,
390 "bt_ctf_field_type_enumeration_get_mapping handles a NULL string correctly");
391 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, &ret_char,
392 NULL, &ret_range_end_int64_t) < 0,
393 "bt_ctf_field_type_enumeration_get_mapping handles a NULL start correctly");
394 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, &ret_char,
395 &ret_range_start_int64_t, NULL) < 0,
396 "bt_ctf_field_type_enumeration_get_mapping handles a NULL end correctly");
397 ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 5, &ret_char,
398 &ret_range_start_int64_t, &ret_range_end_int64_t) == 0,
399 "bt_ctf_field_type_enumeration_get_mapping returns a value");
400 ok(!strcmp(ret_char, mapping_name_test),
401 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping name");
402 ok(ret_range_start_int64_t == 42,
403 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping start");
404 ok(ret_range_end_int64_t == 42,
405 "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping end");
406
407 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned,
408 "escaping; \"test\"", 0, 0) == 0,
409 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing quotes");
410 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned,
411 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
412 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing special characters");
413 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned,
414 "event clock int float", 5, 22) == 0,
415 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing reserved keywords");
416 bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test,
417 42, 42);
418 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test,
419 43, 51), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects duplicate mapping names");
420 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, "something",
421 7, 8), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects overlapping enum entries");
422 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test,
423 55, 54), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects mapping where end < start");
424 ok(bt_ctf_event_class_add_field(simple_event_class, enum_type_unsigned,
425 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
426
427 ok(bt_ctf_field_type_enumeration_get_mapping_count(NULL) < 0,
428 "bt_ctf_field_type_enumeration_get_mapping_count handles NULL correctly");
429 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned) == 4,
430 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
431
432 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(NULL, 0, &ret_char,
433 &ret_range_start_uint64_t, &ret_range_end_uint64_t) < 0,
434 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL enumeration correctly");
435 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, NULL,
436 &ret_range_start_uint64_t, &ret_range_end_uint64_t) < 0,
437 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL string correctly");
438 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, &ret_char,
439 NULL, &ret_range_end_uint64_t) < 0,
440 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL start correctly");
441 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, &ret_char,
442 &ret_range_start_uint64_t, NULL) < 0,
443 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL end correctly");
444 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 3, &ret_char,
445 &ret_range_start_uint64_t, &ret_range_end_uint64_t) == 0,
446 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a value");
447 ok(!strcmp(ret_char, mapping_name_test),
448 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping name");
449 ok(ret_range_start_uint64_t == 42,
450 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping start");
451 ok(ret_range_end_uint64_t == 42,
452 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping end");
453
454 bt_ctf_event_class_add_field(simple_event_class, uint_12_type,
455 "integer_field");
456 bt_ctf_event_class_add_field(simple_event_class, float_type,
457 "float_field");
458
459 assert(!bt_ctf_event_class_set_id(simple_event_class, 13));
460
461 /* Set an event context type which will contain a single integer*/
462 ok(!bt_ctf_field_type_structure_add_field(event_context_type, uint_12_type,
463 "event_specific_context"),
464 "Add event specific context field");
465 ok(bt_ctf_event_class_get_context_type(NULL) == NULL,
466 "bt_ctf_event_class_get_context_type handles NULL correctly");
467 ok(bt_ctf_event_class_get_context_type(simple_event_class) == NULL,
468 "bt_ctf_event_class_get_context_type returns NULL when no event context type is set");
469
470 ok(bt_ctf_event_class_set_context_type(simple_event_class, NULL) < 0,
471 "bt_ctf_event_class_set_context_type handles a NULL context type correctly");
472 ok(bt_ctf_event_class_set_context_type(NULL, event_context_type) < 0,
473 "bt_ctf_event_class_set_context_type handles a NULL event class correctly");
474 ok(!bt_ctf_event_class_set_context_type(simple_event_class, event_context_type),
475 "Set an event class' context type successfully");
476 returned_type = bt_ctf_event_class_get_context_type(simple_event_class);
477 ok(returned_type == event_context_type,
478 "bt_ctf_event_class_get_context_type returns the appropriate type");
479 bt_ctf_field_type_put(returned_type);
480
481 bt_ctf_stream_class_add_event_class(stream_class, simple_event_class);
482
483 ok(bt_ctf_stream_class_get_event_class_count(NULL) < 0,
484 "bt_ctf_stream_class_get_event_class_count handles NULL correctly");
485 ok(bt_ctf_stream_class_get_event_class_count(stream_class) == 1,
486 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
487 ok(bt_ctf_stream_class_get_event_class(NULL, 0) == NULL,
488 "bt_ctf_stream_class_get_event_class handles NULL correctly");
489 ok(bt_ctf_stream_class_get_event_class(stream_class, 8724) == NULL,
490 "bt_ctf_stream_class_get_event_class handles invalid indexes correctly");
491 ret_event_class = bt_ctf_stream_class_get_event_class(stream_class, 0);
492 ok(ret_event_class == simple_event_class,
493 "bt_ctf_stream_class_get_event_class returns the correct event class");
494 bt_ctf_event_class_put(ret_event_class);
495 ok(!bt_ctf_stream_class_get_event_class_by_id(NULL, 0),
496 "bt_ctf_stream_class_get_event_class_by_id handles NULL correctly");
497 ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class, 2),
498 "bt_ctf_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
499 ret_event_class =
500 bt_ctf_stream_class_get_event_class_by_id(stream_class, 13);
501 ok(ret_event_class == simple_event_class,
502 "bt_ctf_stream_class_get_event_class_by_id returns a correct event class");
503 bt_ctf_event_class_put(ret_event_class);
504
505 ok(bt_ctf_stream_class_get_event_class_by_name(NULL, "some event name") == NULL,
506 "bt_ctf_stream_class_get_event_class_by_name handles a NULL stream class correctly");
507 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, NULL) == NULL,
508 "bt_ctf_stream_class_get_event_class_by_name handles a NULL event class name correctly");
509 ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, "some event name") == NULL,
510 "bt_ctf_stream_class_get_event_class_by_name handles non-existing event class names correctly");
511 ret_event_class = bt_ctf_stream_class_get_event_class_by_name(stream_class, "Simple Event");
512 ok(ret_event_class == simple_event_class,
513 "bt_ctf_stream_class_get_event_class_by_name returns a correct event class");
514 bt_ctf_event_class_put(ret_event_class);
515
516 simple_event = bt_ctf_event_create(simple_event_class);
517 ok(simple_event,
518 "Instantiate an event containing a single integer field");
519
520 ok(bt_ctf_event_get_clock(NULL) == NULL,
521 "bt_ctf_event_get_clock handles NULL correctly");
522 ret_clock = bt_ctf_event_get_clock(simple_event);
523 ok(ret_clock == clock,
524 "bt_ctf_event_get_clock returns a correct clock");
525 bt_ctf_clock_put(clock);
526
527 integer_field = bt_ctf_field_create(uint_12_type);
528 bt_ctf_field_unsigned_integer_set_value(integer_field, 42);
529 ok(bt_ctf_event_set_payload(simple_event, "integer_field",
530 integer_field) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
531
532 float_field = bt_ctf_event_get_payload(simple_event, "float_field");
533 ok(bt_ctf_field_floating_point_get_value(float_field, &ret_double),
534 "bt_ctf_field_floating_point_get_value fails on an unset float field");
535 bt_ctf_field_floating_point_set_value(float_field, double_test_value);
536 ok(bt_ctf_field_floating_point_get_value(NULL, &ret_double),
537 "bt_ctf_field_floating_point_get_value properly handles a NULL field");
538 ok(bt_ctf_field_floating_point_get_value(float_field, NULL),
539 "bt_ctf_field_floating_point_get_value properly handles a NULL return value pointer");
540 ok(!bt_ctf_field_floating_point_get_value(float_field, &ret_double),
541 "bt_ctf_field_floating_point_get_value returns a double value");
542 ok(fabs(ret_double - double_test_value) <= DBL_EPSILON,
543 "bt_ctf_field_floating_point_get_value returns a correct value");
544
545 enum_field = bt_ctf_field_create(enum_type);
546 ret_char = bt_ctf_field_enumeration_get_mapping_name(NULL);
547 ok(!ret_char, "bt_ctf_field_enumeration_get_mapping_name handles NULL correctly");
548 ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field);
549 ok(!ret_char, "bt_ctf_field_enumeration_get_mapping_name returns NULL if the enumeration's container field is unset");
550 enum_container_field = bt_ctf_field_enumeration_get_container(
551 enum_field);
552 ok(bt_ctf_field_signed_integer_set_value(
553 enum_container_field, -42) == 0,
554 "Set signed enumeration container value");
555 ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field);
556 ok(!strcmp(ret_char, mapping_name_negative_test),
557 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an signed container");
558 bt_ctf_event_set_payload(simple_event, "enum_field", enum_field);
559
560 enum_field_unsigned = bt_ctf_field_create(enum_type_unsigned);
561 enum_container_field_unsigned = bt_ctf_field_enumeration_get_container(
562 enum_field_unsigned);
563 ok(bt_ctf_field_unsigned_integer_set_value(
564 enum_container_field_unsigned, 42) == 0,
565 "Set unsigned enumeration container value");
566 bt_ctf_event_set_payload(simple_event, "enum_field_unsigned",
567 enum_field_unsigned);
568 ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field_unsigned);
569 ok(!strcmp(ret_char, mapping_name_test),
570 "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an unsigned container");
571
572 ok(bt_ctf_clock_set_time(clock, current_time) == 0, "Set clock time");
573
574 /* Populate stream event context */
575 stream_event_context = bt_ctf_stream_get_event_context(stream);
576 stream_event_context_field = bt_ctf_field_structure_get_field(
577 stream_event_context, "common_event_context");
578 bt_ctf_field_unsigned_integer_set_value(stream_event_context_field, 42);
579
580 /* Populate the event's context */
581 ok(bt_ctf_event_get_event_context(NULL) == NULL,
582 "bt_ctf_event_get_event_context handles NULL correctly");
583 event_context = bt_ctf_event_get_event_context(simple_event);
584 ok(event_context,
585 "bt_ctf_event_get_event_context returns a field");
586 returned_type = bt_ctf_field_get_type(event_context);
587 ok(returned_type == event_context_type,
588 "bt_ctf_event_get_event_context returns a field of the appropriate type");
589 event_context_field = bt_ctf_field_structure_get_field(event_context,
590 "event_specific_context");
591 ok(!bt_ctf_field_unsigned_integer_set_value(event_context_field, 1234),
592 "Successfully set an event context's value");
593 ok(bt_ctf_event_set_event_context(NULL, event_context) < 0,
594 "bt_ctf_event_set_event_context handles a NULL event correctly");
595 ok(bt_ctf_event_set_event_context(simple_event, NULL) < 0,
596 "bt_ctf_event_set_event_context handles a NULL event context correctly");
597 ok(bt_ctf_event_set_event_context(simple_event, event_context_field) < 0,
598 "bt_ctf_event_set_event_context rejects a context of the wrong type");
599 ok(!bt_ctf_event_set_event_context(simple_event, event_context),
600 "Set an event context successfully");
601
602 ok(bt_ctf_stream_append_event(stream, simple_event) == 0,
603 "Append simple event to trace stream");
604
605 ok(bt_ctf_stream_get_packet_context(NULL) == NULL,
606 "bt_ctf_stream_get_packet_context handles NULL correctly");
607 packet_context = bt_ctf_stream_get_packet_context(stream);
608 ok(packet_context,
609 "bt_ctf_stream_get_packet_context returns a packet context");
610
611 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
612 "packet_size");
613 ok(packet_context_field,
614 "Packet context contains the default packet_size field.");
615 bt_ctf_field_put(packet_context_field);
616 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
617 "custom_packet_context_field");
618 ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field, 8) == 0,
619 "Custom packet context field value successfully set.");
620
621 ok(bt_ctf_stream_set_packet_context(NULL, packet_context_field) < 0,
622 "bt_ctf_stream_set_packet_context handles a NULL stream correctly");
623 ok(bt_ctf_stream_set_packet_context(stream, NULL) < 0,
624 "bt_ctf_stream_set_packet_context handles a NULL packet context correctly");
625 ok(bt_ctf_stream_set_packet_context(stream, packet_context) == 0,
626 "Successfully set a stream's packet context");
627
628 ok(bt_ctf_stream_flush(stream) == 0,
629 "Flush trace stream with one event");
630
631 bt_ctf_event_class_put(simple_event_class);
632 bt_ctf_event_put(simple_event);
633 bt_ctf_field_type_put(uint_12_type);
634 bt_ctf_field_type_put(int_64_type);
635 bt_ctf_field_type_put(float_type);
636 bt_ctf_field_type_put(enum_type);
637 bt_ctf_field_type_put(enum_type_unsigned);
638 bt_ctf_field_type_put(returned_type);
639 bt_ctf_field_type_put(event_context_type);
640 bt_ctf_field_put(integer_field);
641 bt_ctf_field_put(float_field);
642 bt_ctf_field_put(enum_field);
643 bt_ctf_field_put(enum_field_unsigned);
644 bt_ctf_field_put(enum_container_field);
645 bt_ctf_field_put(enum_container_field_unsigned);
646 bt_ctf_field_put(packet_context);
647 bt_ctf_field_put(packet_context_field);
648 bt_ctf_field_put(stream_event_context);
649 bt_ctf_field_put(stream_event_context_field);
650 bt_ctf_field_put(event_context);
651 bt_ctf_field_put(event_context_field);
652 }
653
654 void append_complex_event(struct bt_ctf_stream_class *stream_class,
655 struct bt_ctf_stream *stream, struct bt_ctf_clock *clock)
656 {
657 int i;
658 const char *complex_test_event_string = "Complex Test Event";
659 const char *test_string = "Test string";
660 struct bt_ctf_field_type *uint_35_type =
661 bt_ctf_field_type_integer_create(35);
662 struct bt_ctf_field_type *int_16_type =
663 bt_ctf_field_type_integer_create(16);
664 struct bt_ctf_field_type *uint_3_type =
665 bt_ctf_field_type_integer_create(3);
666 struct bt_ctf_field_type *enum_variant_type =
667 bt_ctf_field_type_enumeration_create(uint_3_type);
668 struct bt_ctf_field_type *variant_type =
669 bt_ctf_field_type_variant_create(enum_variant_type,
670 "variant_selector");
671 struct bt_ctf_field_type *string_type =
672 bt_ctf_field_type_string_create();
673 struct bt_ctf_field_type *sequence_type;
674 struct bt_ctf_field_type *array_type;
675 struct bt_ctf_field_type *inner_structure_type =
676 bt_ctf_field_type_structure_create();
677 struct bt_ctf_field_type *complex_structure_type =
678 bt_ctf_field_type_structure_create();
679 struct bt_ctf_field_type *ret_field_type;
680 struct bt_ctf_event_class *event_class;
681 struct bt_ctf_event *event;
682 struct bt_ctf_field *uint_35_field, *int_16_field, *a_string_field,
683 *inner_structure_field, *complex_structure_field,
684 *a_sequence_field, *enum_variant_field, *enum_container_field,
685 *variant_field, *an_array_field, *ret_field;
686 uint64_t ret_unsigned_int;
687 int64_t ret_signed_int;
688 const char *ret_string;
689 struct bt_ctf_stream_class *ret_stream_class;
690 struct bt_ctf_event_class *ret_event_class;
691 struct bt_ctf_field *packet_context, *packet_context_field;
692
693 bt_ctf_field_type_set_alignment(int_16_type, 32);
694 bt_ctf_field_type_integer_set_signed(int_16_type, 1);
695 bt_ctf_field_type_integer_set_base(uint_35_type,
696 BT_CTF_INTEGER_BASE_HEXADECIMAL);
697
698 array_type = bt_ctf_field_type_array_create(int_16_type, ARRAY_TEST_LENGTH);
699 sequence_type = bt_ctf_field_type_sequence_create(int_16_type,
700 "seq_len");
701
702 ok(bt_ctf_field_type_array_get_element_type(NULL) == NULL,
703 "bt_ctf_field_type_array_get_element_type handles NULL correctly");
704 ret_field_type = bt_ctf_field_type_array_get_element_type(
705 array_type);
706 ok(ret_field_type == int_16_type,
707 "bt_ctf_field_type_array_get_element_type returns the correct type");
708 bt_ctf_field_type_put(ret_field_type);
709
710 ok(bt_ctf_field_type_array_get_length(NULL) < 0,
711 "bt_ctf_field_type_array_get_length handles NULL correctly");
712 ok(bt_ctf_field_type_array_get_length(array_type) == ARRAY_TEST_LENGTH,
713 "bt_ctf_field_type_array_get_length returns the correct length");
714
715 bt_ctf_field_type_structure_add_field(inner_structure_type,
716 uint_35_type, "seq_len");
717 bt_ctf_field_type_structure_add_field(inner_structure_type,
718 sequence_type, "a_sequence");
719 bt_ctf_field_type_structure_add_field(inner_structure_type,
720 array_type, "an_array");
721
722 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type,
723 "UINT3_TYPE", 0, 0);
724 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type,
725 "INT16_TYPE", 1, 1);
726 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type,
727 "UINT35_TYPE", 2, 7);
728
729 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL,
730 "INT16_TYPE") < 0,
731 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly");
732 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
733 enum_variant_type, NULL) < 0,
734 "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly");
735 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(
736 enum_variant_type, "INT16_TYPE") == 1,
737 "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index");
738
739 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL, 1) < 0,
740 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly");
741 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, -42) < 0,
742 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly");
743 ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, 5) == 2,
744 "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index");
745
746 ok(bt_ctf_field_type_variant_add_field(variant_type, uint_3_type,
747 "An unknown entry"), "Reject a variant field based on an unknown tag value");
748 ok(bt_ctf_field_type_variant_add_field(variant_type, uint_3_type,
749 "UINT3_TYPE") == 0, "Add a field to a variant");
750 bt_ctf_field_type_variant_add_field(variant_type, int_16_type,
751 "INT16_TYPE");
752 bt_ctf_field_type_variant_add_field(variant_type, uint_35_type,
753 "UINT35_TYPE");
754
755 ok(bt_ctf_field_type_variant_get_tag_type(NULL) == NULL,
756 "bt_ctf_field_type_variant_get_tag_type handles NULL correctly");
757 ret_field_type = bt_ctf_field_type_variant_get_tag_type(variant_type);
758 ok(ret_field_type == enum_variant_type,
759 "bt_ctf_field_type_variant_get_tag_type returns a correct tag type");
760 bt_ctf_field_type_put(ret_field_type);
761
762 ok(bt_ctf_field_type_variant_get_tag_name(NULL) == NULL,
763 "bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
764 ret_string = bt_ctf_field_type_variant_get_tag_name(variant_type);
765 ok(!strcmp(ret_string, "variant_selector"),
766 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
767 ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL,
768 "INT16_TYPE") == NULL,
769 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
770 ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type,
771 NULL) == NULL,
772 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
773 ret_field_type = bt_ctf_field_type_variant_get_field_type_by_name(
774 variant_type, "INT16_TYPE");
775 ok(ret_field_type == int_16_type,
776 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
777 bt_ctf_field_type_put(ret_field_type);
778
779 ok(bt_ctf_field_type_variant_get_field_count(NULL) < 0,
780 "bt_ctf_field_type_variant_get_field_count handles NULL correctly");
781 ok(bt_ctf_field_type_variant_get_field_count(variant_type) == 3,
782 "bt_ctf_field_type_variant_get_field_count returns the correct count");
783
784 ok(bt_ctf_field_type_variant_get_field(NULL, &ret_string, &ret_field_type, 0) < 0,
785 "bt_ctf_field_type_variant_get_field handles a NULL type correctly");
786 ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) < 0,
787 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
788 ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) < 0,
789 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
790 ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 200) < 0,
791 "bt_ctf_field_type_variant_get_field handles an invalid index correctly");
792 ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 1) == 0,
793 "bt_ctf_field_type_variant_get_field returns a field");
794 ok(!strcmp("INT16_TYPE", ret_string),
795 "bt_ctf_field_type_variant_get_field returns a correct field name");
796 ok(ret_field_type == int_16_type,
797 "bt_ctf_field_type_variant_get_field returns a correct field type");
798 bt_ctf_field_type_put(ret_field_type);
799
800 bt_ctf_field_type_structure_add_field(complex_structure_type,
801 enum_variant_type, "variant_selector");
802 bt_ctf_field_type_structure_add_field(complex_structure_type,
803 string_type, "a_string");
804 bt_ctf_field_type_structure_add_field(complex_structure_type,
805 variant_type, "variant_value");
806 bt_ctf_field_type_structure_add_field(complex_structure_type,
807 inner_structure_type, "inner_structure");
808
809 ok(bt_ctf_event_class_create("clock") == NULL,
810 "Reject creation of an event class with an illegal name");
811 event_class = bt_ctf_event_class_create(complex_test_event_string);
812 ok(event_class, "Create an event class");
813 ok(bt_ctf_event_class_add_field(event_class, uint_35_type, ""),
814 "Reject addition of a field with an empty name to an event");
815 ok(bt_ctf_event_class_add_field(event_class, NULL, "an_integer"),
816 "Reject addition of a field with a NULL type to an event");
817 ok(bt_ctf_event_class_add_field(event_class, uint_35_type,
818 "int"),
819 "Reject addition of a type with an illegal name to an event");
820 ok(bt_ctf_event_class_add_field(event_class, uint_35_type,
821 "uint_35") == 0,
822 "Add field of type unsigned integer to an event");
823 ok(bt_ctf_event_class_add_field(event_class, int_16_type,
824 "int_16") == 0, "Add field of type signed integer to an event");
825 ok(bt_ctf_event_class_add_field(event_class, complex_structure_type,
826 "complex_structure") == 0,
827 "Add composite structure to an event");
828
829 ok(bt_ctf_event_class_get_name(NULL) == NULL,
830 "bt_ctf_event_class_get_name handles NULL correctly");
831 ret_string = bt_ctf_event_class_get_name(event_class);
832 ok(!strcmp(ret_string, complex_test_event_string),
833 "bt_ctf_event_class_get_name returns a correct name");
834 ok(bt_ctf_event_class_get_id(event_class) < 0,
835 "bt_ctf_event_class_get_id returns a negative value when not set");
836 ok(bt_ctf_event_class_get_id(NULL) < 0,
837 "bt_ctf_event_class_get_id handles NULL correctly");
838 ok(bt_ctf_event_class_set_id(NULL, 42) < 0,
839 "bt_ctf_event_class_set_id handles NULL correctly");
840 ok(bt_ctf_event_class_set_id(event_class, 42) == 0,
841 "Set an event class' id");
842 ok(bt_ctf_event_class_get_id(event_class) == 42,
843 "bt_ctf_event_class_get_id returns the correct value");
844
845 /* Add event class to the stream class */
846 ok(bt_ctf_stream_class_add_event_class(stream_class, NULL),
847 "Reject addition of NULL event class to a stream class");
848 ok(bt_ctf_stream_class_add_event_class(stream_class,
849 event_class) == 0, "Add an event class to stream class");
850
851 ok(bt_ctf_event_class_get_stream_class(NULL) == NULL,
852 "bt_ctf_event_class_get_stream_class handles NULL correctly");
853 ret_stream_class = bt_ctf_event_class_get_stream_class(event_class);
854 ok(ret_stream_class == stream_class,
855 "bt_ctf_event_class_get_stream_class returns the correct stream class");
856 bt_ctf_stream_class_put(ret_stream_class);
857
858 ok(bt_ctf_event_class_get_field_count(NULL) < 0,
859 "bt_ctf_event_class_get_field_count handles NULL correctly");
860 ok(bt_ctf_event_class_get_field_count(event_class) == 3,
861 "bt_ctf_event_class_get_field_count returns a correct value");
862
863 ok(bt_ctf_event_class_get_field(NULL, &ret_string,
864 &ret_field_type, 0) < 0,
865 "bt_ctf_event_class_get_field handles a NULL event class correctly");
866 ok(bt_ctf_event_class_get_field(event_class, NULL,
867 &ret_field_type, 0) < 0,
868 "bt_ctf_event_class_get_field handles a NULL field name correctly");
869 ok(bt_ctf_event_class_get_field(event_class, &ret_string,
870 NULL, 0) < 0,
871 "bt_ctf_event_class_get_field handles a NULL field type correctly");
872 ok(bt_ctf_event_class_get_field(event_class, &ret_string,
873 &ret_field_type, 42) < 0,
874 "bt_ctf_event_class_get_field handles an invalid index correctly");
875 ok(bt_ctf_event_class_get_field(event_class, &ret_string,
876 &ret_field_type, 0) == 0,
877 "bt_ctf_event_class_get_field returns a field");
878 ok(ret_field_type == uint_35_type,
879 "bt_ctf_event_class_get_field returns a correct field type");
880 bt_ctf_field_type_put(ret_field_type);
881 ok(!strcmp(ret_string, "uint_35"),
882 "bt_ctf_event_class_get_field returns a correct field name");
883 ok(bt_ctf_event_class_get_field_by_name(NULL, "") == NULL,
884 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
885 ok(bt_ctf_event_class_get_field_by_name(event_class, NULL) == NULL,
886 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
887 ok(bt_ctf_event_class_get_field_by_name(event_class, "truie") == NULL,
888 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
889 ret_field_type = bt_ctf_event_class_get_field_by_name(event_class,
890 "complex_structure");
891 ok(ret_field_type == complex_structure_type,
892 "bt_ctf_event_class_get_field_by_name returns a correct field type");
893 bt_ctf_field_type_put(ret_field_type);
894
895 event = bt_ctf_event_create(event_class);
896 ok(event, "Instanciate a complex event");
897
898 ok(bt_ctf_event_get_class(NULL) == NULL,
899 "bt_ctf_event_get_class handles NULL correctly");
900 ret_event_class = bt_ctf_event_get_class(event);
901 ok(ret_event_class == event_class,
902 "bt_ctf_event_get_class returns the correct event class");
903 bt_ctf_event_class_put(ret_event_class);
904
905 uint_35_field = bt_ctf_event_get_payload(event, "uint_35");
906 if (!uint_35_field) {
907 printf("uint_35_field is NULL\n");
908 }
909
910 ok(uint_35_field, "Use bt_ctf_event_get_payload to get a field instance ");
911 bt_ctf_field_unsigned_integer_set_value(uint_35_field, 0x0DDF00D);
912 ok(bt_ctf_field_unsigned_integer_get_value(NULL, &ret_unsigned_int) < 0,
913 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
914 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field, NULL) < 0,
915 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
916 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field,
917 &ret_unsigned_int) == 0,
918 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
919 ok(ret_unsigned_int == 0x0DDF00D,
920 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
921 ok(bt_ctf_field_signed_integer_get_value(uint_35_field,
922 &ret_signed_int) < 0,
923 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
924 bt_ctf_field_put(uint_35_field);
925
926 int_16_field = bt_ctf_event_get_payload(event, "int_16");
927 bt_ctf_field_signed_integer_set_value(int_16_field, -12345);
928 ok(bt_ctf_field_signed_integer_get_value(NULL, &ret_signed_int) < 0,
929 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
930 ok(bt_ctf_field_signed_integer_get_value(int_16_field, NULL) < 0,
931 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
932 ok(bt_ctf_field_signed_integer_get_value(int_16_field,
933 &ret_signed_int) == 0,
934 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
935 ok(ret_signed_int == -12345,
936 "bt_ctf_field_signed_integer_get_value returns the correct value");
937 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field,
938 &ret_unsigned_int) < 0,
939 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
940 bt_ctf_field_put(int_16_field);
941
942 complex_structure_field = bt_ctf_event_get_payload(event,
943 "complex_structure");
944
945 ok(bt_ctf_field_structure_get_field_by_index(NULL, 0) == NULL,
946 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
947 ok(bt_ctf_field_structure_get_field_by_index(NULL, 9) == NULL,
948 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
949 inner_structure_field = bt_ctf_field_structure_get_field_by_index(
950 complex_structure_field, 3);
951 ret_field_type = bt_ctf_field_get_type(inner_structure_field);
952 bt_ctf_field_put(inner_structure_field);
953 ok(ret_field_type == inner_structure_type,
954 "bt_ctf_field_structure_get_field_by_index returns a correct field");
955 bt_ctf_field_type_put(ret_field_type);
956
957 inner_structure_field = bt_ctf_field_structure_get_field(
958 complex_structure_field, "inner_structure");
959 a_string_field = bt_ctf_field_structure_get_field(
960 complex_structure_field, "a_string");
961 enum_variant_field = bt_ctf_field_structure_get_field(
962 complex_structure_field, "variant_selector");
963 variant_field = bt_ctf_field_structure_get_field(
964 complex_structure_field, "variant_value");
965 uint_35_field = bt_ctf_field_structure_get_field(
966 inner_structure_field, "seq_len");
967 a_sequence_field = bt_ctf_field_structure_get_field(
968 inner_structure_field, "a_sequence");
969 an_array_field = bt_ctf_field_structure_get_field(
970 inner_structure_field, "an_array");
971
972 enum_container_field = bt_ctf_field_enumeration_get_container(
973 enum_variant_field);
974 bt_ctf_field_unsigned_integer_set_value(enum_container_field, 1);
975 int_16_field = bt_ctf_field_variant_get_field(variant_field,
976 enum_variant_field);
977 bt_ctf_field_signed_integer_set_value(int_16_field, -200);
978 bt_ctf_field_put(int_16_field);
979 ok(!bt_ctf_field_string_get_value(a_string_field),
980 "bt_ctf_field_string_get_value returns NULL on an unset field");
981 bt_ctf_field_string_set_value(a_string_field,
982 test_string);
983 ok(!bt_ctf_field_string_get_value(NULL),
984 "bt_ctf_field_string_get_value correctly handles NULL");
985 ret_string = bt_ctf_field_string_get_value(a_string_field);
986 ok(ret_string, "bt_ctf_field_string_get_value returns a string");
987 ok(ret_string ? !strcmp(ret_string, test_string) : 0,
988 "bt_ctf_field_string_get_value returns a correct value");
989 bt_ctf_field_unsigned_integer_set_value(uint_35_field,
990 SEQUENCE_TEST_LENGTH);
991
992 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL,
993 enum_container_field) == NULL,
994 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
995 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type,
996 NULL) == NULL,
997 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
998 ret_field_type = bt_ctf_field_type_variant_get_field_type_from_tag(
999 variant_type, enum_variant_field);
1000 ok(ret_field_type == int_16_type,
1001 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
1002
1003 ok(bt_ctf_field_sequence_get_length(a_sequence_field) == NULL,
1004 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
1005 ok(bt_ctf_field_sequence_set_length(a_sequence_field,
1006 uint_35_field) == 0, "Set a sequence field's length");
1007 ret_field = bt_ctf_field_sequence_get_length(a_sequence_field);
1008 ok(ret_field == uint_35_field,
1009 "bt_ctf_field_sequence_get_length returns the correct length field");
1010 ok(bt_ctf_field_sequence_get_length(NULL) == NULL,
1011 "bt_ctf_field_sequence_get_length properly handles NULL");
1012
1013 for (i = 0; i < SEQUENCE_TEST_LENGTH; i++) {
1014 int_16_field = bt_ctf_field_sequence_get_field(
1015 a_sequence_field, i);
1016 bt_ctf_field_signed_integer_set_value(int_16_field, 4 - i);
1017 bt_ctf_field_put(int_16_field);
1018 }
1019
1020 for (i = 0; i < ARRAY_TEST_LENGTH; i++) {
1021 int_16_field = bt_ctf_field_array_get_field(
1022 an_array_field, i);
1023 bt_ctf_field_signed_integer_set_value(int_16_field, i);
1024 bt_ctf_field_put(int_16_field);
1025 }
1026
1027 bt_ctf_clock_set_time(clock, ++current_time);
1028 ok(bt_ctf_stream_append_event(stream, event) == 0,
1029 "Append a complex event to a stream");
1030
1031 /*
1032 * Populate the custom packet context field with a dummy value
1033 * otherwise flush will fail.
1034 */
1035 packet_context = bt_ctf_stream_get_packet_context(stream);
1036 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
1037 "custom_packet_context_field");
1038 bt_ctf_field_unsigned_integer_set_value(packet_context_field, 1);
1039
1040 ok(bt_ctf_stream_flush(stream) == 0,
1041 "Flush a stream containing a complex event");
1042
1043 bt_ctf_field_put(uint_35_field);
1044 bt_ctf_field_put(a_string_field);
1045 bt_ctf_field_put(inner_structure_field);
1046 bt_ctf_field_put(complex_structure_field);
1047 bt_ctf_field_put(a_sequence_field);
1048 bt_ctf_field_put(an_array_field);
1049 bt_ctf_field_put(enum_variant_field);
1050 bt_ctf_field_put(enum_container_field);
1051 bt_ctf_field_put(variant_field);
1052 bt_ctf_field_put(ret_field);
1053 bt_ctf_field_put(packet_context_field);
1054 bt_ctf_field_put(packet_context);
1055 bt_ctf_field_type_put(uint_35_type);
1056 bt_ctf_field_type_put(int_16_type);
1057 bt_ctf_field_type_put(string_type);
1058 bt_ctf_field_type_put(sequence_type);
1059 bt_ctf_field_type_put(array_type);
1060 bt_ctf_field_type_put(inner_structure_type);
1061 bt_ctf_field_type_put(complex_structure_type);
1062 bt_ctf_field_type_put(uint_3_type);
1063 bt_ctf_field_type_put(enum_variant_type);
1064 bt_ctf_field_type_put(variant_type);
1065 bt_ctf_field_type_put(ret_field_type);
1066 bt_ctf_event_class_put(event_class);
1067 bt_ctf_event_put(event);
1068 }
1069
1070 void type_field_tests()
1071 {
1072 struct bt_ctf_field *uint_12;
1073 struct bt_ctf_field *int_16;
1074 struct bt_ctf_field *string;
1075 struct bt_ctf_field *enumeration;
1076 struct bt_ctf_field_type *composite_structure_type;
1077 struct bt_ctf_field_type *structure_seq_type;
1078 struct bt_ctf_field_type *string_type;
1079 struct bt_ctf_field_type *sequence_type;
1080 struct bt_ctf_field_type *uint_8_type;
1081 struct bt_ctf_field_type *int_16_type;
1082 struct bt_ctf_field_type *uint_12_type =
1083 bt_ctf_field_type_integer_create(12);
1084 struct bt_ctf_field_type *enumeration_type;
1085 struct bt_ctf_field_type *enumeration_sequence_type;
1086 struct bt_ctf_field_type *enumeration_array_type;
1087 struct bt_ctf_field_type *returned_type;
1088 const char *ret_string;
1089
1090 returned_type = bt_ctf_field_get_type(NULL);
1091 ok(!returned_type, "bt_ctf_field_get_type handles NULL correctly");
1092
1093 ok(uint_12_type, "Create an unsigned integer type");
1094 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1095 BT_CTF_INTEGER_BASE_BINARY) == 0,
1096 "Set integer type's base as binary");
1097 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1098 BT_CTF_INTEGER_BASE_DECIMAL) == 0,
1099 "Set integer type's base as decimal");
1100 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1101 BT_CTF_INTEGER_BASE_UNKNOWN),
1102 "Reject integer type's base set as unknown");
1103 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1104 BT_CTF_INTEGER_BASE_OCTAL) == 0,
1105 "Set integer type's base as octal");
1106 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1107 BT_CTF_INTEGER_BASE_HEXADECIMAL) == 0,
1108 "Set integer type's base as hexadecimal");
1109 ok(bt_ctf_field_type_integer_set_base(uint_12_type, 457417),
1110 "Reject unknown integer base value");
1111 ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 952835) == 0,
1112 "Set integer type signedness to signed");
1113 ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0) == 0,
1114 "Set integer type signedness to unsigned");
1115 ok(bt_ctf_field_type_integer_get_size(NULL) < 0,
1116 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1117 ok(bt_ctf_field_type_integer_get_size(uint_12_type) == 12,
1118 "bt_ctf_field_type_integer_get_size returns a correct value");
1119 ok(bt_ctf_field_type_integer_get_signed(NULL) < 0,
1120 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1121 ok(bt_ctf_field_type_integer_get_signed(uint_12_type) == 0,
1122 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1123
1124 ok(bt_ctf_field_type_set_byte_order(NULL,
1125 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN) < 0,
1126 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1127 ok(bt_ctf_field_type_set_byte_order(uint_12_type,
1128 (enum bt_ctf_byte_order) 42) < 0,
1129 "bt_ctf_field_type_set_byte_order rejects invalid values");
1130 ok(bt_ctf_field_type_set_byte_order(uint_12_type,
1131 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN) == 0,
1132 "Set an integer's byte order to little endian");
1133 ok(bt_ctf_field_type_set_byte_order(uint_12_type,
1134 BT_CTF_BYTE_ORDER_BIG_ENDIAN) == 0,
1135 "Set an integer's byte order to big endian");
1136 ok(bt_ctf_field_type_get_byte_order(uint_12_type) ==
1137 BT_CTF_BYTE_ORDER_BIG_ENDIAN,
1138 "bt_ctf_field_type_get_byte_order returns a correct value");
1139 ok(bt_ctf_field_type_get_byte_order(NULL) ==
1140 BT_CTF_BYTE_ORDER_UNKNOWN,
1141 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1142
1143 ok(bt_ctf_field_type_get_type_id(NULL) ==
1144 CTF_TYPE_UNKNOWN,
1145 "bt_ctf_field_type_get_type_id handles NULL correctly");
1146 ok(bt_ctf_field_type_get_type_id(uint_12_type) ==
1147 CTF_TYPE_INTEGER,
1148 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1149
1150 ok(bt_ctf_field_type_integer_get_base(NULL) ==
1151 BT_CTF_INTEGER_BASE_UNKNOWN,
1152 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1153 ok(bt_ctf_field_type_integer_get_base(uint_12_type) ==
1154 BT_CTF_INTEGER_BASE_HEXADECIMAL,
1155 "bt_ctf_field_type_integer_get_base returns a correct value");
1156
1157 ok(bt_ctf_field_type_integer_set_encoding(NULL, CTF_STRING_ASCII) < 0,
1158 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1159 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type,
1160 (enum ctf_string_encoding) 123) < 0,
1161 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1162 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type,
1163 CTF_STRING_UTF8) == 0,
1164 "Set integer type encoding to UTF8");
1165 ok(bt_ctf_field_type_integer_get_encoding(NULL) == CTF_STRING_UNKNOWN,
1166 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1167 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type) == CTF_STRING_UTF8,
1168 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1169
1170 int_16_type = bt_ctf_field_type_integer_create(16);
1171 bt_ctf_field_type_integer_set_signed(int_16_type, 1);
1172 ok(bt_ctf_field_type_integer_get_signed(int_16_type) == 1,
1173 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1174 uint_8_type = bt_ctf_field_type_integer_create(8);
1175 sequence_type =
1176 bt_ctf_field_type_sequence_create(int_16_type, "seq_len");
1177 ok(sequence_type, "Create a sequence of int16_t type");
1178 ok(bt_ctf_field_type_get_type_id(sequence_type) ==
1179 CTF_TYPE_SEQUENCE,
1180 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1181
1182 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL) == NULL,
1183 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1184 ret_string = bt_ctf_field_type_sequence_get_length_field_name(
1185 sequence_type);
1186 ok(!strcmp(ret_string, "seq_len"),
1187 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1188 ok(bt_ctf_field_type_sequence_get_element_type(NULL) == NULL,
1189 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1190 returned_type = bt_ctf_field_type_sequence_get_element_type(
1191 sequence_type);
1192 ok(returned_type == int_16_type,
1193 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
1194 bt_ctf_field_type_put(returned_type);
1195
1196 string_type = bt_ctf_field_type_string_create();
1197 ok(string_type, "Create a string type");
1198 ok(bt_ctf_field_type_string_set_encoding(string_type,
1199 CTF_STRING_NONE),
1200 "Reject invalid \"None\" string encoding");
1201 ok(bt_ctf_field_type_string_set_encoding(string_type,
1202 42),
1203 "Reject invalid string encoding");
1204 ok(bt_ctf_field_type_string_set_encoding(string_type,
1205 CTF_STRING_ASCII) == 0,
1206 "Set string encoding to ASCII");
1207
1208 ok(bt_ctf_field_type_string_get_encoding(NULL) ==
1209 CTF_STRING_UNKNOWN,
1210 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
1211 ok(bt_ctf_field_type_string_get_encoding(string_type) ==
1212 CTF_STRING_ASCII,
1213 "bt_ctf_field_type_string_get_encoding returns the correct value");
1214
1215 structure_seq_type = bt_ctf_field_type_structure_create();
1216 ok(bt_ctf_field_type_get_type_id(structure_seq_type) ==
1217 CTF_TYPE_STRUCT,
1218 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
1219 ok(structure_seq_type, "Create a structure type");
1220 ok(bt_ctf_field_type_structure_add_field(structure_seq_type,
1221 uint_8_type, "seq_len") == 0,
1222 "Add a uint8_t type to a structure");
1223 ok(bt_ctf_field_type_structure_add_field(structure_seq_type,
1224 sequence_type, "a_sequence") == 0,
1225 "Add a sequence type to a structure");
1226
1227 ok(bt_ctf_field_type_structure_get_field_count(NULL) < 0,
1228 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
1229 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type) == 2,
1230 "bt_ctf_field_type_structure_get_field_count returns a correct value");
1231
1232 ok(bt_ctf_field_type_structure_get_field(NULL,
1233 &ret_string, &returned_type, 1) < 0,
1234 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
1235 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
1236 NULL, &returned_type, 1) < 0,
1237 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
1238 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
1239 &ret_string, NULL, 1) < 0,
1240 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
1241 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
1242 &ret_string, &returned_type, 10) < 0,
1243 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
1244 ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
1245 &ret_string, &returned_type, 1) == 0,
1246 "bt_ctf_field_type_structure_get_field returns a field");
1247 ok(!strcmp(ret_string, "a_sequence"),
1248 "bt_ctf_field_type_structure_get_field returns a correct field name");
1249 ok(returned_type == sequence_type,
1250 "bt_ctf_field_type_structure_get_field returns a correct field type");
1251 bt_ctf_field_type_put(returned_type);
1252
1253 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL, "a_sequence") == NULL,
1254 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
1255 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type, NULL) == NULL,
1256 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1257 returned_type = bt_ctf_field_type_structure_get_field_type_by_name(
1258 structure_seq_type, "a_sequence");
1259 ok(returned_type == sequence_type,
1260 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
1261 bt_ctf_field_type_put(returned_type);
1262
1263 composite_structure_type = bt_ctf_field_type_structure_create();
1264 ok(bt_ctf_field_type_structure_add_field(composite_structure_type,
1265 string_type, "a_string") == 0,
1266 "Add a string type to a structure");
1267 ok(bt_ctf_field_type_structure_add_field(composite_structure_type,
1268 structure_seq_type, "inner_structure") == 0,
1269 "Add a structure type to a structure");
1270
1271 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1272 NULL, "a_sequence") == NULL,
1273 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
1274 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1275 structure_seq_type, NULL) == NULL,
1276 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1277 returned_type = bt_ctf_field_type_structure_get_field_type_by_name(
1278 structure_seq_type, "a_sequence");
1279 ok(returned_type == sequence_type,
1280 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1281 bt_ctf_field_type_put(returned_type);
1282
1283 int_16 = bt_ctf_field_create(int_16_type);
1284 ok(int_16, "Instanciate a signed 16-bit integer");
1285 uint_12 = bt_ctf_field_create(uint_12_type);
1286 ok(uint_12, "Instanciate an unsigned 12-bit integer");
1287 returned_type = bt_ctf_field_get_type(int_16);
1288 ok(returned_type == int_16_type,
1289 "bt_ctf_field_get_type returns the correct type");
1290
1291 /* Can't modify types after instanciating them */
1292 ok(bt_ctf_field_type_integer_set_base(uint_12_type,
1293 BT_CTF_INTEGER_BASE_DECIMAL),
1294 "Check an integer type' base can't be modified after instanciation");
1295 ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0),
1296 "Check an integer type's signedness can't be modified after instanciation");
1297
1298 /* Check signed property is checked */
1299 ok(bt_ctf_field_signed_integer_set_value(uint_12, -52),
1300 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
1301 ok(bt_ctf_field_unsigned_integer_set_value(int_16, 42),
1302 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
1303
1304 /* Check overflows are properly tested for */
1305 ok(bt_ctf_field_signed_integer_set_value(int_16, -32768) == 0,
1306 "Check -32768 is allowed for a signed 16-bit integer");
1307 ok(bt_ctf_field_signed_integer_set_value(int_16, 32767) == 0,
1308 "Check 32767 is allowed for a signed 16-bit integer");
1309 ok(bt_ctf_field_signed_integer_set_value(int_16, 32768),
1310 "Check 32768 is not allowed for a signed 16-bit integer");
1311 ok(bt_ctf_field_signed_integer_set_value(int_16, -32769),
1312 "Check -32769 is not allowed for a signed 16-bit integer");
1313 ok(bt_ctf_field_signed_integer_set_value(int_16, -42) == 0,
1314 "Check -42 is allowed for a signed 16-bit integer");
1315
1316 ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 4095) == 0,
1317 "Check 4095 is allowed for an unsigned 12-bit integer");
1318 ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 4096),
1319 "Check 4096 is not allowed for a unsigned 12-bit integer");
1320 ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 0) == 0,
1321 "Check 0 is allowed for an unsigned 12-bit integer");
1322
1323 string = bt_ctf_field_create(string_type);
1324 ok(string, "Instanciate a string field");
1325 ok(bt_ctf_field_string_set_value(string, "A value") == 0,
1326 "Set a string's value");
1327
1328 enumeration_type = bt_ctf_field_type_enumeration_create(uint_12_type);
1329 ok(enumeration_type,
1330 "Create an enumeration type with an unsigned 12-bit integer as container");
1331 enumeration_sequence_type = bt_ctf_field_type_sequence_create(
1332 enumeration_type, "count");
1333 ok(!enumeration_sequence_type,
1334 "Check enumeration types are validated when creating a sequence");
1335 enumeration_array_type = bt_ctf_field_type_array_create(
1336 enumeration_type, 10);
1337 ok(!enumeration_array_type,
1338 "Check enumeration types are validated when creating an array");
1339 ok(bt_ctf_field_type_structure_add_field(composite_structure_type,
1340 enumeration_type, "enumeration"),
1341 "Check enumeration types are validated when adding them as structure members");
1342 enumeration = bt_ctf_field_create(enumeration_type);
1343 ok(!enumeration,
1344 "Check enumeration types are validated before instantiation");
1345
1346 bt_ctf_field_put(string);
1347 bt_ctf_field_put(uint_12);
1348 bt_ctf_field_put(int_16);
1349 bt_ctf_field_put(enumeration);
1350 bt_ctf_field_type_put(composite_structure_type);
1351 bt_ctf_field_type_put(structure_seq_type);
1352 bt_ctf_field_type_put(string_type);
1353 bt_ctf_field_type_put(sequence_type);
1354 bt_ctf_field_type_put(uint_8_type);
1355 bt_ctf_field_type_put(int_16_type);
1356 bt_ctf_field_type_put(uint_12_type);
1357 bt_ctf_field_type_put(enumeration_type);
1358 bt_ctf_field_type_put(enumeration_sequence_type);
1359 bt_ctf_field_type_put(enumeration_array_type);
1360 bt_ctf_field_type_put(returned_type);
1361 }
1362
1363 void packet_resize_test(struct bt_ctf_stream_class *stream_class,
1364 struct bt_ctf_stream *stream, struct bt_ctf_clock *clock)
1365 {
1366 /*
1367 * Append enough events to force the underlying packet to be resized.
1368 * Also tests that a new event can be declared after a stream has been
1369 * instantiated and used/flushed.
1370 */
1371 int ret = 0;
1372 int i;
1373 struct bt_ctf_event_class *event_class = bt_ctf_event_class_create(
1374 "Spammy_Event");
1375 struct bt_ctf_field_type *integer_type =
1376 bt_ctf_field_type_integer_create(17);
1377 struct bt_ctf_field_type *string_type =
1378 bt_ctf_field_type_string_create();
1379 struct bt_ctf_event *event = NULL;
1380 struct bt_ctf_field *ret_field = NULL;
1381 struct bt_ctf_field_type *ret_field_type = NULL;
1382 uint64_t ret_uint64;
1383 int events_appended = 0;
1384 struct bt_ctf_field *packet_context = NULL,
1385 *packet_context_field = NULL, *event_context = NULL;
1386
1387 ret |= bt_ctf_event_class_add_field(event_class, integer_type,
1388 "field_1");
1389 ret |= bt_ctf_event_class_add_field(event_class, string_type,
1390 "a_string");
1391 ret |= bt_ctf_stream_class_add_event_class(stream_class, event_class);
1392 ok(ret == 0, "Add a new event class to a stream class after writing an event");
1393 if (ret) {
1394 goto end;
1395 }
1396
1397 event = bt_ctf_event_create(event_class);
1398 ret_field = bt_ctf_event_get_payload_by_index(event, 0);
1399 ret_field_type = bt_ctf_field_get_type(ret_field);
1400 ok(ret_field_type == integer_type,
1401 "bt_ctf_event_get_payload_by_index returns a correct field");
1402 bt_ctf_field_type_put(ret_field_type);
1403 bt_ctf_field_put(ret_field);
1404
1405 ok(bt_ctf_event_get_payload_by_index(NULL, 0) == NULL,
1406 "bt_ctf_event_get_payload_by_index handles NULL correctly");
1407 ok(bt_ctf_event_get_payload_by_index(event, 4) == NULL,
1408 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
1409 bt_ctf_event_put(event);
1410
1411 ok(bt_ctf_stream_get_event_context(NULL) == NULL,
1412 "bt_ctf_stream_get_event_context handles NULL correctly");
1413 event_context = bt_ctf_stream_get_event_context(stream);
1414 ok(event_context,
1415 "bt_ctf_stream_get_event_context returns a stream event context");
1416 ok(bt_ctf_stream_set_event_context(NULL, event_context) < 0,
1417 "bt_ctf_stream_set_event_context handles a NULL stream correctly");
1418 ok(bt_ctf_stream_set_event_context(stream, NULL) < 0,
1419 "bt_ctf_stream_set_event_context handles a NULL stream event context correctly");
1420 ok(!bt_ctf_stream_set_event_context(stream, event_context),
1421 "bt_ctf_stream_set_event_context correctly set a stream event context");
1422 ret_field = bt_ctf_field_create(integer_type);
1423 ok(bt_ctf_stream_set_event_context(stream, ret_field) < 0,
1424 "bt_ctf_stream_set_event_context rejects an event context of incorrect type");
1425 bt_ctf_field_put(ret_field);
1426
1427 for (i = 0; i < PACKET_RESIZE_TEST_LENGTH; i++) {
1428 event = bt_ctf_event_create(event_class);
1429 struct bt_ctf_field *integer =
1430 bt_ctf_field_create(integer_type);
1431 struct bt_ctf_field *string =
1432 bt_ctf_field_create(string_type);
1433
1434 ret |= bt_ctf_clock_set_time(clock, ++current_time);
1435 ret |= bt_ctf_field_unsigned_integer_set_value(integer, i);
1436 ret |= bt_ctf_event_set_payload(event, "field_1",
1437 integer);
1438 bt_ctf_field_put(integer);
1439 ret |= bt_ctf_field_string_set_value(string, "This is a test");
1440 ret |= bt_ctf_event_set_payload(event, "a_string",
1441 string);
1442 bt_ctf_field_put(string);
1443
1444 /* Populate stream event context */
1445 integer = bt_ctf_field_structure_get_field(event_context,
1446 "common_event_context");
1447 ret |= bt_ctf_field_unsigned_integer_set_value(integer,
1448 i % 42);
1449 bt_ctf_field_put(integer);
1450
1451 ret |= bt_ctf_stream_append_event(stream, event);
1452 bt_ctf_event_put(event);
1453
1454 if (ret) {
1455 break;
1456 }
1457 }
1458
1459 events_appended = !!(i == PACKET_RESIZE_TEST_LENGTH);
1460 ok(bt_ctf_stream_get_discarded_events_count(NULL, &ret_uint64) < 0,
1461 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
1462 ok(bt_ctf_stream_get_discarded_events_count(stream, NULL) < 0,
1463 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
1464 ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64);
1465 ok(ret == 0 && ret_uint64 == 0,
1466 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
1467 bt_ctf_stream_append_discarded_events(stream, 1000);
1468 ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64);
1469 ok(ret == 0 && ret_uint64 == 1000,
1470 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
1471
1472 end:
1473 ok(events_appended, "Append 100 000 events to a stream");
1474
1475 /*
1476 * Populate the custom packet context field with a dummy value
1477 * otherwise flush will fail.
1478 */
1479 packet_context = bt_ctf_stream_get_packet_context(stream);
1480 packet_context_field = bt_ctf_field_structure_get_field(packet_context,
1481 "custom_packet_context_field");
1482 bt_ctf_field_unsigned_integer_set_value(packet_context_field, 2);
1483
1484 ok(bt_ctf_stream_flush(stream) == 0,
1485 "Flush a stream that forces a packet resize");
1486 ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64);
1487 ok(ret == 0 && ret_uint64 == 1000,
1488 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
1489 bt_ctf_field_type_put(integer_type);
1490 bt_ctf_field_type_put(string_type);
1491 bt_ctf_field_put(packet_context);
1492 bt_ctf_field_put(packet_context_field);
1493 bt_ctf_field_put(event_context);
1494 bt_ctf_event_class_put(event_class);
1495 }
1496
1497 void test_empty_stream(struct bt_ctf_writer *writer)
1498 {
1499 int ret = 0;
1500 struct bt_ctf_trace *trace = NULL;
1501 struct bt_ctf_stream_class *stream_class = NULL;
1502 struct bt_ctf_stream *stream = NULL;
1503
1504 trace = bt_ctf_writer_get_trace(writer);
1505 if (!trace) {
1506 diag("Failed to get trace from writer");
1507 ret = -1;
1508 goto end;
1509 }
1510
1511 stream_class = bt_ctf_stream_class_create("empty_stream");
1512 if (!stream_class) {
1513 diag("Failed to create stream class");
1514 ret = -1;
1515 goto end;
1516 }
1517
1518 stream = bt_ctf_writer_create_stream(writer, stream_class);
1519 if (!stream) {
1520 diag("Failed to create writer stream");
1521 ret = -1;
1522 goto end;
1523 }
1524 end:
1525 ok(ret == 0,
1526 "Created a stream class with default attributes and an empty stream");
1527 bt_ctf_trace_put(trace);
1528 bt_ctf_stream_put(stream);
1529 bt_ctf_stream_class_put(stream_class);
1530 }
1531
1532 void test_instanciate_event_before_stream(struct bt_ctf_writer *writer)
1533 {
1534 int ret = 0;
1535 struct bt_ctf_trace *trace = NULL;
1536 struct bt_ctf_clock *clock = NULL;
1537 struct bt_ctf_stream_class *stream_class = NULL;
1538 struct bt_ctf_stream *stream = NULL;
1539 struct bt_ctf_event_class *event_class = NULL;
1540 struct bt_ctf_event *event = NULL;
1541 struct bt_ctf_field_type *integer_type = NULL;
1542 struct bt_ctf_field *integer = NULL;
1543
1544 trace = bt_ctf_writer_get_trace(writer);
1545 if (!trace) {
1546 diag("Failed to get trace from writer");
1547 ret = -1;
1548 goto end;
1549 }
1550
1551 clock = bt_ctf_trace_get_clock(trace, 0);
1552 if (!clock) {
1553 diag("Failed to get clock from trace");
1554 ret = -1;
1555 goto end;
1556 }
1557
1558 stream_class = bt_ctf_stream_class_create("event_before_stream_test");
1559 if (!stream_class) {
1560 diag("Failed to create stream class");
1561 ret = -1;
1562 goto end;
1563 }
1564
1565 ret = bt_ctf_stream_class_set_clock(stream_class, clock);
1566 if (ret) {
1567 diag("Failed to set stream class clock");
1568 goto end;
1569 }
1570
1571 event_class = bt_ctf_event_class_create("some_event_class_name");
1572 integer_type = bt_ctf_field_type_integer_create(32);
1573 if (!integer_type) {
1574 diag("Failed to create integer field type");
1575 ret = -1;
1576 goto end;
1577 }
1578
1579 ret = bt_ctf_event_class_add_field(event_class, integer_type,
1580 "integer_field");
1581 if (ret) {
1582 diag("Failed to add field to event class");
1583 goto end;
1584 }
1585
1586 ret = bt_ctf_stream_class_add_event_class(stream_class,
1587 event_class);
1588 if (ret) {
1589 diag("Failed to add event class to stream class");
1590 }
1591
1592 event = bt_ctf_event_create(event_class);
1593 if (!event) {
1594 diag("Failed to create event");
1595 ret = -1;
1596 goto end;
1597 }
1598
1599 integer = bt_ctf_event_get_payload_by_index(event, 0);
1600 if (!integer) {
1601 diag("Failed to get integer field payload from event");
1602 ret = -1;
1603 goto end;
1604 }
1605
1606 ret = bt_ctf_field_unsigned_integer_set_value(integer, 1234);
1607 if (ret) {
1608 diag("Failed to set integer field value");
1609 goto end;
1610 }
1611
1612 stream = bt_ctf_writer_create_stream(writer, stream_class);
1613 if (!stream) {
1614 diag("Failed to create writer stream");
1615 ret = -1;
1616 goto end;
1617 }
1618
1619 ret = bt_ctf_stream_append_event(stream, event);
1620 if (ret) {
1621 diag("Failed to append event to stream");
1622 goto end;
1623 }
1624 end:
1625 ok(ret == 0,
1626 "Create an event before instanciating its associated stream");
1627 bt_ctf_trace_put(trace);
1628 bt_ctf_stream_put(stream);
1629 bt_ctf_stream_class_put(stream_class);
1630 bt_ctf_event_class_put(event_class);
1631 bt_ctf_event_put(event);
1632 bt_ctf_field_type_put(integer_type);
1633 bt_ctf_field_put(integer);
1634 bt_ctf_clock_put(clock);
1635 }
1636
1637 int main(int argc, char **argv)
1638 {
1639 char trace_path[] = "/tmp/ctfwriter_XXXXXX";
1640 char metadata_path[sizeof(trace_path) + 9];
1641 const char *clock_name = "test_clock";
1642 const char *clock_description = "This is a test clock";
1643 const char *returned_clock_name;
1644 const char *returned_clock_description;
1645 const uint64_t frequency = 1123456789;
1646 const uint64_t offset_s = 1351530929945824323;
1647 const uint64_t offset = 1234567;
1648 const uint64_t precision = 10;
1649 const int is_absolute = 0xFF;
1650 char *metadata_string;
1651 struct bt_ctf_writer *writer;
1652 struct utsname name;
1653 char hostname[BABELTRACE_HOST_NAME_MAX];
1654 struct bt_ctf_clock *clock, *ret_clock;
1655 struct bt_ctf_stream_class *stream_class, *ret_stream_class;
1656 struct bt_ctf_stream *stream1;
1657 const char *ret_string;
1658 const unsigned char *ret_uuid;
1659 unsigned char tmp_uuid[16] = { 0 };
1660 struct bt_ctf_field_type *packet_context_type,
1661 *packet_context_field_type,
1662 *packet_header_type,
1663 *packet_header_field_type,
1664 *integer_type,
1665 *stream_event_context_type,
1666 *ret_field_type,
1667 *event_header_field_type;
1668 struct bt_ctf_field *packet_header, *packet_header_field;
1669 struct bt_ctf_trace *trace;
1670 int ret;
1671 int64_t ret_int64_t;
1672 struct bt_object *obj;
1673
1674 if (argc < 3) {
1675 printf("Usage: tests-ctf-writer path_to_ctf_parser_test path_to_babeltrace\n");
1676 return -1;
1677 }
1678
1679 plan_no_plan();
1680
1681 if (!mkdtemp(trace_path)) {
1682 perror("# perror");
1683 }
1684
1685 strcpy(metadata_path, trace_path);
1686 strcat(metadata_path + sizeof(trace_path) - 1, "/metadata");
1687
1688 writer = bt_ctf_writer_create(trace_path);
1689 ok(writer, "bt_ctf_create succeeds in creating trace with path");
1690
1691 ok(!bt_ctf_writer_get_trace(NULL),
1692 "bt_ctf_writer_get_trace correctly handles NULL");
1693 trace = bt_ctf_writer_get_trace(writer);
1694 ok(trace,
1695 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
1696 ok(bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_BIG_ENDIAN) == 0,
1697 "Set a trace's byte order to big endian");
1698 ok(bt_ctf_trace_get_byte_order(trace) == BT_CTF_BYTE_ORDER_BIG_ENDIAN,
1699 "bt_ctf_trace_get_byte_order returns a correct endianness");
1700
1701 /* Add environment context to the trace */
1702 ret = gethostname(hostname, sizeof(hostname));
1703 if (ret < 0) {
1704 return ret;
1705 }
1706 ok(bt_ctf_writer_add_environment_field(writer, "host", hostname) == 0,
1707 "Add host (%s) environment field to writer instance",
1708 hostname);
1709 ok(bt_ctf_writer_add_environment_field(NULL, "test_field",
1710 "test_value"),
1711 "bt_ctf_writer_add_environment_field error with NULL writer");
1712 ok(bt_ctf_writer_add_environment_field(writer, NULL,
1713 "test_value"),
1714 "bt_ctf_writer_add_environment_field error with NULL field name");
1715 ok(bt_ctf_writer_add_environment_field(writer, "test_field",
1716 NULL),
1717 "bt_ctf_writer_add_environment_field error with NULL field value");
1718
1719 /* Test bt_ctf_trace_set_environment_field with an integer object */
1720 obj = bt_object_integer_create_init(23);
1721 assert(obj);
1722 ok(bt_ctf_trace_set_environment_field(NULL, "test_env_int_obj", obj),
1723 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
1724 ok(bt_ctf_trace_set_environment_field(trace, NULL, obj),
1725 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
1726 ok(bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", NULL),
1727 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
1728 ok(!bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", obj),
1729 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
1730 BT_OBJECT_PUT(obj);
1731
1732 /* Test bt_ctf_trace_set_environment_field with a string object */
1733 obj = bt_object_string_create_init("the value");
1734 assert(obj);
1735 ok(!bt_ctf_trace_set_environment_field(trace, "test_env_str_obj", obj),
1736 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
1737 BT_OBJECT_PUT(obj);
1738
1739 /* Test bt_ctf_trace_set_environment_field_integer */
1740 ok(bt_ctf_trace_set_environment_field_integer(NULL, "test_env_int",
1741 -194875),
1742 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
1743 ok(bt_ctf_trace_set_environment_field_integer(trace, NULL, -194875),
1744 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
1745 ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int",
1746 -164973),
1747 "bt_ctf_trace_set_environment_field_integer succeeds");
1748
1749 /* Test bt_ctf_trace_set_environment_field_string */
1750 ok(bt_ctf_trace_set_environment_field_string(NULL, "test_env_str",
1751 "yeah"),
1752 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
1753 ok(bt_ctf_trace_set_environment_field_string(trace, NULL, "yeah"),
1754 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
1755 ok(bt_ctf_trace_set_environment_field_string(trace, "test_env_str",
1756 NULL),
1757 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
1758 ok(!bt_ctf_trace_set_environment_field_string(trace, "test_env_str",
1759 "oh yeah"),
1760 "bt_ctf_trace_set_environment_field_string succeeds");
1761
1762 /* Test bt_ctf_trace_get_environment_field_count */
1763 ok(bt_ctf_trace_get_environment_field_count(NULL) < 0,
1764 "bt_ctf_trace_get_environment_field_count handles a NULL trace correctly");
1765 ok(bt_ctf_trace_get_environment_field_count(trace) == 5,
1766 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
1767
1768 /* Test bt_ctf_trace_get_environment_field_name */
1769 ok(bt_ctf_trace_get_environment_field_name(NULL, 0) == NULL,
1770 "bt_ctf_trace_get_environment_field_name handles a NULL trace correctly");
1771 ok(bt_ctf_trace_get_environment_field_name(trace, -1) == NULL,
1772 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (negative)");
1773 ok(bt_ctf_trace_get_environment_field_name(trace, 5) == NULL,
1774 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (too large)");
1775 ret_string = bt_ctf_trace_get_environment_field_name(trace, 0);
1776 ok(ret_string && !strcmp(ret_string, "host"),
1777 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1778 ret_string = bt_ctf_trace_get_environment_field_name(trace, 1);
1779 ok(ret_string && !strcmp(ret_string, "test_env_int_obj"),
1780 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1781 ret_string = bt_ctf_trace_get_environment_field_name(trace, 2);
1782 ok(ret_string && !strcmp(ret_string, "test_env_str_obj"),
1783 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1784 ret_string = bt_ctf_trace_get_environment_field_name(trace, 3);
1785 ok(ret_string && !strcmp(ret_string, "test_env_int"),
1786 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1787 ret_string = bt_ctf_trace_get_environment_field_name(trace, 4);
1788 ok(ret_string && !strcmp(ret_string, "test_env_str"),
1789 "bt_ctf_trace_get_environment_field_name returns a correct field name");
1790
1791 /* Test bt_ctf_trace_get_environment_field_value */
1792 ok(bt_ctf_trace_get_environment_field_value(NULL, 0) == NULL,
1793 "bt_ctf_trace_get_environment_field_value handles a NULL trace correctly");
1794 ok(bt_ctf_trace_get_environment_field_value(trace, -1) == NULL,
1795 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (negative)");
1796 ok(bt_ctf_trace_get_environment_field_value(trace, 5) == NULL,
1797 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (too large)");
1798 obj = bt_ctf_trace_get_environment_field_value(trace, 1);
1799 ret = bt_object_integer_get(obj, &ret_int64_t);
1800 ok(!ret && ret_int64_t == 23,
1801 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
1802 BT_OBJECT_PUT(obj);
1803 obj = bt_ctf_trace_get_environment_field_value(trace, 2);
1804 ret = bt_object_string_get(obj, &ret_string);
1805 ok(!ret && ret_string && !strcmp(ret_string, "the value"),
1806 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
1807 BT_OBJECT_PUT(obj);
1808
1809 /* Test bt_ctf_trace_get_environment_field_value_by_name */
1810 ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL,
1811 "test_env_str"),
1812 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL trace correctly");
1813 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace, NULL),
1814 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL name correctly");
1815 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace, "oh oh"),
1816 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
1817 obj = bt_ctf_trace_get_environment_field_value_by_name(trace,
1818 "test_env_str");
1819 ret = bt_object_string_get(obj, &ret_string);
1820 ok(!ret && ret_string && !strcmp(ret_string, "oh yeah"),
1821 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
1822 BT_OBJECT_PUT(obj);
1823
1824 /* Test environment field replacement */
1825 ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int",
1826 654321),
1827 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
1828 ok(bt_ctf_trace_get_environment_field_count(trace) == 5,
1829 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
1830 obj = bt_ctf_trace_get_environment_field_value(trace, 3);
1831 ret = bt_object_integer_get(obj, &ret_int64_t);
1832 ok(!ret && ret_int64_t == 654321,
1833 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
1834 BT_OBJECT_PUT(obj);
1835
1836 if (uname(&name)) {
1837 perror("uname");
1838 return -1;
1839 }
1840
1841 ok(bt_ctf_writer_add_environment_field(writer, "sysname", name.sysname)
1842 == 0, "Add sysname (%s) environment field to writer instance",
1843 name.sysname);
1844 ok(bt_ctf_writer_add_environment_field(writer, "nodename",
1845 name.nodename) == 0,
1846 "Add nodename (%s) environment field to writer instance",
1847 name.nodename);
1848 ok(bt_ctf_writer_add_environment_field(writer, "release", name.release)
1849 == 0, "Add release (%s) environment field to writer instance",
1850 name.release);
1851 ok(bt_ctf_writer_add_environment_field(writer, "version", name.version)
1852 == 0, "Add version (%s) environment field to writer instance",
1853 name.version);
1854 ok(bt_ctf_writer_add_environment_field(writer, "machine", name.machine)
1855 == 0, "Add machine (%s) environment field to writer istance",
1856 name.machine);
1857
1858 /* Define a clock and add it to the trace */
1859 ok(bt_ctf_clock_create("signed") == NULL,
1860 "Illegal clock name rejected");
1861 ok(bt_ctf_clock_create(NULL) == NULL, "NULL clock name rejected");
1862 clock = bt_ctf_clock_create(clock_name);
1863 ok(clock, "Clock created sucessfully");
1864 returned_clock_name = bt_ctf_clock_get_name(clock);
1865 ok(returned_clock_name, "bt_ctf_clock_get_name returns a clock name");
1866 ok(returned_clock_name ? !strcmp(returned_clock_name, clock_name) : 0,
1867 "Returned clock name is valid");
1868
1869 returned_clock_description = bt_ctf_clock_get_description(clock);
1870 ok(!returned_clock_description, "bt_ctf_clock_get_description returns NULL on an unset description");
1871 ok(bt_ctf_clock_set_description(clock, clock_description) == 0,
1872 "Clock description set successfully");
1873
1874 returned_clock_description = bt_ctf_clock_get_description(clock);
1875 ok(returned_clock_description,
1876 "bt_ctf_clock_get_description returns a description.");
1877 ok(returned_clock_description ?
1878 !strcmp(returned_clock_description, clock_description) : 0,
1879 "Returned clock description is valid");
1880
1881 ok(bt_ctf_clock_get_frequency(clock) == DEFAULT_CLOCK_FREQ,
1882 "bt_ctf_clock_get_frequency returns the correct default frequency");
1883 ok(bt_ctf_clock_set_frequency(clock, frequency) == 0,
1884 "Set clock frequency");
1885 ok(bt_ctf_clock_get_frequency(clock) == frequency,
1886 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
1887
1888 ok(bt_ctf_clock_get_offset_s(clock) == DEFAULT_CLOCK_OFFSET_S,
1889 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
1890 ok(bt_ctf_clock_set_offset_s(clock, offset_s) == 0,
1891 "Set clock offset (seconds)");
1892 ok(bt_ctf_clock_get_offset_s(clock) == offset_s,
1893 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
1894
1895 ok(bt_ctf_clock_get_offset(clock) == DEFAULT_CLOCK_OFFSET,
1896 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks)");
1897 ok(bt_ctf_clock_set_offset(clock, offset) == 0, "Set clock offset");
1898 ok(bt_ctf_clock_get_offset(clock) == offset,
1899 "bt_ctf_clock_get_frequency returns the correct default offset (in ticks) once it is set");
1900
1901 ok(bt_ctf_clock_get_precision(clock) == DEFAULT_CLOCK_PRECISION,
1902 "bt_ctf_clock_get_precision returns the correct default precision");
1903 ok(bt_ctf_clock_set_precision(clock, precision) == 0,
1904 "Set clock precision");
1905 ok(bt_ctf_clock_get_precision(clock) == precision,
1906 "bt_ctf_clock_get_precision returns the correct precision once it is set");
1907
1908 ok(bt_ctf_clock_get_is_absolute(clock) == DEFAULT_CLOCK_IS_ABSOLUTE,
1909 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
1910 ok(bt_ctf_clock_set_is_absolute(clock, is_absolute) == 0,
1911 "Set clock absolute property");
1912 ok(bt_ctf_clock_get_is_absolute(clock) == !!is_absolute,
1913 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
1914
1915 ok(bt_ctf_clock_get_time(clock) == DEFAULT_CLOCK_TIME,
1916 "bt_ctf_clock_get_time returns the correct default time");
1917 ok(bt_ctf_clock_set_time(clock, current_time) == 0,
1918 "Set clock time");
1919 ok(bt_ctf_clock_get_time(clock) == current_time,
1920 "bt_ctf_clock_get_time returns the correct time once it is set");
1921
1922 ok(bt_ctf_writer_add_clock(writer, clock) == 0,
1923 "Add clock to writer instance");
1924 ok(bt_ctf_writer_add_clock(writer, clock),
1925 "Verify a clock can't be added twice to a writer instance");
1926
1927 ok(bt_ctf_trace_get_clock_count(NULL) < 0,
1928 "bt_ctf_trace_get_clock_count correctly handles NULL");
1929 ok(bt_ctf_trace_get_clock_count(trace) == 1,
1930 "bt_ctf_trace_get_clock_count returns the correct number of clocks");
1931 ok(!bt_ctf_trace_get_clock(NULL, 0),
1932 "bt_ctf_trace_get_clock correctly handles NULL");
1933 ok(!bt_ctf_trace_get_clock(trace, -1),
1934 "bt_ctf_trace_get_clock correctly handles negative indexes");
1935 ok(!bt_ctf_trace_get_clock(trace, 1),
1936 "bt_ctf_trace_get_clock correctly handles out of bound accesses");
1937 ret_clock = bt_ctf_trace_get_clock(trace, 0);
1938 ok(ret_clock == clock,
1939 "bt_ctf_trace_get_clock returns the right clock instance");
1940 bt_ctf_clock_put(ret_clock);
1941 ok(!bt_ctf_trace_get_clock_by_name(trace, NULL),
1942 "bt_ctf_trace_get_clock_by_name correctly handles NULL (trace)");
1943 ok(!bt_ctf_trace_get_clock_by_name(NULL, clock_name),
1944 "bt_ctf_trace_get_clock_by_name correctly handles NULL (clock name)");
1945 ok(!bt_ctf_trace_get_clock_by_name(NULL, NULL),
1946 "bt_ctf_trace_get_clock_by_name correctly handles NULL (both)");
1947 ret_clock = bt_ctf_trace_get_clock_by_name(trace, clock_name);
1948 ok(ret_clock == clock,
1949 "bt_ctf_trace_get_clock_by_name returns the right clock instance");
1950 bt_ctf_clock_put(ret_clock);
1951 ok(!bt_ctf_trace_get_clock_by_name(trace, "random"),
1952 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
1953
1954 ok(!bt_ctf_clock_get_name(NULL),
1955 "bt_ctf_clock_get_name correctly handles NULL");
1956 ok(!bt_ctf_clock_get_description(NULL),
1957 "bt_ctf_clock_get_description correctly handles NULL");
1958 ok(bt_ctf_clock_get_frequency(NULL) == -1ULL,
1959 "bt_ctf_clock_get_frequency correctly handles NULL");
1960 ok(bt_ctf_clock_get_precision(NULL) == -1ULL,
1961 "bt_ctf_clock_get_precision correctly handles NULL");
1962 ok(bt_ctf_clock_get_offset_s(NULL) == -1ULL,
1963 "bt_ctf_clock_get_offset_s correctly handles NULL");
1964 ok(bt_ctf_clock_get_offset(NULL) == -1ULL,
1965 "bt_ctf_clock_get_offset correctly handles NULL");
1966 ok(bt_ctf_clock_get_is_absolute(NULL) < 0,
1967 "bt_ctf_clock_get_is_absolute correctly handles NULL");
1968 ok(bt_ctf_clock_get_time(NULL) == -1ULL,
1969 "bt_ctf_clock_get_time correctly handles NULL");
1970
1971 ok(bt_ctf_clock_set_description(NULL, NULL) < 0,
1972 "bt_ctf_clock_set_description correctly handles NULL clock");
1973 ok(bt_ctf_clock_set_frequency(NULL, frequency) < 0,
1974 "bt_ctf_clock_set_frequency correctly handles NULL clock");
1975 ok(bt_ctf_clock_set_precision(NULL, precision) < 0,
1976 "bt_ctf_clock_get_precision correctly handles NULL clock");
1977 ok(bt_ctf_clock_set_offset_s(NULL, offset_s) < 0,
1978 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
1979 ok(bt_ctf_clock_set_offset(NULL, offset) < 0,
1980 "bt_ctf_clock_set_offset correctly handles NULL clock");
1981 ok(bt_ctf_clock_set_is_absolute(NULL, is_absolute) < 0,
1982 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
1983 ok(bt_ctf_clock_set_time(NULL, current_time) < 0,
1984 "bt_ctf_clock_set_time correctly handles NULL clock");
1985 ok(bt_ctf_clock_get_uuid(NULL) == NULL,
1986 "bt_ctf_clock_get_uuid correctly handles NULL clock");
1987 ret_uuid = bt_ctf_clock_get_uuid(clock);
1988 ok(ret_uuid,
1989 "bt_ctf_clock_get_uuid returns a UUID");
1990 if (ret_uuid) {
1991 memcpy(tmp_uuid, ret_uuid, sizeof(tmp_uuid));
1992 /* Slightly modify UUID */
1993 tmp_uuid[sizeof(tmp_uuid) - 1]++;
1994 }
1995
1996 ok(bt_ctf_clock_set_uuid(NULL, tmp_uuid) < 0,
1997 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
1998 ok(bt_ctf_clock_set_uuid(clock, NULL) < 0,
1999 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
2000 ok(bt_ctf_clock_set_uuid(clock, tmp_uuid) == 0,
2001 "bt_ctf_clock_set_uuid sets a new uuid succesfully");
2002 ret_uuid = bt_ctf_clock_get_uuid(clock);
2003 ok(ret_uuid,
2004 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
2005 ok(uuid_match(ret_uuid, tmp_uuid),
2006 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
2007
2008 /* Define a stream class */
2009 stream_class = bt_ctf_stream_class_create("test_stream");
2010
2011 ok(bt_ctf_stream_class_get_name(NULL) == NULL,
2012 "bt_ctf_stream_class_get_name handles NULL correctly");
2013 ret_string = bt_ctf_stream_class_get_name(stream_class);
2014 ok(ret_string && !strcmp(ret_string, "test_stream"),
2015 "bt_ctf_stream_class_get_name returns a correct stream class name");
2016
2017 ok(bt_ctf_stream_class_get_clock(stream_class) == NULL,
2018 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
2019 ok(bt_ctf_stream_class_get_clock(NULL) == NULL,
2020 "bt_ctf_stream_class_get_clock handles NULL correctly");
2021
2022 ok(stream_class, "Create stream class");
2023 ok(bt_ctf_stream_class_set_clock(stream_class, clock) == 0,
2024 "Set a stream class' clock");
2025 ret_clock = bt_ctf_stream_class_get_clock(stream_class);
2026 ok(ret_clock == clock,
2027 "bt_ctf_stream_class_get_clock returns a correct clock");
2028 bt_ctf_clock_put(ret_clock);
2029
2030 /* Test the event fields and event types APIs */
2031 type_field_tests();
2032
2033 ok(bt_ctf_stream_class_get_id(stream_class) < 0,
2034 "bt_ctf_stream_class_get_id returns an error when no id is set");
2035 ok(bt_ctf_stream_class_get_id(NULL) < 0,
2036 "bt_ctf_stream_class_get_id handles NULL correctly");
2037 ok(bt_ctf_stream_class_set_id(NULL, 123) < 0,
2038 "bt_ctf_stream_class_set_id handles NULL correctly");
2039 ok(bt_ctf_stream_class_set_id(stream_class, 123) == 0,
2040 "Set an stream class' id");
2041 ok(bt_ctf_stream_class_get_id(stream_class) == 123,
2042 "bt_ctf_stream_class_get_id returns the correct value");
2043
2044 /* Validate default event header fields */
2045 ok(bt_ctf_stream_class_get_event_header_type(NULL) == NULL,
2046 "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
2047 ret_field_type = bt_ctf_stream_class_get_event_header_type(
2048 stream_class);
2049 ok(ret_field_type,
2050 "bt_ctf_stream_class_get_event_header_type returns an event header type");
2051 ok(bt_ctf_field_type_get_type_id(ret_field_type) == CTF_TYPE_STRUCT,
2052 "Default event header type is a structure");
2053 event_header_field_type =
2054 bt_ctf_field_type_structure_get_field_type_by_name(
2055 ret_field_type, "id");
2056 ok(event_header_field_type,
2057 "Default event header type contains an \"id\" field");
2058 ok(bt_ctf_field_type_get_type_id(
2059 event_header_field_type) == CTF_TYPE_INTEGER,
2060 "Default event header \"id\" field is an integer");
2061 bt_ctf_field_type_put(event_header_field_type);
2062 event_header_field_type =
2063 bt_ctf_field_type_structure_get_field_type_by_name(
2064 ret_field_type, "timestamp");
2065 ok(event_header_field_type,
2066 "Default event header type contains a \"timestamp\" field");
2067 ok(bt_ctf_field_type_get_type_id(
2068 event_header_field_type) == CTF_TYPE_INTEGER,
2069 "Default event header \"timestamp\" field is an integer");
2070 bt_ctf_field_type_put(event_header_field_type);
2071 bt_ctf_field_type_put(ret_field_type);
2072
2073 /* Add a custom trace packet header field */
2074 ok(bt_ctf_trace_get_packet_header_type(NULL) == NULL,
2075 "bt_ctf_trace_get_packet_header_type handles NULL correctly");
2076 packet_header_type = bt_ctf_trace_get_packet_header_type(trace);
2077 ok(packet_header_type,
2078 "bt_ctf_trace_get_packet_header_type returns a packet header");
2079 ok(bt_ctf_field_type_get_type_id(packet_header_type) == CTF_TYPE_STRUCT,
2080 "bt_ctf_trace_get_packet_header_type returns a packet header of type struct");
2081 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
2082 packet_header_type, "magic");
2083 ok(ret_field_type, "Default packet header type contains a \"magic\" field");
2084 bt_ctf_field_type_put(ret_field_type);
2085 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
2086 packet_header_type, "uuid");
2087 ok(ret_field_type, "Default packet header type contains a \"uuid\" field");
2088 bt_ctf_field_type_put(ret_field_type);
2089 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
2090 packet_header_type, "stream_id");
2091 ok(ret_field_type, "Default packet header type contains a \"stream_id\" field");
2092 bt_ctf_field_type_put(ret_field_type);
2093
2094 packet_header_field_type = bt_ctf_field_type_integer_create(22);
2095 ok(!bt_ctf_field_type_structure_add_field(packet_header_type,
2096 packet_header_field_type, "custom_trace_packet_header_field"),
2097 "Added a custom trace packet header field successfully");
2098
2099 ok(bt_ctf_trace_set_packet_header_type(NULL, packet_header_type) < 0,
2100 "bt_ctf_trace_set_packet_header_type handles a NULL trace correctly");
2101 ok(bt_ctf_trace_set_packet_header_type(trace, NULL) < 0,
2102 "bt_ctf_trace_set_packet_header_type handles a NULL packet_header_type correctly");
2103 ok(!bt_ctf_trace_set_packet_header_type(trace, packet_header_type),
2104 "Set a trace packet_header_type successfully");
2105
2106 ok(bt_ctf_stream_class_get_packet_context_type(NULL) == NULL,
2107 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
2108
2109 /* Add a custom field to the stream class' packet context */
2110 packet_context_type = bt_ctf_stream_class_get_packet_context_type(stream_class);
2111 ok(packet_context_type,
2112 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
2113 ok(bt_ctf_field_type_get_type_id(packet_context_type) == CTF_TYPE_STRUCT,
2114 "Packet context is a structure");
2115
2116 ok(bt_ctf_stream_class_set_packet_context_type(NULL, packet_context_type),
2117 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
2118 ok(bt_ctf_stream_class_set_packet_context_type(stream_class, NULL),
2119 "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly");
2120
2121 integer_type = bt_ctf_field_type_integer_create(32);
2122 ok(bt_ctf_stream_class_set_packet_context_type(stream_class,
2123 integer_type) < 0,
2124 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
2125 /* Create a "uint5_t" equivalent custom packet context field */
2126 packet_context_field_type = bt_ctf_field_type_integer_create(5);
2127
2128 ret = bt_ctf_field_type_structure_add_field(packet_context_type,
2129 packet_context_field_type, "custom_packet_context_field");
2130 ok(ret == 0, "Packet context field added successfully");
2131
2132 /* Define a stream event context containing a my_integer field. */
2133 ok(bt_ctf_stream_class_get_event_context_type(NULL) == NULL,
2134 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
2135 ok(bt_ctf_stream_class_get_event_context_type(
2136 stream_class) == NULL,
2137 "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set.");
2138 stream_event_context_type = bt_ctf_field_type_structure_create();
2139 bt_ctf_field_type_structure_add_field(stream_event_context_type,
2140 integer_type, "common_event_context");
2141
2142 ok(bt_ctf_stream_class_set_event_context_type(NULL,
2143 stream_event_context_type) < 0,
2144 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
2145 ok(bt_ctf_stream_class_set_event_context_type(stream_class,
2146 NULL) < 0,
2147 "bt_ctf_stream_class_set_event_context_type handles a NULL event_context correctly");
2148 ok(bt_ctf_stream_class_set_event_context_type(stream_class,
2149 integer_type) < 0,
2150 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
2151
2152 ok(bt_ctf_stream_class_set_event_context_type(
2153 stream_class, stream_event_context_type) == 0,
2154 "Set a new stream event context type");
2155 ret_field_type = bt_ctf_stream_class_get_event_context_type(
2156 stream_class);
2157 ok(ret_field_type == stream_event_context_type,
2158 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
2159 bt_ctf_field_type_put(ret_field_type);
2160
2161 /* Instantiate a stream and append events */
2162 stream1 = bt_ctf_writer_create_stream(writer, stream_class);
2163 ok(stream1, "Instanciate a stream class from writer");
2164
2165 ok(bt_ctf_stream_get_class(NULL) == NULL,
2166 "bt_ctf_stream_get_class correctly handles NULL");
2167 ret_stream_class = bt_ctf_stream_get_class(stream1);
2168 ok(ret_stream_class,
2169 "bt_ctf_stream_get_class returns a stream class");
2170 ok(ret_stream_class == stream_class,
2171 "Returned stream class is of the correct type");
2172
2173 /*
2174 * Try to modify the packet context type after a stream has been
2175 * created.
2176 */
2177 ret = bt_ctf_field_type_structure_add_field(packet_header_type,
2178 packet_header_field_type, "should_fail");
2179 ok(ret < 0,
2180 "Trace packet header type can't be modified once a stream has been instanciated");
2181
2182 /*
2183 * Try to modify the packet context type after a stream has been
2184 * created.
2185 */
2186 ret = bt_ctf_field_type_structure_add_field(packet_context_type,
2187 packet_context_field_type, "should_fail");
2188 ok(ret < 0,
2189 "Packet context type can't be modified once a stream has been instanciated");
2190
2191 /*
2192 * Try to modify the stream event context type after a stream has been
2193 * created.
2194 */
2195 ret = bt_ctf_field_type_structure_add_field(stream_event_context_type,
2196 integer_type, "should_fail");
2197 ok(ret < 0,
2198 "Stream event context type can't be modified once a stream has been instanciated");
2199
2200 /* Should fail after instanciating a stream (frozen) */
2201 ok(bt_ctf_stream_class_set_clock(stream_class, clock),
2202 "Changes to a stream class that was already instantiated fail");
2203
2204 /* Populate the custom packet header field only once for all tests */
2205 ok(bt_ctf_stream_get_packet_header(NULL) == NULL,
2206 "bt_ctf_stream_get_packet_header handles NULL correctly");
2207 packet_header = bt_ctf_stream_get_packet_header(stream1);
2208 ok(packet_header,
2209 "bt_ctf_stream_get_packet_header returns a packet header");
2210 ret_field_type = bt_ctf_field_get_type(packet_header);
2211 ok(ret_field_type == packet_header_type,
2212 "Stream returns a packet header of the appropriate type");
2213 bt_ctf_field_type_put(ret_field_type);
2214 packet_header_field = bt_ctf_field_structure_get_field(packet_header,
2215 "custom_trace_packet_header_field");
2216 ok(packet_header_field,
2217 "Packet header structure contains a custom field with the appropriate name");
2218 ret_field_type = bt_ctf_field_get_type(packet_header_field);
2219 ok(ret_field_type == packet_header_field_type,
2220 "Custom packet header field is of the expected type");
2221 ok(!bt_ctf_field_unsigned_integer_set_value(packet_header_field,
2222 54321), "Set custom packet header value successfully");
2223 ok(bt_ctf_stream_set_packet_header(stream1, NULL) < 0,
2224 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
2225 ok(bt_ctf_stream_set_packet_header(NULL, packet_header) < 0,
2226 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
2227 ok(bt_ctf_stream_set_packet_header(stream1, packet_header_field) < 0,
2228 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
2229 ok(!bt_ctf_stream_set_packet_header(stream1, packet_header),
2230 "Successfully set a stream's packet header");
2231
2232 test_instanciate_event_before_stream(writer);
2233
2234 append_simple_event(stream_class, stream1, clock);
2235
2236 packet_resize_test(stream_class, stream1, clock);
2237
2238 append_complex_event(stream_class, stream1, clock);
2239
2240 test_empty_stream(writer);
2241
2242 metadata_string = bt_ctf_writer_get_metadata_string(writer);
2243 ok(metadata_string, "Get metadata string");
2244
2245 bt_ctf_writer_flush_metadata(writer);
2246 validate_metadata(argv[1], metadata_path);
2247 validate_trace(argv[2], trace_path);
2248
2249 bt_ctf_clock_put(clock);
2250 bt_ctf_stream_class_put(stream_class);
2251 bt_ctf_stream_class_put(ret_stream_class);
2252 bt_ctf_writer_put(writer);
2253 bt_ctf_stream_put(stream1);
2254 bt_ctf_field_type_put(packet_context_type);
2255 bt_ctf_field_type_put(packet_context_field_type);
2256 bt_ctf_field_type_put(integer_type);
2257 bt_ctf_field_type_put(stream_event_context_type);
2258 bt_ctf_field_type_put(ret_field_type);
2259 bt_ctf_field_type_put(packet_header_type);
2260 bt_ctf_field_type_put(packet_header_field_type);
2261 bt_ctf_field_put(packet_header);
2262 bt_ctf_field_put(packet_header_field);
2263 bt_ctf_trace_put(trace);
2264 free(metadata_string);
2265
2266 /* Remove all trace files and delete temporary trace directory */
2267 DIR *trace_dir = opendir(trace_path);
2268 if (!trace_dir) {
2269 perror("# opendir");
2270 return -1;
2271 }
2272
2273 struct dirent *entry;
2274 while ((entry = readdir(trace_dir))) {
2275 if (entry->d_type == DT_REG) {
2276 unlinkat(dirfd(trace_dir), entry->d_name, 0);
2277 }
2278 }
2279
2280 rmdir(trace_path);
2281 closedir(trace_dir);
2282 return 0;
2283 }
This page took 0.092281 seconds and 3 git commands to generate.