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