2bf0843b79abedc60580bc0ad6f9c682dbb44b31
1 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright (C) 2019 EfficiOS Inc.
10 # Source component classes in this file recognize and group inputs in
11 # various ways. One stream is created by each component, with a name
12 # derived from the component class and the inputs. This is then checked
13 # using the `sink.text.details` sink.
16 class TestIter(bt2
._UserMessageIterator
):
17 def __init__(self
, config
, output_port
):
18 inputs
= output_port
.user_data
["inputs"]
19 sc
= output_port
.user_data
["sc"]
22 s
= t
.create_stream(sc
, name
=self
._make
_stream
_name
(inputs
))
25 self
._create
_stream
_beginning
_message
(s
),
26 self
._create
_stream
_end
_message
(s
),
29 def _make_stream_name(self
, inputs
):
30 comp_cls_name
= self
._component
.__class
__.__name
__
34 + ", ".join(sorted([os
.path
.basename(str(x
)) for x
in inputs
]))
38 if len(self
._msgs
) == 0:
41 return self
._msgs
.pop(0)
45 def __init__(self
, params
):
46 tc
= self
._create
_trace
_class
()
47 sc
= tc
.create_stream_class()
49 self
._add
_output
_port
("out", {"inputs": params
["inputs"], "sc": sc
})
52 @bt2.plugin_component_class
53 class TestSourceExt(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
55 Recognize files whose name start with 'aaa', 'bbb' or 'ccc'.
57 'aaa' files are grouped together, 'bbb' files are grouped together, 'ccc'
58 files are not grouped.
61 def __init__(self
, config
, params
, obj
):
62 super().__init
__(params
)
65 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
66 if obj
== "babeltrace.support-info":
67 if params
["type"] == "file":
68 name
= os
.path
.basename(str(params
["input"]))
70 if name
.startswith("aaa"):
71 return {"weight": 1, "group": "aaa"}
72 elif name
.startswith("bbb"):
73 return {"weight": 0.5, "group": "bbb"}
74 elif name
.startswith("ccc"):
75 # Try two different ways of returning 1 (an int and a float).
83 raise bt2
.UnknownObject
86 @bt2.plugin_component_class
87 class TestSourceSomeDir(
88 Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
90 """Recognizes directories named "some-dir". The file "aaa10" in the
91 directory "some-dir" won't be found by TestSourceExt, because we won't
92 recurse in "some-dir"."""
94 def __init__(self
, config
, params
, obj
):
95 super().__init
__(params
)
98 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
99 if obj
== "babeltrace.support-info":
100 if params
["type"] == "directory":
101 name
= os
.path
.basename(str(params
["input"]))
102 return 1 if name
== "some-dir" else 0
106 raise bt2
.UnknownObject
109 @bt2.plugin_component_class
110 class TestSourceABCDE(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
111 """A source that recognizes the arbitrary string input "ABCDE"."""
113 def __init__(self
, config
, params
, obj
):
114 super().__init
__(params
)
117 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
118 if obj
== "babeltrace.support-info":
121 if params
["type"] == "string" and params
["input"] == "ABCDE"
125 raise bt2
.UnknownObject
128 class TestSourceNoQuery(bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
129 """A source that does not implement _query at all."""
132 bt2
.register_plugin(module_name
=__name__
, name
="test")
This page took 0.033857 seconds and 5 git commands to generate.