Silence -Wunused-but-set-variable error with clang
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-validate.c
CommitLineData
7b33a0e0
PP
1/*
2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 */
14
16699f85
PP
15#define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
16#define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
b03487ab 17#define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE"
3fa1b6a3 18#include "logging/comp-logging.h"
7b33a0e0 19
71c5da58 20#include <babeltrace2/babeltrace.h>
85e7137b 21#include "common/macros.h"
57952005 22#include "common/assert.h"
7b33a0e0
PP
23#include <glib.h>
24#include <stdint.h>
25#include <string.h>
26#include <inttypes.h>
27
28#include "ctf-meta-visitors.h"
16699f85 29#include "logging.h"
7b33a0e0
PP
30
31static
1f1f2720 32int validate_stream_class(struct ctf_stream_class *sc,
16699f85 33 struct meta_log_config *log_cfg)
7b33a0e0
PP
34{
35 int ret = 0;
939190b3
PP
36 struct ctf_field_class_int *int_fc;
37 struct ctf_field_class *fc;
7b33a0e0
PP
38
39 if (sc->is_translated) {
40 goto end;
41 }
42
939190b3
PP
43 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
44 (void *) sc->packet_context_fc, "timestamp_begin");
45 if (fc) {
af0c18e3
PP
46 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
47 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 48 BT_COMP_LOGE_STR("Invalid packet context field class: "
939190b3 49 "`timestamp_begin` member is not an integer field class.");
7b33a0e0
PP
50 goto invalid;
51 }
52
939190b3 53 int_fc = (void *) fc;
7b33a0e0 54
939190b3 55 if (int_fc->is_signed) {
16699f85 56 BT_COMP_LOGE_STR("Invalid packet context field class: "
7b33a0e0
PP
57 "`timestamp_begin` member is signed.");
58 goto invalid;
59 }
60 }
61
939190b3
PP
62 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
63 (void *) sc->packet_context_fc, "timestamp_end");
64 if (fc) {
af0c18e3
PP
65 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
66 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 67 BT_COMP_LOGE_STR("Invalid packet context field class: "
939190b3 68 "`timestamp_end` member is not an integer field class.");
7b33a0e0
PP
69 goto invalid;
70 }
71
939190b3 72 int_fc = (void *) fc;
7b33a0e0 73
939190b3 74 if (int_fc->is_signed) {
16699f85 75 BT_COMP_LOGE_STR("Invalid packet context field class: "
7b33a0e0
PP
76 "`timestamp_end` member is signed.");
77 goto invalid;
78 }
79 }
80
939190b3
PP
81 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
82 (void *) sc->packet_context_fc, "events_discarded");
83 if (fc) {
af0c18e3
PP
84 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
85 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 86 BT_COMP_LOGE_STR("Invalid packet context field class: "
939190b3 87 "`events_discarded` member is not an integer field class.");
7b33a0e0
PP
88 goto invalid;
89 }
90
939190b3 91 int_fc = (void *) fc;
7b33a0e0 92
939190b3 93 if (int_fc->is_signed) {
16699f85 94 BT_COMP_LOGE_STR("Invalid packet context field class: "
7b33a0e0
PP
95 "`events_discarded` member is signed.");
96 goto invalid;
97 }
98 }
99
939190b3
PP
100 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
101 (void *) sc->packet_context_fc, "packet_seq_num");
102 if (fc) {
af0c18e3
PP
103 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
104 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 105 BT_COMP_LOGE_STR("Invalid packet context field class: "
939190b3 106 "`packet_seq_num` member is not an integer field class.");
7b33a0e0
PP
107 goto invalid;
108 }
109
939190b3 110 int_fc = (void *) fc;
7b33a0e0 111
939190b3 112 if (int_fc->is_signed) {
16699f85 113 BT_COMP_LOGE_STR("Invalid packet context field class: "
7b33a0e0
PP
114 "`packet_seq_num` member is signed.");
115 goto invalid;
116 }
117 }
118
939190b3
PP
119 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
120 (void *) sc->packet_context_fc, "packet_size");
121 if (fc) {
af0c18e3
PP
122 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
123 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 124 BT_COMP_LOGE_STR("Invalid packet context field class: "
939190b3 125 "`packet_size` member is not an integer field class.");
7b33a0e0
PP
126 goto invalid;
127 }
128
939190b3 129 int_fc = (void *) fc;
7b33a0e0 130
939190b3 131 if (int_fc->is_signed) {
16699f85 132 BT_COMP_LOGE_STR("Invalid packet context field class: "
7b33a0e0
PP
133 "`packet_size` member is signed.");
134 goto invalid;
135 }
7b33a0e0
PP
136 }
137
939190b3
PP
138 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
139 (void *) sc->packet_context_fc, "content_size");
140 if (fc) {
af0c18e3
PP
141 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
142 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 143 BT_COMP_LOGE_STR("Invalid packet context field class: "
939190b3 144 "`content_size` member is not an integer field class.");
7b33a0e0
PP
145 goto invalid;
146 }
147
939190b3 148 int_fc = (void *) fc;
7b33a0e0 149
939190b3 150 if (int_fc->is_signed) {
16699f85 151 BT_COMP_LOGE_STR("Invalid packet context field class: "
7b33a0e0
PP
152 "`content_size` member is signed.");
153 goto invalid;
154 }
7b33a0e0
PP
155 }
156
939190b3
PP
157 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
158 (void *) sc->event_header_fc, "id");
159 if (fc) {
af0c18e3
PP
160 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
161 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 162 BT_COMP_LOGE_STR("Invalid event header field class: "
939190b3 163 "`id` member is not an integer field class.");
7b33a0e0
PP
164 goto invalid;
165 }
166
939190b3 167 int_fc = (void *) fc;
7b33a0e0 168
939190b3 169 if (int_fc->is_signed) {
16699f85 170 BT_COMP_LOGE_STR("Invalid event header field class: "
7b33a0e0
PP
171 "`id` member is signed.");
172 goto invalid;
173 }
174 } else {
175 if (sc->event_classes->len > 1) {
16699f85 176 BT_COMP_LOGE_STR("Invalid event header field class: "
7b33a0e0
PP
177 "missing `id` member as there's "
178 "more than one event class.");
179 goto invalid;
180 }
181 }
182
183 goto end;
184
185invalid:
186 ret = -1;
187
188end:
189 return ret;
190}
191
192BT_HIDDEN
1f1f2720 193int ctf_trace_class_validate(struct ctf_trace_class *ctf_tc,
16699f85 194 struct meta_log_config *log_cfg)
7b33a0e0
PP
195{
196 int ret = 0;
939190b3 197 struct ctf_field_class_int *int_fc;
7b33a0e0
PP
198 uint64_t i;
199
200 if (!ctf_tc->is_translated) {
939190b3
PP
201 struct ctf_field_class *fc;
202
203 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
204 (void *) ctf_tc->packet_header_fc, "magic");
205 if (fc) {
206 struct ctf_named_field_class *named_fc =
207 ctf_field_class_struct_borrow_member_by_index(
208 (void *) ctf_tc->packet_header_fc,
7b33a0e0
PP
209 0);
210
939190b3 211 if (named_fc->fc != fc) {
16699f85 212 BT_COMP_LOGE_STR("Invalid packet header field class: "
7b33a0e0
PP
213 "`magic` member is not the first member.");
214 goto invalid;
215 }
216
af0c18e3
PP
217 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
218 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 219 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3 220 "`magic` member is not an integer field class.");
7b33a0e0
PP
221 goto invalid;
222 }
223
939190b3 224 int_fc = (void *) fc;
7b33a0e0 225
939190b3 226 if (int_fc->is_signed) {
16699f85 227 BT_COMP_LOGE_STR("Invalid packet header field class: "
7b33a0e0
PP
228 "`magic` member is signed.");
229 goto invalid;
230 }
231
939190b3 232 if (int_fc->base.size != 32) {
16699f85 233 BT_COMP_LOGE_STR("Invalid packet header field class: "
7b33a0e0
PP
234 "`magic` member is not 32-bit.");
235 goto invalid;
236 }
237 }
238
939190b3
PP
239 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
240 (void *) ctf_tc->packet_header_fc, "stream_id");
241 if (fc) {
af0c18e3
PP
242 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
243 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 244 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3 245 "`stream_id` member is not an integer field class.");
7b33a0e0
PP
246 goto invalid;
247 }
248
939190b3 249 int_fc = (void *) fc;
7b33a0e0 250
939190b3 251 if (int_fc->is_signed) {
16699f85 252 BT_COMP_LOGE_STR("Invalid packet header field class: "
7b33a0e0
PP
253 "`stream_id` member is signed.");
254 goto invalid;
255 }
256 } else {
257 if (ctf_tc->stream_classes->len > 1) {
16699f85 258 BT_COMP_LOGE_STR("Invalid packet header field class: "
7b33a0e0
PP
259 "missing `stream_id` member as there's "
260 "more than one stream class.");
261 goto invalid;
262 }
263 }
264
939190b3
PP
265 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
266 (void *) ctf_tc->packet_header_fc,
7b33a0e0 267 "stream_instance_id");
939190b3 268 if (fc) {
af0c18e3
PP
269 if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
270 fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
16699f85 271 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3 272 "`stream_instance_id` member is not an integer field class.");
7b33a0e0
PP
273 goto invalid;
274 }
275
939190b3 276 int_fc = (void *) fc;
7b33a0e0 277
939190b3 278 if (int_fc->is_signed) {
16699f85 279 BT_COMP_LOGE_STR("Invalid packet header field class: "
7b33a0e0
PP
280 "`stream_instance_id` member is signed.");
281 goto invalid;
282 }
283 }
284
939190b3
PP
285 fc = ctf_field_class_struct_borrow_member_field_class_by_name(
286 (void *) ctf_tc->packet_header_fc, "uuid");
287 if (fc) {
288 struct ctf_field_class_array *array_fc = (void *) fc;
7b33a0e0 289
af0c18e3 290 if (fc->type != CTF_FIELD_CLASS_TYPE_ARRAY) {
16699f85 291 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3 292 "`uuid` member is not an array field class.");
7b33a0e0
PP
293 goto invalid;
294 }
295
939190b3 296 array_fc = (void *) fc;
7b33a0e0 297
939190b3 298 if (array_fc->length != 16) {
16699f85 299 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3 300 "`uuid` member is not a 16-element array field class.");
7b33a0e0
PP
301 goto invalid;
302 }
303
af0c18e3 304 if (array_fc->base.elem_fc->type != CTF_FIELD_CLASS_TYPE_INT) {
16699f85 305 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3
PP
306 "`uuid` member's element field class is not "
307 "an integer field class.");
7b33a0e0
PP
308 goto invalid;
309 }
310
939190b3 311 int_fc = (void *) array_fc->base.elem_fc;
7b33a0e0 312
939190b3 313 if (int_fc->is_signed) {
16699f85 314 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3
PP
315 "`uuid` member's element field class "
316 "is a signed integer field class.");
7b33a0e0
PP
317 goto invalid;
318 }
319
939190b3 320 if (int_fc->base.size != 8) {
16699f85 321 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3
PP
322 "`uuid` member's element field class "
323 "is not an 8-bit integer field class.");
7b33a0e0
PP
324 goto invalid;
325 }
326
939190b3 327 if (int_fc->base.base.alignment != 8) {
16699f85 328 BT_COMP_LOGE_STR("Invalid packet header field class: "
939190b3 329 "`uuid` member's element field class's "
7b33a0e0
PP
330 "alignment is not 8.");
331 goto invalid;
332 }
333 }
334 }
335
336 for (i = 0; i < ctf_tc->stream_classes->len; i++) {
337 struct ctf_stream_class *sc =
338 ctf_tc->stream_classes->pdata[i];
339
16699f85 340 ret = validate_stream_class(sc, log_cfg);
7b33a0e0 341 if (ret) {
16699f85 342 BT_COMP_LOGE("Invalid stream class: sc-id=%" PRIu64, sc->id);
7b33a0e0
PP
343 goto invalid;
344 }
345 }
346
347 goto end;
348
349invalid:
350 ret = -1;
351
352end:
353 return ret;
354}
This page took 0.072153 seconds and 4 git commands to generate.