X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_trace_collection_message_iterator.py;h=f2ddb6d03394976cd477c0510c0001d739133ec9;hp=3abbe358b5a579441139928192b4bd3e6cad26a8;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hpb=c87f23fa2be424d0e97c4ca677c738a847813acf diff --git a/tests/bindings/python/bt2/test_trace_collection_message_iterator.py b/tests/bindings/python/bt2/test_trace_collection_message_iterator.py index 3abbe358..f2ddb6d0 100644 --- a/tests/bindings/python/bt2/test_trace_collection_message_iterator.py +++ b/tests/bindings/python/bt2/test_trace_collection_message_iterator.py @@ -1,20 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only # # Copyright (C) 2019 EfficiOS Inc. # -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; only version 2 -# of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# import unittest import datetime @@ -100,7 +87,8 @@ class ComponentSpecTestCase(unittest.TestCase): def test_create_sink_from_object(self): with self.assertRaisesRegex( - TypeError, "'_SinkComponentClass' is not a source or filter component class" + TypeError, + "'_SinkComponentClassConst' is not a source or filter component class", ): bt2.ComponentSpec(self._pretty_cc) @@ -258,7 +246,7 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): msgs = list(msg_iter) self.assertEqual(len(msgs), 28) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 8) + self.assertEqual(hist[bt2._EventMessageConst], 8) # Same as the above, but we pass a single spec instead of a spec list. def test_iter_specs_not_list(self): @@ -269,7 +257,7 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): msgs = list(msg_iter) self.assertEqual(len(msgs), 28) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 8) + self.assertEqual(hist[bt2._EventMessageConst], 8) def test_iter_custom_filter(self): src_spec = bt2.ComponentSpec.from_named_plugin_and_component_class( @@ -280,7 +268,7 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): ) msg_iter = bt2.TraceCollectionMessageIterator(src_spec, flt_spec) hist = _count_msgs_by_type(msg_iter) - self.assertEqual(hist[bt2._EventMessage], 5) + self.assertEqual(hist[bt2._EventMessageConst], 5) def test_iter_intersection(self): specs = [ @@ -294,17 +282,37 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): msgs = list(msg_iter) self.assertEqual(len(msgs), 15) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 3) + self.assertEqual(hist[bt2._EventMessageConst], 3) - def test_iter_intersection_no_inputs_param(self): + def test_iter_intersection_params(self): + # Check that all params used to create the source component are passed + # to the `babeltrace.trace-infos` query. specs = [ bt2.ComponentSpec.from_named_plugin_and_component_class( - 'text', 'dmesg', {'read-from-stdin': True} + 'ctf', + 'fs', + { + 'inputs': [_3EVENTS_INTERSECT_TRACE_PATH], + 'clock-class-offset-s': 1000, + }, ) ] - with self.assertRaises(ValueError): - bt2.TraceCollectionMessageIterator(specs, stream_intersection_mode=True) + msg_iter = bt2.TraceCollectionMessageIterator( + specs, stream_intersection_mode=True + ) + + event_msgs = [x for x in msg_iter if type(x) is bt2._EventMessageConst] + self.assertEqual(len(event_msgs), 3) + self.assertEqual( + event_msgs[0].default_clock_snapshot.ns_from_origin, 13516309000000071 + ) + self.assertEqual( + event_msgs[1].default_clock_snapshot.ns_from_origin, 13516309000000072 + ) + self.assertEqual( + event_msgs[2].default_clock_snapshot.ns_from_origin, 13516309000000082 + ) def test_iter_no_intersection_two_traces(self): spec = bt2.ComponentSpec.from_named_plugin_and_component_class( @@ -315,7 +323,7 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): msgs = list(msg_iter) self.assertEqual(len(msgs), 56) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 16) + self.assertEqual(hist[bt2._EventMessageConst], 16) def test_iter_no_intersection_begin(self): specs = [ @@ -325,7 +333,7 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): ] msg_iter = bt2.TraceCollectionMessageIterator(specs, begin=13515309.000000023) hist = _count_msgs_by_type(msg_iter) - self.assertEqual(hist[bt2._EventMessage], 6) + self.assertEqual(hist[bt2._EventMessageConst], 6) def test_iter_no_intersection_end(self): specs = [ @@ -335,7 +343,7 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): ] msg_iter = bt2.TraceCollectionMessageIterator(specs, end=13515309.000000075) hist = _count_msgs_by_type(msg_iter) - self.assertEqual(hist[bt2._EventMessage], 5) + self.assertEqual(hist[bt2._EventMessageConst], 5) def test_iter_auto_source_component_spec(self): specs = [bt2.AutoSourceComponentSpec(_3EVENTS_INTERSECT_TRACE_PATH)] @@ -343,21 +351,21 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): msgs = list(msg_iter) self.assertEqual(len(msgs), 28) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 8) + self.assertEqual(hist[bt2._EventMessageConst], 8) def test_iter_auto_source_component_spec_list_of_strings(self): msg_iter = bt2.TraceCollectionMessageIterator([_3EVENTS_INTERSECT_TRACE_PATH]) msgs = list(msg_iter) self.assertEqual(len(msgs), 28) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 8) + self.assertEqual(hist[bt2._EventMessageConst], 8) def test_iter_auto_source_component_spec_string(self): msg_iter = bt2.TraceCollectionMessageIterator(_3EVENTS_INTERSECT_TRACE_PATH) msgs = list(msg_iter) self.assertEqual(len(msgs), 28) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 8) + self.assertEqual(hist[bt2._EventMessageConst], 8) def test_iter_mixed_inputs(self): msg_iter = bt2.TraceCollectionMessageIterator( @@ -372,7 +380,7 @@ class TraceCollectionMessageIteratorTestCase(unittest.TestCase): msgs = list(msg_iter) self.assertEqual(len(msgs), 76) hist = _count_msgs_by_type(msgs) - self.assertEqual(hist[bt2._EventMessage], 24) + self.assertEqual(hist[bt2._EventMessageConst], 24) def test_auto_source_component_non_existent(self): with self.assertRaisesRegex( @@ -406,7 +414,7 @@ class TestAutoDiscoverSourceComponentSpecsGrouping( bt2.AutoSourceComponentSpec(_AUTO_SOURCE_DISCOVERY_GROUPING_PATH), ] it = bt2.TraceCollectionMessageIterator(specs) - msgs = [x for x in it if type(x) is bt2._StreamBeginningMessage] + msgs = [x for x in it if type(x) is bt2._StreamBeginningMessageConst] self.assertEqual(len(msgs), 8) @@ -436,7 +444,7 @@ class TestAutoDiscoverSourceComponentSpecsParamsObjLogLevel( ) ] it = bt2.TraceCollectionMessageIterator(specs) - msgs = [x for x in it if type(x) is bt2._StreamBeginningMessage] + msgs = [x for x in it if type(x) is bt2._StreamBeginningMessageConst] self.assertEqual(len(msgs), 2) @@ -488,7 +496,7 @@ class TestAutoDiscoverSourceComponentSpecsParamsObjLogLevel( ), ] it = bt2.TraceCollectionMessageIterator(specs) - msgs = [x for x in it if type(x) is bt2._StreamBeginningMessage] + msgs = [x for x in it if type(x) is bt2._StreamBeginningMessageConst] self.assertEqual(len(msgs), 2) @@ -552,7 +560,7 @@ class TestAutoDiscoverSourceComponentSpecsParamsObjLogLevel( ), ] it = bt2.TraceCollectionMessageIterator(specs) - msgs = [x for x in it if type(x) is bt2._StreamBeginningMessage] + msgs = [x for x in it if type(x) is bt2._StreamBeginningMessageConst] self.assertEqual(len(msgs), 2) @@ -619,7 +627,7 @@ class TestAutoDiscoverSourceComponentSpecsParamsObjLogLevel( ), ] it = bt2.TraceCollectionMessageIterator(specs) - msgs = [x for x in it if type(x) is bt2._StreamBeginningMessage] + msgs = [x for x in it if type(x) is bt2._StreamBeginningMessageConst] self.assertEqual(len(msgs), 2) @@ -680,7 +688,7 @@ class TestAutoDiscoverSourceComponentSpecsParamsObjLogLevel( ), ] it = bt2.TraceCollectionMessageIterator(specs) - msgs = [x for x in it if type(x) is bt2._StreamBeginningMessage] + msgs = [x for x in it if type(x) is bt2._StreamBeginningMessageConst] self.assertEqual(len(msgs), 2) self.assertEqual(msgs[0].stream.name, "TestSourceA: None") @@ -694,7 +702,7 @@ class TestAutoDiscoverSourceComponentSpecsParamsObjLogLevel( bt2.AutoSourceComponentSpec(self._dir_a, params={'what': 'python-obj'}), ] it = bt2.TraceCollectionMessageIterator(specs) - msgs = [x for x in it if type(x) is bt2._StreamBeginningMessage] + msgs = [x for x in it if type(x) is bt2._StreamBeginningMessageConst] self.assertEqual(len(msgs), 2) self.assertEqual(msgs[0].stream.name, "TestSourceA: deore")