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_LOG_OUTPUT_LEVEL log_level
16 #define BT_LOG_TAG "PLUGIN/CTF/META/VALIDATE"
17 #include "logging/log.h"
19 #include <babeltrace2/babeltrace.h>
20 #include "common/macros.h"
21 #include "common/assert.h"
27 #include "ctf-meta-visitors.h"
30 int validate_stream_class(struct ctf_stream_class
*sc
,
31 bt_logging_level log_level
)
34 struct ctf_field_class_int
*int_fc
;
35 struct ctf_field_class
*fc
;
37 if (sc
->is_translated
) {
41 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
42 (void *) sc
->packet_context_fc
, "timestamp_begin");
44 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
45 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
46 BT_LOGE_STR("Invalid packet context field class: "
47 "`timestamp_begin` member is not an integer field class.");
53 if (int_fc
->is_signed
) {
54 BT_LOGE_STR("Invalid packet context field class: "
55 "`timestamp_begin` member is signed.");
60 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
61 (void *) sc
->packet_context_fc
, "timestamp_end");
63 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
64 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
65 BT_LOGE_STR("Invalid packet context field class: "
66 "`timestamp_end` member is not an integer field class.");
72 if (int_fc
->is_signed
) {
73 BT_LOGE_STR("Invalid packet context field class: "
74 "`timestamp_end` member is signed.");
79 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
80 (void *) sc
->packet_context_fc
, "events_discarded");
82 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
83 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
84 BT_LOGE_STR("Invalid packet context field class: "
85 "`events_discarded` member is not an integer field class.");
91 if (int_fc
->is_signed
) {
92 BT_LOGE_STR("Invalid packet context field class: "
93 "`events_discarded` member is signed.");
98 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
99 (void *) sc
->packet_context_fc
, "packet_seq_num");
101 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
102 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
103 BT_LOGE_STR("Invalid packet context field class: "
104 "`packet_seq_num` member is not an integer field class.");
108 int_fc
= (void *) fc
;
110 if (int_fc
->is_signed
) {
111 BT_LOGE_STR("Invalid packet context field class: "
112 "`packet_seq_num` member is signed.");
117 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
118 (void *) sc
->packet_context_fc
, "packet_size");
120 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
121 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
122 BT_LOGE_STR("Invalid packet context field class: "
123 "`packet_size` member is not an integer field class.");
127 int_fc
= (void *) fc
;
129 if (int_fc
->is_signed
) {
130 BT_LOGE_STR("Invalid packet context field class: "
131 "`packet_size` member is signed.");
136 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
137 (void *) sc
->packet_context_fc
, "content_size");
139 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
140 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
141 BT_LOGE_STR("Invalid packet context field class: "
142 "`content_size` member is not an integer field class.");
146 int_fc
= (void *) fc
;
148 if (int_fc
->is_signed
) {
149 BT_LOGE_STR("Invalid packet context field class: "
150 "`content_size` member is signed.");
155 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
156 (void *) sc
->event_header_fc
, "id");
158 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
159 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
160 BT_LOGE_STR("Invalid event header field class: "
161 "`id` member is not an integer field class.");
165 int_fc
= (void *) fc
;
167 if (int_fc
->is_signed
) {
168 BT_LOGE_STR("Invalid event header field class: "
169 "`id` member is signed.");
173 if (sc
->event_classes
->len
> 1) {
174 BT_LOGE_STR("Invalid event header field class: "
175 "missing `id` member as there's "
176 "more than one event class.");
191 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
,
192 bt_logging_level log_level
)
195 struct ctf_field_class_int
*int_fc
;
198 if (!ctf_tc
->is_translated
) {
199 struct ctf_field_class
*fc
;
201 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
202 (void *) ctf_tc
->packet_header_fc
, "magic");
204 struct ctf_named_field_class
*named_fc
=
205 ctf_field_class_struct_borrow_member_by_index(
206 (void *) ctf_tc
->packet_header_fc
,
209 if (named_fc
->fc
!= fc
) {
210 BT_LOGE_STR("Invalid packet header field class: "
211 "`magic` member is not the first member.");
215 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
216 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
217 BT_LOGE_STR("Invalid packet header field class: "
218 "`magic` member is not an integer field class.");
222 int_fc
= (void *) fc
;
224 if (int_fc
->is_signed
) {
225 BT_LOGE_STR("Invalid packet header field class: "
226 "`magic` member is signed.");
230 if (int_fc
->base
.size
!= 32) {
231 BT_LOGE_STR("Invalid packet header field class: "
232 "`magic` member is not 32-bit.");
237 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
238 (void *) ctf_tc
->packet_header_fc
, "stream_id");
240 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
241 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
242 BT_LOGE_STR("Invalid packet header field class: "
243 "`stream_id` member is not an integer field class.");
247 int_fc
= (void *) fc
;
249 if (int_fc
->is_signed
) {
250 BT_LOGE_STR("Invalid packet header field class: "
251 "`stream_id` member is signed.");
255 if (ctf_tc
->stream_classes
->len
> 1) {
256 BT_LOGE_STR("Invalid packet header field class: "
257 "missing `stream_id` member as there's "
258 "more than one stream class.");
263 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
264 (void *) ctf_tc
->packet_header_fc
,
265 "stream_instance_id");
267 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
268 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
269 BT_LOGE_STR("Invalid packet header field class: "
270 "`stream_instance_id` member is not an integer field class.");
274 int_fc
= (void *) fc
;
276 if (int_fc
->is_signed
) {
277 BT_LOGE_STR("Invalid packet header field class: "
278 "`stream_instance_id` member is signed.");
283 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
284 (void *) ctf_tc
->packet_header_fc
, "uuid");
286 struct ctf_field_class_array
*array_fc
= (void *) fc
;
288 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
289 BT_LOGE_STR("Invalid packet header field class: "
290 "`uuid` member is not an array field class.");
294 array_fc
= (void *) fc
;
296 if (array_fc
->length
!= 16) {
297 BT_LOGE_STR("Invalid packet header field class: "
298 "`uuid` member is not a 16-element array field class.");
302 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
303 BT_LOGE_STR("Invalid packet header field class: "
304 "`uuid` member's element field class is not "
305 "an integer field class.");
309 int_fc
= (void *) array_fc
->base
.elem_fc
;
311 if (int_fc
->is_signed
) {
312 BT_LOGE_STR("Invalid packet header field class: "
313 "`uuid` member's element field class "
314 "is a signed integer field class.");
318 if (int_fc
->base
.size
!= 8) {
319 BT_LOGE_STR("Invalid packet header field class: "
320 "`uuid` member's element field class "
321 "is not an 8-bit integer field class.");
325 if (int_fc
->base
.base
.alignment
!= 8) {
326 BT_LOGE_STR("Invalid packet header field class: "
327 "`uuid` member's element field class's "
328 "alignment is not 8.");
334 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
335 struct ctf_stream_class
*sc
=
336 ctf_tc
->stream_classes
->pdata
[i
];
338 ret
= validate_stream_class(sc
, log_level
);
340 BT_LOGE("Invalid stream class: sc-id=%" PRIu64
, sc
->id
);