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 event_class
= bt_ctf_event_class_create(complex_test_event_string
);
787 ok(event_class
, "Create an event class");
788 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
, ""),
789 "Reject addition of a field with an empty name to an event");
790 ok(bt_ctf_event_class_add_field(event_class
, NULL
, "an_integer"),
791 "Reject addition of a field with a NULL type to an event");
792 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
794 "Reject addition of a type with an illegal name to an event");
795 ok(bt_ctf_event_class_add_field(event_class
, uint_35_type
,
797 "Add field of type unsigned integer to an event");
798 ok(bt_ctf_event_class_add_field(event_class
, int_16_type
,
799 "int_16") == 0, "Add field of type signed integer to an event");
800 ok(bt_ctf_event_class_add_field(event_class
, complex_structure_type
,
801 "complex_structure") == 0,
802 "Add composite structure to an event");
804 ok(bt_ctf_event_class_get_name(NULL
) == NULL
,
805 "bt_ctf_event_class_get_name handles NULL correctly");
806 ret_string
= bt_ctf_event_class_get_name(event_class
);
807 ok(!strcmp(ret_string
, complex_test_event_string
),
808 "bt_ctf_event_class_get_name returns a correct name");
809 ok(bt_ctf_event_class_get_id(event_class
) < 0,
810 "bt_ctf_event_class_get_id returns a negative value when not set");
811 ok(bt_ctf_event_class_get_id(NULL
) < 0,
812 "bt_ctf_event_class_get_id handles NULL correctly");
813 ok(bt_ctf_event_class_set_id(NULL
, 42) < 0,
814 "bt_ctf_event_class_set_id handles NULL correctly");
815 ok(bt_ctf_event_class_set_id(event_class
, 42) == 0,
816 "Set an event class' id");
817 ok(bt_ctf_event_class_get_id(event_class
) == 42,
818 "bt_ctf_event_class_get_id returns the correct value");
820 /* Test event class attributes */
821 obj
= bt_value_integer_create_init(15);
823 ok(bt_ctf_event_class_set_attribute(NULL
, "id", obj
),
824 "bt_ctf_event_class_set_attribute handles a NULL event class correctly");
825 ok(bt_ctf_event_class_set_attribute(event_class
, NULL
, obj
),
826 "bt_ctf_event_class_set_attribute handles a NULL name correctly");
827 ok(bt_ctf_event_class_set_attribute(event_class
, "id", NULL
),
828 "bt_ctf_event_class_set_attribute handles a NULL value correctly");
829 assert(!bt_value_integer_set(obj
, -3));
830 ok(bt_ctf_event_class_set_attribute(event_class
, "id", obj
),
831 "bt_ctf_event_class_set_attribute fails with a negative \"id\" attribute");
832 assert(!bt_value_integer_set(obj
, 11));
833 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
834 ok(!ret
&& bt_ctf_event_class_get_id(event_class
) == 11,
835 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"id\" attribute");
836 ret
= bt_ctf_event_class_set_attribute(event_class
, "name", obj
);
837 ret
&= bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
);
839 "bt_ctf_event_class_set_attribute cannot set \"name\" or \"model.emf.uri\" to an integer value");
842 obj
= bt_value_integer_create_init(5);
844 ok(!bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
),
845 "bt_ctf_event_class_set_attribute succeeds in setting the \"loglevel\" attribute");
847 ok(!bt_ctf_event_class_get_attribute_value_by_name(NULL
, "loglevel"),
848 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL event class correctly");
849 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, NULL
),
850 "bt_ctf_event_class_get_attribute_value_by_name handles a NULL name correctly");
851 ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class
, "meow"),
852 "bt_ctf_event_class_get_attribute_value_by_name fails with a non-existing attribute name");
853 obj
= bt_ctf_event_class_get_attribute_value_by_name(event_class
,
856 ret
= bt_value_integer_get(obj
, &int64_value
);
857 ok(obj
&& !ret
&& int64_value
== 5,
858 "bt_ctf_event_class_get_attribute_value_by_name returns the correct value");
861 obj
= bt_value_string_create_init("nu name");
863 assert(!bt_ctf_event_class_set_attribute(event_class
, "name", obj
));
864 ret_string
= bt_ctf_event_class_get_name(event_class
);
865 ok(!strcmp(ret_string
, "nu name"),
866 "bt_ctf_event_class_set_attribute succeeds in replacing the existing \"name\" attribute");
867 ret
= bt_ctf_event_class_set_attribute(event_class
, "id", obj
);
868 ret
&= bt_ctf_event_class_set_attribute(event_class
, "loglevel", obj
);
870 "bt_ctf_event_class_set_attribute cannot set \"id\" or \"loglevel\" to a string value");
872 obj
= bt_value_string_create_init("http://kernel.org/");
874 assert(!bt_ctf_event_class_set_attribute(event_class
, "model.emf.uri", obj
));
877 ok(bt_ctf_event_class_get_attribute_count(NULL
),
878 "bt_ctf_event_class_get_attribute_count handles a NULL event class");
879 ok(bt_ctf_event_class_get_attribute_count(event_class
) == 4,
880 "bt_ctf_event_class_get_attribute_count returns the correct count");
881 ok(!bt_ctf_event_class_get_attribute_name_by_index(NULL
, 0),
882 "bt_ctf_event_class_get_attribute_name handles a NULL event class correctly");
883 ok(!bt_ctf_event_class_get_attribute_name_by_index(event_class
, 4),
884 "bt_ctf_event_class_get_attribute_name handles a too large index correctly");
885 ok(!bt_ctf_event_class_get_attribute_value_by_index(NULL
, 0),
886 "bt_ctf_event_class_get_attribute_value handles a NULL event class correctly");
887 ok(!bt_ctf_event_class_get_attribute_value_by_index(event_class
, 4),
888 "bt_ctf_event_class_get_attribute_value handles a too large index correctly");
890 memset(&attrs_count
, 0, sizeof(attrs_count
));
892 for (i
= 0; i
< 4; ++i
) {
893 ret_string
= bt_ctf_event_class_get_attribute_name_by_index(
895 obj
= bt_ctf_event_class_get_attribute_value_by_index(
897 assert(ret_string
&& obj
);
899 if (!strcmp(ret_string
, "id")) {
901 ok(bt_value_is_integer(obj
),
902 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
904 } else if (!strcmp(ret_string
, "name")) {
906 ok(bt_value_is_string(obj
),
907 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
909 } else if (!strcmp(ret_string
, "loglevel")) {
910 attrs_count
.loglevel
++;
911 ok(bt_value_is_integer(obj
),
912 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
914 } else if (!strcmp(ret_string
, "model.emf.uri")) {
915 attrs_count
.modelemfuri
++;
916 ok(bt_value_is_string(obj
),
917 "bt_ctf_event_class_get_attribute_value returns the correct type (\"%s\")",
920 attrs_count
.unknown
++;
926 ok(attrs_count
.unknown
== 0, "event class has no unknown attributes");
927 ok(attrs_count
.id
== 1 && attrs_count
.name
== 1 &&
928 attrs_count
.loglevel
== 1 && attrs_count
.modelemfuri
== 1,
929 "event class has one instance of each known attribute");
931 /* Add event class to the stream class */
932 ok(bt_ctf_stream_class_add_event_class(stream_class
, NULL
),
933 "Reject addition of NULL event class to a stream class");
934 ok(bt_ctf_stream_class_add_event_class(stream_class
,
935 event_class
) == 0, "Add an event class to stream class");
937 ok(bt_ctf_event_class_get_stream_class(NULL
) == NULL
,
938 "bt_ctf_event_class_get_stream_class handles NULL correctly");
939 ret_stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
940 ok(ret_stream_class
== stream_class
,
941 "bt_ctf_event_class_get_stream_class returns the correct stream class");
942 bt_put(ret_stream_class
);
944 ok(bt_ctf_event_class_get_payload_type_field_count(NULL
) < 0,
945 "bt_ctf_event_class_get_field_count handles NULL correctly");
946 ok(bt_ctf_event_class_get_payload_type_field_count(event_class
) == 3,
947 "bt_ctf_event_class_get_field_count returns a correct value");
949 ok(bt_ctf_event_class_get_payload_type_field_by_index(NULL
, &ret_string
,
950 &ret_field_type
, 0) < 0,
951 "bt_ctf_event_class_get_field handles a NULL event class correctly");
952 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, NULL
,
953 &ret_field_type
, 0) == 0,
954 "bt_ctf_event_class_get_field handles a NULL field name correctly");
955 bt_put(ret_field_type
);
956 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, &ret_string
,
958 "bt_ctf_event_class_get_field handles a NULL field type correctly");
959 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, &ret_string
,
960 &ret_field_type
, 42) < 0,
961 "bt_ctf_event_class_get_field handles an invalid index correctly");
962 ok(bt_ctf_event_class_get_payload_type_field_by_index(event_class
, &ret_string
,
963 &ret_field_type
, 0) == 0,
964 "bt_ctf_event_class_get_field returns a field");
965 ok(bt_ctf_field_type_compare(ret_field_type
, uint_35_type
) == 0,
966 "bt_ctf_event_class_get_field returns a correct field type");
967 bt_put(ret_field_type
);
968 ok(!strcmp(ret_string
, "uint_35"),
969 "bt_ctf_event_class_get_field returns a correct field name");
970 ok(bt_ctf_event_class_get_field_by_name(NULL
, "") == NULL
,
971 "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly");
972 ok(bt_ctf_event_class_get_field_by_name(event_class
, NULL
) == NULL
,
973 "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly");
974 ok(bt_ctf_event_class_get_field_by_name(event_class
, "truie") == NULL
,
975 "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly");
976 ret_field_type
= bt_ctf_event_class_get_field_by_name(event_class
,
977 "complex_structure");
978 ok(bt_ctf_field_type_compare(ret_field_type
, complex_structure_type
) == 0,
979 "bt_ctf_event_class_get_field_by_name returns a correct field type");
980 bt_put(ret_field_type
);
982 event
= bt_ctf_event_create(event_class
);
983 ok(event
, "Instanciate a complex event");
985 ok(bt_ctf_event_get_class(NULL
) == NULL
,
986 "bt_ctf_event_get_class handles NULL correctly");
987 ret_event_class
= bt_ctf_event_get_class(event
);
988 ok(ret_event_class
== event_class
,
989 "bt_ctf_event_get_class returns the correct event class");
990 bt_put(ret_event_class
);
992 uint_35_field
= bt_ctf_event_get_payload(event
, "uint_35");
993 if (!uint_35_field
) {
994 printf("uint_35_field is NULL\n");
997 ok(uint_35_field
, "Use bt_ctf_event_get_payload to get a field instance ");
998 bt_ctf_field_unsigned_integer_set_value(uint_35_field
, 0x0DDF00D);
999 ok(bt_ctf_field_unsigned_integer_get_value(NULL
, &ret_unsigned_int
) < 0,
1000 "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field.");
1001 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
, NULL
) < 0,
1002 "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value");
1003 ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field
,
1004 &ret_unsigned_int
) == 0,
1005 "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value");
1006 ok(ret_unsigned_int
== 0x0DDF00D,
1007 "bt_ctf_field_unsigned_integer_get_value returns the correct value");
1008 ok(bt_ctf_field_signed_integer_get_value(uint_35_field
,
1009 &ret_signed_int
) < 0,
1010 "bt_ctf_field_signed_integer_get_value fails on an unsigned field");
1011 bt_put(uint_35_field
);
1013 int_16_field
= bt_ctf_event_get_payload(event
, "int_16");
1014 bt_ctf_field_signed_integer_set_value(int_16_field
, -12345);
1015 ok(bt_ctf_field_signed_integer_get_value(NULL
, &ret_signed_int
) < 0,
1016 "bt_ctf_field_signed_integer_get_value properly handles a NULL field");
1017 ok(bt_ctf_field_signed_integer_get_value(int_16_field
, NULL
) < 0,
1018 "bt_ctf_field_signed_integer_get_value properly handles a NULL return value");
1019 ok(bt_ctf_field_signed_integer_get_value(int_16_field
,
1020 &ret_signed_int
) == 0,
1021 "bt_ctf_field_signed_integer_get_value succeeds after setting a value");
1022 ok(ret_signed_int
== -12345,
1023 "bt_ctf_field_signed_integer_get_value returns the correct value");
1024 ok(bt_ctf_field_unsigned_integer_get_value(int_16_field
,
1025 &ret_unsigned_int
) < 0,
1026 "bt_ctf_field_unsigned_integer_get_value fails on a signed field");
1027 bt_put(int_16_field
);
1029 complex_structure_field
= bt_ctf_event_get_payload(event
,
1030 "complex_structure");
1032 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 0) == NULL
,
1033 "bt_ctf_field_structure_get_field_by_index handles NULL correctly");
1034 ok(bt_ctf_field_structure_get_field_by_index(NULL
, 9) == NULL
,
1035 "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly");
1036 inner_structure_field
= bt_ctf_field_structure_get_field_by_index(
1037 complex_structure_field
, 3);
1038 ret_field_type
= bt_ctf_field_get_type(inner_structure_field
);
1039 bt_put(inner_structure_field
);
1040 ok(bt_ctf_field_type_compare(ret_field_type
, inner_structure_type
) == 0,
1041 "bt_ctf_field_structure_get_field_by_index returns a correct field");
1042 bt_put(ret_field_type
);
1044 inner_structure_field
= bt_ctf_field_structure_get_field(
1045 complex_structure_field
, "inner_structure");
1046 a_string_field
= bt_ctf_field_structure_get_field(
1047 complex_structure_field
, "a_string");
1048 enum_variant_field
= bt_ctf_field_structure_get_field(
1049 complex_structure_field
, "variant_selector");
1050 variant_field
= bt_ctf_field_structure_get_field(
1051 complex_structure_field
, "variant_value");
1052 uint_35_field
= bt_ctf_field_structure_get_field(
1053 inner_structure_field
, "seq_len");
1054 a_sequence_field
= bt_ctf_field_structure_get_field(
1055 inner_structure_field
, "a_sequence");
1056 an_array_field
= bt_ctf_field_structure_get_field(
1057 inner_structure_field
, "an_array");
1059 enum_container_field
= bt_ctf_field_enumeration_get_container(
1060 enum_variant_field
);
1061 bt_ctf_field_unsigned_integer_set_value(enum_container_field
, 1);
1062 int_16_field
= bt_ctf_field_variant_get_field(variant_field
,
1063 enum_variant_field
);
1064 bt_ctf_field_signed_integer_set_value(int_16_field
, -200);
1065 bt_put(int_16_field
);
1066 ok(!bt_ctf_field_string_get_value(a_string_field
),
1067 "bt_ctf_field_string_get_value returns NULL on an unset field");
1068 bt_ctf_field_string_set_value(a_string_field
,
1070 ok(!bt_ctf_field_string_get_value(NULL
),
1071 "bt_ctf_field_string_get_value correctly handles NULL");
1072 ok(bt_ctf_field_string_append(NULL
, "yeah"),
1073 "bt_ctf_field_string_append correctly handles a NULL string field");
1074 ok(bt_ctf_field_string_append(a_string_field
, NULL
),
1075 "bt_ctf_field_string_append correctly handles a NULL string value");
1076 ok(!bt_ctf_field_string_append(a_string_field
, test_string_2
),
1077 "bt_ctf_field_string_append succeeds");
1078 ok(bt_ctf_field_string_append_len(NULL
, "oh noes", 3),
1079 "bt_ctf_field_string_append_len correctly handles a NULL string field");
1080 ok(bt_ctf_field_string_append_len(a_string_field
, NULL
, 3),
1081 "bt_ctf_field_string_append_len correctly handles a NULL string value");
1082 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 5),
1083 "bt_ctf_field_string_append_len succeeds (append 5 characters)");
1084 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_4
, 10),
1085 "bt_ctf_field_string_append_len succeeds (append 4 characters)");
1086 ok(!bt_ctf_field_string_append_len(a_string_field
, &test_string_4
[4], 3),
1087 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
1088 ok(!bt_ctf_field_string_append_len(a_string_field
, test_string_3
, 0),
1089 "bt_ctf_field_string_append_len succeeds (append 0 characters)");
1091 ret_string
= bt_ctf_field_string_get_value(a_string_field
);
1092 ok(ret_string
, "bt_ctf_field_string_get_value returns a string");
1093 ok(ret_string
? !strcmp(ret_string
, test_string_cat
) : 0,
1094 "bt_ctf_field_string_get_value returns a correct value");
1095 bt_ctf_field_unsigned_integer_set_value(uint_35_field
,
1096 SEQUENCE_TEST_LENGTH
);
1098 ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL
,
1099 enum_container_field
) == NULL
,
1100 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly");
1101 ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type
,
1103 "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly");
1104 ret_field_type
= bt_ctf_field_type_variant_get_field_type_from_tag(
1105 variant_type
, enum_variant_field
);
1106 ok(ret_field_type
== int_16_type
,
1107 "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type");
1109 ok(bt_ctf_field_sequence_get_length(a_sequence_field
) == NULL
,
1110 "bt_ctf_field_sequence_get_length returns NULL when length is unset");
1111 ok(bt_ctf_field_sequence_set_length(a_sequence_field
,
1112 uint_35_field
) == 0, "Set a sequence field's length");
1113 ret_field
= bt_ctf_field_sequence_get_length(a_sequence_field
);
1114 ok(ret_field
== uint_35_field
,
1115 "bt_ctf_field_sequence_get_length returns the correct length field");
1116 ok(bt_ctf_field_sequence_get_length(NULL
) == NULL
,
1117 "bt_ctf_field_sequence_get_length properly handles NULL");
1119 for (i
= 0; i
< SEQUENCE_TEST_LENGTH
; i
++) {
1120 int_16_field
= bt_ctf_field_sequence_get_field(
1121 a_sequence_field
, i
);
1122 bt_ctf_field_signed_integer_set_value(int_16_field
, 4 - i
);
1123 bt_put(int_16_field
);
1126 for (i
= 0; i
< ARRAY_TEST_LENGTH
; i
++) {
1127 int_16_field
= bt_ctf_field_array_get_field(
1129 bt_ctf_field_signed_integer_set_value(int_16_field
, i
);
1130 bt_put(int_16_field
);
1133 stream_event_ctx_field
= bt_ctf_event_get_stream_event_context(event
);
1134 assert(stream_event_ctx_field
);
1135 stream_event_ctx_int_field
= bt_ctf_field_structure_get_field(
1136 stream_event_ctx_field
, "common_event_context");
1137 BT_PUT(stream_event_ctx_field
);
1138 bt_ctf_field_unsigned_integer_set_value(stream_event_ctx_int_field
, 17);
1139 BT_PUT(stream_event_ctx_int_field
);
1141 bt_ctf_clock_set_time(clock
, ++current_time
);
1142 ok(bt_ctf_stream_append_event(stream
, event
) == 0,
1143 "Append a complex event to a stream");
1146 * Populate the custom packet context field with a dummy value
1147 * otherwise flush will fail.
1149 packet_context
= bt_ctf_stream_get_packet_context(stream
);
1150 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
1151 "custom_packet_context_field");
1152 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 1);
1154 ok(bt_ctf_stream_flush(stream
) == 0,
1155 "Flush a stream containing a complex event");
1157 bt_put(uint_35_field
);
1158 bt_put(a_string_field
);
1159 bt_put(inner_structure_field
);
1160 bt_put(complex_structure_field
);
1161 bt_put(a_sequence_field
);
1162 bt_put(an_array_field
);
1163 bt_put(enum_variant_field
);
1164 bt_put(enum_container_field
);
1165 bt_put(variant_field
);
1167 bt_put(packet_context_field
);
1168 bt_put(packet_context
);
1169 bt_put(uint_35_type
);
1170 bt_put(int_16_type
);
1171 bt_put(string_type
);
1172 bt_put(sequence_type
);
1174 bt_put(inner_structure_type
);
1175 bt_put(complex_structure_type
);
1176 bt_put(uint_3_type
);
1177 bt_put(enum_variant_type
);
1178 bt_put(variant_type
);
1179 bt_put(ret_field_type
);
1180 bt_put(event_class
);
1185 void field_copy_tests_validate_same_type(struct bt_ctf_field
*field
,
1186 struct bt_ctf_field_type
*expected_type
, const char *name
)
1188 struct bt_ctf_field_type
*copy_type
;
1190 copy_type
= bt_ctf_field_get_type(field
);
1191 ok(copy_type
== expected_type
,
1192 "bt_ctf_field_copy does not copy the type (%s)", name
);
1197 void field_copy_tests_validate_diff_ptrs(struct bt_ctf_field
*field_a
,
1198 struct bt_ctf_field
*field_b
, const char *name
)
1200 ok(field_a
!= field_b
,
1201 "bt_ctf_field_copy creates different pointers (%s)", name
);
1205 void field_copy_tests()
1207 struct bt_ctf_field_type
*len_type
= NULL
;
1208 struct bt_ctf_field_type
*fp_type
= NULL
;
1209 struct bt_ctf_field_type
*s_type
= NULL
;
1210 struct bt_ctf_field_type
*e_int_type
= NULL
;
1211 struct bt_ctf_field_type
*e_type
= NULL
;
1212 struct bt_ctf_field_type
*v_type
= NULL
;
1213 struct bt_ctf_field_type
*v_label1_type
= NULL
;
1214 struct bt_ctf_field_type
*v_label1_array_type
= NULL
;
1215 struct bt_ctf_field_type
*v_label2_type
= NULL
;
1216 struct bt_ctf_field_type
*v_label2_seq_type
= NULL
;
1217 struct bt_ctf_field_type
*strct_type
= NULL
;
1218 struct bt_ctf_field
*len
= NULL
;
1219 struct bt_ctf_field
*fp
= NULL
;
1220 struct bt_ctf_field
*s
= NULL
;
1221 struct bt_ctf_field
*e_int
= NULL
;
1222 struct bt_ctf_field
*e
= NULL
;
1223 struct bt_ctf_field
*v
= NULL
;
1224 struct bt_ctf_field
*v_selected
= NULL
;
1225 struct bt_ctf_field
*v_selected_cur
= NULL
;
1226 struct bt_ctf_field
*v_selected_0
= NULL
;
1227 struct bt_ctf_field
*v_selected_1
= NULL
;
1228 struct bt_ctf_field
*v_selected_2
= NULL
;
1229 struct bt_ctf_field
*v_selected_3
= NULL
;
1230 struct bt_ctf_field
*v_selected_4
= NULL
;
1231 struct bt_ctf_field
*v_selected_5
= NULL
;
1232 struct bt_ctf_field
*v_selected_6
= NULL
;
1233 struct bt_ctf_field
*a
= NULL
;
1234 struct bt_ctf_field
*a_0
= NULL
;
1235 struct bt_ctf_field
*a_1
= NULL
;
1236 struct bt_ctf_field
*a_2
= NULL
;
1237 struct bt_ctf_field
*a_3
= NULL
;
1238 struct bt_ctf_field
*a_4
= NULL
;
1239 struct bt_ctf_field
*strct
= NULL
;
1240 struct bt_ctf_field
*len_copy
= NULL
;
1241 struct bt_ctf_field
*fp_copy
= NULL
;
1242 struct bt_ctf_field
*s_copy
= NULL
;
1243 struct bt_ctf_field
*e_int_copy
= NULL
;
1244 struct bt_ctf_field
*e_copy
= NULL
;
1245 struct bt_ctf_field
*v_copy
= NULL
;
1246 struct bt_ctf_field
*v_selected_copy
= NULL
;
1247 struct bt_ctf_field
*v_selected_copy_len
= NULL
;
1248 struct bt_ctf_field
*v_selected_0_copy
= NULL
;
1249 struct bt_ctf_field
*v_selected_1_copy
= NULL
;
1250 struct bt_ctf_field
*v_selected_2_copy
= NULL
;
1251 struct bt_ctf_field
*v_selected_3_copy
= NULL
;
1252 struct bt_ctf_field
*v_selected_4_copy
= NULL
;
1253 struct bt_ctf_field
*v_selected_5_copy
= NULL
;
1254 struct bt_ctf_field
*v_selected_6_copy
= NULL
;
1255 struct bt_ctf_field
*a_copy
= NULL
;
1256 struct bt_ctf_field
*a_0_copy
= NULL
;
1257 struct bt_ctf_field
*a_1_copy
= NULL
;
1258 struct bt_ctf_field
*a_2_copy
= NULL
;
1259 struct bt_ctf_field
*a_3_copy
= NULL
;
1260 struct bt_ctf_field
*a_4_copy
= NULL
;
1261 struct bt_ctf_field
*strct_copy
= NULL
;
1262 struct bt_ctf_field_type_enumeration_mapping_iterator
*e_iter
= NULL
;
1263 uint64_t uint64_t_val
;
1264 const char *str_val
;
1268 /* create len type */
1269 len_type
= bt_ctf_field_type_integer_create(32);
1272 /* create fp type */
1273 fp_type
= bt_ctf_field_type_floating_point_create();
1277 s_type
= bt_ctf_field_type_string_create();
1280 /* create e_int type */
1281 e_int_type
= bt_ctf_field_type_integer_create(8);
1285 e_type
= bt_ctf_field_type_enumeration_create(e_int_type
);
1287 ret
= bt_ctf_field_type_enumeration_add_mapping(e_type
, "LABEL1",
1290 ret
= bt_ctf_field_type_enumeration_add_mapping(e_type
, "LABEL2",
1294 /* create v_label1 type */
1295 v_label1_type
= bt_ctf_field_type_string_create();
1296 assert(v_label1_type
);
1298 /* create v_label1_array type */
1299 v_label1_array_type
= bt_ctf_field_type_array_create(v_label1_type
, 5);
1300 assert(v_label1_array_type
);
1302 /* create v_label2 type */
1303 v_label2_type
= bt_ctf_field_type_integer_create(16);
1304 assert(v_label2_type
);
1306 /* create v_label2_seq type */
1307 v_label2_seq_type
= bt_ctf_field_type_sequence_create(v_label2_type
,
1309 assert(v_label2_seq_type
);
1312 v_type
= bt_ctf_field_type_variant_create(e_type
, "e");
1314 ret
= bt_ctf_field_type_variant_add_field(v_type
, v_label1_array_type
,
1317 ret
= bt_ctf_field_type_variant_add_field(v_type
, v_label2_seq_type
,
1321 /* create strct type */
1322 strct_type
= bt_ctf_field_type_structure_create();
1324 ret
= bt_ctf_field_type_structure_add_field(strct_type
, len_type
,
1327 ret
= bt_ctf_field_type_structure_add_field(strct_type
, fp_type
, "fp");
1329 ret
= bt_ctf_field_type_structure_add_field(strct_type
, s_type
, "s");
1331 ret
= bt_ctf_field_type_structure_add_field(strct_type
, e_type
, "e");
1333 ret
= bt_ctf_field_type_structure_add_field(strct_type
, v_type
, "v");
1335 ret
= bt_ctf_field_type_structure_add_field(strct_type
,
1336 v_label1_array_type
, "a");
1340 strct
= bt_ctf_field_create(strct_type
);
1344 len
= bt_ctf_field_structure_get_field(strct
, "len");
1348 fp
= bt_ctf_field_structure_get_field(strct
, "fp");
1352 s
= bt_ctf_field_structure_get_field(strct
, "s");
1356 e
= bt_ctf_field_structure_get_field(strct
, "e");
1359 /* get e_int (underlying integer) */
1360 e_int
= bt_ctf_field_enumeration_get_container(e
);
1364 v
= bt_ctf_field_structure_get_field(strct
, "v");
1368 a
= bt_ctf_field_structure_get_field(strct
, "a");
1372 ret
= bt_ctf_field_unsigned_integer_set_value(len
, 7);
1376 ret
= bt_ctf_field_floating_point_set_value(fp
, 3.14);
1380 ret
= bt_ctf_field_string_set_value(s
, "btbt");
1383 /* set e field (LABEL2) */
1384 ret
= bt_ctf_field_unsigned_integer_set_value(e_int
, 23);
1388 v_selected
= bt_ctf_field_variant_get_field(v
, e
);
1390 ok(!bt_ctf_field_variant_get_current_field(NULL
),
1391 "bt_ctf_field_variant_get_current_field handles NULL correctly");
1392 v_selected_cur
= bt_ctf_field_variant_get_current_field(v
);
1393 ok(v_selected_cur
== v_selected
,
1394 "bt_ctf_field_variant_get_current_field returns the current field");
1395 bt_put(v_selected_cur
);
1397 /* set selected v field */
1398 ret
= bt_ctf_field_sequence_set_length(v_selected
, len
);
1400 v_selected_0
= bt_ctf_field_sequence_get_field(v_selected
, 0);
1401 assert(v_selected_0
);
1402 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_0
, 7);
1404 v_selected_1
= bt_ctf_field_sequence_get_field(v_selected
, 1);
1405 assert(v_selected_1
);
1406 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_1
, 6);
1408 v_selected_2
= bt_ctf_field_sequence_get_field(v_selected
, 2);
1409 assert(v_selected_2
);
1410 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_2
, 5);
1412 v_selected_3
= bt_ctf_field_sequence_get_field(v_selected
, 3);
1413 assert(v_selected_3
);
1414 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_3
, 4);
1416 v_selected_4
= bt_ctf_field_sequence_get_field(v_selected
, 4);
1417 assert(v_selected_4
);
1418 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_4
, 3);
1420 v_selected_5
= bt_ctf_field_sequence_get_field(v_selected
, 5);
1421 assert(v_selected_5
);
1422 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_5
, 2);
1424 v_selected_6
= bt_ctf_field_sequence_get_field(v_selected
, 6);
1425 assert(v_selected_6
);
1426 ret
= bt_ctf_field_unsigned_integer_set_value(v_selected_6
, 1);
1430 a_0
= bt_ctf_field_array_get_field(a
, 0);
1432 ret
= bt_ctf_field_string_set_value(a_0
, "a_0");
1434 a_1
= bt_ctf_field_array_get_field(a
, 1);
1436 ret
= bt_ctf_field_string_set_value(a_1
, "a_1");
1438 a_2
= bt_ctf_field_array_get_field(a
, 2);
1440 ret
= bt_ctf_field_string_set_value(a_2
, "a_2");
1442 a_3
= bt_ctf_field_array_get_field(a
, 3);
1444 ret
= bt_ctf_field_string_set_value(a_3
, "a_3");
1446 a_4
= bt_ctf_field_array_get_field(a
, 4);
1448 ret
= bt_ctf_field_string_set_value(a_4
, "a_4");
1451 /* create copy of strct */
1452 ok(!bt_ctf_field_copy(NULL
),
1453 "bt_ctf_field_copy handles NULL correctly");
1454 strct_copy
= bt_ctf_field_copy(strct
);
1456 "bt_ctf_field_copy returns a valid pointer");
1458 /* get all copied fields */
1459 len_copy
= bt_ctf_field_structure_get_field(strct_copy
, "len");
1461 fp_copy
= bt_ctf_field_structure_get_field(strct_copy
, "fp");
1463 s_copy
= bt_ctf_field_structure_get_field(strct_copy
, "s");
1465 e_copy
= bt_ctf_field_structure_get_field(strct_copy
, "e");
1467 e_int_copy
= bt_ctf_field_enumeration_get_container(e_copy
);
1469 v_copy
= bt_ctf_field_structure_get_field(strct_copy
, "v");
1471 v_selected_copy
= bt_ctf_field_variant_get_field(v_copy
, e_copy
);
1472 assert(v_selected_copy
);
1473 v_selected_0_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 0);
1474 assert(v_selected_0_copy
);
1475 v_selected_1_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 1);
1476 assert(v_selected_1_copy
);
1477 v_selected_2_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 2);
1478 assert(v_selected_2_copy
);
1479 v_selected_3_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 3);
1480 assert(v_selected_3_copy
);
1481 v_selected_4_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 4);
1482 assert(v_selected_4_copy
);
1483 v_selected_5_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 5);
1484 assert(v_selected_5_copy
);
1485 v_selected_6_copy
= bt_ctf_field_sequence_get_field(v_selected_copy
, 6);
1486 assert(v_selected_6_copy
);
1487 ok(!bt_ctf_field_sequence_get_field(v_selected_copy
, 7),
1488 "sequence field copy is not too large");
1489 a_copy
= bt_ctf_field_structure_get_field(strct_copy
, "a");
1491 a_0_copy
= bt_ctf_field_array_get_field(a_copy
, 0);
1493 a_1_copy
= bt_ctf_field_array_get_field(a_copy
, 1);
1495 a_2_copy
= bt_ctf_field_array_get_field(a_copy
, 2);
1497 a_3_copy
= bt_ctf_field_array_get_field(a_copy
, 3);
1499 a_4_copy
= bt_ctf_field_array_get_field(a_copy
, 4);
1501 ok(!bt_ctf_field_array_get_field(v_selected_copy
, 5),
1502 "array field copy is not too large");
1504 /* make sure copied fields are different pointers */
1505 field_copy_tests_validate_diff_ptrs(strct_copy
, strct
, "strct");
1506 field_copy_tests_validate_diff_ptrs(len_copy
, len
, "len");
1507 field_copy_tests_validate_diff_ptrs(fp_copy
, fp
, "fp");
1508 field_copy_tests_validate_diff_ptrs(s_copy
, s
, "s");
1509 field_copy_tests_validate_diff_ptrs(e_int_copy
, e_int
, "e_int");
1510 field_copy_tests_validate_diff_ptrs(e_copy
, e
, "e");
1511 field_copy_tests_validate_diff_ptrs(v_copy
, v
, "v");
1512 field_copy_tests_validate_diff_ptrs(v_selected_copy
, v_selected
,
1514 field_copy_tests_validate_diff_ptrs(v_selected_0_copy
, v_selected_0
,
1516 field_copy_tests_validate_diff_ptrs(v_selected_1_copy
, v_selected_1
,
1518 field_copy_tests_validate_diff_ptrs(v_selected_2_copy
, v_selected_2
,
1520 field_copy_tests_validate_diff_ptrs(v_selected_3_copy
, v_selected_3
,
1522 field_copy_tests_validate_diff_ptrs(v_selected_4_copy
, v_selected_4
,
1524 field_copy_tests_validate_diff_ptrs(v_selected_5_copy
, v_selected_5
,
1526 field_copy_tests_validate_diff_ptrs(v_selected_6_copy
, v_selected_6
,
1528 field_copy_tests_validate_diff_ptrs(a_copy
, a
, "a");
1529 field_copy_tests_validate_diff_ptrs(a_0_copy
, a_0
, "a_0");
1530 field_copy_tests_validate_diff_ptrs(a_1_copy
, a_1
, "a_1");
1531 field_copy_tests_validate_diff_ptrs(a_2_copy
, a_2
, "a_2");
1532 field_copy_tests_validate_diff_ptrs(a_3_copy
, a_3
, "a_3");
1533 field_copy_tests_validate_diff_ptrs(a_4_copy
, a_4
, "a_4");
1535 /* make sure copied fields share the same types */
1536 field_copy_tests_validate_same_type(strct_copy
, strct_type
, "strct");
1537 field_copy_tests_validate_same_type(len_copy
, len_type
, "len");
1538 field_copy_tests_validate_same_type(fp_copy
, fp_type
, "fp");
1539 field_copy_tests_validate_same_type(e_int_copy
, e_int_type
, "e_int");
1540 field_copy_tests_validate_same_type(e_copy
, e_type
, "e");
1541 field_copy_tests_validate_same_type(v_copy
, v_type
, "v");
1542 field_copy_tests_validate_same_type(v_selected_copy
, v_label2_seq_type
,
1544 field_copy_tests_validate_same_type(v_selected_0_copy
, v_label2_type
,
1546 field_copy_tests_validate_same_type(v_selected_1_copy
, v_label2_type
,
1548 field_copy_tests_validate_same_type(v_selected_2_copy
, v_label2_type
,
1550 field_copy_tests_validate_same_type(v_selected_3_copy
, v_label2_type
,
1552 field_copy_tests_validate_same_type(v_selected_4_copy
, v_label2_type
,
1554 field_copy_tests_validate_same_type(v_selected_5_copy
, v_label2_type
,
1556 field_copy_tests_validate_same_type(v_selected_6_copy
, v_label2_type
,
1558 field_copy_tests_validate_same_type(a_copy
, v_label1_array_type
, "a");
1559 field_copy_tests_validate_same_type(a_0_copy
, v_label1_type
, "a_0");
1560 field_copy_tests_validate_same_type(a_1_copy
, v_label1_type
, "a_1");
1561 field_copy_tests_validate_same_type(a_2_copy
, v_label1_type
, "a_2");
1562 field_copy_tests_validate_same_type(a_3_copy
, v_label1_type
, "a_3");
1563 field_copy_tests_validate_same_type(a_4_copy
, v_label1_type
, "a_4");
1565 /* validate len copy */
1566 ret
= bt_ctf_field_unsigned_integer_get_value(len_copy
, &uint64_t_val
);
1568 ok(uint64_t_val
== 7,
1569 "bt_ctf_field_copy creates a valid integer field copy");
1571 /* validate fp copy */
1572 ret
= bt_ctf_field_floating_point_get_value(fp_copy
, &double_val
);
1574 ok(double_val
== 3.14,
1575 "bt_ctf_field_copy creates a valid floating point number field copy");
1577 /* validate s copy */
1578 str_val
= bt_ctf_field_string_get_value(s_copy
);
1579 ok(str_val
&& !strcmp(str_val
, "btbt"),
1580 "bt_ctf_field_copy creates a valid string field copy");
1582 /* validate e_int copy */
1583 ret
= bt_ctf_field_unsigned_integer_get_value(e_int_copy
,
1586 ok(uint64_t_val
== 23,
1587 "bt_ctf_field_copy creates a valid enum's integer field copy");
1589 /* validate e copy */
1590 e_iter
= bt_ctf_field_enumeration_get_mappings(e_copy
);
1591 (void) bt_ctf_field_type_enumeration_mapping_iterator_get_signed(e_iter
,
1592 &str_val
, NULL
, NULL
);
1593 ok(str_val
&& !strcmp(str_val
, "LABEL2"),
1594 "bt_ctf_field_copy creates a valid enum field copy");
1596 /* validate v_selected copy */
1597 v_selected_copy_len
= bt_ctf_field_sequence_get_length(v_selected
);
1598 assert(v_selected_copy_len
);
1599 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_copy_len
,
1602 ok(uint64_t_val
== 7,
1603 "bt_ctf_field_copy creates a sequence field copy with the proper length");
1604 bt_put(v_selected_copy_len
);
1605 v_selected_copy_len
= NULL
;
1607 /* validate v_selected copy fields */
1608 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_0_copy
,
1611 ok(uint64_t_val
== 7,
1612 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_0)");
1613 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_1_copy
,
1616 ok(uint64_t_val
== 6,
1617 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_1)");
1618 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_2_copy
,
1621 ok(uint64_t_val
== 5,
1622 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_2)");
1623 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_3_copy
,
1626 ok(uint64_t_val
== 4,
1627 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_3)");
1628 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_4_copy
,
1631 ok(uint64_t_val
== 3,
1632 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_4)");
1633 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_5_copy
,
1636 ok(uint64_t_val
== 2,
1637 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_5)");
1638 ret
= bt_ctf_field_unsigned_integer_get_value(v_selected_6_copy
,
1641 ok(uint64_t_val
== 1,
1642 "bt_ctf_field_copy creates a valid sequence field element copy (v_selected_6)");
1644 /* validate a copy fields */
1645 str_val
= bt_ctf_field_string_get_value(a_0_copy
);
1646 ok(str_val
&& !strcmp(str_val
, "a_0"),
1647 "bt_ctf_field_copy creates a valid array field element copy (a_0)");
1648 str_val
= bt_ctf_field_string_get_value(a_1_copy
);
1649 ok(str_val
&& !strcmp(str_val
, "a_1"),
1650 "bt_ctf_field_copy creates a valid array field element copy (a_1)");
1651 str_val
= bt_ctf_field_string_get_value(a_2_copy
);
1652 ok(str_val
&& !strcmp(str_val
, "a_2"),
1653 "bt_ctf_field_copy creates a valid array field element copy (a_2)");
1654 str_val
= bt_ctf_field_string_get_value(a_3_copy
);
1655 ok(str_val
&& !strcmp(str_val
, "a_3"),
1656 "bt_ctf_field_copy creates a valid array field element copy (a_3)");
1657 str_val
= bt_ctf_field_string_get_value(a_4_copy
);
1658 ok(str_val
&& !strcmp(str_val
, "a_4"),
1659 "bt_ctf_field_copy creates a valid array field element copy (a_4)");
1661 /* put everything */
1668 bt_put(v_label1_type
);
1669 bt_put(v_label1_array_type
);
1670 bt_put(v_label2_type
);
1671 bt_put(v_label2_seq_type
);
1680 bt_put(v_selected_0
);
1681 bt_put(v_selected_1
);
1682 bt_put(v_selected_2
);
1683 bt_put(v_selected_3
);
1684 bt_put(v_selected_4
);
1685 bt_put(v_selected_5
);
1686 bt_put(v_selected_6
);
1700 bt_put(v_selected_copy
);
1701 bt_put(v_selected_0_copy
);
1702 bt_put(v_selected_1_copy
);
1703 bt_put(v_selected_2_copy
);
1704 bt_put(v_selected_3_copy
);
1705 bt_put(v_selected_4_copy
);
1706 bt_put(v_selected_5_copy
);
1707 bt_put(v_selected_6_copy
);
1719 void type_field_tests()
1721 struct bt_ctf_field
*uint_12
;
1722 struct bt_ctf_field
*int_16
;
1723 struct bt_ctf_field
*string
;
1724 struct bt_ctf_field
*enumeration
;
1725 struct bt_ctf_field_type
*composite_structure_type
;
1726 struct bt_ctf_field_type
*structure_seq_type
;
1727 struct bt_ctf_field_type
*string_type
;
1728 struct bt_ctf_field_type
*sequence_type
;
1729 struct bt_ctf_field_type
*uint_8_type
;
1730 struct bt_ctf_field_type
*int_16_type
;
1731 struct bt_ctf_field_type
*uint_12_type
=
1732 bt_ctf_field_type_integer_create(12);
1733 struct bt_ctf_field_type
*enumeration_type
;
1734 struct bt_ctf_field_type
*returned_type
;
1735 const char *ret_string
;
1737 returned_type
= bt_ctf_field_get_type(NULL
);
1738 ok(!returned_type
, "bt_ctf_field_get_type handles NULL correctly");
1740 ok(uint_12_type
, "Create an unsigned integer type");
1741 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1742 BT_CTF_INTEGER_BASE_BINARY
) == 0,
1743 "Set integer type's base as binary");
1744 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1745 BT_CTF_INTEGER_BASE_DECIMAL
) == 0,
1746 "Set integer type's base as decimal");
1747 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1748 BT_CTF_INTEGER_BASE_UNKNOWN
),
1749 "Reject integer type's base set as unknown");
1750 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1751 BT_CTF_INTEGER_BASE_OCTAL
) == 0,
1752 "Set integer type's base as octal");
1753 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1754 BT_CTF_INTEGER_BASE_HEXADECIMAL
) == 0,
1755 "Set integer type's base as hexadecimal");
1756 ok(bt_ctf_field_type_integer_set_base(uint_12_type
, 457417),
1757 "Reject unknown integer base value");
1758 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 952835) == 0,
1759 "Set integer type signedness to signed");
1760 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0) == 0,
1761 "Set integer type signedness to unsigned");
1762 ok(bt_ctf_field_type_integer_get_size(NULL
) < 0,
1763 "bt_ctf_field_type_integer_get_size handles NULL correctly");
1764 ok(bt_ctf_field_type_integer_get_size(uint_12_type
) == 12,
1765 "bt_ctf_field_type_integer_get_size returns a correct value");
1766 ok(bt_ctf_field_type_integer_get_signed(NULL
) < 0,
1767 "bt_ctf_field_type_integer_get_signed handles NULL correctly");
1768 ok(bt_ctf_field_type_integer_get_signed(uint_12_type
) == 0,
1769 "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types");
1771 ok(bt_ctf_field_type_set_byte_order(NULL
,
1772 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) < 0,
1773 "bt_ctf_field_type_set_byte_order handles NULL correctly");
1774 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1775 (enum bt_ctf_byte_order
) 42) < 0,
1776 "bt_ctf_field_type_set_byte_order rejects invalid values");
1777 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1778 BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
) == 0,
1779 "Set an integer's byte order to little endian");
1780 ok(bt_ctf_field_type_set_byte_order(uint_12_type
,
1781 BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
1782 "Set an integer's byte order to big endian");
1783 ok(bt_ctf_field_type_get_byte_order(uint_12_type
) ==
1784 BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
1785 "bt_ctf_field_type_get_byte_order returns a correct value");
1786 ok(bt_ctf_field_type_get_byte_order(NULL
) ==
1787 BT_CTF_BYTE_ORDER_UNKNOWN
,
1788 "bt_ctf_field_type_get_byte_order handles NULL correctly");
1790 ok(bt_ctf_field_type_get_type_id(NULL
) ==
1791 BT_CTF_FIELD_TYPE_ID_UNKNOWN
,
1792 "bt_ctf_field_type_get_type_id handles NULL correctly");
1793 ok(bt_ctf_field_type_get_type_id(uint_12_type
) ==
1794 BT_CTF_FIELD_TYPE_ID_INTEGER
,
1795 "bt_ctf_field_type_get_type_id returns a correct value with an integer type");
1797 ok(bt_ctf_field_type_integer_get_base(NULL
) ==
1798 BT_CTF_INTEGER_BASE_UNKNOWN
,
1799 "bt_ctf_field_type_integer_get_base handles NULL correctly");
1800 ok(bt_ctf_field_type_integer_get_base(uint_12_type
) ==
1801 BT_CTF_INTEGER_BASE_HEXADECIMAL
,
1802 "bt_ctf_field_type_integer_get_base returns a correct value");
1804 ok(bt_ctf_field_type_integer_set_encoding(NULL
,
1805 BT_CTF_STRING_ENCODING_ASCII
) < 0,
1806 "bt_ctf_field_type_integer_set_encoding handles NULL correctly");
1807 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1808 (enum bt_ctf_string_encoding
) 123) < 0,
1809 "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly");
1810 ok(bt_ctf_field_type_integer_set_encoding(uint_12_type
,
1811 BT_CTF_STRING_ENCODING_UTF8
) == 0,
1812 "Set integer type encoding to UTF8");
1813 ok(bt_ctf_field_type_integer_get_encoding(NULL
) ==
1814 BT_CTF_STRING_ENCODING_UNKNOWN
,
1815 "bt_ctf_field_type_integer_get_encoding handles NULL correctly");
1816 ok(bt_ctf_field_type_integer_get_encoding(uint_12_type
) ==
1817 BT_CTF_STRING_ENCODING_UTF8
,
1818 "bt_ctf_field_type_integer_get_encoding returns a correct value");
1820 int_16_type
= bt_ctf_field_type_integer_create(16);
1821 assert(int_16_type
);
1822 ok(!bt_ctf_field_type_integer_set_signed(int_16_type
, 1),
1823 "Set signedness of 16 bit integer to true");
1824 ok(bt_ctf_field_type_integer_get_signed(int_16_type
) == 1,
1825 "bt_ctf_field_type_integer_get_signed returns a correct value for signed types");
1826 uint_8_type
= bt_ctf_field_type_integer_create(8);
1828 bt_ctf_field_type_sequence_create(int_16_type
, "seq_len");
1829 ok(sequence_type
, "Create a sequence of int16_t type");
1830 ok(bt_ctf_field_type_get_type_id(sequence_type
) ==
1831 BT_CTF_FIELD_TYPE_ID_SEQUENCE
,
1832 "bt_ctf_field_type_get_type_id returns a correct value with a sequence type");
1834 ok(bt_ctf_field_type_sequence_get_length_field_name(NULL
) == NULL
,
1835 "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly");
1836 ret_string
= bt_ctf_field_type_sequence_get_length_field_name(
1838 ok(!strcmp(ret_string
, "seq_len"),
1839 "bt_ctf_field_type_sequence_get_length_field_name returns the correct value");
1840 ok(bt_ctf_field_type_sequence_get_element_type(NULL
) == NULL
,
1841 "bt_ctf_field_type_sequence_get_element_type handles NULL correctly");
1842 returned_type
= bt_ctf_field_type_sequence_get_element_type(
1844 ok(returned_type
== int_16_type
,
1845 "bt_ctf_field_type_sequence_get_element_type returns the correct type");
1846 bt_put(returned_type
);
1848 string_type
= bt_ctf_field_type_string_create();
1849 ok(string_type
, "Create a string type");
1850 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1851 BT_CTF_STRING_ENCODING_NONE
),
1852 "Reject invalid \"None\" string encoding");
1853 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1855 "Reject invalid string encoding");
1856 ok(bt_ctf_field_type_string_set_encoding(string_type
,
1857 BT_CTF_STRING_ENCODING_ASCII
) == 0,
1858 "Set string encoding to ASCII");
1860 ok(bt_ctf_field_type_string_get_encoding(NULL
) ==
1861 BT_CTF_STRING_ENCODING_UNKNOWN
,
1862 "bt_ctf_field_type_string_get_encoding handles NULL correctly");
1863 ok(bt_ctf_field_type_string_get_encoding(string_type
) ==
1864 BT_CTF_STRING_ENCODING_ASCII
,
1865 "bt_ctf_field_type_string_get_encoding returns the correct value");
1867 structure_seq_type
= bt_ctf_field_type_structure_create();
1868 ok(bt_ctf_field_type_get_type_id(structure_seq_type
) ==
1869 BT_CTF_FIELD_TYPE_ID_STRUCT
,
1870 "bt_ctf_field_type_get_type_id returns a correct value with a structure type");
1871 ok(structure_seq_type
, "Create a structure type");
1872 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1873 uint_8_type
, "seq_len") == 0,
1874 "Add a uint8_t type to a structure");
1875 ok(bt_ctf_field_type_structure_add_field(structure_seq_type
,
1876 sequence_type
, "a_sequence") == 0,
1877 "Add a sequence type to a structure");
1879 ok(bt_ctf_field_type_structure_get_field_count(NULL
) < 0,
1880 "bt_ctf_field_type_structure_get_field_count handles NULL correctly");
1881 ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type
) == 2,
1882 "bt_ctf_field_type_structure_get_field_count returns a correct value");
1884 ok(bt_ctf_field_type_structure_get_field(NULL
,
1885 &ret_string
, &returned_type
, 1) < 0,
1886 "bt_ctf_field_type_structure_get_field handles a NULL type correctly");
1887 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1888 NULL
, &returned_type
, 1) == 0,
1889 "bt_ctf_field_type_structure_get_field handles a NULL name correctly");
1890 bt_put(returned_type
);
1891 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1892 &ret_string
, NULL
, 1) == 0,
1893 "bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
1894 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1895 &ret_string
, &returned_type
, 10) < 0,
1896 "bt_ctf_field_type_structure_get_field handles an invalid index correctly");
1897 ok(bt_ctf_field_type_structure_get_field(structure_seq_type
,
1898 &ret_string
, &returned_type
, 1) == 0,
1899 "bt_ctf_field_type_structure_get_field returns a field");
1900 ok(!strcmp(ret_string
, "a_sequence"),
1901 "bt_ctf_field_type_structure_get_field returns a correct field name");
1902 ok(returned_type
== sequence_type
,
1903 "bt_ctf_field_type_structure_get_field returns a correct field type");
1904 bt_put(returned_type
);
1906 ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL
, "a_sequence") == NULL
,
1907 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly");
1908 ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type
, NULL
) == NULL
,
1909 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1910 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1911 structure_seq_type
, "a_sequence");
1912 ok(returned_type
== sequence_type
,
1913 "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type");
1914 bt_put(returned_type
);
1916 composite_structure_type
= bt_ctf_field_type_structure_create();
1917 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1918 string_type
, "a_string") == 0,
1919 "Add a string type to a structure");
1920 ok(bt_ctf_field_type_structure_add_field(composite_structure_type
,
1921 structure_seq_type
, "inner_structure") == 0,
1922 "Add a structure type to a structure");
1924 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1925 NULL
, "a_sequence") == NULL
,
1926 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly");
1927 ok(bt_ctf_field_type_structure_get_field_type_by_name(
1928 structure_seq_type
, NULL
) == NULL
,
1929 "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly");
1930 returned_type
= bt_ctf_field_type_structure_get_field_type_by_name(
1931 structure_seq_type
, "a_sequence");
1932 ok(returned_type
== sequence_type
,
1933 "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type");
1934 bt_put(returned_type
);
1936 int_16
= bt_ctf_field_create(int_16_type
);
1937 ok(int_16
, "Instanciate a signed 16-bit integer");
1938 uint_12
= bt_ctf_field_create(uint_12_type
);
1939 ok(uint_12
, "Instanciate an unsigned 12-bit integer");
1940 returned_type
= bt_ctf_field_get_type(int_16
);
1941 ok(returned_type
== int_16_type
,
1942 "bt_ctf_field_get_type returns the correct type");
1944 /* Can't modify types after instanciating them */
1945 ok(bt_ctf_field_type_integer_set_base(uint_12_type
,
1946 BT_CTF_INTEGER_BASE_DECIMAL
),
1947 "Check an integer type' base can't be modified after instanciation");
1948 ok(bt_ctf_field_type_integer_set_signed(uint_12_type
, 0),
1949 "Check an integer type's signedness can't be modified after instanciation");
1951 /* Check signed property is checked */
1952 ok(bt_ctf_field_signed_integer_set_value(uint_12
, -52),
1953 "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer");
1954 ok(bt_ctf_field_unsigned_integer_set_value(int_16
, 42),
1955 "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer");
1957 /* Check overflows are properly tested for */
1958 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32768) == 0,
1959 "Check -32768 is allowed for a signed 16-bit integer");
1960 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32767) == 0,
1961 "Check 32767 is allowed for a signed 16-bit integer");
1962 ok(bt_ctf_field_signed_integer_set_value(int_16
, 32768),
1963 "Check 32768 is not allowed for a signed 16-bit integer");
1964 ok(bt_ctf_field_signed_integer_set_value(int_16
, -32769),
1965 "Check -32769 is not allowed for a signed 16-bit integer");
1966 ok(bt_ctf_field_signed_integer_set_value(int_16
, -42) == 0,
1967 "Check -42 is allowed for a signed 16-bit integer");
1969 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4095) == 0,
1970 "Check 4095 is allowed for an unsigned 12-bit integer");
1971 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 4096),
1972 "Check 4096 is not allowed for a unsigned 12-bit integer");
1973 ok(bt_ctf_field_unsigned_integer_set_value(uint_12
, 0) == 0,
1974 "Check 0 is allowed for an unsigned 12-bit integer");
1976 string
= bt_ctf_field_create(string_type
);
1977 ok(string
, "Instanciate a string field");
1978 ok(bt_ctf_field_string_set_value(string
, "A value") == 0,
1979 "Set a string's value");
1981 enumeration_type
= bt_ctf_field_type_enumeration_create(uint_12_type
);
1982 ok(enumeration_type
,
1983 "Create an enumeration type with an unsigned 12-bit integer as container");
1984 enumeration
= bt_ctf_field_create(enumeration_type
);
1986 "Check enumeration types are validated before instantiation");
1991 bt_put(enumeration
);
1992 bt_put(composite_structure_type
);
1993 bt_put(structure_seq_type
);
1994 bt_put(string_type
);
1995 bt_put(sequence_type
);
1996 bt_put(uint_8_type
);
1997 bt_put(int_16_type
);
1998 bt_put(uint_12_type
);
1999 bt_put(enumeration_type
);
2000 bt_put(returned_type
);
2004 void packet_resize_test(struct bt_ctf_stream_class
*stream_class
,
2005 struct bt_ctf_stream
*stream
, struct bt_ctf_clock
*clock
)
2008 * Append enough events to force the underlying packet to be resized.
2009 * Also tests that a new event can be declared after a stream has been
2010 * instantiated and used/flushed.
2014 struct bt_ctf_event_class
*event_class
= bt_ctf_event_class_create(
2016 struct bt_ctf_field_type
*integer_type
=
2017 bt_ctf_field_type_integer_create(17);
2018 struct bt_ctf_field_type
*string_type
=
2019 bt_ctf_field_type_string_create();
2020 struct bt_ctf_event
*event
= NULL
;
2021 struct bt_ctf_field
*ret_field
= NULL
;
2022 struct bt_ctf_field_type
*ret_field_type
= NULL
;
2023 uint64_t ret_uint64
;
2024 int events_appended
= 0;
2025 struct bt_ctf_field
*packet_context
= NULL
,
2026 *packet_context_field
= NULL
, *stream_event_context
= NULL
;
2027 struct bt_ctf_field_type
*ep_field_1_type
= NULL
;
2028 struct bt_ctf_field_type
*ep_a_string_type
= NULL
;
2029 struct bt_ctf_field_type
*ep_type
= NULL
;
2031 ret
|= bt_ctf_event_class_add_field(event_class
, integer_type
,
2033 ret
|= bt_ctf_event_class_add_field(event_class
, string_type
,
2035 ret
|= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
2036 ok(ret
== 0, "Add a new event class to a stream class after writing an event");
2042 * bt_ctf_stream_class_add_event_class() copies the field types
2043 * of event_class, so we retrieve the new ones to create the
2044 * appropriate fields.
2046 ep_type
= bt_ctf_event_class_get_payload_type(event_class
);
2048 ep_field_1_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2049 ep_type
, "field_1");
2050 assert(ep_field_1_type
);
2051 ep_a_string_type
= bt_ctf_field_type_structure_get_field_type_by_name(
2052 ep_type
, "a_string");
2053 assert(ep_a_string_type
);
2055 event
= bt_ctf_event_create(event_class
);
2056 ret_field
= bt_ctf_event_get_payload_by_index(event
, 0);
2057 ret_field_type
= bt_ctf_field_get_type(ret_field
);
2058 ok(bt_ctf_field_type_compare(ret_field_type
, integer_type
) == 0,
2059 "bt_ctf_event_get_payload_by_index returns a correct field");
2060 bt_put(ret_field_type
);
2063 ok(bt_ctf_event_get_payload_by_index(NULL
, 0) == NULL
,
2064 "bt_ctf_event_get_payload_by_index handles NULL correctly");
2065 ok(bt_ctf_event_get_payload_by_index(event
, 4) == NULL
,
2066 "bt_ctf_event_get_payload_by_index handles an invalid index correctly");
2069 for (i
= 0; i
< PACKET_RESIZE_TEST_LENGTH
; i
++) {
2070 event
= bt_ctf_event_create(event_class
);
2071 struct bt_ctf_field
*integer
=
2072 bt_ctf_field_create(ep_field_1_type
);
2073 struct bt_ctf_field
*string
=
2074 bt_ctf_field_create(ep_a_string_type
);
2076 ret
|= bt_ctf_clock_set_time(clock
, ++current_time
);
2077 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
2078 ret
|= bt_ctf_event_set_payload(event
, "field_1",
2081 ret
|= bt_ctf_field_string_set_value(string
, "This is a test");
2082 ret
|= bt_ctf_event_set_payload(event
, "a_string",
2086 /* Populate stream event context */
2087 stream_event_context
=
2088 bt_ctf_event_get_stream_event_context(event
);
2089 integer
= bt_ctf_field_structure_get_field(stream_event_context
,
2090 "common_event_context");
2091 BT_PUT(stream_event_context
);
2092 ret
|= bt_ctf_field_unsigned_integer_set_value(integer
,
2096 ret
|= bt_ctf_stream_append_event(stream
, event
);
2104 events_appended
= !!(i
== PACKET_RESIZE_TEST_LENGTH
);
2105 ok(bt_ctf_stream_get_discarded_events_count(NULL
, &ret_uint64
) < 0,
2106 "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly");
2107 ok(bt_ctf_stream_get_discarded_events_count(stream
, NULL
) < 0,
2108 "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly");
2109 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
2110 ok(ret
== 0 && ret_uint64
== 0,
2111 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded");
2112 bt_ctf_stream_append_discarded_events(stream
, 1000);
2113 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
2114 ok(ret
== 0 && ret_uint64
== 1000,
2115 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded");
2118 ok(events_appended
, "Append 100 000 events to a stream");
2121 * Populate the custom packet context field with a dummy value
2122 * otherwise flush will fail.
2124 packet_context
= bt_ctf_stream_get_packet_context(stream
);
2125 packet_context_field
= bt_ctf_field_structure_get_field(packet_context
,
2126 "custom_packet_context_field");
2127 bt_ctf_field_unsigned_integer_set_value(packet_context_field
, 2);
2129 ok(bt_ctf_stream_flush(stream
) == 0,
2130 "Flush a stream that forces a packet resize");
2131 ret
= bt_ctf_stream_get_discarded_events_count(stream
, &ret_uint64
);
2132 ok(ret
== 0 && ret_uint64
== 1000,
2133 "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush");
2134 bt_put(integer_type
);
2135 bt_put(string_type
);
2136 bt_put(packet_context
);
2137 bt_put(packet_context_field
);
2138 bt_put(stream_event_context
);
2139 bt_put(event_class
);
2140 bt_put(ep_field_1_type
);
2141 bt_put(ep_a_string_type
);
2146 void test_empty_stream(struct bt_ctf_writer
*writer
)
2149 struct bt_ctf_trace
*trace
= NULL
, *ret_trace
= NULL
;
2150 struct bt_ctf_stream_class
*stream_class
= NULL
;
2151 struct bt_ctf_stream
*stream
= NULL
;
2153 trace
= bt_ctf_writer_get_trace(writer
);
2155 diag("Failed to get trace from writer");
2160 stream_class
= bt_ctf_stream_class_create("empty_stream");
2161 if (!stream_class
) {
2162 diag("Failed to create stream class");
2167 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
2169 ret
= bt_ctf_stream_class_set_event_header_type(stream_class
, NULL
);
2172 ok(bt_ctf_stream_class_get_trace(NULL
) == NULL
,
2173 "bt_ctf_stream_class_get_trace handles NULL correctly");
2174 ok(bt_ctf_stream_class_get_trace(stream_class
) == NULL
,
2175 "bt_ctf_stream_class_get_trace returns NULL when stream class is orphaned");
2177 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
2179 diag("Failed to create writer stream");
2184 ret_trace
= bt_ctf_stream_class_get_trace(stream_class
);
2185 ok(ret_trace
== trace
,
2186 "bt_ctf_stream_class_get_trace returns the correct trace after a stream has been created");
2189 "Created a stream class with default attributes and an empty stream");
2193 bt_put(stream_class
);
2197 void test_custom_event_header_stream(struct bt_ctf_writer
*writer
,
2198 struct bt_ctf_clock
*clock
)
2201 struct bt_ctf_stream_class
*stream_class
= NULL
;
2202 struct bt_ctf_stream
*stream
= NULL
;
2203 struct bt_ctf_field_type
*integer_type
= NULL
,
2204 *sequence_type
= NULL
, *event_header_type
= NULL
;
2205 struct bt_ctf_field
*integer
= NULL
, *sequence
= NULL
,
2206 *event_header
= NULL
, *packet_header
= NULL
;
2207 struct bt_ctf_event_class
*event_class
= NULL
;
2208 struct bt_ctf_event
*event
= NULL
;
2210 stream_class
= bt_ctf_stream_class_create("custom_event_header_stream");
2211 if (!stream_class
) {
2212 fail("Failed to create stream class");
2216 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
2218 fail("Failed to set stream class clock");
2223 * Customize event header to add an "seq_len" integer member
2224 * which will be used as the length of a sequence in an event of this
2227 event_header_type
= bt_ctf_stream_class_get_event_header_type(
2229 if (!event_header_type
) {
2230 fail("Failed to get event header type");
2234 integer_type
= bt_ctf_field_type_integer_create(13);
2235 if (!integer_type
) {
2236 fail("Failed to create length integer type");
2240 ret
= bt_ctf_field_type_structure_add_field(event_header_type
,
2241 integer_type
, "seq_len");
2243 fail("Failed to add a new field to stream event header");
2247 event_class
= bt_ctf_event_class_create("sequence_event");
2249 fail("Failed to create event class");
2254 * This event's payload will contain a sequence which references
2255 * stream.event.header.seq_len as its length field.
2257 sequence_type
= bt_ctf_field_type_sequence_create(integer_type
,
2258 "stream.event.header.seq_len");
2259 if (!sequence_type
) {
2260 fail("Failed to create a sequence");
2264 ret
= bt_ctf_event_class_add_field(event_class
, sequence_type
,
2267 fail("Failed to add a sequence to an event class");
2271 ret
= bt_ctf_stream_class_add_event_class(stream_class
, event_class
);
2273 fail("Failed to add event class to stream class");
2277 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
2279 fail("Failed to create stream")
2284 * We have defined a custom packet header field. We have to populate it
2287 packet_header
= bt_ctf_stream_get_packet_header(stream
);
2288 if (!packet_header
) {
2289 fail("Failed to get stream packet header");
2293 integer
= bt_ctf_field_structure_get_field(packet_header
,
2294 "custom_trace_packet_header_field");
2296 fail("Failed to retrieve custom_trace_packet_header_field");
2300 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 3487);
2302 fail("Failed to set custom_trace_packet_header_field value");
2307 event
= bt_ctf_event_create(event_class
);
2309 fail("Failed to create event");
2313 event_header
= bt_ctf_event_get_header(event
);
2314 if (!event_header
) {
2315 fail("Failed to get event header");
2319 integer
= bt_ctf_field_structure_get_field(event_header
,
2322 fail("Failed to get seq_len field from event header");
2326 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 2);
2328 fail("Failed to set seq_len value in event header");
2332 /* Populate both sequence integer fields */
2333 sequence
= bt_ctf_event_get_payload(event
, "some_sequence");
2335 fail("Failed to retrieve sequence from event");
2339 ret
= bt_ctf_field_sequence_set_length(sequence
, integer
);
2341 fail("Failed to set sequence length");
2346 for (i
= 0; i
< 2; i
++) {
2347 integer
= bt_ctf_field_sequence_get_field(sequence
, i
);
2349 fail("Failed to retrieve sequence element");
2353 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, i
);
2355 fail("Failed to set sequence element value");
2363 ret
= bt_ctf_stream_append_event(stream
, event
);
2365 fail("Failed to append event to stream");
2369 ret
= bt_ctf_stream_flush(stream
);
2371 fail("Failed to flush custom_event_header stream");
2375 bt_put(stream_class
);
2376 bt_put(event_class
);
2380 bt_put(event_header
);
2381 bt_put(packet_header
);
2382 bt_put(sequence_type
);
2383 bt_put(integer_type
);
2384 bt_put(event_header_type
);
2388 void test_instanciate_event_before_stream(struct bt_ctf_writer
*writer
,
2389 struct bt_ctf_clock
*clock
)
2392 struct bt_ctf_stream_class
*stream_class
= NULL
;
2393 struct bt_ctf_stream
*stream
= NULL
,
2395 struct bt_ctf_event_class
*event_class
= NULL
;
2396 struct bt_ctf_event
*event
= NULL
;
2397 struct bt_ctf_field_type
*integer_type
= NULL
;
2398 struct bt_ctf_field
*integer
= NULL
;
2400 stream_class
= bt_ctf_stream_class_create("event_before_stream_test");
2401 if (!stream_class
) {
2402 diag("Failed to create stream class");
2407 ret
= bt_ctf_stream_class_set_clock(stream_class
, clock
);
2409 diag("Failed to set stream class clock");
2413 event_class
= bt_ctf_event_class_create("some_event_class_name");
2414 integer_type
= bt_ctf_field_type_integer_create(32);
2415 if (!integer_type
) {
2416 diag("Failed to create integer field type");
2421 ret
= bt_ctf_event_class_add_field(event_class
, integer_type
,
2424 diag("Failed to add field to event class");
2428 ret
= bt_ctf_stream_class_add_event_class(stream_class
,
2431 diag("Failed to add event class to stream class");
2434 event
= bt_ctf_event_create(event_class
);
2436 diag("Failed to create event");
2441 integer
= bt_ctf_event_get_payload_by_index(event
, 0);
2443 diag("Failed to get integer field payload from event");
2448 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, 1234);
2450 diag("Failed to set integer field value");
2454 stream
= bt_ctf_writer_create_stream(writer
, stream_class
);
2456 diag("Failed to create writer stream");
2461 ok(bt_ctf_event_get_stream(NULL
) == NULL
,
2462 "bt_ctf_event_get_stream handles NULL correctly");
2463 ok(bt_ctf_event_get_stream(event
) == NULL
,
2464 "bt_ctf_event_get_stream returns NULL on event which has not yet been appended to a stream");
2466 ret
= bt_ctf_stream_append_event(stream
, event
);
2468 diag("Failed to append event to stream");
2472 ret_stream
= bt_ctf_event_get_stream(event
);
2473 ok(ret_stream
== stream
,
2474 "bt_ctf_event_get_stream returns an event's stream after it has been appended");
2477 "Create an event before instanciating its associated stream");
2480 bt_put(stream_class
);
2481 bt_put(event_class
);
2483 bt_put(integer_type
);
2488 void append_existing_event_class(struct bt_ctf_stream_class
*stream_class
)
2490 struct bt_ctf_event_class
*event_class
;
2492 event_class
= bt_ctf_event_class_create("Simple Event");
2493 assert(event_class
);
2494 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
) == 0,
2495 "two event classes with the same name may cohabit within the same stream class");
2496 bt_put(event_class
);
2498 event_class
= bt_ctf_event_class_create("different name, ok");
2499 assert(event_class
);
2500 assert(!bt_ctf_event_class_set_id(event_class
, 11));
2501 ok(bt_ctf_stream_class_add_event_class(stream_class
, event_class
),
2502 "two event classes with the same ID cannot cohabit within the same stream class");
2503 bt_put(event_class
);
2507 struct bt_ctf_event_class
*create_minimal_event_class(void)
2509 struct bt_ctf_event_class
*ec
= NULL
;
2510 struct bt_ctf_field_type
*int_ft
= NULL
;
2513 int_ft
= bt_ctf_field_type_integer_create(23);
2515 ec
= bt_ctf_event_class_create("minimal");
2517 ret
= bt_ctf_event_class_add_field(ec
, int_ft
, "field");
2525 void test_create_writer_vs_non_writer_mode(void)
2528 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
2529 const char *writer_stream_name
= "writer stream instance";
2530 struct bt_ctf_writer
*writer
= NULL
;
2531 struct bt_ctf_trace
*writer_trace
= NULL
;
2532 struct bt_ctf_stream_class
*writer_sc
= NULL
;
2533 struct bt_ctf_stream
*writer_stream
= NULL
;
2534 struct bt_ctf_stream
*writer_stream2
= NULL
;
2535 struct bt_ctf_stream
*packet_stream
= NULL
;
2536 struct bt_ctf_trace
*non_writer_trace
= NULL
;
2537 struct bt_ctf_stream_class
*non_writer_sc
= NULL
;
2538 struct bt_ctf_stream
*non_writer_stream
= NULL
;
2539 struct bt_ctf_stream
*non_writer_stream2
= NULL
;
2540 struct bt_ctf_event_class
*writer_ec
= NULL
;
2541 struct bt_ctf_event_class
*non_writer_ec
= NULL
;
2542 struct bt_ctf_event
*event
= NULL
;
2543 struct bt_ctf_event
*event2
= NULL
;
2544 struct bt_ctf_field_type
*empty_struct_ft
= NULL
;
2545 struct bt_ctf_field
*int_field
= NULL
;
2546 struct bt_ctf_clock
*writer_clock
= NULL
;
2547 struct bt_ctf_clock_class
*non_writer_clock_class
= NULL
;
2548 struct bt_ctf_packet
*packet
= NULL
;
2549 struct bt_ctf_packet
*packet2
= NULL
;
2551 if (!bt_mkdtemp(trace_path
)) {
2555 /* Create empty structure field type (event header) */
2556 empty_struct_ft
= bt_ctf_field_type_structure_create();
2557 assert(empty_struct_ft
);
2559 /* Create writer, writer stream class, stream, and clock */
2560 writer
= bt_ctf_writer_create(trace_path
);
2562 writer_clock
= bt_ctf_clock_create("writer_clock");
2563 assert(writer_clock
);
2564 ret
= bt_ctf_writer_add_clock(writer
, writer_clock
);
2566 ret
= bt_ctf_writer_set_byte_order(writer
, BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
);
2568 writer_trace
= bt_ctf_writer_get_trace(writer
);
2569 ok(writer_trace
, "bt_ctf_writer_get_trace() returns a trace");
2570 writer_sc
= bt_ctf_stream_class_create("writer_sc");
2572 ret
= bt_ctf_stream_class_set_event_header_type(writer_sc
,
2575 ret
= bt_ctf_stream_class_set_clock(writer_sc
, writer_clock
);
2577 ret
= bt_ctf_trace_add_stream_class(writer_trace
, writer_sc
);
2579 writer_stream
= bt_ctf_stream_create(writer_sc
, writer_stream_name
);
2580 assert(writer_stream
);
2581 ok(!strcmp(bt_ctf_stream_get_name(writer_stream
), writer_stream_name
),
2582 "bt_ctf_stream_get_name() returns the stream's name");
2584 /* Create non-writer trace, stream class, stream, and clock */
2585 non_writer_trace
= bt_ctf_trace_create();
2586 assert(non_writer_trace
);
2587 non_writer_sc
= bt_ctf_stream_class_create("nonwriter_sc");
2588 assert(non_writer_sc
);
2589 ret
= bt_ctf_stream_class_set_event_header_type(non_writer_sc
,
2592 ret
= bt_ctf_stream_class_set_packet_context_type(non_writer_sc
, NULL
);
2594 ret
= bt_ctf_trace_add_stream_class(non_writer_trace
, non_writer_sc
);
2596 non_writer_stream
= bt_ctf_stream_create(non_writer_sc
, NULL
);
2597 assert(non_writer_stream
);
2598 non_writer_clock_class
=
2599 bt_ctf_clock_class_create("non_writer_clock_class");
2600 assert(non_writer_clock_class
);
2601 ret
= bt_ctf_trace_add_clock_class(non_writer_trace
,
2602 non_writer_clock_class
);
2605 /* Create event class and event */
2606 writer_ec
= create_minimal_event_class();
2608 ret
= bt_ctf_stream_class_add_event_class(writer_sc
, writer_ec
);
2610 event
= bt_ctf_event_create(writer_ec
);
2612 int_field
= bt_ctf_event_get_payload_by_index(event
, 0);
2614 bt_ctf_field_unsigned_integer_set_value(int_field
, 17);
2617 * Verify non-writer stream: it should be impossible to append
2620 ok(bt_ctf_stream_append_event(non_writer_stream
, event
),
2621 "bt_ctf_stream_append_event() fails with a non-writer stream");
2624 * Verify writer stream: it should be possible to append an
2627 ok(!bt_ctf_stream_append_event(writer_stream
, event
),
2628 "bt_ctf_stream_append_event() succeeds with a writer stream");
2631 * It should be possible to create a packet from a non-writer
2632 * stream, but not from a writer stream.
2634 packet
= bt_ctf_packet_create(writer_stream
);
2635 ok(!packet
, "bt_ctf_packet_create() fails with a writer stream");
2636 packet
= bt_ctf_packet_create(non_writer_stream
);
2637 ok(packet
, "bt_ctf_packet_create() succeeds with a non-writer stream");
2638 packet_stream
= bt_ctf_packet_get_stream(packet
);
2639 ok(packet_stream
== non_writer_stream
,
2640 "bt_ctf_packet_get_stream() returns the correct stream");
2643 * It should not be possible to append an event associated to
2644 * a stream to a different stream.
2646 writer_stream2
= bt_ctf_stream_create(writer_sc
, "zoo");
2647 assert(writer_stream2
);
2648 ok(bt_ctf_stream_append_event(writer_stream2
, event
),
2649 "bt_ctf_stream_append_event() fails with an event associated to another stream");
2652 * It should not be possible to set the packet of an event
2653 * associated to a given stream to a packet associated with
2654 * a different stream.
2656 ok(bt_ctf_event_set_packet(event
, packet
),
2657 "bt_ctf_event_set_packet() fails with a packet not sharing the event's stream");
2660 * It should be possible to set the packet of a fresh event, as
2661 * long as the originating stream classes are the same.
2663 event2
= bt_ctf_event_create(writer_ec
);
2665 ok(bt_ctf_event_set_packet(event2
, packet
),
2666 "bt_ctf_event_set_packet() fails when the event's and the packet's stream class differ");
2667 non_writer_ec
= create_minimal_event_class();
2668 assert(non_writer_ec
);
2669 ret
= bt_ctf_stream_class_add_event_class(non_writer_sc
, non_writer_ec
);
2672 event2
= bt_ctf_event_create(non_writer_ec
);
2674 ok(!bt_ctf_event_set_packet(event2
, packet
),
2675 "bt_ctf_event_set_packet() succeeds when the event's and the packet's stream class are the same");
2678 * It should be possible to set a packet created from the same
2679 * stream to an event with an existing packet.
2681 packet2
= bt_ctf_packet_create(non_writer_stream
);
2683 ok(!bt_ctf_event_set_packet(event2
, packet2
),
2684 "bt_ctf_event_set_packet() succeeds when the event's current packet has the same stream");
2688 * It should not be possible to set a packet created from a
2689 * different stream to an event with an existing packet.
2691 non_writer_stream2
= bt_ctf_stream_create(non_writer_sc
, "rj45");
2692 assert(non_writer_stream2
);
2693 packet2
= bt_ctf_packet_create(non_writer_stream
);
2695 ok(!bt_ctf_event_set_packet(event2
, packet2
),
2696 "bt_ctf_event_set_packet() fails when the event's current packet does not have the same stream");
2699 bt_put(writer_trace
);
2701 bt_put(writer_stream
);
2702 bt_put(writer_stream2
);
2703 bt_put(non_writer_trace
);
2704 bt_put(non_writer_sc
);
2705 bt_put(non_writer_stream
);
2706 bt_put(non_writer_stream2
);
2707 bt_put(packet_stream
);
2709 bt_put(non_writer_ec
);
2713 bt_put(empty_struct_ft
);
2714 bt_put(writer_clock
);
2715 bt_put(non_writer_clock_class
);
2718 recursive_rmdir(trace_path
);
2722 void test_clock_utils(void)
2725 struct bt_ctf_clock
*clock
= NULL
;
2727 clock
= bt_ctf_clock_create("water");
2729 ret
= bt_ctf_clock_set_offset_s(clock
, 1234);
2731 ret
= bt_ctf_clock_set_offset(clock
, 1000);
2733 ret
= bt_ctf_clock_set_frequency(clock
, 1000000000);
2735 ret
= bt_ctf_clock_set_frequency(clock
, 1534);
2741 void test_set_clock_non_writer_stream_class(void)
2743 struct bt_ctf_clock
*clock
;
2744 struct bt_ctf_trace
*trace
;
2745 struct bt_ctf_stream_class
*sc
;
2748 clock
= bt_ctf_clock_create("the_clock");
2751 trace
= bt_ctf_trace_create();
2754 sc
= bt_ctf_stream_class_create(NULL
);
2757 ret
= bt_ctf_stream_class_set_clock(sc
, clock
);
2760 ret
= bt_ctf_trace_add_stream_class(trace
, sc
);
2762 "bt_ctf_trace_add_stream_class() fails with a stream class with a registered clock");
2770 void test_static_trace(void)
2772 struct bt_ctf_trace
*trace
;
2773 struct bt_ctf_stream_class
*stream_class
;
2774 struct bt_ctf_stream_class
*stream_class2
;
2775 struct bt_ctf_stream
*stream
;
2776 struct bt_ctf_clock_class
*clock_class
;
2779 trace
= bt_ctf_trace_create();
2781 stream_class
= bt_ctf_stream_class_create(NULL
);
2782 assert(stream_class
);
2783 ret
= bt_ctf_stream_class_set_packet_context_type(stream_class
, NULL
);
2785 ret
= bt_ctf_trace_add_stream_class(trace
, stream_class
);
2787 stream
= bt_ctf_stream_create(stream_class
, "hello");
2788 ok(stream
, "bt_ctf_stream_create() succeeds with a non-static trace");
2790 ok(!bt_ctf_trace_is_static(trace
),
2791 "bt_ctf_trace_is_static() returns the expected value");
2792 ok(bt_ctf_trace_set_is_static(trace
) == 0,
2793 "bt_ctf_trace_set_is_static() succeeds");
2794 ok(bt_ctf_trace_is_static(trace
),
2795 "bt_ctf_trace_is_static() returns the expected value");
2796 clock_class
= bt_ctf_clock_class_create("yes");
2797 assert(clock_class
);
2798 stream_class2
= bt_ctf_stream_class_create(NULL
);
2799 assert(stream_class2
);
2800 ok(bt_ctf_trace_add_stream_class(trace
, stream_class2
),
2801 "bt_ctf_trace_add_stream_class() fails with a static trace");
2802 ok(bt_ctf_trace_add_clock_class(trace
, clock_class
),
2803 "bt_ctf_trace_add_clock_class() fails with a static trace");
2804 ok(!bt_ctf_stream_create(stream_class
, "hello2"),
2805 "bt_ctf_stream_create() fails with a static trace");
2808 bt_put(stream_class
);
2809 bt_put(stream_class2
);
2810 bt_put(clock_class
);
2814 void trace_is_static_listener(struct bt_ctf_trace
*trace
, void *data
)
2816 *((int *) data
) = 1;
2820 void test_trace_is_static_listener(void)
2822 struct bt_ctf_trace
*trace
;
2833 trace
= bt_ctf_trace_create();
2835 ret
= bt_ctf_trace_add_is_static_listener(NULL
,
2836 trace_is_static_listener
, &called1
);
2837 ok(ret
< 0, "bt_ctf_trace_add_is_static_listener() handles NULL (trace)");
2838 ret
= bt_ctf_trace_add_is_static_listener(trace
, NULL
, &called1
);
2839 ok(ret
< 0, "bt_ctf_trace_add_is_static_listener() handles NULL (listener)");
2840 listener1_id
= bt_ctf_trace_add_is_static_listener(trace
,
2841 trace_is_static_listener
, &called1
);
2842 ok(listener1_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (1)");
2843 listener2_id
= bt_ctf_trace_add_is_static_listener(trace
,
2844 trace_is_static_listener
, &called2
);
2845 ok(listener2_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (2)");
2846 listener3_id
= bt_ctf_trace_add_is_static_listener(trace
,
2847 trace_is_static_listener
, &called3
);
2848 ok(listener3_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (3)");
2849 ret
= bt_ctf_trace_remove_is_static_listener(NULL
, 0);
2850 ok(ret
< 0, "bt_ctf_trace_remove_is_static_listener() handles NULL (trace)");
2851 ret
= bt_ctf_trace_remove_is_static_listener(trace
, -2);
2852 ok(ret
< 0, "bt_ctf_trace_remove_is_static_listener() handles invalid ID (negative)");
2853 ret
= bt_ctf_trace_remove_is_static_listener(trace
, 77);
2854 ok(ret
< 0, "bt_ctf_trace_remove_is_static_listener() handles invalid ID (non existing)");
2855 ret
= bt_ctf_trace_remove_is_static_listener(trace
, listener2_id
);
2856 ok(ret
== 0, "bt_ctf_trace_remove_is_static_listener() succeeds");
2857 listener4_id
= bt_ctf_trace_add_is_static_listener(trace
,
2858 trace_is_static_listener
, &called4
);
2859 ok(listener4_id
>= 0, "bt_ctf_trace_add_is_static_listener() succeeds (4)");
2860 ok(called1
== 0, "\"trace is static\" listener not called before the trace is made static (1)");
2861 ok(called2
== 0, "\"trace is static\" listener not called before the trace is made static (2)");
2862 ok(called3
== 0, "\"trace is static\" listener not called before the trace is made static (3)");
2863 ok(called4
== 0, "\"trace is static\" listener not called before the trace is made static (4)");
2864 ret
= bt_ctf_trace_set_is_static(trace
);
2866 ret
= bt_ctf_trace_add_is_static_listener(trace
,
2867 trace_is_static_listener
, &called1
);
2869 "bt_ctf_trace_add_is_static_listener() fails when the trace is static");
2870 ok(called1
== 1, "\"trace is static\" listener called when the trace is made static (1)");
2871 ok(called2
== 0, "\"trace is static\" listener not called when the trace is made static (2)");
2872 ok(called3
== 1, "\"trace is static\" listener called when the trace is made static (3)");
2873 ok(called4
== 1, "\"trace is static\" listener called when the trace is made static (4)");
2879 ok(called1
== 0, "\"trace is static\" listener not called after the trace is put (1)");
2880 ok(called2
== 0, "\"trace is static\" listener not called after the trace is put (2)");
2881 ok(called3
== 0, "\"trace is static\" listener not called after the trace is put (3)");
2882 ok(called4
== 0, "\"trace is static\" listener not called after the trace is put (4)");
2886 void test_trace_uuid(void)
2888 struct bt_ctf_trace
*trace
;
2889 const unsigned char uuid
[] = {
2890 0x35, 0x92, 0x63, 0xab, 0xb4, 0xbe, 0x40, 0xb4,
2891 0xb2, 0x60, 0xd3, 0xf1, 0x3b, 0xb0, 0xd8, 0x59,
2893 const unsigned char *ret_uuid
;
2895 trace
= bt_ctf_trace_create();
2897 ok(!bt_ctf_trace_get_uuid(NULL
),
2898 "bt_ctf_trace_get_uuid() handles NULL");
2899 ok(!bt_ctf_trace_get_uuid(trace
),
2900 "bt_ctf_trace_get_uuid() returns NULL initially");
2901 ok(bt_ctf_trace_set_uuid(NULL
, uuid
),
2902 "bt_ctf_trace_set_uuid() handles NULL (trace)");
2903 ok(bt_ctf_trace_set_uuid(trace
, NULL
),
2904 "bt_ctf_trace_set_uuid() handles NULL (UUID)");
2905 ok(bt_ctf_trace_set_uuid(trace
, uuid
) == 0,
2906 "bt_ctf_trace_set_uuid() succeeds with a valid UUID");
2907 ret_uuid
= bt_ctf_trace_get_uuid(trace
);
2908 ok(ret_uuid
, "bt_ctf_trace_get_uuid() returns a UUID");
2910 ok(memcmp(uuid
, ret_uuid
, 16) == 0,
2911 "bt_ctf_trace_get_uuid() returns the expected UUID");
2916 int main(int argc
, char **argv
)
2918 char trace_path
[] = "/tmp/ctfwriter_XXXXXX";
2919 char metadata_path
[sizeof(trace_path
) + 9];
2920 const char *clock_name
= "test_clock";
2921 const char *clock_description
= "This is a test clock";
2922 const char *returned_clock_name
;
2923 const char *returned_clock_description
;
2924 const uint64_t frequency
= 1123456789;
2925 const int64_t offset_s
= 1351530929945824323;
2926 const int64_t offset
= 1234567;
2927 int64_t get_offset_s
,
2929 const uint64_t precision
= 10;
2930 const int is_absolute
= 0xFF;
2931 char *metadata_string
;
2932 struct bt_ctf_writer
*writer
;
2933 struct utsname name
;
2934 char hostname
[BABELTRACE_HOST_NAME_MAX
];
2935 struct bt_ctf_clock
*clock
, *ret_clock
;
2936 struct bt_ctf_clock_class
*ret_clock_class
;
2937 struct bt_ctf_stream_class
*stream_class
, *ret_stream_class
;
2938 struct bt_ctf_stream
*stream1
;
2939 struct bt_ctf_stream
*stream
;
2940 const char *ret_string
;
2941 const unsigned char *ret_uuid
;
2942 unsigned char tmp_uuid
[16] = { 0 };
2943 struct bt_ctf_field_type
*packet_context_type
,
2944 *packet_context_field_type
,
2945 *packet_header_type
,
2946 *packet_header_field_type
,
2948 *stream_event_context_type
,
2950 *event_header_field_type
;
2951 struct bt_ctf_field
*packet_header
, *packet_header_field
;
2952 struct bt_ctf_trace
*trace
;
2954 int64_t ret_int64_t
;
2955 struct bt_value
*obj
;
2958 printf("Usage: tests-ctf-writer path_to_babeltrace\n");
2962 plan_tests(NR_TESTS
);
2964 if (!bt_mkdtemp(trace_path
)) {
2968 strcpy(metadata_path
, trace_path
);
2969 strcat(metadata_path
+ sizeof(trace_path
) - 1, "/metadata");
2971 writer
= bt_ctf_writer_create(trace_path
);
2972 ok(writer
, "bt_ctf_create succeeds in creating trace with path");
2974 ok(!bt_ctf_writer_get_trace(NULL
),
2975 "bt_ctf_writer_get_trace correctly handles NULL");
2976 trace
= bt_ctf_writer_get_trace(writer
);
2977 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
),
2978 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NATIVE");
2979 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_NONE
),
2980 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NONE");
2982 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
2983 ok(bt_ctf_trace_set_native_byte_order(trace
, BT_CTF_BYTE_ORDER_BIG_ENDIAN
) == 0,
2984 "Set a trace's byte order to big endian");
2985 ok(bt_ctf_trace_get_native_byte_order(trace
) == BT_CTF_BYTE_ORDER_BIG_ENDIAN
,
2986 "bt_ctf_trace_get_native_byte_order returns a correct endianness");
2988 /* Add environment context to the trace */
2989 ret
= gethostname(hostname
, sizeof(hostname
));
2993 ok(bt_ctf_writer_add_environment_field(writer
, "host", hostname
) == 0,
2994 "Add host (%s) environment field to writer instance",
2996 ok(bt_ctf_writer_add_environment_field(NULL
, "test_field",
2998 "bt_ctf_writer_add_environment_field error with NULL writer");
2999 ok(bt_ctf_writer_add_environment_field(writer
, NULL
,
3001 "bt_ctf_writer_add_environment_field error with NULL field name");
3002 ok(bt_ctf_writer_add_environment_field(writer
, "test_field",
3004 "bt_ctf_writer_add_environment_field error with NULL field value");
3006 /* Test bt_ctf_trace_set_environment_field with an integer object */
3007 obj
= bt_value_integer_create_init(23);
3009 ok(bt_ctf_trace_set_environment_field(NULL
, "test_env_int_obj", obj
),
3010 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
3011 ok(bt_ctf_trace_set_environment_field(trace
, NULL
, obj
),
3012 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
3013 ok(bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", NULL
),
3014 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
3015 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_int_obj", obj
),
3016 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
3019 /* Test bt_ctf_trace_set_environment_field with a string object */
3020 obj
= bt_value_string_create_init("the value");
3022 ok(!bt_ctf_trace_set_environment_field(trace
, "test_env_str_obj", obj
),
3023 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
3026 /* Test bt_ctf_trace_set_environment_field_integer */
3027 ok(bt_ctf_trace_set_environment_field_integer(NULL
, "test_env_int",
3029 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
3030 ok(bt_ctf_trace_set_environment_field_integer(trace
, NULL
, -194875),
3031 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
3032 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
3034 "bt_ctf_trace_set_environment_field_integer succeeds");
3036 /* Test bt_ctf_trace_set_environment_field_string */
3037 ok(bt_ctf_trace_set_environment_field_string(NULL
, "test_env_str",
3039 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
3040 ok(bt_ctf_trace_set_environment_field_string(trace
, NULL
, "yeah"),
3041 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
3042 ok(bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
3044 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
3045 ok(!bt_ctf_trace_set_environment_field_string(trace
, "test_env_str",
3047 "bt_ctf_trace_set_environment_field_string succeeds");
3049 /* Test bt_ctf_trace_get_environment_field_count */
3050 ok(bt_ctf_trace_get_environment_field_count(NULL
) < 0,
3051 "bt_ctf_trace_get_environment_field_count handles a NULL trace correctly");
3052 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
3053 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
3055 /* Test bt_ctf_trace_get_environment_field_name */
3056 ok(bt_ctf_trace_get_environment_field_name_by_index(NULL
, 0) == NULL
,
3057 "bt_ctf_trace_get_environment_field_name handles a NULL trace correctly");
3058 ok(bt_ctf_trace_get_environment_field_name_by_index(trace
, 5) == NULL
,
3059 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (too large)");
3060 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 0);
3061 ok(ret_string
&& !strcmp(ret_string
, "host"),
3062 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3063 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 1);
3064 ok(ret_string
&& !strcmp(ret_string
, "test_env_int_obj"),
3065 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3066 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 2);
3067 ok(ret_string
&& !strcmp(ret_string
, "test_env_str_obj"),
3068 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3069 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 3);
3070 ok(ret_string
&& !strcmp(ret_string
, "test_env_int"),
3071 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3072 ret_string
= bt_ctf_trace_get_environment_field_name_by_index(trace
, 4);
3073 ok(ret_string
&& !strcmp(ret_string
, "test_env_str"),
3074 "bt_ctf_trace_get_environment_field_name returns a correct field name");
3076 /* Test bt_ctf_trace_get_environment_field_value */
3077 ok(bt_ctf_trace_get_environment_field_value_by_index(NULL
, 0) == NULL
,
3078 "bt_ctf_trace_get_environment_field_value handles a NULL trace correctly");
3079 ok(bt_ctf_trace_get_environment_field_value_by_index(trace
, 5) == NULL
,
3080 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (too large)");
3081 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 1);
3082 ret
= bt_value_integer_get(obj
, &ret_int64_t
);
3083 ok(!ret
&& ret_int64_t
== 23,
3084 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
3086 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 2);
3087 ret
= bt_value_string_get(obj
, &ret_string
);
3088 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "the value"),
3089 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
3092 /* Test bt_ctf_trace_get_environment_field_value_by_name */
3093 ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL
,
3095 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL trace correctly");
3096 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, NULL
),
3097 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL name correctly");
3098 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace
, "oh oh"),
3099 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
3100 obj
= bt_ctf_trace_get_environment_field_value_by_name(trace
,
3102 ret
= bt_value_string_get(obj
, &ret_string
);
3103 ok(!ret
&& ret_string
&& !strcmp(ret_string
, "oh yeah"),
3104 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
3107 /* Test environment field replacement */
3108 ok(!bt_ctf_trace_set_environment_field_integer(trace
, "test_env_int",
3110 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
3111 ok(bt_ctf_trace_get_environment_field_count(trace
) == 5,
3112 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
3113 obj
= bt_ctf_trace_get_environment_field_value_by_index(trace
, 3);
3114 ret
= bt_value_integer_get(obj
, &ret_int64_t
);
3115 ok(!ret
&& ret_int64_t
== 654321,
3116 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
3119 /* On Solaris, uname() can return any positive value on success */
3120 if (uname(&name
) < 0) {
3125 ok(bt_ctf_writer_add_environment_field(writer
, "sysname", name
.sysname
)
3126 == 0, "Add sysname (%s) environment field to writer instance",
3128 ok(bt_ctf_writer_add_environment_field(writer
, "nodename",
3129 name
.nodename
) == 0,
3130 "Add nodename (%s) environment field to writer instance",
3132 ok(bt_ctf_writer_add_environment_field(writer
, "release", name
.release
)
3133 == 0, "Add release (%s) environment field to writer instance",
3135 ok(bt_ctf_writer_add_environment_field(writer
, "version", name
.version
)
3136 == 0, "Add version (%s) environment field to writer instance",
3138 ok(bt_ctf_writer_add_environment_field(writer
, "machine", name
.machine
)
3139 == 0, "Add machine (%s) environment field to writer istance",
3142 /* Define a clock and add it to the trace */
3143 ok(bt_ctf_clock_create("signed") == NULL
,
3144 "Illegal clock name rejected");
3145 clock
= bt_ctf_clock_create(clock_name
);
3146 ok(clock
, "Clock created sucessfully");
3147 returned_clock_name
= bt_ctf_clock_get_name(clock
);
3148 ok(returned_clock_name
, "bt_ctf_clock_get_name returns a clock name");
3149 ok(returned_clock_name
? !strcmp(returned_clock_name
, clock_name
) : 0,
3150 "Returned clock name is valid");
3152 returned_clock_description
= bt_ctf_clock_get_description(clock
);
3153 ok(!returned_clock_description
, "bt_ctf_clock_get_description returns NULL on an unset description");
3154 ok(bt_ctf_clock_set_description(clock
, clock_description
) == 0,
3155 "Clock description set successfully");
3157 returned_clock_description
= bt_ctf_clock_get_description(clock
);
3158 ok(returned_clock_description
,
3159 "bt_ctf_clock_get_description returns a description.");
3160 ok(returned_clock_description
?
3161 !strcmp(returned_clock_description
, clock_description
) : 0,
3162 "Returned clock description is valid");
3164 ok(bt_ctf_clock_get_frequency(clock
) == DEFAULT_CLOCK_FREQ
,
3165 "bt_ctf_clock_get_frequency returns the correct default frequency");
3166 ok(bt_ctf_clock_set_frequency(clock
, frequency
) == 0,
3167 "Set clock frequency");
3168 ok(bt_ctf_clock_get_frequency(clock
) == frequency
,
3169 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
3171 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
3172 "bt_ctf_clock_get_offset_s succeeds");
3173 ok(get_offset_s
== DEFAULT_CLOCK_OFFSET_S
,
3174 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
3175 ok(bt_ctf_clock_set_offset_s(clock
, offset_s
) == 0,
3176 "Set clock offset (seconds)");
3177 ok(bt_ctf_clock_get_offset_s(clock
, &get_offset_s
) == 0,
3178 "bt_ctf_clock_get_offset_s succeeds");
3179 ok(get_offset_s
== offset_s
,
3180 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
3182 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
3183 "bt_ctf_clock_get_offset succeeds");
3184 ok(get_offset
== DEFAULT_CLOCK_OFFSET
,
3185 "bt_ctf_clock_get_offset returns the correct default offset (in ticks)");
3186 ok(bt_ctf_clock_set_offset(clock
, offset
) == 0, "Set clock offset");
3187 ok(bt_ctf_clock_get_offset(clock
, &get_offset
) == 0,
3188 "bt_ctf_clock_get_offset succeeds");
3189 ok(get_offset
== offset
,
3190 "bt_ctf_clock_get_offset returns the correct default offset (in ticks) once it is set");
3192 ok(bt_ctf_clock_get_precision(clock
) == DEFAULT_CLOCK_PRECISION
,
3193 "bt_ctf_clock_get_precision returns the correct default precision");
3194 ok(bt_ctf_clock_set_precision(clock
, precision
) == 0,
3195 "Set clock precision");
3196 ok(bt_ctf_clock_get_precision(clock
) == precision
,
3197 "bt_ctf_clock_get_precision returns the correct precision once it is set");
3199 ok(bt_ctf_clock_get_is_absolute(clock
) == DEFAULT_CLOCK_IS_ABSOLUTE
,
3200 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
3201 ok(bt_ctf_clock_set_is_absolute(clock
, is_absolute
) == 0,
3202 "Set clock absolute property");
3203 ok(bt_ctf_clock_get_is_absolute(clock
) == !!is_absolute
,
3204 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
3206 ok(bt_ctf_clock_set_time(clock
, current_time
) == 0,
3209 ok(!bt_ctf_clock_get_name(NULL
),
3210 "bt_ctf_clock_get_name correctly handles NULL");
3211 ok(!bt_ctf_clock_get_description(NULL
),
3212 "bt_ctf_clock_get_description correctly handles NULL");
3213 ok(bt_ctf_clock_get_frequency(NULL
) == -1ULL,
3214 "bt_ctf_clock_get_frequency correctly handles NULL");
3215 ok(bt_ctf_clock_get_precision(NULL
) == -1ULL,
3216 "bt_ctf_clock_get_precision correctly handles NULL");
3217 ok(bt_ctf_clock_get_offset_s(NULL
, &get_offset_s
) < 0,
3218 "bt_ctf_clock_get_offset_s correctly handles NULL clock");
3219 ok(bt_ctf_clock_get_offset_s(clock
, NULL
) < 0,
3220 "bt_ctf_clock_get_offset_s correctly handles NULL output");
3221 ok(bt_ctf_clock_get_offset(NULL
, &get_offset
) < 0,
3222 "bt_ctf_clock_get_offset correctly handles NULL clock");
3223 ok(bt_ctf_clock_get_offset(clock
, NULL
) < 0,
3224 "bt_ctf_clock_get_offset correctly handles NULL output");
3225 ok(bt_ctf_clock_get_is_absolute(NULL
) < 0,
3226 "bt_ctf_clock_get_is_absolute correctly handles NULL");
3228 ok(bt_ctf_clock_set_description(NULL
, NULL
) < 0,
3229 "bt_ctf_clock_set_description correctly handles NULL clock");
3230 ok(bt_ctf_clock_set_frequency(NULL
, frequency
) < 0,
3231 "bt_ctf_clock_set_frequency correctly handles NULL clock");
3232 ok(bt_ctf_clock_set_precision(NULL
, precision
) < 0,
3233 "bt_ctf_clock_get_precision correctly handles NULL clock");
3234 ok(bt_ctf_clock_set_offset_s(NULL
, offset_s
) < 0,
3235 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
3236 ok(bt_ctf_clock_set_offset(NULL
, offset
) < 0,
3237 "bt_ctf_clock_set_offset correctly handles NULL clock");
3238 ok(bt_ctf_clock_set_is_absolute(NULL
, is_absolute
) < 0,
3239 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
3240 ok(bt_ctf_clock_set_time(NULL
, current_time
) < 0,
3241 "bt_ctf_clock_set_time correctly handles NULL clock");
3242 ok(bt_ctf_clock_get_uuid(NULL
) == NULL
,
3243 "bt_ctf_clock_get_uuid correctly handles NULL clock");
3244 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
3246 "bt_ctf_clock_get_uuid returns a UUID");
3248 memcpy(tmp_uuid
, ret_uuid
, sizeof(tmp_uuid
));
3249 /* Slightly modify UUID */
3250 tmp_uuid
[sizeof(tmp_uuid
) - 1]++;
3253 ok(bt_ctf_clock_set_uuid(NULL
, tmp_uuid
) < 0,
3254 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
3255 ok(bt_ctf_clock_set_uuid(clock
, NULL
) < 0,
3256 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
3257 ok(bt_ctf_clock_set_uuid(clock
, tmp_uuid
) == 0,
3258 "bt_ctf_clock_set_uuid sets a new uuid successfully");
3259 ret_uuid
= bt_ctf_clock_get_uuid(clock
);
3261 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
3262 ok(uuid_match(ret_uuid
, tmp_uuid
),
3263 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
3265 /* Define a stream class */
3266 stream_class
= bt_ctf_stream_class_create("test_stream");
3268 ok(bt_ctf_stream_class_get_name(NULL
) == NULL
,
3269 "bt_ctf_stream_class_get_name handles NULL correctly");
3270 ret_string
= bt_ctf_stream_class_get_name(stream_class
);
3271 ok(ret_string
&& !strcmp(ret_string
, "test_stream"),
3272 "bt_ctf_stream_class_get_name returns a correct stream class name");
3274 ok(bt_ctf_stream_class_get_clock(stream_class
) == NULL
,
3275 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
3276 ok(bt_ctf_stream_class_get_clock(NULL
) == NULL
,
3277 "bt_ctf_stream_class_get_clock handles NULL correctly");
3279 ok(stream_class
, "Create stream class");
3280 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
) == 0,
3281 "Set a stream class' clock");
3282 ret_clock
= bt_ctf_stream_class_get_clock(stream_class
);
3283 ok(ret_clock
== clock
,
3284 "bt_ctf_stream_class_get_clock returns a correct clock");
3287 /* Test the event fields and event types APIs */
3290 /* Test fields copying */
3293 ok(bt_ctf_stream_class_get_id(stream_class
) < 0,
3294 "bt_ctf_stream_class_get_id returns an error when no id is set");
3295 ok(bt_ctf_stream_class_get_id(NULL
) < 0,
3296 "bt_ctf_stream_class_get_id handles NULL correctly");
3297 ok(bt_ctf_stream_class_set_id(NULL
, 123) < 0,
3298 "bt_ctf_stream_class_set_id handles NULL correctly");
3299 ok(bt_ctf_stream_class_set_id(stream_class
, 123) == 0,
3300 "Set an stream class' id");
3301 ok(bt_ctf_stream_class_get_id(stream_class
) == 123,
3302 "bt_ctf_stream_class_get_id returns the correct value");
3304 /* Validate default event header fields */
3305 ok(bt_ctf_stream_class_get_event_header_type(NULL
) == NULL
,
3306 "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
3307 ret_field_type
= bt_ctf_stream_class_get_event_header_type(
3310 "bt_ctf_stream_class_get_event_header_type returns an event header type");
3311 ok(bt_ctf_field_type_get_type_id(ret_field_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
3312 "Default event header type is a structure");
3313 event_header_field_type
=
3314 bt_ctf_field_type_structure_get_field_type_by_name(
3315 ret_field_type
, "id");
3316 ok(event_header_field_type
,
3317 "Default event header type contains an \"id\" field");
3318 ok(bt_ctf_field_type_get_type_id(
3319 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
3320 "Default event header \"id\" field is an integer");
3321 bt_put(event_header_field_type
);
3322 event_header_field_type
=
3323 bt_ctf_field_type_structure_get_field_type_by_name(
3324 ret_field_type
, "timestamp");
3325 ok(event_header_field_type
,
3326 "Default event header type contains a \"timestamp\" field");
3327 ok(bt_ctf_field_type_get_type_id(
3328 event_header_field_type
) == BT_CTF_FIELD_TYPE_ID_INTEGER
,
3329 "Default event header \"timestamp\" field is an integer");
3330 bt_put(event_header_field_type
);
3331 bt_put(ret_field_type
);
3333 /* Add a custom trace packet header field */
3334 ok(bt_ctf_trace_get_packet_header_type(NULL
) == NULL
,
3335 "bt_ctf_trace_get_packet_header_type handles NULL correctly");
3336 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
3337 ok(packet_header_type
,
3338 "bt_ctf_trace_get_packet_header_type returns a packet header");
3339 ok(bt_ctf_field_type_get_type_id(packet_header_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
3340 "bt_ctf_trace_get_packet_header_type returns a packet header of type struct");
3341 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
3342 packet_header_type
, "magic");
3343 ok(ret_field_type
, "Default packet header type contains a \"magic\" field");
3344 bt_put(ret_field_type
);
3345 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
3346 packet_header_type
, "uuid");
3347 ok(ret_field_type
, "Default packet header type contains a \"uuid\" field");
3348 bt_put(ret_field_type
);
3349 ret_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
3350 packet_header_type
, "stream_id");
3351 ok(ret_field_type
, "Default packet header type contains a \"stream_id\" field");
3352 bt_put(ret_field_type
);
3354 packet_header_field_type
= bt_ctf_field_type_integer_create(22);
3355 ok(!bt_ctf_field_type_structure_add_field(packet_header_type
,
3356 packet_header_field_type
, "custom_trace_packet_header_field"),
3357 "Added a custom trace packet header field successfully");
3359 ok(bt_ctf_trace_set_packet_header_type(NULL
, packet_header_type
) < 0,
3360 "bt_ctf_trace_set_packet_header_type handles a NULL trace correctly");
3361 ok(!bt_ctf_trace_set_packet_header_type(trace
, packet_header_type
),
3362 "Set a trace packet_header_type successfully");
3364 ok(bt_ctf_stream_class_get_packet_context_type(NULL
) == NULL
,
3365 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
3367 /* Add a custom field to the stream class' packet context */
3368 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
3369 ok(packet_context_type
,
3370 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
3371 ok(bt_ctf_field_type_get_type_id(packet_context_type
) == BT_CTF_FIELD_TYPE_ID_STRUCT
,
3372 "Packet context is a structure");
3374 ok(bt_ctf_stream_class_set_packet_context_type(NULL
, packet_context_type
),
3375 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
3377 integer_type
= bt_ctf_field_type_integer_create(32);
3378 ok(bt_ctf_stream_class_set_packet_context_type(stream_class
,
3380 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
3381 /* Create a "uint5_t" equivalent custom packet context field */
3382 packet_context_field_type
= bt_ctf_field_type_integer_create(5);
3384 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
3385 packet_context_field_type
, "custom_packet_context_field");
3386 ok(ret
== 0, "Packet context field added successfully");
3388 /* Define a stream event context containing a my_integer field. */
3389 ok(bt_ctf_stream_class_get_event_context_type(NULL
) == NULL
,
3390 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
3391 stream_event_context_type
= bt_ctf_field_type_structure_create();
3392 bt_ctf_field_type_structure_add_field(stream_event_context_type
,
3393 integer_type
, "common_event_context");
3395 ok(bt_ctf_stream_class_set_event_context_type(NULL
,
3396 stream_event_context_type
) < 0,
3397 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
3398 ok(bt_ctf_stream_class_set_event_context_type(stream_class
,
3400 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
3402 ok(bt_ctf_stream_class_set_event_context_type(
3403 stream_class
, stream_event_context_type
) == 0,
3404 "Set a new stream event context type");
3405 ret_field_type
= bt_ctf_stream_class_get_event_context_type(
3407 ok(ret_field_type
== stream_event_context_type
,
3408 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
3409 bt_put(ret_field_type
);
3411 /* Instantiate a stream and append events */
3412 ret
= bt_ctf_writer_add_clock(writer
, clock
);
3414 ok(bt_ctf_trace_get_stream_count(trace
) == 0,
3415 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (0)");
3416 stream1
= bt_ctf_writer_create_stream(writer
, stream_class
);
3417 ok(stream1
, "Instanciate a stream class from writer");
3418 ok(bt_ctf_trace_get_stream_count(trace
) == 1,
3419 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (1)");
3420 stream
= bt_ctf_trace_get_stream_by_index(trace
, 0);
3421 ok(stream
== stream1
,
3422 "bt_ctf_trace_get_stream_by_index() succeeds and returns the correct value");
3426 * Creating a stream through a writer adds the given stream
3427 * class to the writer's trace, thus registering the stream
3428 * class's clock to the trace.
3430 ok(bt_ctf_trace_get_clock_class_count(NULL
) < 0,
3431 "bt_ctf_trace_get_clock_class_count correctly handles NULL");
3432 ok(bt_ctf_trace_get_clock_class_count(trace
) == 1,
3433 "bt_ctf_trace_get_clock_class_count returns the correct number of clocks");
3434 ok(!bt_ctf_trace_get_clock_class_by_index(NULL
, 0),
3435 "bt_ctf_trace_get_clock_class correctly handles NULL");
3436 ok(!bt_ctf_trace_get_clock_class_by_index(trace
, 1),
3437 "bt_ctf_trace_get_clock_class correctly handles out of bound accesses");
3438 ret_clock_class
= bt_ctf_trace_get_clock_class_by_index(trace
, 0);
3439 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class
),
3440 bt_ctf_clock_get_name(clock
)) == 0,
3441 "bt_ctf_trace_get_clock_class returns the right clock instance");
3442 bt_put(ret_clock_class
);
3443 ok(!bt_ctf_trace_get_clock_class_by_name(trace
, NULL
),
3444 "bt_ctf_trace_get_clock_class_by_name correctly handles NULL (trace)");
3445 ok(!bt_ctf_trace_get_clock_class_by_name(NULL
, clock_name
),
3446 "bt_ctf_trace_get_clock_by_name correctly handles NULL (clock name)");
3447 ok(!bt_ctf_trace_get_clock_class_by_name(NULL
, NULL
),
3448 "bt_ctf_trace_get_clock_by_name correctly handles NULL (both)");
3449 ret_clock_class
= bt_ctf_trace_get_clock_class_by_name(trace
, clock_name
);
3450 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class
),
3451 bt_ctf_clock_get_name(clock
)) == 0,
3452 "bt_ctf_trace_get_clock_class returns the right clock instance");
3453 bt_put(ret_clock_class
);
3454 ok(!bt_ctf_trace_get_clock_class_by_name(trace
, "random"),
3455 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
3457 ok(bt_ctf_stream_get_class(NULL
) == NULL
,
3458 "bt_ctf_stream_get_class correctly handles NULL");
3459 ret_stream_class
= bt_ctf_stream_get_class(stream1
);
3460 ok(ret_stream_class
,
3461 "bt_ctf_stream_get_class returns a stream class");
3462 ok(ret_stream_class
== stream_class
,
3463 "Returned stream class is of the correct type");
3466 * Packet header, packet context, event header, and stream
3467 * event context types were copied for the resolving
3470 BT_PUT(packet_header_type
);
3471 BT_PUT(packet_context_type
);
3472 BT_PUT(stream_event_context_type
);
3473 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
3474 assert(packet_header_type
);
3475 packet_context_type
=
3476 bt_ctf_stream_class_get_packet_context_type(stream_class
);
3477 assert(packet_context_type
);
3478 stream_event_context_type
=
3479 bt_ctf_stream_class_get_event_context_type(stream_class
);
3480 assert(stream_event_context_type
);
3483 * Try to modify the packet context type after a stream has been
3486 ret
= bt_ctf_field_type_structure_add_field(packet_header_type
,
3487 packet_header_field_type
, "should_fail");
3489 "Trace packet header type can't be modified once a stream has been instanciated");
3492 * Try to modify the packet context type after a stream has been
3495 ret
= bt_ctf_field_type_structure_add_field(packet_context_type
,
3496 packet_context_field_type
, "should_fail");
3498 "Packet context type can't be modified once a stream has been instanciated");
3501 * Try to modify the stream event context type after a stream has been
3504 ret
= bt_ctf_field_type_structure_add_field(stream_event_context_type
,
3505 integer_type
, "should_fail");
3507 "Stream event context type can't be modified once a stream has been instanciated");
3509 /* Should fail after instanciating a stream (frozen) */
3510 ok(bt_ctf_stream_class_set_clock(stream_class
, clock
),
3511 "Changes to a stream class that was already instantiated fail");
3513 /* Populate the custom packet header field only once for all tests */
3514 ok(bt_ctf_stream_get_packet_header(NULL
) == NULL
,
3515 "bt_ctf_stream_get_packet_header handles NULL correctly");
3516 packet_header
= bt_ctf_stream_get_packet_header(stream1
);
3518 "bt_ctf_stream_get_packet_header returns a packet header");
3519 ret_field_type
= bt_ctf_field_get_type(packet_header
);
3520 ok(ret_field_type
== packet_header_type
,
3521 "Stream returns a packet header of the appropriate type");
3522 bt_put(ret_field_type
);
3523 packet_header_field
= bt_ctf_field_structure_get_field(packet_header
,
3524 "custom_trace_packet_header_field");
3525 ok(packet_header_field
,
3526 "Packet header structure contains a custom field with the appropriate name");
3527 ret_field_type
= bt_ctf_field_get_type(packet_header_field
);
3528 ok(bt_ctf_field_type_compare(ret_field_type
, packet_header_field_type
) == 0,
3529 "Custom packet header field is of the expected type");
3530 ok(!bt_ctf_field_unsigned_integer_set_value(packet_header_field
,
3531 54321), "Set custom packet header value successfully");
3532 ok(bt_ctf_stream_set_packet_header(stream1
, NULL
) < 0,
3533 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
3534 ok(bt_ctf_stream_set_packet_header(NULL
, packet_header
) < 0,
3535 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
3536 ok(bt_ctf_stream_set_packet_header(stream1
, packet_header_field
) < 0,
3537 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
3538 ok(!bt_ctf_stream_set_packet_header(stream1
, packet_header
),
3539 "Successfully set a stream's packet header");
3541 ok(bt_ctf_writer_add_environment_field(writer
, "new_field", "test") == 0,
3542 "Add environment field to writer after stream creation");
3546 test_create_writer_vs_non_writer_mode();
3548 test_set_clock_non_writer_stream_class();
3550 test_instanciate_event_before_stream(writer
, clock
);
3552 append_simple_event(stream_class
, stream1
, clock
);
3554 packet_resize_test(stream_class
, stream1
, clock
);
3556 append_complex_event(stream_class
, stream1
, clock
);
3558 append_existing_event_class(stream_class
);
3560 test_empty_stream(writer
);
3562 test_custom_event_header_stream(writer
, clock
);
3564 test_static_trace();
3566 test_trace_is_static_listener();
3570 metadata_string
= bt_ctf_writer_get_metadata_string(writer
);
3571 ok(metadata_string
, "Get metadata string");
3573 bt_ctf_writer_flush_metadata(writer
);
3576 bt_put(ret_stream_class
);
3579 bt_put(packet_context_type
);
3580 bt_put(packet_context_field_type
);
3581 bt_put(integer_type
);
3582 bt_put(stream_event_context_type
);
3583 bt_put(ret_field_type
);
3584 bt_put(packet_header_type
);
3585 bt_put(packet_header_field_type
);
3586 bt_put(packet_header
);
3587 bt_put(packet_header_field
);
3589 free(metadata_string
);
3590 bt_put(stream_class
);
3592 validate_trace(argv
[1], trace_path
);
3594 //recursive_rmdir(trace_path);