2 # Copyright (C) 2019 EfficiOS Inc.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; only version 2
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 _BT_TESTS_DATADIR
= os
.environ
['BT_TESTS_DATADIR']
27 _BT_CTF_TRACES_PATH
= os
.environ
['BT_CTF_TRACES_PATH']
28 _3EVENTS_INTERSECT_TRACE_PATH
= os
.path
.join(
29 _BT_CTF_TRACES_PATH
, 'intersection', '3eventsintersect'
31 _NOINTERSECT_TRACE_PATH
= os
.path
.join(
32 _BT_CTF_TRACES_PATH
, 'intersection', 'nointersect'
34 _SEQUENCE_TRACE_PATH
= os
.path
.join(_BT_CTF_TRACES_PATH
, 'succeed', 'sequence')
35 _AUTO_SOURCE_DISCOVERY_GROUPING_PATH
= os
.path
.join(
36 _BT_TESTS_DATADIR
, 'auto-source-discovery', 'grouping'
38 _AUTO_SOURCE_DISCOVERY_PARAMS_LOG_LEVEL_PATH
= os
.path
.join(
39 _BT_TESTS_DATADIR
, 'auto-source-discovery', 'params-log-level'
44 bt2
._UserSourceComponent
, message_iterator_class
=bt2
._UserMessageIterator
50 bt2
._UserFilterComponent
, message_iterator_class
=bt2
._UserMessageIterator
55 class _SomeSink(bt2
._UserSinkComponent
):
56 def _user_consume(self
):
60 class ComponentSpecTestCase(unittest
.TestCase
):
62 # A source CC from a plugin.
63 self
._dmesg
_cc
= bt2
.find_plugin('text').source_component_classes
['dmesg']
64 assert self
._dmesg
_cc
is not None
66 # A filter CC from a plugin.
67 self
._muxer
_cc
= bt2
.find_plugin('utils').filter_component_classes
['muxer']
68 assert self
._muxer
_cc
is not None
70 # A sink CC from a plugin.
71 self
._pretty
_cc
= bt2
.find_plugin('text').sink_component_classes
['pretty']
72 assert self
._pretty
_cc
is not None
74 def test_create_source_from_name(self
):
75 spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class('text', 'dmesg')
76 self
.assertEqual(spec
.component_class
.name
, 'dmesg')
78 def test_create_source_from_plugin(self
):
79 spec
= bt2
.ComponentSpec(self
._dmesg
_cc
)
80 self
.assertEqual(spec
.component_class
.name
, 'dmesg')
82 def test_create_source_from_user(self
):
83 spec
= bt2
.ComponentSpec(_SomeSource
)
84 self
.assertEqual(spec
.component_class
.name
, '_SomeSource')
86 def test_create_filter_from_name(self
):
87 spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class('utils', 'muxer')
88 self
.assertEqual(spec
.component_class
.name
, 'muxer')
90 def test_create_filter_from_object(self
):
91 spec
= bt2
.ComponentSpec(self
._muxer
_cc
)
92 self
.assertEqual(spec
.component_class
.name
, 'muxer')
94 def test_create_sink_from_name(self
):
95 with self
.assertRaisesRegex(
97 'source or filter component class `pretty` not found in plugin `text`',
99 bt2
.ComponentSpec
.from_named_plugin_and_component_class('text', 'pretty')
101 def test_create_sink_from_object(self
):
102 with self
.assertRaisesRegex(
103 TypeError, "'_SinkComponentClass' is not a source or filter component class"
105 bt2
.ComponentSpec(self
._pretty
_cc
)
107 def test_create_from_object_with_params(self
):
108 spec
= bt2
.ComponentSpec(self
._dmesg
_cc
, {'salut': 23})
109 self
.assertEqual(spec
.params
['salut'], 23)
111 def test_create_from_name_with_params(self
):
112 spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class(
113 'text', 'dmesg', {'salut': 23}
115 self
.assertEqual(spec
.params
['salut'], 23)
117 def test_create_from_object_with_path_params(self
):
118 spec
= spec
= bt2
.ComponentSpec(self
._dmesg
_cc
, 'a path')
119 self
.assertEqual(spec
.params
['inputs'], ['a path'])
121 def test_create_from_name_with_path_params(self
):
122 spec
= spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class(
123 'text', 'dmesg', 'a path'
125 self
.assertEqual(spec
.params
['inputs'], ['a path'])
127 def test_create_wrong_comp_class_type(self
):
128 with self
.assertRaisesRegex(
129 TypeError, "'int' is not a source or filter component class"
131 bt2
.ComponentSpec(18)
133 def test_create_from_name_wrong_plugin_name_type(self
):
134 with self
.assertRaisesRegex(TypeError, "'int' is not a 'str' object"):
135 bt2
.ComponentSpec
.from_named_plugin_and_component_class(23, 'compcls')
137 def test_create_from_name_non_existent_plugin(self
):
138 with self
.assertRaisesRegex(
139 ValueError, "no such plugin: this_plugin_does_not_exist"
141 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
142 'this_plugin_does_not_exist', 'compcls'
145 def test_create_from_name_wrong_component_class_name_type(self
):
146 with self
.assertRaisesRegex(TypeError, "'int' is not a 'str' object"):
147 bt2
.ComponentSpec
.from_named_plugin_and_component_class('utils', 190)
149 def test_create_wrong_params_type(self
):
150 with self
.assertRaisesRegex(
151 TypeError, "cannot create value object from 'datetime' object"
153 bt2
.ComponentSpec(self
._dmesg
_cc
, params
=datetime
.datetime
.now())
155 def test_create_from_name_wrong_params_type(self
):
156 with self
.assertRaisesRegex(
157 TypeError, "cannot create value object from 'datetime' object"
159 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
160 'text', 'dmesg', datetime
.datetime
.now()
163 def test_create_wrong_log_level_type(self
):
164 with self
.assertRaisesRegex(TypeError, "'str' is not an 'int' object"):
165 bt2
.ComponentSpec(self
._dmesg
_cc
, logging_level
='banane')
167 def test_create_from_name_wrong_log_level_type(self
):
168 with self
.assertRaisesRegex(TypeError, "'str' is not an 'int' object"):
169 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
170 'text', 'dmesg', logging_level
='banane'
174 # Return a map, msg type -> number of messages of this type.
177 def _count_msgs_by_type(msgs
):
188 class TraceCollectionMessageIteratorTestCase(unittest
.TestCase
):
189 def test_create_wrong_stream_intersection_mode_type(self
):
191 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
192 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
196 with self
.assertRaises(TypeError):
197 bt2
.TraceCollectionMessageIterator(specs
, stream_intersection_mode
=23)
199 def test_create_wrong_begin_type(self
):
201 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
202 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
206 with self
.assertRaises(TypeError):
207 bt2
.TraceCollectionMessageIterator(specs
, begin
='hi')
209 def test_create_wrong_end_type(self
):
211 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
212 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
216 with self
.assertRaises(TypeError):
217 bt2
.TraceCollectionMessageIterator(specs
, begin
='lel')
219 def test_create_begin_s(self
):
221 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
222 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
225 bt2
.TraceCollectionMessageIterator(specs
, begin
=19457.918232)
227 def test_create_end_s(self
):
229 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
230 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
233 bt2
.TraceCollectionMessageIterator(specs
, end
=123.12312)
235 def test_create_begin_datetime(self
):
237 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
238 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
241 bt2
.TraceCollectionMessageIterator(specs
, begin
=datetime
.datetime
.now())
243 def test_create_end_datetime(self
):
245 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
246 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
249 bt2
.TraceCollectionMessageIterator(specs
, end
=datetime
.datetime
.now())
251 def test_iter_no_intersection(self
):
253 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
254 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
257 msg_iter
= bt2
.TraceCollectionMessageIterator(specs
)
258 msgs
= list(msg_iter
)
259 self
.assertEqual(len(msgs
), 28)
260 hist
= _count_msgs_by_type(msgs
)
261 self
.assertEqual(hist
[bt2
._EventMessage
], 8)
263 # Same as the above, but we pass a single spec instead of a spec list.
264 def test_iter_specs_not_list(self
):
265 spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class(
266 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
268 msg_iter
= bt2
.TraceCollectionMessageIterator(spec
)
269 msgs
= list(msg_iter
)
270 self
.assertEqual(len(msgs
), 28)
271 hist
= _count_msgs_by_type(msgs
)
272 self
.assertEqual(hist
[bt2
._EventMessage
], 8)
274 def test_iter_custom_filter(self
):
275 src_spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class(
276 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
278 flt_spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class(
279 'utils', 'trimmer', {'end': '13515309.000000075'}
281 msg_iter
= bt2
.TraceCollectionMessageIterator(src_spec
, flt_spec
)
282 hist
= _count_msgs_by_type(msg_iter
)
283 self
.assertEqual(hist
[bt2
._EventMessage
], 5)
285 def test_iter_intersection(self
):
287 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
288 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
291 msg_iter
= bt2
.TraceCollectionMessageIterator(
292 specs
, stream_intersection_mode
=True
294 msgs
= list(msg_iter
)
295 self
.assertEqual(len(msgs
), 15)
296 hist
= _count_msgs_by_type(msgs
)
297 self
.assertEqual(hist
[bt2
._EventMessage
], 3)
299 def test_iter_intersection_params(self
):
300 # Check that all params used to create the source component are passed
301 # to the `babeltrace.trace-infos` query.
303 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
307 'inputs': [_3EVENTS_INTERSECT_TRACE_PATH
],
308 'clock-class-offset-s': 1000,
313 msg_iter
= bt2
.TraceCollectionMessageIterator(
314 specs
, stream_intersection_mode
=True
317 event_msgs
= [x
for x
in msg_iter
if type(x
) is bt2
._EventMessage
]
318 self
.assertEqual(len(event_msgs
), 3)
320 event_msgs
[0].default_clock_snapshot
.ns_from_origin
, 13516309000000071
323 event_msgs
[1].default_clock_snapshot
.ns_from_origin
, 13516309000000072
326 event_msgs
[2].default_clock_snapshot
.ns_from_origin
, 13516309000000082
329 def test_iter_no_intersection_two_traces(self
):
330 spec
= bt2
.ComponentSpec
.from_named_plugin_and_component_class(
331 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
334 msg_iter
= bt2
.TraceCollectionMessageIterator(specs
)
335 msgs
= list(msg_iter
)
336 self
.assertEqual(len(msgs
), 56)
337 hist
= _count_msgs_by_type(msgs
)
338 self
.assertEqual(hist
[bt2
._EventMessage
], 16)
340 def test_iter_no_intersection_begin(self
):
342 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
343 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
346 msg_iter
= bt2
.TraceCollectionMessageIterator(specs
, begin
=13515309.000000023)
347 hist
= _count_msgs_by_type(msg_iter
)
348 self
.assertEqual(hist
[bt2
._EventMessage
], 6)
350 def test_iter_no_intersection_end(self
):
352 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
353 'ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH
356 msg_iter
= bt2
.TraceCollectionMessageIterator(specs
, end
=13515309.000000075)
357 hist
= _count_msgs_by_type(msg_iter
)
358 self
.assertEqual(hist
[bt2
._EventMessage
], 5)
360 def test_iter_auto_source_component_spec(self
):
361 specs
= [bt2
.AutoSourceComponentSpec(_3EVENTS_INTERSECT_TRACE_PATH
)]
362 msg_iter
= bt2
.TraceCollectionMessageIterator(specs
)
363 msgs
= list(msg_iter
)
364 self
.assertEqual(len(msgs
), 28)
365 hist
= _count_msgs_by_type(msgs
)
366 self
.assertEqual(hist
[bt2
._EventMessage
], 8)
368 def test_iter_auto_source_component_spec_list_of_strings(self
):
369 msg_iter
= bt2
.TraceCollectionMessageIterator([_3EVENTS_INTERSECT_TRACE_PATH
])
370 msgs
= list(msg_iter
)
371 self
.assertEqual(len(msgs
), 28)
372 hist
= _count_msgs_by_type(msgs
)
373 self
.assertEqual(hist
[bt2
._EventMessage
], 8)
375 def test_iter_auto_source_component_spec_string(self
):
376 msg_iter
= bt2
.TraceCollectionMessageIterator(_3EVENTS_INTERSECT_TRACE_PATH
)
377 msgs
= list(msg_iter
)
378 self
.assertEqual(len(msgs
), 28)
379 hist
= _count_msgs_by_type(msgs
)
380 self
.assertEqual(hist
[bt2
._EventMessage
], 8)
382 def test_iter_mixed_inputs(self
):
383 msg_iter
= bt2
.TraceCollectionMessageIterator(
385 _3EVENTS_INTERSECT_TRACE_PATH
,
386 bt2
.AutoSourceComponentSpec(_SEQUENCE_TRACE_PATH
),
387 bt2
.ComponentSpec
.from_named_plugin_and_component_class(
388 'ctf', 'fs', _NOINTERSECT_TRACE_PATH
392 msgs
= list(msg_iter
)
393 self
.assertEqual(len(msgs
), 76)
394 hist
= _count_msgs_by_type(msgs
)
395 self
.assertEqual(hist
[bt2
._EventMessage
], 24)
397 def test_auto_source_component_non_existent(self
):
398 with self
.assertRaisesRegex(
400 'Some auto source component specs did not produce any component',
402 # Test with one path known to contain a trace and one path known
403 # to not contain any trace.
404 bt2
.TraceCollectionMessageIterator(
405 [_SEQUENCE_TRACE_PATH
, '/this/path/better/not/exist']
409 class _TestAutoDiscoverSourceComponentSpecs(unittest
.TestCase
):
411 self
._saved
_babeltrace
_plugin
_path
= os
.environ
['BABELTRACE_PLUGIN_PATH']
412 os
.environ
['BABELTRACE_PLUGIN_PATH'] += os
.pathsep
+ self
._plugin
_path
415 os
.environ
['BABELTRACE_PLUGIN_PATH'] = self
._saved
_babeltrace
_plugin
_path
418 class TestAutoDiscoverSourceComponentSpecsGrouping(
419 _TestAutoDiscoverSourceComponentSpecs
421 _plugin_path
= _AUTO_SOURCE_DISCOVERY_GROUPING_PATH
423 def test_grouping(self
):
425 bt2
.AutoSourceComponentSpec('ABCDE'),
426 bt2
.AutoSourceComponentSpec(_AUTO_SOURCE_DISCOVERY_GROUPING_PATH
),
428 it
= bt2
.TraceCollectionMessageIterator(specs
)
429 msgs
= [x
for x
in it
if type(x
) is bt2
._StreamBeginningMessage
]
431 self
.assertEqual(len(msgs
), 8)
433 self
.assertEqual(msgs
[0].stream
.name
, 'TestSourceABCDE: ABCDE')
434 self
.assertEqual(msgs
[1].stream
.name
, 'TestSourceExt: aaa1, aaa2, aaa3')
435 self
.assertEqual(msgs
[2].stream
.name
, 'TestSourceExt: bbb1, bbb2')
436 self
.assertEqual(msgs
[3].stream
.name
, 'TestSourceExt: ccc1')
437 self
.assertEqual(msgs
[4].stream
.name
, 'TestSourceExt: ccc2')
438 self
.assertEqual(msgs
[5].stream
.name
, 'TestSourceExt: ccc3')
439 self
.assertEqual(msgs
[6].stream
.name
, 'TestSourceExt: ccc4')
440 self
.assertEqual(msgs
[7].stream
.name
, 'TestSourceSomeDir: some-dir')
443 class TestAutoDiscoverSourceComponentSpecsParamsObjLogLevel(
444 _TestAutoDiscoverSourceComponentSpecs
446 _plugin_path
= _AUTO_SOURCE_DISCOVERY_PARAMS_LOG_LEVEL_PATH
448 _dir_a
= os
.path
.join(_AUTO_SOURCE_DISCOVERY_PARAMS_LOG_LEVEL_PATH
, 'dir-a')
449 _dir_b
= os
.path
.join(_AUTO_SOURCE_DISCOVERY_PARAMS_LOG_LEVEL_PATH
, 'dir-b')
450 _dir_ab
= os
.path
.join(_AUTO_SOURCE_DISCOVERY_PARAMS_LOG_LEVEL_PATH
, 'dir-ab')
452 def _test_two_comps_from_one_spec(self
, params
, obj
=None, logging_level
=None):
454 bt2
.AutoSourceComponentSpec(
455 self
._dir
_ab
, params
=params
, obj
=obj
, logging_level
=logging_level
458 it
= bt2
.TraceCollectionMessageIterator(specs
)
459 msgs
= [x
for x
in it
if type(x
) is bt2
._StreamBeginningMessage
]
461 self
.assertEqual(len(msgs
), 2)
465 def test_params_two_comps_from_one_spec(self
):
466 msgs
= self
._test
_two
_comps
_from
_one
_spec
(
467 params
={'test-allo': 'madame', 'what': 'test-params'}
470 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: ('test-allo', 'madame')")
471 self
.assertEqual(msgs
[1].stream
.name
, "TestSourceB: ('test-allo', 'madame')")
473 def test_obj_two_comps_from_one_spec(self
):
474 msgs
= self
._test
_two
_comps
_from
_one
_spec
(
475 params
={'what': 'python-obj'}, obj
='deore'
478 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: deore")
479 self
.assertEqual(msgs
[1].stream
.name
, "TestSourceB: deore")
481 def test_log_level_two_comps_from_one_spec(self
):
482 msgs
= self
._test
_two
_comps
_from
_one
_spec
(
483 params
={'what': 'log-level'}, logging_level
=bt2
.LoggingLevel
.DEBUG
487 msgs
[0].stream
.name
, "TestSourceA: {}".format(bt2
.LoggingLevel
.DEBUG
)
490 msgs
[1].stream
.name
, "TestSourceB: {}".format(bt2
.LoggingLevel
.DEBUG
)
493 def _test_two_comps_from_two_specs(
499 logging_level_a
=None,
500 logging_level_b
=None,
503 bt2
.AutoSourceComponentSpec(
504 self
._dir
_a
, params
=params_a
, obj
=obj_a
, logging_level
=logging_level_a
506 bt2
.AutoSourceComponentSpec(
507 self
._dir
_b
, params
=params_b
, obj
=obj_b
, logging_level
=logging_level_b
510 it
= bt2
.TraceCollectionMessageIterator(specs
)
511 msgs
= [x
for x
in it
if type(x
) is bt2
._StreamBeginningMessage
]
513 self
.assertEqual(len(msgs
), 2)
517 def test_params_two_comps_from_two_specs(self
):
518 msgs
= self
._test
_two
_comps
_from
_two
_specs
(
519 params_a
={'test-allo': 'madame', 'what': 'test-params'},
520 params_b
={'test-bonjour': 'monsieur', 'what': 'test-params'},
523 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: ('test-allo', 'madame')")
525 msgs
[1].stream
.name
, "TestSourceB: ('test-bonjour', 'monsieur')"
528 def test_obj_two_comps_from_two_specs(self
):
529 msgs
= self
._test
_two
_comps
_from
_two
_specs
(
530 params_a
={'what': 'python-obj'},
531 params_b
={'what': 'python-obj'},
536 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: deore")
537 self
.assertEqual(msgs
[1].stream
.name
, "TestSourceB: alivio")
539 def test_log_level_two_comps_from_two_specs(self
):
540 msgs
= self
._test
_two
_comps
_from
_two
_specs
(
541 params_a
={'what': 'log-level'},
542 params_b
={'what': 'log-level'},
543 logging_level_a
=bt2
.LoggingLevel
.DEBUG
,
544 logging_level_b
=bt2
.LoggingLevel
.TRACE
,
548 msgs
[0].stream
.name
, "TestSourceA: {}".format(bt2
.LoggingLevel
.DEBUG
)
551 msgs
[1].stream
.name
, "TestSourceB: {}".format(bt2
.LoggingLevel
.TRACE
)
554 def _test_one_comp_from_one_spec_one_comp_from_both_1(
560 logging_level_a
=None,
561 logging_level_ab
=None,
564 bt2
.AutoSourceComponentSpec(
565 self
._dir
_a
, params
=params_a
, obj
=obj_a
, logging_level
=logging_level_a
567 bt2
.AutoSourceComponentSpec(
571 logging_level
=logging_level_ab
,
574 it
= bt2
.TraceCollectionMessageIterator(specs
)
575 msgs
= [x
for x
in it
if type(x
) is bt2
._StreamBeginningMessage
]
577 self
.assertEqual(len(msgs
), 2)
581 def test_params_one_comp_from_one_spec_one_comp_from_both_1(self
):
582 msgs
= self
._test
_one
_comp
_from
_one
_spec
_one
_comp
_from
_both
_1(
583 params_a
={'test-allo': 'madame', 'what': 'test-params'},
584 params_ab
={'test-bonjour': 'monsieur', 'what': 'test-params'},
589 "TestSourceA: ('test-allo', 'madame'), ('test-bonjour', 'monsieur')",
592 msgs
[1].stream
.name
, "TestSourceB: ('test-bonjour', 'monsieur')"
595 def test_obj_one_comp_from_one_spec_one_comp_from_both_1(self
):
596 msgs
= self
._test
_one
_comp
_from
_one
_spec
_one
_comp
_from
_both
_1(
597 params_a
={'what': 'python-obj'},
598 params_ab
={'what': 'python-obj'},
603 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: alivio")
604 self
.assertEqual(msgs
[1].stream
.name
, "TestSourceB: alivio")
606 def test_log_level_one_comp_from_one_spec_one_comp_from_both_1(self
):
607 msgs
= self
._test
_one
_comp
_from
_one
_spec
_one
_comp
_from
_both
_1(
608 params_a
={'what': 'log-level'},
609 params_ab
={'what': 'log-level'},
610 logging_level_a
=bt2
.LoggingLevel
.DEBUG
,
611 logging_level_ab
=bt2
.LoggingLevel
.TRACE
,
615 msgs
[0].stream
.name
, "TestSourceA: {}".format(bt2
.LoggingLevel
.TRACE
)
618 msgs
[1].stream
.name
, "TestSourceB: {}".format(bt2
.LoggingLevel
.TRACE
)
621 def _test_one_comp_from_one_spec_one_comp_from_both_2(
627 logging_level_ab
=None,
628 logging_level_a
=None,
631 bt2
.AutoSourceComponentSpec(
635 logging_level
=logging_level_ab
,
637 bt2
.AutoSourceComponentSpec(
638 self
._dir
_a
, params
=params_a
, obj
=obj_a
, logging_level
=logging_level_a
641 it
= bt2
.TraceCollectionMessageIterator(specs
)
642 msgs
= [x
for x
in it
if type(x
) is bt2
._StreamBeginningMessage
]
644 self
.assertEqual(len(msgs
), 2)
648 def test_params_one_comp_from_one_spec_one_comp_from_both_2(self
):
649 msgs
= self
._test
_one
_comp
_from
_one
_spec
_one
_comp
_from
_both
_2(
651 'test-bonjour': 'madame',
652 'test-salut': 'les amis',
653 'what': 'test-params',
655 params_a
={'test-bonjour': 'monsieur', 'what': 'test-params'},
660 "TestSourceA: ('test-bonjour', 'monsieur'), ('test-salut', 'les amis')",
664 "TestSourceB: ('test-bonjour', 'madame'), ('test-salut', 'les amis')",
667 def test_obj_one_comp_from_one_spec_one_comp_from_both_2(self
):
668 msgs
= self
._test
_one
_comp
_from
_one
_spec
_one
_comp
_from
_both
_2(
669 params_ab
={'what': 'python-obj'},
670 params_a
={'what': 'python-obj'},
675 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: alivio")
676 self
.assertEqual(msgs
[1].stream
.name
, "TestSourceB: deore")
678 def test_log_level_one_comp_from_one_spec_one_comp_from_both_2(self
):
679 msgs
= self
._test
_one
_comp
_from
_one
_spec
_one
_comp
_from
_both
_2(
680 params_ab
={'what': 'log-level'},
681 params_a
={'what': 'log-level'},
682 logging_level_ab
=bt2
.LoggingLevel
.DEBUG
,
683 logging_level_a
=bt2
.LoggingLevel
.TRACE
,
687 msgs
[0].stream
.name
, "TestSourceA: {}".format(bt2
.LoggingLevel
.TRACE
)
690 msgs
[1].stream
.name
, "TestSourceB: {}".format(bt2
.LoggingLevel
.DEBUG
)
693 def test_obj_override_with_none(self
):
695 bt2
.AutoSourceComponentSpec(
696 self
._dir
_ab
, params
={'what': 'python-obj'}, obj
='deore'
698 bt2
.AutoSourceComponentSpec(
699 self
._dir
_a
, params
={'what': 'python-obj'}, obj
=None
702 it
= bt2
.TraceCollectionMessageIterator(specs
)
703 msgs
= [x
for x
in it
if type(x
) is bt2
._StreamBeginningMessage
]
705 self
.assertEqual(len(msgs
), 2)
706 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: None")
707 self
.assertEqual(msgs
[1].stream
.name
, "TestSourceB: deore")
709 def test_obj_no_override_with_no_obj(self
):
711 bt2
.AutoSourceComponentSpec(
712 self
._dir
_ab
, params
={'what': 'python-obj'}, obj
='deore'
714 bt2
.AutoSourceComponentSpec(self
._dir
_a
, params
={'what': 'python-obj'}),
716 it
= bt2
.TraceCollectionMessageIterator(specs
)
717 msgs
= [x
for x
in it
if type(x
) is bt2
._StreamBeginningMessage
]
719 self
.assertEqual(len(msgs
), 2)
720 self
.assertEqual(msgs
[0].stream
.name
, "TestSourceA: deore")
721 self
.assertEqual(msgs
[1].stream
.name
, "TestSourceB: deore")
724 if __name__
== '__main__':