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