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_LOG_OUTPUT_LEVEL (log_cfg->log_level)
9 #define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE"
10 #include "logging/comp-logging.h"
12 #include <babeltrace2/babeltrace.h>
13 #include "common/macros.h"
14 #include "common/assert.h"
20 #include "ctf-meta-visitors.h"
24 int validate_stream_class(struct ctf_stream_class
*sc
,
25 struct meta_log_config
*log_cfg
)
28 struct ctf_field_class_int
*int_fc
;
29 struct ctf_field_class
*fc
;
31 if (sc
->is_translated
) {
35 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
36 (void *) sc
->packet_context_fc
, "timestamp_begin");
38 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
39 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
40 BT_COMP_LOGE_STR("Invalid packet context field class: "
41 "`timestamp_begin` member is not an integer field class.");
47 if (int_fc
->is_signed
) {
48 BT_COMP_LOGE_STR("Invalid packet context field class: "
49 "`timestamp_begin` member is signed.");
54 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
55 (void *) sc
->packet_context_fc
, "timestamp_end");
57 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
58 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
59 BT_COMP_LOGE_STR("Invalid packet context field class: "
60 "`timestamp_end` member is not an integer field class.");
66 if (int_fc
->is_signed
) {
67 BT_COMP_LOGE_STR("Invalid packet context field class: "
68 "`timestamp_end` member is signed.");
73 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
74 (void *) sc
->packet_context_fc
, "events_discarded");
76 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
77 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
78 BT_COMP_LOGE_STR("Invalid packet context field class: "
79 "`events_discarded` member is not an integer field class.");
85 if (int_fc
->is_signed
) {
86 BT_COMP_LOGE_STR("Invalid packet context field class: "
87 "`events_discarded` member is signed.");
92 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
93 (void *) sc
->packet_context_fc
, "packet_seq_num");
95 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
96 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
97 BT_COMP_LOGE_STR("Invalid packet context field class: "
98 "`packet_seq_num` member is not an integer field class.");
102 int_fc
= (void *) fc
;
104 if (int_fc
->is_signed
) {
105 BT_COMP_LOGE_STR("Invalid packet context field class: "
106 "`packet_seq_num` member is signed.");
111 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
112 (void *) sc
->packet_context_fc
, "packet_size");
114 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
115 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
116 BT_COMP_LOGE_STR("Invalid packet context field class: "
117 "`packet_size` member is not an integer field class.");
121 int_fc
= (void *) fc
;
123 if (int_fc
->is_signed
) {
124 BT_COMP_LOGE_STR("Invalid packet context field class: "
125 "`packet_size` member is signed.");
130 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
131 (void *) sc
->packet_context_fc
, "content_size");
133 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
134 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
135 BT_COMP_LOGE_STR("Invalid packet context field class: "
136 "`content_size` member is not an integer field class.");
140 int_fc
= (void *) fc
;
142 if (int_fc
->is_signed
) {
143 BT_COMP_LOGE_STR("Invalid packet context field class: "
144 "`content_size` member is signed.");
149 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
150 (void *) sc
->event_header_fc
, "id");
152 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
153 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
154 BT_COMP_LOGE_STR("Invalid event header field class: "
155 "`id` member is not an integer field class.");
159 int_fc
= (void *) fc
;
161 if (int_fc
->is_signed
) {
162 BT_COMP_LOGE_STR("Invalid event header field class: "
163 "`id` member is signed.");
167 if (sc
->event_classes
->len
> 1) {
168 BT_COMP_LOGE_STR("Invalid event header field class: "
169 "missing `id` member as there's "
170 "more than one event class.");
185 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
,
186 struct meta_log_config
*log_cfg
)
189 struct ctf_field_class_int
*int_fc
;
192 if (!ctf_tc
->is_translated
) {
193 struct ctf_field_class
*fc
;
195 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
196 (void *) ctf_tc
->packet_header_fc
, "magic");
198 struct ctf_named_field_class
*named_fc
=
199 ctf_field_class_struct_borrow_member_by_index(
200 (void *) ctf_tc
->packet_header_fc
,
203 if (named_fc
->fc
!= fc
) {
204 BT_COMP_LOGE_STR("Invalid packet header field class: "
205 "`magic` member is not the first member.");
209 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
210 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
211 BT_COMP_LOGE_STR("Invalid packet header field class: "
212 "`magic` member is not an integer field class.");
216 int_fc
= (void *) fc
;
218 if (int_fc
->is_signed
) {
219 BT_COMP_LOGE_STR("Invalid packet header field class: "
220 "`magic` member is signed.");
224 if (int_fc
->base
.size
!= 32) {
225 BT_COMP_LOGE_STR("Invalid packet header field class: "
226 "`magic` member is not 32-bit.");
231 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
232 (void *) ctf_tc
->packet_header_fc
, "stream_id");
234 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
235 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
236 BT_COMP_LOGE_STR("Invalid packet header field class: "
237 "`stream_id` member is not an integer field class.");
241 int_fc
= (void *) fc
;
243 if (int_fc
->is_signed
) {
244 BT_COMP_LOGE_STR("Invalid packet header field class: "
245 "`stream_id` member is signed.");
249 if (ctf_tc
->stream_classes
->len
> 1) {
250 BT_COMP_LOGE_STR("Invalid packet header field class: "
251 "missing `stream_id` member as there's "
252 "more than one stream class.");
257 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
258 (void *) ctf_tc
->packet_header_fc
,
259 "stream_instance_id");
261 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
262 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
263 BT_COMP_LOGE_STR("Invalid packet header field class: "
264 "`stream_instance_id` member is not an integer field class.");
268 int_fc
= (void *) fc
;
270 if (int_fc
->is_signed
) {
271 BT_COMP_LOGE_STR("Invalid packet header field class: "
272 "`stream_instance_id` member is signed.");
277 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
278 (void *) ctf_tc
->packet_header_fc
, "uuid");
280 struct ctf_field_class_array
*array_fc
= (void *) fc
;
282 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
283 BT_COMP_LOGE_STR("Invalid packet header field class: "
284 "`uuid` member is not an array field class.");
288 array_fc
= (void *) fc
;
290 if (array_fc
->length
!= 16) {
291 BT_COMP_LOGE_STR("Invalid packet header field class: "
292 "`uuid` member is not a 16-element array field class.");
296 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
297 BT_COMP_LOGE_STR("Invalid packet header field class: "
298 "`uuid` member's element field class is not "
299 "an integer field class.");
303 int_fc
= (void *) array_fc
->base
.elem_fc
;
305 if (int_fc
->is_signed
) {
306 BT_COMP_LOGE_STR("Invalid packet header field class: "
307 "`uuid` member's element field class "
308 "is a signed integer field class.");
312 if (int_fc
->base
.size
!= 8) {
313 BT_COMP_LOGE_STR("Invalid packet header field class: "
314 "`uuid` member's element field class "
315 "is not an 8-bit integer field class.");
319 if (int_fc
->base
.base
.alignment
!= 8) {
320 BT_COMP_LOGE_STR("Invalid packet header field class: "
321 "`uuid` member's element field class's "
322 "alignment is not 8.");
328 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
329 struct ctf_stream_class
*sc
=
330 ctf_tc
->stream_classes
->pdata
[i
];
332 ret
= validate_stream_class(sc
, log_cfg
);
334 BT_COMP_LOGE("Invalid stream class: sc-id=%" PRIu64
, sc
->id
);