a1ac699454bef32ec8937e49a789e1a381e0c942
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']
18 comp_cls_name
= self
._component
.__class
__.__name
__
20 if params
['what'] == 'test-params':
21 items
= sorted([str(x
) for x
in params
.items() if x
[0].startswith('test-')])
22 stream_name
= '{}: {}'.format(comp_cls_name
, ', '.join(items
))
23 elif params
['what'] == 'log-level':
24 log_level
= self
._component
.logging_level
25 stream_name
= '{}: {}'.format(comp_cls_name
, log_level
)
29 sc
= output_port
.user_data
['sc']
32 s
= t
.create_stream(sc
, name
=stream_name
)
35 self
._create
_stream
_beginning
_message
(s
),
36 self
._create
_stream
_end
_message
(s
),
40 if len(self
._msgs
) == 0:
43 return self
._msgs
.pop(0)
47 def __init__(self
, params
):
48 tc
= self
._create
_trace
_class
()
49 sc
= tc
.create_stream_class()
51 self
._add
_output
_port
('out', {'params': params
, 'sc': sc
})
54 @bt2.plugin_component_class
55 class TestSourceA(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
56 def __init__(self
, params
, obj
):
57 super().__init
__(params
)
60 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
61 # Match files starting with 'aaa'.
63 if obj
== 'babeltrace.support-info':
64 if params
['type'] != 'file':
67 name
= os
.path
.basename(str(params
['input']))
69 if name
.startswith('aaa'):
70 return {'weight': 1, 'group': 'aaa'}
74 raise bt2
.UnknownObject
77 @bt2.plugin_component_class
78 class TestSourceB(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
79 def __init__(self
, params
, obj
):
80 super().__init
__(params
)
83 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
84 # Match files starting with 'bbb'.
86 if obj
== 'babeltrace.support-info':
87 if params
['type'] != 'file':
90 name
= os
.path
.basename(str(params
['input']))
92 if name
.startswith('bbb'):
93 return {'weight': 1, 'group': 'bbb'}
97 raise bt2
.UnknownObject
100 bt2
.register_plugin(module_name
=__name__
, name
="test")
This page took 0.032178 seconds and 3 git commands to generate.