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