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_TAG "PLUGIN-CTF-METADATA-META-VALIDATE"
18 #include <babeltrace2/babeltrace.h>
19 #include "common/babeltrace.h"
20 #include "common/assert.h"
26 #include "ctf-meta-visitors.h"
29 int validate_stream_class(struct ctf_stream_class
*sc
)
32 struct ctf_field_class_int
*int_fc
;
33 struct ctf_field_class
*fc
;
35 if (sc
->is_translated
) {
39 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
40 (void *) sc
->packet_context_fc
, "timestamp_begin");
42 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
43 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
44 BT_LOGE_STR("Invalid packet context field class: "
45 "`timestamp_begin` member is not an integer field class.");
51 if (int_fc
->is_signed
) {
52 BT_LOGE_STR("Invalid packet context field class: "
53 "`timestamp_begin` member is signed.");
58 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
59 (void *) sc
->packet_context_fc
, "timestamp_end");
61 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
62 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
63 BT_LOGE_STR("Invalid packet context field class: "
64 "`timestamp_end` member is not an integer field class.");
70 if (int_fc
->is_signed
) {
71 BT_LOGE_STR("Invalid packet context field class: "
72 "`timestamp_end` member is signed.");
77 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
78 (void *) sc
->packet_context_fc
, "events_discarded");
80 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
81 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
82 BT_LOGE_STR("Invalid packet context field class: "
83 "`events_discarded` member is not an integer field class.");
89 if (int_fc
->is_signed
) {
90 BT_LOGE_STR("Invalid packet context field class: "
91 "`events_discarded` member is signed.");
96 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
97 (void *) sc
->packet_context_fc
, "packet_seq_num");
99 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
100 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
101 BT_LOGE_STR("Invalid packet context field class: "
102 "`packet_seq_num` member is not an integer field class.");
106 int_fc
= (void *) fc
;
108 if (int_fc
->is_signed
) {
109 BT_LOGE_STR("Invalid packet context field class: "
110 "`packet_seq_num` member is signed.");
115 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
116 (void *) sc
->packet_context_fc
, "packet_size");
118 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
119 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
120 BT_LOGE_STR("Invalid packet context field class: "
121 "`packet_size` member is not an integer field class.");
125 int_fc
= (void *) fc
;
127 if (int_fc
->is_signed
) {
128 BT_LOGE_STR("Invalid packet context field class: "
129 "`packet_size` member is signed.");
134 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
135 (void *) sc
->packet_context_fc
, "content_size");
137 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
138 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
139 BT_LOGE_STR("Invalid packet context field class: "
140 "`content_size` member is not an integer field class.");
144 int_fc
= (void *) fc
;
146 if (int_fc
->is_signed
) {
147 BT_LOGE_STR("Invalid packet context field class: "
148 "`content_size` member is signed.");
153 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
154 (void *) sc
->event_header_fc
, "id");
156 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
157 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
158 BT_LOGE_STR("Invalid event header field class: "
159 "`id` member is not an integer field class.");
163 int_fc
= (void *) fc
;
165 if (int_fc
->is_signed
) {
166 BT_LOGE_STR("Invalid event header field class: "
167 "`id` member is signed.");
171 if (sc
->event_classes
->len
> 1) {
172 BT_LOGE_STR("Invalid event header field class: "
173 "missing `id` member as there's "
174 "more than one event class.");
189 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
)
192 struct ctf_field_class_int
*int_fc
;
195 if (!ctf_tc
->is_translated
) {
196 struct ctf_field_class
*fc
;
198 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
199 (void *) ctf_tc
->packet_header_fc
, "magic");
201 struct ctf_named_field_class
*named_fc
=
202 ctf_field_class_struct_borrow_member_by_index(
203 (void *) ctf_tc
->packet_header_fc
,
206 if (named_fc
->fc
!= fc
) {
207 BT_LOGE_STR("Invalid packet header field class: "
208 "`magic` member is not the first member.");
212 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
213 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
214 BT_LOGE_STR("Invalid packet header field class: "
215 "`magic` member is not an integer field class.");
219 int_fc
= (void *) fc
;
221 if (int_fc
->is_signed
) {
222 BT_LOGE_STR("Invalid packet header field class: "
223 "`magic` member is signed.");
227 if (int_fc
->base
.size
!= 32) {
228 BT_LOGE_STR("Invalid packet header field class: "
229 "`magic` member is not 32-bit.");
234 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
235 (void *) ctf_tc
->packet_header_fc
, "stream_id");
237 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
238 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
239 BT_LOGE_STR("Invalid packet header field class: "
240 "`stream_id` member is not an integer field class.");
244 int_fc
= (void *) fc
;
246 if (int_fc
->is_signed
) {
247 BT_LOGE_STR("Invalid packet header field class: "
248 "`stream_id` member is signed.");
252 if (ctf_tc
->stream_classes
->len
> 1) {
253 BT_LOGE_STR("Invalid packet header field class: "
254 "missing `stream_id` member as there's "
255 "more than one stream class.");
260 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
261 (void *) ctf_tc
->packet_header_fc
,
262 "stream_instance_id");
264 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
265 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
266 BT_LOGE_STR("Invalid packet header field class: "
267 "`stream_instance_id` member is not an integer field class.");
271 int_fc
= (void *) fc
;
273 if (int_fc
->is_signed
) {
274 BT_LOGE_STR("Invalid packet header field class: "
275 "`stream_instance_id` member is signed.");
280 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
281 (void *) ctf_tc
->packet_header_fc
, "uuid");
283 struct ctf_field_class_array
*array_fc
= (void *) fc
;
285 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
286 BT_LOGE_STR("Invalid packet header field class: "
287 "`uuid` member is not an array field class.");
291 array_fc
= (void *) fc
;
293 if (array_fc
->length
!= 16) {
294 BT_LOGE_STR("Invalid packet header field class: "
295 "`uuid` member is not a 16-element array field class.");
299 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
300 BT_LOGE_STR("Invalid packet header field class: "
301 "`uuid` member's element field class is not "
302 "an integer field class.");
306 int_fc
= (void *) array_fc
->base
.elem_fc
;
308 if (int_fc
->is_signed
) {
309 BT_LOGE_STR("Invalid packet header field class: "
310 "`uuid` member's element field class "
311 "is a signed integer field class.");
315 if (int_fc
->base
.size
!= 8) {
316 BT_LOGE_STR("Invalid packet header field class: "
317 "`uuid` member's element field class "
318 "is not an 8-bit integer field class.");
322 if (int_fc
->base
.base
.alignment
!= 8) {
323 BT_LOGE_STR("Invalid packet header field class: "
324 "`uuid` member's element field class's "
325 "alignment is not 8.");
331 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
332 struct ctf_stream_class
*sc
=
333 ctf_tc
->stream_classes
->pdata
[i
];
335 ret
= validate_stream_class(sc
);
337 BT_LOGE("Invalid stream class: sc-id=%" PRIu64
, sc
->id
);