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