1 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright (C) 2019 EfficiOS Inc.
9 # This file defines source component classes to help verify the parameters an
10 # log levels passed to components. Each component creates one stream, with a
11 # name derived from either:
13 # - the received params that start with `test-`
14 # - the received log level
16 # The `what` parameter determines what is used.
19 class TestIter(bt2
._UserMessageIterator
):
20 def __init__(self
, config
, output_port
):
21 params
= output_port
.user_data
["params"]
22 obj
= output_port
.user_data
["obj"]
24 comp_cls_name
= self
._component
.__class
__.__name
__
26 if params
["what"] == "test-params":
27 items
= sorted([str(x
) for x
in params
.items() if x
[0].startswith("test-")])
28 stream_name
= "{}: {}".format(comp_cls_name
, ", ".join(items
))
29 elif params
["what"] == "log-level":
30 log_level
= self
._component
.logging_level
31 stream_name
= "{}: {}".format(comp_cls_name
, log_level
)
32 elif params
["what"] == "python-obj":
33 assert type(obj
) == str or obj
is None
34 stream_name
= "{}: {}".format(comp_cls_name
, obj
)
38 sc
= output_port
.user_data
["sc"]
41 s
= t
.create_stream(sc
, name
=stream_name
)
44 self
._create
_stream
_beginning
_message
(s
),
45 self
._create
_stream
_end
_message
(s
),
49 if len(self
._msgs
) == 0:
52 return self
._msgs
.pop(0)
56 def __init__(self
, params
, obj
):
57 tc
= self
._create
_trace
_class
()
58 sc
= tc
.create_stream_class()
60 self
._add
_output
_port
("out", {"params": params
, "obj": obj
, "sc": sc
})
63 @bt2.plugin_component_class
64 class TestSourceA(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
65 def __init__(self
, config
, params
, obj
):
66 super().__init
__(params
, obj
)
69 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
70 # Match files starting with 'aaa'.
72 if obj
== "babeltrace.support-info":
73 if params
["type"] != "file":
76 name
= os
.path
.basename(str(params
["input"]))
78 if name
.startswith("aaa"):
79 return {"weight": 1, "group": "aaa"}
83 raise bt2
.UnknownObject
86 @bt2.plugin_component_class
87 class TestSourceB(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
88 def __init__(self
, config
, params
, obj
):
89 super().__init
__(params
, obj
)
92 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
93 # Match files starting with 'bbb'.
95 if obj
== "babeltrace.support-info":
96 if params
["type"] != "file":
99 name
= os
.path
.basename(str(params
["input"]))
101 if name
.startswith("bbb"):
102 return {"weight": 1, "group": "bbb"}
106 raise bt2
.UnknownObject
109 bt2
.register_plugin(module_name
=__name__
, name
="test")
This page took 0.032188 seconds and 5 git commands to generate.