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