Add dynamic array tracing tests
[deliverable/barectf.git] / barectf / config_parse_v2.py
index 9118562dfdb6c8679fd0b278799d51cd6e2cca82..668f0b9478ee599e662ab01e9d6a7304ce3368f7 100644 (file)
@@ -80,7 +80,7 @@ class _Parser(config_parse_common._Parser):
             'floating-point': self._conv_real_ft_node,
             'str': self._conv_string_ft_node,
             'string': self._conv_string_ft_node,
-            'array': self._conv_static_array_ft_node,
+            'array': self._conv_array_ft_node,
             'struct': self._conv_struct_ft_node,
             'structure': self._conv_struct_ft_node,
         }
@@ -129,6 +129,9 @@ class _Parser(config_parse_common._Parser):
         # remove `encoding` property
         _del_prop_if_exists(v3_ft_node, 'encoding')
 
+        # remove `byte-order` property (always target BO in v3)
+        _del_prop_if_exists(v3_ft_node, 'byte-order')
+
         # remove `property-mappings` property
         _del_prop_if_exists(v3_ft_node, 'property-mappings')
 
@@ -219,12 +222,15 @@ class _Parser(config_parse_common._Parser):
 
     # Converts a v2 array field type node to a v3 (static) array field
     # type node and returns it.
-    def _conv_static_array_ft_node(self, v2_ft_node: _MapNode) -> _MapNode:
-        # class renamed to `static-array`
-        v3_ft_node: _MapNode = collections.OrderedDict({'class': 'static-array'})
+    def _conv_array_ft_node(self, v2_ft_node: _MapNode) -> _MapNode:
+        # class renamed to `static-array` or `dynamic-array`
+        is_dynamic = v2_ft_node['length'] == 'dynamic'
+        array_type = 'dynamic' if is_dynamic else 'static'
+        v3_ft_node: _MapNode = collections.OrderedDict({'class': f'{array_type}-array'})
 
-        # copy `length` property
-        _copy_prop_if_exists(v3_ft_node, v2_ft_node, 'length')
+        # copy `length` property if it's a static array field type
+        if not is_dynamic:
+            _copy_prop_if_exists(v3_ft_node, v2_ft_node, 'length')
 
         # convert element field type
         v3_ft_node['element-field-type'] = self._conv_ft_node(v2_ft_node['element-type'])
@@ -483,8 +489,9 @@ class _Parser(config_parse_common._Parser):
         v3_trace_type_node: _MapNode = collections.OrderedDict()
         v2_trace_node = v2_meta_node['trace']
 
-        # rename `byte-order` property to `$default-byte-order`
-        _copy_prop_if_exists(v3_trace_type_node, v2_trace_node, 'byte-order', '$default-byte-order')
+        # Move `byte-order` property to root node's `target-byte-order`
+        # property.
+        typing.cast(_MapNode, self._root_node)['target-byte-order'] = v2_trace_node['byte-order']
 
         # copy `uuid` property
         _copy_prop_if_exists(v3_trace_type_node, v2_trace_node, 'uuid')
This page took 0.022785 seconds and 4 git commands to generate.