2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
15 #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
16 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
17 #define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE"
18 #include "plugins/comp-logging.h"
20 #include <babeltrace2/babeltrace.h>
21 #include "common/macros.h"
22 #include "common/assert.h"
28 #include "ctf-meta-visitors.h"
32 int validate_stream_class(struct ctf_stream_class
*sc
,
33 struct meta_log_config
*log_cfg
)
36 struct ctf_field_class_int
*int_fc
;
37 struct ctf_field_class
*fc
;
39 if (sc
->is_translated
) {
43 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
44 (void *) sc
->packet_context_fc
, "timestamp_begin");
46 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
47 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
48 BT_COMP_LOGE_STR("Invalid packet context field class: "
49 "`timestamp_begin` member is not an integer field class.");
55 if (int_fc
->is_signed
) {
56 BT_COMP_LOGE_STR("Invalid packet context field class: "
57 "`timestamp_begin` member is signed.");
62 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
63 (void *) sc
->packet_context_fc
, "timestamp_end");
65 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
66 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
67 BT_COMP_LOGE_STR("Invalid packet context field class: "
68 "`timestamp_end` member is not an integer field class.");
74 if (int_fc
->is_signed
) {
75 BT_COMP_LOGE_STR("Invalid packet context field class: "
76 "`timestamp_end` member is signed.");
81 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
82 (void *) sc
->packet_context_fc
, "events_discarded");
84 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
85 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
86 BT_COMP_LOGE_STR("Invalid packet context field class: "
87 "`events_discarded` member is not an integer field class.");
93 if (int_fc
->is_signed
) {
94 BT_COMP_LOGE_STR("Invalid packet context field class: "
95 "`events_discarded` member is signed.");
100 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
101 (void *) sc
->packet_context_fc
, "packet_seq_num");
103 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
104 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
105 BT_COMP_LOGE_STR("Invalid packet context field class: "
106 "`packet_seq_num` member is not an integer field class.");
110 int_fc
= (void *) fc
;
112 if (int_fc
->is_signed
) {
113 BT_COMP_LOGE_STR("Invalid packet context field class: "
114 "`packet_seq_num` member is signed.");
119 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
120 (void *) sc
->packet_context_fc
, "packet_size");
122 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
123 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
124 BT_COMP_LOGE_STR("Invalid packet context field class: "
125 "`packet_size` member is not an integer field class.");
129 int_fc
= (void *) fc
;
131 if (int_fc
->is_signed
) {
132 BT_COMP_LOGE_STR("Invalid packet context field class: "
133 "`packet_size` member is signed.");
138 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
139 (void *) sc
->packet_context_fc
, "content_size");
141 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
142 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
143 BT_COMP_LOGE_STR("Invalid packet context field class: "
144 "`content_size` member is not an integer field class.");
148 int_fc
= (void *) fc
;
150 if (int_fc
->is_signed
) {
151 BT_COMP_LOGE_STR("Invalid packet context field class: "
152 "`content_size` member is signed.");
157 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
158 (void *) sc
->event_header_fc
, "id");
160 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
161 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
162 BT_COMP_LOGE_STR("Invalid event header field class: "
163 "`id` member is not an integer field class.");
167 int_fc
= (void *) fc
;
169 if (int_fc
->is_signed
) {
170 BT_COMP_LOGE_STR("Invalid event header field class: "
171 "`id` member is signed.");
175 if (sc
->event_classes
->len
> 1) {
176 BT_COMP_LOGE_STR("Invalid event header field class: "
177 "missing `id` member as there's "
178 "more than one event class.");
193 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
,
194 struct meta_log_config
*log_cfg
)
197 struct ctf_field_class_int
*int_fc
;
200 if (!ctf_tc
->is_translated
) {
201 struct ctf_field_class
*fc
;
203 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
204 (void *) ctf_tc
->packet_header_fc
, "magic");
206 struct ctf_named_field_class
*named_fc
=
207 ctf_field_class_struct_borrow_member_by_index(
208 (void *) ctf_tc
->packet_header_fc
,
211 if (named_fc
->fc
!= fc
) {
212 BT_COMP_LOGE_STR("Invalid packet header field class: "
213 "`magic` member is not the first member.");
217 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
218 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
219 BT_COMP_LOGE_STR("Invalid packet header field class: "
220 "`magic` member is not an integer field class.");
224 int_fc
= (void *) fc
;
226 if (int_fc
->is_signed
) {
227 BT_COMP_LOGE_STR("Invalid packet header field class: "
228 "`magic` member is signed.");
232 if (int_fc
->base
.size
!= 32) {
233 BT_COMP_LOGE_STR("Invalid packet header field class: "
234 "`magic` member is not 32-bit.");
239 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
240 (void *) ctf_tc
->packet_header_fc
, "stream_id");
242 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
243 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
244 BT_COMP_LOGE_STR("Invalid packet header field class: "
245 "`stream_id` member is not an integer field class.");
249 int_fc
= (void *) fc
;
251 if (int_fc
->is_signed
) {
252 BT_COMP_LOGE_STR("Invalid packet header field class: "
253 "`stream_id` member is signed.");
257 if (ctf_tc
->stream_classes
->len
> 1) {
258 BT_COMP_LOGE_STR("Invalid packet header field class: "
259 "missing `stream_id` member as there's "
260 "more than one stream class.");
265 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
266 (void *) ctf_tc
->packet_header_fc
,
267 "stream_instance_id");
269 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
270 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
271 BT_COMP_LOGE_STR("Invalid packet header field class: "
272 "`stream_instance_id` member is not an integer field class.");
276 int_fc
= (void *) fc
;
278 if (int_fc
->is_signed
) {
279 BT_COMP_LOGE_STR("Invalid packet header field class: "
280 "`stream_instance_id` member is signed.");
285 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
286 (void *) ctf_tc
->packet_header_fc
, "uuid");
288 struct ctf_field_class_array
*array_fc
= (void *) fc
;
290 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
291 BT_COMP_LOGE_STR("Invalid packet header field class: "
292 "`uuid` member is not an array field class.");
296 array_fc
= (void *) fc
;
298 if (array_fc
->length
!= 16) {
299 BT_COMP_LOGE_STR("Invalid packet header field class: "
300 "`uuid` member is not a 16-element array field class.");
304 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
305 BT_COMP_LOGE_STR("Invalid packet header field class: "
306 "`uuid` member's element field class is not "
307 "an integer field class.");
311 int_fc
= (void *) array_fc
->base
.elem_fc
;
313 if (int_fc
->is_signed
) {
314 BT_COMP_LOGE_STR("Invalid packet header field class: "
315 "`uuid` member's element field class "
316 "is a signed integer field class.");
320 if (int_fc
->base
.size
!= 8) {
321 BT_COMP_LOGE_STR("Invalid packet header field class: "
322 "`uuid` member's element field class "
323 "is not an 8-bit integer field class.");
327 if (int_fc
->base
.base
.alignment
!= 8) {
328 BT_COMP_LOGE_STR("Invalid packet header field class: "
329 "`uuid` member's element field class's "
330 "alignment is not 8.");
336 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
337 struct ctf_stream_class
*sc
=
338 ctf_tc
->stream_classes
->pdata
[i
];
340 ret
= validate_stream_class(sc
, log_cfg
);
342 BT_COMP_LOGE("Invalid stream class: sc-id=%" PRIu64
, sc
->id
);