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 <babeltrace/babeltrace.h>
19 #include <babeltrace/babeltrace-internal.h>
20 #include <babeltrace/assert-internal.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
;
34 bool has_total_size
= false;
35 bool has_content_size
= false;
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.");
135 has_total_size
= true;
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_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_LOGE_STR("Invalid packet context field class: "
152 "`content_size` member is signed.");
156 has_content_size
= true;
159 if (has_content_size
&& !has_total_size
) {
160 BT_LOGE_STR("Invalid packet context field class: "
161 "`content_size` member exists without "
162 "`packet_size` member.");
166 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
167 (void *) sc
->event_header_fc
, "id");
169 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
170 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
171 BT_LOGE_STR("Invalid event header field class: "
172 "`id` member is not an integer field class.");
176 int_fc
= (void *) fc
;
178 if (int_fc
->is_signed
) {
179 BT_LOGE_STR("Invalid event header field class: "
180 "`id` member is signed.");
184 if (sc
->event_classes
->len
> 1) {
185 BT_LOGE_STR("Invalid event header field class: "
186 "missing `id` member as there's "
187 "more than one event class.");
202 int ctf_trace_class_validate(struct ctf_trace_class
*ctf_tc
)
205 struct ctf_field_class_int
*int_fc
;
208 if (!ctf_tc
->is_translated
) {
209 struct ctf_field_class
*fc
;
211 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
212 (void *) ctf_tc
->packet_header_fc
, "magic");
214 struct ctf_named_field_class
*named_fc
=
215 ctf_field_class_struct_borrow_member_by_index(
216 (void *) ctf_tc
->packet_header_fc
,
219 if (named_fc
->fc
!= fc
) {
220 BT_LOGE_STR("Invalid packet header field class: "
221 "`magic` member is not the first member.");
225 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
226 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
227 BT_LOGE_STR("Invalid packet header field class: "
228 "`magic` member is not an integer field class.");
232 int_fc
= (void *) fc
;
234 if (int_fc
->is_signed
) {
235 BT_LOGE_STR("Invalid packet header field class: "
236 "`magic` member is signed.");
240 if (int_fc
->base
.size
!= 32) {
241 BT_LOGE_STR("Invalid packet header field class: "
242 "`magic` member is not 32-bit.");
247 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
248 (void *) ctf_tc
->packet_header_fc
, "stream_id");
250 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
251 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
252 BT_LOGE_STR("Invalid packet header field class: "
253 "`stream_id` member is not an integer field class.");
257 int_fc
= (void *) fc
;
259 if (int_fc
->is_signed
) {
260 BT_LOGE_STR("Invalid packet header field class: "
261 "`stream_id` member is signed.");
265 if (ctf_tc
->stream_classes
->len
> 1) {
266 BT_LOGE_STR("Invalid packet header field class: "
267 "missing `stream_id` member as there's "
268 "more than one stream class.");
273 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
274 (void *) ctf_tc
->packet_header_fc
,
275 "stream_instance_id");
277 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
&&
278 fc
->type
!= CTF_FIELD_CLASS_TYPE_ENUM
) {
279 BT_LOGE_STR("Invalid packet header field class: "
280 "`stream_instance_id` member is not an integer field class.");
284 int_fc
= (void *) fc
;
286 if (int_fc
->is_signed
) {
287 BT_LOGE_STR("Invalid packet header field class: "
288 "`stream_instance_id` member is signed.");
293 fc
= ctf_field_class_struct_borrow_member_field_class_by_name(
294 (void *) ctf_tc
->packet_header_fc
, "uuid");
296 struct ctf_field_class_array
*array_fc
= (void *) fc
;
298 if (fc
->type
!= CTF_FIELD_CLASS_TYPE_ARRAY
) {
299 BT_LOGE_STR("Invalid packet header field class: "
300 "`uuid` member is not an array field class.");
304 array_fc
= (void *) fc
;
306 if (array_fc
->length
!= 16) {
307 BT_LOGE_STR("Invalid packet header field class: "
308 "`uuid` member is not a 16-element array field class.");
312 if (array_fc
->base
.elem_fc
->type
!= CTF_FIELD_CLASS_TYPE_INT
) {
313 BT_LOGE_STR("Invalid packet header field class: "
314 "`uuid` member's element field class is not "
315 "an integer field class.");
319 int_fc
= (void *) array_fc
->base
.elem_fc
;
321 if (int_fc
->is_signed
) {
322 BT_LOGE_STR("Invalid packet header field class: "
323 "`uuid` member's element field class "
324 "is a signed integer field class.");
328 if (int_fc
->base
.size
!= 8) {
329 BT_LOGE_STR("Invalid packet header field class: "
330 "`uuid` member's element field class "
331 "is not an 8-bit integer field class.");
335 if (int_fc
->base
.base
.alignment
!= 8) {
336 BT_LOGE_STR("Invalid packet header field class: "
337 "`uuid` member's element field class's "
338 "alignment is not 8.");
344 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
345 struct ctf_stream_class
*sc
=
346 ctf_tc
->stream_classes
->pdata
[i
];
348 ret
= validate_stream_class(sc
);
350 BT_LOGE("Invalid stream class: sc-id=%" PRIu64
, sc
->id
);