Commit | Line | Data |
---|---|---|
39d74371 JG |
1 | /* |
2 | * test-ctf-writer.c | |
3 | * | |
4 | * CTF Writer test | |
5 | * | |
6 | * Copyright 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
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 | ||
22 | #define _GNU_SOURCE | |
23 | #include <babeltrace/ctf-writer/writer.h> | |
24 | #include <babeltrace/ctf-writer/clock.h> | |
25 | #include <babeltrace/ctf-writer/stream.h> | |
26 | #include <babeltrace/ctf-writer/event.h> | |
27 | #include <babeltrace/ctf-writer/event-types.h> | |
28 | #include <babeltrace/ctf-writer/event-fields.h> | |
29 | #include <babeltrace/ctf/events.h> | |
30 | #include <unistd.h> | |
31 | #include <stdlib.h> | |
32 | #include <stdio.h> | |
33 | #include <sys/utsname.h> | |
22843b66 | 34 | #include <babeltrace/compat/limits.h> |
39d74371 JG |
35 | #include <string.h> |
36 | #include <assert.h> | |
39d74371 JG |
37 | #include <sys/wait.h> |
38 | #include <fcntl.h> | |
39 | #include <dirent.h> | |
40 | #include "tap/tap.h" | |
10817e06 JG |
41 | #include <math.h> |
42 | #include <float.h> | |
39d74371 JG |
43 | |
44 | #define METADATA_LINE_SIZE 512 | |
45 | #define SEQUENCE_TEST_LENGTH 10 | |
1fac895e | 46 | #define ARRAY_TEST_LENGTH 5 |
39d74371 JG |
47 | #define PACKET_RESIZE_TEST_LENGTH 100000 |
48 | ||
5494ce8b JG |
49 | #define DEFAULT_CLOCK_FREQ 1000000000 |
50 | #define DEFAULT_CLOCK_PRECISION 1 | |
51 | #define DEFAULT_CLOCK_OFFSET 0 | |
52 | #define DEFAULT_CLOCK_OFFSET_S 0 | |
53 | #define DEFAULT_CLOCK_IS_ABSOLUTE 0 | |
54 | #define DEFAULT_CLOCK_TIME 0 | |
55 | ||
56 | static uint64_t current_time = 42; | |
39d74371 | 57 | |
e61caf8e JG |
58 | /* Return 1 if uuids match, zero if different. */ |
59 | int uuid_match(const unsigned char *uuid_a, const unsigned char *uuid_b) | |
60 | { | |
61 | int ret = 0; | |
62 | int i; | |
63 | ||
64 | if (!uuid_a || !uuid_b) { | |
65 | goto end; | |
66 | } | |
67 | ||
23f1c913 | 68 | for (i = 0; i < 16; i++) { |
e61caf8e JG |
69 | if (uuid_a[i] != uuid_b[i]) { |
70 | goto end; | |
71 | } | |
72 | } | |
73 | ||
74 | ret = 1; | |
75 | end: | |
76 | return ret; | |
77 | } | |
78 | ||
39d74371 JG |
79 | void validate_metadata(char *parser_path, char *metadata_path) |
80 | { | |
81 | int ret = 0; | |
82 | char parser_output_path[] = "/tmp/parser_output_XXXXXX"; | |
83 | int parser_output_fd = -1, metadata_fd = -1; | |
84 | ||
85 | if (!metadata_path) { | |
86 | ret = -1; | |
87 | goto result; | |
88 | } | |
89 | ||
90 | parser_output_fd = mkstemp(parser_output_path); | |
91 | metadata_fd = open(metadata_path, O_RDONLY); | |
92 | ||
93 | unlink(parser_output_path); | |
94 | ||
95 | if (parser_output_fd == -1 || metadata_fd == -1) { | |
96 | diag("Failed create temporary files for metadata parsing."); | |
97 | ret = -1; | |
98 | goto result; | |
99 | } | |
100 | ||
101 | pid_t pid = fork(); | |
102 | if (pid) { | |
103 | int status = 0; | |
104 | waitpid(pid, &status, 0); | |
105 | ret = WIFEXITED(status) ? WEXITSTATUS(status) : -1; | |
106 | } else { | |
107 | /* ctf-parser-test expects a metadata string on stdin. */ | |
108 | ret = dup2(metadata_fd, STDIN_FILENO); | |
109 | if (ret < 0) { | |
110 | perror("# dup2 metadata_fd to STDIN"); | |
111 | goto result; | |
112 | } | |
113 | ||
114 | ret = dup2(parser_output_fd, STDOUT_FILENO); | |
115 | if (ret < 0) { | |
116 | perror("# dup2 parser_output_fd to STDOUT"); | |
117 | goto result; | |
118 | } | |
119 | ||
120 | ret = dup2(parser_output_fd, STDERR_FILENO); | |
121 | if (ret < 0) { | |
122 | perror("# dup2 parser_output_fd to STDERR"); | |
123 | goto result; | |
124 | } | |
125 | ||
126 | execl(parser_path, "ctf-parser-test", NULL); | |
127 | perror("# Could not launch the ctf metadata parser process"); | |
128 | exit(-1); | |
129 | } | |
130 | result: | |
131 | ok(ret == 0, "Metadata string is valid"); | |
132 | ||
25afa9e5 | 133 | if (ret && metadata_fd >= 0 && parser_output_fd >= 0) { |
39d74371 JG |
134 | char *line; |
135 | size_t len = METADATA_LINE_SIZE; | |
136 | FILE *metadata_fp = NULL, *parser_output_fp = NULL; | |
137 | ||
138 | metadata_fp = fdopen(metadata_fd, "r"); | |
139 | if (!metadata_fp) { | |
140 | perror("fdopen on metadata_fd"); | |
141 | goto close_fp; | |
142 | } | |
e1d776cd | 143 | metadata_fd = -1; |
39d74371 JG |
144 | |
145 | parser_output_fp = fdopen(parser_output_fd, "r"); | |
146 | if (!parser_output_fp) { | |
147 | perror("fdopen on parser_output_fd"); | |
148 | goto close_fp; | |
149 | } | |
e1d776cd | 150 | parser_output_fd = -1; |
39d74371 JG |
151 | |
152 | line = malloc(len); | |
153 | if (!line) { | |
154 | diag("malloc failure"); | |
155 | } | |
156 | ||
157 | rewind(metadata_fp); | |
158 | ||
159 | /* Output the metadata and parser output as diagnostic */ | |
160 | while (getline(&line, &len, metadata_fp) > 0) { | |
161 | diag("%s", line); | |
162 | } | |
163 | ||
164 | rewind(parser_output_fp); | |
165 | while (getline(&line, &len, parser_output_fp) > 0) { | |
166 | diag("%s", line); | |
167 | } | |
168 | ||
169 | free(line); | |
170 | close_fp: | |
e1d776cd MD |
171 | if (metadata_fp) { |
172 | if (fclose(metadata_fp)) { | |
173 | diag("fclose failure"); | |
174 | } | |
175 | } | |
176 | if (parser_output_fp) { | |
177 | if (fclose(parser_output_fp)) { | |
178 | diag("fclose failure"); | |
179 | } | |
180 | } | |
39d74371 JG |
181 | } |
182 | ||
25afa9e5 | 183 | if (parser_output_fd >= 0) { |
e1d776cd MD |
184 | if (close(parser_output_fd)) { |
185 | diag("close error"); | |
186 | } | |
187 | } | |
25afa9e5 | 188 | if (metadata_fd >= 0) { |
e1d776cd MD |
189 | if (close(metadata_fd)) { |
190 | diag("close error"); | |
191 | } | |
192 | } | |
39d74371 JG |
193 | } |
194 | ||
195 | void validate_trace(char *parser_path, char *trace_path) | |
196 | { | |
197 | int ret = 0; | |
198 | char babeltrace_output_path[] = "/tmp/babeltrace_output_XXXXXX"; | |
199 | int babeltrace_output_fd = -1; | |
200 | ||
201 | if (!trace_path) { | |
202 | ret = -1; | |
203 | goto result; | |
204 | } | |
205 | ||
206 | babeltrace_output_fd = mkstemp(babeltrace_output_path); | |
207 | unlink(babeltrace_output_path); | |
208 | ||
209 | if (babeltrace_output_fd == -1) { | |
210 | diag("Failed to create a temporary file for trace parsing."); | |
211 | ret = -1; | |
212 | goto result; | |
213 | } | |
214 | ||
215 | pid_t pid = fork(); | |
216 | if (pid) { | |
217 | int status = 0; | |
218 | waitpid(pid, &status, 0); | |
219 | ret = WIFEXITED(status) ? WEXITSTATUS(status) : -1; | |
220 | } else { | |
221 | ret = dup2(babeltrace_output_fd, STDOUT_FILENO); | |
222 | if (ret < 0) { | |
223 | perror("# dup2 babeltrace_output_fd to STDOUT"); | |
224 | goto result; | |
225 | } | |
226 | ||
227 | ret = dup2(babeltrace_output_fd, STDERR_FILENO); | |
228 | if (ret < 0) { | |
229 | perror("# dup2 babeltrace_output_fd to STDERR"); | |
230 | goto result; | |
231 | } | |
232 | ||
233 | execl(parser_path, "babeltrace", trace_path, NULL); | |
234 | perror("# Could not launch the babeltrace process"); | |
235 | exit(-1); | |
236 | } | |
237 | result: | |
238 | ok(ret == 0, "Babeltrace could read the resulting trace"); | |
239 | ||
25afa9e5 | 240 | if (ret && babeltrace_output_fd >= 0) { |
39d74371 JG |
241 | char *line; |
242 | size_t len = METADATA_LINE_SIZE; | |
243 | FILE *babeltrace_output_fp = NULL; | |
244 | ||
245 | babeltrace_output_fp = fdopen(babeltrace_output_fd, "r"); | |
246 | if (!babeltrace_output_fp) { | |
247 | perror("fdopen on babeltrace_output_fd"); | |
248 | goto close_fp; | |
249 | } | |
e1d776cd | 250 | babeltrace_output_fd = -1; |
39d74371 JG |
251 | |
252 | line = malloc(len); | |
e1d776cd MD |
253 | if (!line) { |
254 | diag("malloc error"); | |
255 | } | |
39d74371 JG |
256 | rewind(babeltrace_output_fp); |
257 | while (getline(&line, &len, babeltrace_output_fp) > 0) { | |
258 | diag("%s", line); | |
259 | } | |
260 | ||
261 | free(line); | |
262 | close_fp: | |
e1d776cd MD |
263 | if (babeltrace_output_fp) { |
264 | if (fclose(babeltrace_output_fp)) { | |
265 | diag("fclose error"); | |
266 | } | |
267 | } | |
39d74371 JG |
268 | } |
269 | ||
25afa9e5 | 270 | if (babeltrace_output_fd >= 0) { |
e1d776cd MD |
271 | if (close(babeltrace_output_fd)) { |
272 | diag("close error"); | |
273 | } | |
274 | } | |
39d74371 JG |
275 | } |
276 | ||
277 | void append_simple_event(struct bt_ctf_stream_class *stream_class, | |
278 | struct bt_ctf_stream *stream, struct bt_ctf_clock *clock) | |
279 | { | |
280 | /* Create and add a simple event class */ | |
281 | struct bt_ctf_event_class *simple_event_class = | |
282 | bt_ctf_event_class_create("Simple Event"); | |
283 | struct bt_ctf_field_type *uint_12_type = | |
284 | bt_ctf_field_type_integer_create(12); | |
7cfd41d6 JG |
285 | struct bt_ctf_field_type *int_64_type = |
286 | bt_ctf_field_type_integer_create(64); | |
39d74371 JG |
287 | struct bt_ctf_field_type *float_type = |
288 | bt_ctf_field_type_floating_point_create(); | |
7cfd41d6 JG |
289 | struct bt_ctf_field_type *enum_type; |
290 | struct bt_ctf_field_type *enum_type_unsigned = | |
8382544f | 291 | bt_ctf_field_type_enumeration_create(uint_12_type); |
5edae678 JG |
292 | struct bt_ctf_field_type *event_context_type = |
293 | bt_ctf_field_type_structure_create(); | |
7cfd41d6 | 294 | struct bt_ctf_field_type *returned_type; |
39d74371 JG |
295 | struct bt_ctf_event *simple_event; |
296 | struct bt_ctf_field *integer_field; | |
297 | struct bt_ctf_field *float_field; | |
8382544f | 298 | struct bt_ctf_field *enum_field; |
7cfd41d6 | 299 | struct bt_ctf_field *enum_field_unsigned; |
8382544f | 300 | struct bt_ctf_field *enum_container_field; |
10817e06 | 301 | const char *mapping_name_test = "truie"; |
10817e06 | 302 | const double double_test_value = 3.1415; |
7cfd41d6 JG |
303 | struct bt_ctf_field *enum_container_field_unsigned; |
304 | const char *mapping_name_negative_test = "negative_value"; | |
305 | const char *ret_char; | |
10817e06 | 306 | double ret_double; |
7cfd41d6 JG |
307 | int64_t ret_range_start_int64_t, ret_range_end_int64_t; |
308 | uint64_t ret_range_start_uint64_t, ret_range_end_uint64_t; | |
1ff9582c | 309 | struct bt_ctf_clock *ret_clock; |
e3c971da | 310 | struct bt_ctf_event_class *ret_event_class; |
12c8a1a3 JG |
311 | struct bt_ctf_field *packet_context; |
312 | struct bt_ctf_field *packet_context_field; | |
5edae678 JG |
313 | struct bt_ctf_field *stream_event_context; |
314 | struct bt_ctf_field *stream_event_context_field; | |
6e1f8ea1 JG |
315 | struct bt_ctf_field *event_context; |
316 | struct bt_ctf_field *event_context_field; | |
7cfd41d6 JG |
317 | |
318 | ok(uint_12_type, "Create an unsigned integer type"); | |
319 | ||
320 | bt_ctf_field_type_integer_set_signed(int_64_type, 1); | |
321 | ok(int_64_type, "Create a signed integer type"); | |
322 | enum_type = bt_ctf_field_type_enumeration_create(int_64_type); | |
323 | ||
324 | returned_type = bt_ctf_field_type_enumeration_get_container_type(enum_type); | |
325 | ok(returned_type == int_64_type, "bt_ctf_field_type_enumeration_get_container_type returns the right type"); | |
326 | ok(!bt_ctf_field_type_enumeration_get_container_type(NULL), "bt_ctf_field_type_enumeration_get_container_type handles NULL correctly"); | |
327 | ok(!bt_ctf_field_type_enumeration_create(enum_type), | |
328 | "bt_ctf_field_enumeration_type_create rejects non-integer container field types"); | |
5edae678 | 329 | bt_ctf_field_type_put(returned_type); |
39d74371 JG |
330 | |
331 | bt_ctf_field_type_set_alignment(float_type, 32); | |
7cfd41d6 JG |
332 | ok(bt_ctf_field_type_get_alignment(NULL) < 0, |
333 | "bt_ctf_field_type_get_alignment handles NULL correctly"); | |
334 | ok(bt_ctf_field_type_get_alignment(float_type) == 32, | |
335 | "bt_ctf_field_type_get_alignment returns a correct value"); | |
336 | ||
337 | ok(bt_ctf_field_type_floating_point_set_exponent_digits(float_type, 11) == 0, | |
338 | "Set a floating point type's exponent digit count"); | |
339 | ok(bt_ctf_field_type_floating_point_set_mantissa_digits(float_type, 53) == 0, | |
340 | "Set a floating point type's mantissa digit count"); | |
341 | ||
342 | ok(bt_ctf_field_type_floating_point_get_exponent_digits(NULL) < 0, | |
343 | "bt_ctf_field_type_floating_point_get_exponent_digits handles NULL properly"); | |
344 | ok(bt_ctf_field_type_floating_point_get_mantissa_digits(NULL) < 0, | |
345 | "bt_ctf_field_type_floating_point_get_mantissa_digits handles NULL properly"); | |
346 | ok(bt_ctf_field_type_floating_point_get_exponent_digits(float_type) == 11, | |
347 | "bt_ctf_field_type_floating_point_get_exponent_digits returns the correct value"); | |
348 | ok(bt_ctf_field_type_floating_point_get_mantissa_digits(float_type) == 53, | |
349 | "bt_ctf_field_type_floating_point_get_mantissa_digits returns the correct value"); | |
8382544f JG |
350 | |
351 | ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, | |
7cfd41d6 JG |
352 | mapping_name_negative_test, -12345, 0) == 0, |
353 | "bt_ctf_field_type_enumeration_add_mapping accepts negative enumeration mappings"); | |
8382544f | 354 | ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, |
7cfd41d6 JG |
355 | "escaping; \"test\"", 1, 1) == 0, |
356 | "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing quotes"); | |
357 | ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, | |
358 | "\tanother \'escaping\'\n test\"", 2, 4) == 0, | |
359 | "bt_ctf_field_type_enumeration_add_mapping accepts enumeration mapping strings containing special characters"); | |
8382544f JG |
360 | ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, |
361 | "event clock int float", 5, 22) == 0, | |
362 | "Accept enumeration mapping strings containing reserved keywords"); | |
7cfd41d6 JG |
363 | bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test, |
364 | 42, 42); | |
365 | ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test, | |
366 | 43, 51), "bt_ctf_field_type_enumeration_add_mapping rejects duplicate mapping names"); | |
367 | ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, "something", | |
368 | -500, -400), "bt_ctf_field_type_enumeration_add_mapping rejects overlapping enum entries"); | |
369 | ok(bt_ctf_field_type_enumeration_add_mapping(enum_type, mapping_name_test, | |
370 | -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start"); | |
371 | bt_ctf_field_type_enumeration_add_mapping(enum_type, "another entry", -42000, -13000); | |
372 | ||
074ee56d | 373 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(NULL, -42) < 0, |
7cfd41d6 | 374 | "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles a NULL field type correctly"); |
074ee56d | 375 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, 1000000) < 0, |
7cfd41d6 | 376 | "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles invalid values correctly"); |
074ee56d | 377 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, -55) == 1, |
7cfd41d6 JG |
378 | "bt_ctf_field_type_enumeration_get_mapping_index_by_value returns the correct index"); |
379 | ||
8382544f | 380 | ok(bt_ctf_event_class_add_field(simple_event_class, enum_type, |
7cfd41d6 JG |
381 | "enum_field") == 0, "Add signed enumeration field to event"); |
382 | ||
383 | ok(bt_ctf_field_type_enumeration_get_mapping(NULL, 0, &ret_char, | |
384 | &ret_range_start_int64_t, &ret_range_end_int64_t) < 0, | |
385 | "bt_ctf_field_type_enumeration_get_mapping handles a NULL enumeration correctly"); | |
386 | ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, NULL, | |
387 | &ret_range_start_int64_t, &ret_range_end_int64_t) < 0, | |
388 | "bt_ctf_field_type_enumeration_get_mapping handles a NULL string correctly"); | |
389 | ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, &ret_char, | |
390 | NULL, &ret_range_end_int64_t) < 0, | |
391 | "bt_ctf_field_type_enumeration_get_mapping handles a NULL start correctly"); | |
392 | ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 0, &ret_char, | |
393 | &ret_range_start_int64_t, NULL) < 0, | |
394 | "bt_ctf_field_type_enumeration_get_mapping handles a NULL end correctly"); | |
395 | ok(bt_ctf_field_type_enumeration_get_mapping(enum_type, 5, &ret_char, | |
396 | &ret_range_start_int64_t, &ret_range_end_int64_t) == 0, | |
397 | "bt_ctf_field_type_enumeration_get_mapping returns a value"); | |
398 | ok(!strcmp(ret_char, mapping_name_test), | |
399 | "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping name"); | |
400 | ok(ret_range_start_int64_t == 42, | |
401 | "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping start"); | |
402 | ok(ret_range_end_int64_t == 42, | |
403 | "bt_ctf_field_type_enumeration_get_mapping returns a correct mapping end"); | |
404 | ||
405 | ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, | |
406 | "escaping; \"test\"", 0, 0) == 0, | |
407 | "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing quotes"); | |
408 | ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, | |
409 | "\tanother \'escaping\'\n test\"", 1, 4) == 0, | |
410 | "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing special characters"); | |
411 | ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, | |
412 | "event clock int float", 5, 22) == 0, | |
413 | "bt_ctf_field_type_enumeration_add_mapping_unsigned accepts enumeration mapping strings containing reserved keywords"); | |
414 | bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test, | |
415 | 42, 42); | |
416 | ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test, | |
417 | 43, 51), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects duplicate mapping names"); | |
418 | ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, "something", | |
419 | 7, 8), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects overlapping enum entries"); | |
420 | ok(bt_ctf_field_type_enumeration_add_mapping_unsigned(enum_type_unsigned, mapping_name_test, | |
421 | 55, 54), "bt_ctf_field_type_enumeration_add_mapping_unsigned rejects mapping where end < start"); | |
422 | ok(bt_ctf_event_class_add_field(simple_event_class, enum_type_unsigned, | |
423 | "enum_field_unsigned") == 0, "Add unsigned enumeration field to event"); | |
424 | ||
425 | ok(bt_ctf_field_type_enumeration_get_mapping_count(NULL) < 0, | |
426 | "bt_ctf_field_type_enumeration_get_mapping_count handles NULL correctly"); | |
427 | ok(bt_ctf_field_type_enumeration_get_mapping_count(enum_type_unsigned) == 4, | |
428 | "bt_ctf_field_type_enumeration_get_mapping_count returns the correct value"); | |
429 | ||
430 | ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(NULL, 0, &ret_char, | |
431 | &ret_range_start_uint64_t, &ret_range_end_uint64_t) < 0, | |
432 | "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL enumeration correctly"); | |
433 | ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, NULL, | |
434 | &ret_range_start_uint64_t, &ret_range_end_uint64_t) < 0, | |
435 | "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL string correctly"); | |
436 | ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, &ret_char, | |
437 | NULL, &ret_range_end_uint64_t) < 0, | |
438 | "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL start correctly"); | |
439 | ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 0, &ret_char, | |
440 | &ret_range_start_uint64_t, NULL) < 0, | |
441 | "bt_ctf_field_type_enumeration_get_mapping_unsigned handles a NULL end correctly"); | |
442 | ok(bt_ctf_field_type_enumeration_get_mapping_unsigned(enum_type_unsigned, 3, &ret_char, | |
443 | &ret_range_start_uint64_t, &ret_range_end_uint64_t) == 0, | |
444 | "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a value"); | |
445 | ok(!strcmp(ret_char, mapping_name_test), | |
446 | "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping name"); | |
447 | ok(ret_range_start_uint64_t == 42, | |
448 | "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping start"); | |
449 | ok(ret_range_end_uint64_t == 42, | |
450 | "bt_ctf_field_type_enumeration_get_mapping_unsigned returns a correct mapping end"); | |
8382544f | 451 | |
39d74371 JG |
452 | bt_ctf_event_class_add_field(simple_event_class, uint_12_type, |
453 | "integer_field"); | |
454 | bt_ctf_event_class_add_field(simple_event_class, float_type, | |
455 | "float_field"); | |
456 | bt_ctf_stream_class_add_event_class(stream_class, | |
457 | simple_event_class); | |
458 | ||
e3c971da JG |
459 | ok(bt_ctf_stream_class_get_event_class_count(NULL) < 0, |
460 | "bt_ctf_stream_class_get_event_class_count handles NULL correctly"); | |
461 | ok(bt_ctf_stream_class_get_event_class_count(stream_class) == 1, | |
462 | "bt_ctf_stream_class_get_event_class_count returns a correct number of event classes"); | |
463 | ok(bt_ctf_stream_class_get_event_class(NULL, 0) == NULL, | |
464 | "bt_ctf_stream_class_get_event_class handles NULL correctly"); | |
465 | ok(bt_ctf_stream_class_get_event_class(stream_class, 8724) == NULL, | |
466 | "bt_ctf_stream_class_get_event_class handles invalid indexes correctly"); | |
467 | ret_event_class = bt_ctf_stream_class_get_event_class(stream_class, 0); | |
468 | ok(ret_event_class == simple_event_class, | |
469 | "bt_ctf_stream_class_get_event_class returns the correct event class"); | |
470 | bt_ctf_event_class_put(ret_event_class); | |
471 | ||
472 | ok(bt_ctf_stream_class_get_event_class_by_name(NULL, "some event name") == NULL, | |
473 | "bt_ctf_stream_class_get_event_class_by_name handles a NULL stream class correctly"); | |
474 | ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, NULL) == NULL, | |
475 | "bt_ctf_stream_class_get_event_class_by_name handles a NULL event class name correctly"); | |
476 | ok(bt_ctf_stream_class_get_event_class_by_name(stream_class, "some event name") == NULL, | |
477 | "bt_ctf_stream_class_get_event_class_by_name handles non-existing event class names correctly"); | |
5edae678 | 478 | ret_event_class = bt_ctf_stream_class_get_event_class_by_name(stream_class, "Simple Event"); |
e3c971da JG |
479 | ok(ret_event_class == simple_event_class, |
480 | "bt_ctf_stream_class_get_event_class_by_name returns a correct event class"); | |
481 | bt_ctf_event_class_put(ret_event_class); | |
482 | ||
5edae678 JG |
483 | /* Set an event context type which will contain a single integer*/ |
484 | bt_ctf_field_type_structure_add_field(event_context_type, uint_12_type, | |
485 | "event_specific_context"); | |
486 | ok(bt_ctf_event_class_get_context_type(NULL) == NULL, | |
487 | "bt_ctf_event_class_get_context_type handles NULL correctly"); | |
488 | ok(bt_ctf_event_class_get_context_type(simple_event_class) == NULL, | |
489 | "bt_ctf_event_class_get_context_type returns NULL when no event context type is set"); | |
490 | ok(bt_ctf_event_class_set_context_type(simple_event_class, NULL) < 0, | |
491 | "bt_ctf_event_class_set_context_type handles a NULL context type correctly"); | |
492 | ok(bt_ctf_event_class_set_context_type(NULL, event_context_type) < 0, | |
493 | "bt_ctf_event_class_set_context_type handles a NULL event class correctly"); | |
494 | ok(!bt_ctf_event_class_set_context_type(simple_event_class, event_context_type), | |
495 | "Set an event class' context type successfully"); | |
496 | returned_type = bt_ctf_event_class_get_context_type(simple_event_class); | |
497 | ok(returned_type == event_context_type, | |
498 | "bt_ctf_event_class_get_context_type returns the appropriate type"); | |
499 | bt_ctf_field_type_put(returned_type); | |
500 | ||
39d74371 | 501 | simple_event = bt_ctf_event_create(simple_event_class); |
39d74371 JG |
502 | ok(simple_event, |
503 | "Instantiate an event containing a single integer field"); | |
504 | ||
1ff9582c JG |
505 | ok(bt_ctf_event_get_clock(NULL) == NULL, |
506 | "bt_ctf_event_get_clock handles NULL correctly"); | |
507 | ret_clock = bt_ctf_event_get_clock(simple_event); | |
508 | ok(ret_clock == clock, | |
509 | "bt_ctf_event_get_clock returns a correct clock"); | |
510 | bt_ctf_clock_put(clock); | |
511 | ||
39d74371 JG |
512 | integer_field = bt_ctf_field_create(uint_12_type); |
513 | bt_ctf_field_unsigned_integer_set_value(integer_field, 42); | |
514 | ok(bt_ctf_event_set_payload(simple_event, "integer_field", | |
515 | integer_field) == 0, "Use bt_ctf_event_set_payload to set a manually allocated field"); | |
516 | ||
517 | float_field = bt_ctf_event_get_payload(simple_event, "float_field"); | |
10817e06 JG |
518 | ok(bt_ctf_field_floating_point_get_value(float_field, &ret_double), |
519 | "bt_ctf_field_floating_point_get_value fails on an unset float field"); | |
520 | bt_ctf_field_floating_point_set_value(float_field, double_test_value); | |
521 | ok(bt_ctf_field_floating_point_get_value(NULL, &ret_double), | |
522 | "bt_ctf_field_floating_point_get_value properly handles a NULL field"); | |
523 | ok(bt_ctf_field_floating_point_get_value(float_field, NULL), | |
524 | "bt_ctf_field_floating_point_get_value properly handles a NULL return value pointer"); | |
525 | ok(!bt_ctf_field_floating_point_get_value(float_field, &ret_double), | |
526 | "bt_ctf_field_floating_point_get_value returns a double value"); | |
527 | ok(fabs(ret_double - double_test_value) <= DBL_EPSILON, | |
528 | "bt_ctf_field_floating_point_get_value returns a correct value"); | |
529 | ||
8382544f | 530 | enum_field = bt_ctf_field_create(enum_type); |
7cfd41d6 JG |
531 | ret_char = bt_ctf_field_enumeration_get_mapping_name(NULL); |
532 | ok(!ret_char, "bt_ctf_field_enumeration_get_mapping_name handles NULL correctly"); | |
533 | ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field); | |
534 | ok(!ret_char, "bt_ctf_field_enumeration_get_mapping_name returns NULL if the enumeration's container field is unset"); | |
8382544f JG |
535 | enum_container_field = bt_ctf_field_enumeration_get_container( |
536 | enum_field); | |
7cfd41d6 JG |
537 | ok(bt_ctf_field_signed_integer_set_value( |
538 | enum_container_field, -42) == 0, | |
539 | "Set signed enumeration container value"); | |
540 | ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field); | |
541 | ok(!strcmp(ret_char, mapping_name_negative_test), | |
542 | "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an signed container"); | |
8382544f | 543 | bt_ctf_event_set_payload(simple_event, "enum_field", enum_field); |
39d74371 | 544 | |
7cfd41d6 JG |
545 | enum_field_unsigned = bt_ctf_field_create(enum_type_unsigned); |
546 | enum_container_field_unsigned = bt_ctf_field_enumeration_get_container( | |
547 | enum_field_unsigned); | |
548 | ok(bt_ctf_field_unsigned_integer_set_value( | |
549 | enum_container_field_unsigned, 42) == 0, | |
550 | "Set unsigned enumeration container value"); | |
551 | bt_ctf_event_set_payload(simple_event, "enum_field_unsigned", | |
552 | enum_field_unsigned); | |
553 | ret_char = bt_ctf_field_enumeration_get_mapping_name(enum_field_unsigned); | |
554 | ok(!strcmp(ret_char, mapping_name_test), | |
555 | "bt_ctf_field_enumeration_get_mapping_name returns the correct mapping name with an unsigned container"); | |
556 | ||
39d74371 JG |
557 | ok(bt_ctf_clock_set_time(clock, current_time) == 0, "Set clock time"); |
558 | ||
6e1f8ea1 | 559 | /* Populate stream event context */ |
5edae678 JG |
560 | stream_event_context = bt_ctf_stream_get_event_context(stream); |
561 | stream_event_context_field = bt_ctf_field_structure_get_field( | |
562 | stream_event_context, "common_event_context"); | |
563 | bt_ctf_field_unsigned_integer_set_value(stream_event_context_field, 42); | |
564 | ||
565 | /* Populate the event's context */ | |
566 | ok(bt_ctf_event_get_event_context(NULL) == NULL, | |
567 | "bt_ctf_event_get_event_context handles NULL correctly"); | |
568 | event_context = bt_ctf_event_get_event_context(simple_event); | |
569 | ok(event_context, | |
570 | "bt_ctf_event_get_event_context returns a field"); | |
571 | returned_type = bt_ctf_field_get_type(event_context); | |
572 | ok(returned_type == event_context_type, | |
573 | "bt_ctf_event_get_event_context returns a field of the appropriate type"); | |
574 | event_context_field = bt_ctf_field_structure_get_field(event_context, | |
575 | "event_specific_context"); | |
576 | ok(!bt_ctf_field_unsigned_integer_set_value(event_context_field, 1234), | |
577 | "Successfully set an event context's value"); | |
578 | ok(bt_ctf_event_set_event_context(NULL, event_context) < 0, | |
579 | "bt_ctf_event_set_event_context handles a NULL event correctly"); | |
580 | ok(bt_ctf_event_set_event_context(simple_event, NULL) < 0, | |
581 | "bt_ctf_event_set_event_context handles a NULL event context correctly"); | |
582 | ok(bt_ctf_event_set_event_context(simple_event, event_context_field) < 0, | |
583 | "bt_ctf_event_set_event_context rejects a context of the wrong type"); | |
584 | ok(!bt_ctf_event_set_event_context(simple_event, event_context), | |
585 | "Set an event context successfully"); | |
6e1f8ea1 | 586 | |
39d74371 JG |
587 | ok(bt_ctf_stream_append_event(stream, simple_event) == 0, |
588 | "Append simple event to trace stream"); | |
589 | ||
12c8a1a3 JG |
590 | ok(bt_ctf_stream_get_packet_context(NULL) == NULL, |
591 | "bt_ctf_stream_get_packet_context handles NULL correctly"); | |
592 | packet_context = bt_ctf_stream_get_packet_context(stream); | |
593 | ok(packet_context, | |
594 | "bt_ctf_stream_get_packet_context returns a packet context"); | |
595 | ||
596 | packet_context_field = bt_ctf_field_structure_get_field(packet_context, | |
597 | "packet_size"); | |
598 | ok(packet_context_field, | |
599 | "Packet context contains the default packet_size field."); | |
600 | bt_ctf_field_put(packet_context_field); | |
601 | packet_context_field = bt_ctf_field_structure_get_field(packet_context, | |
35e8709f | 602 | "custom_packet_context_field"); |
12c8a1a3 JG |
603 | ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field, 8) == 0, |
604 | "Custom packet context field value successfully set."); | |
605 | ||
606 | ok(bt_ctf_stream_set_packet_context(NULL, packet_context_field) < 0, | |
607 | "bt_ctf_stream_set_packet_context handles a NULL stream correctly"); | |
608 | ok(bt_ctf_stream_set_packet_context(stream, NULL) < 0, | |
609 | "bt_ctf_stream_set_packet_context handles a NULL packet context correctly"); | |
610 | ok(bt_ctf_stream_set_packet_context(stream, packet_context) == 0, | |
611 | "Successfully set a stream's packet context"); | |
612 | ||
39d74371 JG |
613 | ok(bt_ctf_stream_flush(stream) == 0, |
614 | "Flush trace stream with one event"); | |
615 | ||
616 | bt_ctf_event_class_put(simple_event_class); | |
617 | bt_ctf_event_put(simple_event); | |
618 | bt_ctf_field_type_put(uint_12_type); | |
7cfd41d6 | 619 | bt_ctf_field_type_put(int_64_type); |
39d74371 | 620 | bt_ctf_field_type_put(float_type); |
8382544f | 621 | bt_ctf_field_type_put(enum_type); |
7cfd41d6 JG |
622 | bt_ctf_field_type_put(enum_type_unsigned); |
623 | bt_ctf_field_type_put(returned_type); | |
5edae678 | 624 | bt_ctf_field_type_put(event_context_type); |
39d74371 JG |
625 | bt_ctf_field_put(integer_field); |
626 | bt_ctf_field_put(float_field); | |
8382544f | 627 | bt_ctf_field_put(enum_field); |
7cfd41d6 | 628 | bt_ctf_field_put(enum_field_unsigned); |
8382544f | 629 | bt_ctf_field_put(enum_container_field); |
7cfd41d6 | 630 | bt_ctf_field_put(enum_container_field_unsigned); |
12c8a1a3 JG |
631 | bt_ctf_field_put(packet_context); |
632 | bt_ctf_field_put(packet_context_field); | |
5edae678 JG |
633 | bt_ctf_field_put(stream_event_context); |
634 | bt_ctf_field_put(stream_event_context_field); | |
6e1f8ea1 JG |
635 | bt_ctf_field_put(event_context); |
636 | bt_ctf_field_put(event_context_field); | |
39d74371 JG |
637 | } |
638 | ||
639 | void append_complex_event(struct bt_ctf_stream_class *stream_class, | |
640 | struct bt_ctf_stream *stream, struct bt_ctf_clock *clock) | |
641 | { | |
642 | int i; | |
1ff9582c | 643 | const char *complex_test_event_string = "Complex Test Event"; |
10817e06 | 644 | const char *test_string = "Test string"; |
39d74371 JG |
645 | struct bt_ctf_field_type *uint_35_type = |
646 | bt_ctf_field_type_integer_create(35); | |
647 | struct bt_ctf_field_type *int_16_type = | |
648 | bt_ctf_field_type_integer_create(16); | |
649 | struct bt_ctf_field_type *uint_3_type = | |
650 | bt_ctf_field_type_integer_create(3); | |
651 | struct bt_ctf_field_type *enum_variant_type = | |
652 | bt_ctf_field_type_enumeration_create(uint_3_type); | |
653 | struct bt_ctf_field_type *variant_type = | |
654 | bt_ctf_field_type_variant_create(enum_variant_type, | |
655 | "variant_selector"); | |
656 | struct bt_ctf_field_type *string_type = | |
657 | bt_ctf_field_type_string_create(); | |
658 | struct bt_ctf_field_type *sequence_type; | |
1fac895e | 659 | struct bt_ctf_field_type *array_type; |
39d74371 JG |
660 | struct bt_ctf_field_type *inner_structure_type = |
661 | bt_ctf_field_type_structure_create(); | |
662 | struct bt_ctf_field_type *complex_structure_type = | |
663 | bt_ctf_field_type_structure_create(); | |
7cfd41d6 | 664 | struct bt_ctf_field_type *ret_field_type; |
39d74371 JG |
665 | struct bt_ctf_event_class *event_class; |
666 | struct bt_ctf_event *event; | |
667 | struct bt_ctf_field *uint_35_field, *int_16_field, *a_string_field, | |
668 | *inner_structure_field, *complex_structure_field, | |
669 | *a_sequence_field, *enum_variant_field, *enum_container_field, | |
1fac895e | 670 | *variant_field, *an_array_field, *ret_field; |
10817e06 | 671 | uint64_t ret_unsigned_int; |
1fac895e | 672 | int64_t ret_signed_int; |
10817e06 | 673 | const char *ret_string; |
1ff9582c JG |
674 | struct bt_ctf_stream_class *ret_stream_class; |
675 | struct bt_ctf_event_class *ret_event_class; | |
12c8a1a3 | 676 | struct bt_ctf_field *packet_context, *packet_context_field; |
39d74371 JG |
677 | |
678 | bt_ctf_field_type_set_alignment(int_16_type, 32); | |
679 | bt_ctf_field_type_integer_set_signed(int_16_type, 1); | |
680 | bt_ctf_field_type_integer_set_base(uint_35_type, | |
681 | BT_CTF_INTEGER_BASE_HEXADECIMAL); | |
682 | ||
1fac895e | 683 | array_type = bt_ctf_field_type_array_create(int_16_type, ARRAY_TEST_LENGTH); |
39d74371 JG |
684 | sequence_type = bt_ctf_field_type_sequence_create(int_16_type, |
685 | "seq_len"); | |
7cfd41d6 JG |
686 | |
687 | ok(bt_ctf_field_type_array_get_element_type(NULL) == NULL, | |
688 | "bt_ctf_field_type_array_get_element_type handles NULL correctly"); | |
689 | ret_field_type = bt_ctf_field_type_array_get_element_type( | |
690 | array_type); | |
691 | ok(ret_field_type == int_16_type, | |
692 | "bt_ctf_field_type_array_get_element_type returns the correct type"); | |
693 | bt_ctf_field_type_put(ret_field_type); | |
694 | ||
695 | ok(bt_ctf_field_type_array_get_length(NULL) < 0, | |
696 | "bt_ctf_field_type_array_get_length handles NULL correctly"); | |
697 | ok(bt_ctf_field_type_array_get_length(array_type) == ARRAY_TEST_LENGTH, | |
698 | "bt_ctf_field_type_array_get_length returns the correct length"); | |
699 | ||
39d74371 JG |
700 | bt_ctf_field_type_structure_add_field(inner_structure_type, |
701 | uint_35_type, "seq_len"); | |
702 | bt_ctf_field_type_structure_add_field(inner_structure_type, | |
703 | sequence_type, "a_sequence"); | |
1fac895e JG |
704 | bt_ctf_field_type_structure_add_field(inner_structure_type, |
705 | array_type, "an_array"); | |
39d74371 JG |
706 | |
707 | bt_ctf_field_type_enumeration_add_mapping(enum_variant_type, | |
708 | "UINT3_TYPE", 0, 0); | |
709 | bt_ctf_field_type_enumeration_add_mapping(enum_variant_type, | |
710 | "INT16_TYPE", 1, 1); | |
711 | bt_ctf_field_type_enumeration_add_mapping(enum_variant_type, | |
712 | "UINT35_TYPE", 2, 7); | |
7cfd41d6 | 713 | |
074ee56d JG |
714 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL, |
715 | "INT16_TYPE") < 0, | |
7cfd41d6 | 716 | "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly"); |
074ee56d JG |
717 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name( |
718 | enum_variant_type, NULL) < 0, | |
7cfd41d6 | 719 | "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly"); |
074ee56d JG |
720 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name( |
721 | enum_variant_type, "INT16_TYPE") == 1, | |
7cfd41d6 JG |
722 | "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index"); |
723 | ||
074ee56d | 724 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL, 1) < 0, |
7cfd41d6 | 725 | "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly"); |
074ee56d | 726 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, -42) < 0, |
7cfd41d6 | 727 | "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly"); |
074ee56d | 728 | ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, 5) == 2, |
7cfd41d6 JG |
729 | "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index"); |
730 | ||
39d74371 JG |
731 | ok(bt_ctf_field_type_variant_add_field(variant_type, uint_3_type, |
732 | "An unknown entry"), "Reject a variant field based on an unknown tag value"); | |
733 | ok(bt_ctf_field_type_variant_add_field(variant_type, uint_3_type, | |
734 | "UINT3_TYPE") == 0, "Add a field to a variant"); | |
735 | bt_ctf_field_type_variant_add_field(variant_type, int_16_type, | |
736 | "INT16_TYPE"); | |
737 | bt_ctf_field_type_variant_add_field(variant_type, uint_35_type, | |
738 | "UINT35_TYPE"); | |
739 | ||
7cfd41d6 JG |
740 | ok(bt_ctf_field_type_variant_get_tag_type(NULL) == NULL, |
741 | "bt_ctf_field_type_variant_get_tag_type handles NULL correctly"); | |
742 | ret_field_type = bt_ctf_field_type_variant_get_tag_type(variant_type); | |
743 | ok(ret_field_type == enum_variant_type, | |
744 | "bt_ctf_field_type_variant_get_tag_type returns a correct tag type"); | |
745 | bt_ctf_field_type_put(ret_field_type); | |
746 | ||
747 | ok(bt_ctf_field_type_variant_get_tag_name(NULL) == NULL, | |
748 | "bt_ctf_field_type_variant_get_tag_name handles NULL correctly"); | |
749 | ret_string = bt_ctf_field_type_variant_get_tag_name(variant_type); | |
750 | ok(!strcmp(ret_string, "variant_selector"), | |
751 | "bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name"); | |
752 | ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL, | |
753 | "INT16_TYPE") == NULL, | |
754 | "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL variant_type correctly"); | |
755 | ok(bt_ctf_field_type_variant_get_field_type_by_name(variant_type, | |
756 | NULL) == NULL, | |
757 | "bt_ctf_field_type_variant_get_field_type_by_name handles a NULL field name correctly"); | |
758 | ret_field_type = bt_ctf_field_type_variant_get_field_type_by_name( | |
759 | variant_type, "INT16_TYPE"); | |
760 | ok(ret_field_type == int_16_type, | |
761 | "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type"); | |
762 | bt_ctf_field_type_put(ret_field_type); | |
763 | ||
764 | ok(bt_ctf_field_type_variant_get_field_count(NULL) < 0, | |
765 | "bt_ctf_field_type_variant_get_field_count handles NULL correctly"); | |
766 | ok(bt_ctf_field_type_variant_get_field_count(variant_type) == 3, | |
767 | "bt_ctf_field_type_variant_get_field_count returns the correct count"); | |
768 | ||
769 | ok(bt_ctf_field_type_variant_get_field(NULL, &ret_string, &ret_field_type, 0) < 0, | |
770 | "bt_ctf_field_type_variant_get_field handles a NULL type correctly"); | |
771 | ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) < 0, | |
772 | "bt_ctf_field_type_variant_get_field handles a NULL field name correctly"); | |
773 | ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) < 0, | |
774 | "bt_ctf_field_type_variant_get_field handles a NULL field type correctly"); | |
775 | ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 200) < 0, | |
776 | "bt_ctf_field_type_variant_get_field handles an invalid index correctly"); | |
777 | ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 1) == 0, | |
778 | "bt_ctf_field_type_variant_get_field returns a field"); | |
779 | ok(!strcmp("INT16_TYPE", ret_string), | |
780 | "bt_ctf_field_type_variant_get_field returns a correct field name"); | |
781 | ok(ret_field_type == int_16_type, | |
782 | "bt_ctf_field_type_variant_get_field returns a correct field type"); | |
783 | bt_ctf_field_type_put(ret_field_type); | |
784 | ||
39d74371 JG |
785 | bt_ctf_field_type_structure_add_field(complex_structure_type, |
786 | enum_variant_type, "variant_selector"); | |
787 | bt_ctf_field_type_structure_add_field(complex_structure_type, | |
788 | string_type, "a_string"); | |
789 | bt_ctf_field_type_structure_add_field(complex_structure_type, | |
790 | variant_type, "variant_value"); | |
791 | bt_ctf_field_type_structure_add_field(complex_structure_type, | |
792 | inner_structure_type, "inner_structure"); | |
793 | ||
794 | ok(bt_ctf_event_class_create("clock") == NULL, | |
795 | "Reject creation of an event class with an illegal name"); | |
1ff9582c | 796 | event_class = bt_ctf_event_class_create(complex_test_event_string); |
39d74371 JG |
797 | ok(event_class, "Create an event class"); |
798 | ok(bt_ctf_event_class_add_field(event_class, uint_35_type, ""), | |
799 | "Reject addition of a field with an empty name to an event"); | |
800 | ok(bt_ctf_event_class_add_field(event_class, NULL, "an_integer"), | |
801 | "Reject addition of a field with a NULL type to an event"); | |
802 | ok(bt_ctf_event_class_add_field(event_class, uint_35_type, | |
803 | "int"), | |
804 | "Reject addition of a type with an illegal name to an event"); | |
805 | ok(bt_ctf_event_class_add_field(event_class, uint_35_type, | |
806 | "uint_35") == 0, | |
807 | "Add field of type unsigned integer to an event"); | |
808 | ok(bt_ctf_event_class_add_field(event_class, int_16_type, | |
809 | "int_16") == 0, "Add field of type signed integer to an event"); | |
810 | ok(bt_ctf_event_class_add_field(event_class, complex_structure_type, | |
811 | "complex_structure") == 0, | |
812 | "Add composite structure to an event"); | |
813 | ||
1ff9582c JG |
814 | ok(bt_ctf_event_class_get_name(NULL) == NULL, |
815 | "bt_ctf_event_class_get_name handles NULL correctly"); | |
816 | ret_string = bt_ctf_event_class_get_name(event_class); | |
817 | ok(!strcmp(ret_string, complex_test_event_string), | |
818 | "bt_ctf_event_class_get_name returns a correct name"); | |
819 | ok(bt_ctf_event_class_get_id(event_class) < 0, | |
820 | "bt_ctf_event_class_get_id returns a negative value when not set"); | |
821 | ok(bt_ctf_event_class_get_id(NULL) < 0, | |
822 | "bt_ctf_event_class_get_id handles NULL correctly"); | |
823 | ok(bt_ctf_event_class_set_id(NULL, 42) < 0, | |
824 | "bt_ctf_event_class_set_id handles NULL correctly"); | |
825 | ok(bt_ctf_event_class_set_id(event_class, 42) == 0, | |
826 | "Set an event class' id"); | |
827 | ok(bt_ctf_event_class_get_id(event_class) == 42, | |
828 | "bt_ctf_event_class_get_id returns the correct value"); | |
829 | ||
39d74371 JG |
830 | /* Add event class to the stream class */ |
831 | ok(bt_ctf_stream_class_add_event_class(stream_class, NULL), | |
832 | "Reject addition of NULL event class to a stream class"); | |
833 | ok(bt_ctf_stream_class_add_event_class(stream_class, | |
834 | event_class) == 0, "Add an event class to stream class"); | |
835 | ||
1ff9582c JG |
836 | ok(bt_ctf_event_class_get_stream_class(NULL) == NULL, |
837 | "bt_ctf_event_class_get_stream_class handles NULL correctly"); | |
838 | ret_stream_class = bt_ctf_event_class_get_stream_class(event_class); | |
839 | ok(ret_stream_class == stream_class, | |
840 | "bt_ctf_event_class_get_stream_class returns the correct stream class"); | |
841 | bt_ctf_stream_class_put(ret_stream_class); | |
842 | ||
843 | ok(bt_ctf_event_class_get_field_count(NULL) < 0, | |
844 | "bt_ctf_event_class_get_field_count handles NULL correctly"); | |
845 | ok(bt_ctf_event_class_get_field_count(event_class) == 3, | |
846 | "bt_ctf_event_class_get_field_count returns a correct value"); | |
847 | ||
848 | ok(bt_ctf_event_class_get_field(NULL, &ret_string, | |
849 | &ret_field_type, 0) < 0, | |
850 | "bt_ctf_event_class_get_field handles a NULL event class correctly"); | |
851 | ok(bt_ctf_event_class_get_field(event_class, NULL, | |
852 | &ret_field_type, 0) < 0, | |
853 | "bt_ctf_event_class_get_field handles a NULL field name correctly"); | |
854 | ok(bt_ctf_event_class_get_field(event_class, &ret_string, | |
855 | NULL, 0) < 0, | |
856 | "bt_ctf_event_class_get_field handles a NULL field type correctly"); | |
857 | ok(bt_ctf_event_class_get_field(event_class, &ret_string, | |
858 | &ret_field_type, 42) < 0, | |
859 | "bt_ctf_event_class_get_field handles an invalid index correctly"); | |
860 | ok(bt_ctf_event_class_get_field(event_class, &ret_string, | |
861 | &ret_field_type, 0) == 0, | |
862 | "bt_ctf_event_class_get_field returns a field"); | |
863 | ok(ret_field_type == uint_35_type, | |
864 | "bt_ctf_event_class_get_field returns a correct field type"); | |
865 | bt_ctf_field_type_put(ret_field_type); | |
866 | ok(!strcmp(ret_string, "uint_35"), | |
867 | "bt_ctf_event_class_get_field returns a correct field name"); | |
868 | ok(bt_ctf_event_class_get_field_by_name(NULL, "") == NULL, | |
869 | "bt_ctf_event_class_get_field_by_name handles a NULL event class correctly"); | |
870 | ok(bt_ctf_event_class_get_field_by_name(event_class, NULL) == NULL, | |
871 | "bt_ctf_event_class_get_field_by_name handles a NULL field name correctly"); | |
872 | ok(bt_ctf_event_class_get_field_by_name(event_class, "truie") == NULL, | |
873 | "bt_ctf_event_class_get_field_by_name handles an invalid field name correctly"); | |
874 | ret_field_type = bt_ctf_event_class_get_field_by_name(event_class, | |
875 | "complex_structure"); | |
876 | ok(ret_field_type == complex_structure_type, | |
877 | "bt_ctf_event_class_get_field_by_name returns a correct field type"); | |
878 | bt_ctf_field_type_put(ret_field_type); | |
879 | ||
39d74371 JG |
880 | event = bt_ctf_event_create(event_class); |
881 | ok(event, "Instanciate a complex event"); | |
882 | ||
1ff9582c JG |
883 | ok(bt_ctf_event_get_class(NULL) == NULL, |
884 | "bt_ctf_event_get_class handles NULL correctly"); | |
885 | ret_event_class = bt_ctf_event_get_class(event); | |
886 | ok(ret_event_class == event_class, | |
887 | "bt_ctf_event_get_class returns the correct event class"); | |
888 | bt_ctf_event_class_put(ret_event_class); | |
889 | ||
39d74371 | 890 | uint_35_field = bt_ctf_event_get_payload(event, "uint_35"); |
7cfd41d6 | 891 | if (!uint_35_field) { |
10817e06 | 892 | printf("uint_35_field is NULL\n"); |
7cfd41d6 JG |
893 | } |
894 | ||
39d74371 JG |
895 | ok(uint_35_field, "Use bt_ctf_event_get_payload to get a field instance "); |
896 | bt_ctf_field_unsigned_integer_set_value(uint_35_field, 0x0DDF00D); | |
3c1d148b | 897 | ok(bt_ctf_field_unsigned_integer_get_value(NULL, &ret_unsigned_int) < 0, |
10817e06 | 898 | "bt_ctf_field_unsigned_integer_get_value properly properly handles a NULL field."); |
3c1d148b | 899 | ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field, NULL) < 0, |
10817e06 JG |
900 | "bt_ctf_field_unsigned_integer_get_value properly handles a NULL return value"); |
901 | ok(bt_ctf_field_unsigned_integer_get_value(uint_35_field, | |
902 | &ret_unsigned_int) == 0, | |
903 | "bt_ctf_field_unsigned_integer_get_value succeeds after setting a value"); | |
904 | ok(ret_unsigned_int == 0x0DDF00D, | |
905 | "bt_ctf_field_unsigned_integer_get_value returns the correct value"); | |
906 | ok(bt_ctf_field_signed_integer_get_value(uint_35_field, | |
3c1d148b | 907 | &ret_signed_int) < 0, |
10817e06 | 908 | "bt_ctf_field_signed_integer_get_value fails on an unsigned field"); |
39d74371 JG |
909 | bt_ctf_field_put(uint_35_field); |
910 | ||
911 | int_16_field = bt_ctf_event_get_payload(event, "int_16"); | |
912 | bt_ctf_field_signed_integer_set_value(int_16_field, -12345); | |
3c1d148b | 913 | ok(bt_ctf_field_signed_integer_get_value(NULL, &ret_signed_int) < 0, |
10817e06 | 914 | "bt_ctf_field_signed_integer_get_value properly handles a NULL field"); |
3c1d148b | 915 | ok(bt_ctf_field_signed_integer_get_value(int_16_field, NULL) < 0, |
10817e06 JG |
916 | "bt_ctf_field_signed_integer_get_value properly handles a NULL return value"); |
917 | ok(bt_ctf_field_signed_integer_get_value(int_16_field, | |
918 | &ret_signed_int) == 0, | |
919 | "bt_ctf_field_signed_integer_get_value succeeds after setting a value"); | |
920 | ok(ret_signed_int == -12345, | |
921 | "bt_ctf_field_signed_integer_get_value returns the correct value"); | |
922 | ok(bt_ctf_field_unsigned_integer_get_value(int_16_field, | |
3c1d148b | 923 | &ret_unsigned_int) < 0, |
10817e06 | 924 | "bt_ctf_field_unsigned_integer_get_value fails on a signed field"); |
39d74371 JG |
925 | bt_ctf_field_put(int_16_field); |
926 | ||
927 | complex_structure_field = bt_ctf_event_get_payload(event, | |
928 | "complex_structure"); | |
10817e06 JG |
929 | |
930 | ok(bt_ctf_field_structure_get_field_by_index(NULL, 0) == NULL, | |
931 | "bt_ctf_field_structure_get_field_by_index handles NULL correctly"); | |
932 | ok(bt_ctf_field_structure_get_field_by_index(NULL, 9) == NULL, | |
933 | "bt_ctf_field_structure_get_field_by_index handles an invalid index correctly"); | |
934 | inner_structure_field = bt_ctf_field_structure_get_field_by_index( | |
935 | complex_structure_field, 3); | |
936 | ret_field_type = bt_ctf_field_get_type(inner_structure_field); | |
937 | bt_ctf_field_put(inner_structure_field); | |
938 | ok(ret_field_type == inner_structure_type, | |
939 | "bt_ctf_field_structure_get_field_by_index returns a correct field"); | |
940 | bt_ctf_field_type_put(ret_field_type); | |
941 | ||
39d74371 JG |
942 | inner_structure_field = bt_ctf_field_structure_get_field( |
943 | complex_structure_field, "inner_structure"); | |
944 | a_string_field = bt_ctf_field_structure_get_field( | |
945 | complex_structure_field, "a_string"); | |
946 | enum_variant_field = bt_ctf_field_structure_get_field( | |
947 | complex_structure_field, "variant_selector"); | |
948 | variant_field = bt_ctf_field_structure_get_field( | |
949 | complex_structure_field, "variant_value"); | |
950 | uint_35_field = bt_ctf_field_structure_get_field( | |
951 | inner_structure_field, "seq_len"); | |
952 | a_sequence_field = bt_ctf_field_structure_get_field( | |
953 | inner_structure_field, "a_sequence"); | |
1fac895e JG |
954 | an_array_field = bt_ctf_field_structure_get_field( |
955 | inner_structure_field, "an_array"); | |
39d74371 JG |
956 | |
957 | enum_container_field = bt_ctf_field_enumeration_get_container( | |
958 | enum_variant_field); | |
959 | bt_ctf_field_unsigned_integer_set_value(enum_container_field, 1); | |
960 | int_16_field = bt_ctf_field_variant_get_field(variant_field, | |
961 | enum_variant_field); | |
962 | bt_ctf_field_signed_integer_set_value(int_16_field, -200); | |
963 | bt_ctf_field_put(int_16_field); | |
10817e06 JG |
964 | ok(!bt_ctf_field_string_get_value(a_string_field), |
965 | "bt_ctf_field_string_get_value returns NULL on an unset field"); | |
39d74371 | 966 | bt_ctf_field_string_set_value(a_string_field, |
10817e06 JG |
967 | test_string); |
968 | ok(!bt_ctf_field_string_get_value(NULL), | |
969 | "bt_ctf_field_string_get_value correctly handles NULL"); | |
970 | ret_string = bt_ctf_field_string_get_value(a_string_field); | |
971 | ok(ret_string, "bt_ctf_field_string_get_value returns a string"); | |
d50c7132 | 972 | ok(ret_string ? !strcmp(ret_string, test_string) : 0, |
10817e06 | 973 | "bt_ctf_field_string_get_value returns a correct value"); |
39d74371 JG |
974 | bt_ctf_field_unsigned_integer_set_value(uint_35_field, |
975 | SEQUENCE_TEST_LENGTH); | |
10817e06 | 976 | |
7cfd41d6 JG |
977 | ok(bt_ctf_field_type_variant_get_field_type_from_tag(NULL, |
978 | enum_container_field) == NULL, | |
979 | "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL variant type correctly"); | |
980 | ok(bt_ctf_field_type_variant_get_field_type_from_tag(variant_type, | |
981 | NULL) == NULL, | |
982 | "bt_ctf_field_type_variant_get_field_type_from_tag handles a NULL tag correctly"); | |
983 | ret_field_type = bt_ctf_field_type_variant_get_field_type_from_tag( | |
984 | variant_type, enum_variant_field); | |
985 | ok(ret_field_type == int_16_type, | |
986 | "bt_ctf_field_type_variant_get_field_type_from_tag returns the correct field type"); | |
987 | ||
10817e06 JG |
988 | ok(bt_ctf_field_sequence_get_length(a_sequence_field) == NULL, |
989 | "bt_ctf_field_sequence_get_length returns NULL when length is unset"); | |
39d74371 JG |
990 | ok(bt_ctf_field_sequence_set_length(a_sequence_field, |
991 | uint_35_field) == 0, "Set a sequence field's length"); | |
cd95e351 JG |
992 | ret_field = bt_ctf_field_sequence_get_length(a_sequence_field); |
993 | ok(ret_field == uint_35_field, | |
994 | "bt_ctf_field_sequence_get_length returns the correct length field"); | |
995 | ok(bt_ctf_field_sequence_get_length(NULL) == NULL, | |
996 | "bt_ctf_field_sequence_get_length properly handles NULL"); | |
39d74371 JG |
997 | |
998 | for (i = 0; i < SEQUENCE_TEST_LENGTH; i++) { | |
999 | int_16_field = bt_ctf_field_sequence_get_field( | |
1000 | a_sequence_field, i); | |
1001 | bt_ctf_field_signed_integer_set_value(int_16_field, 4 - i); | |
1002 | bt_ctf_field_put(int_16_field); | |
1003 | } | |
1004 | ||
1fac895e JG |
1005 | for (i = 0; i < ARRAY_TEST_LENGTH; i++) { |
1006 | int_16_field = bt_ctf_field_array_get_field( | |
1007 | an_array_field, i); | |
1008 | bt_ctf_field_signed_integer_set_value(int_16_field, i); | |
1009 | bt_ctf_field_put(int_16_field); | |
1010 | } | |
1011 | ||
39d74371 JG |
1012 | bt_ctf_clock_set_time(clock, ++current_time); |
1013 | ok(bt_ctf_stream_append_event(stream, event) == 0, | |
1014 | "Append a complex event to a stream"); | |
12c8a1a3 JG |
1015 | |
1016 | /* | |
1017 | * Populate the custom packet context field with a dummy value | |
1018 | * otherwise flush will fail. | |
1019 | */ | |
1020 | packet_context = bt_ctf_stream_get_packet_context(stream); | |
1021 | packet_context_field = bt_ctf_field_structure_get_field(packet_context, | |
35e8709f | 1022 | "custom_packet_context_field"); |
12c8a1a3 JG |
1023 | bt_ctf_field_unsigned_integer_set_value(packet_context_field, 1); |
1024 | ||
39d74371 JG |
1025 | ok(bt_ctf_stream_flush(stream) == 0, |
1026 | "Flush a stream containing a complex event"); | |
1027 | ||
1028 | bt_ctf_field_put(uint_35_field); | |
1029 | bt_ctf_field_put(a_string_field); | |
1030 | bt_ctf_field_put(inner_structure_field); | |
1031 | bt_ctf_field_put(complex_structure_field); | |
1032 | bt_ctf_field_put(a_sequence_field); | |
1fac895e | 1033 | bt_ctf_field_put(an_array_field); |
39d74371 JG |
1034 | bt_ctf_field_put(enum_variant_field); |
1035 | bt_ctf_field_put(enum_container_field); | |
1036 | bt_ctf_field_put(variant_field); | |
cd95e351 | 1037 | bt_ctf_field_put(ret_field); |
12c8a1a3 JG |
1038 | bt_ctf_field_put(packet_context_field); |
1039 | bt_ctf_field_put(packet_context); | |
39d74371 JG |
1040 | bt_ctf_field_type_put(uint_35_type); |
1041 | bt_ctf_field_type_put(int_16_type); | |
1042 | bt_ctf_field_type_put(string_type); | |
1043 | bt_ctf_field_type_put(sequence_type); | |
1fac895e | 1044 | bt_ctf_field_type_put(array_type); |
39d74371 JG |
1045 | bt_ctf_field_type_put(inner_structure_type); |
1046 | bt_ctf_field_type_put(complex_structure_type); | |
1047 | bt_ctf_field_type_put(uint_3_type); | |
1048 | bt_ctf_field_type_put(enum_variant_type); | |
1049 | bt_ctf_field_type_put(variant_type); | |
7cfd41d6 | 1050 | bt_ctf_field_type_put(ret_field_type); |
39d74371 JG |
1051 | bt_ctf_event_class_put(event_class); |
1052 | bt_ctf_event_put(event); | |
1053 | } | |
1054 | ||
1055 | void type_field_tests() | |
1056 | { | |
1057 | struct bt_ctf_field *uint_12; | |
1058 | struct bt_ctf_field *int_16; | |
1059 | struct bt_ctf_field *string; | |
0abce37e | 1060 | struct bt_ctf_field *enumeration; |
39d74371 JG |
1061 | struct bt_ctf_field_type *composite_structure_type; |
1062 | struct bt_ctf_field_type *structure_seq_type; | |
1063 | struct bt_ctf_field_type *string_type; | |
1064 | struct bt_ctf_field_type *sequence_type; | |
1065 | struct bt_ctf_field_type *uint_8_type; | |
1066 | struct bt_ctf_field_type *int_16_type; | |
1067 | struct bt_ctf_field_type *uint_12_type = | |
1068 | bt_ctf_field_type_integer_create(12); | |
0abce37e JG |
1069 | struct bt_ctf_field_type *enumeration_type; |
1070 | struct bt_ctf_field_type *enumeration_sequence_type; | |
1071 | struct bt_ctf_field_type *enumeration_array_type; | |
10817e06 | 1072 | struct bt_ctf_field_type *returned_type; |
7cfd41d6 | 1073 | const char *ret_string; |
10817e06 JG |
1074 | |
1075 | returned_type = bt_ctf_field_get_type(NULL); | |
1076 | ok(!returned_type, "bt_ctf_field_get_type handles NULL correctly"); | |
39d74371 JG |
1077 | |
1078 | ok(uint_12_type, "Create an unsigned integer type"); | |
1079 | ok(bt_ctf_field_type_integer_set_base(uint_12_type, | |
1080 | BT_CTF_INTEGER_BASE_BINARY) == 0, | |
1081 | "Set integer type's base as binary"); | |
1082 | ok(bt_ctf_field_type_integer_set_base(uint_12_type, | |
1083 | BT_CTF_INTEGER_BASE_DECIMAL) == 0, | |
1084 | "Set integer type's base as decimal"); | |
1085 | ok(bt_ctf_field_type_integer_set_base(uint_12_type, | |
1086 | BT_CTF_INTEGER_BASE_UNKNOWN), | |
1087 | "Reject integer type's base set as unknown"); | |
1088 | ok(bt_ctf_field_type_integer_set_base(uint_12_type, | |
1089 | BT_CTF_INTEGER_BASE_OCTAL) == 0, | |
1090 | "Set integer type's base as octal"); | |
1091 | ok(bt_ctf_field_type_integer_set_base(uint_12_type, | |
1092 | BT_CTF_INTEGER_BASE_HEXADECIMAL) == 0, | |
1093 | "Set integer type's base as hexadecimal"); | |
1094 | ok(bt_ctf_field_type_integer_set_base(uint_12_type, 457417), | |
1095 | "Reject unknown integer base value"); | |
1096 | ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 952835) == 0, | |
1097 | "Set integer type signedness to signed"); | |
1098 | ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0) == 0, | |
1099 | "Set integer type signedness to unsigned"); | |
7cfd41d6 JG |
1100 | ok(bt_ctf_field_type_integer_get_size(NULL) < 0, |
1101 | "bt_ctf_field_type_integer_get_size handles NULL correctly"); | |
1102 | ok(bt_ctf_field_type_integer_get_size(uint_12_type) == 12, | |
1103 | "bt_ctf_field_type_integer_get_size returns a correct value"); | |
1104 | ok(bt_ctf_field_type_integer_get_signed(NULL) < 0, | |
1105 | "bt_ctf_field_type_integer_get_signed handles NULL correctly"); | |
1106 | ok(bt_ctf_field_type_integer_get_signed(uint_12_type) == 0, | |
1107 | "bt_ctf_field_type_integer_get_signed returns a correct value for unsigned types"); | |
1108 | ||
1109 | ok(bt_ctf_field_type_set_byte_order(NULL, | |
1110 | BT_CTF_BYTE_ORDER_LITTLE_ENDIAN) < 0, | |
1111 | "bt_ctf_field_type_set_byte_order handles NULL correctly"); | |
1112 | ok(bt_ctf_field_type_set_byte_order(uint_12_type, | |
1113 | (enum bt_ctf_byte_order) 42) < 0, | |
1114 | "bt_ctf_field_type_set_byte_order rejects invalid values"); | |
1115 | ok(bt_ctf_field_type_set_byte_order(uint_12_type, | |
1116 | BT_CTF_BYTE_ORDER_LITTLE_ENDIAN) == 0, | |
1117 | "Set an integer's byte order to little endian"); | |
1118 | ok(bt_ctf_field_type_set_byte_order(uint_12_type, | |
1119 | BT_CTF_BYTE_ORDER_BIG_ENDIAN) == 0, | |
1120 | "Set an integer's byte order to big endian"); | |
1121 | ok(bt_ctf_field_type_get_byte_order(uint_12_type) == | |
1122 | BT_CTF_BYTE_ORDER_BIG_ENDIAN, | |
1123 | "bt_ctf_field_type_get_byte_order returns a correct value"); | |
1124 | ok(bt_ctf_field_type_get_byte_order(NULL) == | |
1125 | BT_CTF_BYTE_ORDER_UNKNOWN, | |
1126 | "bt_ctf_field_type_get_byte_order handles NULL correctly"); | |
1127 | ||
1128 | ok(bt_ctf_field_type_get_type_id(NULL) == | |
1129 | CTF_TYPE_UNKNOWN, | |
1130 | "bt_ctf_field_type_get_type_id handles NULL correctly"); | |
1131 | ok(bt_ctf_field_type_get_type_id(uint_12_type) == | |
1132 | CTF_TYPE_INTEGER, | |
1133 | "bt_ctf_field_type_get_type_id returns a correct value with an integer type"); | |
1134 | ||
1135 | ok(bt_ctf_field_type_integer_get_base(NULL) == | |
1136 | BT_CTF_INTEGER_BASE_UNKNOWN, | |
1137 | "bt_ctf_field_type_integer_get_base handles NULL correctly"); | |
1138 | ok(bt_ctf_field_type_integer_get_base(uint_12_type) == | |
1139 | BT_CTF_INTEGER_BASE_HEXADECIMAL, | |
1140 | "bt_ctf_field_type_integer_get_base returns a correct value"); | |
1141 | ||
1142 | ok(bt_ctf_field_type_integer_set_encoding(NULL, CTF_STRING_ASCII) < 0, | |
1143 | "bt_ctf_field_type_integer_set_encoding handles NULL correctly"); | |
1144 | ok(bt_ctf_field_type_integer_set_encoding(uint_12_type, | |
1145 | (enum ctf_string_encoding) 123) < 0, | |
1146 | "bt_ctf_field_type_integer_set_encoding handles invalid encodings correctly"); | |
1147 | ok(bt_ctf_field_type_integer_set_encoding(uint_12_type, | |
1148 | CTF_STRING_UTF8) == 0, | |
1149 | "Set integer type encoding to UTF8"); | |
1150 | ok(bt_ctf_field_type_integer_get_encoding(NULL) == CTF_STRING_UNKNOWN, | |
1151 | "bt_ctf_field_type_integer_get_encoding handles NULL correctly"); | |
1152 | ok(bt_ctf_field_type_integer_get_encoding(uint_12_type) == CTF_STRING_UTF8, | |
1153 | "bt_ctf_field_type_integer_get_encoding returns a correct value"); | |
39d74371 JG |
1154 | |
1155 | int_16_type = bt_ctf_field_type_integer_create(16); | |
1156 | bt_ctf_field_type_integer_set_signed(int_16_type, 1); | |
7cfd41d6 JG |
1157 | ok(bt_ctf_field_type_integer_get_signed(int_16_type) == 1, |
1158 | "bt_ctf_field_type_integer_get_signed returns a correct value for signed types"); | |
39d74371 JG |
1159 | uint_8_type = bt_ctf_field_type_integer_create(8); |
1160 | sequence_type = | |
1161 | bt_ctf_field_type_sequence_create(int_16_type, "seq_len"); | |
1162 | ok(sequence_type, "Create a sequence of int16_t type"); | |
7cfd41d6 JG |
1163 | ok(bt_ctf_field_type_get_type_id(sequence_type) == |
1164 | CTF_TYPE_SEQUENCE, | |
1165 | "bt_ctf_field_type_get_type_id returns a correct value with a sequence type"); | |
1166 | ||
1167 | ok(bt_ctf_field_type_sequence_get_length_field_name(NULL) == NULL, | |
1168 | "bt_ctf_field_type_sequence_get_length_field_name handles NULL correctly"); | |
1169 | ret_string = bt_ctf_field_type_sequence_get_length_field_name( | |
1170 | sequence_type); | |
1171 | ok(!strcmp(ret_string, "seq_len"), | |
1172 | "bt_ctf_field_type_sequence_get_length_field_name returns the correct value"); | |
1173 | ok(bt_ctf_field_type_sequence_get_element_type(NULL) == NULL, | |
1174 | "bt_ctf_field_type_sequence_get_element_type handles NULL correctly"); | |
1175 | returned_type = bt_ctf_field_type_sequence_get_element_type( | |
1176 | sequence_type); | |
1177 | ok(returned_type == int_16_type, | |
1178 | "bt_ctf_field_type_sequence_get_element_type returns the correct type"); | |
1179 | bt_ctf_field_type_put(returned_type); | |
39d74371 JG |
1180 | |
1181 | string_type = bt_ctf_field_type_string_create(); | |
1182 | ok(string_type, "Create a string type"); | |
1183 | ok(bt_ctf_field_type_string_set_encoding(string_type, | |
1184 | CTF_STRING_NONE), | |
1185 | "Reject invalid \"None\" string encoding"); | |
1186 | ok(bt_ctf_field_type_string_set_encoding(string_type, | |
1187 | 42), | |
1188 | "Reject invalid string encoding"); | |
1189 | ok(bt_ctf_field_type_string_set_encoding(string_type, | |
1190 | CTF_STRING_ASCII) == 0, | |
1191 | "Set string encoding to ASCII"); | |
1192 | ||
7cfd41d6 JG |
1193 | ok(bt_ctf_field_type_string_get_encoding(NULL) == |
1194 | CTF_STRING_UNKNOWN, | |
1195 | "bt_ctf_field_type_string_get_encoding handles NULL correctly"); | |
1196 | ok(bt_ctf_field_type_string_get_encoding(string_type) == | |
1197 | CTF_STRING_ASCII, | |
1198 | "bt_ctf_field_type_string_get_encoding returns the correct value"); | |
1199 | ||
39d74371 | 1200 | structure_seq_type = bt_ctf_field_type_structure_create(); |
7cfd41d6 JG |
1201 | ok(bt_ctf_field_type_get_type_id(structure_seq_type) == |
1202 | CTF_TYPE_STRUCT, | |
1203 | "bt_ctf_field_type_get_type_id returns a correct value with a structure type"); | |
39d74371 JG |
1204 | ok(structure_seq_type, "Create a structure type"); |
1205 | ok(bt_ctf_field_type_structure_add_field(structure_seq_type, | |
1206 | uint_8_type, "seq_len") == 0, | |
1207 | "Add a uint8_t type to a structure"); | |
1208 | ok(bt_ctf_field_type_structure_add_field(structure_seq_type, | |
1209 | sequence_type, "a_sequence") == 0, | |
1210 | "Add a sequence type to a structure"); | |
7cfd41d6 JG |
1211 | |
1212 | ok(bt_ctf_field_type_structure_get_field_count(NULL) < 0, | |
1213 | "bt_ctf_field_type_structure_get_field_count handles NULL correctly"); | |
1214 | ok(bt_ctf_field_type_structure_get_field_count(structure_seq_type) == 2, | |
1215 | "bt_ctf_field_type_structure_get_field_count returns a correct value"); | |
1216 | ||
1217 | ok(bt_ctf_field_type_structure_get_field(NULL, | |
1218 | &ret_string, &returned_type, 1) < 0, | |
1219 | "bt_ctf_field_type_structure_get_field handles a NULL type correctly"); | |
1220 | ok(bt_ctf_field_type_structure_get_field(structure_seq_type, | |
1221 | NULL, &returned_type, 1) < 0, | |
1222 | "bt_ctf_field_type_structure_get_field handles a NULL name correctly"); | |
1223 | ok(bt_ctf_field_type_structure_get_field(structure_seq_type, | |
1224 | &ret_string, NULL, 1) < 0, | |
1225 | "bt_ctf_field_type_structure_get_field handles a NULL return type correctly"); | |
1226 | ok(bt_ctf_field_type_structure_get_field(structure_seq_type, | |
1227 | &ret_string, &returned_type, 10) < 0, | |
1228 | "bt_ctf_field_type_structure_get_field handles an invalid index correctly"); | |
1229 | ok(bt_ctf_field_type_structure_get_field(structure_seq_type, | |
1230 | &ret_string, &returned_type, 1) == 0, | |
1231 | "bt_ctf_field_type_structure_get_field returns a field"); | |
1232 | ok(!strcmp(ret_string, "a_sequence"), | |
1233 | "bt_ctf_field_type_structure_get_field returns a correct field name"); | |
1234 | ok(returned_type == sequence_type, | |
1235 | "bt_ctf_field_type_structure_get_field returns a correct field type"); | |
1236 | bt_ctf_field_type_put(returned_type); | |
1237 | ||
1238 | ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL, "a_sequence") == NULL, | |
1239 | "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly"); | |
1240 | ok(bt_ctf_field_type_structure_get_field_type_by_name(structure_seq_type, NULL) == NULL, | |
1241 | "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly"); | |
1242 | returned_type = bt_ctf_field_type_structure_get_field_type_by_name( | |
1243 | structure_seq_type, "a_sequence"); | |
1244 | ok(returned_type == sequence_type, | |
1245 | "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type"); | |
1246 | bt_ctf_field_type_put(returned_type); | |
1247 | ||
39d74371 JG |
1248 | composite_structure_type = bt_ctf_field_type_structure_create(); |
1249 | ok(bt_ctf_field_type_structure_add_field(composite_structure_type, | |
1250 | string_type, "a_string") == 0, | |
1251 | "Add a string type to a structure"); | |
1252 | ok(bt_ctf_field_type_structure_add_field(composite_structure_type, | |
1253 | structure_seq_type, "inner_structure") == 0, | |
1254 | "Add a structure type to a structure"); | |
1255 | ||
7cfd41d6 JG |
1256 | ok(bt_ctf_field_type_structure_get_field_type_by_name( |
1257 | NULL, "a_sequence") == NULL, | |
1258 | "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field correctly"); | |
1259 | ok(bt_ctf_field_type_structure_get_field_type_by_name( | |
1260 | structure_seq_type, NULL) == NULL, | |
1261 | "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL field name correctly"); | |
1262 | returned_type = bt_ctf_field_type_structure_get_field_type_by_name( | |
1263 | structure_seq_type, "a_sequence"); | |
1264 | ok(returned_type == sequence_type, | |
1265 | "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type"); | |
1266 | bt_ctf_field_type_put(returned_type); | |
1267 | ||
39d74371 JG |
1268 | int_16 = bt_ctf_field_create(int_16_type); |
1269 | ok(int_16, "Instanciate a signed 16-bit integer"); | |
1270 | uint_12 = bt_ctf_field_create(uint_12_type); | |
1271 | ok(uint_12, "Instanciate an unsigned 12-bit integer"); | |
10817e06 JG |
1272 | returned_type = bt_ctf_field_get_type(int_16); |
1273 | ok(returned_type == int_16_type, | |
1274 | "bt_ctf_field_get_type returns the correct type"); | |
39d74371 JG |
1275 | |
1276 | /* Can't modify types after instanciating them */ | |
1277 | ok(bt_ctf_field_type_integer_set_base(uint_12_type, | |
1278 | BT_CTF_INTEGER_BASE_DECIMAL), | |
1279 | "Check an integer type' base can't be modified after instanciation"); | |
1280 | ok(bt_ctf_field_type_integer_set_signed(uint_12_type, 0), | |
1281 | "Check an integer type's signedness can't be modified after instanciation"); | |
1282 | ||
1283 | /* Check signed property is checked */ | |
1284 | ok(bt_ctf_field_signed_integer_set_value(uint_12, -52), | |
1285 | "Check bt_ctf_field_signed_integer_set_value is not allowed on an unsigned integer"); | |
1286 | ok(bt_ctf_field_unsigned_integer_set_value(int_16, 42), | |
1287 | "Check bt_ctf_field_unsigned_integer_set_value is not allowed on a signed integer"); | |
1288 | ||
1289 | /* Check overflows are properly tested for */ | |
1290 | ok(bt_ctf_field_signed_integer_set_value(int_16, -32768) == 0, | |
1291 | "Check -32768 is allowed for a signed 16-bit integer"); | |
1292 | ok(bt_ctf_field_signed_integer_set_value(int_16, 32767) == 0, | |
1293 | "Check 32767 is allowed for a signed 16-bit integer"); | |
1294 | ok(bt_ctf_field_signed_integer_set_value(int_16, 32768), | |
1295 | "Check 32768 is not allowed for a signed 16-bit integer"); | |
1296 | ok(bt_ctf_field_signed_integer_set_value(int_16, -32769), | |
1297 | "Check -32769 is not allowed for a signed 16-bit integer"); | |
1298 | ok(bt_ctf_field_signed_integer_set_value(int_16, -42) == 0, | |
1299 | "Check -42 is allowed for a signed 16-bit integer"); | |
1300 | ||
1301 | ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 4095) == 0, | |
1302 | "Check 4095 is allowed for an unsigned 12-bit integer"); | |
1303 | ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 4096), | |
1304 | "Check 4096 is not allowed for a unsigned 12-bit integer"); | |
1305 | ok(bt_ctf_field_unsigned_integer_set_value(uint_12, 0) == 0, | |
1306 | "Check 0 is allowed for an unsigned 12-bit integer"); | |
1307 | ||
1308 | string = bt_ctf_field_create(string_type); | |
1309 | ok(string, "Instanciate a string field"); | |
1310 | ok(bt_ctf_field_string_set_value(string, "A value") == 0, | |
1311 | "Set a string's value"); | |
1312 | ||
0abce37e JG |
1313 | enumeration_type = bt_ctf_field_type_enumeration_create(uint_12_type); |
1314 | ok(enumeration_type, | |
1315 | "Create an enumeration type with an unsigned 12-bit integer as container"); | |
1316 | enumeration_sequence_type = bt_ctf_field_type_sequence_create( | |
1317 | enumeration_type, "count"); | |
1318 | ok(!enumeration_sequence_type, | |
1319 | "Check enumeration types are validated when creating a sequence"); | |
1320 | enumeration_array_type = bt_ctf_field_type_array_create( | |
1321 | enumeration_type, 10); | |
1322 | ok(!enumeration_array_type, | |
1323 | "Check enumeration types are validated when creating an array"); | |
1324 | ok(bt_ctf_field_type_structure_add_field(composite_structure_type, | |
e6235f1f | 1325 | enumeration_type, "enumeration"), |
0abce37e JG |
1326 | "Check enumeration types are validated when adding them as structure members"); |
1327 | enumeration = bt_ctf_field_create(enumeration_type); | |
1328 | ok(!enumeration, | |
1329 | "Check enumeration types are validated before instantiation"); | |
1330 | ||
39d74371 JG |
1331 | bt_ctf_field_put(string); |
1332 | bt_ctf_field_put(uint_12); | |
1333 | bt_ctf_field_put(int_16); | |
0abce37e | 1334 | bt_ctf_field_put(enumeration); |
39d74371 JG |
1335 | bt_ctf_field_type_put(composite_structure_type); |
1336 | bt_ctf_field_type_put(structure_seq_type); | |
1337 | bt_ctf_field_type_put(string_type); | |
1338 | bt_ctf_field_type_put(sequence_type); | |
1339 | bt_ctf_field_type_put(uint_8_type); | |
1340 | bt_ctf_field_type_put(int_16_type); | |
1341 | bt_ctf_field_type_put(uint_12_type); | |
0abce37e JG |
1342 | bt_ctf_field_type_put(enumeration_type); |
1343 | bt_ctf_field_type_put(enumeration_sequence_type); | |
1344 | bt_ctf_field_type_put(enumeration_array_type); | |
7cfd41d6 | 1345 | bt_ctf_field_type_put(returned_type); |
39d74371 JG |
1346 | } |
1347 | ||
1348 | void packet_resize_test(struct bt_ctf_stream_class *stream_class, | |
1349 | struct bt_ctf_stream *stream, struct bt_ctf_clock *clock) | |
1350 | { | |
1351 | /* | |
1352 | * Append enough events to force the underlying packet to be resized. | |
1353 | * Also tests that a new event can be declared after a stream has been | |
1354 | * instantiated and used/flushed. | |
1355 | */ | |
1356 | int ret = 0; | |
1357 | int i; | |
1358 | struct bt_ctf_event_class *event_class = bt_ctf_event_class_create( | |
1359 | "Spammy_Event"); | |
1360 | struct bt_ctf_field_type *integer_type = | |
1361 | bt_ctf_field_type_integer_create(17); | |
1362 | struct bt_ctf_field_type *string_type = | |
1363 | bt_ctf_field_type_string_create(); | |
35e8709f JG |
1364 | struct bt_ctf_event *event = NULL; |
1365 | struct bt_ctf_field *ret_field = NULL; | |
1366 | struct bt_ctf_field_type *ret_field_type = NULL; | |
6809e227 | 1367 | uint64_t ret_uint64; |
12c8a1a3 | 1368 | int events_appended = 0; |
35e8709f JG |
1369 | struct bt_ctf_field *packet_context = NULL, |
1370 | *packet_context_field = NULL, *event_context = NULL; | |
39d74371 JG |
1371 | |
1372 | ret |= bt_ctf_event_class_add_field(event_class, integer_type, | |
1373 | "field_1"); | |
1374 | ret |= bt_ctf_event_class_add_field(event_class, string_type, | |
1375 | "a_string"); | |
1376 | ret |= bt_ctf_stream_class_add_event_class(stream_class, event_class); | |
1377 | ok(ret == 0, "Add a new event class to a stream class after writing an event"); | |
1378 | if (ret) { | |
1379 | goto end; | |
1380 | } | |
1381 | ||
1ff9582c JG |
1382 | event = bt_ctf_event_create(event_class); |
1383 | ret_field = bt_ctf_event_get_payload_by_index(event, 0); | |
1384 | ret_field_type = bt_ctf_field_get_type(ret_field); | |
1385 | ok(ret_field_type == integer_type, | |
1386 | "bt_ctf_event_get_payload_by_index returns a correct field"); | |
1387 | bt_ctf_field_type_put(ret_field_type); | |
1388 | bt_ctf_field_put(ret_field); | |
1389 | ||
1390 | ok(bt_ctf_event_get_payload_by_index(NULL, 0) == NULL, | |
1391 | "bt_ctf_event_get_payload_by_index handles NULL correctly"); | |
1392 | ok(bt_ctf_event_get_payload_by_index(event, 4) == NULL, | |
1393 | "bt_ctf_event_get_payload_by_index handles an invalid index correctly"); | |
1394 | bt_ctf_event_put(event); | |
1395 | ||
6e1f8ea1 JG |
1396 | ok(bt_ctf_stream_get_event_context(NULL) == NULL, |
1397 | "bt_ctf_stream_get_event_context handles NULL correctly"); | |
1398 | event_context = bt_ctf_stream_get_event_context(stream); | |
1399 | ok(event_context, | |
1400 | "bt_ctf_stream_get_event_context returns a stream event context"); | |
1401 | ok(bt_ctf_stream_set_event_context(NULL, event_context) < 0, | |
1402 | "bt_ctf_stream_set_event_context handles a NULL stream correctly"); | |
1403 | ok(bt_ctf_stream_set_event_context(stream, NULL) < 0, | |
1404 | "bt_ctf_stream_set_event_context handles a NULL stream event context correctly"); | |
1405 | ok(!bt_ctf_stream_set_event_context(stream, event_context), | |
1406 | "bt_ctf_stream_set_event_context correctly set a stream event context"); | |
1407 | ret_field = bt_ctf_field_create(integer_type); | |
1408 | ok(bt_ctf_stream_set_event_context(stream, ret_field) < 0, | |
1409 | "bt_ctf_stream_set_event_context rejects an event context of incorrect type"); | |
1410 | bt_ctf_field_put(ret_field); | |
1411 | ||
39d74371 | 1412 | for (i = 0; i < PACKET_RESIZE_TEST_LENGTH; i++) { |
1ff9582c | 1413 | event = bt_ctf_event_create(event_class); |
39d74371 JG |
1414 | struct bt_ctf_field *integer = |
1415 | bt_ctf_field_create(integer_type); | |
1416 | struct bt_ctf_field *string = | |
1417 | bt_ctf_field_create(string_type); | |
1418 | ||
1419 | ret |= bt_ctf_clock_set_time(clock, ++current_time); | |
1420 | ret |= bt_ctf_field_unsigned_integer_set_value(integer, i); | |
1421 | ret |= bt_ctf_event_set_payload(event, "field_1", | |
1422 | integer); | |
1423 | bt_ctf_field_put(integer); | |
1424 | ret |= bt_ctf_field_string_set_value(string, "This is a test"); | |
1425 | ret |= bt_ctf_event_set_payload(event, "a_string", | |
1426 | string); | |
1427 | bt_ctf_field_put(string); | |
6e1f8ea1 JG |
1428 | |
1429 | /* Populate stream event context */ | |
1430 | integer = bt_ctf_field_structure_get_field(event_context, | |
1431 | "common_event_context"); | |
1432 | ret |= bt_ctf_field_unsigned_integer_set_value(integer, | |
1433 | i % 42); | |
1434 | bt_ctf_field_put(integer); | |
1435 | ||
39d74371 JG |
1436 | ret |= bt_ctf_stream_append_event(stream, event); |
1437 | bt_ctf_event_put(event); | |
1438 | ||
1439 | if (ret) { | |
1440 | break; | |
1441 | } | |
1442 | } | |
12c8a1a3 | 1443 | |
6e1f8ea1 | 1444 | events_appended = !!(i == PACKET_RESIZE_TEST_LENGTH); |
3c1d148b | 1445 | ok(bt_ctf_stream_get_discarded_events_count(NULL, &ret_uint64) < 0, |
6809e227 | 1446 | "bt_ctf_stream_get_discarded_events_count handles a NULL stream correctly"); |
3c1d148b | 1447 | ok(bt_ctf_stream_get_discarded_events_count(stream, NULL) < 0, |
6809e227 JG |
1448 | "bt_ctf_stream_get_discarded_events_count handles a NULL return pointer correctly"); |
1449 | ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64); | |
1450 | ok(ret == 0 && ret_uint64 == 0, | |
1451 | "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when none were discarded"); | |
1452 | bt_ctf_stream_append_discarded_events(stream, 1000); | |
1453 | ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64); | |
1454 | ok(ret == 0 && ret_uint64 == 1000, | |
1455 | "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events when some were discarded"); | |
1456 | ||
39d74371 | 1457 | end: |
12c8a1a3 JG |
1458 | ok(events_appended, "Append 100 000 events to a stream"); |
1459 | ||
1460 | /* | |
1461 | * Populate the custom packet context field with a dummy value | |
1462 | * otherwise flush will fail. | |
1463 | */ | |
1464 | packet_context = bt_ctf_stream_get_packet_context(stream); | |
1465 | packet_context_field = bt_ctf_field_structure_get_field(packet_context, | |
35e8709f | 1466 | "custom_packet_context_field"); |
12c8a1a3 JG |
1467 | bt_ctf_field_unsigned_integer_set_value(packet_context_field, 2); |
1468 | ||
39d74371 JG |
1469 | ok(bt_ctf_stream_flush(stream) == 0, |
1470 | "Flush a stream that forces a packet resize"); | |
6809e227 JG |
1471 | ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64); |
1472 | ok(ret == 0 && ret_uint64 == 1000, | |
1473 | "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush"); | |
39d74371 JG |
1474 | bt_ctf_field_type_put(integer_type); |
1475 | bt_ctf_field_type_put(string_type); | |
12c8a1a3 JG |
1476 | bt_ctf_field_put(packet_context); |
1477 | bt_ctf_field_put(packet_context_field); | |
6e1f8ea1 | 1478 | bt_ctf_field_put(event_context); |
39d74371 JG |
1479 | bt_ctf_event_class_put(event_class); |
1480 | } | |
1481 | ||
1482 | int main(int argc, char **argv) | |
1483 | { | |
1484 | char trace_path[] = "/tmp/ctfwriter_XXXXXX"; | |
1485 | char metadata_path[sizeof(trace_path) + 9]; | |
1486 | const char *clock_name = "test_clock"; | |
1487 | const char *clock_description = "This is a test clock"; | |
5494ce8b JG |
1488 | const char *returned_clock_name; |
1489 | const char *returned_clock_description; | |
1490 | const uint64_t frequency = 1123456789; | |
39d74371 JG |
1491 | const uint64_t offset_s = 1351530929945824323; |
1492 | const uint64_t offset = 1234567; | |
1493 | const uint64_t precision = 10; | |
5494ce8b | 1494 | const int is_absolute = 0xFF; |
39d74371 JG |
1495 | char *metadata_string; |
1496 | struct bt_ctf_writer *writer; | |
1497 | struct utsname name; | |
22843b66 | 1498 | char hostname[BABELTRACE_HOST_NAME_MAX]; |
1ff9582c | 1499 | struct bt_ctf_clock *clock, *ret_clock; |
39d74371 JG |
1500 | struct bt_ctf_stream_class *stream_class; |
1501 | struct bt_ctf_stream *stream1; | |
e3c971da | 1502 | const char *ret_string; |
e61caf8e JG |
1503 | const unsigned char *ret_uuid; |
1504 | unsigned char tmp_uuid[16] = { 0 }; | |
b34f4d90 JG |
1505 | struct bt_ctf_field_type *packet_context_type, |
1506 | *packet_context_field_type, | |
35e8709f JG |
1507 | *integer_type, |
1508 | *stream_event_context_type, | |
1509 | *ret_field_type; | |
8cdae8c6 | 1510 | struct bt_ctf_trace *trace; |
12c8a1a3 | 1511 | int ret; |
39d74371 JG |
1512 | |
1513 | if (argc < 3) { | |
1514 | printf("Usage: tests-ctf-writer path_to_ctf_parser_test path_to_babeltrace\n"); | |
783c9151 | 1515 | return -1; |
39d74371 JG |
1516 | } |
1517 | ||
1518 | plan_no_plan(); | |
1519 | ||
1520 | if (!mkdtemp(trace_path)) { | |
1521 | perror("# perror"); | |
1522 | } | |
1523 | ||
1524 | strcpy(metadata_path, trace_path); | |
1525 | strcat(metadata_path + sizeof(trace_path) - 1, "/metadata"); | |
1526 | ||
1527 | writer = bt_ctf_writer_create(trace_path); | |
1528 | ok(writer, "bt_ctf_create succeeds in creating trace with path"); | |
1529 | ||
1530 | /* Add environment context to the trace */ | |
22843b66 JG |
1531 | ret = gethostname(hostname, sizeof(hostname)); |
1532 | if (ret < 0) { | |
1533 | return ret; | |
1534 | } | |
39d74371 JG |
1535 | ok(bt_ctf_writer_add_environment_field(writer, "host", hostname) == 0, |
1536 | "Add host (%s) environment field to writer instance", | |
1537 | hostname); | |
1538 | ok(bt_ctf_writer_add_environment_field(NULL, "test_field", | |
1539 | "test_value"), | |
1540 | "bt_ctf_writer_add_environment_field error with NULL writer"); | |
1541 | ok(bt_ctf_writer_add_environment_field(writer, NULL, | |
1542 | "test_value"), | |
1543 | "bt_ctf_writer_add_environment_field error with NULL field name"); | |
1544 | ok(bt_ctf_writer_add_environment_field(writer, "test_field", | |
1545 | NULL), | |
1546 | "bt_ctf_writer_add_environment_field error with NULL field value"); | |
1547 | ||
1548 | if (uname(&name)) { | |
1549 | perror("uname"); | |
1550 | return -1; | |
1551 | } | |
1552 | ||
1553 | ok(bt_ctf_writer_add_environment_field(writer, "sysname", name.sysname) | |
1554 | == 0, "Add sysname (%s) environment field to writer instance", | |
1555 | name.sysname); | |
1556 | ok(bt_ctf_writer_add_environment_field(writer, "nodename", | |
1557 | name.nodename) == 0, | |
1558 | "Add nodename (%s) environment field to writer instance", | |
1559 | name.nodename); | |
1560 | ok(bt_ctf_writer_add_environment_field(writer, "release", name.release) | |
1561 | == 0, "Add release (%s) environment field to writer instance", | |
1562 | name.release); | |
1563 | ok(bt_ctf_writer_add_environment_field(writer, "version", name.version) | |
1564 | == 0, "Add version (%s) environment field to writer instance", | |
1565 | name.version); | |
1566 | ok(bt_ctf_writer_add_environment_field(writer, "machine", name.machine) | |
1567 | == 0, "Add machine (%s) environment field to writer istance", | |
1568 | name.machine); | |
1569 | ||
1570 | /* Define a clock and add it to the trace */ | |
5494ce8b JG |
1571 | ok(bt_ctf_clock_create("signed") == NULL, |
1572 | "Illegal clock name rejected"); | |
39d74371 JG |
1573 | ok(bt_ctf_clock_create(NULL) == NULL, "NULL clock name rejected"); |
1574 | clock = bt_ctf_clock_create(clock_name); | |
1575 | ok(clock, "Clock created sucessfully"); | |
5494ce8b JG |
1576 | returned_clock_name = bt_ctf_clock_get_name(clock); |
1577 | ok(returned_clock_name, "bt_ctf_clock_get_name returns a clock name"); | |
d50c7132 | 1578 | ok(returned_clock_name ? !strcmp(returned_clock_name, clock_name) : 0, |
5494ce8b JG |
1579 | "Returned clock name is valid"); |
1580 | ||
1581 | returned_clock_description = bt_ctf_clock_get_description(clock); | |
1582 | ok(!returned_clock_description, "bt_ctf_clock_get_description returns NULL on an unset description"); | |
1583 | ok(bt_ctf_clock_set_description(clock, clock_description) == 0, | |
1584 | "Clock description set successfully"); | |
1585 | ||
1586 | returned_clock_description = bt_ctf_clock_get_description(clock); | |
1587 | ok(returned_clock_description, | |
1588 | "bt_ctf_clock_get_description returns a description."); | |
d50c7132 JG |
1589 | ok(returned_clock_description ? |
1590 | !strcmp(returned_clock_description, clock_description) : 0, | |
5494ce8b JG |
1591 | "Returned clock description is valid"); |
1592 | ||
1593 | ok(bt_ctf_clock_get_frequency(clock) == DEFAULT_CLOCK_FREQ, | |
1594 | "bt_ctf_clock_get_frequency returns the correct default frequency"); | |
39d74371 JG |
1595 | ok(bt_ctf_clock_set_frequency(clock, frequency) == 0, |
1596 | "Set clock frequency"); | |
5494ce8b JG |
1597 | ok(bt_ctf_clock_get_frequency(clock) == frequency, |
1598 | "bt_ctf_clock_get_frequency returns the correct frequency once it is set"); | |
1599 | ||
1600 | ok(bt_ctf_clock_get_offset_s(clock) == DEFAULT_CLOCK_OFFSET_S, | |
1601 | "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds)"); | |
39d74371 JG |
1602 | ok(bt_ctf_clock_set_offset_s(clock, offset_s) == 0, |
1603 | "Set clock offset (seconds)"); | |
5494ce8b JG |
1604 | ok(bt_ctf_clock_get_offset_s(clock) == offset_s, |
1605 | "bt_ctf_clock_get_offset_s returns the correct default offset (in seconds) once it is set"); | |
1606 | ||
1607 | ok(bt_ctf_clock_get_offset(clock) == DEFAULT_CLOCK_OFFSET, | |
1608 | "bt_ctf_clock_get_frequency returns the correct default offset (in ticks)"); | |
39d74371 | 1609 | ok(bt_ctf_clock_set_offset(clock, offset) == 0, "Set clock offset"); |
5494ce8b JG |
1610 | ok(bt_ctf_clock_get_offset(clock) == offset, |
1611 | "bt_ctf_clock_get_frequency returns the correct default offset (in ticks) once it is set"); | |
1612 | ||
1613 | ok(bt_ctf_clock_get_precision(clock) == DEFAULT_CLOCK_PRECISION, | |
1614 | "bt_ctf_clock_get_precision returns the correct default precision"); | |
39d74371 JG |
1615 | ok(bt_ctf_clock_set_precision(clock, precision) == 0, |
1616 | "Set clock precision"); | |
5494ce8b JG |
1617 | ok(bt_ctf_clock_get_precision(clock) == precision, |
1618 | "bt_ctf_clock_get_precision returns the correct precision once it is set"); | |
1619 | ||
1620 | ok(bt_ctf_clock_get_is_absolute(clock) == DEFAULT_CLOCK_IS_ABSOLUTE, | |
1621 | "bt_ctf_clock_get_precision returns the correct default is_absolute attribute"); | |
1622 | ok(bt_ctf_clock_set_is_absolute(clock, is_absolute) == 0, | |
39d74371 | 1623 | "Set clock absolute property"); |
5494ce8b JG |
1624 | ok(bt_ctf_clock_get_is_absolute(clock) == !!is_absolute, |
1625 | "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set"); | |
1626 | ||
1627 | ok(bt_ctf_clock_get_time(clock) == DEFAULT_CLOCK_TIME, | |
1628 | "bt_ctf_clock_get_time returns the correct default time"); | |
1629 | ok(bt_ctf_clock_set_time(clock, current_time) == 0, | |
1630 | "Set clock time"); | |
1631 | ok(bt_ctf_clock_get_time(clock) == current_time, | |
1632 | "bt_ctf_clock_get_time returns the correct time once it is set"); | |
39d74371 JG |
1633 | |
1634 | ok(bt_ctf_writer_add_clock(writer, clock) == 0, | |
1635 | "Add clock to writer instance"); | |
1636 | ok(bt_ctf_writer_add_clock(writer, clock), | |
1637 | "Verify a clock can't be added twice to a writer instance"); | |
1638 | ||
8cdae8c6 JG |
1639 | ok(!bt_ctf_writer_get_trace(NULL), |
1640 | "bt_ctf_writer_get_trace correctly handles NULL"); | |
1641 | trace = bt_ctf_writer_get_trace(writer); | |
1642 | ok(trace, | |
1643 | "bt_ctf_writer_get_trace returns a bt_ctf_trace object"); | |
1644 | ok(bt_ctf_trace_get_clock_count(NULL) < 0, | |
1645 | "bt_ctf_trace_get_clock_count correctly handles NULL"); | |
1646 | ok(bt_ctf_trace_get_clock_count(trace) == 1, | |
1647 | "bt_ctf_trace_get_clock_count returns the correct number of clocks"); | |
1648 | ok(!bt_ctf_trace_get_clock(NULL, 0), | |
1649 | "bt_ctf_trace_get_clock correctly handles NULL"); | |
1650 | ok(!bt_ctf_trace_get_clock(trace, -1), | |
1651 | "bt_ctf_trace_get_clock correctly handles negative indexes"); | |
1652 | ok(!bt_ctf_trace_get_clock(trace, 1), | |
1653 | "bt_ctf_trace_get_clock correctly handles out of bound accesses"); | |
1654 | ret_clock = bt_ctf_trace_get_clock(trace, 0); | |
1655 | ok(ret_clock == clock, | |
1656 | "bt_ctf_trace_get_clock returns the right clock instance"); | |
1657 | bt_ctf_clock_put(ret_clock); | |
1658 | ||
5494ce8b JG |
1659 | ok(!bt_ctf_clock_get_name(NULL), |
1660 | "bt_ctf_clock_get_name correctly handles NULL"); | |
1661 | ok(!bt_ctf_clock_get_description(NULL), | |
1662 | "bt_ctf_clock_get_description correctly handles NULL"); | |
1663 | ok(bt_ctf_clock_get_frequency(NULL) == -1ULL, | |
1664 | "bt_ctf_clock_get_frequency correctly handles NULL"); | |
1665 | ok(bt_ctf_clock_get_precision(NULL) == -1ULL, | |
1666 | "bt_ctf_clock_get_precision correctly handles NULL"); | |
1667 | ok(bt_ctf_clock_get_offset_s(NULL) == -1ULL, | |
1668 | "bt_ctf_clock_get_offset_s correctly handles NULL"); | |
1669 | ok(bt_ctf_clock_get_offset(NULL) == -1ULL, | |
1670 | "bt_ctf_clock_get_offset correctly handles NULL"); | |
3c1d148b | 1671 | ok(bt_ctf_clock_get_is_absolute(NULL) < 0, |
5494ce8b JG |
1672 | "bt_ctf_clock_get_is_absolute correctly handles NULL"); |
1673 | ok(bt_ctf_clock_get_time(NULL) == -1ULL, | |
1674 | "bt_ctf_clock_get_time correctly handles NULL"); | |
1675 | ||
3c1d148b | 1676 | ok(bt_ctf_clock_set_description(NULL, NULL) < 0, |
5494ce8b | 1677 | "bt_ctf_clock_set_description correctly handles NULL clock"); |
3c1d148b | 1678 | ok(bt_ctf_clock_set_frequency(NULL, frequency) < 0, |
5494ce8b | 1679 | "bt_ctf_clock_set_frequency correctly handles NULL clock"); |
3c1d148b | 1680 | ok(bt_ctf_clock_set_precision(NULL, precision) < 0, |
5494ce8b | 1681 | "bt_ctf_clock_get_precision correctly handles NULL clock"); |
3c1d148b | 1682 | ok(bt_ctf_clock_set_offset_s(NULL, offset_s) < 0, |
5494ce8b | 1683 | "bt_ctf_clock_set_offset_s correctly handles NULL clock"); |
3c1d148b | 1684 | ok(bt_ctf_clock_set_offset(NULL, offset) < 0, |
5494ce8b | 1685 | "bt_ctf_clock_set_offset correctly handles NULL clock"); |
3c1d148b | 1686 | ok(bt_ctf_clock_set_is_absolute(NULL, is_absolute) < 0, |
5494ce8b | 1687 | "bt_ctf_clock_set_is_absolute correctly handles NULL clock"); |
3c1d148b | 1688 | ok(bt_ctf_clock_set_time(NULL, current_time) < 0, |
5494ce8b | 1689 | "bt_ctf_clock_set_time correctly handles NULL clock"); |
e61caf8e JG |
1690 | ok(bt_ctf_clock_get_uuid(NULL) == NULL, |
1691 | "bt_ctf_clock_get_uuid correctly handles NULL clock"); | |
1692 | ret_uuid = bt_ctf_clock_get_uuid(clock); | |
1693 | ok(ret_uuid, | |
1694 | "bt_ctf_clock_get_uuid returns a UUID"); | |
1695 | if (ret_uuid) { | |
1696 | memcpy(tmp_uuid, ret_uuid, sizeof(tmp_uuid)); | |
1697 | /* Slightly modify UUID */ | |
1698 | tmp_uuid[sizeof(tmp_uuid) - 1]++; | |
1699 | } | |
1700 | ||
1701 | ok(bt_ctf_clock_set_uuid(NULL, tmp_uuid) < 0, | |
1702 | "bt_ctf_clock_set_uuid correctly handles a NULL clock"); | |
1703 | ok(bt_ctf_clock_set_uuid(clock, NULL) < 0, | |
1704 | "bt_ctf_clock_set_uuid correctly handles a NULL UUID"); | |
1705 | ok(bt_ctf_clock_set_uuid(clock, tmp_uuid) == 0, | |
1706 | "bt_ctf_clock_set_uuid sets a new uuid succesfully"); | |
1707 | ret_uuid = bt_ctf_clock_get_uuid(clock); | |
1708 | ok(ret_uuid, | |
1709 | "bt_ctf_clock_get_uuid returns a UUID after setting a new one"); | |
1710 | ok(uuid_match(ret_uuid, tmp_uuid), | |
1711 | "bt_ctf_clock_get_uuid returns the correct UUID after setting a new one"); | |
5494ce8b | 1712 | |
39d74371 JG |
1713 | /* Define a stream class */ |
1714 | stream_class = bt_ctf_stream_class_create("test_stream"); | |
e3c971da JG |
1715 | |
1716 | ok(bt_ctf_stream_class_get_name(NULL) == NULL, | |
1717 | "bt_ctf_stream_class_get_name handles NULL correctly"); | |
1718 | ret_string = bt_ctf_stream_class_get_name(stream_class); | |
1719 | ok(!strcmp(ret_string, "test_stream"), | |
12c8a1a3 | 1720 | "bt_ctf_stream_class_get_name returns a correct stream class name"); |
e3c971da | 1721 | |
1ff9582c JG |
1722 | ok(bt_ctf_stream_class_get_clock(stream_class) == NULL, |
1723 | "bt_ctf_stream_class_get_clock returns NULL when a clock was not set"); | |
1724 | ok(bt_ctf_stream_class_get_clock(NULL) == NULL, | |
1725 | "bt_ctf_stream_class_get_clock handles NULL correctly"); | |
1726 | ||
39d74371 JG |
1727 | ok(stream_class, "Create stream class"); |
1728 | ok(bt_ctf_stream_class_set_clock(stream_class, clock) == 0, | |
1729 | "Set a stream class' clock"); | |
1ff9582c JG |
1730 | ret_clock = bt_ctf_stream_class_get_clock(stream_class); |
1731 | ok(ret_clock == clock, | |
1732 | "bt_ctf_stream_class_get_clock returns a correct clock"); | |
1733 | bt_ctf_clock_put(ret_clock); | |
39d74371 JG |
1734 | |
1735 | /* Test the event fields and event types APIs */ | |
1736 | type_field_tests(); | |
1737 | ||
1ff9582c JG |
1738 | ok(bt_ctf_stream_class_get_id(stream_class) < 0, |
1739 | "bt_ctf_stream_class_get_id returns an error when no id is set"); | |
1740 | ok(bt_ctf_stream_class_get_id(NULL) < 0, | |
1741 | "bt_ctf_stream_class_get_id handles NULL correctly"); | |
1742 | ok(bt_ctf_stream_class_set_id(NULL, 123) < 0, | |
1743 | "bt_ctf_stream_class_set_id handles NULL correctly"); | |
1744 | ok(bt_ctf_stream_class_set_id(stream_class, 123) == 0, | |
1745 | "Set an stream class' id"); | |
1746 | ok(bt_ctf_stream_class_get_id(stream_class) == 123, | |
1747 | "bt_ctf_stream_class_get_id returns the correct value"); | |
1748 | ||
12c8a1a3 JG |
1749 | /* Create a "uint5_t" equivalent custom packet context field */ |
1750 | packet_context_field_type = bt_ctf_field_type_integer_create(5); | |
1751 | ||
1752 | ok(bt_ctf_stream_class_get_packet_context_type(NULL) == NULL, | |
1753 | "bt_ctf_stream_class_get_packet_context_type handles NULL correctly"); | |
1754 | ||
1755 | /* Add a custom field to the stream class' packet context */ | |
1756 | packet_context_type = bt_ctf_stream_class_get_packet_context_type(stream_class); | |
1757 | ok(packet_context_type, | |
1758 | "bt_ctf_stream_class_get_packet_context_type returns a packet context type."); | |
1759 | ok(bt_ctf_field_type_get_type_id(packet_context_type) == CTF_TYPE_STRUCT, | |
1760 | "Packet context is a structure"); | |
1761 | ||
1762 | ok(bt_ctf_stream_class_set_packet_context_type(NULL, packet_context_type), | |
1763 | "bt_ctf_stream_class_set_packet_context_type handles a NULL stream class correctly"); | |
1764 | ok(bt_ctf_stream_class_set_packet_context_type(stream_class, NULL), | |
1765 | "bt_ctf_stream_class_set_packet_context_type handles a NULL packet context type correctly"); | |
b34f4d90 JG |
1766 | |
1767 | integer_type = bt_ctf_field_type_integer_create(32); | |
1768 | ok(bt_ctf_stream_class_set_packet_context_type(stream_class, | |
1769 | integer_type) < 0, | |
1770 | "bt_ctf_stream_class_set_packet_context_type rejects a packet context that is not a structure"); | |
12c8a1a3 | 1771 | ret = bt_ctf_field_type_structure_add_field(packet_context_type, |
35e8709f | 1772 | packet_context_field_type, "custom_packet_context_field"); |
12c8a1a3 JG |
1773 | ok(ret == 0, "Packet context field added successfully"); |
1774 | ||
35e8709f JG |
1775 | /* Define a stream event context containing a my_integer field. */ |
1776 | ok(bt_ctf_stream_class_get_event_context_type(NULL) == NULL, | |
1777 | "bt_ctf_stream_class_get_event_context_type handles NULL correctly"); | |
1778 | ok(bt_ctf_stream_class_get_event_context_type( | |
1779 | stream_class) == NULL, | |
1780 | "bt_ctf_stream_class_get_event_context_type returns NULL when no stream event context type was set."); | |
1781 | stream_event_context_type = bt_ctf_field_type_structure_create(); | |
1782 | bt_ctf_field_type_structure_add_field(stream_event_context_type, | |
1783 | integer_type, "common_event_context"); | |
1784 | ||
1785 | ok(bt_ctf_stream_class_set_event_context_type(NULL, | |
1786 | stream_event_context_type) < 0, | |
1787 | "bt_ctf_stream_class_set_event_context_type handles a NULL stream_class correctly"); | |
1788 | ok(bt_ctf_stream_class_set_event_context_type(stream_class, | |
1789 | NULL) < 0, | |
1790 | "bt_ctf_stream_class_set_event_context_type handles a NULL event_context correctly"); | |
1791 | ok(bt_ctf_stream_class_set_event_context_type(stream_class, | |
1792 | integer_type) < 0, | |
1793 | "bt_ctf_stream_class_set_event_context_type validates that the event context os a structure"); | |
1794 | ||
1795 | ok(bt_ctf_stream_class_set_event_context_type( | |
1796 | stream_class, stream_event_context_type) == 0, | |
1797 | "Set a new stream event context type"); | |
1798 | ret_field_type = bt_ctf_stream_class_get_event_context_type( | |
1799 | stream_class); | |
1800 | ok(ret_field_type == stream_event_context_type, | |
1801 | "bt_ctf_stream_class_get_event_context_type returns the correct field type."); | |
12c8a1a3 | 1802 | |
39d74371 JG |
1803 | /* Instantiate a stream and append events */ |
1804 | stream1 = bt_ctf_writer_create_stream(writer, stream_class); | |
1805 | ok(stream1, "Instanciate a stream class from writer"); | |
1806 | ||
12c8a1a3 JG |
1807 | /* |
1808 | * Try to modify the packet context type after a stream has been | |
1809 | * created. | |
1810 | */ | |
1811 | ret = bt_ctf_field_type_structure_add_field(packet_context_type, | |
1812 | packet_context_field_type, "should_fail"); | |
1813 | ok(ret < 0, | |
1814 | "Packet context type can't be modified once a stream class has been instanciated"); | |
1815 | ||
35e8709f JG |
1816 | /* |
1817 | * Try to modify the stream event context type after a stream has been | |
1818 | * created. | |
1819 | */ | |
1820 | ret = bt_ctf_field_type_structure_add_field(stream_event_context_type, | |
1821 | integer_type, "should_fail"); | |
1822 | ok(ret < 0, | |
1823 | "Stream event context type can't be modified once a stream class has been instanciated"); | |
1824 | ||
1825 | /* Should fail after instanciating a stream (frozen) */ | |
39d74371 JG |
1826 | ok(bt_ctf_stream_class_set_clock(stream_class, clock), |
1827 | "Changes to a stream class that was already instantiated fail"); | |
1828 | ||
1829 | append_simple_event(stream_class, stream1, clock); | |
1830 | ||
1831 | packet_resize_test(stream_class, stream1, clock); | |
1832 | ||
1833 | append_complex_event(stream_class, stream1, clock); | |
1834 | ||
1835 | metadata_string = bt_ctf_writer_get_metadata_string(writer); | |
1836 | ok(metadata_string, "Get metadata string"); | |
1837 | ||
1838 | bt_ctf_writer_flush_metadata(writer); | |
1839 | validate_metadata(argv[1], metadata_path); | |
1840 | validate_trace(argv[2], trace_path); | |
1841 | ||
1842 | bt_ctf_clock_put(clock); | |
1843 | bt_ctf_stream_class_put(stream_class); | |
1844 | bt_ctf_writer_put(writer); | |
1845 | bt_ctf_stream_put(stream1); | |
12c8a1a3 JG |
1846 | bt_ctf_field_type_put(packet_context_type); |
1847 | bt_ctf_field_type_put(packet_context_field_type); | |
b34f4d90 | 1848 | bt_ctf_field_type_put(integer_type); |
35e8709f JG |
1849 | bt_ctf_field_type_put(stream_event_context_type); |
1850 | bt_ctf_field_type_put(ret_field_type); | |
8cdae8c6 | 1851 | bt_ctf_trace_put(trace); |
39d74371 JG |
1852 | free(metadata_string); |
1853 | ||
1854 | /* Remove all trace files and delete temporary trace directory */ | |
1855 | DIR *trace_dir = opendir(trace_path); | |
1856 | if (!trace_dir) { | |
1857 | perror("# opendir"); | |
1858 | return -1; | |
1859 | } | |
1860 | ||
1861 | struct dirent *entry; | |
1862 | while ((entry = readdir(trace_dir))) { | |
1863 | if (entry->d_type == DT_REG) { | |
1864 | unlinkat(dirfd(trace_dir), entry->d_name, 0); | |
1865 | } | |
1866 | } | |
1867 | ||
1868 | rmdir(trace_path); | |
1869 | closedir(trace_dir); | |
1870 | ||
1871 | return 0; | |
1872 | } |