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