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