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