2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
9 #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
10 #define BT_COMP_LOG_SELF_COMP_CLASS (log_cfg->self_comp_class)
11 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
12 #define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE"
13 #include "logging.hpp"
15 #include "ctf-meta-visitors.hpp"
17 static int validate_stream_class(struct ctf_stream_class
*sc
, struct meta_log_config
*log_cfg
)
20 struct ctf_field_class_int
*int_fc
;
21 struct ctf_field_class
*fc
;
23 if (sc
->is_translated
) {
27 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
28 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_begin");
30 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
31 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
32 "Invalid packet context field class: "
33 "`timestamp_begin` member is not an integer field class.");
37 int_fc
= ctf_field_class_as_int(fc
);
39 if (int_fc
->is_signed
) {
40 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
41 "`timestamp_begin` member is signed.");
46 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
47 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_end");
49 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
50 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
51 "Invalid packet context field class: "
52 "`timestamp_end` member is not an integer field class.");
56 int_fc
= ctf_field_class_as_int(fc
);
58 if (int_fc
->is_signed
) {
59 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
60 "`timestamp_end` member is signed.");
65 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
66 ctf_field_class_as_struct(sc
->packet_context_fc
), "events_discarded");
68 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
69 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
70 "Invalid packet context field class: "
71 "`events_discarded` member is not an integer field class.");
75 int_fc
= ctf_field_class_as_int(fc
);
77 if (int_fc
->is_signed
) {
78 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
79 "`events_discarded` member is signed.");
84 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
85 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_seq_num");
87 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
88 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
89 "Invalid packet context field class: "
90 "`packet_seq_num` member is not an integer field class.");
94 int_fc
= ctf_field_class_as_int(fc
);
96 if (int_fc
->is_signed
) {
97 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
98 "`packet_seq_num` member is signed.");
103 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
104 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_size");
106 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
107 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
108 "Invalid packet context field class: "
109 "`packet_size` member is not an integer field class.");
113 int_fc
= ctf_field_class_as_int(fc
);
115 if (int_fc
->is_signed
) {
116 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
117 "`packet_size` member is signed.");
122 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
123 ctf_field_class_as_struct(sc
->packet_context_fc
), "content_size");
125 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
126 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
127 "Invalid packet context field class: "
128 "`content_size` member is not an integer field class.");
132 int_fc
= ctf_field_class_as_int(fc
);
134 if (int_fc
->is_signed
) {
135 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
136 "`content_size` member is signed.");
141 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
142 ctf_field_class_as_struct(sc
->event_header_fc
), "id");
144 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
145 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
146 "`id` member is not an integer field class.");
150 int_fc
= ctf_field_class_as_int(fc
);
152 if (int_fc
->is_signed
) {
153 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
154 "`id` member is signed.");
158 if (sc
->event_classes
->len
> 1) {
159 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
160 "missing `id` member as there's "
161 "more than one event class.");
175 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
, struct meta_log_config
*log_cfg
)
178 struct ctf_field_class_int
*int_fc
;
181 if (!ctf_tc
->is_translated
) {
182 struct ctf_field_class
*fc
;
184 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
185 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
187 struct ctf_named_field_class
*named_fc
= ctf_field_class_struct_borrow_member_by_index(
188 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), 0);
190 if (named_fc
->fc
!= fc
) {
191 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
192 "`magic` member is not the first member.");
196 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
197 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
198 "Invalid packet header field class: "
199 "`magic` member is not an integer field class.");
203 int_fc
= ctf_field_class_as_int(fc
);
205 if (int_fc
->is_signed
) {
206 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
207 "`magic` member is signed.");
211 if (int_fc
->base
.size
!= 32) {
212 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
213 "`magic` member is not 32-bit.");
218 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
219 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
221 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
222 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
223 "Invalid packet header field class: "
224 "`stream_id` member is not an integer field class.");
228 int_fc
= ctf_field_class_as_int(fc
);
230 if (int_fc
->is_signed
) {
231 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
232 "`stream_id` member is signed.");
236 if (ctf_tc
->stream_classes
->len
> 1) {
237 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
238 "missing `stream_id` member as there's "
239 "more than one stream class.");
244 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
245 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_instance_id");
247 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
248 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
249 "Invalid packet header field class: "
250 "`stream_instance_id` member is not an integer field class.");
254 int_fc
= ctf_field_class_as_int(fc
);
256 if (int_fc
->is_signed
) {
257 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
258 "`stream_instance_id` member is signed.");
263 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
264 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
266 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
267 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
268 "Invalid packet header field class: "
269 "`uuid` member is not an array field class.");
273 ctf_field_class_array
*array_fc
= ctf_field_class_as_array(fc
);
275 if (array_fc
->length
!= 16) {
276 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
277 "Invalid packet header field class: "
278 "`uuid` member is not a 16-element array field class.");
282 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
283 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
284 "Invalid packet header field class: "
285 "`uuid` member's element field class is not "
286 "an integer field class.");
290 int_fc
= ctf_field_class_as_int(array_fc
->base
.elem_fc
);
292 if (int_fc
->is_signed
) {
293 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
294 "`uuid` member's element field class "
295 "is a signed integer field class.");
299 if (int_fc
->base
.size
!= 8) {
300 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
301 "`uuid` member's element field class "
302 "is not an 8-bit integer field class.");
306 if (int_fc
->base
.base
.alignment
!= 8) {
307 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
308 "`uuid` member's element field class's "
309 "alignment is not 8.");
315 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
316 struct ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
318 ret
= validate_stream_class(sc
, log_cfg
);
320 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid stream class: sc-id=%" PRIu64
,