From d024537859c1d869bfa1cedc8abe8e3f7a648faa Mon Sep 17 00:00:00 2001 From: Erica Bugden Date: Tue, 25 Apr 2023 12:01:36 -0400 Subject: [PATCH] Fix: Make traces with no data stream type ID readable by babeltrace MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently, when the barectf configuration property ‘data-stream-type-id-field-type’ is false, barectf produces traces that babeltrace (and Trace Compass) cannot parse. To resolve this, remove all mentions of the data stream type ID from the metadata file when there is no stream type ID field type feature. Apparent cause: When data stream type IDs are disabled, the barectf metadata file will specify that the one data stream type has an ID of 0. This superfluous information appears to be confusing to babeltrace even when the packet header is explicitly empty (i.e. there is no mention of the stream type ID in the actual trace data). This case falls into a grey area in the CTF 1.8 specifcation (see below) and could arguably be a bug in babeltrace since all the information needed to parse the trace unambiguously is present in the metadata file. For example, the CTF reader yactfr successfully reads such a trace. The stream type ID information that barectf includes is superfluous, but not contradictory of any data present in the trace. However, add this fix because: a. Two common CTF trace format readers (babeltrace and Trace Compass) are unable to read these traces, and b. It is an easy fix in barectf. CTF 1.8 specification: This metadata issue is in a grey area of the CTF specification. The specification says, “[The data stream type ID] field is optional if there is only one [data stream type] in the metadata” and, “The [data stream type ID] can be left out if there is only one [data stream type] in the trace.” However, it does not say the data stream type ID _must_ be left out of the metadata if there is only one data stream type. Implementation: The condition added to the metadata Jinja template simply checks that ‘data-stream-type-id-field-type’ is not None. This works when ‘data-stream-type-id-field-type’ is set to false in the configuration, because the data stream type ID field type will be set to None when the trace type is created in config_parse_v3.py: dst_id_ft = self._feature_ft(...) Testing: The test does not check that babeltrace can read the trace, but it does test that the lines mentioning the stream id are not present in the generated metadata. Removing these lines has been manually verified to be sufficient to allow babeltrace to read the trace. The test source is adapted from the barectf test two-packets.c Change-Id: I9de677440b98c41afe592d21a2ec18aa3c2e5bec Signed-off-by: Erica Bugden --- barectf/templates/metadata/metadata.j2 | 4 + tests/tracing/configs/basic/ds/no-dst-id.yaml | 66 +++++++++++++++ .../expect/basic/ds/no-dst-id.data.expect | Bin 0 -> 256 bytes .../expect/basic/ds/no-dst-id.metadata.expect | 76 ++++++++++++++++++ tests/tracing/src/basic/ds/no-dst-id.c | 43 ++++++++++ 5 files changed, 189 insertions(+) create mode 100644 tests/tracing/configs/basic/ds/no-dst-id.yaml create mode 100644 tests/tracing/expect/basic/ds/no-dst-id.data.expect create mode 100644 tests/tracing/expect/basic/ds/no-dst-id.metadata.expect create mode 100644 tests/tracing/src/basic/ds/no-dst-id.c diff --git a/barectf/templates/metadata/metadata.j2 b/barectf/templates/metadata/metadata.j2 index ec1e43a..b1f2c18 100644 --- a/barectf/templates/metadata/metadata.j2 +++ b/barectf/templates/metadata/metadata.j2 @@ -76,7 +76,9 @@ clock { {% for dst in cfg.trace.type.data_stream_types | sort %} /* Data stream type `{{ dst.name }}` */ stream { + {% if cfg.trace.type.features.data_stream_type_id_field_type %} id = {{ dst.id }}; + {% endif %} {{ root_ft('packet.context', dst._pkt_ctx_ft) | indent_tab }} {% if dst._er_header_ft %} {{ root_ft('event.header', dst._er_header_ft) | indent_tab }} @@ -89,7 +91,9 @@ stream { {# data stream type's event record types #} {% for ert in dst.event_record_types | sort %} event { + {% if cfg.trace.type.features.data_stream_type_id_field_type %} stream_id = {{ dst.id }}; + {% endif %} id = {{ ert.id }}; name = "{{ ert.name }}"; {% if ert.log_level %} diff --git a/tests/tracing/configs/basic/ds/no-dst-id.yaml b/tests/tracing/configs/basic/ds/no-dst-id.yaml new file mode 100644 index 0000000..08fad38 --- /dev/null +++ b/tests/tracing/configs/basic/ds/no-dst-id.yaml @@ -0,0 +1,66 @@ +# The MIT License (MIT) +# +# Copyright (c) 2020 Philippe Proulx +# Copyright (c) 2023 Erica Bugden +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# Test Purpose +# +# This test configuration aims to verify that when the config property +# 'data-stream-type-id-field-type' is set to false, that the metadata +# file generated by barectf will not mention the type id (in either the +# stream type description or in the event type descriptions). +# +# This makes sure that two common CTF trace readers (Babeltrace and +# Trace Compass) will be able to read the traces produced. + +%YAML 1.2 +--- ! +trace: + type: + $include: + - base.yaml + - stdmisc.yaml + $features: + magic-field-type: false + uuid-field-type: false + data-stream-type-id-field-type: false + data-stream-types: + default: + $features: + packet: + total-size-field-type: + class: unsigned-integer + size: 16 + content-size-field-type: + class: unsigned-integer + size: 16 + beginning-timestamp-field-type: false + end-timestamp-field-type: false + event-record: + type-id-field-type: false + timestamp-field-type: false + event-record-types: + my_event: + payload-field-type: + class: structure + members: + - my_field: string diff --git a/tests/tracing/expect/basic/ds/no-dst-id.data.expect b/tests/tracing/expect/basic/ds/no-dst-id.data.expect new file mode 100644 index 0000000000000000000000000000000000000000..adad9a6be5a5df472512776c9e1cd8eb257be8e7 GIT binary patch literal 256 zcma*h!3o1K3WH1F`r8x%w(hAXHJYj4e*JweIX!YPJF*Q7da#Xu^=We+5hvarq i#8f^pdzlH@K5ELmxBH5s&QQb1E(g{3!Jno64f+9C<2L31 literal 0 HcmV?d00001 diff --git a/tests/tracing/expect/basic/ds/no-dst-id.metadata.expect b/tests/tracing/expect/basic/ds/no-dst-id.metadata.expect new file mode 100644 index 0000000..f252294 --- /dev/null +++ b/tests/tracing/expect/basic/ds/no-dst-id.metadata.expect @@ -0,0 +1,76 @@ +/* CTF 1.8 */ + +/* + * The MIT License (MIT) + * + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * + * + * For more details, see . + */ + +trace { + major = 1; + minor = 8; + byte_order = le; + packet.header := struct { + } align(8); +}; + +env { + domain = "bare"; + tracer_name = "barectf"; +}; + +/* Data stream type `default` */ +stream { + packet.context := struct { + integer { + signed = false; + size = 16; + align = 8; + byte_order = native; + base = 10; + } packet_size; + integer { + signed = false; + size = 16; + align = 8; + byte_order = native; + base = 10; + } content_size; + } align(8); + event.header := struct { + } align(8); +}; + +event { + id = 0; + name = "my_event"; + fields := struct { + string { + encoding = UTF8; + } my_field; + } align(1); +}; diff --git a/tests/tracing/src/basic/ds/no-dst-id.c b/tests/tracing/src/basic/ds/no-dst-id.c new file mode 100644 index 0000000..8bb300a --- /dev/null +++ b/tests/tracing/src/basic/ds/no-dst-id.c @@ -0,0 +1,43 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Philippe Proulx + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include "test-platform.h" +#include "barectf.h" + +int main(void) +{ + struct test_platform_ctx * const platform_ctx = test_platform_init(128); + + assert(platform_ctx); + barectf_default_trace_my_event(test_platform_barectf_ctx(platform_ctx), + "When she was younger, Akko went to a magic show hosted by a witch named Shiny Chariot."); + barectf_default_trace_my_event(test_platform_barectf_ctx(platform_ctx), + "Akko was so inspired that she dreamed to someday be a cool witch."); + test_platform_fini(platform_ctx); + return 0; +} -- 2.34.1