From: Philippe Proulx Date: Thu, 9 Nov 2017 17:38:40 +0000 (-0500) Subject: Add bindings/python/babeltrace/test_ctf_writer.py test X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=d5cb339b7bc8f622cacbafc57dfb47d9f805711e Add bindings/python/babeltrace/test_ctf_writer.py test This test ensures that we can use the legacy Python bindings to create a CTF trace without caring about timestamp fields (they should be automatically updated from the stream's class's clock value). Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/tests/bindings/python/babeltrace/test_ctf_writer.py b/tests/bindings/python/babeltrace/test_ctf_writer.py new file mode 100644 index 00000000..e5096c7c --- /dev/null +++ b/tests/bindings/python/babeltrace/test_ctf_writer.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +# +# The MIT License (MIT) +# +# Copyright (C) 2017 - Jérémie Galarneau +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import tempfile +import babeltrace.writer as btw +import babeltrace.reader as btr +import shutil +import uuid +import unittest + +class CtfWriterTestCase(unittest.TestCase): + def setUp(self): + self._expected_event_count = 100 + self._trace_path = tempfile.mkdtemp() + + def tearDown(self): + shutil.rmtree(self._trace_path) + + def _create_trace(self): + trace = btw.Writer(self._trace_path) + clock = btw.Clock('test_clock') + trace.add_clock(clock) + + integer_field_type = btw.IntegerFieldDeclaration(32) + + event_class = btw.EventClass('simple_event') + event_class.add_field(integer_field_type, 'int_field') + + stream_class = btw.StreamClass('empty_packet_stream') + stream_class.add_event_class(event_class) + stream_class.clock = clock + + stream = trace.create_stream(stream_class) + + for j in range(2): + for i in range(self._expected_event_count // 2): + val = i * (j + 1) + clock.time = val * 200 + event = btw.Event(event_class) + event.payload('int_field').value = val + stream.append_event(event) + + stream.flush() + + def test_writer(self): + self._create_trace() + + traces = btr.TraceCollection() + trace_handle = traces.add_trace(self._trace_path, 'ctf') + self.assertIsNotNone(trace_handle) + + event_count = sum(1 for event in traces.events) + self.assertEqual(self._expected_event_count, event_count) + + self.assertEqual(traces.timestamp_begin, 0) + self.assertEqual(traces.timestamp_end, 19600)