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.");
182 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
, struct meta_log_config
*log_cfg
)
185 struct ctf_field_class_int
*int_fc
;
188 if (!ctf_tc
->is_translated
) {
189 struct ctf_field_class
*fc
;
191 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
192 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "magic");
194 struct ctf_named_field_class
*named_fc
= ctf_field_class_struct_borrow_member_by_index(
195 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), 0);
197 if (named_fc
->fc
!= fc
) {
198 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
199 "`magic` member is not the first member.");
203 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
204 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
205 "Invalid packet header field class: "
206 "`magic` member is not an integer field class.");
210 int_fc
= ctf_field_class_as_int(fc
);
212 if (int_fc
->is_signed
) {
213 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
214 "`magic` member is signed.");
218 if (int_fc
->base
.size
!= 32) {
219 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
220 "`magic` member is not 32-bit.");
225 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
226 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_id");
228 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
229 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
230 "Invalid packet header field class: "
231 "`stream_id` member is not an integer field class.");
235 int_fc
= ctf_field_class_as_int(fc
);
237 if (int_fc
->is_signed
) {
238 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
239 "`stream_id` member is signed.");
243 if (ctf_tc
->stream_classes
->len
> 1) {
244 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
245 "missing `stream_id` member as there's "
246 "more than one stream class.");
251 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
252 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "stream_instance_id");
254 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&& fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
255 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
256 "Invalid packet header field class: "
257 "`stream_instance_id` member is not an integer field class.");
261 int_fc
= ctf_field_class_as_int(fc
);
263 if (int_fc
->is_signed
) {
264 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
265 "`stream_instance_id` member is signed.");
270 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
271 ctf_field_class_as_struct(ctf_tc
->packet_header_fc
), "uuid");
273 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
274 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
275 "Invalid packet header field class: "
276 "`uuid` member is not an array field class.");
280 ctf_field_class_array
*array_fc
= ctf_field_class_as_array(fc
);
282 if (array_fc
->length
!= 16) {
283 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
284 "Invalid packet header field class: "
285 "`uuid` member is not a 16-element array field class.");
289 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
290 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
291 "Invalid packet header field class: "
292 "`uuid` member's element field class is not "
293 "an integer field class.");
297 int_fc
= ctf_field_class_as_int(array_fc
->base
.elem_fc
);
299 if (int_fc
->is_signed
) {
300 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
301 "`uuid` member's element field class "
302 "is a signed integer field class.");
306 if (int_fc
->base
.size
!= 8) {
307 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
308 "`uuid` member's element field class "
309 "is not an 8-bit integer field class.");
313 if (int_fc
->base
.base
.alignment
!= 8) {
314 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid packet header field class: "
315 "`uuid` member's element field class's "
316 "alignment is not 8.");
322 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
323 struct ctf_stream_class
*sc
= (ctf_stream_class
*) ctf_tc
->stream_classes
->pdata
[i
];
325 ret
= validate_stream_class(sc
, log_cfg
);
327 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid stream class: sc-id=%" PRIu64
,