6 * Copyright 2013 - 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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.
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.
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>
28 #include <babeltrace/ctf-writer/stream-class.h>
29 #include <babeltrace/ctf-ir/packet.h>
30 #include <babeltrace/ctf-ir/clock-class.h>
31 #include <babeltrace/ctf-ir/trace.h>
32 #include <babeltrace/ref.h>
33 #include <babeltrace/ctf/events.h>
34 #include <babeltrace/values.h>
36 #include <babeltrace/compat/stdlib-internal.h>
38 #include <babeltrace/compat/utsname-internal.h>
39 #include <babeltrace/compat/limits-internal.h>
40 #include <babeltrace/compat/stdio-internal.h>
45 #include <babeltrace/compat/dirent-internal.h>
51 #define METADATA_LINE_SIZE 512
52 #define SEQUENCE_TEST_LENGTH 10
53 #define ARRAY_TEST_LENGTH 5
54 #define PACKET_RESIZE_TEST_LENGTH 100000
56 #define DEFAULT_CLOCK_FREQ 1000000000
57 #define DEFAULT_CLOCK_PRECISION 1
58 #define DEFAULT_CLOCK_OFFSET 0
59 #define DEFAULT_CLOCK_OFFSET_S 0
60 #define DEFAULT_CLOCK_IS_ABSOLUTE 0
61 #define DEFAULT_CLOCK_TIME 0
62 #define DEFAULT_CLOCK_VALUE 0
66 static int64_t current_time
= 42;
68 /* Return 1 if uuids match, zero if different. */
70 int uuid_match(const unsigned char *uuid_a
, const unsigned char *uuid_b
)
75 if (!uuid_a
|| !uuid_b
) {
79 for (i
= 0; i
< 16; i
++) {
80 if (uuid_a
[i
] != uuid_b
[i
]) {
91 void validate_trace(char *parser_path
, char *trace_path
)
94 char babeltrace_output_path
[] = "/tmp/babeltrace_output_XXXXXX";
95 int babeltrace_output_fd
= -1;
102 babeltrace_output_fd
= mkstemp(babeltrace_output_path
);
103 unlink(babeltrace_output_path
);
105 if (babeltrace_output_fd
== -1) {
106 diag("Failed to create a temporary file for trace parsing.");
114 waitpid(pid
, &status
, 0);
115 ret
= WIFEXITED(status
) ? WEXITSTATUS(status
) : -1;
117 ret
= dup2(babeltrace_output_fd
, STDOUT_FILENO
);
119 perror("# dup2 babeltrace_output_fd to STDOUT");
123 ret
= dup2(babeltrace_output_fd
, STDERR_FILENO
);
125 perror("# dup2 babeltrace_output_fd to STDERR");
129 execl(parser_path
, "babeltrace", trace_path
, NULL
);
130 perror("# Could not launch the babeltrace process");
134 ok(ret
== 0, "Babeltrace could read the resulting trace");
136 if (ret
&& babeltrace_output_fd
>= 0) {
138 size_t len
= METADATA_LINE_SIZE
;
139 FILE *babeltrace_output_fp
= NULL
;
141 babeltrace_output_fp
= fdopen(babeltrace_output_fd
, "r");
142 if (!babeltrace_output_fp
) {
143 perror("fdopen on babeltrace_output_fd");
146 babeltrace_output_fd
= -1;
150 diag("malloc error");
152 rewind(babeltrace_output_fp
);
153 while (bt_getline(&line
, &len
, babeltrace_output_fp
) > 0) {
159 if (babeltrace_output_fp
) {
160 if (fclose(babeltrace_output_fp
)) {
161 diag("fclose error");
166 if (babeltrace_output_fd
>= 0) {
167 if (close(babeltrace_output_fd
)) {
174 void append_simple_event(struct bt_ctf_stream_class
*stream_class
,
175 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
177 /* Create and add a simple event class */
178 struct bt_ctf_event_class
*simple_event_class
=
179 bt_ctf_event_class_create("Simple Event");
180 struct bt_ctf_field_type
*uint_12_type
=
181 bt_ctf_field_type_integer_create(12);
182 struct bt_ctf_field_type
*int_64_type
=
183 bt_ctf_field_type_integer_create(64);
184 struct bt_ctf_field_type
*float_type
=
185 bt_ctf_field_type_floating_point_create();
186 struct bt_ctf_field_type
*enum_type
;
187 struct bt_ctf_field_type
*enum_type_unsigned
=
188 bt_ctf_field_type_enumeration_create(uint_12_type
);
189 struct bt_ctf_field_type
*event_context_type
=
190 bt_ctf_field_type_structure_create();
191 struct bt_ctf_field_type
*event_payload_type
= NULL
;
192 struct bt_ctf_field_type
*returned_type
;
193 struct bt_ctf_event
*simple_event
;
194 struct bt_ctf_field
*integer_field
;
195 struct bt_ctf_field
*float_field
;
196 struct bt_ctf_field
*enum_field
;
197 struct bt_ctf_field
*enum_field_unsigned
;
198 struct bt_ctf_field
*enum_container_field
;
199 const char *mapping_name_test
= "truie";
200 const double double_test_value
= 3.1415;
201 struct bt_ctf_field
*enum_container_field_unsigned
;
202 const char *mapping_name_negative_test
= "negative_value";
203 const char *ret_char
;
205 int64_t ret_range_start_int64_t
, ret_range_end_int64_t
;
206 uint64_t ret_range_start_uint64_t
, ret_range_end_uint64_t
;
207 struct bt_ctf_event_class
*ret_event_class
;
208 struct bt_ctf_field
*packet_context
;
209 struct bt_ctf_field
*packet_context_field
;
210 struct bt_ctf_field
*stream_event_context
;
211 struct bt_ctf_field
*stream_event_context_field
;
212 struct bt_ctf_field
*event_context
;
213 struct bt_ctf_field
*event_context_field
;
214 struct bt_ctf_field_type
*ep_integer_field_type
= NULL
;
215 struct bt_ctf_field_type
*ep_enum_field_type
= NULL
;
216 struct bt_ctf_field_type
*ep_enum_field_unsigned_type
= NULL
;
217 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
220 ok(uint_12_type
, "Create an unsigned integer type");
222 ok(!bt_ctf_field_type_integer_set_signed(int_64_type
, 1),
223 "Set signed 64 bit integer signedness to true");
224 ok(int_64_type
, "Create a signed integer type");
225 enum_type
= bt_ctf_field_type_enumeration_create(int_64_type
);
227 returned_type
= bt_ctf_field_type_enumeration_get_container_type(enum_type
);
228 ok(returned_type
== int_64_type
, "bt_ctf_field_type_enumeration_get_container_type returns the right type");
229 ok(!bt_ctf_field_type_enumeration_get_container_type(NULL
), "bt_ctf_field_type_enumeration_get_container_type handles NULL correctly");
230 ok(!bt_ctf_field_type_enumeration_create(enum_type
),
231 "bt_ctf_field_enumeration_type_create rejects non-integer container field types");
232 bt_put(returned_type
);
234 bt_ctf_field_type_set_alignment(float_type
, 32);
235 ok(bt_ctf_field_type_get_alignment(NULL
) < 0,
236 "bt_ctf_field_type_get_alignment handles NULL correctly");
237 ok(bt_ctf_field_type_get_alignment(float_type
) == 32,
238 "bt_ctf_field_type_get_alignment returns a correct value");
240 ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type
, 11) == 0,
241 "Set a floating point type's exponent digit count");
242 ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type
, 53) == 0,
243 "Set a floating point type's mantissa digit count");
245 ok(bt_ctf_field_type_floating_point_get_exponent_digits(NULL
) < 0,
246 "bt_ctf_field_type_floating_point_get_exponent_digits handles NULL properly");
247 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(NULL
) < 0,
248 "bt_ctf_field_type_floating_point_get_mantissa_digits handles NULL properly");
249 ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type
) == 11,
250 "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value");
251 ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type
) == 53,
252 "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value");
254 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
255 mapping_name_negative_test
, -12345, 0) == 0,
256 "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings");
257 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
258 "escaping; \"test\"", 1, 1) == 0,
259 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes");
260 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
261 "\tanother \'escaping\'\n test\"", 2, 4) == 0,
262 "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters");
263 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
,
264 "event clock int float", 5, 22) == 0,
265 "Accept enumeration mapping strings containing reserved keywords");
266 bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
268 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
269 43, 51) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts duplicate mapping names");
270 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, "something",
271 -500, -400) == 0, "bt_ctf_field_type_enumeration_add_mapping accepts overlapping enum entries");
272 ok(bt_ctf_field_type_enumeration_add_mapping(enum_type
, mapping_name_test
,
273 -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start");
274 bt_ctf_field_type_enumeration_add_mapping(enum_type
, "another entry", -42000, -13000);
276 iter
= bt_ctf_field_type_enumeration_find_mappings_by_signed_value(NULL
, -42);
277 ok(iter
== NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_signed_value handles a NULL field type correctly");
279 iter
= bt_ctf_field_type_enumeration_find_mappings_by_signed_value(enum_type
, -4200000);
280 ok(iter
== NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_signed_value rejects non-mapped values");
282 iter
= bt_ctf_field_type_enumeration_find_mappings_by_signed_value(enum_type
, 3);
283 ok(iter
!= NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_signed_value succeeds with mapped value");
284 ok(bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter
, NULL
, NULL
, NULL
) == 0,
285 "bt_ctf_field_type_enumeration_mapping_iterator_get_signed handles mapped values correctly");
288 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type
,
289 "enum_field") == 0, "Add signed enumeration field to event");
291 ok(bt_ctf_field_type_enumeration_get_mapping_signed(NULL
, 0, &ret_char
,
292 &ret_range_start_int64_t
, &ret_range_end_int64_t
) < 0,
293 "bt_ctf_field_type_enumeration_get_mapping_signed handles a NULL enumeration correctly");
294 ok(bt_ctf_field_type_enumeration_get_mapping_signed(enum_type
, 0, NULL
,
295 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
296 "bt_ctf_field_type_enumeration_get_mapping_signed handles a NULL string correctly");
297 ok(bt_ctf_field_type_enumeration_get_mapping_signed(enum_type
, 0, &ret_char
,
298 NULL
, &ret_range_end_int64_t
) == 0,
299 "bt_ctf_field_type_enumeration_get_mapping_signed handles a NULL start correctly");
300 ok(bt_ctf_field_type_enumeration_get_mapping_signed(enum_type
, 0, &ret_char
,
301 &ret_range_start_int64_t
, NULL
) == 0,
302 "bt_ctf_field_type_enumeration_get_mapping_signed handles a NULL end correctly");
303 /* Assumes entries are sorted by range_start values. */
304 ok(bt_ctf_field_type_enumeration_get_mapping_signed(enum_type
, 6, &ret_char
,
305 &ret_range_start_int64_t
, &ret_range_end_int64_t
) == 0,
306 "bt_ctf_field_type_enumeration_get_mapping_signed returns a value");
307 ok(!strcmp(ret_char
, mapping_name_test
),
308 "bt_ctf_field_type_enumeration_get_mapping_signed returns a correct mapping name");
309 ok(ret_range_start_int64_t
== 42,
310 "bt_ctf_field_type_enumeration_get_mapping_signed returns a correct mapping start");
311 ok(ret_range_end_int64_t
== 42,
312 "bt_ctf_field_type_enumeration_get_mapping_signed returns a correct mapping end");
314 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
315 "escaping; \"test\"", 0, 0) == 0,
316 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing quotes");
317 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
318 "\tanother \'escaping\'\n test\"", 1, 4) == 0,
319 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing special characters");
320 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
,
321 "event clock int float", 5, 22) == 0,
322 "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing reserved keywords");
323 bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
325 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
326 43, 51) == 0, "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts duplicate mapping names");
327 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, "something",
328 7, 8) == 0, "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts overlapping enum entries");
329 ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned
, mapping_name_test
,
330 55, 54), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects mapping where end < start");
331 ok(bt_ctf_event_class_add_field(simple_event_class
, enum_type_unsigned
,
332 "enum_field_unsigned") == 0, "Add unsigned enumeration field to event");
334 ok(bt_ctf_field_type_enumeration_get_mapping_count(NULL
) < 0,
335 "bt_ctf_field_type_enumeration_get_mapping_count handles NULL correctly");
336 ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned
) == 6,
337 "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value");
339 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(NULL
, 0, &ret_char
,
340 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) < 0,
341 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL enumeration correctly");
342 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, NULL
,
343 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
344 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL string correctly");
345 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, &ret_char
,
346 NULL
, &ret_range_end_uint64_t
) == 0,
347 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL start correctly");
348 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 0, &ret_char
,
349 &ret_range_start_uint64_t
, NULL
) == 0,
350 "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL end correctly");
351 ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned
, 4, &ret_char
,
352 &ret_range_start_uint64_t
, &ret_range_end_uint64_t
) == 0,
353 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a value");
354 ok(!strcmp(ret_char
, mapping_name_test
),
355 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping name");
356 ok(ret_range_start_uint64_t
== 42,
357 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping start");
358 ok(ret_range_end_uint64_t
== 42,
359 "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping end");
361 bt_ctf_event_class_add_field(simple_event_class
, uint_12_type
,
363 bt_ctf_event_class_add_field(simple_event_class
, float_type
,
366 assert(!bt_ctf_event_class_set_id(simple_event_class
, 13));
368 /* Set an event context type which will contain a single integer. */
369 ok(!bt_ctf_field_type_structure_add_field(event_context_type
, uint_12_type
,
370 "event_specific_context"),
371 "Add event specific context field");
372 ok(bt_ctf_event_class_get_context_type(NULL
) == NULL
,
373 "bt_ctf_event_class_get_context_type handles NULL correctly");
375 ok(bt_ctf_event_class_set_context_type(NULL
, event_context_type
) < 0,
376 "bt_ctf_event_class_set_context_type handles a NULL event class correctly");
377 ok(!bt_ctf_event_class_set_context_type(simple_event_class
, event_context_type
),
378 "Set an event class' context type successfully");
379 returned_type
= bt_ctf_event_class_get_context_type(simple_event_class
);
380 ok(returned_type
== event_context_type
,
381 "bt_ctf_event_class_get_context_type returns the appropriate type");
382 bt_put(returned_type
);
384 ok(!bt_ctf_stream_class_add_event_class(stream_class
, simple_event_class
),
385 "Adding simple event class to stream class");
388 * bt_ctf_stream_class_add_event_class() copies the field types
389 * of simple_event_class, so we retrieve the new ones to create
390 * the appropriate fields.
392 BT_PUT(event_context_type
);
393 BT_PUT(event_payload_type
);
394 event_payload_type
= bt_ctf_event_class_get_payload_type(
396 assert(event_payload_type
);
397 event_context_type
= bt_ctf_event_class_get_context_type(
399 assert(event_context_type
);
400 ep_integer_field_type
=
401 bt_ctf_field_type_structure_get_field_type_by_name(
402 event_payload_type
, "integer_field");
403 assert(ep_integer_field_type
);
405 bt_ctf_field_type_structure_get_field_type_by_name(
406 event_payload_type
, "enum_field");
407 assert(ep_enum_field_type
);
408 ep_enum_field_unsigned_type
=
409 bt_ctf_field_type_structure_get_field_type_by_name(
410 event_payload_type
, "enum_field_unsigned");
411 assert(ep_enum_field_unsigned_type
);
413 ok(bt_ctf_stream_class_get_event_class_count(NULL
) < 0,
414 "bt_ctf_stream_class_get_event_class_count handles NULL correctly");
415 ok(bt_ctf_stream_class_get_event_class_count(stream_class
) == 1,
416 "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes");
417 ok(bt_ctf_stream_class_get_event_class_by_index(NULL
, 0) == NULL
,
418 "bt_ctf_stream_class_get_event_class handles NULL correctly");
419 ok(bt_ctf_stream_class_get_event_class_by_index(stream_class
, 8724) == NULL
,
420 "bt_ctf_stream_class_get_event_class handles invalid indexes correctly");
421 ret_event_class
= bt_ctf_stream_class_get_event_class_by_index(stream_class
, 0);
422 ok(ret_event_class
== simple_event_class
,
423 "bt_ctf_stream_class_get_event_class returns the correct event class");
424 bt_put(ret_event_class
);
425 ok(!bt_ctf_stream_class_get_event_class_by_id(NULL
, 0),
426 "bt_ctf_stream_class_get_event_class_by_id handles NULL correctly");
427 ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class
, 2),
428 "bt_ctf_stream_class_get_event_class_by_id returns NULL when the requested ID doesn't exist");
430 bt_ctf_stream_class_get_event_class_by_id(stream_class
, 13);
431 ok(ret_event_class
== simple_event_class
,
432 "bt_ctf_stream_class_get_event_class_by_id returns a correct event class");
433 bt_put(ret_event_class
);
435 simple_event
= bt_ctf_event_create(simple_event_class
);
437 "Instantiate an event containing a single integer field");
439 integer_field
= bt_ctf_field_create(ep_integer_field_type
);
440 bt_ctf_field_unsigned_integer_set_value(integer_field
, 42);
441 ok(bt_ctf_event_set_payload(simple_event
, "integer_field",
442 integer_field
) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field");
444 float_field
= bt_ctf_event_get_payload(simple_event
, "float_field");
445 ok(bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
446 "bt_ctf_field_floating_point_get_value fails on an unset float field");
447 bt_ctf_field_floating_point_set_value(float_field
, double_test_value
);
448 ok(bt_ctf_field_floating_point_get_value(NULL
, &ret_double
),
449 "bt_ctf_field_floating_point_get_value properly handles a NULL field");
450 ok(bt_ctf_field_floating_point_get_value(float_field
, NULL
),
451 "bt_ctf_field_floating_point_get_value properly handles a NULL return value pointer");
452 ok(!bt_ctf_field_floating_point_get_value(float_field
, &ret_double
),
453 "bt_ctf_field_floating_point_get_value returns a double value");
454 ok(fabs(ret_double
- double_test_value
) <= DBL_EPSILON
,
455 "bt_ctf_field_floating_point_get_value returns a correct value");
457 enum_field
= bt_ctf_field_create(ep_enum_field_type
);
460 iter
= bt_ctf_field_enumeration_get_mappings(NULL
);
461 ok(!iter
, "bt_ctf_field_enumeration_get_mappings handles NULL correctly");
462 iter
= bt_ctf_field_enumeration_get_mappings(enum_field
);
463 ok(!iter
, "bt_ctf_field_enumeration_get_mappings returns NULL if the enumeration's container field is unset");
464 enum_container_field
= bt_ctf_field_enumeration_get_container(
466 ok(bt_ctf_field_signed_integer_set_value(
467 enum_container_field
, -42) == 0,
468 "Set signed enumeration container value");
469 iter
= bt_ctf_field_enumeration_get_mappings(enum_field
);
470 ok(iter
, "bt_ctf_field_enumeration_get_mappings returns an iterator to matching mappings");
471 ret
= bt_ctf_field_type_enumeration_mapping_iterator_get_signed(iter
, &ret_char
, NULL
, NULL
);
472 ok(!ret
&& ret_char
, "bt_ctf_field_type_enumeration_mapping_iterator_get_signed return a mapping name");
474 ok(!strcmp(ret_char
, mapping_name_negative_test
),
475 "bt_ctf_field_enumeration_get_single_mapping_name returns the correct mapping name with an signed container");
476 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field", enum_field
);
480 enum_field_unsigned
= bt_ctf_field_create(ep_enum_field_unsigned_type
);
481 assert(enum_field_unsigned
);
482 enum_container_field_unsigned
= bt_ctf_field_enumeration_get_container(
483 enum_field_unsigned
);
484 ok(bt_ctf_field_unsigned_integer_set_value(
485 enum_container_field_unsigned
, 42) == 0,
486 "Set unsigned enumeration container value");
487 ret
= bt_ctf_event_set_payload(simple_event
, "enum_field_unsigned",
488 enum_field_unsigned
);
490 iter
= bt_ctf_field_enumeration_get_mappings(enum_field_unsigned
);
492 (void) bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(iter
, &ret_char
, NULL
, NULL
);
493 ok(ret_char
&& !strcmp(ret_char
, mapping_name_test
),
494 "bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned returns the correct mapping name with an unsigned container");
496 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0, "Set clock time");
498 /* Populate stream event context */
499 stream_event_context
=
500 bt_ctf_event_get_stream_event_context(simple_event
);
501 assert(stream_event_context
);
502 stream_event_context_field
= bt_ctf_field_structure_get_field(
503 stream_event_context
, "common_event_context");
504 bt_ctf_field_unsigned_integer_set_value(stream_event_context_field
, 42);
506 /* Populate the event's context */
507 ok(bt_ctf_event_get_event_context(NULL
) == NULL
,
508 "bt_ctf_event_get_event_context handles NULL correctly");
509 event_context
= bt_ctf_event_get_event_context(simple_event
);
511 "bt_ctf_event_get_event_context returns a field");
512 returned_type
= bt_ctf_field_get_type(event_context
);
513 ok(returned_type
== event_context_type
,
514 "bt_ctf_event_get_event_context returns a field of the appropriate type");
515 event_context_field
= bt_ctf_field_structure_get_field(event_context
,
516 "event_specific_context");
517 ok(!bt_ctf_field_unsigned_integer_set_value(event_context_field
, 1234),
518 "Successfully set an event context's value");
519 ok(bt_ctf_event_set_event_context(NULL
, event_context
) < 0,
520 "bt_ctf_event_set_event_context handles a NULL event correctly");
521 ok(bt_ctf_event_set_event_context(simple_event
, NULL
) < 0,
522 "bt_ctf_event_set_event_context handles a NULL event context correctly");
523 ok(bt_ctf_event_set_event_context(simple_event
, event_context_field
) < 0,
524 "bt_ctf_event_set_event_context rejects a context of the wrong type");
525 ok(!bt_ctf_event_set_event_context(simple_event
, event_context
),
526 "Set an event context successfully");
528 ok(bt_ctf_stream_append_event(stream
, simple_event
) == 0,
529 "Append simple event to trace stream");
531 ok(bt_ctf_stream_get_packet_context(NULL
) == NULL
,
532 "bt_ctf_stream_get_packet_context handles NULL correctly");
533 packet_context
= bt_ctf_stream_get_packet_context(stream
);
535 "bt_ctf_stream_get_packet_context returns a packet context");
537 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
539 ok(packet_context_field
,
540 "Packet context contains the default packet_size field.");
541 bt_put(packet_context_field
);
542 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
543 "custom_packet_context_field");
544 ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 8) == 0,
545 "Custom packet context field value successfully set.");
547 ok(bt_ctf_stream_set_packet_context(NULL
, packet_context_field
) < 0,
548 "bt_ctf_stream_set_packet_context handles a NULL stream correctly");
549 ok(bt_ctf_stream_set_packet_context(stream
, NULL
) < 0,
550 "bt_ctf_stream_set_packet_context handles a NULL packet context correctly");
551 ok(bt_ctf_stream_set_packet_context(stream
, packet_context
) == 0,
552 "Successfully set a stream's packet context");
554 ok(bt_ctf_stream_flush(stream
) == 0,
555 "Flush trace stream with one event");
557 bt_put(simple_event_class
);
558 bt_put(simple_event
);
559 bt_put(uint_12_type
);
563 bt_put(enum_type_unsigned
);
564 bt_put(returned_type
);
565 bt_put(event_context_type
);
566 bt_put(integer_field
);
569 bt_put(enum_field_unsigned
);
570 bt_put(enum_container_field
);
571 bt_put(enum_container_field_unsigned
);
572 bt_put(packet_context
);
573 bt_put(packet_context_field
);
574 bt_put(stream_event_context
);
575 bt_put(stream_event_context_field
);
576 bt_put(event_context
);
577 bt_put(event_context_field
);
578 bt_put(event_payload_type
);
579 bt_put(ep_integer_field_type
);
580 bt_put(ep_enum_field_type
);
581 bt_put(ep_enum_field_unsigned_type
);
586 void append_complex_event(struct bt_ctf_stream_class
*stream_class
,
587 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
589 struct event_class_attrs_counts
{
600 struct event_class_attrs_counts
;
601 const char *complex_test_event_string
= "Complex Test Event";
602 const char *test_string_1
= "Test ";
603 const char *test_string_2
= "string ";
604 const char *test_string_3
= "abcdefghi";
605 const char *test_string_4
= "abcd\0efg\0hi";
606 const char *test_string_cat
= "Test string abcdeabcd";
607 struct bt_ctf_field_type
*uint_35_type
=
608 bt_ctf_field_type_integer_create(35);
609 struct bt_ctf_field_type
*int_16_type
=
610 bt_ctf_field_type_integer_create(16);
611 struct bt_ctf_field_type
*uint_3_type
=
612 bt_ctf_field_type_integer_create(3);
613 struct bt_ctf_field_type
*enum_variant_type
=
614 bt_ctf_field_type_enumeration_create(uint_3_type
);
615 struct bt_ctf_field_type
*variant_type
=
616 bt_ctf_field_type_variant_create(enum_variant_type
,
618 struct bt_ctf_field_type
*string_type
=
619 bt_ctf_field_type_string_create();
620 struct bt_ctf_field_type
*sequence_type
;
621 struct bt_ctf_field_type
*array_type
;
622 struct bt_ctf_field_type
*inner_structure_type
=
623 bt_ctf_field_type_structure_create();
624 struct bt_ctf_field_type
*complex_structure_type
=
625 bt_ctf_field_type_structure_create();
626 struct bt_ctf_field_type
*ret_field_type
;
627 struct bt_ctf_event_class
*event_class
;
628 struct bt_ctf_event
*event
;
629 struct bt_ctf_field
*uint_35_field
, *int_16_field
, *a_string_field
,
630 *inner_structure_field
, *complex_structure_field
,
631 *a_sequence_field
, *enum_variant_field
, *enum_container_field
,
632 *variant_field
, *an_array_field
, *stream_event_ctx_field
,
633 *stream_event_ctx_int_field
, *ret_field
;
634 uint64_t ret_unsigned_int
;
635 int64_t ret_signed_int
;
636 const char *ret_string
;
637 struct bt_ctf_stream_class
*ret_stream_class
;
638 struct bt_ctf_event_class
*ret_event_class
;
639 struct bt_ctf_field
*packet_context
, *packet_context_field
;
640 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
641 struct bt_value
*obj
;
643 ok(bt_ctf_field_type_set_alignment(int_16_type
, 0),
644 "bt_ctf_field_type_set_alignment handles 0-alignment correctly");
645 ok(bt_ctf_field_type_set_alignment(int_16_type
, 3),
646 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (3)");
647 ok(bt_ctf_field_type_set_alignment(int_16_type
, 24),
648 "bt_ctf_field_type_set_alignment handles wrong alignment correctly (24)");
649 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 4),
650 "bt_ctf_field_type_set_alignment handles correct alignment correctly (4)");
651 ok(!bt_ctf_field_type_set_alignment(int_16_type
, 32),
652 "Set alignment of signed 16 bit integer to 32");
653 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
654 "Set integer signedness to true");
655 ok(!bt_ctf_field_type_integer_set_base(uint_35_type
,
656 BT_CTF_INTEGER_BASE_HEXADECIMAL
),
657 "Set signed 16 bit integer base to hexadecimal");
659 array_type
= bt_ctf_field_type_array_create(int_16_type
, ARRAY_TEST_LENGTH
);
660 sequence_type
= bt_ctf_field_type_sequence_create(int_16_type
,
663 ok(bt_ctf_field_type_array_get_element_type(NULL
) == NULL
,
664 "bt_ctf_field_type_array_get_element_type handles NULL correctly");
665 ret_field_type
= bt_ctf_field_type_array_get_element_type(
667 ok(ret_field_type
== int_16_type
,
668 "bt_ctf_field_type_array_get_element_type returns the correct type");
669 bt_put(ret_field_type
);
671 ok(bt_ctf_field_type_array_get_length(NULL
) < 0,
672 "bt_ctf_field_type_array_get_length handles NULL correctly");
673 ok(bt_ctf_field_type_array_get_length(array_type
) == ARRAY_TEST_LENGTH
,
674 "bt_ctf_field_type_array_get_length returns the correct length");
676 ok(bt_ctf_field_type_structure_add_field(inner_structure_type
,
677 inner_structure_type
, "yes"), "Cannot add self to structure");
678 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
679 uint_35_type
, "seq_len"), "Add seq_len field to inner structure");
680 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
681 sequence_type
, "a_sequence"), "Add a_sequence field to inner structure");
682 ok(!bt_ctf_field_type_structure_add_field(inner_structure_type
,
683 array_type
, "an_array"), "Add an_array field to inner structure");
685 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
687 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
689 bt_ctf_field_type_enumeration_add_mapping(enum_variant_type
,
690 "UINT35_TYPE", 2, 7);
692 iter
= bt_ctf_field_type_enumeration_find_mappings_by_name(NULL
, "INT16_TYPE");
693 ok(iter
== NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_name handles a NULL field type correctly");
695 iter
= bt_ctf_field_type_enumeration_find_mappings_by_name(enum_variant_type
, "INT16_TYPE");
696 ok(iter
!= NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_name handles an existing mapping correctly");
697 ok(bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(iter
, NULL
, NULL
, NULL
) == 0,
698 "bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned handles mapped values correctly");
701 iter
= bt_ctf_field_type_enumeration_find_mappings_by_name(enum_variant_type
, NULL
);
702 ok(iter
== NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_name handles a NULL name correctly");
704 iter
= bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(NULL
, 1);
705 ok(iter
== NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value handles a NULL field type correctly");
707 iter
= bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(enum_variant_type
, -42);
708 ok(iter
== NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value handles invalid values correctly");
709 ok(bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(iter
, NULL
, NULL
, NULL
) != 0,
710 "bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned handles invalid values correctly");
713 iter
= bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(enum_variant_type
, 5);
714 ok(iter
!= NULL
, "bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value handles valid values correctly");
715 ok(bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned(iter
, NULL
, NULL
, NULL
) == 0,
716 "bt_ctf_field_type_enumeration_mapping_iterator_get_unsigned handles valid values correctly");
719 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
720 "An unknown entry"), "Reject a variant field based on an unknown tag value");
721 ok(bt_ctf_field_type_variant_add_field(variant_type
, uint_3_type
,
722 "UINT3_TYPE") == 0, "Add a field to a variant");
723 ok(!bt_ctf_field_type_variant_add_field(variant_type
, int_16_type
,
724 "INT16_TYPE"), "Add INT16_TYPE field to variant");
725 ok(!bt_ctf_field_type_variant_add_field(variant_type
, uint_35_type
,
726 "UINT35_TYPE"), "Add UINT35_TYPE field to variant");
728 ok(bt_ctf_field_type_variant_get_tag_type(NULL
) == NULL
,
729 "bt_ctf_field_type_variant_get_tag_type handles NULL correctly");
730 ret_field_type
= bt_ctf_field_type_variant_get_tag_type(variant_type
);
731 ok(ret_field_type
== enum_variant_type
,
732 "bt_ctf_field_type_variant_get_tag_type returns a correct tag type");
733 bt_put(ret_field_type
);
735 ok(bt_ctf_field_type_variant_get_tag_name(NULL
) == NULL
,
736 "bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
737 ret_string
= bt_ctf_field_type_variant_get_tag_name(variant_type
);
738 ok(ret_string
? !strcmp(ret_string
, "variant_selector") : 0,
739 "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
740 ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL
,
741 "INT16_TYPE") == NULL
,
742 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly");
743 ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type
,
745 "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly");
746 ret_field_type
= bt_ctf_field_type_variant_get_field_type_by_name(
747 variant_type
, "INT16_TYPE");
748 ok(ret_field_type
== int_16_type
,
749 "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type");
750 bt_put(ret_field_type
);
752 ok(bt_ctf_field_type_variant_get_field_count(NULL
) < 0,
753 "bt_ctf_field_type_variant_get_field_count handles NULL correctly");
754 ok(bt_ctf_field_type_variant_get_field_count(variant_type
) == 3,
755 "bt_ctf_field_type_variant_get_field_count returns the correct count");
757 ok(bt_ctf_field_type_variant_get_field(NULL
, &ret_string
, &ret_field_type
, 0) < 0,
758 "bt_ctf_field_type_variant_get_field handles a NULL type correctly");
759 ok(bt_ctf_field_type_variant_get_field(variant_type
, NULL
, &ret_field_type
, 0) == 0,
760 "bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
761 bt_put(ret_field_type
);
762 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, NULL
, 0) == 0,
763 "bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
764 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 200) < 0,
765 "bt_ctf_field_type_variant_get_field handles an invalid index correctly");
766 ok(bt_ctf_field_type_variant_get_field(variant_type
, &ret_string
, &ret_field_type
, 1) == 0,
767 "bt_ctf_field_type_variant_get_field returns a field");
768 ok(!strcmp("INT16_TYPE", ret_string
),
769 "bt_ctf_field_type_variant_get_field returns a correct field name");
770 ok(ret_field_type
== int_16_type
,
771 "bt_ctf_field_type_variant_get_field returns a correct field type");
772 bt_put(ret_field_type
);
774 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
775 enum_variant_type
, "variant_selector"),
776 "Add variant_selector field to complex structure");
777 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
778 string_type
, "a_string"), "Add a_string field to complex structure");
779 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
780 variant_type
, "variant_value"),
781 "Add variant_value field to complex structure");
782 ok(!bt_ctf_field_type_structure_add_field(complex_structure_type
,
783 inner_structure_type
, "inner_structure"),
784 "Add inner_structure field to complex structure");
786 ok(bt_ctf_event_class_create("clock") == NULL
,
787 "Reject creation of an event class with an illegal name");
788 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
789 ok(event_class
, "Create an event class");
790 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
791 "Reject addition of a field with an empty name to an event");
792 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
793 "Reject addition of a field with a NULL type to an event");
794 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
796 "Reject addition of a type with an illegal name to an event");
797 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
799 "Add field of type unsigned integer to an event");
800 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
801 "int_16") == 0, "Add field of type signed integer to an event");
802 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
803 "complex_structure") == 0,
804 "Add composite structure to an event");
806 ok(bt_ctf_event_class_get_name(NULL
) == NULL
,
807 "bt_ctf_event_class_get_name handles NULL correctly");
808 ret_string
= bt_ctf_event_class_get_name(event_class
);
809 ok(!strcmp(ret_string
, complex_test_event_string
),
810 "bt_ctf_event_class_get_name returns a correct name");
811 ok(bt_ctf_event_class_get_id(event_class
) < 0,
812 "bt_ctf_event_class_get_id returns a negative value when not set");
813 ok(bt_ctf_event_class_get_id(NULL
) < 0,
814 "bt_ctf_event_class_get_id handles NULL correctly");
815 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
816 "bt_ctf_event_class_set_id handles NULL correctly");
817 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
818 "Set an event class' id");
819 ok(bt_ctf_event_class_get_id(event_class
) == 42,
820 "bt_ctf_event_class_get_id returns the correct value");
822 /* Test event class attributes */
823 obj
= bt_value_integer_create_init(15);
825 ok(bt_ctf_event_class_set_attribute(NULL
, "id", obj
),
826 "bt_ctf_event_class_set_attribute handles a NULL event class correctly");
827 ok(bt_ctf_event_class_set_attribute(event_class
, NULL
, obj
),
828 "bt_ctf_event_class_set_attribute handles a NULL name correctly");
829 ok(bt_ctf_event_class_set_attribute(event_class
, "id", NULL
),
830 "bt_ctf_event_class_set_attribute handles a NULL value correctly");
831 assert(!bt_value_integer_set(obj
, -3));
832 ok(bt_ctf_event_class_set_attribute(event_class
, "id", obj
),
833 "bt_ctf_event_class_set_attribute fails with a negative \"id\" attribute");
834 assert(!bt_value_integer_set(obj
, 11));
835 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
836 ok(!ret
&& bt_ctf_event_class_get_id(event_class
) == 11,
837 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"id\" attribute");
838 ret
= bt_ctf_event_class_set_attribute(event_class
, "name", obj
);
839 ret
&= bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
);
841 "bt_ctf_event_class_set_attribute cannot set \"name\" or \"model.emf.uri\" to an integer value");
844 obj
= bt_value_integer_create_init(5);
846 ok(!bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
),
847 "bt_ctf_event_class_set_attribute succeeds in setting the \"loglevel\" attribute");
849 ok(!bt_ctf_event_class_get_attribute_value_by_name(NULL
, "loglevel"),
850 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL event class correctly");
851 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, NULL
),
852 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL name correctly");
853 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, "meow"),
854 "bt_ctf_event_class_get_attribute_value_by_name fails with a non-existing attribute name");
855 obj
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
858 ret
= bt_value_integer_get(obj
, &int64_value
);
859 ok(obj
&& !ret
&& int64_value
== 5,
860 "bt_ctf_event_class_get_attribute_value_by_name returns the correct value");
863 obj
= bt_value_string_create_init("nu name");
865 assert(!bt_ctf_event_class_set_attribute(event_class
, "name", obj
));
866 ret_string
= bt_ctf_event_class_get_name(event_class
);
867 ok(!strcmp(ret_string
, "nu name"),
868 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"name\" attribute");
869 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
870 ret
&= bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
);
872 "bt_ctf_event_class_set_attribute cannot set \"id\" or \"loglevel\" to a string value");
874 obj
= bt_value_string_create_init("http://kernel.org/");
876 assert(!bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
));
879 ok(bt_ctf_event_class_get_attribute_count(NULL
),
880 "bt_ctf_event_class_get_attribute_count handles a NULL event class");
881 ok(bt_ctf_event_class_get_attribute_count(event_class
) == 4,
882 "bt_ctf_event_class_get_attribute_count returns the correct count");
883 ok(!bt_ctf_event_class_get_attribute_name_by_index(NULL
, 0),
884 "bt_ctf_event_class_get_attribute_name handles a NULL event class correctly");
885 ok(!bt_ctf_event_class_get_attribute_name_by_index(event_class
, 4),
886 "bt_ctf_event_class_get_attribute_name handles a too large index correctly");
887 ok(!bt_ctf_event_class_get_attribute_value_by_index(NULL
, 0),
888 "bt_ctf_event_class_get_attribute_value handles a NULL event class correctly");
889 ok(!bt_ctf_event_class_get_attribute_value_by_index(event_class
, 4),
890 "bt_ctf_event_class_get_attribute_value handles a too large index correctly");
892 memset(&attrs_count
, 0, sizeof(attrs_count
));
894 for (i
= 0; i
< 4; ++i
) {
895 ret_string
= bt_ctf_event_class_get_attribute_name_by_index(
897 obj
= bt_ctf_event_class_get_attribute_value_by_index(
899 assert(ret_string
&& obj
);
901 if (!strcmp(ret_string
, "id")) {
903 ok(bt_value_is_integer(obj
),
904 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
906 } else if (!strcmp(ret_string
, "name")) {
908 ok(bt_value_is_string(obj
),
909 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
911 } else if (!strcmp(ret_string
, "loglevel")) {
912 attrs_count
.loglevel
++;
913 ok(bt_value_is_integer(obj
),
914 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
916 } else if (!strcmp(ret_string
, "model.emf.uri")) {
917 attrs_count
.modelemfuri
++;
918 ok(bt_value_is_string(obj
),
919 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
922 attrs_count
.unknown
++;
928 ok(attrs_count
.unknown
== 0, "event class has no unknown attributes");
929 ok(attrs_count
.id
== 1 && attrs_count
.name
== 1 &&
930 attrs_count
.loglevel
== 1 && attrs_count
.modelemfuri
== 1,
931 "event class has one instance of each known attribute");
933 /* Add event class to the stream class */
934 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
935 "Reject addition of NULL event class to a stream class");
936 ok(bt_ctf_stream_class_add_event_class(stream_class
,
937 event_class
) == 0, "Add an event class to stream class");
939 ok(bt_ctf_event_class_get_stream_class(NULL
) == NULL
,
940 "bt_ctf_event_class_get_stream_class handles NULL correctly");
941 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
942 ok(ret_stream_class
== stream_class
,
943 "bt_ctf_event_class_get_stream_class returns the correct stream class");
944 bt_put(ret_stream_class
);
946 ok(bt_ctf_event_class_get_payload_type_field_count(NULL
) < 0,
947 "bt_ctf_event_class_get_field_count handles NULL correctly");
948 ok(bt_ctf_event_class_get_payload_type_field_count(event_class
) == 3,
949 "bt_ctf_event_class_get_field_count returns a correct value");
951 ok(bt_ctf_event_class_get_payload_type_field_by_index(NULL
, &ret_string
,
952 &ret_field_type
, 0) < 0,
953 "bt_ctf_event_class_get_field handles a NULL event class correctly");
954 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, NULL
,
955 &ret_field_type
, 0) == 0,
956 "bt_ctf_event_class_get_field handles a NULL field name correctly");
957 bt_put(ret_field_type
);
958 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, &ret_string
,
960 "bt_ctf_event_class_get_field handles a NULL field type correctly");
961 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, &ret_string
,
962 &ret_field_type
, 42) < 0,
963 "bt_ctf_event_class_get_field handles an invalid index correctly");
964 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, &ret_string
,
965 &ret_field_type
, 0) == 0,
966 "bt_ctf_event_class_get_field returns a field");
967 ok(bt_ctf_field_type_compare(ret_field_type
, uint_35_type
) == 0,
968 "bt_ctf_event_class_get_field returns a correct field type");
969 bt_put(ret_field_type
);
970 ok(!strcmp(ret_string
, "uint_35"),
971 "bt_ctf_event_class_get_field returns a correct field name");
972 ok(bt_ctf_event_class_get_field_by_name(NULL
, "") == NULL
,
973 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
974 ok(bt_ctf_event_class_get_field_by_name(event_class
, NULL
) == NULL
,
975 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
976 ok(bt_ctf_event_class_get_field_by_name(event_class
, "truie") == NULL
,
977 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
978 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
979 "complex_structure");
980 ok(bt_ctf_field_type_compare(ret_field_type
, complex_structure_type
) == 0,
981 "bt_ctf_event_class_get_field_by_name returns a correct field type");
982 bt_put(ret_field_type
);
984 event
= bt_ctf_event_create(event_class
);
985 ok(event
, "Instanciate a complex event");
987 ok(bt_ctf_event_get_class(NULL
) == NULL
,
988 "bt_ctf_event_get_class handles NULL correctly");
989 ret_event_class
= bt_ctf_event_get_class(event
);
990 ok(ret_event_class
== event_class
,
991 "bt_ctf_event_get_class returns the correct event class");
992 bt_put(ret_event_class
);
994 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
995 if (!uint_35_field
) {
996 printf("uint_35_field is NULL\n");
999 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
1000 bt_ctf_field_unsigned_integer_set_value(uint_35_field
, 0x0DDF00D);
1001 ok(bt_ctf_field_unsigned_integer_get_value(NULL
, &ret_unsigned_int
) < 0,
1002 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
1003 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
, NULL
) < 0,
1004 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
1005 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
,
1006 &ret_unsigned_int
) == 0,
1007 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
1008 ok(ret_unsigned_int
== 0x0DDF00D,
1009 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
1010 ok(bt_ctf_field_signed_integer_get_value(uint_35_field
,
1011 &ret_signed_int
) < 0,
1012 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
1013 bt_put(uint_35_field
);
1015 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
1016 bt_ctf_field_signed_integer_set_value(int_16_field
, -12345);
1017 ok(bt_ctf_field_signed_integer_get_value(NULL
, &ret_signed_int
) < 0,
1018 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
1019 ok(bt_ctf_field_signed_integer_get_value(int_16_field
, NULL
) < 0,
1020 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
1021 ok(bt_ctf_field_signed_integer_get_value(int_16_field
,
1022 &ret_signed_int
) == 0,
1023 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
1024 ok(ret_signed_int
== -12345,
1025 "bt_ctf_field_signed_integer_get_value returns the correct value");
1026 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field
,
1027 &ret_unsigned_int
) < 0,
1028 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
1029 bt_put(int_16_field
);
1031 complex_structure_field
= bt_ctf_event_get_payload(event
,
1032 "complex_structure");
1034 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 0) == NULL
,
1035 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
1036 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 9) == NULL
,
1037 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
1038 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
1039 complex_structure_field
, 3);
1040 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
1041 bt_put(inner_structure_field
);
1042 ok(bt_ctf_field_type_compare(ret_field_type
, inner_structure_type
) == 0,
1043 "bt_ctf_field_structure_get_field_by_index returns a correct field");
1044 bt_put(ret_field_type
);
1046 inner_structure_field
= bt_ctf_field_structure_get_field(
1047 complex_structure_field
, "inner_structure");
1048 a_string_field
= bt_ctf_field_structure_get_field(
1049 complex_structure_field
, "a_string");
1050 enum_variant_field
= bt_ctf_field_structure_get_field(
1051 complex_structure_field
, "variant_selector");
1052 variant_field
= bt_ctf_field_structure_get_field(
1053 complex_structure_field
, "variant_value");
1054 uint_35_field
= bt_ctf_field_structure_get_field(
1055 inner_structure_field
, "seq_len");
1056 a_sequence_field
= bt_ctf_field_structure_get_field(
1057 inner_structure_field
, "a_sequence");
1058 an_array_field
= bt_ctf_field_structure_get_field(
1059 inner_structure_field
, "an_array");
1061 enum_container_field
= bt_ctf_field_enumeration_get_container(
1062 enum_variant_field
);
1063 bt_ctf_field_unsigned_integer_set_value(enum_container_field
, 1);
1064 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
1065 enum_variant_field
);
1066 bt_ctf_field_signed_integer_set_value(int_16_field
, -200);
1067 bt_put(int_16_field
);
1068 ok(!bt_ctf_field_string_get_value(a_string_field
),
1069 "bt_ctf_field_string_get_value returns NULL on an unset field");
1070 bt_ctf_field_string_set_value(a_string_field
,
1072 ok(!bt_ctf_field_string_get_value(NULL
),
1073 "bt_ctf_field_string_get_value correctly handles NULL");
1074 ok(bt_ctf_field_string_append(NULL
, "yeah"),
1075 "bt_ctf_field_string_append correctly handles a NULL string field");
1076 ok(bt_ctf_field_string_append(a_string_field
, NULL
),
1077 "bt_ctf_field_string_append correctly handles a NULL string value");
1078 ok(!bt_ctf_field_string_append(a_string_field
, test_string_2
),
1079 "bt_ctf_field_string_append succeeds");
1080 ok(bt_ctf_field_string_append_len(NULL
, "oh noes", 3),
1081 "bt_ctf_field_string_append_len correctly handles a NULL string field");
1082 ok(bt_ctf_field_string_append_len(a_string_field
, NULL
, 3),
1083 "bt_ctf_field_string_append_len correctly handles a NULL string value");
1084 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 5),
1085 "bt_ctf_field_string_append_len succeeds (append 5 characters)");
1086 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_4
, 10),
1087 "bt_ctf_field_string_append_len succeeds (append 4 characters)");
1088 ok(!bt_ctf_field_string_append_len(a_string_field
, &test_string_4
[4], 3),
1089 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
1090 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 0),
1091 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
1093 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
1094 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
1095 ok(ret_string
? !strcmp(ret_string
, test_string_cat
) : 0,
1096 "bt_ctf_field_string_get_value returns a correct value");
1097 bt_ctf_field_unsigned_integer_set_value(uint_35_field
,
1098 SEQUENCE_TEST_LENGTH
);
1100 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL
,
1101 enum_container_field
) == NULL
,
1102 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
1103 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type
,
1105 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
1106 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
1107 variant_type
, enum_variant_field
);
1108 ok(ret_field_type
== int_16_type
,
1109 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
1111 ok(bt_ctf_field_sequence_get_length(a_sequence_field
) == NULL
,
1112 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
1113 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
1114 uint_35_field
) == 0, "Set a sequence field's length");
1115 ret_field
= bt_ctf_field_sequence_get_length(a_sequence_field
);
1116 ok(ret_field
== uint_35_field
,
1117 "bt_ctf_field_sequence_get_length returns the correct length field");
1118 ok(bt_ctf_field_sequence_get_length(NULL
) == NULL
,
1119 "bt_ctf_field_sequence_get_length properly handles NULL");
1121 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
1122 int_16_field
= bt_ctf_field_sequence_get_field(
1123 a_sequence_field
, i
);
1124 bt_ctf_field_signed_integer_set_value(int_16_field
, 4 - i
);
1125 bt_put(int_16_field
);
1128 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
1129 int_16_field
= bt_ctf_field_array_get_field(
1131 bt_ctf_field_signed_integer_set_value(int_16_field
, i
);
1132 bt_put(int_16_field
);
1135 stream_event_ctx_field
= bt_ctf_event_get_stream_event_context(event
);
1136 assert(stream_event_ctx_field
);
1137 stream_event_ctx_int_field
= bt_ctf_field_structure_get_field(
1138 stream_event_ctx_field
, "common_event_context");
1139 BT_PUT(stream_event_ctx_field
);
1140 bt_ctf_field_unsigned_integer_set_value(stream_event_ctx_int_field
, 17);
1141 BT_PUT(stream_event_ctx_int_field
);
1143 bt_ctf_clock_set_time(clock
, ++current_time
);
1144 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
1145 "Append a complex event to a stream");
1148 * Populate the custom packet context field with a dummy value
1149 * otherwise flush will fail.
1151 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1152 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1153 "custom_packet_context_field");
1154 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 1);
1156 ok(bt_ctf_stream_flush(stream
) == 0,
1157 "Flush a stream containing a complex event");
1159 bt_put(uint_35_field
);
1160 bt_put(a_string_field
);
1161 bt_put(inner_structure_field
);
1162 bt_put(complex_structure_field
);
1163 bt_put(a_sequence_field
);
1164 bt_put(an_array_field
);
1165 bt_put(enum_variant_field
);
1166 bt_put(enum_container_field
);
1167 bt_put(variant_field
);
1169 bt_put(packet_context_field
);
1170 bt_put(packet_context
);
1171 bt_put(uint_35_type
);
1172 bt_put(int_16_type
);
1173 bt_put(string_type
);
1174 bt_put(sequence_type
);
1176 bt_put(inner_structure_type
);
1177 bt_put(complex_structure_type
);
1178 bt_put(uint_3_type
);
1179 bt_put(enum_variant_type
);
1180 bt_put(variant_type
);
1181 bt_put(ret_field_type
);
1182 bt_put(event_class
);
1187 void field_copy_tests_validate_same_type(struct bt_ctf_field
*field
,
1188 struct bt_ctf_field_type
*expected_type
, const char *name
)
1190 struct bt_ctf_field_type
*copy_type
;
1192 copy_type
= bt_ctf_field_get_type(field
);
1193 ok(copy_type
== expected_type
,
1194 "bt_ctf_field_copy does not copy the type (%s)", name
);
1199 void field_copy_tests_validate_diff_ptrs(struct bt_ctf_field
*field_a
,
1200 struct bt_ctf_field
*field_b
, const char *name
)
1202 ok(field_a
!= field_b
,
1203 "bt_ctf_field_copy creates different pointers (%s)", name
);
1207 void field_copy_tests()
1209 struct bt_ctf_field_type
*len_type
= NULL
;
1210 struct bt_ctf_field_type
*fp_type
= NULL
;
1211 struct bt_ctf_field_type
*s_type
= NULL
;
1212 struct bt_ctf_field_type
*e_int_type
= NULL
;
1213 struct bt_ctf_field_type
*e_type
= NULL
;
1214 struct bt_ctf_field_type
*v_type
= NULL
;
1215 struct bt_ctf_field_type
*v_label1_type
= NULL
;
1216 struct bt_ctf_field_type
*v_label1_array_type
= NULL
;
1217 struct bt_ctf_field_type
*v_label2_type
= NULL
;
1218 struct bt_ctf_field_type
*v_label2_seq_type
= NULL
;
1219 struct bt_ctf_field_type
*strct_type
= NULL
;
1220 struct bt_ctf_field
*len
= NULL
;
1221 struct bt_ctf_field
*fp
= NULL
;
1222 struct bt_ctf_field
*s
= NULL
;
1223 struct bt_ctf_field
*e_int
= NULL
;
1224 struct bt_ctf_field
*e
= NULL
;
1225 struct bt_ctf_field
*v
= NULL
;
1226 struct bt_ctf_field
*v_selected
= NULL
;
1227 struct bt_ctf_field
*v_selected_cur
= NULL
;
1228 struct bt_ctf_field
*v_selected_0
= NULL
;
1229 struct bt_ctf_field
*v_selected_1
= NULL
;
1230 struct bt_ctf_field
*v_selected_2
= NULL
;
1231 struct bt_ctf_field
*v_selected_3
= NULL
;
1232 struct bt_ctf_field
*v_selected_4
= NULL
;
1233 struct bt_ctf_field
*v_selected_5
= NULL
;
1234 struct bt_ctf_field
*v_selected_6
= NULL
;
1235 struct bt_ctf_field
*a
= NULL
;
1236 struct bt_ctf_field
*a_0
= NULL
;
1237 struct bt_ctf_field
*a_1
= NULL
;
1238 struct bt_ctf_field
*a_2
= NULL
;
1239 struct bt_ctf_field
*a_3
= NULL
;
1240 struct bt_ctf_field
*a_4
= NULL
;
1241 struct bt_ctf_field
*strct
= NULL
;
1242 struct bt_ctf_field
*len_copy
= NULL
;
1243 struct bt_ctf_field
*fp_copy
= NULL
;
1244 struct bt_ctf_field
*s_copy
= NULL
;
1245 struct bt_ctf_field
*e_int_copy
= NULL
;
1246 struct bt_ctf_field
*e_copy
= NULL
;
1247 struct bt_ctf_field
*v_copy
= NULL
;
1248 struct bt_ctf_field
*v_selected_copy
= NULL
;
1249 struct bt_ctf_field
*v_selected_copy_len
= NULL
;
1250 struct bt_ctf_field
*v_selected_0_copy
= NULL
;
1251 struct bt_ctf_field
*v_selected_1_copy
= NULL
;
1252 struct bt_ctf_field
*v_selected_2_copy
= NULL
;
1253 struct bt_ctf_field
*v_selected_3_copy
= NULL
;
1254 struct bt_ctf_field
*v_selected_4_copy
= NULL
;
1255 struct bt_ctf_field
*v_selected_5_copy
= NULL
;
1256 struct bt_ctf_field
*v_selected_6_copy
= NULL
;
1257 struct bt_ctf_field
*a_copy
= NULL
;
1258 struct bt_ctf_field
*a_0_copy
= NULL
;
1259 struct bt_ctf_field
*a_1_copy
= NULL
;
1260 struct bt_ctf_field
*a_2_copy
= NULL
;
1261 struct bt_ctf_field
*a_3_copy
= NULL
;
1262 struct bt_ctf_field
*a_4_copy
= NULL
;
1263 struct bt_ctf_field
*strct_copy
= NULL
;
1264 struct bt_ctf_field_type_enumeration_mapping_iterator
*e_iter
= NULL
;
1265 uint64_t uint64_t_val
;
1266 const char *str_val
;
1270 /* create len type */
1271 len_type
= bt_ctf_field_type_integer_create(32);
1274 /* create fp type */
1275 fp_type
= bt_ctf_field_type_floating_point_create();
1279 s_type
= bt_ctf_field_type_string_create();
1282 /* create e_int type */
1283 e_int_type
= bt_ctf_field_type_integer_create(8);
1287 e_type
= bt_ctf_field_type_enumeration_create(e_int_type
);
1289 ret
= bt_ctf_field_type_enumeration_add_mapping(e_type
, "LABEL1",
1292 ret
= bt_ctf_field_type_enumeration_add_mapping(e_type
, "LABEL2",
1296 /* create v_label1 type */
1297 v_label1_type
= bt_ctf_field_type_string_create();
1298 assert(v_label1_type
);
1300 /* create v_label1_array type */
1301 v_label1_array_type
= bt_ctf_field_type_array_create(v_label1_type
, 5);
1302 assert(v_label1_array_type
);
1304 /* create v_label2 type */
1305 v_label2_type
= bt_ctf_field_type_integer_create(16);
1306 assert(v_label2_type
);
1308 /* create v_label2_seq type */
1309 v_label2_seq_type
= bt_ctf_field_type_sequence_create(v_label2_type
,
1311 assert(v_label2_seq_type
);
1314 v_type
= bt_ctf_field_type_variant_create(e_type
, "e");
1316 ret
= bt_ctf_field_type_variant_add_field(v_type
, v_label1_array_type
,
1319 ret
= bt_ctf_field_type_variant_add_field(v_type
, v_label2_seq_type
,
1323 /* create strct type */
1324 strct_type
= bt_ctf_field_type_structure_create();
1326 ret
= bt_ctf_field_type_structure_add_field(strct_type
, len_type
,
1329 ret
= bt_ctf_field_type_structure_add_field(strct_type
, fp_type
, "fp");
1331 ret
= bt_ctf_field_type_structure_add_field(strct_type
, s_type
, "s");
1333 ret
= bt_ctf_field_type_structure_add_field(strct_type
, e_type
, "e");
1335 ret
= bt_ctf_field_type_structure_add_field(strct_type
, v_type
, "v");
1337 ret
= bt_ctf_field_type_structure_add_field(strct_type
,
1338 v_label1_array_type
, "a");
1342 strct
= bt_ctf_field_create(strct_type
);
1346 len
= bt_ctf_field_structure_get_field(strct
, "len");
1350 fp
= bt_ctf_field_structure_get_field(strct
, "fp");
1354 s
= bt_ctf_field_structure_get_field(strct
, "s");
1358 e
= bt_ctf_field_structure_get_field(strct
, "e");
1361 /* get e_int (underlying integer) */
1362 e_int
= bt_ctf_field_enumeration_get_container(e
);
1366 v
= bt_ctf_field_structure_get_field(strct
, "v");
1370 a
= bt_ctf_field_structure_get_field(strct
, "a");
1374 ret
= bt_ctf_field_unsigned_integer_set_value(len
, 7);
1378 ret
= bt_ctf_field_floating_point_set_value(fp
, 3.14);
1382 ret
= bt_ctf_field_string_set_value(s
, "btbt");
1385 /* set e field (LABEL2) */
1386 ret
= bt_ctf_field_unsigned_integer_set_value(e_int
, 23);
1390 v_selected
= bt_ctf_field_variant_get_field(v
, e
);
1392 ok(!bt_ctf_field_variant_get_current_field(NULL
),
1393 "bt_ctf_field_variant_get_current_field handles NULL correctly");
1394 v_selected_cur
= bt_ctf_field_variant_get_current_field(v
);
1395 ok(v_selected_cur
== v_selected
,
1396 "bt_ctf_field_variant_get_current_field returns the current field");
1397 bt_put(v_selected_cur
);
1399 /* set selected v field */
1400 ret
= bt_ctf_field_sequence_set_length(v_selected
, len
);
1402 v_selected_0
= bt_ctf_field_sequence_get_field(v_selected
, 0);
1403 assert(v_selected_0
);
1404 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_0
, 7);
1406 v_selected_1
= bt_ctf_field_sequence_get_field(v_selected
, 1);
1407 assert(v_selected_1
);
1408 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_1
, 6);
1410 v_selected_2
= bt_ctf_field_sequence_get_field(v_selected
, 2);
1411 assert(v_selected_2
);
1412 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_2
, 5);
1414 v_selected_3
= bt_ctf_field_sequence_get_field(v_selected
, 3);
1415 assert(v_selected_3
);
1416 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_3
, 4);
1418 v_selected_4
= bt_ctf_field_sequence_get_field(v_selected
, 4);
1419 assert(v_selected_4
);
1420 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_4
, 3);
1422 v_selected_5
= bt_ctf_field_sequence_get_field(v_selected
, 5);
1423 assert(v_selected_5
);
1424 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_5
, 2);
1426 v_selected_6
= bt_ctf_field_sequence_get_field(v_selected
, 6);
1427 assert(v_selected_6
);
1428 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_6
, 1);
1432 a_0
= bt_ctf_field_array_get_field(a
, 0);
1434 ret
= bt_ctf_field_string_set_value(a_0
, "a_0");
1436 a_1
= bt_ctf_field_array_get_field(a
, 1);
1438 ret
= bt_ctf_field_string_set_value(a_1
, "a_1");
1440 a_2
= bt_ctf_field_array_get_field(a
, 2);
1442 ret
= bt_ctf_field_string_set_value(a_2
, "a_2");
1444 a_3
= bt_ctf_field_array_get_field(a
, 3);
1446 ret
= bt_ctf_field_string_set_value(a_3
, "a_3");
1448 a_4
= bt_ctf_field_array_get_field(a
, 4);
1450 ret
= bt_ctf_field_string_set_value(a_4
, "a_4");
1453 /* create copy of strct */
1454 ok(!bt_ctf_field_copy(NULL
),
1455 "bt_ctf_field_copy handles NULL correctly");
1456 strct_copy
= bt_ctf_field_copy(strct
);
1458 "bt_ctf_field_copy returns a valid pointer");
1460 /* get all copied fields */
1461 len_copy
= bt_ctf_field_structure_get_field(strct_copy
, "len");
1463 fp_copy
= bt_ctf_field_structure_get_field(strct_copy
, "fp");
1465 s_copy
= bt_ctf_field_structure_get_field(strct_copy
, "s");
1467 e_copy
= bt_ctf_field_structure_get_field(strct_copy
, "e");
1469 e_int_copy
= bt_ctf_field_enumeration_get_container(e_copy
);
1471 v_copy
= bt_ctf_field_structure_get_field(strct_copy
, "v");
1473 v_selected_copy
= bt_ctf_field_variant_get_field(v_copy
, e_copy
);
1474 assert(v_selected_copy
);
1475 v_selected_0_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 0);
1476 assert(v_selected_0_copy
);
1477 v_selected_1_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 1);
1478 assert(v_selected_1_copy
);
1479 v_selected_2_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 2);
1480 assert(v_selected_2_copy
);
1481 v_selected_3_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 3);
1482 assert(v_selected_3_copy
);
1483 v_selected_4_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 4);
1484 assert(v_selected_4_copy
);
1485 v_selected_5_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 5);
1486 assert(v_selected_5_copy
);
1487 v_selected_6_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 6);
1488 assert(v_selected_6_copy
);
1489 ok(!bt_ctf_field_sequence_get_field(v_selected_copy
, 7),
1490 "sequence field copy is not too large");
1491 a_copy
= bt_ctf_field_structure_get_field(strct_copy
, "a");
1493 a_0_copy
= bt_ctf_field_array_get_field(a_copy
, 0);
1495 a_1_copy
= bt_ctf_field_array_get_field(a_copy
, 1);
1497 a_2_copy
= bt_ctf_field_array_get_field(a_copy
, 2);
1499 a_3_copy
= bt_ctf_field_array_get_field(a_copy
, 3);
1501 a_4_copy
= bt_ctf_field_array_get_field(a_copy
, 4);
1503 ok(!bt_ctf_field_array_get_field(v_selected_copy
, 5),
1504 "array field copy is not too large");
1506 /* make sure copied fields are different pointers */
1507 field_copy_tests_validate_diff_ptrs(strct_copy
, strct
, "strct");
1508 field_copy_tests_validate_diff_ptrs(len_copy
, len
, "len");
1509 field_copy_tests_validate_diff_ptrs(fp_copy
, fp
, "fp");
1510 field_copy_tests_validate_diff_ptrs(s_copy
, s
, "s");
1511 field_copy_tests_validate_diff_ptrs(e_int_copy
, e_int
, "e_int");
1512 field_copy_tests_validate_diff_ptrs(e_copy
, e
, "e");
1513 field_copy_tests_validate_diff_ptrs(v_copy
, v
, "v");
1514 field_copy_tests_validate_diff_ptrs(v_selected_copy
, v_selected
,
1516 field_copy_tests_validate_diff_ptrs(v_selected_0_copy
, v_selected_0
,
1518 field_copy_tests_validate_diff_ptrs(v_selected_1_copy
, v_selected_1
,
1520 field_copy_tests_validate_diff_ptrs(v_selected_2_copy
, v_selected_2
,
1522 field_copy_tests_validate_diff_ptrs(v_selected_3_copy
, v_selected_3
,
1524 field_copy_tests_validate_diff_ptrs(v_selected_4_copy
, v_selected_4
,
1526 field_copy_tests_validate_diff_ptrs(v_selected_5_copy
, v_selected_5
,
1528 field_copy_tests_validate_diff_ptrs(v_selected_6_copy
, v_selected_6
,
1530 field_copy_tests_validate_diff_ptrs(a_copy
, a
, "a");
1531 field_copy_tests_validate_diff_ptrs(a_0_copy
, a_0
, "a_0");
1532 field_copy_tests_validate_diff_ptrs(a_1_copy
, a_1
, "a_1");
1533 field_copy_tests_validate_diff_ptrs(a_2_copy
, a_2
, "a_2");
1534 field_copy_tests_validate_diff_ptrs(a_3_copy
, a_3
, "a_3");
1535 field_copy_tests_validate_diff_ptrs(a_4_copy
, a_4
, "a_4");
1537 /* make sure copied fields share the same types */
1538 field_copy_tests_validate_same_type(strct_copy
, strct_type
, "strct");
1539 field_copy_tests_validate_same_type(len_copy
, len_type
, "len");
1540 field_copy_tests_validate_same_type(fp_copy
, fp_type
, "fp");
1541 field_copy_tests_validate_same_type(e_int_copy
, e_int_type
, "e_int");
1542 field_copy_tests_validate_same_type(e_copy
, e_type
, "e");
1543 field_copy_tests_validate_same_type(v_copy
, v_type
, "v");
1544 field_copy_tests_validate_same_type(v_selected_copy
, v_label2_seq_type
,
1546 field_copy_tests_validate_same_type(v_selected_0_copy
, v_label2_type
,
1548 field_copy_tests_validate_same_type(v_selected_1_copy
, v_label2_type
,
1550 field_copy_tests_validate_same_type(v_selected_2_copy
, v_label2_type
,
1552 field_copy_tests_validate_same_type(v_selected_3_copy
, v_label2_type
,
1554 field_copy_tests_validate_same_type(v_selected_4_copy
, v_label2_type
,
1556 field_copy_tests_validate_same_type(v_selected_5_copy
, v_label2_type
,
1558 field_copy_tests_validate_same_type(v_selected_6_copy
, v_label2_type
,
1560 field_copy_tests_validate_same_type(a_copy
, v_label1_array_type
, "a");
1561 field_copy_tests_validate_same_type(a_0_copy
, v_label1_type
, "a_0");
1562 field_copy_tests_validate_same_type(a_1_copy
, v_label1_type
, "a_1");
1563 field_copy_tests_validate_same_type(a_2_copy
, v_label1_type
, "a_2");
1564 field_copy_tests_validate_same_type(a_3_copy
, v_label1_type
, "a_3");
1565 field_copy_tests_validate_same_type(a_4_copy
, v_label1_type
, "a_4");
1567 /* validate len copy */
1568 ret
= bt_ctf_field_unsigned_integer_get_value(len_copy
, &uint64_t_val
);
1570 ok(uint64_t_val
== 7,
1571 "bt_ctf_field_copy creates a valid integer field copy");
1573 /* validate fp copy */
1574 ret
= bt_ctf_field_floating_point_get_value(fp_copy
, &double_val
);
1576 ok(double_val
== 3.14,
1577 "bt_ctf_field_copy creates a valid floating point number field copy");
1579 /* validate s copy */
1580 str_val
= bt_ctf_field_string_get_value(s_copy
);
1581 ok(str_val
&& !strcmp(str_val
, "btbt"),
1582 "bt_ctf_field_copy creates a valid string field copy");
1584 /* validate e_int copy */
1585 ret
= bt_ctf_field_unsigned_integer_get_value(e_int_copy
,
1588 ok(uint64_t_val
== 23,
1589 "bt_ctf_field_copy creates a valid enum's integer field copy");
1591 /* validate e copy */
1592 e_iter
= bt_ctf_field_enumeration_get_mappings(e_copy
);
1593 (void) bt_ctf_field_type_enumeration_mapping_iterator_get_signed(e_iter
,
1594 &str_val
, NULL
, NULL
);
1595 ok(str_val
&& !strcmp(str_val
, "LABEL2"),
1596 "bt_ctf_field_copy creates a valid enum field copy");
1598 /* validate v_selected copy */
1599 v_selected_copy_len
= bt_ctf_field_sequence_get_length(v_selected
);
1600 assert(v_selected_copy_len
);
1601 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_copy_len
,
1604 ok(uint64_t_val
== 7,
1605 "bt_ctf_field_copy creates a sequence field copy with the proper length");
1606 bt_put(v_selected_copy_len
);
1607 v_selected_copy_len
= NULL
;
1609 /* validate v_selected copy fields */
1610 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_0_copy
,
1613 ok(uint64_t_val
== 7,
1614 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_0)");
1615 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_1_copy
,
1618 ok(uint64_t_val
== 6,
1619 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_1)");
1620 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_2_copy
,
1623 ok(uint64_t_val
== 5,
1624 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_2)");
1625 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_3_copy
,
1628 ok(uint64_t_val
== 4,
1629 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_3)");
1630 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_4_copy
,
1633 ok(uint64_t_val
== 3,
1634 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_4)");
1635 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_5_copy
,
1638 ok(uint64_t_val
== 2,
1639 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_5)");
1640 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_6_copy
,
1643 ok(uint64_t_val
== 1,
1644 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_6)");
1646 /* validate a copy fields */
1647 str_val
= bt_ctf_field_string_get_value(a_0_copy
);
1648 ok(str_val
&& !strcmp(str_val
, "a_0"),
1649 "bt_ctf_field_copy creates a valid array field element copy (a_0)");
1650 str_val
= bt_ctf_field_string_get_value(a_1_copy
);
1651 ok(str_val
&& !strcmp(str_val
, "a_1"),
1652 "bt_ctf_field_copy creates a valid array field element copy (a_1)");
1653 str_val
= bt_ctf_field_string_get_value(a_2_copy
);
1654 ok(str_val
&& !strcmp(str_val
, "a_2"),
1655 "bt_ctf_field_copy creates a valid array field element copy (a_2)");
1656 str_val
= bt_ctf_field_string_get_value(a_3_copy
);
1657 ok(str_val
&& !strcmp(str_val
, "a_3"),
1658 "bt_ctf_field_copy creates a valid array field element copy (a_3)");
1659 str_val
= bt_ctf_field_string_get_value(a_4_copy
);
1660 ok(str_val
&& !strcmp(str_val
, "a_4"),
1661 "bt_ctf_field_copy creates a valid array field element copy (a_4)");
1663 /* put everything */
1670 bt_put(v_label1_type
);
1671 bt_put(v_label1_array_type
);
1672 bt_put(v_label2_type
);
1673 bt_put(v_label2_seq_type
);
1682 bt_put(v_selected_0
);
1683 bt_put(v_selected_1
);
1684 bt_put(v_selected_2
);
1685 bt_put(v_selected_3
);
1686 bt_put(v_selected_4
);
1687 bt_put(v_selected_5
);
1688 bt_put(v_selected_6
);
1702 bt_put(v_selected_copy
);
1703 bt_put(v_selected_0_copy
);
1704 bt_put(v_selected_1_copy
);
1705 bt_put(v_selected_2_copy
);
1706 bt_put(v_selected_3_copy
);
1707 bt_put(v_selected_4_copy
);
1708 bt_put(v_selected_5_copy
);
1709 bt_put(v_selected_6_copy
);
1721 void type_field_tests()
1723 struct bt_ctf_field
*uint_12
;
1724 struct bt_ctf_field
*int_16
;
1725 struct bt_ctf_field
*string
;
1726 struct bt_ctf_field
*enumeration
;
1727 struct bt_ctf_field_type
*composite_structure_type
;
1728 struct bt_ctf_field_type
*structure_seq_type
;
1729 struct bt_ctf_field_type
*string_type
;
1730 struct bt_ctf_field_type
*sequence_type
;
1731 struct bt_ctf_field_type
*uint_8_type
;
1732 struct bt_ctf_field_type
*int_16_type
;
1733 struct bt_ctf_field_type
*uint_12_type
=
1734 bt_ctf_field_type_integer_create(12);
1735 struct bt_ctf_field_type
*enumeration_type
;
1736 struct bt_ctf_field_type
*returned_type
;
1737 const char *ret_string
;
1739 returned_type
= bt_ctf_field_get_type(NULL
);
1740 ok(!returned_type
, "bt_ctf_field_get_type handles NULL correctly");
1742 ok(uint_12_type
, "Create an unsigned integer type");
1743 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1744 BT_CTF_INTEGER_BASE_BINARY
) == 0,
1745 "Set integer type's base as binary");
1746 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1747 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
1748 "Set integer type's base as decimal");
1749 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1750 BT_CTF_INTEGER_BASE_UNKNOWN
),
1751 "Reject integer type's base set as unknown");
1752 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1753 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
1754 "Set integer type's base as octal");
1755 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1756 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
1757 "Set integer type's base as hexadecimal");
1758 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
1759 "Reject unknown integer base value");
1760 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
1761 "Set integer type signedness to signed");
1762 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
1763 "Set integer type signedness to unsigned");
1764 ok(bt_ctf_field_type_integer_get_size(NULL
) < 0,
1765 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1766 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
1767 "bt_ctf_field_type_integer_get_size returns a correct value");
1768 ok(bt_ctf_field_type_integer_get_signed(NULL
) < 0,
1769 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1770 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
1771 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1773 ok(bt_ctf_field_type_set_byte_order(NULL
,
1774 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
1775 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1776 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1777 (enum bt_ctf_byte_order
) 42) < 0,
1778 "bt_ctf_field_type_set_byte_order rejects invalid values");
1779 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1780 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
1781 "Set an integer's byte order to little endian");
1782 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1783 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1784 "Set an integer's byte order to big endian");
1785 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
1786 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1787 "bt_ctf_field_type_get_byte_order returns a correct value");
1788 ok(bt_ctf_field_type_get_byte_order(NULL
) ==
1789 BT_CTF_BYTE_ORDER_UNKNOWN
,
1790 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1792 ok(bt_ctf_field_type_get_type_id(NULL
) ==
1793 BT_CTF_FIELD_TYPE_ID_UNKNOWN
,
1794 "bt_ctf_field_type_get_type_id handles NULL correctly");
1795 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
1796 BT_CTF_FIELD_TYPE_ID_INTEGER
,
1797 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1799 ok(bt_ctf_field_type_integer_get_base(NULL
) ==
1800 BT_CTF_INTEGER_BASE_UNKNOWN
,
1801 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1802 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
1803 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
1804 "bt_ctf_field_type_integer_get_base returns a correct value");
1806 ok(bt_ctf_field_type_integer_set_encoding(NULL
,
1807 BT_CTF_STRING_ENCODING_ASCII
) < 0,
1808 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1809 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1810 (enum bt_ctf_string_encoding
) 123) < 0,
1811 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1812 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1813 BT_CTF_STRING_ENCODING_UTF8
) == 0,
1814 "Set integer type encoding to UTF8");
1815 ok(bt_ctf_field_type_integer_get_encoding(NULL
) ==
1816 BT_CTF_STRING_ENCODING_UNKNOWN
,
1817 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1818 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) ==
1819 BT_CTF_STRING_ENCODING_UTF8
,
1820 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1822 int_16_type
= bt_ctf_field_type_integer_create(16);
1823 assert(int_16_type
);
1824 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
1825 "Set signedness of 16 bit integer to true");
1826 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
1827 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1828 uint_8_type
= bt_ctf_field_type_integer_create(8);
1830 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
1831 ok(sequence_type
, "Create a sequence of int16_t type");
1832 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
1833 BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
1834 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1836 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL
) == NULL
,
1837 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1838 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
1840 ok(!strcmp(ret_string
, "seq_len"),
1841 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1842 ok(bt_ctf_field_type_sequence_get_element_type(NULL
) == NULL
,
1843 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1844 returned_type
= bt_ctf_field_type_sequence_get_element_type(
1846 ok(returned_type
== int_16_type
,
1847 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
1848 bt_put(returned_type
);
1850 string_type
= bt_ctf_field_type_string_create();
1851 ok(string_type
, "Create a string type");
1852 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1853 BT_CTF_STRING_ENCODING_NONE
),
1854 "Reject invalid \"None\" string encoding");
1855 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1857 "Reject invalid string encoding");
1858 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1859 BT_CTF_STRING_ENCODING_ASCII
) == 0,
1860 "Set string encoding to ASCII");
1862 ok(bt_ctf_field_type_string_get_encoding(NULL
) ==
1863 BT_CTF_STRING_ENCODING_UNKNOWN
,
1864 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
1865 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
1866 BT_CTF_STRING_ENCODING_ASCII
,
1867 "bt_ctf_field_type_string_get_encoding returns the correct value");
1869 structure_seq_type
= bt_ctf_field_type_structure_create();
1870 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
1871 BT_CTF_FIELD_TYPE_ID_STRUCT
,
1872 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
1873 ok(structure_seq_type
, "Create a structure type");
1874 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1875 uint_8_type
, "seq_len") == 0,
1876 "Add a uint8_t type to a structure");
1877 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1878 sequence_type
, "a_sequence") == 0,
1879 "Add a sequence type to a structure");
1881 ok(bt_ctf_field_type_structure_get_field_count(NULL
) < 0,
1882 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
1883 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
1884 "bt_ctf_field_type_structure_get_field_count returns a correct value");
1886 ok(bt_ctf_field_type_structure_get_field(NULL
,
1887 &ret_string
, &returned_type
, 1) < 0,
1888 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
1889 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1890 NULL
, &returned_type
, 1) == 0,
1891 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
1892 bt_put(returned_type
);
1893 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1894 &ret_string
, NULL
, 1) == 0,
1895 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
1896 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1897 &ret_string
, &returned_type
, 10) < 0,
1898 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
1899 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1900 &ret_string
, &returned_type
, 1) == 0,
1901 "bt_ctf_field_type_structure_get_field returns a field");
1902 ok(!strcmp(ret_string
, "a_sequence"),
1903 "bt_ctf_field_type_structure_get_field returns a correct field name");
1904 ok(returned_type
== sequence_type
,
1905 "bt_ctf_field_type_structure_get_field returns a correct field type");
1906 bt_put(returned_type
);
1908 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL
, "a_sequence") == NULL
,
1909 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
1910 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type
, NULL
) == NULL
,
1911 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1912 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1913 structure_seq_type
, "a_sequence");
1914 ok(returned_type
== sequence_type
,
1915 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
1916 bt_put(returned_type
);
1918 composite_structure_type
= bt_ctf_field_type_structure_create();
1919 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1920 string_type
, "a_string") == 0,
1921 "Add a string type to a structure");
1922 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1923 structure_seq_type
, "inner_structure") == 0,
1924 "Add a structure type to a structure");
1926 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1927 NULL
, "a_sequence") == NULL
,
1928 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
1929 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1930 structure_seq_type
, NULL
) == NULL
,
1931 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1932 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1933 structure_seq_type
, "a_sequence");
1934 ok(returned_type
== sequence_type
,
1935 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1936 bt_put(returned_type
);
1938 int_16
= bt_ctf_field_create(int_16_type
);
1939 ok(int_16
, "Instanciate a signed 16-bit integer");
1940 uint_12
= bt_ctf_field_create(uint_12_type
);
1941 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1942 returned_type
= bt_ctf_field_get_type(int_16
);
1943 ok(returned_type
== int_16_type
,
1944 "bt_ctf_field_get_type returns the correct type");
1946 /* Can't modify types after instanciating them */
1947 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1948 BT_CTF_INTEGER_BASE_DECIMAL
),
1949 "Check an integer type' base can't be modified after instanciation");
1950 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1951 "Check an integer type's signedness can't be modified after instanciation");
1953 /* Check signed property is checked */
1954 ok(bt_ctf_field_signed_integer_set_value(uint_12
, -52),
1955 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
1956 ok(bt_ctf_field_unsigned_integer_set_value(int_16
, 42),
1957 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
1959 /* Check overflows are properly tested for */
1960 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32768) == 0,
1961 "Check -32768 is allowed for a signed 16-bit integer");
1962 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32767) == 0,
1963 "Check 32767 is allowed for a signed 16-bit integer");
1964 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32768),
1965 "Check 32768 is not allowed for a signed 16-bit integer");
1966 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32769),
1967 "Check -32769 is not allowed for a signed 16-bit integer");
1968 ok(bt_ctf_field_signed_integer_set_value(int_16
, -42) == 0,
1969 "Check -42 is allowed for a signed 16-bit integer");
1971 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4095) == 0,
1972 "Check 4095 is allowed for an unsigned 12-bit integer");
1973 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4096),
1974 "Check 4096 is not allowed for a unsigned 12-bit integer");
1975 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 0) == 0,
1976 "Check 0 is allowed for an unsigned 12-bit integer");
1978 string
= bt_ctf_field_create(string_type
);
1979 ok(string
, "Instanciate a string field");
1980 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1981 "Set a string's value");
1983 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1984 ok(enumeration_type
,
1985 "Create an enumeration type with an unsigned 12-bit integer as container");
1986 enumeration
= bt_ctf_field_create(enumeration_type
);
1988 "Check enumeration types are validated before instantiation");
1993 bt_put(enumeration
);
1994 bt_put(composite_structure_type
);
1995 bt_put(structure_seq_type
);
1996 bt_put(string_type
);
1997 bt_put(sequence_type
);
1998 bt_put(uint_8_type
);
1999 bt_put(int_16_type
);
2000 bt_put(uint_12_type
);
2001 bt_put(enumeration_type
);
2002 bt_put(returned_type
);
2006 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
2007 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
2010 * Append enough events to force the underlying packet to be resized.
2011 * Also tests that a new event can be declared after a stream has been
2012 * instantiated and used/flushed.
2016 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
2018 struct bt_ctf_field_type
*integer_type
=
2019 bt_ctf_field_type_integer_create(17);
2020 struct bt_ctf_field_type
*string_type
=
2021 bt_ctf_field_type_string_create();
2022 struct bt_ctf_event
*event
= NULL
;
2023 struct bt_ctf_field
*ret_field
= NULL
;
2024 struct bt_ctf_field_type
*ret_field_type
= NULL
;
2025 uint64_t ret_uint64
;
2026 int events_appended
= 0;
2027 struct bt_ctf_field
*packet_context
= NULL
,
2028 *packet_context_field
= NULL
, *stream_event_context
= NULL
;
2029 struct bt_ctf_field_type
*ep_field_1_type
= NULL
;
2030 struct bt_ctf_field_type
*ep_a_string_type
= NULL
;
2031 struct bt_ctf_field_type
*ep_type
= NULL
;
2033 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
2035 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
2037 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
2038 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
2044 * bt_ctf_stream_class_add_event_class() copies the field types
2045 * of event_class, so we retrieve the new ones to create the
2046 * appropriate fields.
2048 ep_type
= bt_ctf_event_class_get_payload_type(event_class
);
2050 ep_field_1_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2051 ep_type
, "field_1");
2052 assert(ep_field_1_type
);
2053 ep_a_string_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2054 ep_type
, "a_string");
2055 assert(ep_a_string_type
);
2057 event
= bt_ctf_event_create(event_class
);
2058 ret_field
= bt_ctf_event_get_payload_by_index(event
, 0);
2059 ret_field_type
= bt_ctf_field_get_type(ret_field
);
2060 ok(bt_ctf_field_type_compare(ret_field_type
, integer_type
) == 0,
2061 "bt_ctf_event_get_payload_by_index returns a correct field");
2062 bt_put(ret_field_type
);
2065 ok(bt_ctf_event_get_payload_by_index(NULL
, 0) == NULL
,
2066 "bt_ctf_event_get_payload_by_index handles NULL correctly");
2067 ok(bt_ctf_event_get_payload_by_index(event
, 4) == NULL
,
2068 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
2071 for (i
= 0; i
< PACKET_RESIZE_TEST_LENGTH
; i
++) {
2072 event
= bt_ctf_event_create(event_class
);
2073 struct bt_ctf_field
*integer
=
2074 bt_ctf_field_create(ep_field_1_type
);
2075 struct bt_ctf_field
*string
=
2076 bt_ctf_field_create(ep_a_string_type
);
2078 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
2079 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
2080 ret
|= bt_ctf_event_set_payload(event
, "field_1",
2083 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
2084 ret
|= bt_ctf_event_set_payload(event
, "a_string",
2088 /* Populate stream event context */
2089 stream_event_context
=
2090 bt_ctf_event_get_stream_event_context(event
);
2091 integer
= bt_ctf_field_structure_get_field(stream_event_context
,
2092 "common_event_context");
2093 BT_PUT(stream_event_context
);
2094 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
,
2098 ret
|= bt_ctf_stream_append_event(stream
, event
);
2106 events_appended
= !!(i
== PACKET_RESIZE_TEST_LENGTH
);
2107 ok(bt_ctf_stream_get_discarded_events_count(NULL
, &ret_uint64
) < 0,
2108 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
2109 ok(bt_ctf_stream_get_discarded_events_count(stream
, NULL
) < 0,
2110 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
2111 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
2112 ok(ret
== 0 && ret_uint64
== 0,
2113 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
2114 bt_ctf_stream_append_discarded_events(stream
, 1000);
2115 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
2116 ok(ret
== 0 && ret_uint64
== 1000,
2117 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
2120 ok(events_appended
, "Append 100 000 events to a stream");
2123 * Populate the custom packet context field with a dummy value
2124 * otherwise flush will fail.
2126 packet_context
= bt_ctf_stream_get_packet_context(stream
);
2127 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
2128 "custom_packet_context_field");
2129 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 2);
2131 ok(bt_ctf_stream_flush(stream
) == 0,
2132 "Flush a stream that forces a packet resize");
2133 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
2134 ok(ret
== 0 && ret_uint64
== 1000,
2135 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
2136 bt_put(integer_type
);
2137 bt_put(string_type
);
2138 bt_put(packet_context
);
2139 bt_put(packet_context_field
);
2140 bt_put(stream_event_context
);
2141 bt_put(event_class
);
2142 bt_put(ep_field_1_type
);
2143 bt_put(ep_a_string_type
);
2148 void test_empty_stream(struct bt_ctf_writer
*writer
)
2151 struct bt_ctf_trace
*trace
= NULL
, *ret_trace
= NULL
;
2152 struct bt_ctf_stream_class
*stream_class
= NULL
;
2153 struct bt_ctf_stream
*stream
= NULL
;
2155 trace
= bt_ctf_writer_get_trace(writer
);
2157 diag("Failed to get trace from writer");
2162 stream_class
= bt_ctf_stream_class_create("empty_stream");
2163 if (!stream_class
) {
2164 diag("Failed to create stream class");
2169 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
2171 ret
= bt_ctf_stream_class_set_event_header_type(stream_class
, NULL
);
2174 ok(bt_ctf_stream_class_get_trace(NULL
) == NULL
,
2175 "bt_ctf_stream_class_get_trace handles NULL correctly");
2176 ok(bt_ctf_stream_class_get_trace(stream_class
) == NULL
,
2177 "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned");
2179 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
2181 diag("Failed to create writer stream");
2186 ret_trace
= bt_ctf_stream_class_get_trace(stream_class
);
2187 ok(ret_trace
== trace
,
2188 "bt_ctf_stream_class_get_trace returns the correct trace after a stream has been created");
2191 "Created a stream class with default attributes and an empty stream");
2195 bt_put(stream_class
);
2199 void test_custom_event_header_stream(struct bt_ctf_writer
*writer
,
2200 struct bt_ctf_clock
*clock
)
2203 struct bt_ctf_stream_class
*stream_class
= NULL
;
2204 struct bt_ctf_stream
*stream
= NULL
;
2205 struct bt_ctf_field_type
*integer_type
= NULL
,
2206 *sequence_type
= NULL
, *event_header_type
= NULL
;
2207 struct bt_ctf_field
*integer
= NULL
, *sequence
= NULL
,
2208 *event_header
= NULL
, *packet_header
= NULL
;
2209 struct bt_ctf_event_class
*event_class
= NULL
;
2210 struct bt_ctf_event
*event
= NULL
;
2212 stream_class
= bt_ctf_stream_class_create("custom_event_header_stream");
2213 if (!stream_class
) {
2214 fail("Failed to create stream class");
2218 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
2220 fail("Failed to set stream class clock");
2225 * Customize event header to add an "seq_len" integer member
2226 * which will be used as the length of a sequence in an event of this
2229 event_header_type
= bt_ctf_stream_class_get_event_header_type(
2231 if (!event_header_type
) {
2232 fail("Failed to get event header type");
2236 integer_type
= bt_ctf_field_type_integer_create(13);
2237 if (!integer_type
) {
2238 fail("Failed to create length integer type");
2242 ret
= bt_ctf_field_type_structure_add_field(event_header_type
,
2243 integer_type
, "seq_len");
2245 fail("Failed to add a new field to stream event header");
2249 event_class
= bt_ctf_event_class_create("sequence_event");
2251 fail("Failed to create event class");
2256 * This event's payload will contain a sequence which references
2257 * stream.event.header.seq_len as its length field.
2259 sequence_type
= bt_ctf_field_type_sequence_create(integer_type
,
2260 "stream.event.header.seq_len");
2261 if (!sequence_type
) {
2262 fail("Failed to create a sequence");
2266 ret
= bt_ctf_event_class_add_field(event_class
, sequence_type
,
2269 fail("Failed to add a sequence to an event class");
2273 ret
= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
2275 fail("Failed to add event class to stream class");
2279 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
2281 fail("Failed to create stream")
2286 * We have defined a custom packet header field. We have to populate it
2289 packet_header
= bt_ctf_stream_get_packet_header(stream
);
2290 if (!packet_header
) {
2291 fail("Failed to get stream packet header");
2295 integer
= bt_ctf_field_structure_get_field(packet_header
,
2296 "custom_trace_packet_header_field");
2298 fail("Failed to retrieve custom_trace_packet_header_field");
2302 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 3487);
2304 fail("Failed to set custom_trace_packet_header_field value");
2309 event
= bt_ctf_event_create(event_class
);
2311 fail("Failed to create event");
2315 event_header
= bt_ctf_event_get_header(event
);
2316 if (!event_header
) {
2317 fail("Failed to get event header");
2321 integer
= bt_ctf_field_structure_get_field(event_header
,
2324 fail("Failed to get seq_len field from event header");
2328 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 2);
2330 fail("Failed to set seq_len value in event header");
2334 /* Populate both sequence integer fields */
2335 sequence
= bt_ctf_event_get_payload(event
, "some_sequence");
2337 fail("Failed to retrieve sequence from event");
2341 ret
= bt_ctf_field_sequence_set_length(sequence
, integer
);
2343 fail("Failed to set sequence length");
2348 for (i
= 0; i
< 2; i
++) {
2349 integer
= bt_ctf_field_sequence_get_field(sequence
, i
);
2351 fail("Failed to retrieve sequence element");
2355 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
2357 fail("Failed to set sequence element value");
2365 ret
= bt_ctf_stream_append_event(stream
, event
);
2367 fail("Failed to append event to stream");
2371 ret
= bt_ctf_stream_flush(stream
);
2373 fail("Failed to flush custom_event_header stream");
2377 bt_put(stream_class
);
2378 bt_put(event_class
);
2382 bt_put(event_header
);
2383 bt_put(packet_header
);
2384 bt_put(sequence_type
);
2385 bt_put(integer_type
);
2386 bt_put(event_header_type
);
2390 void test_instanciate_event_before_stream(struct bt_ctf_writer
*writer
,
2391 struct bt_ctf_clock
*clock
)
2394 struct bt_ctf_stream_class
*stream_class
= NULL
;
2395 struct bt_ctf_stream
*stream
= NULL
,
2397 struct bt_ctf_event_class
*event_class
= NULL
;
2398 struct bt_ctf_event
*event
= NULL
;
2399 struct bt_ctf_field_type
*integer_type
= NULL
;
2400 struct bt_ctf_field
*integer
= NULL
;
2402 stream_class
= bt_ctf_stream_class_create("event_before_stream_test");
2403 if (!stream_class
) {
2404 diag("Failed to create stream class");
2409 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
2411 diag("Failed to set stream class clock");
2415 event_class
= bt_ctf_event_class_create("some_event_class_name");
2416 integer_type
= bt_ctf_field_type_integer_create(32);
2417 if (!integer_type
) {
2418 diag("Failed to create integer field type");
2423 ret
= bt_ctf_event_class_add_field(event_class
, integer_type
,
2426 diag("Failed to add field to event class");
2430 ret
= bt_ctf_stream_class_add_event_class(stream_class
,
2433 diag("Failed to add event class to stream class");
2436 event
= bt_ctf_event_create(event_class
);
2438 diag("Failed to create event");
2443 integer
= bt_ctf_event_get_payload_by_index(event
, 0);
2445 diag("Failed to get integer field payload from event");
2450 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 1234);
2452 diag("Failed to set integer field value");
2456 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
2458 diag("Failed to create writer stream");
2463 ok(bt_ctf_event_get_stream(NULL
) == NULL
,
2464 "bt_ctf_event_get_stream handles NULL correctly");
2465 ok(bt_ctf_event_get_stream(event
) == NULL
,
2466 "bt_ctf_event_get_stream returns NULL on event which has not yet been appended to a stream");
2468 ret
= bt_ctf_stream_append_event(stream
, event
);
2470 diag("Failed to append event to stream");
2474 ret_stream
= bt_ctf_event_get_stream(event
);
2475 ok(ret_stream
== stream
,
2476 "bt_ctf_event_get_stream returns an event's stream after it has been appended");
2479 "Create an event before instanciating its associated stream");
2482 bt_put(stream_class
);
2483 bt_put(event_class
);
2485 bt_put(integer_type
);
2490 void append_existing_event_class(struct bt_ctf_stream_class
*stream_class
)
2492 struct bt_ctf_event_class
*event_class
;
2494 event_class
= bt_ctf_event_class_create("Simple Event");
2495 assert(event_class
);
2496 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
) == 0,
2497 "two event classes with the same name may cohabit within the same stream class");
2498 bt_put(event_class
);
2500 event_class
= bt_ctf_event_class_create("different name, ok");
2501 assert(event_class
);
2502 assert(!bt_ctf_event_class_set_id(event_class
, 11));
2503 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
2504 "two event classes with the same ID cannot cohabit within the same stream class");
2505 bt_put(event_class
);
2509 struct bt_ctf_event_class
*create_minimal_event_class(void)
2511 struct bt_ctf_event_class
*ec
= NULL
;
2512 struct bt_ctf_field_type
*int_ft
= NULL
;
2515 int_ft
= bt_ctf_field_type_integer_create(23);
2517 ec
= bt_ctf_event_class_create("minimal");
2519 ret
= bt_ctf_event_class_add_field(ec
, int_ft
, "field");
2527 void test_create_writer_vs_non_writer_mode(void)
2530 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
2531 const char *writer_stream_name
= "writer stream instance";
2532 struct bt_ctf_writer
*writer
= NULL
;
2533 struct bt_ctf_trace
*writer_trace
= NULL
;
2534 struct bt_ctf_stream_class
*writer_sc
= NULL
;
2535 struct bt_ctf_stream
*writer_stream
= NULL
;
2536 struct bt_ctf_stream
*writer_stream2
= NULL
;
2537 struct bt_ctf_stream
*packet_stream
= NULL
;
2538 struct bt_ctf_trace
*non_writer_trace
= NULL
;
2539 struct bt_ctf_stream_class
*non_writer_sc
= NULL
;
2540 struct bt_ctf_stream
*non_writer_stream
= NULL
;
2541 struct bt_ctf_stream
*non_writer_stream2
= NULL
;
2542 struct bt_ctf_event_class
*writer_ec
= NULL
;
2543 struct bt_ctf_event_class
*non_writer_ec
= NULL
;
2544 struct bt_ctf_event
*event
= NULL
;
2545 struct bt_ctf_event
*event2
= NULL
;
2546 struct bt_ctf_field_type
*empty_struct_ft
= NULL
;
2547 struct bt_ctf_field
*int_field
= NULL
;
2548 struct bt_ctf_clock
*writer_clock
= NULL
;
2549 struct bt_ctf_clock_class
*non_writer_clock_class
= NULL
;
2550 struct bt_ctf_packet
*packet
= NULL
;
2551 struct bt_ctf_packet
*packet2
= NULL
;
2553 if (!bt_mkdtemp(trace_path
)) {
2557 /* Create empty structure field type (event header) */
2558 empty_struct_ft
= bt_ctf_field_type_structure_create();
2559 assert(empty_struct_ft
);
2561 /* Create writer, writer stream class, stream, and clock */
2562 writer
= bt_ctf_writer_create(trace_path
);
2564 writer_clock
= bt_ctf_clock_create("writer_clock");
2565 assert(writer_clock
);
2566 ret
= bt_ctf_writer_add_clock(writer
, writer_clock
);
2568 ret
= bt_ctf_writer_set_byte_order(writer
, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
);
2570 writer_trace
= bt_ctf_writer_get_trace(writer
);
2571 ok(writer_trace
, "bt_ctf_writer_get_trace() returns a trace");
2572 writer_sc
= bt_ctf_stream_class_create("writer_sc");
2574 ret
= bt_ctf_stream_class_set_event_header_type(writer_sc
,
2577 ret
= bt_ctf_stream_class_set_clock(writer_sc
, writer_clock
);
2579 ret
= bt_ctf_trace_add_stream_class(writer_trace
, writer_sc
);
2581 writer_stream
= bt_ctf_stream_create(writer_sc
, writer_stream_name
);
2582 assert(writer_stream
);
2583 ok(!strcmp(bt_ctf_stream_get_name(writer_stream
), writer_stream_name
),
2584 "bt_ctf_stream_get_name() returns the stream's name");
2586 /* Create non-writer trace, stream class, stream, and clock */
2587 non_writer_trace
= bt_ctf_trace_create();
2588 assert(non_writer_trace
);
2589 non_writer_sc
= bt_ctf_stream_class_create("nonwriter_sc");
2590 assert(non_writer_sc
);
2591 ret
= bt_ctf_stream_class_set_event_header_type(non_writer_sc
,
2594 ret
= bt_ctf_stream_class_set_packet_context_type(non_writer_sc
, NULL
);
2596 ret
= bt_ctf_trace_add_stream_class(non_writer_trace
, non_writer_sc
);
2598 non_writer_stream
= bt_ctf_stream_create(non_writer_sc
, NULL
);
2599 assert(non_writer_stream
);
2600 non_writer_clock_class
=
2601 bt_ctf_clock_class_create("non_writer_clock_class");
2602 assert(non_writer_clock_class
);
2603 ret
= bt_ctf_trace_add_clock_class(non_writer_trace
,
2604 non_writer_clock_class
);
2607 /* Create event class and event */
2608 writer_ec
= create_minimal_event_class();
2610 ret
= bt_ctf_stream_class_add_event_class(writer_sc
, writer_ec
);
2612 event
= bt_ctf_event_create(writer_ec
);
2614 int_field
= bt_ctf_event_get_payload_by_index(event
, 0);
2616 bt_ctf_field_unsigned_integer_set_value(int_field
, 17);
2619 * Verify non-writer stream: it should be impossible to append
2622 ok(bt_ctf_stream_append_event(non_writer_stream
, event
),
2623 "bt_ctf_stream_append_event() fails with a non-writer stream");
2626 * Verify writer stream: it should be possible to append an
2629 ok(!bt_ctf_stream_append_event(writer_stream
, event
),
2630 "bt_ctf_stream_append_event() succeeds with a writer stream");
2633 * It should be possible to create a packet from a non-writer
2634 * stream, but not from a writer stream.
2636 packet
= bt_ctf_packet_create(writer_stream
);
2637 ok(!packet
, "bt_ctf_packet_create() fails with a writer stream");
2638 packet
= bt_ctf_packet_create(non_writer_stream
);
2639 ok(packet
, "bt_ctf_packet_create() succeeds with a non-writer stream");
2640 packet_stream
= bt_ctf_packet_get_stream(packet
);
2641 ok(packet_stream
== non_writer_stream
,
2642 "bt_ctf_packet_get_stream() returns the correct stream");
2645 * It should not be possible to append an event associated to
2646 * a stream to a different stream.
2648 writer_stream2
= bt_ctf_stream_create(writer_sc
, "zoo");
2649 assert(writer_stream2
);
2650 ok(bt_ctf_stream_append_event(writer_stream2
, event
),
2651 "bt_ctf_stream_append_event() fails with an event associated to another stream");
2654 * It should not be possible to set the packet of an event
2655 * associated to a given stream to a packet associated with
2656 * a different stream.
2658 ok(bt_ctf_event_set_packet(event
, packet
),
2659 "bt_ctf_event_set_packet() fails with a packet not sharing the event's stream");
2662 * It should be possible to set the packet of a fresh event, as
2663 * long as the originating stream classes are the same.
2665 event2
= bt_ctf_event_create(writer_ec
);
2667 ok(bt_ctf_event_set_packet(event2
, packet
),
2668 "bt_ctf_event_set_packet() fails when the event's and the packet's stream class differ");
2669 non_writer_ec
= create_minimal_event_class();
2670 assert(non_writer_ec
);
2671 ret
= bt_ctf_stream_class_add_event_class(non_writer_sc
, non_writer_ec
);
2674 event2
= bt_ctf_event_create(non_writer_ec
);
2676 ok(!bt_ctf_event_set_packet(event2
, packet
),
2677 "bt_ctf_event_set_packet() succeeds when the event's and the packet's stream class are the same");
2680 * It should be possible to set a packet created from the same
2681 * stream to an event with an existing packet.
2683 packet2
= bt_ctf_packet_create(non_writer_stream
);
2685 ok(!bt_ctf_event_set_packet(event2
, packet2
),
2686 "bt_ctf_event_set_packet() succeeds when the event's current packet has the same stream");
2690 * It should not be possible to set a packet created from a
2691 * different stream to an event with an existing packet.
2693 non_writer_stream2
= bt_ctf_stream_create(non_writer_sc
, "rj45");
2694 assert(non_writer_stream2
);
2695 packet2
= bt_ctf_packet_create(non_writer_stream
);
2697 ok(!bt_ctf_event_set_packet(event2
, packet2
),
2698 "bt_ctf_event_set_packet() fails when the event's current packet does not have the same stream");
2701 bt_put(writer_trace
);
2703 bt_put(writer_stream
);
2704 bt_put(writer_stream2
);
2705 bt_put(non_writer_trace
);
2706 bt_put(non_writer_sc
);
2707 bt_put(non_writer_stream
);
2708 bt_put(non_writer_stream2
);
2709 bt_put(packet_stream
);
2711 bt_put(non_writer_ec
);
2715 bt_put(empty_struct_ft
);
2716 bt_put(writer_clock
);
2717 bt_put(non_writer_clock_class
);
2720 recursive_rmdir(trace_path
);
2724 void test_clock_utils(void)
2727 struct bt_ctf_clock
*clock
= NULL
;
2729 clock
= bt_ctf_clock_create("water");
2731 ret
= bt_ctf_clock_set_offset_s(clock
, 1234);
2733 ret
= bt_ctf_clock_set_offset(clock
, 1000);
2735 ret
= bt_ctf_clock_set_frequency(clock
, 1000000000);
2737 ret
= bt_ctf_clock_set_frequency(clock
, 1534);
2743 void test_set_clock_non_writer_stream_class(void)
2745 struct bt_ctf_clock
*clock
;
2746 struct bt_ctf_trace
*trace
;
2747 struct bt_ctf_stream_class
*sc
;
2750 clock
= bt_ctf_clock_create("the_clock");
2753 trace
= bt_ctf_trace_create();
2756 sc
= bt_ctf_stream_class_create(NULL
);
2759 ret
= bt_ctf_stream_class_set_clock(sc
, clock
);
2762 ret
= bt_ctf_trace_add_stream_class(trace
, sc
);
2764 "bt_ctf_trace_add_stream_class() fails with a stream class with a registered clock");
2772 void test_static_trace(void)
2774 struct bt_ctf_trace
*trace
;
2775 struct bt_ctf_stream_class
*stream_class
;
2776 struct bt_ctf_stream_class
*stream_class2
;
2777 struct bt_ctf_stream
*stream
;
2778 struct bt_ctf_clock_class
*clock_class
;
2781 trace
= bt_ctf_trace_create();
2783 stream_class
= bt_ctf_stream_class_create(NULL
);
2784 assert(stream_class
);
2785 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
2787 ret
= bt_ctf_trace_add_stream_class(trace
, stream_class
);
2789 stream
= bt_ctf_stream_create(stream_class
, "hello");
2790 ok(stream
, "bt_ctf_stream_create() succeeds with a non-static trace");
2792 ok(!bt_ctf_trace_is_static(trace
),
2793 "bt_ctf_trace_is_static() returns the expected value");
2794 ok(bt_ctf_trace_set_is_static(trace
) == 0,
2795 "bt_ctf_trace_set_is_static() succeeds");
2796 ok(bt_ctf_trace_is_static(trace
),
2797 "bt_ctf_trace_is_static() returns the expected value");
2798 clock_class
= bt_ctf_clock_class_create("yes");
2799 assert(clock_class
);
2800 stream_class2
= bt_ctf_stream_class_create(NULL
);
2801 assert(stream_class2
);
2802 ok(bt_ctf_trace_add_stream_class(trace
, stream_class2
),
2803 "bt_ctf_trace_add_stream_class() fails with a static trace");
2804 ok(bt_ctf_trace_add_clock_class(trace
, clock_class
),
2805 "bt_ctf_trace_add_clock_class() fails with a static trace");
2806 ok(!bt_ctf_stream_create(stream_class
, "hello2"),
2807 "bt_ctf_stream_create() fails with a static trace");
2810 bt_put(stream_class
);
2811 bt_put(stream_class2
);
2812 bt_put(clock_class
);
2816 void trace_is_static_listener(struct bt_ctf_trace
*trace
, void *data
)
2818 *((int *) data
) = 1;
2822 void test_trace_is_static_listener(void)
2824 struct bt_ctf_trace
*trace
;
2835 trace
= bt_ctf_trace_create();
2837 ret
= bt_ctf_trace_add_is_static_listener(NULL
,
2838 trace_is_static_listener
, &called1
);
2839 ok(ret
< 0, "bt_ctf_trace_add_is_static_listener() handles NULL (trace)");
2840 ret
= bt_ctf_trace_add_is_static_listener(trace
, NULL
, &called1
);
2841 ok(ret
< 0, "bt_ctf_trace_add_is_static_listener() handles NULL (listener)");
2842 listener1_id
= bt_ctf_trace_add_is_static_listener(trace
,
2843 trace_is_static_listener
, &called1
);
2844 ok(listener1_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (1)");
2845 listener2_id
= bt_ctf_trace_add_is_static_listener(trace
,
2846 trace_is_static_listener
, &called2
);
2847 ok(listener2_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (2)");
2848 listener3_id
= bt_ctf_trace_add_is_static_listener(trace
,
2849 trace_is_static_listener
, &called3
);
2850 ok(listener3_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (3)");
2851 ret
= bt_ctf_trace_remove_is_static_listener(NULL
, 0);
2852 ok(ret
< 0, "bt_ctf_trace_remove_is_static_listener() handles NULL (trace)");
2853 ret
= bt_ctf_trace_remove_is_static_listener(trace
, -2);
2854 ok(ret
< 0, "bt_ctf_trace_remove_is_static_listener() handles invalid ID (negative)");
2855 ret
= bt_ctf_trace_remove_is_static_listener(trace
, 77);
2856 ok(ret
< 0, "bt_ctf_trace_remove_is_static_listener() handles invalid ID (non existing)");
2857 ret
= bt_ctf_trace_remove_is_static_listener(trace
, listener2_id
);
2858 ok(ret
== 0, "bt_ctf_trace_remove_is_static_listener() succeeds");
2859 listener4_id
= bt_ctf_trace_add_is_static_listener(trace
,
2860 trace_is_static_listener
, &called4
);
2861 ok(listener4_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (4)");
2862 ok(called1
== 0, "\"trace is static\" listener not called before the trace is made static (1)");
2863 ok(called2
== 0, "\"trace is static\" listener not called before the trace is made static (2)");
2864 ok(called3
== 0, "\"trace is static\" listener not called before the trace is made static (3)");
2865 ok(called4
== 0, "\"trace is static\" listener not called before the trace is made static (4)");
2866 ret
= bt_ctf_trace_set_is_static(trace
);
2868 ret
= bt_ctf_trace_add_is_static_listener(trace
,
2869 trace_is_static_listener
, &called1
);
2871 "bt_ctf_trace_add_is_static_listener() fails when the trace is static");
2872 ok(called1
== 1, "\"trace is static\" listener called when the trace is made static (1)");
2873 ok(called2
== 0, "\"trace is static\" listener not called when the trace is made static (2)");
2874 ok(called3
== 1, "\"trace is static\" listener called when the trace is made static (3)");
2875 ok(called4
== 1, "\"trace is static\" listener called when the trace is made static (4)");
2881 ok(called1
== 0, "\"trace is static\" listener not called after the trace is put (1)");
2882 ok(called2
== 0, "\"trace is static\" listener not called after the trace is put (2)");
2883 ok(called3
== 0, "\"trace is static\" listener not called after the trace is put (3)");
2884 ok(called4
== 0, "\"trace is static\" listener not called after the trace is put (4)");
2888 void test_trace_uuid(void)
2890 struct bt_ctf_trace
*trace
;
2891 const unsigned char uuid
[] = {
2892 0x35, 0x92, 0x63, 0xab, 0xb4, 0xbe, 0x40, 0xb4,
2893 0xb2, 0x60, 0xd3, 0xf1, 0x3b, 0xb0, 0xd8, 0x59,
2895 const unsigned char *ret_uuid
;
2897 trace
= bt_ctf_trace_create();
2899 ok(!bt_ctf_trace_get_uuid(NULL
),
2900 "bt_ctf_trace_get_uuid() handles NULL");
2901 ok(!bt_ctf_trace_get_uuid(trace
),
2902 "bt_ctf_trace_get_uuid() returns NULL initially");
2903 ok(bt_ctf_trace_set_uuid(NULL
, uuid
),
2904 "bt_ctf_trace_set_uuid() handles NULL (trace)");
2905 ok(bt_ctf_trace_set_uuid(trace
, NULL
),
2906 "bt_ctf_trace_set_uuid() handles NULL (UUID)");
2907 ok(bt_ctf_trace_set_uuid(trace
, uuid
) == 0,
2908 "bt_ctf_trace_set_uuid() succeeds with a valid UUID");
2909 ret_uuid
= bt_ctf_trace_get_uuid(trace
);
2910 ok(ret_uuid
, "bt_ctf_trace_get_uuid() returns a UUID");
2912 ok(memcmp(uuid
, ret_uuid
, 16) == 0,
2913 "bt_ctf_trace_get_uuid() returns the expected UUID");
2918 int main(int argc
, char **argv
)
2920 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
2921 char metadata_path
[sizeof(trace_path
) + 9];
2922 const char *clock_name
= "test_clock";
2923 const char *clock_description
= "This is a test clock";
2924 const char *returned_clock_name
;
2925 const char *returned_clock_description
;
2926 const uint64_t frequency
= 1123456789;
2927 const int64_t offset_s
= 1351530929945824323;
2928 const int64_t offset
= 1234567;
2929 int64_t get_offset_s
,
2931 const uint64_t precision
= 10;
2932 const int is_absolute
= 0xFF;
2933 char *metadata_string
;
2934 struct bt_ctf_writer
*writer
;
2935 struct utsname name
;
2936 char hostname
[BABELTRACE_HOST_NAME_MAX
];
2937 struct bt_ctf_clock
*clock
, *ret_clock
;
2938 struct bt_ctf_clock_class
*ret_clock_class
;
2939 struct bt_ctf_stream_class
*stream_class
, *ret_stream_class
;
2940 struct bt_ctf_stream
*stream1
;
2941 struct bt_ctf_stream
*stream
;
2942 const char *ret_string
;
2943 const unsigned char *ret_uuid
;
2944 unsigned char tmp_uuid
[16] = { 0 };
2945 struct bt_ctf_field_type
*packet_context_type
,
2946 *packet_context_field_type
,
2947 *packet_header_type
,
2948 *packet_header_field_type
,
2950 *stream_event_context_type
,
2952 *event_header_field_type
;
2953 struct bt_ctf_field
*packet_header
, *packet_header_field
;
2954 struct bt_ctf_trace
*trace
;
2956 int64_t ret_int64_t
;
2957 struct bt_value
*obj
;
2960 printf("Usage: tests-ctf-writer path_to_babeltrace\n");
2964 plan_tests(NR_TESTS
);
2966 if (!bt_mkdtemp(trace_path
)) {
2970 strcpy(metadata_path
, trace_path
);
2971 strcat(metadata_path
+ sizeof(trace_path
) - 1, "/metadata");
2973 writer
= bt_ctf_writer_create(trace_path
);
2974 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
2976 ok(!bt_ctf_writer_get_trace(NULL
),
2977 "bt_ctf_writer_get_trace correctly handles NULL");
2978 trace
= bt_ctf_writer_get_trace(writer
);
2979 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
),
2980 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NATIVE");
2981 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_NONE
),
2982 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NONE");
2984 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
2985 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
2986 "Set a trace's byte order to big endian");
2987 ok(bt_ctf_trace_get_native_byte_order(trace
) == BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
2988 "bt_ctf_trace_get_native_byte_order returns a correct endianness");
2990 /* Add environment context to the trace */
2991 ret
= gethostname(hostname
, sizeof(hostname
));
2995 ok(bt_ctf_writer_add_environment_field(writer
, "host", hostname
) == 0,
2996 "Add host (%s) environment field to writer instance",
2998 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
3000 "bt_ctf_writer_add_environment_field error with NULL writer");
3001 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
3003 "bt_ctf_writer_add_environment_field error with NULL field name");
3004 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
3006 "bt_ctf_writer_add_environment_field error with NULL field value");
3008 /* Test bt_ctf_trace_set_environment_field with an integer object */
3009 obj
= bt_value_integer_create_init(23);
3011 ok(bt_ctf_trace_set_environment_field(NULL
, "test_env_int_obj", obj
),
3012 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
3013 ok(bt_ctf_trace_set_environment_field(trace
, NULL
, obj
),
3014 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
3015 ok(bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", NULL
),
3016 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
3017 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", obj
),
3018 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
3021 /* Test bt_ctf_trace_set_environment_field with a string object */
3022 obj
= bt_value_string_create_init("the value");
3024 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_str_obj", obj
),
3025 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
3028 /* Test bt_ctf_trace_set_environment_field_integer */
3029 ok(bt_ctf_trace_set_environment_field_integer(NULL
, "test_env_int",
3031 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
3032 ok(bt_ctf_trace_set_environment_field_integer(trace
, NULL
, -194875),
3033 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
3034 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
3036 "bt_ctf_trace_set_environment_field_integer succeeds");
3038 /* Test bt_ctf_trace_set_environment_field_string */
3039 ok(bt_ctf_trace_set_environment_field_string(NULL
, "test_env_str",
3041 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
3042 ok(bt_ctf_trace_set_environment_field_string(trace
, NULL
, "yeah"),
3043 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
3044 ok(bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
3046 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
3047 ok(!bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
3049 "bt_ctf_trace_set_environment_field_string succeeds");
3051 /* Test bt_ctf_trace_get_environment_field_count */
3052 ok(bt_ctf_trace_get_environment_field_count(NULL
) < 0,
3053 "bt_ctf_trace_get_environment_field_count handles a NULL trace correctly");
3054 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
3055 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
3057 /* Test bt_ctf_trace_get_environment_field_name */
3058 ok(bt_ctf_trace_get_environment_field_name_by_index(NULL
, 0) == NULL
,
3059 "bt_ctf_trace_get_environment_field_name handles a NULL trace correctly");
3060 ok(bt_ctf_trace_get_environment_field_name_by_index(trace
, 5) == NULL
,
3061 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (too large)");
3062 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 0);
3063 ok(ret_string
&& !strcmp(ret_string
, "host"),
3064 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3065 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 1);
3066 ok(ret_string
&& !strcmp(ret_string
, "test_env_int_obj"),
3067 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3068 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 2);
3069 ok(ret_string
&& !strcmp(ret_string
, "test_env_str_obj"),
3070 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3071 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 3);
3072 ok(ret_string
&& !strcmp(ret_string
, "test_env_int"),
3073 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3074 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 4);
3075 ok(ret_string
&& !strcmp(ret_string
, "test_env_str"),
3076 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3078 /* Test bt_ctf_trace_get_environment_field_value */
3079 ok(bt_ctf_trace_get_environment_field_value_by_index(NULL
, 0) == NULL
,
3080 "bt_ctf_trace_get_environment_field_value handles a NULL trace correctly");
3081 ok(bt_ctf_trace_get_environment_field_value_by_index(trace
, 5) == NULL
,
3082 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (too large)");
3083 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 1);
3084 ret
= bt_value_integer_get(obj
, &ret_int64_t
);
3085 ok(!ret
&& ret_int64_t
== 23,
3086 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
3088 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 2);
3089 ret
= bt_value_string_get(obj
, &ret_string
);
3090 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "the value"),
3091 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
3094 /* Test bt_ctf_trace_get_environment_field_value_by_name */
3095 ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL
,
3097 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL trace correctly");
3098 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, NULL
),
3099 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL name correctly");
3100 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, "oh oh"),
3101 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
3102 obj
= bt_ctf_trace_get_environment_field_value_by_name(trace
,
3104 ret
= bt_value_string_get(obj
, &ret_string
);
3105 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "oh yeah"),
3106 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
3109 /* Test environment field replacement */
3110 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
3112 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
3113 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
3114 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
3115 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 3);
3116 ret
= bt_value_integer_get(obj
, &ret_int64_t
);
3117 ok(!ret
&& ret_int64_t
== 654321,
3118 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
3121 /* On Solaris, uname() can return any positive value on success */
3122 if (uname(&name
) < 0) {
3127 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
3128 == 0, "Add sysname (%s) environment field to writer instance",
3130 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
3131 name
.nodename
) == 0,
3132 "Add nodename (%s) environment field to writer instance",
3134 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
3135 == 0, "Add release (%s) environment field to writer instance",
3137 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
3138 == 0, "Add version (%s) environment field to writer instance",
3140 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
3141 == 0, "Add machine (%s) environment field to writer istance",
3144 /* Define a clock and add it to the trace */
3145 ok(bt_ctf_clock_create("signed") == NULL
,
3146 "Illegal clock name rejected");
3147 clock
= bt_ctf_clock_create(clock_name
);
3148 ok(clock
, "Clock created sucessfully");
3149 returned_clock_name
= bt_ctf_clock_get_name(clock
);
3150 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
3151 ok(returned_clock_name
? !strcmp(returned_clock_name
, clock_name
) : 0,
3152 "Returned clock name is valid");
3154 returned_clock_description
= bt_ctf_clock_get_description(clock
);
3155 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
3156 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
3157 "Clock description set successfully");
3159 returned_clock_description
= bt_ctf_clock_get_description(clock
);
3160 ok(returned_clock_description
,
3161 "bt_ctf_clock_get_description returns a description.");
3162 ok(returned_clock_description
?
3163 !strcmp(returned_clock_description
, clock_description
) : 0,
3164 "Returned clock description is valid");
3166 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
3167 "bt_ctf_clock_get_frequency returns the correct default frequency");
3168 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
3169 "Set clock frequency");
3170 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
3171 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
3173 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
3174 "bt_ctf_clock_get_offset_s succeeds");
3175 ok(get_offset_s
== DEFAULT_CLOCK_OFFSET_S
,
3176 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
3177 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
3178 "Set clock offset (seconds)");
3179 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
3180 "bt_ctf_clock_get_offset_s succeeds");
3181 ok(get_offset_s
== offset_s
,
3182 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
3184 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
3185 "bt_ctf_clock_get_offset succeeds");
3186 ok(get_offset
== DEFAULT_CLOCK_OFFSET
,
3187 "bt_ctf_clock_get_offset returns the correct default offset (in ticks)");
3188 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
3189 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
3190 "bt_ctf_clock_get_offset succeeds");
3191 ok(get_offset
== offset
,
3192 "bt_ctf_clock_get_offset returns the correct default offset (in ticks) once it is set");
3194 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
3195 "bt_ctf_clock_get_precision returns the correct default precision");
3196 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
3197 "Set clock precision");
3198 ok(bt_ctf_clock_get_precision(clock
) == precision
,
3199 "bt_ctf_clock_get_precision returns the correct precision once it is set");
3201 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
3202 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
3203 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
3204 "Set clock absolute property");
3205 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
3206 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
3208 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
3211 ok(!bt_ctf_clock_get_name(NULL
),
3212 "bt_ctf_clock_get_name correctly handles NULL");
3213 ok(!bt_ctf_clock_get_description(NULL
),
3214 "bt_ctf_clock_get_description correctly handles NULL");
3215 ok(bt_ctf_clock_get_frequency(NULL
) == -1ULL,
3216 "bt_ctf_clock_get_frequency correctly handles NULL");
3217 ok(bt_ctf_clock_get_precision(NULL
) == -1ULL,
3218 "bt_ctf_clock_get_precision correctly handles NULL");
3219 ok(bt_ctf_clock_get_offset_s(NULL
, &get_offset_s
) < 0,
3220 "bt_ctf_clock_get_offset_s correctly handles NULL clock");
3221 ok(bt_ctf_clock_get_offset_s(clock
, NULL
) < 0,
3222 "bt_ctf_clock_get_offset_s correctly handles NULL output");
3223 ok(bt_ctf_clock_get_offset(NULL
, &get_offset
) < 0,
3224 "bt_ctf_clock_get_offset correctly handles NULL clock");
3225 ok(bt_ctf_clock_get_offset(clock
, NULL
) < 0,
3226 "bt_ctf_clock_get_offset correctly handles NULL output");
3227 ok(bt_ctf_clock_get_is_absolute(NULL
) < 0,
3228 "bt_ctf_clock_get_is_absolute correctly handles NULL");
3230 ok(bt_ctf_clock_set_description(NULL
, NULL
) < 0,
3231 "bt_ctf_clock_set_description correctly handles NULL clock");
3232 ok(bt_ctf_clock_set_frequency(NULL
, frequency
) < 0,
3233 "bt_ctf_clock_set_frequency correctly handles NULL clock");
3234 ok(bt_ctf_clock_set_precision(NULL
, precision
) < 0,
3235 "bt_ctf_clock_get_precision correctly handles NULL clock");
3236 ok(bt_ctf_clock_set_offset_s(NULL
, offset_s
) < 0,
3237 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
3238 ok(bt_ctf_clock_set_offset(NULL
, offset
) < 0,
3239 "bt_ctf_clock_set_offset correctly handles NULL clock");
3240 ok(bt_ctf_clock_set_is_absolute(NULL
, is_absolute
) < 0,
3241 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
3242 ok(bt_ctf_clock_set_time(NULL
, current_time
) < 0,
3243 "bt_ctf_clock_set_time correctly handles NULL clock");
3244 ok(bt_ctf_clock_get_uuid(NULL
) == NULL
,
3245 "bt_ctf_clock_get_uuid correctly handles NULL clock");
3246 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
3248 "bt_ctf_clock_get_uuid returns a UUID");
3250 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
3251 /* Slightly modify UUID */
3252 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
3255 ok(bt_ctf_clock_set_uuid(NULL
, tmp_uuid
) < 0,
3256 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
3257 ok(bt_ctf_clock_set_uuid(clock
, NULL
) < 0,
3258 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
3259 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
3260 "bt_ctf_clock_set_uuid sets a new uuid successfully");
3261 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
3263 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
3264 ok(uuid_match(ret_uuid
, tmp_uuid
),
3265 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
3267 /* Define a stream class */
3268 stream_class
= bt_ctf_stream_class_create("test_stream");
3270 ok(bt_ctf_stream_class_get_name(NULL
) == NULL
,
3271 "bt_ctf_stream_class_get_name handles NULL correctly");
3272 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
3273 ok(ret_string
&& !strcmp(ret_string
, "test_stream"),
3274 "bt_ctf_stream_class_get_name returns a correct stream class name");
3276 ok(bt_ctf_stream_class_get_clock(stream_class
) == NULL
,
3277 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
3278 ok(bt_ctf_stream_class_get_clock(NULL
) == NULL
,
3279 "bt_ctf_stream_class_get_clock handles NULL correctly");
3281 ok(stream_class
, "Create stream class");
3282 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
3283 "Set a stream class' clock");
3284 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
3285 ok(ret_clock
== clock
,
3286 "bt_ctf_stream_class_get_clock returns a correct clock");
3289 /* Test the event fields and event types APIs */
3292 /* Test fields copying */
3295 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
3296 "bt_ctf_stream_class_get_id returns an error when no id is set");
3297 ok(bt_ctf_stream_class_get_id(NULL
) < 0,
3298 "bt_ctf_stream_class_get_id handles NULL correctly");
3299 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
3300 "bt_ctf_stream_class_set_id handles NULL correctly");
3301 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
3302 "Set an stream class' id");
3303 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
3304 "bt_ctf_stream_class_get_id returns the correct value");
3306 /* Validate default event header fields */
3307 ok(bt_ctf_stream_class_get_event_header_type(NULL
) == NULL
,
3308 "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
3309 ret_field_type
= bt_ctf_stream_class_get_event_header_type(
3312 "bt_ctf_stream_class_get_event_header_type returns an event header type");
3313 ok(bt_ctf_field_type_get_type_id(ret_field_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
3314 "Default event header type is a structure");
3315 event_header_field_type
=
3316 bt_ctf_field_type_structure_get_field_type_by_name(
3317 ret_field_type
, "id");
3318 ok(event_header_field_type
,
3319 "Default event header type contains an \"id\" field");
3320 ok(bt_ctf_field_type_get_type_id(
3321 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
3322 "Default event header \"id\" field is an integer");
3323 bt_put(event_header_field_type
);
3324 event_header_field_type
=
3325 bt_ctf_field_type_structure_get_field_type_by_name(
3326 ret_field_type
, "timestamp");
3327 ok(event_header_field_type
,
3328 "Default event header type contains a \"timestamp\" field");
3329 ok(bt_ctf_field_type_get_type_id(
3330 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
3331 "Default event header \"timestamp\" field is an integer");
3332 bt_put(event_header_field_type
);
3333 bt_put(ret_field_type
);
3335 /* Add a custom trace packet header field */
3336 ok(bt_ctf_trace_get_packet_header_type(NULL
) == NULL
,
3337 "bt_ctf_trace_get_packet_header_type handles NULL correctly");
3338 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
3339 ok(packet_header_type
,
3340 "bt_ctf_trace_get_packet_header_type returns a packet header");
3341 ok(bt_ctf_field_type_get_type_id(packet_header_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
3342 "bt_ctf_trace_get_packet_header_type returns a packet header of type struct");
3343 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
3344 packet_header_type
, "magic");
3345 ok(ret_field_type
, "Default packet header type contains a \"magic\" field");
3346 bt_put(ret_field_type
);
3347 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
3348 packet_header_type
, "uuid");
3349 ok(ret_field_type
, "Default packet header type contains a \"uuid\" field");
3350 bt_put(ret_field_type
);
3351 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
3352 packet_header_type
, "stream_id");
3353 ok(ret_field_type
, "Default packet header type contains a \"stream_id\" field");
3354 bt_put(ret_field_type
);
3356 packet_header_field_type
= bt_ctf_field_type_integer_create(22);
3357 ok(!bt_ctf_field_type_structure_add_field(packet_header_type
,
3358 packet_header_field_type
, "custom_trace_packet_header_field"),
3359 "Added a custom trace packet header field successfully");
3361 ok(bt_ctf_trace_set_packet_header_type(NULL
, packet_header_type
) < 0,
3362 "bt_ctf_trace_set_packet_header_type handles a NULL trace correctly");
3363 ok(!bt_ctf_trace_set_packet_header_type(trace
, packet_header_type
),
3364 "Set a trace packet_header_type successfully");
3366 ok(bt_ctf_stream_class_get_packet_context_type(NULL
) == NULL
,
3367 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
3369 /* Add a custom field to the stream class' packet context */
3370 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
3371 ok(packet_context_type
,
3372 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
3373 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
3374 "Packet context is a structure");
3376 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
3377 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
3379 integer_type
= bt_ctf_field_type_integer_create(32);
3380 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
3382 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
3383 /* Create a "uint5_t" equivalent custom packet context field */
3384 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
3386 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
3387 packet_context_field_type
, "custom_packet_context_field");
3388 ok(ret
== 0, "Packet context field added successfully");
3390 /* Define a stream event context containing a my_integer field. */
3391 ok(bt_ctf_stream_class_get_event_context_type(NULL
) == NULL
,
3392 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
3393 stream_event_context_type
= bt_ctf_field_type_structure_create();
3394 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
3395 integer_type
, "common_event_context");
3397 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
3398 stream_event_context_type
) < 0,
3399 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
3400 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
3402 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
3404 ok(bt_ctf_stream_class_set_event_context_type(
3405 stream_class
, stream_event_context_type
) == 0,
3406 "Set a new stream event context type");
3407 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
3409 ok(ret_field_type
== stream_event_context_type
,
3410 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
3411 bt_put(ret_field_type
);
3413 /* Instantiate a stream and append events */
3414 ret
= bt_ctf_writer_add_clock(writer
, clock
);
3416 ok(bt_ctf_trace_get_stream_count(trace
) == 0,
3417 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (0)");
3418 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
3419 ok(stream1
, "Instanciate a stream class from writer");
3420 ok(bt_ctf_trace_get_stream_count(trace
) == 1,
3421 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (1)");
3422 stream
= bt_ctf_trace_get_stream_by_index(trace
, 0);
3423 ok(stream
== stream1
,
3424 "bt_ctf_trace_get_stream_by_index() succeeds and returns the correct value");
3428 * Creating a stream through a writer adds the given stream
3429 * class to the writer's trace, thus registering the stream
3430 * class's clock to the trace.
3432 ok(bt_ctf_trace_get_clock_class_count(NULL
) < 0,
3433 "bt_ctf_trace_get_clock_class_count correctly handles NULL");
3434 ok(bt_ctf_trace_get_clock_class_count(trace
) == 1,
3435 "bt_ctf_trace_get_clock_class_count returns the correct number of clocks");
3436 ok(!bt_ctf_trace_get_clock_class_by_index(NULL
, 0),
3437 "bt_ctf_trace_get_clock_class correctly handles NULL");
3438 ok(!bt_ctf_trace_get_clock_class_by_index(trace
, 1),
3439 "bt_ctf_trace_get_clock_class correctly handles out of bound accesses");
3440 ret_clock_class
= bt_ctf_trace_get_clock_class_by_index(trace
, 0);
3441 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class
),
3442 bt_ctf_clock_get_name(clock
)) == 0,
3443 "bt_ctf_trace_get_clock_class returns the right clock instance");
3444 bt_put(ret_clock_class
);
3445 ok(!bt_ctf_trace_get_clock_class_by_name(trace
, NULL
),
3446 "bt_ctf_trace_get_clock_class_by_name correctly handles NULL (trace)");
3447 ok(!bt_ctf_trace_get_clock_class_by_name(NULL
, clock_name
),
3448 "bt_ctf_trace_get_clock_by_name correctly handles NULL (clock name)");
3449 ok(!bt_ctf_trace_get_clock_class_by_name(NULL
, NULL
),
3450 "bt_ctf_trace_get_clock_by_name correctly handles NULL (both)");
3451 ret_clock_class
= bt_ctf_trace_get_clock_class_by_name(trace
, clock_name
);
3452 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class
),
3453 bt_ctf_clock_get_name(clock
)) == 0,
3454 "bt_ctf_trace_get_clock_class returns the right clock instance");
3455 bt_put(ret_clock_class
);
3456 ok(!bt_ctf_trace_get_clock_class_by_name(trace
, "random"),
3457 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
3459 ok(bt_ctf_stream_get_class(NULL
) == NULL
,
3460 "bt_ctf_stream_get_class correctly handles NULL");
3461 ret_stream_class
= bt_ctf_stream_get_class(stream1
);
3462 ok(ret_stream_class
,
3463 "bt_ctf_stream_get_class returns a stream class");
3464 ok(ret_stream_class
== stream_class
,
3465 "Returned stream class is of the correct type");
3468 * Packet header, packet context, event header, and stream
3469 * event context types were copied for the resolving
3472 BT_PUT(packet_header_type
);
3473 BT_PUT(packet_context_type
);
3474 BT_PUT(stream_event_context_type
);
3475 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
3476 assert(packet_header_type
);
3477 packet_context_type
=
3478 bt_ctf_stream_class_get_packet_context_type(stream_class
);
3479 assert(packet_context_type
);
3480 stream_event_context_type
=
3481 bt_ctf_stream_class_get_event_context_type(stream_class
);
3482 assert(stream_event_context_type
);
3485 * Try to modify the packet context type after a stream has been
3488 ret
= bt_ctf_field_type_structure_add_field(packet_header_type
,
3489 packet_header_field_type
, "should_fail");
3491 "Trace packet header type can't be modified once a stream has been instanciated");
3494 * Try to modify the packet context type after a stream has been
3497 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
3498 packet_context_field_type
, "should_fail");
3500 "Packet context type can't be modified once a stream has been instanciated");
3503 * Try to modify the stream event context type after a stream has been
3506 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
3507 integer_type
, "should_fail");
3509 "Stream event context type can't be modified once a stream has been instanciated");
3511 /* Should fail after instanciating a stream (frozen) */
3512 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
3513 "Changes to a stream class that was already instantiated fail");
3515 /* Populate the custom packet header field only once for all tests */
3516 ok(bt_ctf_stream_get_packet_header(NULL
) == NULL
,
3517 "bt_ctf_stream_get_packet_header handles NULL correctly");
3518 packet_header
= bt_ctf_stream_get_packet_header(stream1
);
3520 "bt_ctf_stream_get_packet_header returns a packet header");
3521 ret_field_type
= bt_ctf_field_get_type(packet_header
);
3522 ok(ret_field_type
== packet_header_type
,
3523 "Stream returns a packet header of the appropriate type");
3524 bt_put(ret_field_type
);
3525 packet_header_field
= bt_ctf_field_structure_get_field(packet_header
,
3526 "custom_trace_packet_header_field");
3527 ok(packet_header_field
,
3528 "Packet header structure contains a custom field with the appropriate name");
3529 ret_field_type
= bt_ctf_field_get_type(packet_header_field
);
3530 ok(bt_ctf_field_type_compare(ret_field_type
, packet_header_field_type
) == 0,
3531 "Custom packet header field is of the expected type");
3532 ok(!bt_ctf_field_unsigned_integer_set_value(packet_header_field
,
3533 54321), "Set custom packet header value successfully");
3534 ok(bt_ctf_stream_set_packet_header(stream1
, NULL
) < 0,
3535 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
3536 ok(bt_ctf_stream_set_packet_header(NULL
, packet_header
) < 0,
3537 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
3538 ok(bt_ctf_stream_set_packet_header(stream1
, packet_header_field
) < 0,
3539 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
3540 ok(!bt_ctf_stream_set_packet_header(stream1
, packet_header
),
3541 "Successfully set a stream's packet header");
3543 ok(bt_ctf_writer_add_environment_field(writer
, "new_field", "test") == 0,
3544 "Add environment field to writer after stream creation");
3548 test_create_writer_vs_non_writer_mode();
3550 test_set_clock_non_writer_stream_class();
3552 test_instanciate_event_before_stream(writer
, clock
);
3554 append_simple_event(stream_class
, stream1
, clock
);
3556 packet_resize_test(stream_class
, stream1
, clock
);
3558 append_complex_event(stream_class
, stream1
, clock
);
3560 append_existing_event_class(stream_class
);
3562 test_empty_stream(writer
);
3564 test_custom_event_header_stream(writer
, clock
);
3566 test_static_trace();
3568 test_trace_is_static_listener();
3572 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
3573 ok(metadata_string
, "Get metadata string");
3575 bt_ctf_writer_flush_metadata(writer
);
3578 bt_put(ret_stream_class
);
3581 bt_put(packet_context_type
);
3582 bt_put(packet_context_field_type
);
3583 bt_put(integer_type
);
3584 bt_put(stream_event_context_type
);
3585 bt_put(ret_field_type
);
3586 bt_put(packet_header_type
);
3587 bt_put(packet_header_field_type
);
3588 bt_put(packet_header
);
3589 bt_put(packet_header_field
);
3591 free(metadata_string
);
3592 bt_put(stream_class
);
3594 validate_trace(argv
[1], trace_path
);
3596 //recursive_rmdir(trace_path);