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