plan_tests $NUM_TESTS
-data_dir="${BT_TESTS_DATADIR}/cli/convert/auto-source-discovery-grouping"
+data_dir="${BT_TESTS_DATADIR}/auto-source-discovery/grouping"
plugin_dir="${data_dir}"
trace_dir="${data_dir}/traces"
dir_sep='/'
fi
-stdout_expected_file="${data_dir}/stdout.expect"
+stdout_expected_file="${BT_TESTS_DATADIR}/cli/convert/auto-source-discovery-grouping.expect"
stdout_actual_file=$(mktemp -t stdout-actual.XXXXXX)
stderr_actual_file=$(mktemp -t actual-stderr.XXXXXX)
plan_tests $NUM_TESTS
-data_dir="${BT_TESTS_DATADIR}/cli/convert/auto-source-discovery-params-log-level"
+data_dir="${BT_TESTS_DATADIR}/auto-source-discovery/params-log-level"
plugin_dir="${data_dir}"
dir_a="${data_dir}/dir-a"
dir_b="${data_dir}/dir-b"
plan_tests $NUM_TESTS
-data_dir="${BT_TESTS_DATADIR}/cli/convert/auto-source-discovery-params-log-level"
+data_dir="${BT_TESTS_DATADIR}/auto-source-discovery/params-log-level"
plugin_dir="${data_dir}"
dir_a="${data_dir}/dir-a"
dir_b="${data_dir}/dir-b"
--- /dev/null
+import bt2
+import os
+
+# Source component classes in this file recognize and group inputs in
+# various ways. One stream is created by each component, with a name
+# derived from the component class and the inputs. This is then checked
+# using the `sink.text.details` sink.
+
+
+class TestIter(bt2._UserMessageIterator):
+ def __init__(self, output_port):
+ inputs = output_port.user_data['inputs']
+ sc = output_port.user_data['sc']
+ tc = sc.trace_class
+ t = tc()
+ s = t.create_stream(sc, name=self._make_stream_name(inputs))
+
+ self._msgs = [
+ self._create_stream_beginning_message(s),
+ self._create_stream_end_message(s),
+ ]
+
+ def _make_stream_name(self, inputs):
+ comp_cls_name = self._component.__class__.__name__
+ return (
+ comp_cls_name
+ + ': '
+ + ', '.join(sorted([os.path.basename(str(x)) for x in inputs]))
+ )
+
+ def __next__(self):
+ if len(self._msgs) == 0:
+ raise StopIteration
+
+ return self._msgs.pop(0)
+
+
+class Base:
+ def __init__(self, params):
+ tc = self._create_trace_class()
+ sc = tc.create_stream_class()
+
+ self._add_output_port('out', {'inputs': params['inputs'], 'sc': sc})
+
+
+@bt2.plugin_component_class
+class TestSourceExt(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
+ """
+ Recognize files whose name start with 'aaa', 'bbb' or 'ccc'.
+
+ 'aaa' files are grouped together, 'bbb' files are grouped together, 'ccc'
+ files are not grouped.
+ """
+
+ def __init__(self, params, obj):
+ super().__init__(params)
+
+ @staticmethod
+ def _user_query(priv_query_exec, obj, params, method_obj):
+ if obj == 'babeltrace.support-info':
+ if params['type'] == 'file':
+ name = os.path.basename(str(params['input']))
+
+ if name.startswith('aaa'):
+ return {'weight': 1, 'group': 'aaa'}
+ elif name.startswith('bbb'):
+ return {'weight': 0.5, 'group': 'bbb'}
+ elif name.startswith('ccc'):
+ # Try two different ways of returning "no group", and two
+ # different ways of returning 1 (an int and a float).
+ if name[3] == '1':
+ return {'weight': 1, 'group': None}
+ elif name[3] == '2':
+ return {'weight': 1.0, 'group': None}
+ elif name[3] == '3':
+ return 1
+ else:
+ return 1.0
+ else:
+ return 0
+ else:
+ raise bt2.UnknownObject
+
+
+@bt2.plugin_component_class
+class TestSourceSomeDir(
+ Base, bt2._UserSourceComponent, message_iterator_class=TestIter
+):
+ """Recognizes directories named "some-dir". The file "aaa10" in the
+ directory "some-dir" won't be found by TestSourceExt, because we won't
+ recurse in "some-dir"."""
+
+ def __init__(self, params, obj):
+ super().__init__(params)
+
+ @staticmethod
+ def _user_query(priv_query_exec, obj, params, method_obj):
+ if obj == 'babeltrace.support-info':
+ if params['type'] == 'directory':
+ name = os.path.basename(str(params['input']))
+ return 1 if name == 'some-dir' else 0
+ else:
+ return 0
+ else:
+ raise bt2.UnknownObject
+
+
+@bt2.plugin_component_class
+class TestSourceABCDE(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
+ """A source that recognizes the arbitrary string input "ABCDE"."""
+
+ def __init__(self, params, obj):
+ super().__init__(params)
+
+ @staticmethod
+ def _user_query(priv_query_exec, obj, params, method_obj):
+ if obj == 'babeltrace.support-info':
+ return (
+ 1.0
+ if params['type'] == 'string' and params['input'] == 'ABCDE'
+ else 0.0
+ )
+ else:
+ raise bt2.UnknownObject
+
+
+class TestSourceNoQuery(bt2._UserSourceComponent, message_iterator_class=TestIter):
+ """A source that does not implement _query at all."""
+
+
+bt2.register_plugin(module_name=__name__, name="test")
--- /dev/null
+import bt2
+import os
+
+# This file defines source component classes to help verify the parameters an
+# log levels passed to components. Each component creates one stream, with a
+# name derived from either:
+#
+# - the received params that start with `test-`
+# - the received log level
+#
+# The `what` parameter determines what is used.
+
+
+class TestIter(bt2._UserMessageIterator):
+ def __init__(self, output_port):
+ params = output_port.user_data['params']
+
+ comp_cls_name = self._component.__class__.__name__
+
+ if params['what'] == 'test-params':
+ items = sorted([str(x) for x in params.items() if x[0].startswith('test-')])
+ stream_name = '{}: {}'.format(comp_cls_name, ', '.join(items))
+ elif params['what'] == 'log-level':
+ log_level = self._component.logging_level
+ stream_name = '{}: {}'.format(comp_cls_name, log_level)
+ else:
+ assert False
+
+ sc = output_port.user_data['sc']
+ tc = sc.trace_class
+ t = tc()
+ s = t.create_stream(sc, name=stream_name)
+
+ self._msgs = [
+ self._create_stream_beginning_message(s),
+ self._create_stream_end_message(s),
+ ]
+
+ def __next__(self):
+ if len(self._msgs) == 0:
+ raise StopIteration
+
+ return self._msgs.pop(0)
+
+
+class Base:
+ def __init__(self, params):
+ tc = self._create_trace_class()
+ sc = tc.create_stream_class()
+
+ self._add_output_port('out', {'params': params, 'sc': sc})
+
+
+@bt2.plugin_component_class
+class TestSourceA(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
+ def __init__(self, params, obj):
+ super().__init__(params)
+
+ @staticmethod
+ def _user_query(priv_query_exec, obj, params, method_obj):
+ # Match files starting with 'aaa'.
+
+ if obj == 'babeltrace.support-info':
+ if params['type'] != 'file':
+ return 0
+
+ name = os.path.basename(str(params['input']))
+
+ if name.startswith('aaa'):
+ return {'weight': 1, 'group': 'aaa'}
+ else:
+ return 0
+ else:
+ raise bt2.UnknownObject
+
+
+@bt2.plugin_component_class
+class TestSourceB(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
+ def __init__(self, params, obj):
+ super().__init__(params)
+
+ @staticmethod
+ def _user_query(priv_query_exec, obj, params, method_obj):
+ # Match files starting with 'bbb'.
+
+ if obj == 'babeltrace.support-info':
+ if params['type'] != 'file':
+ return 0
+
+ name = os.path.basename(str(params['input']))
+
+ if name.startswith('bbb'):
+ return {'weight': 1, 'group': 'bbb'}
+ else:
+ return 0
+ else:
+ raise bt2.UnknownObject
+
+
+bt2.register_plugin(module_name=__name__, name="test")
--- /dev/null
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceABCDE: ABCDE
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceExt: aaa1, aaa2, aaa3
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 2, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceExt: bbb1, bbb2
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 3, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceExt: ccc1
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 4, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceExt: ccc2
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 5, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceExt: ccc3
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 6, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceExt: ccc4
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 7, Stream class ID 0, Stream ID 0}
+Stream beginning:
+ Name: TestSourceSomeDir: some-dir
+ Trace:
+ Stream (ID 0, Class ID 0)
+
+{Trace 0, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 1, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 2, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 3, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 4, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 5, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 6, Stream class ID 0, Stream ID 0}
+Stream end
+
+{Trace 7, Stream class ID 0, Stream ID 0}
+Stream end
+++ /dev/null
-import bt2
-import os
-
-# Source component classes in this file recognize and group inputs in
-# various ways. One stream is created by each component, with a name
-# derived from the component class and the inputs. This is then checked
-# using the `sink.text.details` sink.
-
-
-class TestIter(bt2._UserMessageIterator):
- def __init__(self, output_port):
- inputs = output_port.user_data['inputs']
- sc = output_port.user_data['sc']
- tc = sc.trace_class
- t = tc()
- s = t.create_stream(sc, name=self._make_stream_name(inputs))
-
- self._msgs = [
- self._create_stream_beginning_message(s),
- self._create_stream_end_message(s),
- ]
-
- def _make_stream_name(self, inputs):
- comp_cls_name = self._component.__class__.__name__
- return (
- comp_cls_name
- + ': '
- + ', '.join(sorted([os.path.basename(str(x)) for x in inputs]))
- )
-
- def __next__(self):
- if len(self._msgs) == 0:
- raise StopIteration
-
- return self._msgs.pop(0)
-
-
-class Base:
- def __init__(self, params):
- tc = self._create_trace_class()
- sc = tc.create_stream_class()
-
- self._add_output_port('out', {'inputs': params['inputs'], 'sc': sc})
-
-
-@bt2.plugin_component_class
-class TestSourceExt(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
- """
- Recognize files whose name start with 'aaa', 'bbb' or 'ccc'.
-
- 'aaa' files are grouped together, 'bbb' files are grouped together, 'ccc'
- files are not grouped.
- """
-
- def __init__(self, params, obj):
- super().__init__(params)
-
- @staticmethod
- def _user_query(priv_query_exec, obj, params, method_obj):
- if obj == 'babeltrace.support-info':
- if params['type'] == 'file':
- name = os.path.basename(str(params['input']))
-
- if name.startswith('aaa'):
- return {'weight': 1, 'group': 'aaa'}
- elif name.startswith('bbb'):
- return {'weight': 0.5, 'group': 'bbb'}
- elif name.startswith('ccc'):
- # Try two different ways of returning "no group", and two
- # different ways of returning 1 (an int and a float).
- if name[3] == '1':
- return {'weight': 1, 'group': None}
- elif name[3] == '2':
- return {'weight': 1.0, 'group': None}
- elif name[3] == '3':
- return 1
- else:
- return 1.0
- else:
- return 0
- else:
- raise bt2.UnknownObject
-
-
-@bt2.plugin_component_class
-class TestSourceSomeDir(
- Base, bt2._UserSourceComponent, message_iterator_class=TestIter
-):
- """Recognizes directories named "some-dir". The file "aaa10" in the
- directory "some-dir" won't be found by TestSourceExt, because we won't
- recurse in "some-dir"."""
-
- def __init__(self, params, obj):
- super().__init__(params)
-
- @staticmethod
- def _user_query(priv_query_exec, obj, params, method_obj):
- if obj == 'babeltrace.support-info':
- if params['type'] == 'directory':
- name = os.path.basename(str(params['input']))
- return 1 if name == 'some-dir' else 0
- else:
- return 0
- else:
- raise bt2.UnknownObject
-
-
-@bt2.plugin_component_class
-class TestSourceABCDE(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
- """A source that recognizes the arbitrary string input "ABCDE"."""
-
- def __init__(self, params, obj):
- super().__init__(params)
-
- @staticmethod
- def _user_query(priv_query_exec, obj, params, method_obj):
- if obj == 'babeltrace.support-info':
- return (
- 1.0
- if params['type'] == 'string' and params['input'] == 'ABCDE'
- else 0.0
- )
- else:
- raise bt2.UnknownObject
-
-
-class TestSourceNoQuery(bt2._UserSourceComponent, message_iterator_class=TestIter):
- """A source that does not implement _query at all."""
-
-
-bt2.register_plugin(module_name=__name__, name="test")
+++ /dev/null
-{Trace 0, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceABCDE: ABCDE
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 1, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceExt: aaa1, aaa2, aaa3
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 2, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceExt: bbb1, bbb2
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 3, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceExt: ccc1
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 4, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceExt: ccc2
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 5, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceExt: ccc3
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 6, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceExt: ccc4
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 7, Stream class ID 0, Stream ID 0}
-Stream beginning:
- Name: TestSourceSomeDir: some-dir
- Trace:
- Stream (ID 0, Class ID 0)
-
-{Trace 0, Stream class ID 0, Stream ID 0}
-Stream end
-
-{Trace 1, Stream class ID 0, Stream ID 0}
-Stream end
-
-{Trace 2, Stream class ID 0, Stream ID 0}
-Stream end
-
-{Trace 3, Stream class ID 0, Stream ID 0}
-Stream end
-
-{Trace 4, Stream class ID 0, Stream ID 0}
-Stream end
-
-{Trace 5, Stream class ID 0, Stream ID 0}
-Stream end
-
-{Trace 6, Stream class ID 0, Stream ID 0}
-Stream end
-
-{Trace 7, Stream class ID 0, Stream ID 0}
-Stream end
+++ /dev/null
-import bt2
-import os
-
-# This file defines source component classes to help verify the parameters an
-# log levels passed to components. Each component creates one stream, with a
-# name derived from either:
-#
-# - the received params that start with `test-`
-# - the received log level
-#
-# The `what` parameter determines what is used.
-
-
-class TestIter(bt2._UserMessageIterator):
- def __init__(self, output_port):
- params = output_port.user_data['params']
-
- comp_cls_name = self._component.__class__.__name__
-
- if params['what'] == 'test-params':
- items = sorted([str(x) for x in params.items() if x[0].startswith('test-')])
- stream_name = '{}: {}'.format(comp_cls_name, ', '.join(items))
- elif params['what'] == 'log-level':
- log_level = self._component.logging_level
- stream_name = '{}: {}'.format(comp_cls_name, log_level)
- else:
- assert False
-
- sc = output_port.user_data['sc']
- tc = sc.trace_class
- t = tc()
- s = t.create_stream(sc, name=stream_name)
-
- self._msgs = [
- self._create_stream_beginning_message(s),
- self._create_stream_end_message(s),
- ]
-
- def __next__(self):
- if len(self._msgs) == 0:
- raise StopIteration
-
- return self._msgs.pop(0)
-
-
-class Base:
- def __init__(self, params):
- tc = self._create_trace_class()
- sc = tc.create_stream_class()
-
- self._add_output_port('out', {'params': params, 'sc': sc})
-
-
-@bt2.plugin_component_class
-class TestSourceA(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
- def __init__(self, params, obj):
- super().__init__(params)
-
- @staticmethod
- def _user_query(priv_query_exec, obj, params, method_obj):
- # Match files starting with 'aaa'.
-
- if obj == 'babeltrace.support-info':
- if params['type'] != 'file':
- return 0
-
- name = os.path.basename(str(params['input']))
-
- if name.startswith('aaa'):
- return {'weight': 1, 'group': 'aaa'}
- else:
- return 0
- else:
- raise bt2.UnknownObject
-
-
-@bt2.plugin_component_class
-class TestSourceB(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
- def __init__(self, params, obj):
- super().__init__(params)
-
- @staticmethod
- def _user_query(priv_query_exec, obj, params, method_obj):
- # Match files starting with 'bbb'.
-
- if obj == 'babeltrace.support-info':
- if params['type'] != 'file':
- return 0
-
- name = os.path.basename(str(params['input']))
-
- if name.startswith('bbb'):
- return {'weight': 1, 'group': 'bbb'}
- else:
- return 0
- else:
- raise bt2.UnknownObject
-
-
-bt2.register_plugin(module_name=__name__, name="test")