test_ctf_writer.c: set PACKET_RESIZE_TEST_LENGTH to 100000 again
[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
PP
2503 non_writer_clock_class =
2504 bt_ctf_clock_class_create("non_writer_clock_class");
2505 assert(non_writer_clock_class);
2506 ret = bt_ctf_trace_add_clock_class(non_writer_trace,
2507 non_writer_clock_class);
54e27fc1 2508 assert(!ret);
44ac03eb
PP
2509
2510 /* Create event class and event */
bcd3a967
PP
2511 writer_ec = create_minimal_event_class();
2512 assert(writer_ec);
2513 ret = bt_ctf_stream_class_add_event_class(writer_sc, writer_ec);
44ac03eb 2514 assert(!ret);
bcd3a967 2515 event = bt_ctf_event_create(writer_ec);
44ac03eb
PP
2516 assert(event);
2517 int_field = bt_ctf_event_get_payload_by_index(event, 0);
2518 assert(int_field);
2519 bt_ctf_field_unsigned_integer_set_value(int_field, 17);
2520
2521 /*
2522 * Verify non-writer stream: it should be impossible to append
2523 * an event to it.
2524 */
2525 ok(bt_ctf_stream_append_event(non_writer_stream, event),
2526 "bt_ctf_stream_append_event() fails with a non-writer stream");
2527
2528 /*
2529 * Verify writer stream: it should be possible to append an
2530 * event to it.
2531 */
2532 ok(!bt_ctf_stream_append_event(writer_stream, event),
2533 "bt_ctf_stream_append_event() succeeds with a writer stream");
2534
bcd3a967
PP
2535 /*
2536 * It should be possible to create a packet from a non-writer
2537 * stream, but not from a writer stream.
2538 */
2539 packet = bt_ctf_packet_create(writer_stream);
2540 ok(!packet, "bt_ctf_packet_create() fails with a writer stream");
2541 packet = bt_ctf_packet_create(non_writer_stream);
2542 ok(packet, "bt_ctf_packet_create() succeeds with a non-writer stream");
2543 packet_stream = bt_ctf_packet_get_stream(packet);
2544 ok(packet_stream == non_writer_stream,
2545 "bt_ctf_packet_get_stream() returns the correct stream");
2546
2547 /*
2548 * It should not be possible to append an event associated to
2549 * a stream to a different stream.
2550 */
2551 writer_stream2 = bt_ctf_stream_create(writer_sc, "zoo");
2552 assert(writer_stream2);
2553 ok(bt_ctf_stream_append_event(writer_stream2, event),
2554 "bt_ctf_stream_append_event() fails with an event associated to another stream");
2555
2556 /*
2557 * It should not be possible to set the packet of an event
2558 * associated to a given stream to a packet associated with
2559 * a different stream.
2560 */
2561 ok(bt_ctf_event_set_packet(event, packet),
2562 "bt_ctf_event_set_packet() fails with a packet not sharing the event's stream");
2563
2564 /*
2565 * It should be possible to set the packet of a fresh event, as
2566 * long as the originating stream classes are the same.
2567 */
2568 event2 = bt_ctf_event_create(writer_ec);
2569 assert(event2);
2570 ok(bt_ctf_event_set_packet(event2, packet),
2571 "bt_ctf_event_set_packet() fails when the event's and the packet's stream class differ");
2572 non_writer_ec = create_minimal_event_class();
2573 assert(non_writer_ec);
2574 ret = bt_ctf_stream_class_add_event_class(non_writer_sc, non_writer_ec);
2575 assert(!ret);
2576 BT_PUT(event2);
2577 event2 = bt_ctf_event_create(non_writer_ec);
2578 assert(event2);
2579 ok(!bt_ctf_event_set_packet(event2, packet),
2580 "bt_ctf_event_set_packet() succeeds when the event's and the packet's stream class are the same");
2581
2582 /*
2583 * It should be possible to set a packet created from the same
2584 * stream to an event with an existing packet.
2585 */
2586 packet2 = bt_ctf_packet_create(non_writer_stream);
2587 assert(packet2);
2588 ok(!bt_ctf_event_set_packet(event2, packet2),
2589 "bt_ctf_event_set_packet() succeeds when the event's current packet has the same stream");
2590 BT_PUT(packet2);
2591
2592 /*
2593 * It should not be possible to set a packet created from a
2594 * different stream to an event with an existing packet.
2595 */
2596 non_writer_stream2 = bt_ctf_stream_create(non_writer_sc, "rj45");
2597 assert(non_writer_stream2);
2598 packet2 = bt_ctf_packet_create(non_writer_stream);
2599 assert(packet2);
2600 ok(!bt_ctf_event_set_packet(event2, packet2),
2601 "bt_ctf_event_set_packet() fails when the event's current packet does not have the same stream");
2602
2603 bt_put(writer);
2604 bt_put(writer_trace);
2605 bt_put(writer_sc);
2606 bt_put(writer_stream);
2607 bt_put(writer_stream2);
2608 bt_put(non_writer_trace);
2609 bt_put(non_writer_sc);
2610 bt_put(non_writer_stream);
2611 bt_put(non_writer_stream2);
2612 bt_put(packet_stream);
2613 bt_put(writer_ec);
2614 bt_put(non_writer_ec);
2615 bt_put(event);
2616 bt_put(event2);
2617 bt_put(int_field);
2618 bt_put(empty_struct_ft);
2619 bt_put(writer_clock);
ac0c6bdd 2620 bt_put(non_writer_clock_class);
bcd3a967
PP
2621 bt_put(packet);
2622 bt_put(packet2);
851299b9 2623 recursive_rmdir(trace_path);
44ac03eb
PP
2624}
2625
a3d8579b 2626static
44e0165b
PP
2627void test_clock_utils(void)
2628{
2629 int ret;
2630 struct bt_ctf_clock *clock = NULL;
2631
2632 clock = bt_ctf_clock_create("water");
2633 assert(clock);
2634 ret = bt_ctf_clock_set_offset_s(clock, 1234);
72995028 2635 assert(!ret);
44e0165b
PP
2636 ret = bt_ctf_clock_set_offset(clock, 1000);
2637 assert(!ret);
2638 ret = bt_ctf_clock_set_frequency(clock, 1000000000);
2639 assert(!ret);
44e0165b
PP
2640 ret = bt_ctf_clock_set_frequency(clock, 1534);
2641 assert(!ret);
44e0165b
PP
2642
2643 BT_PUT(clock);
2644}
2645
ac0c6bdd
PP
2646void test_set_clock_non_writer_stream_class(void)
2647{
2648 struct bt_ctf_clock *clock;
2649 struct bt_ctf_trace *trace;
2650 struct bt_ctf_stream_class *sc;
2651 int ret;
2652
2653 clock = bt_ctf_clock_create("the_clock");
2654 assert(clock);
2655
2656 trace = bt_ctf_trace_create();
2657 assert(trace);
2658
2659 sc = bt_ctf_stream_class_create(NULL);
2660 assert(sc);
2661
2662 ret = bt_ctf_stream_class_set_clock(sc, clock);
2663 assert(ret == 0);
2664
2665 ret = bt_ctf_trace_add_stream_class(trace, sc);
2666 ok(ret < 0,
2667 "bt_ctf_trace_add_stream_class() fails with a stream class with a registered clock");
2668
2669 bt_put(clock);
2670 bt_put(trace);
2671 bt_put(sc);
2672}
2673
28437b95
PP
2674static
2675void test_static_trace(void)
2676{
2677 struct bt_ctf_trace *trace;
2678 struct bt_ctf_stream_class *stream_class;
2679 struct bt_ctf_stream_class *stream_class2;
2680 struct bt_ctf_stream *stream;
2681 struct bt_ctf_clock_class *clock_class;
2682 int ret;
2683
2684 trace = bt_ctf_trace_create();
2685 assert(trace);
28437b95
PP
2686 stream_class = bt_ctf_stream_class_create(NULL);
2687 assert(stream_class);
e011d2c1
PP
2688 ret = bt_ctf_stream_class_set_packet_context_type(stream_class, NULL);
2689 assert(ret == 0);
28437b95
PP
2690 ret = bt_ctf_trace_add_stream_class(trace, stream_class);
2691 assert(ret == 0);
2692 stream = bt_ctf_stream_create(stream_class, "hello");
2693 ok(stream, "bt_ctf_stream_create() succeeds with a non-static trace");
2694 bt_put(stream);
2695 ok(!bt_ctf_trace_is_static(trace),
2696 "bt_ctf_trace_is_static() returns the expected value");
2697 ok(bt_ctf_trace_set_is_static(trace) == 0,
2698 "bt_ctf_trace_set_is_static() succeeds");
2699 ok(bt_ctf_trace_is_static(trace),
2700 "bt_ctf_trace_is_static() returns the expected value");
2701 clock_class = bt_ctf_clock_class_create("yes");
2702 assert(clock_class);
2703 stream_class2 = bt_ctf_stream_class_create(NULL);
2704 assert(stream_class2);
2705 ok(bt_ctf_trace_add_stream_class(trace, stream_class2),
2706 "bt_ctf_trace_add_stream_class() fails with a static trace");
2707 ok(bt_ctf_trace_add_clock_class(trace, clock_class),
2708 "bt_ctf_trace_add_clock_class() fails with a static trace");
2709 ok(!bt_ctf_stream_create(stream_class, "hello2"),
2710 "bt_ctf_stream_create() fails with a static trace");
2711
2712 bt_put(trace);
2713 bt_put(stream_class);
2714 bt_put(stream_class2);
2715 bt_put(clock_class);
2716}
2717
d40a81d5
PP
2718static
2719void trace_is_static_listener(struct bt_ctf_trace *trace, void *data)
2720{
2721 *((int *) data) = 1;
2722}
2723
2724static
2725void test_trace_is_static_listener(void)
2726{
2727 struct bt_ctf_trace *trace;
2728 int ret;
2729 int called1 = 0;
2730 int called2 = 0;
2731 int called3 = 0;
2732 int called4 = 0;
2733 int listener1_id;
2734 int listener2_id;
2735 int listener3_id;
2736 int listener4_id;
2737
2738 trace = bt_ctf_trace_create();
2739 assert(trace);
2740 ret = bt_ctf_trace_add_is_static_listener(NULL,
2741 trace_is_static_listener, &called1);
2742 ok(ret < 0, "bt_ctf_trace_add_is_static_listener() handles NULL (trace)");
2743 ret = bt_ctf_trace_add_is_static_listener(trace, NULL, &called1);
2744 ok(ret < 0, "bt_ctf_trace_add_is_static_listener() handles NULL (listener)");
2745 listener1_id = bt_ctf_trace_add_is_static_listener(trace,
2746 trace_is_static_listener, &called1);
2747 ok(listener1_id >= 0, "bt_ctf_trace_add_is_static_listener() succeeds (1)");
2748 listener2_id = bt_ctf_trace_add_is_static_listener(trace,
2749 trace_is_static_listener, &called2);
2750 ok(listener2_id >= 0, "bt_ctf_trace_add_is_static_listener() succeeds (2)");
2751 listener3_id = bt_ctf_trace_add_is_static_listener(trace,
2752 trace_is_static_listener, &called3);
2753 ok(listener3_id >= 0, "bt_ctf_trace_add_is_static_listener() succeeds (3)");
2754 ret = bt_ctf_trace_remove_is_static_listener(NULL, 0);
2755 ok(ret < 0, "bt_ctf_trace_remove_is_static_listener() handles NULL (trace)");
2756 ret = bt_ctf_trace_remove_is_static_listener(trace, -2);
2757 ok(ret < 0, "bt_ctf_trace_remove_is_static_listener() handles invalid ID (negative)");
2758 ret = bt_ctf_trace_remove_is_static_listener(trace, 77);
2759 ok(ret < 0, "bt_ctf_trace_remove_is_static_listener() handles invalid ID (non existing)");
2760 ret = bt_ctf_trace_remove_is_static_listener(trace, listener2_id);
2761 ok(ret == 0, "bt_ctf_trace_remove_is_static_listener() succeeds");
2762 listener4_id = bt_ctf_trace_add_is_static_listener(trace,
2763 trace_is_static_listener, &called4);
2764 ok(listener4_id >= 0, "bt_ctf_trace_add_is_static_listener() succeeds (4)");
2765 ok(called1 == 0, "\"trace is static\" listener not called before the trace is made static (1)");
2766 ok(called2 == 0, "\"trace is static\" listener not called before the trace is made static (2)");
2767 ok(called3 == 0, "\"trace is static\" listener not called before the trace is made static (3)");
2768 ok(called4 == 0, "\"trace is static\" listener not called before the trace is made static (4)");
2769 ret = bt_ctf_trace_set_is_static(trace);
2770 assert(ret == 0);
2771 ret = bt_ctf_trace_add_is_static_listener(trace,
2772 trace_is_static_listener, &called1);
2773 ok(ret < 0,
2774 "bt_ctf_trace_add_is_static_listener() fails when the trace is static");
2775 ok(called1 == 1, "\"trace is static\" listener called when the trace is made static (1)");
2776 ok(called2 == 0, "\"trace is static\" listener not called when the trace is made static (2)");
2777 ok(called3 == 1, "\"trace is static\" listener called when the trace is made static (3)");
2778 ok(called4 == 1, "\"trace is static\" listener called when the trace is made static (4)");
2779 called1 = 0;
2780 called2 = 0;
2781 called3 = 0;
2782 called4 = 0;
2783 bt_put(trace);
2784 ok(called1 == 0, "\"trace is static\" listener not called after the trace is put (1)");
2785 ok(called2 == 0, "\"trace is static\" listener not called after the trace is put (2)");
2786 ok(called3 == 0, "\"trace is static\" listener not called after the trace is put (3)");
2787 ok(called4 == 0, "\"trace is static\" listener not called after the trace is put (4)");
2788}
2789
4a32fda0
PP
2790static
2791void test_trace_uuid(void)
2792{
2793 struct bt_ctf_trace *trace;
2794 const unsigned char uuid[] = {
2795 0x35, 0x92, 0x63, 0xab, 0xb4, 0xbe, 0x40, 0xb4,
2796 0xb2, 0x60, 0xd3, 0xf1, 0x3b, 0xb0, 0xd8, 0x59,
2797 };
2798 const unsigned char *ret_uuid;
2799
2800 trace = bt_ctf_trace_create();
2801 assert(trace);
2802 ok(!bt_ctf_trace_get_uuid(NULL),
2803 "bt_ctf_trace_get_uuid() handles NULL");
2804 ok(!bt_ctf_trace_get_uuid(trace),
2805 "bt_ctf_trace_get_uuid() returns NULL initially");
2806 ok(bt_ctf_trace_set_uuid(NULL, uuid),
2807 "bt_ctf_trace_set_uuid() handles NULL (trace)");
2808 ok(bt_ctf_trace_set_uuid(trace, NULL),
2809 "bt_ctf_trace_set_uuid() handles NULL (UUID)");
2810 ok(bt_ctf_trace_set_uuid(trace, uuid) == 0,
2811 "bt_ctf_trace_set_uuid() succeeds with a valid UUID");
2812 ret_uuid = bt_ctf_trace_get_uuid(trace);
2813 ok(ret_uuid, "bt_ctf_trace_get_uuid() returns a UUID");
6de1e606 2814 assert(ret_uuid);
4a32fda0
PP
2815 ok(memcmp(uuid, ret_uuid, 16) == 0,
2816 "bt_ctf_trace_get_uuid() returns the expected UUID");
2817
2818 bt_put(trace);
2819}
2820
39d74371
JG
2821int main(int argc, char **argv)
2822{
2823 char trace_path[] = "/tmp/ctfwriter_XXXXXX";
2824 char metadata_path[sizeof(trace_path) + 9];
2825 const char *clock_name = "test_clock";
2826 const char *clock_description = "This is a test clock";
5494ce8b
JG
2827 const char *returned_clock_name;
2828 const char *returned_clock_description;
2829 const uint64_t frequency = 1123456789;
61cf588b
MD
2830 const int64_t offset_s = 1351530929945824323;
2831 const int64_t offset = 1234567;
2832 int64_t get_offset_s,
61ec14e6 2833 get_offset;
39d74371 2834 const uint64_t precision = 10;
5494ce8b 2835 const int is_absolute = 0xFF;
39d74371
JG
2836 char *metadata_string;
2837 struct bt_ctf_writer *writer;
2838 struct utsname name;
22843b66 2839 char hostname[BABELTRACE_HOST_NAME_MAX];
1ff9582c 2840 struct bt_ctf_clock *clock, *ret_clock;
ac0c6bdd 2841 struct bt_ctf_clock_class *ret_clock_class;
36336d93 2842 struct bt_ctf_stream_class *stream_class, *ret_stream_class;
39d74371 2843 struct bt_ctf_stream *stream1;
c1e730fe 2844 struct bt_ctf_stream *stream;
e3c971da 2845 const char *ret_string;
e61caf8e
JG
2846 const unsigned char *ret_uuid;
2847 unsigned char tmp_uuid[16] = { 0 };
b34f4d90
JG
2848 struct bt_ctf_field_type *packet_context_type,
2849 *packet_context_field_type,
751b05c7
JG
2850 *packet_header_type,
2851 *packet_header_field_type,
35e8709f
JG
2852 *integer_type,
2853 *stream_event_context_type,
88d26616
JG
2854 *ret_field_type,
2855 *event_header_field_type;
751b05c7 2856 struct bt_ctf_field *packet_header, *packet_header_field;
8cdae8c6 2857 struct bt_ctf_trace *trace;
12c8a1a3 2858 int ret;
4ae7c93b 2859 int64_t ret_int64_t;
dac5c838 2860 struct bt_value *obj;
39d74371 2861
dc3fffef
PP
2862 if (argc < 2) {
2863 printf("Usage: tests-ctf-writer path_to_babeltrace\n");
783c9151 2864 return -1;
39d74371
JG
2865 }
2866
8bbe269d 2867 plan_tests(NR_TESTS);
39d74371 2868
2bb37f06 2869 if (!bt_mkdtemp(trace_path)) {
39d74371
JG
2870 perror("# perror");
2871 }
2872
2873 strcpy(metadata_path, trace_path);
2874 strcat(metadata_path + sizeof(trace_path) - 1, "/metadata");
2875
2876 writer = bt_ctf_writer_create(trace_path);
2877 ok(writer, "bt_ctf_create succeeds in creating trace with path");
2878
4ae7c93b
JG
2879 ok(!bt_ctf_writer_get_trace(NULL),
2880 "bt_ctf_writer_get_trace correctly handles NULL");
2881 trace = bt_ctf_writer_get_trace(writer);
5c565c45
PP
2882 ok(bt_ctf_trace_set_native_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE),
2883 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_NATIVE");
2f4b93cd
PP
2884 ok(bt_ctf_trace_set_native_byte_order(trace, BT_CTF_BYTE_ORDER_UNSPECIFIED),
2885 "Cannot set a trace's byte order to BT_CTF_BYTE_ORDER_UNSPECIFIED");
4ae7c93b
JG
2886 ok(trace,
2887 "bt_ctf_writer_get_trace returns a bt_ctf_trace object");
391c8f0d 2888 ok(bt_ctf_trace_set_native_byte_order(trace, BT_CTF_BYTE_ORDER_BIG_ENDIAN) == 0,
35731220 2889 "Set a trace's byte order to big endian");
8a716c8d
PP
2890 ok(bt_ctf_trace_get_native_byte_order(trace) == BT_CTF_BYTE_ORDER_BIG_ENDIAN,
2891 "bt_ctf_trace_get_native_byte_order returns a correct endianness");
4ae7c93b 2892
39d74371 2893 /* Add environment context to the trace */
22843b66
JG
2894 ret = gethostname(hostname, sizeof(hostname));
2895 if (ret < 0) {
2896 return ret;
2897 }
39d74371
JG
2898 ok(bt_ctf_writer_add_environment_field(writer, "host", hostname) == 0,
2899 "Add host (%s) environment field to writer instance",
2900 hostname);
2901 ok(bt_ctf_writer_add_environment_field(NULL, "test_field",
2902 "test_value"),
2903 "bt_ctf_writer_add_environment_field error with NULL writer");
2904 ok(bt_ctf_writer_add_environment_field(writer, NULL,
2905 "test_value"),
2906 "bt_ctf_writer_add_environment_field error with NULL field name");
2907 ok(bt_ctf_writer_add_environment_field(writer, "test_field",
2908 NULL),
2909 "bt_ctf_writer_add_environment_field error with NULL field value");
7f800dc7
PP
2910
2911 /* Test bt_ctf_trace_set_environment_field with an integer object */
dac5c838 2912 obj = bt_value_integer_create_init(23);
7f800dc7
PP
2913 assert(obj);
2914 ok(bt_ctf_trace_set_environment_field(NULL, "test_env_int_obj", obj),
2915 "bt_ctf_trace_set_environment_field handles a NULL trace correctly");
2916 ok(bt_ctf_trace_set_environment_field(trace, NULL, obj),
2917 "bt_ctf_trace_set_environment_field handles a NULL name correctly");
2918 ok(bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", NULL),
2919 "bt_ctf_trace_set_environment_field handles a NULL value correctly");
2920 ok(!bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", obj),
2921 "bt_ctf_trace_set_environment_field succeeds in adding an integer object");
83509119 2922 BT_PUT(obj);
7f800dc7
PP
2923
2924 /* Test bt_ctf_trace_set_environment_field with a string object */
dac5c838 2925 obj = bt_value_string_create_init("the value");
7f800dc7
PP
2926 assert(obj);
2927 ok(!bt_ctf_trace_set_environment_field(trace, "test_env_str_obj", obj),
2928 "bt_ctf_trace_set_environment_field succeeds in adding a string object");
83509119 2929 BT_PUT(obj);
7f800dc7
PP
2930
2931 /* Test bt_ctf_trace_set_environment_field_integer */
2932 ok(bt_ctf_trace_set_environment_field_integer(NULL, "test_env_int",
2933 -194875),
2934 "bt_ctf_trace_set_environment_field_integer handles a NULL trace correctly");
2935 ok(bt_ctf_trace_set_environment_field_integer(trace, NULL, -194875),
2936 "bt_ctf_trace_set_environment_field_integer handles a NULL name correctly");
2937 ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int",
2938 -164973),
2939 "bt_ctf_trace_set_environment_field_integer succeeds");
2940
2941 /* Test bt_ctf_trace_set_environment_field_string */
2942 ok(bt_ctf_trace_set_environment_field_string(NULL, "test_env_str",
2943 "yeah"),
2944 "bt_ctf_trace_set_environment_field_string handles a NULL trace correctly");
2945 ok(bt_ctf_trace_set_environment_field_string(trace, NULL, "yeah"),
2946 "bt_ctf_trace_set_environment_field_string handles a NULL name correctly");
2947 ok(bt_ctf_trace_set_environment_field_string(trace, "test_env_str",
2948 NULL),
2949 "bt_ctf_trace_set_environment_field_string handles a NULL value correctly");
2950 ok(!bt_ctf_trace_set_environment_field_string(trace, "test_env_str",
2951 "oh yeah"),
2952 "bt_ctf_trace_set_environment_field_string succeeds");
4ae7c93b
JG
2953
2954 /* Test bt_ctf_trace_get_environment_field_count */
2955 ok(bt_ctf_trace_get_environment_field_count(NULL) < 0,
2956 "bt_ctf_trace_get_environment_field_count handles a NULL trace correctly");
7f800dc7 2957 ok(bt_ctf_trace_get_environment_field_count(trace) == 5,
4ae7c93b
JG
2958 "bt_ctf_trace_get_environment_field_count returns a correct number of environment fields");
2959
4ae7c93b 2960 /* Test bt_ctf_trace_get_environment_field_name */
9ac68eb1 2961 ok(bt_ctf_trace_get_environment_field_name_by_index(NULL, 0) == NULL,
4ae7c93b 2962 "bt_ctf_trace_get_environment_field_name handles a NULL trace correctly");
9ac68eb1 2963 ok(bt_ctf_trace_get_environment_field_name_by_index(trace, 5) == NULL,
7f800dc7 2964 "bt_ctf_trace_get_environment_field_name handles an invalid index correctly (too large)");
9ac68eb1 2965 ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 0);
4ae7c93b
JG
2966 ok(ret_string && !strcmp(ret_string, "host"),
2967 "bt_ctf_trace_get_environment_field_name returns a correct field name");
9ac68eb1 2968 ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 1);
7f800dc7
PP
2969 ok(ret_string && !strcmp(ret_string, "test_env_int_obj"),
2970 "bt_ctf_trace_get_environment_field_name returns a correct field name");
9ac68eb1 2971 ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 2);
7f800dc7
PP
2972 ok(ret_string && !strcmp(ret_string, "test_env_str_obj"),
2973 "bt_ctf_trace_get_environment_field_name returns a correct field name");
9ac68eb1 2974 ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 3);
7f800dc7
PP
2975 ok(ret_string && !strcmp(ret_string, "test_env_int"),
2976 "bt_ctf_trace_get_environment_field_name returns a correct field name");
9ac68eb1 2977 ret_string = bt_ctf_trace_get_environment_field_name_by_index(trace, 4);
7f800dc7
PP
2978 ok(ret_string && !strcmp(ret_string, "test_env_str"),
2979 "bt_ctf_trace_get_environment_field_name returns a correct field name");
4ae7c93b 2980
7f800dc7 2981 /* Test bt_ctf_trace_get_environment_field_value */
9ac68eb1 2982 ok(bt_ctf_trace_get_environment_field_value_by_index(NULL, 0) == NULL,
7f800dc7 2983 "bt_ctf_trace_get_environment_field_value handles a NULL trace correctly");
9ac68eb1 2984 ok(bt_ctf_trace_get_environment_field_value_by_index(trace, 5) == NULL,
7f800dc7 2985 "bt_ctf_trace_get_environment_field_value handles an invalid index correctly (too large)");
9ac68eb1 2986 obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 1);
dac5c838 2987 ret = bt_value_integer_get(obj, &ret_int64_t);
7f800dc7
PP
2988 ok(!ret && ret_int64_t == 23,
2989 "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value");
83509119 2990 BT_PUT(obj);
9ac68eb1 2991 obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 2);
dac5c838 2992 ret = bt_value_string_get(obj, &ret_string);
7f800dc7
PP
2993 ok(!ret && ret_string && !strcmp(ret_string, "the value"),
2994 "bt_ctf_trace_get_environment_field_value succeeds in getting a string value");
83509119 2995 BT_PUT(obj);
7f800dc7
PP
2996
2997 /* Test bt_ctf_trace_get_environment_field_value_by_name */
2998 ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL,
2999 "test_env_str"),
3000 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL trace correctly");
3001 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace, NULL),
3002 "bt_ctf_trace_get_environment_field_value_by_name handles a NULL name correctly");
3003 ok(!bt_ctf_trace_get_environment_field_value_by_name(trace, "oh oh"),
3004 "bt_ctf_trace_get_environment_field_value_by_name returns NULL or an unknown field name");
3005 obj = bt_ctf_trace_get_environment_field_value_by_name(trace,
3006 "test_env_str");
dac5c838 3007 ret = bt_value_string_get(obj, &ret_string);
7f800dc7
PP
3008 ok(!ret && ret_string && !strcmp(ret_string, "oh yeah"),
3009 "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field");
83509119 3010 BT_PUT(obj);
7f800dc7
PP
3011
3012 /* Test environment field replacement */
3013 ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int",
3014 654321),
3015 "bt_ctf_trace_set_environment_field_integer succeeds with an existing name");
3016 ok(bt_ctf_trace_get_environment_field_count(trace) == 5,
3017 "bt_ctf_trace_set_environment_field_integer with an existing key does not increase the environment size");
9ac68eb1 3018 obj = bt_ctf_trace_get_environment_field_value_by_index(trace, 3);
dac5c838 3019 ret = bt_value_integer_get(obj, &ret_int64_t);
7f800dc7
PP
3020 ok(!ret && ret_int64_t == 654321,
3021 "bt_ctf_trace_get_environment_field_value successfully replaces an existing field");
83509119 3022 BT_PUT(obj);
39d74371 3023
c2d6366f
MJ
3024 /* On Solaris, uname() can return any positive value on success */
3025 if (uname(&name) < 0) {
39d74371
JG
3026 perror("uname");
3027 return -1;
3028 }
3029
3030 ok(bt_ctf_writer_add_environment_field(writer, "sysname", name.sysname)
3031 == 0, "Add sysname (%s) environment field to writer instance",
3032 name.sysname);
3033 ok(bt_ctf_writer_add_environment_field(writer, "nodename",
3034 name.nodename) == 0,
3035 "Add nodename (%s) environment field to writer instance",
3036 name.nodename);
3037 ok(bt_ctf_writer_add_environment_field(writer, "release", name.release)
3038 == 0, "Add release (%s) environment field to writer instance",
3039 name.release);
3040 ok(bt_ctf_writer_add_environment_field(writer, "version", name.version)
3041 == 0, "Add version (%s) environment field to writer instance",
3042 name.version);
3043 ok(bt_ctf_writer_add_environment_field(writer, "machine", name.machine)
3044 == 0, "Add machine (%s) environment field to writer istance",
3045 name.machine);
3046
3047 /* Define a clock and add it to the trace */
5494ce8b
JG
3048 ok(bt_ctf_clock_create("signed") == NULL,
3049 "Illegal clock name rejected");
39d74371
JG
3050 clock = bt_ctf_clock_create(clock_name);
3051 ok(clock, "Clock created sucessfully");
5494ce8b
JG
3052 returned_clock_name = bt_ctf_clock_get_name(clock);
3053 ok(returned_clock_name, "bt_ctf_clock_get_name returns a clock name");
d50c7132 3054 ok(returned_clock_name ? !strcmp(returned_clock_name, clock_name) : 0,
5494ce8b
JG
3055 "Returned clock name is valid");
3056
3057 returned_clock_description = bt_ctf_clock_get_description(clock);
3058 ok(!returned_clock_description, "bt_ctf_clock_get_description returns NULL on an unset description");
3059 ok(bt_ctf_clock_set_description(clock, clock_description) == 0,
3060 "Clock description set successfully");
3061
3062 returned_clock_description = bt_ctf_clock_get_description(clock);
3063 ok(returned_clock_description,
3064 "bt_ctf_clock_get_description returns a description.");
d50c7132
JG
3065 ok(returned_clock_description ?
3066 !strcmp(returned_clock_description, clock_description) : 0,
5494ce8b
JG
3067 "Returned clock description is valid");
3068
3069 ok(bt_ctf_clock_get_frequency(clock) == DEFAULT_CLOCK_FREQ,
3070 "bt_ctf_clock_get_frequency returns the correct default frequency");
39d74371
JG
3071 ok(bt_ctf_clock_set_frequency(clock, frequency) == 0,
3072 "Set clock frequency");
5494ce8b
JG
3073 ok(bt_ctf_clock_get_frequency(clock) == frequency,
3074 "bt_ctf_clock_get_frequency returns the correct frequency once it is set");
3075
61cf588b
MD
3076 ok(bt_ctf_clock_get_offset_s(clock, &get_offset_s) == 0,
3077 "bt_ctf_clock_get_offset_s succeeds");
3078 ok(get_offset_s == DEFAULT_CLOCK_OFFSET_S,
5494ce8b 3079 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)");
39d74371
JG
3080 ok(bt_ctf_clock_set_offset_s(clock, offset_s) == 0,
3081 "Set clock offset (seconds)");
61cf588b
MD
3082 ok(bt_ctf_clock_get_offset_s(clock, &get_offset_s) == 0,
3083 "bt_ctf_clock_get_offset_s succeeds");
3084 ok(get_offset_s == offset_s,
5494ce8b
JG
3085 "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set");
3086
61cf588b
MD
3087 ok(bt_ctf_clock_get_offset(clock, &get_offset) == 0,
3088 "bt_ctf_clock_get_offset succeeds");
3089 ok(get_offset == DEFAULT_CLOCK_OFFSET,
3090 "bt_ctf_clock_get_offset returns the correct default offset (in ticks)");
39d74371 3091 ok(bt_ctf_clock_set_offset(clock, offset) == 0, "Set clock offset");
61cf588b
MD
3092 ok(bt_ctf_clock_get_offset(clock, &get_offset) == 0,
3093 "bt_ctf_clock_get_offset succeeds");
3094 ok(get_offset == offset,
3095 "bt_ctf_clock_get_offset returns the correct default offset (in ticks) once it is set");
5494ce8b
JG
3096
3097 ok(bt_ctf_clock_get_precision(clock) == DEFAULT_CLOCK_PRECISION,
3098 "bt_ctf_clock_get_precision returns the correct default precision");
39d74371
JG
3099 ok(bt_ctf_clock_set_precision(clock, precision) == 0,
3100 "Set clock precision");
5494ce8b
JG
3101 ok(bt_ctf_clock_get_precision(clock) == precision,
3102 "bt_ctf_clock_get_precision returns the correct precision once it is set");
3103
3104 ok(bt_ctf_clock_get_is_absolute(clock) == DEFAULT_CLOCK_IS_ABSOLUTE,
3105 "bt_ctf_clock_get_precision returns the correct default is_absolute attribute");
3106 ok(bt_ctf_clock_set_is_absolute(clock, is_absolute) == 0,
39d74371 3107 "Set clock absolute property");
5494ce8b
JG
3108 ok(bt_ctf_clock_get_is_absolute(clock) == !!is_absolute,
3109 "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
3110
5494ce8b
JG
3111 ok(bt_ctf_clock_set_time(clock, current_time) == 0,
3112 "Set clock time");
39d74371 3113
5494ce8b
JG
3114 ok(!bt_ctf_clock_get_name(NULL),
3115 "bt_ctf_clock_get_name correctly handles NULL");
3116 ok(!bt_ctf_clock_get_description(NULL),
3117 "bt_ctf_clock_get_description correctly handles NULL");
3118 ok(bt_ctf_clock_get_frequency(NULL) == -1ULL,
3119 "bt_ctf_clock_get_frequency correctly handles NULL");
3120 ok(bt_ctf_clock_get_precision(NULL) == -1ULL,
3121 "bt_ctf_clock_get_precision correctly handles NULL");
61cf588b
MD
3122 ok(bt_ctf_clock_get_offset_s(NULL, &get_offset_s) < 0,
3123 "bt_ctf_clock_get_offset_s correctly handles NULL clock");
3124 ok(bt_ctf_clock_get_offset_s(clock, NULL) < 0,
3125 "bt_ctf_clock_get_offset_s correctly handles NULL output");
3126 ok(bt_ctf_clock_get_offset(NULL, &get_offset) < 0,
3127 "bt_ctf_clock_get_offset correctly handles NULL clock");
3128 ok(bt_ctf_clock_get_offset(clock, NULL) < 0,
3129 "bt_ctf_clock_get_offset correctly handles NULL output");
3c1d148b 3130 ok(bt_ctf_clock_get_is_absolute(NULL) < 0,
5494ce8b 3131 "bt_ctf_clock_get_is_absolute correctly handles NULL");
5494ce8b 3132
3c1d148b 3133 ok(bt_ctf_clock_set_description(NULL, NULL) < 0,
5494ce8b 3134 "bt_ctf_clock_set_description correctly handles NULL clock");
3c1d148b 3135 ok(bt_ctf_clock_set_frequency(NULL, frequency) < 0,
5494ce8b 3136 "bt_ctf_clock_set_frequency correctly handles NULL clock");
3c1d148b 3137 ok(bt_ctf_clock_set_precision(NULL, precision) < 0,
5494ce8b 3138 "bt_ctf_clock_get_precision correctly handles NULL clock");
3c1d148b 3139 ok(bt_ctf_clock_set_offset_s(NULL, offset_s) < 0,
5494ce8b 3140 "bt_ctf_clock_set_offset_s correctly handles NULL clock");
3c1d148b 3141 ok(bt_ctf_clock_set_offset(NULL, offset) < 0,
5494ce8b 3142 "bt_ctf_clock_set_offset correctly handles NULL clock");
3c1d148b 3143 ok(bt_ctf_clock_set_is_absolute(NULL, is_absolute) < 0,
5494ce8b 3144 "bt_ctf_clock_set_is_absolute correctly handles NULL clock");
3c1d148b 3145 ok(bt_ctf_clock_set_time(NULL, current_time) < 0,
5494ce8b 3146 "bt_ctf_clock_set_time correctly handles NULL clock");
e61caf8e
JG
3147 ok(bt_ctf_clock_get_uuid(NULL) == NULL,
3148 "bt_ctf_clock_get_uuid correctly handles NULL clock");
3149 ret_uuid = bt_ctf_clock_get_uuid(clock);
3150 ok(ret_uuid,
3151 "bt_ctf_clock_get_uuid returns a UUID");
3152 if (ret_uuid) {
3153 memcpy(tmp_uuid, ret_uuid, sizeof(tmp_uuid));
3154 /* Slightly modify UUID */
3155 tmp_uuid[sizeof(tmp_uuid) - 1]++;
3156 }
3157
3158 ok(bt_ctf_clock_set_uuid(NULL, tmp_uuid) < 0,
3159 "bt_ctf_clock_set_uuid correctly handles a NULL clock");
3160 ok(bt_ctf_clock_set_uuid(clock, NULL) < 0,
3161 "bt_ctf_clock_set_uuid correctly handles a NULL UUID");
3162 ok(bt_ctf_clock_set_uuid(clock, tmp_uuid) == 0,
4caab45b 3163 "bt_ctf_clock_set_uuid sets a new uuid successfully");
e61caf8e
JG
3164 ret_uuid = bt_ctf_clock_get_uuid(clock);
3165 ok(ret_uuid,
3166 "bt_ctf_clock_get_uuid returns a UUID after setting a new one");
3167 ok(uuid_match(ret_uuid, tmp_uuid),
3168 "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one");
5494ce8b 3169
39d74371
JG
3170 /* Define a stream class */
3171 stream_class = bt_ctf_stream_class_create("test_stream");
e3c971da
JG
3172
3173 ok(bt_ctf_stream_class_get_name(NULL) == NULL,
3174 "bt_ctf_stream_class_get_name handles NULL correctly");
3175 ret_string = bt_ctf_stream_class_get_name(stream_class);
88d26616 3176 ok(ret_string && !strcmp(ret_string, "test_stream"),
12c8a1a3 3177 "bt_ctf_stream_class_get_name returns a correct stream class name");
e3c971da 3178
1ff9582c
JG
3179 ok(bt_ctf_stream_class_get_clock(stream_class) == NULL,
3180 "bt_ctf_stream_class_get_clock returns NULL when a clock was not set");
3181 ok(bt_ctf_stream_class_get_clock(NULL) == NULL,
3182 "bt_ctf_stream_class_get_clock handles NULL correctly");
3183
39d74371
JG
3184 ok(stream_class, "Create stream class");
3185 ok(bt_ctf_stream_class_set_clock(stream_class, clock) == 0,
3186 "Set a stream class' clock");
1ff9582c
JG
3187 ret_clock = bt_ctf_stream_class_get_clock(stream_class);
3188 ok(ret_clock == clock,
3189 "bt_ctf_stream_class_get_clock returns a correct clock");
83509119 3190 bt_put(ret_clock);
39d74371
JG
3191
3192 /* Test the event fields and event types APIs */
3193 type_field_tests();
3194
e7cb4506
PP
3195 /* Test fields copying */
3196 field_copy_tests();
3197
1ff9582c
JG
3198 ok(bt_ctf_stream_class_get_id(stream_class) < 0,
3199 "bt_ctf_stream_class_get_id returns an error when no id is set");
3200 ok(bt_ctf_stream_class_get_id(NULL) < 0,
3201 "bt_ctf_stream_class_get_id handles NULL correctly");
3202 ok(bt_ctf_stream_class_set_id(NULL, 123) < 0,
3203 "bt_ctf_stream_class_set_id handles NULL correctly");
3204 ok(bt_ctf_stream_class_set_id(stream_class, 123) == 0,
3205 "Set an stream class' id");
3206 ok(bt_ctf_stream_class_get_id(stream_class) == 123,
3207 "bt_ctf_stream_class_get_id returns the correct value");
3208
d8469458 3209 /* Validate default event header fields */
88d26616
JG
3210 ok(bt_ctf_stream_class_get_event_header_type(NULL) == NULL,
3211 "bt_ctf_stream_class_get_event_header_type handles NULL correctly");
3212 ret_field_type = bt_ctf_stream_class_get_event_header_type(
3213 stream_class);
3214 ok(ret_field_type,
3215 "bt_ctf_stream_class_get_event_header_type returns an event header type");
1487a16a 3216 ok(bt_ctf_field_type_get_type_id(ret_field_type) == BT_CTF_FIELD_TYPE_ID_STRUCT,
88d26616
JG
3217 "Default event header type is a structure");
3218 event_header_field_type =
3219 bt_ctf_field_type_structure_get_field_type_by_name(
3220 ret_field_type, "id");
3221 ok(event_header_field_type,
3222 "Default event header type contains an \"id\" field");
3223 ok(bt_ctf_field_type_get_type_id(
1487a16a 3224 event_header_field_type) == BT_CTF_FIELD_TYPE_ID_INTEGER,
88d26616 3225 "Default event header \"id\" field is an integer");
83509119 3226 bt_put(event_header_field_type);
88d26616
JG
3227 event_header_field_type =
3228 bt_ctf_field_type_structure_get_field_type_by_name(
3229 ret_field_type, "timestamp");
3230 ok(event_header_field_type,
3231 "Default event header type contains a \"timestamp\" field");
3232 ok(bt_ctf_field_type_get_type_id(
1487a16a 3233 event_header_field_type) == BT_CTF_FIELD_TYPE_ID_INTEGER,
88d26616 3234 "Default event header \"timestamp\" field is an integer");
83509119
JG
3235 bt_put(event_header_field_type);
3236 bt_put(ret_field_type);
88d26616 3237
751b05c7
JG
3238 /* Add a custom trace packet header field */
3239 ok(bt_ctf_trace_get_packet_header_type(NULL) == NULL,
3240 "bt_ctf_trace_get_packet_header_type handles NULL correctly");
3241 packet_header_type = bt_ctf_trace_get_packet_header_type(trace);
3242 ok(packet_header_type,
3243 "bt_ctf_trace_get_packet_header_type returns a packet header");
1487a16a 3244 ok(bt_ctf_field_type_get_type_id(packet_header_type) == BT_CTF_FIELD_TYPE_ID_STRUCT,
751b05c7
JG
3245 "bt_ctf_trace_get_packet_header_type returns a packet header of type struct");
3246 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
3247 packet_header_type, "magic");
3248 ok(ret_field_type, "Default packet header type contains a \"magic\" field");
83509119 3249 bt_put(ret_field_type);
751b05c7
JG
3250 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
3251 packet_header_type, "uuid");
3252 ok(ret_field_type, "Default packet header type contains a \"uuid\" field");
83509119 3253 bt_put(ret_field_type);
751b05c7
JG
3254 ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
3255 packet_header_type, "stream_id");
3256 ok(ret_field_type, "Default packet header type contains a \"stream_id\" field");
83509119 3257 bt_put(ret_field_type);
751b05c7
JG
3258
3259 packet_header_field_type = bt_ctf_field_type_integer_create(22);
3260 ok(!bt_ctf_field_type_structure_add_field(packet_header_type,
3261 packet_header_field_type, "custom_trace_packet_header_field"),
3262 "Added a custom trace packet header field successfully");
3263
3264 ok(bt_ctf_trace_set_packet_header_type(NULL, packet_header_type) < 0,
3265 "bt_ctf_trace_set_packet_header_type handles a NULL trace correctly");
751b05c7
JG
3266 ok(!bt_ctf_trace_set_packet_header_type(trace, packet_header_type),
3267 "Set a trace packet_header_type successfully");
3268
12c8a1a3
JG
3269 ok(bt_ctf_stream_class_get_packet_context_type(NULL) == NULL,
3270 "bt_ctf_stream_class_get_packet_context_type handles NULL correctly");
3271
3272 /* Add a custom field to the stream class' packet context */
3273 packet_context_type = bt_ctf_stream_class_get_packet_context_type(stream_class);
3274 ok(packet_context_type,
3275 "bt_ctf_stream_class_get_packet_context_type returns a packet context type.");
1487a16a 3276 ok(bt_ctf_field_type_get_type_id(packet_context_type) == BT_CTF_FIELD_TYPE_ID_STRUCT,
12c8a1a3
JG
3277 "Packet context is a structure");
3278
3279 ok(bt_ctf_stream_class_set_packet_context_type(NULL, packet_context_type),
3280 "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly");
b34f4d90
JG
3281
3282 integer_type = bt_ctf_field_type_integer_create(32);
3283 ok(bt_ctf_stream_class_set_packet_context_type(stream_class,
3284 integer_type) < 0,
3285 "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure");
88d26616
JG
3286 /* Create a "uint5_t" equivalent custom packet context field */
3287 packet_context_field_type = bt_ctf_field_type_integer_create(5);
3288
12c8a1a3 3289 ret = bt_ctf_field_type_structure_add_field(packet_context_type,
35e8709f 3290 packet_context_field_type, "custom_packet_context_field");
12c8a1a3
JG
3291 ok(ret == 0, "Packet context field added successfully");
3292
35e8709f
JG
3293 /* Define a stream event context containing a my_integer field. */
3294 ok(bt_ctf_stream_class_get_event_context_type(NULL) == NULL,
3295 "bt_ctf_stream_class_get_event_context_type handles NULL correctly");
35e8709f
JG
3296 stream_event_context_type = bt_ctf_field_type_structure_create();
3297 bt_ctf_field_type_structure_add_field(stream_event_context_type,
3298 integer_type, "common_event_context");
3299
3300 ok(bt_ctf_stream_class_set_event_context_type(NULL,
3301 stream_event_context_type) < 0,
3302 "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly");
35e8709f
JG
3303 ok(bt_ctf_stream_class_set_event_context_type(stream_class,
3304 integer_type) < 0,
3305 "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure");
3306
3307 ok(bt_ctf_stream_class_set_event_context_type(
3308 stream_class, stream_event_context_type) == 0,
3309 "Set a new stream event context type");
3310 ret_field_type = bt_ctf_stream_class_get_event_context_type(
3311 stream_class);
3312 ok(ret_field_type == stream_event_context_type,
3313 "bt_ctf_stream_class_get_event_context_type returns the correct field type.");
83509119 3314 bt_put(ret_field_type);
12c8a1a3 3315
39d74371 3316 /* Instantiate a stream and append events */
ac0c6bdd
PP
3317 ret = bt_ctf_writer_add_clock(writer, clock);
3318 assert(ret == 0);
c1e730fe
PP
3319 ok(bt_ctf_trace_get_stream_count(trace) == 0,
3320 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (0)");
39d74371
JG
3321 stream1 = bt_ctf_writer_create_stream(writer, stream_class);
3322 ok(stream1, "Instanciate a stream class from writer");
c1e730fe
PP
3323 ok(bt_ctf_trace_get_stream_count(trace) == 1,
3324 "bt_ctf_trace_get_stream_count() succeeds and returns the correct value (1)");
9ac68eb1 3325 stream = bt_ctf_trace_get_stream_by_index(trace, 0);
c1e730fe 3326 ok(stream == stream1,
9ac68eb1 3327 "bt_ctf_trace_get_stream_by_index() succeeds and returns the correct value");
c1e730fe 3328 BT_PUT(stream);
39d74371 3329
b25d20ad
PP
3330 /*
3331 * Creating a stream through a writer adds the given stream
3332 * class to the writer's trace, thus registering the stream
3333 * class's clock to the trace.
3334 */
ac0c6bdd
PP
3335 ok(bt_ctf_trace_get_clock_class_count(NULL) < 0,
3336 "bt_ctf_trace_get_clock_class_count correctly handles NULL");
3337 ok(bt_ctf_trace_get_clock_class_count(trace) == 1,
3338 "bt_ctf_trace_get_clock_class_count returns the correct number of clocks");
9ac68eb1 3339 ok(!bt_ctf_trace_get_clock_class_by_index(NULL, 0),
ac0c6bdd 3340 "bt_ctf_trace_get_clock_class correctly handles NULL");
9ac68eb1 3341 ok(!bt_ctf_trace_get_clock_class_by_index(trace, 1),
ac0c6bdd 3342 "bt_ctf_trace_get_clock_class correctly handles out of bound accesses");
9ac68eb1 3343 ret_clock_class = bt_ctf_trace_get_clock_class_by_index(trace, 0);
ac0c6bdd
PP
3344 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class),
3345 bt_ctf_clock_get_name(clock)) == 0,
3346 "bt_ctf_trace_get_clock_class returns the right clock instance");
3347 bt_put(ret_clock_class);
3348 ok(!bt_ctf_trace_get_clock_class_by_name(trace, NULL),
3349 "bt_ctf_trace_get_clock_class_by_name correctly handles NULL (trace)");
3350 ok(!bt_ctf_trace_get_clock_class_by_name(NULL, clock_name),
b25d20ad 3351 "bt_ctf_trace_get_clock_by_name correctly handles NULL (clock name)");
ac0c6bdd 3352 ok(!bt_ctf_trace_get_clock_class_by_name(NULL, NULL),
b25d20ad 3353 "bt_ctf_trace_get_clock_by_name correctly handles NULL (both)");
ac0c6bdd
PP
3354 ret_clock_class = bt_ctf_trace_get_clock_class_by_name(trace, clock_name);
3355 ok(strcmp(bt_ctf_clock_class_get_name(ret_clock_class),
3356 bt_ctf_clock_get_name(clock)) == 0,
3357 "bt_ctf_trace_get_clock_class returns the right clock instance");
3358 bt_put(ret_clock_class);
3359 ok(!bt_ctf_trace_get_clock_class_by_name(trace, "random"),
b25d20ad
PP
3360 "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist");
3361
36336d93
JG
3362 ok(bt_ctf_stream_get_class(NULL) == NULL,
3363 "bt_ctf_stream_get_class correctly handles NULL");
3364 ret_stream_class = bt_ctf_stream_get_class(stream1);
3365 ok(ret_stream_class,
3366 "bt_ctf_stream_get_class returns a stream class");
3367 ok(ret_stream_class == stream_class,
3368 "Returned stream class is of the correct type");
3369
09840de5
PP
3370 /*
3371 * Packet header, packet context, event header, and stream
3372 * event context types were copied for the resolving
3373 * process
3374 */
3375 BT_PUT(packet_header_type);
3376 BT_PUT(packet_context_type);
3377 BT_PUT(stream_event_context_type);
3378 packet_header_type = bt_ctf_trace_get_packet_header_type(trace);
3379 assert(packet_header_type);
3380 packet_context_type =
3381 bt_ctf_stream_class_get_packet_context_type(stream_class);
3382 assert(packet_context_type);
3383 stream_event_context_type =
3384 bt_ctf_stream_class_get_event_context_type(stream_class);
3385 assert(stream_event_context_type);
3386
751b05c7
JG
3387 /*
3388 * Try to modify the packet context type after a stream has been
3389 * created.
3390 */
3391 ret = bt_ctf_field_type_structure_add_field(packet_header_type,
3392 packet_header_field_type, "should_fail");
3393 ok(ret < 0,
3394 "Trace packet header type can't be modified once a stream has been instanciated");
3395
12c8a1a3
JG
3396 /*
3397 * Try to modify the packet context type after a stream has been
3398 * created.
3399 */
3400 ret = bt_ctf_field_type_structure_add_field(packet_context_type,
3401 packet_context_field_type, "should_fail");
3402 ok(ret < 0,
751b05c7 3403 "Packet context type can't be modified once a stream has been instanciated");
12c8a1a3 3404
35e8709f
JG
3405 /*
3406 * Try to modify the stream event context type after a stream has been
3407 * created.
3408 */
3409 ret = bt_ctf_field_type_structure_add_field(stream_event_context_type,
3410 integer_type, "should_fail");
3411 ok(ret < 0,
751b05c7 3412 "Stream event context type can't be modified once a stream has been instanciated");
35e8709f
JG
3413
3414 /* Should fail after instanciating a stream (frozen) */
39d74371
JG
3415 ok(bt_ctf_stream_class_set_clock(stream_class, clock),
3416 "Changes to a stream class that was already instantiated fail");
3417
751b05c7
JG
3418 /* Populate the custom packet header field only once for all tests */
3419 ok(bt_ctf_stream_get_packet_header(NULL) == NULL,
3420 "bt_ctf_stream_get_packet_header handles NULL correctly");
3421 packet_header = bt_ctf_stream_get_packet_header(stream1);
3422 ok(packet_header,
3423 "bt_ctf_stream_get_packet_header returns a packet header");
3424 ret_field_type = bt_ctf_field_get_type(packet_header);
3425 ok(ret_field_type == packet_header_type,
3426 "Stream returns a packet header of the appropriate type");
83509119 3427 bt_put(ret_field_type);
751b05c7
JG
3428 packet_header_field = bt_ctf_field_structure_get_field(packet_header,
3429 "custom_trace_packet_header_field");
3430 ok(packet_header_field,
3431 "Packet header structure contains a custom field with the appropriate name");
3432 ret_field_type = bt_ctf_field_get_type(packet_header_field);
09840de5 3433 ok(bt_ctf_field_type_compare(ret_field_type, packet_header_field_type) == 0,
751b05c7
JG
3434 "Custom packet header field is of the expected type");
3435 ok(!bt_ctf_field_unsigned_integer_set_value(packet_header_field,
3436 54321), "Set custom packet header value successfully");
3437 ok(bt_ctf_stream_set_packet_header(stream1, NULL) < 0,
3438 "bt_ctf_stream_set_packet_header handles a NULL packet header correctly");
3439 ok(bt_ctf_stream_set_packet_header(NULL, packet_header) < 0,
3440 "bt_ctf_stream_set_packet_header handles a NULL stream correctly");
3441 ok(bt_ctf_stream_set_packet_header(stream1, packet_header_field) < 0,
3442 "bt_ctf_stream_set_packet_header rejects a packet header of the wrong type");
3443 ok(!bt_ctf_stream_set_packet_header(stream1, packet_header),
3444 "Successfully set a stream's packet header");
3445
3975bd7e
JG
3446 ok(bt_ctf_writer_add_environment_field(writer, "new_field", "test") == 0,
3447 "Add environment field to writer after stream creation");
3448
44e0165b
PP
3449 test_clock_utils();
3450
bcd3a967 3451 test_create_writer_vs_non_writer_mode();
44ac03eb 3452
ac0c6bdd
PP
3453 test_set_clock_non_writer_stream_class();
3454
3455 test_instanciate_event_before_stream(writer, clock);
42f45a8d 3456
39d74371
JG
3457 append_simple_event(stream_class, stream1, clock);
3458
3459 packet_resize_test(stream_class, stream1, clock);
3460
3461 append_complex_event(stream_class, stream1, clock);
3462
f60fde63
PP
3463 append_existing_event_class(stream_class);
3464
fdf80f32
JG
3465 test_empty_stream(writer);
3466
ac0c6bdd 3467 test_custom_event_header_stream(writer, clock);
29be776a 3468
28437b95
PP
3469 test_static_trace();
3470
d40a81d5
PP
3471 test_trace_is_static_listener();
3472
4a32fda0
PP
3473 test_trace_uuid();
3474
39d74371
JG
3475 metadata_string = bt_ctf_writer_get_metadata_string(writer);
3476 ok(metadata_string, "Get metadata string");
3477
3478 bt_ctf_writer_flush_metadata(writer);
39d74371 3479
83509119
JG
3480 bt_put(clock);
3481 bt_put(ret_stream_class);
3482 bt_put(writer);
3483 bt_put(stream1);
3484 bt_put(packet_context_type);
3485 bt_put(packet_context_field_type);
3486 bt_put(integer_type);
3487 bt_put(stream_event_context_type);
3488 bt_put(ret_field_type);
3489 bt_put(packet_header_type);
3490 bt_put(packet_header_field_type);
3491 bt_put(packet_header);
3492 bt_put(packet_header_field);
3493 bt_put(trace);
39d74371 3494 free(metadata_string);
83509119 3495 bt_put(stream_class);
9b068522 3496
dc3fffef 3497 validate_trace(argv[1], trace_path);
245bd444 3498
dc3fffef 3499 //recursive_rmdir(trace_path);
39d74371
JG
3500 return 0;
3501}
This page took 0.233568 seconds and 4 git commands to generate.