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