2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
8 #define BT_COMP_LOG_SELF_COMP_CLASS (log_cfg->self_comp_class)
9 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
10 #define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE"
11 #include "logging/comp-logging.h"
13 #include <babeltrace2/babeltrace.h>
14 #include "common/macros.h"
15 #include "common/assert.h"
21 #include "ctf-meta-visitors.hpp"
22 #include "logging.hpp"
24 static int validate_stream_class(struct ctf_stream_class
*sc
, struct meta_log_config
*log_cfg
)
27 struct ctf_field_class_int
*int_fc
;
28 struct ctf_field_class
*fc
;
30 if (sc
->is_translated
) {
34 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
35 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_begin");
37 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
38 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
39 "Invalid packet context field class: "
40 "`timestamp_begin` member is not an integer field class.");
44 int_fc
= ctf_field_class_as_int(fc
);
46 if (int_fc
->is_signed
) {
47 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
48 "`timestamp_begin` member is signed.");
53 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
54 ctf_field_class_as_struct(sc
->packet_context_fc
), "timestamp_end");
56 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
57 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
58 "Invalid packet context field class: "
59 "`timestamp_end` member is not an integer field class.");
63 int_fc
= ctf_field_class_as_int(fc
);
65 if (int_fc
->is_signed
) {
66 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
67 "`timestamp_end` member is signed.");
72 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
73 ctf_field_class_as_struct(sc
->packet_context_fc
), "events_discarded");
75 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
76 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
77 "Invalid packet context field class: "
78 "`events_discarded` member is not an integer field class.");
82 int_fc
= ctf_field_class_as_int(fc
);
84 if (int_fc
->is_signed
) {
85 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
86 "`events_discarded` member is signed.");
91 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
92 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_seq_num");
94 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
95 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
96 "Invalid packet context field class: "
97 "`packet_seq_num` member is not an integer field class.");
101 int_fc
= ctf_field_class_as_int(fc
);
103 if (int_fc
->is_signed
) {
104 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
105 "`packet_seq_num` member is signed.");
110 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
111 ctf_field_class_as_struct(sc
->packet_context_fc
), "packet_size");
113 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
114 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
115 "Invalid packet context field class: "
116 "`packet_size` member is not an integer field class.");
120 int_fc
= ctf_field_class_as_int(fc
);
122 if (int_fc
->is_signed
) {
123 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
124 "`packet_size` member is signed.");
129 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
130 ctf_field_class_as_struct(sc
->packet_context_fc
), "content_size");
132 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
133 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
134 "Invalid packet context field class: "
135 "`content_size` member is not an integer field class.");
139 int_fc
= ctf_field_class_as_int(fc
);
141 if (int_fc
->is_signed
) {
142 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet context field class: "
143 "`content_size` member is signed.");
148 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
149 ctf_field_class_as_struct(sc
->event_header_fc
), "id");
151 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
152 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
153 "`id` member is not an integer field class.");
157 int_fc
= ctf_field_class_as_int(fc
);
159 if (int_fc
->is_signed
) {
160 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
161 "`id` member is signed.");
165 if (sc
->event_classes
->len
> 1) {
166 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid event header field class: "
167 "missing `id` member as there's "
168 "more than one event class.");
183 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
, struct meta_log_config
*log_cfg
)
186 struct ctf_field_class_int
*int_fc
;
189 if (!ctf_tc
->is_translated
) {
190 struct ctf_field_class
*fc
;
192 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
193 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
195 struct ctf_named_field_class
*named_fc
= ctf_field_class_struct_borrow_member_by_index(
196 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), 0);
198 if (named_fc
->fc
!= fc
) {
199 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
200 "`magic` member is not the first member.");
204 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
205 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
206 "Invalid packet header field class: "
207 "`magic` member is not an integer field class.");
211 int_fc
= ctf_field_class_as_int(fc
);
213 if (int_fc
->is_signed
) {
214 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
215 "`magic` member is signed.");
219 if (int_fc
->base
.size
!= 32) {
220 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
221 "`magic` member is not 32-bit.");
226 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
227 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
229 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
230 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
231 "Invalid packet header field class: "
232 "`stream_id` member is not an integer field class.");
236 int_fc
= ctf_field_class_as_int(fc
);
238 if (int_fc
->is_signed
) {
239 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
240 "`stream_id` member is signed.");
244 if (ctf_tc
->stream_classes
->len
> 1) {
245 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
246 "missing `stream_id` member as there's "
247 "more than one stream class.");
252 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
253 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_instance_id");
255 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
256 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
257 "Invalid packet header field class: "
258 "`stream_instance_id` member is not an integer field class.");
262 int_fc
= ctf_field_class_as_int(fc
);
264 if (int_fc
->is_signed
) {
265 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
266 "`stream_instance_id` member is signed.");
271 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
272 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
274 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
275 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
276 "Invalid packet header field class: "
277 "`uuid` member is not an array field class.");
281 ctf_field_class_array
*array_fc
= ctf_field_class_as_array(fc
);
283 if (array_fc
->length
!= 16) {
284 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
285 "Invalid packet header field class: "
286 "`uuid` member is not a 16-element array field class.");
290 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
291 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
292 "Invalid packet header field class: "
293 "`uuid` member's element field class is not "
294 "an integer field class.");
298 int_fc
= ctf_field_class_as_int(array_fc
->base
.elem_fc
);
300 if (int_fc
->is_signed
) {
301 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
302 "`uuid` member's element field class "
303 "is a signed integer field class.");
307 if (int_fc
->base
.size
!= 8) {
308 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
309 "`uuid` member's element field class "
310 "is not an 8-bit integer field class.");
314 if (int_fc
->base
.base
.alignment
!= 8) {
315 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
316 "`uuid` member's element field class's "
317 "alignment is not 8.");
323 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
324 struct ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
326 ret
= validate_stream_class(sc
, log_cfg
);
328 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid stream class: sc-id=%" PRIu64
,