2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
12 #include <babeltrace2/babeltrace.h>
14 #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
15 #define BT_COMP_LOG_SELF_COMP_CLASS (log_cfg->self_comp_class)
16 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
17 #define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE"
18 #include "logging.hpp"
19 #include "logging/comp-logging.h"
21 #include "common/assert.h"
22 #include "common/macros.h"
24 #include "ctf-meta-visitors.hpp"
26 static int validate_stream_class(struct ctf_stream_class
*sc
, struct meta_log_config
*log_cfg
)
29 struct ctf_field_class_int
*int_fc
;
30 struct ctf_field_class
*fc
;
32 if (sc
->is_translated
) {
36 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
37 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_begin");
39 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
40 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
41 "Invalid packet context field class: "
42 "`timestamp_begin` member is not an integer field class.");
46 int_fc
= ctf_field_class_as_int(fc
);
48 if (int_fc
->is_signed
) {
49 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
50 "`timestamp_begin` member is signed.");
55 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
56 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_end");
58 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
59 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
60 "Invalid packet context field class: "
61 "`timestamp_end` member is not an integer field class.");
65 int_fc
= ctf_field_class_as_int(fc
);
67 if (int_fc
->is_signed
) {
68 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
69 "`timestamp_end` member is signed.");
74 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
75 ctf_field_class_as_struct(sc
->packet_context_fc
), "events_discarded");
77 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
78 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
79 "Invalid packet context field class: "
80 "`events_discarded` member is not an integer field class.");
84 int_fc
= ctf_field_class_as_int(fc
);
86 if (int_fc
->is_signed
) {
87 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
88 "`events_discarded` member is signed.");
93 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
94 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_seq_num");
96 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
97 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
98 "Invalid packet context field class: "
99 "`packet_seq_num` member is not an integer field class.");
103 int_fc
= ctf_field_class_as_int(fc
);
105 if (int_fc
->is_signed
) {
106 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
107 "`packet_seq_num` member is signed.");
112 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
113 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_size");
115 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
116 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
117 "Invalid packet context field class: "
118 "`packet_size` member is not an integer field class.");
122 int_fc
= ctf_field_class_as_int(fc
);
124 if (int_fc
->is_signed
) {
125 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
126 "`packet_size` member is signed.");
131 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
132 ctf_field_class_as_struct(sc
->packet_context_fc
), "content_size");
134 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
135 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
136 "Invalid packet context field class: "
137 "`content_size` member is not an integer field class.");
141 int_fc
= ctf_field_class_as_int(fc
);
143 if (int_fc
->is_signed
) {
144 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
145 "`content_size` member is signed.");
150 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
151 ctf_field_class_as_struct(sc
->event_header_fc
), "id");
153 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
154 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
155 "`id` member is not an integer field class.");
159 int_fc
= ctf_field_class_as_int(fc
);
161 if (int_fc
->is_signed
) {
162 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
163 "`id` member is signed.");
167 if (sc
->event_classes
->len
> 1) {
168 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
169 "missing `id` member as there's "
170 "more than one event class.");
184 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
, struct meta_log_config
*log_cfg
)
187 struct ctf_field_class_int
*int_fc
;
190 if (!ctf_tc
->is_translated
) {
191 struct ctf_field_class
*fc
;
193 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
194 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
196 struct ctf_named_field_class
*named_fc
= ctf_field_class_struct_borrow_member_by_index(
197 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), 0);
199 if (named_fc
->fc
!= fc
) {
200 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
201 "`magic` member is not the first member.");
205 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
206 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
207 "Invalid packet header field class: "
208 "`magic` member is not an integer field class.");
212 int_fc
= ctf_field_class_as_int(fc
);
214 if (int_fc
->is_signed
) {
215 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
216 "`magic` member is signed.");
220 if (int_fc
->base
.size
!= 32) {
221 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
222 "`magic` member is not 32-bit.");
227 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
228 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
230 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
231 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
232 "Invalid packet header field class: "
233 "`stream_id` member is not an integer field class.");
237 int_fc
= ctf_field_class_as_int(fc
);
239 if (int_fc
->is_signed
) {
240 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
241 "`stream_id` member is signed.");
245 if (ctf_tc
->stream_classes
->len
> 1) {
246 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
247 "missing `stream_id` member as there's "
248 "more than one stream class.");
253 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
254 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_instance_id");
256 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
257 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
258 "Invalid packet header field class: "
259 "`stream_instance_id` member is not an integer field class.");
263 int_fc
= ctf_field_class_as_int(fc
);
265 if (int_fc
->is_signed
) {
266 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
267 "`stream_instance_id` member is signed.");
272 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
273 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
275 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
276 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
277 "Invalid packet header field class: "
278 "`uuid` member is not an array field class.");
282 ctf_field_class_array
*array_fc
= ctf_field_class_as_array(fc
);
284 if (array_fc
->length
!= 16) {
285 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
286 "Invalid packet header field class: "
287 "`uuid` member is not a 16-element array field class.");
291 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
292 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
293 "Invalid packet header field class: "
294 "`uuid` member's element field class is not "
295 "an integer field class.");
299 int_fc
= ctf_field_class_as_int(array_fc
->base
.elem_fc
);
301 if (int_fc
->is_signed
) {
302 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
303 "`uuid` member's element field class "
304 "is a signed integer field class.");
308 if (int_fc
->base
.size
!= 8) {
309 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
310 "`uuid` member's element field class "
311 "is not an 8-bit integer field class.");
315 if (int_fc
->base
.base
.alignment
!= 8) {
316 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
317 "`uuid` member's element field class's "
318 "alignment is not 8.");
324 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
325 struct ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
327 ret
= validate_stream_class(sc
, log_cfg
);
329 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid stream class: sc-id=%" PRIu64
,