1 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright (C) 2019 EfficiOS Inc.
10 # This file defines source component classes to help verify the parameters an
11 # log levels passed to components. Each component creates one stream, with a
12 # name derived from either:
14 # - the received params that start with `test-`
15 # - the received log level
17 # The `what` parameter determines what is used.
20 class TestIter(bt2
._UserMessageIterator
):
21 def __init__(self
, config
, output_port
):
22 params
= output_port
.user_data
["params"]
23 obj
= output_port
.user_data
["obj"]
25 comp_cls_name
= self
._component
.__class
__.__name
__
27 if params
["what"] == "test-params":
28 items
= sorted([str(x
) for x
in params
.items() if x
[0].startswith("test-")])
29 stream_name
= "{}: {}".format(comp_cls_name
, ", ".join(items
))
30 elif params
["what"] == "log-level":
31 log_level
= self
._component
.logging_level
32 stream_name
= "{}: {}".format(comp_cls_name
, log_level
)
33 elif params
["what"] == "python-obj":
34 assert type(obj
) is str or obj
is None
35 stream_name
= "{}: {}".format(comp_cls_name
, obj
)
39 sc
= output_port
.user_data
["sc"]
42 s
= t
.create_stream(sc
, name
=stream_name
)
45 self
._create
_stream
_beginning
_message
(s
),
46 self
._create
_stream
_end
_message
(s
),
50 if len(self
._msgs
) == 0:
53 return self
._msgs
.pop(0)
57 def __init__(self
, params
, obj
):
58 tc
= self
._create
_trace
_class
()
59 sc
= tc
.create_stream_class()
61 self
._add
_output
_port
("out", {"params": params
, "obj": obj
, "sc": sc
})
64 @bt2.plugin_component_class
65 class TestSourceA(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
66 def __init__(self
, config
, params
, obj
):
67 super().__init
__(params
, obj
)
70 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
71 # Match files starting with 'aaa'.
73 if obj
== "babeltrace.support-info":
74 if params
["type"] != "file":
77 name
= os
.path
.basename(str(params
["input"]))
79 if name
.startswith("aaa"):
80 return {"weight": 1, "group": "aaa"}
84 raise bt2
.UnknownObject
87 @bt2.plugin_component_class
88 class TestSourceB(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
89 def __init__(self
, config
, params
, obj
):
90 super().__init
__(params
, obj
)
93 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
94 # Match files starting with 'bbb'.
96 if obj
== "babeltrace.support-info":
97 if params
["type"] != "file":
100 name
= os
.path
.basename(str(params
["input"]))
102 if name
.startswith("bbb"):
103 return {"weight": 1, "group": "bbb"}
107 raise bt2
.UnknownObject
110 bt2
.register_plugin(module_name
=__name__
, name
="test")
This page took 0.030876 seconds and 4 git commands to generate.