Trace = barectf_config.Trace
TraceEnvironment = barectf_config.TraceEnvironment
TraceType = barectf_config.TraceType
+TraceTypeWithUnknownNativeByteOrder = barectf_config.TraceTypeWithUnknownNativeByteOrder
TraceTypeFeatures = barectf_config.TraceTypeFeatures
UnsignedEnumerationFieldType = barectf_config.UnsignedEnumerationFieldType
UnsignedIntegerFieldType = barectf_config.UnsignedIntegerFieldType
# Trace type of this code generator's barectf configuration.
@property
- def _trace_type(self) -> barectf_config.TraceType:
+ def _trace_type(self) -> barectf_config._TraceType:
return self._cfg.trace.type
# Returns the name of a source variable for the operation `op`.
return self._data_stream_type_id_field_type
-class TraceType:
- def __init__(self, native_byte_order: ByteOrder, data_stream_types: Set[DataStreamType],
- uuid: _OptUuid = None, features: Optional[TraceTypeFeatures] = None):
- self._native_byte_order = native_byte_order
+class _TraceType:
+ def __init__(self, trace_byte_order: ByteOrder, data_stream_types: Set[DataStreamType],
+ uuid: _OptUuid, features: Optional[TraceTypeFeatures]):
+ self._trace_byte_order = trace_byte_order
self._data_stream_types = frozenset(data_stream_types)
# assign unique IDs
self._pkt_header_ft = StructureFieldType(8, members)
@property
- def native_byte_order(self) -> ByteOrder:
- return self._native_byte_order
+ def trace_byte_order(self) -> ByteOrder:
+ return self._trace_byte_order
@property
def uuid(self) -> _OptUuid:
return clk_types
+# Standard trace type class for a barectf 3 configuration.
+#
+# The trace byte order property of an instance is the same as the
+# expected native byte order of the target system.
+class TraceType(_TraceType):
+ def __init__(self, trace_byte_order: ByteOrder, data_stream_types: Set[DataStreamType],
+ uuid: _OptUuid = None, features: Optional[TraceTypeFeatures] = None):
+ super().__init__(trace_byte_order, data_stream_types, uuid, features)
+
+ @property
+ def native_byte_order(self) -> ByteOrder:
+ return self._trace_byte_order
+
+
+# This trace type class specifically exists to support barectf 2
+# configurations. Such configurations define the actual trace byte order
+# instead of the expected native byte order of the target system.
+#
+# The user provides the trace byte order property of an instance.
+#
+# IMPORTANT: When possible, prefer the `TraceType` class instead, as
+# enforcing the trace byte order could result in a less efficient
+# generated tracer.
+class TraceTypeWithUnknownNativeByteOrder(_TraceType):
+ def __init__(self, trace_byte_order: ByteOrder, data_stream_types: Set[DataStreamType],
+ uuid: _OptUuid = None, features: Optional[TraceTypeFeatures] = None):
+ super().__init__(trace_byte_order, data_stream_types, uuid, features)
+
+
_EnvEntry = Union[str, int]
_EnvEntries = Mapping[str, _EnvEntry]
class Trace:
- def __init__(self, type: TraceType, environment: Optional[_EnvEntries] = None):
+ def __init__(self, type: _TraceType, environment: Optional[_EnvEntries] = None):
self._type = type
self._set_env(environment)
self._env = TraceEnvironment(typing.cast(_EnvEntries, init_env))
@property
- def type(self) -> TraceType:
+ def type(self) -> _TraceType:
return self._type
@property
# remove `encoding` property
_del_prop_if_exists(v3_ft_node, 'encoding')
- # remove `byte-order` property (always native BO in v3)
+ # remove `byte-order` property (the equivalent barectf 3
+ # configuration property is named `trace-byte-order`)
_del_prop_if_exists(v3_ft_node, 'byte-order')
# remove `property-mappings` property
v3_trace_type_node: _MapNode = collections.OrderedDict()
v2_trace_node = v2_meta_node['trace']
- # copy `byte-order` property as `native-byte-order` property
- _copy_prop_if_exists(v3_trace_type_node, v2_trace_node, 'byte-order', 'native-byte-order')
+ # copy `byte-order` property as `trace-byte-order` property
+ _copy_prop_if_exists(v3_trace_type_node, v2_trace_node, 'byte-order', 'trace-byte-order')
# copy `uuid` property
_copy_prop_if_exists(v3_trace_type_node, v2_trace_node, 'uuid')
dsts.add(self._create_dst(dst_name, dst_node))
# create trace type
- return barectf_config.TraceType(self._native_byte_order, dsts, trace_type_uuid,
- features)
+ if self._trace_byte_order_prop_key == 'native-byte-order':
+ trace_type_cls = barectf_config.TraceType
+ else:
+ trace_type_cls = barectf_config.TraceTypeWithUnknownNativeByteOrder
+
+ return trace_type_cls(self._trace_byte_order, dsts, trace_type_uuid, features)
except _ConfigurationParseError as exc:
_append_error_ctx(exc, 'Trace type')
def _trace_type_props(self) -> Iterable[Tuple[Any, str]]:
yield from _Parser._props(self.config_node['trace']['type'])
+ def _set_trace_byte_order_prop_key(self):
+ if 'native-byte-order' in self._trace_type_node:
+ self._trace_byte_order_prop_key = 'native-byte-order'
+ else:
+ self._trace_byte_order_prop_key = 'trace-byte-order'
+
# Normalize the properties of the configuration node.
#
# This method, for each property of the trace type node:
#
# 2. Chooses a specific `class` property value.
#
- # 3. Chooses a specific `byte-order`/`native-byte-order` property
- # value.
+ # 3. Chooses a specific trace byte order property value.
#
# 4. Chooses a specific `preferred-display-base` property value.
#
parent_node[key] = 'little-endian'
trace_node = self.config_node['trace']
- normalize_byte_order_prop(self._trace_type_node, 'native-byte-order')
+ normalize_byte_order_prop(self._trace_type_node, self._trace_byte_order_prop_key)
for parent_node, key in self._trace_type_props():
node = parent_node[key]
if node is None:
del trace_node[prop_name]
- # Sets the parser's native byte order.
- def _set_native_byte_order(self):
- self._native_byte_order_node = self._trace_type_node['native-byte-order']
- self._native_byte_order = self._byte_order_from_node(self._native_byte_order_node)
+ # Sets the parser's trace byte order.
+ def _set_trace_byte_order(self):
+ self._trace_byte_order_node = self._trace_type_node[self._trace_byte_order_prop_key]
+ self._trace_byte_order = self._byte_order_from_node(self._trace_byte_order_node)
# Processes the inclusions of the event record type node
# `ert_node`, returning the effective node.
# effective configuration node.
self._schema_validator.validate(self.config_node, 'config/3/config')
+ # Set the trace byte order property key.
+ self._set_trace_byte_order_prop_key()
+
# Normalize properties.
#
# This process removes `None` properties and chooses specific
# doesn't need to check for `None` nodes or enumerator aliases.
self._normalize_props()
- # Set the native byte order.
- self._set_native_byte_order()
+ # Set the trace byte order.
+ self._set_trace_byte_order()
# Create a barectf configuration object from the configuration
# node.
properties:
native-byte-order:
$ref: https://barectf.org/schemas/config/common/common.json#/definitions/byte-order-prop
+ trace-byte-order:
+ $ref: https://barectf.org/schemas/config/common/common.json#/definitions/byte-order-prop
uuid:
$ref: https://barectf.org/schemas/config/common/common.json#/definitions/opt-trace-type-uuid-prop
$features:
additionalProperties: false
minProperties: 1
required:
- - native-byte-order
- data-stream-types
+ oneOf:
+ - required:
+ - trace-byte-order
+ - required:
+ - native-byte-order
additionalProperties: false
clock-type:
title: Clock type object
* Also, consecutive bitfields are placed from higher to lower bits.
*/
-{% if cfg.trace.type.native_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN %}
-/* Native byte order: little-endian */
+{% if cfg.trace.type.trace_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN %}
+/* Trace byte order: little-endian */
#define _bt_bitfield_write_le(_ptr, type, _start, _length, _vtype, _v) \
do { \
#define bt_bitfield_write_le(ptr, _start, _length, _vtype, _v) \
_bt_bitfield_write_le(ptr, uint8_t, _start, _length, _vtype, _v)
{% else %}
-/* Native byte order: big-endian */
+/* Trace byte order: big-endian */
#define _bt_bitfield_write_be(_ptr, type, _start, _length, _vtype, _v) \
do { \
#}
{% import 'common.j2' as common %}
{% set incr_at %}ctx->at += {{ op.ft.size }}{% endset %}
-{% if op.ft.alignment % 8 == 0 and op.ft.size in [8, 16, 32, 64] %}
+{% if op.ft.alignment % 8 == 0 and
+ op.ft.size in [8, 16, 32, 64] and
+ cfg.trace.type.__class__ != barectf_config.TraceTypeWithUnknownNativeByteOrder %}
{% set c_type %}uint{{ op.ft.size }}_t{% endset %}
{
const {{ c_type }} tmp_val = ({{ c_type }}) {{ src }};
{{ incr_at }};
}
{%- else %}
- {% set bo = 'le' if cfg.trace.type.native_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN else 'be' %}
+ {% set bo = 'le' if cfg.trace.type.trace_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN else 'be' %}
{% set c_type_non_const = c_type | replace('const ', '') %}
{% set offset_in_byte = 'ctx->at % 8' if op.offset_in_byte == none else op.offset_in_byte %}
bt_bitfield_write_{{ bo }}(&ctx->buf[_BITS_TO_BYTES(ctx->at)], {{ offset_in_byte }}, {{ op.ft.size }},
trace {
major = 1;
minor = 8;
- byte_order = {{ 'le' if cfg.trace.type.native_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN else 'be' }};
+ byte_order = {{ 'le' if cfg.trace.type.trace_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN else 'be' }};
{% if cfg.trace.type.uuid %}
uuid = "{{ cfg.trace.type.uuid }}";
{% endif %}
|xref:common-values.adoc#byte-order[Byte order]
|Native byte order of the system which produces this trace type's
instance's xref:how-barectf-works:ctf-primer.adoc#ds[data streams].
-|Yes
+
+You must not use this property and the
+<<trace-bo-prop,`trace-byte-order`>> property at the same time.
+|Yes, if the `trace-byte-order` property is missing
+|
+
+|[[trace-bo-prop]]`trace-byte-order`
+|xref:common-values.adoc#byte-order[Byte order]
+|Byte order of fields of this trace type's
+instance's xref:how-barectf-works:ctf-primer.adoc#ds[data streams].
+
+[IMPORTANT]
+====
+This property exists to support barectf{nbsp}2 configurations.
+
+Prefer the <<native-bo-prop,`native-byte-order`>> property instead, as
+enforcing the trace byte order could result in a less efficient
+generated tracer.
+====
+
+You must not use this property and the `native-byte-order` property at
+the same time.
+|Yes, if the `native-byte-order` property is missing
|
|[[uuid-prop]]`uuid`
--- /dev/null
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+# Copyright (c) 2023 Erica Bugden <ebugden@efficios.com>
+#
+# 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.
+
+# Tests that configuration parsing fails when no trace type byte order
+# property exists (neither `native-byte-order` nor `trace-byte-order`).
+%YAML 1.2
+--- !<tag:barectf.org,2020/3/config>
+trace:
+ type:
+ data-stream-types:
+ my_stream:
+ $is-default: true
+ $features:
+ packet:
+ discarded-event-records-counter-snapshot-field-type: false
+ event-record-types:
+ my_event:
+ payload-field-type:
+ class: structure
+ members:
+ - my_field:
+ field-type:
+ class: string
--- /dev/null
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+# Copyright (c) 2023 Erica Bugden <ebugden@efficios.com>
+#
+# 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.
+
+# Tests that configuration parsing fails when both `native-byte-order`
+# and `trace-byte-order` trace type properties exist: barectf accepts
+# one or the other, but not both.
+%YAML 1.2
+--- !<tag:barectf.org,2020/3/config>
+trace:
+ type:
+ native-byte-order: little-endian
+ trace-byte-order: little-endian
+ data-stream-types:
+ my_stream:
+ $is-default: true
+ $features:
+ packet:
+ discarded-event-records-counter-snapshot-field-type: false
+ event-record-types:
+ my_event:
+ payload-field-type:
+ class: structure
+ members:
+ - my_field:
+ field-type:
+ class: string
--- /dev/null
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+# Copyright (c) 2023 Erica Bugden <ebugden@efficios.com>
+#
+# 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.
+
+# Tests that configuration parsing succeeds if only one trace type byte
+# order property exists (`trace-byte-order` in this case).
+%YAML 1.2
+--- !<tag:barectf.org,2020/3/config>
+trace:
+ type:
+ trace-byte-order: big-endian
+ data-stream-types:
+ my_stream:
+ $is-default: true
+ $features:
+ packet:
+ discarded-event-records-counter-snapshot-field-type: false
+ event-record-types:
+ my_event:
+ payload-field-type:
+ class: structure
+ members:
+ - my_field:
+ field-type:
+ class: string
--- /dev/null
+# The MIT License (MIT)
+#
+# Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+# Copyright (c) 2023 Erica Bugden <ebugden@efficios.com>
+#
+# 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.
+
+# Tests that barectf generates a tracer which produces a valid trace on
+# a little-endian system given a barectf 2 configuration having its
+# `byte-order` trace type property set to `big-endian`.
+#
+# NOTE: This test does not validate that it runs on a little-endian
+# system, but we can assume that that is the case since it is what the
+# barectf tests currently require.
+version: '2.2'
+metadata:
+ type-aliases:
+ uint16:
+ class: int
+ size: 16
+ trace:
+ byte-order: big-endian
+ streams:
+ default:
+ $default: true
+ packet-context-type:
+ class: struct
+ fields:
+ packet_size: uint16
+ content_size: uint16
+ events:
+ my_event:
+ payload-type:
+ class: struct
+ fields:
+ my_field:
+ class: str
--- /dev/null
+/* 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 <https://barectf.org/>.
+ */
+
+trace {
+ major = 1;
+ minor = 8;
+ byte_order = be;
+ 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);
+};
--- /dev/null
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+ *
+ * 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 <assert.h>
+
+#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;
+}