336f49c2c904e1fef8007247984794e55530941f
4 # This file defines source component classes to help verify the parameters an
5 # log levels passed to components. Each component creates one stream, with a
6 # name derived from either:
8 # - the received params that start with `test-`
9 # - the received log level
11 # The `what` parameter determines what is used.
14 class TestIter(bt2
._UserMessageIterator
):
15 def __init__(self
, output_port
):
16 params
= output_port
.user_data
['params']
17 obj
= output_port
.user_data
['obj']
19 comp_cls_name
= self
._component
.__class
__.__name
__
21 if params
['what'] == 'test-params':
22 items
= sorted([str(x
) for x
in params
.items() if x
[0].startswith('test-')])
23 stream_name
= '{}: {}'.format(comp_cls_name
, ', '.join(items
))
24 elif params
['what'] == 'log-level':
25 log_level
= self
._component
.logging_level
26 stream_name
= '{}: {}'.format(comp_cls_name
, log_level
)
27 elif params
['what'] == 'python-obj':
28 assert type(obj
) == str or obj
is None
29 stream_name
= '{}: {}'.format(comp_cls_name
, obj
)
33 sc
= output_port
.user_data
['sc']
36 s
= t
.create_stream(sc
, name
=stream_name
)
39 self
._create
_stream
_beginning
_message
(s
),
40 self
._create
_stream
_end
_message
(s
),
44 if len(self
._msgs
) == 0:
47 return self
._msgs
.pop(0)
51 def __init__(self
, params
, obj
):
52 tc
= self
._create
_trace
_class
()
53 sc
= tc
.create_stream_class()
55 self
._add
_output
_port
('out', {'params': params
, 'obj': obj
, 'sc': sc
})
58 @bt2.plugin_component_class
59 class TestSourceA(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
60 def __init__(self
, params
, obj
):
61 super().__init
__(params
, obj
)
64 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
65 # Match files starting with 'aaa'.
67 if obj
== 'babeltrace.support-info':
68 if params
['type'] != 'file':
71 name
= os
.path
.basename(str(params
['input']))
73 if name
.startswith('aaa'):
74 return {'weight': 1, 'group': 'aaa'}
78 raise bt2
.UnknownObject
81 @bt2.plugin_component_class
82 class TestSourceB(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
83 def __init__(self
, params
, obj
):
84 super().__init
__(params
, obj
)
87 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
88 # Match files starting with 'bbb'.
90 if obj
== 'babeltrace.support-info':
91 if params
['type'] != 'file':
94 name
= os
.path
.basename(str(params
['input']))
96 if name
.startswith('bbb'):
97 return {'weight': 1, 'group': 'bbb'}
101 raise bt2
.UnknownObject
104 bt2
.register_plugin(module_name
=__name__
, name
="test")
This page took 0.030936 seconds and 4 git commands to generate.