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