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