Tests babeltrace: adapt python tests to use unittest
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 17 Sep 2017 22:01:03 +0000 (18:01 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 18 Sep 2017 19:56:03 +0000 (15:56 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
16 files changed:
configure.ac
tests/bindings/python/babeltrace/.gitignore [new file with mode: 0644]
tests/bindings/python/babeltrace/Makefile.am
tests/bindings/python/babeltrace/test_ctf_writer_empty_packet.py [new file with mode: 0644]
tests/bindings/python/babeltrace/test_ctf_writer_no_packet_context.py [new file with mode: 0644]
tests/bindings/python/babeltrace/test_python_babeltrace [deleted file]
tests/bindings/python/babeltrace/test_python_babeltrace.in
tests/bindings/python/babeltrace/test_reader_trace_intersection.py [new file with mode: 0644]
tests/cli/intersection/Makefile.am
tests/cli/intersection/bt_python_helper.py.in [deleted file]
tests/cli/intersection/test_multi_trace_intersection.py [deleted file]
tests/lib/Makefile.am
tests/lib/writer/Makefile.am [deleted file]
tests/lib/writer/bt_python_helper.py.in [deleted file]
tests/lib/writer/test_ctf_writer_empty_packet.py.in [deleted file]
tests/lib/writer/test_ctf_writer_no_packet_context.py.in [deleted file]

index da6a5980cf0ef1d0cba01b1ee070537eebacf15f..640cc8f57d0610a893e21905b7ebac9e35c57750 100644 (file)
@@ -671,7 +671,6 @@ AC_CONFIG_FILES([
        tests/cli/Makefile
        tests/cli/intersection/Makefile
        tests/lib/Makefile
-       tests/lib/writer/Makefile
        tests/lib/test-plugin-plugins/Makefile
        tests/utils/common.sh
        tests/utils/Makefile
@@ -709,7 +708,6 @@ AC_CONFIG_FILES([
        babeltrace-ctf.pc
 ])
 
-AC_CONFIG_FILES([tests/cli/intersection/bt_python_helper.py])
 AC_CONFIG_FILES([tests/cli/intersection/test_intersection], [chmod +x tests/cli/intersection/test_intersection])
 AC_CONFIG_FILES([tests/cli/test_convert_args], [chmod +x tests/cli/test_convert_args])
 AC_CONFIG_FILES([tests/cli/test_debug_info], [chmod +x tests/cli/test_debug_info])
@@ -719,9 +717,6 @@ AC_CONFIG_FILES([tests/cli/test_trace_read], [chmod +x tests/cli/test_trace_read
 AC_CONFIG_FILES([tests/cli/test_trimmer], [chmod +x tests/cli/test_trimmer])
 AC_CONFIG_FILES([tests/lib/test_ctf_writer_complete], [chmod +x tests/lib/test_ctf_writer_complete])
 AC_CONFIG_FILES([tests/lib/test_plugin_complete], [chmod +x tests/lib/test_plugin_complete])
-AC_CONFIG_FILES([tests/lib/writer/bt_python_helper.py])
-AC_CONFIG_FILES([tests/lib/writer/test_ctf_writer_empty_packet.py])
-AC_CONFIG_FILES([tests/lib/writer/test_ctf_writer_no_packet_context.py])
 AC_CONFIG_FILES([tests/plugins/test-utils-muxer-complete], [chmod +x tests/plugins/test-utils-muxer-complete])
 AC_CONFIG_FILES([tests/plugins/test_dwarf_complete], [chmod +x tests/plugins/test_dwarf_complete])
 AC_CONFIG_FILES([tests/plugins/test_bin_info_complete], [chmod +x tests/plugins/test_bin_info_complete])
diff --git a/tests/bindings/python/babeltrace/.gitignore b/tests/bindings/python/babeltrace/.gitignore
new file mode 100644 (file)
index 0000000..530df6e
--- /dev/null
@@ -0,0 +1,3 @@
+htmlcov
+.coverage
+test_python_babeltrace
index 6111cb9887e1b9ea9d3b2d8648880e6985202336..7303d1cacf9f6762f1e933b13da34cf30a4cad59 100644 (file)
@@ -1,4 +1,7 @@
 EXTRA_DIST =                                   \
        test_reader_event.py                    \
        test_reader_event_declaration.py        \
-       test_reader_field_declaration.py
+       test_reader_field_declaration.py        \
+       test_ctf_writer_empty_packet.py         \
+       test_ctf_writer_no_packet_context.py    \
+       test_reader_trace_intersection.py
diff --git a/tests/bindings/python/babeltrace/test_ctf_writer_empty_packet.py b/tests/bindings/python/babeltrace/test_ctf_writer_empty_packet.py
new file mode 100644 (file)
index 0000000..f62d9ae
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/env python3
+#
+# The MIT License (MIT)
+#
+# Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# 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 CtfWriterEmptyPacketTestCase(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 i in range(self._expected_event_count):
+            event = btw.Event(event_class)
+            event.payload('int_field').value = i
+            stream.append_event(event)
+        stream.flush()
+
+        # The CTF writer will not be able to populate the packet context's
+        # timestamp_begin and timestamp_end fields if it is asked to flush
+        # without any queued events.
+        with self.assertRaises(ValueError):
+            stream.flush()
+
+        packet_context = stream.packet_context
+        packet_context.field('timestamp_begin').value = 1
+        packet_context.field('timestamp_end').value = 123456
+
+        stream.flush()
+
+    def test_trace_empty_packet(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)
diff --git a/tests/bindings/python/babeltrace/test_ctf_writer_no_packet_context.py b/tests/bindings/python/babeltrace/test_ctf_writer_no_packet_context.py
new file mode 100644 (file)
index 0000000..fb7b8bd
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+#
+# The MIT License (MIT)
+#
+# Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# 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 CtfWriterNoPacketContextTestCase(unittest.TestCase):
+    def setUp(self):
+        self._expected_event_count = 100
+        self._trace_path = tempfile.mkdtemp()
+
+    def tearDown(self):
+        shutil.rmtree(self._trace_path)
+
+    def _write_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('test_stream')
+        stream_class.add_event_class(event_class)
+        stream_class.clock = clock
+
+        stream_class.packet_context_type = None
+        stream = trace.create_stream(stream_class)
+
+        for i in range(self._expected_event_count):
+            event = btw.Event(event_class)
+            event.payload('int_field').value = i
+            stream.append_event(event)
+        stream.flush()
+
+        # It is not valid for a stream to contain more than one packet
+        # if it does not have content_size/packet_size info in its packet
+        # context
+        event = btw.Event(event_class)
+        event.payload('int_field').value = 42
+        stream.append_event(event)
+
+        flush_raises = False
+        try:
+            stream.flush()
+        except ValueError:
+            flush_raises = True
+        self.assertTrue(flush_raises)
+        trace.flush_metadata()
+
+    def test_trace_no_packet_context(self):
+        self._write_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)
diff --git a/tests/bindings/python/babeltrace/test_python_babeltrace b/tests/bindings/python/babeltrace/test_python_babeltrace
deleted file mode 100755 (executable)
index bcf0df4..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2017 - Philippe Proulx <pproulx@efficios.com>
-#               2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# 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.
-#
-
-NO_SH_TAP=1
-. "/home/jgalar/EfficiOS/src/babeltrace/tests/utils/common.sh"
-
-check_coverage() {
-       coverage run "$@"
-}
-
-export BABELTRACE_PYTHON_BT2_NO_TRACEBACK=1
-export TEST_PLUGIN_PLUGINS_PATH="${BT_BUILD_PATH}/plugins"
-export BABELTRACE_PLUGIN_PATH="${BT_BUILD_PATH}/plugins/ctf:${BT_BUILD_PATH}/plugins/utils:${BT_BUILD_PATH}/plugins/text"
-export LD_LIBRARY_PATH="${BT_BUILD_PATH}/lib/.libs"
-PYTHON_BUILD_DIR="${BT_BUILD_PATH}/bindings/python/bt2/build/build_lib:${BT_BUILD_PATH}/bindings/python/babeltrace/build/build_lib"
-TESTS_UTILS_PYTHON_DIR="${BT_SRC_PATH}/tests/utils/python"
-TESTS_CTF_TRACES="${BT_SRC_PATH}/tests/ctf-traces"
-TESTRUNNER_PY="${BT_SRC_PATH}/tests/utils/python/testrunner.py"
-THIS_DIR="${BT_SRC_PATH}/tests/bindings/python/babeltrace"
-
-if test "x$TESTALL_COVERAGE" = "x1"; then
-       EXEC=check_coverage
-else
-       EXEC="/usr/bin/python"
-
-fi
-
-PYTHONPATH="$PYTHON_BUILD_DIR:$TESTS_UTILS_PYTHON_DIR" \
-       "$EXEC" "$TESTRUNNER_PY" "$THIS_DIR"
-res=$?
-
-if test "x$TESTALL_COVERAGE_REPORT" = "x1"; then
-       coverage report -m
-fi
-
-if test "x$TESTALL_COVERAGE_HTML" = "x1"; then
-       coverage html
-fi
-
-exit $res
index fec9e033edf54fea7655d089821ea49f580b13be..9bce63f614469b405f2e11a2fe209b22b9a209c0 100644 (file)
@@ -29,6 +29,7 @@ export BABELTRACE_PYTHON_BT2_NO_TRACEBACK=1
 export TEST_PLUGIN_PLUGINS_PATH="${BT_BUILD_PATH}/plugins"
 export BABELTRACE_PLUGIN_PATH="${BT_BUILD_PATH}/plugins/ctf:${BT_BUILD_PATH}/plugins/utils:${BT_BUILD_PATH}/plugins/text"
 export LD_LIBRARY_PATH="${BT_BUILD_PATH}/lib/.libs"
+export TEST_CTF_TRACES_PATH="${BT_BUILD_PATH}/tests/ctf-traces"
 PYTHON_BUILD_DIR="${BT_BUILD_PATH}/bindings/python/bt2/build/build_lib:${BT_BUILD_PATH}/bindings/python/babeltrace/build/build_lib"
 TESTS_UTILS_PYTHON_DIR="${BT_SRC_PATH}/tests/utils/python"
 TESTS_CTF_TRACES="${BT_SRC_PATH}/tests/ctf-traces"
diff --git a/tests/bindings/python/babeltrace/test_reader_trace_intersection.py b/tests/bindings/python/babeltrace/test_reader_trace_intersection.py
new file mode 100644 (file)
index 0000000..250d6c2
--- /dev/null
@@ -0,0 +1,147 @@
+#!/usr/bin/env python3
+#
+# The MIT License (MIT)
+#
+# Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+#
+# 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 uuid
+import shutil
+import unittest
+
+class Entry(object):
+    def __init__(self, stream_id, timestamp=None, end_of_packet=False):
+        self.stream_id = stream_id
+        self.timestamp = timestamp
+        self.end_of_packet = end_of_packet
+
+
+class Packet(object):
+    def __init__(self, timestamps):
+        self.timestamps = timestamps
+
+
+class TraceIntersectionTestCase(unittest.TestCase):
+    def _create_trace(self, stream_descriptions):
+        trace_path = tempfile.mkdtemp()
+        trace = btw.Writer(trace_path)
+        clock = btw.Clock('test_clock')
+        clock.uuid = self._clock_uuid
+        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('test_stream')
+        stream_class.add_event_class(event_class)
+        stream_class.clock = clock
+
+        streams = []
+        stream_entries = []
+        for stream_id, stream_packets in enumerate(stream_descriptions):
+            stream = trace.create_stream(stream_class)
+            streams.append(stream)
+
+            for packet in stream_packets:
+                for timestamp in packet.timestamps:
+                    stream_entries.append(Entry(stream_id, timestamp))
+                # Mark the last inserted entry as the end of packet
+                stream_entries[len(stream_entries) - 1].end_of_packet = True
+
+        # Sort stream entries which will provide us with a time-ordered list of
+        # events to insert in the streams.
+        for entry in sorted(stream_entries, key=lambda entry: entry.timestamp):
+            clock.time = entry.timestamp
+            event = btw.Event(event_class)
+            event.payload('int_field').value = entry.stream_id
+            streams[entry.stream_id].append_event(event)
+            if entry.end_of_packet is True:
+                streams[entry.stream_id].flush()
+
+        return trace_path
+
+    def setUp(self):
+        self._clock_uuid = uuid.uuid4()
+        self._trace_path_early = self._create_trace(
+            [
+                [Packet(range(1, 7)), Packet(range(11, 18))],
+                [Packet(range(8, 15)), Packet(range(22, 24)), Packet(range(30, 60))],
+                [Packet(range(11, 14))]
+            ]
+        )
+        self._trace_path_late = self._create_trace(
+            [
+                [Packet(range(100, 105)), Packet(range(109, 120))],
+                [Packet(range(88, 95)), Packet(range(96, 110)), Packet(range(112, 140))],
+                [Packet(range(99, 105))]
+            ]
+        )
+
+        self._expected_timestamps_early = []
+        for ts in range(11, 14):
+            for stream in range(3):
+                self._expected_timestamps_early.append(ts)
+
+        self._expected_timestamps_late = []
+        for ts in range(100, 105):
+            for stream in range(3):
+                self._expected_timestamps_late.append(ts)
+
+        self._expected_timestamps_union = (self._expected_timestamps_early +
+                                           self._expected_timestamps_late)
+
+    def tearDown(self):
+        shutil.rmtree(self._trace_path_early)
+        shutil.rmtree(self._trace_path_late)
+        pass
+
+    @staticmethod
+    def _check_trace_expected_timestamps(trace_paths, expected_timestamps):
+        traces = btr.TraceCollection(intersect_mode=True)
+        for trace_path in trace_paths:
+            trace_handle = traces.add_trace(trace_path, 'ctf')
+            if trace_handle is None:
+                print('# Failed to open trace at {}'.format(trace_path))
+                return False
+        for event in traces.events:
+            expected_timestamp = expected_timestamps.pop(0)
+            if event.timestamp != expected_timestamp:
+                print('# Unexpected timestamp ({}), expected {}'.format(
+                    event.timestamp, expected_timestamp))
+                return False
+        return True
+
+    def test_trace_early(self):
+        self._check_trace_expected_timestamps([self._trace_path_early],
+                                              self._expected_timestamps_early)
+
+    def test_trace_late(self):
+        self._check_trace_expected_timestamps([self._trace_path_late],
+                                              self._expected_timestamps_late)
+
+    def test_trace_intersection(self):
+        self._check_trace_expected_timestamps([self._trace_path_early,
+                                               self._trace_path_late],
+                                              self._expected_timestamps_union)
index 6c7330e58fc367326f7b4834ccfd1a500c2521c2..efbe74a182802aa6fc2f6d23bb247022cc75014e 100644 (file)
@@ -1,9 +1,4 @@
-check_SCRIPTS = test_intersection \
-               bt_python_helper.py \
-               test_multi_trace_intersection.py
-
-dist_noinst_SCRIPTS = test_multi_trace_intersection.py
-EXTRA_DIST=test_multi_trace_intersection.py
+check_SCRIPTS = test_intersection
 
 all-local:
        @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
diff --git a/tests/cli/intersection/bt_python_helper.py.in b/tests/cli/intersection/bt_python_helper.py.in
deleted file mode 100644 (file)
index 4b9fcaf..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python3
-#
-# The MIT License (MIT)
-#
-# Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# 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 sys
-
-# Point the Python interpreter to the builddir's library and Babeltrace
-# bindings
-bt_module_path = '@abs_top_builddir@/bindings/python'
-bt_lib_py_path = '@abs_top_builddir@/bindings/python/babeltrace/.libs'
-bt_lib_bt_path = '@abs_top_builddir@/lib/.libs'
-bt_lib_ctf_path = '@abs_top_builddir@/format/ctf/.libs'
-
-sys.path.insert(0, bt_module_path)
-sys.path.insert(1, bt_lib_py_path)
-sys.path.insert(2, bt_lib_bt_path)
-sys.path.insert(3, bt_lib_ctf_path)
diff --git a/tests/cli/intersection/test_multi_trace_intersection.py b/tests/cli/intersection/test_multi_trace_intersection.py
deleted file mode 100755 (executable)
index b4368a1..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env python3
-#
-# The MIT License (MIT)
-#
-# Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# 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 bt_python_helper
-import tempfile
-import babeltrace.writer as btw
-import babeltrace.reader as btr
-import uuid
-import shutil
-
-
-class Entry(object):
-    def __init__(self, stream_id, timestamp=None, end_of_packet=False):
-        self.stream_id = stream_id
-        self.timestamp = timestamp
-        self.end_of_packet = end_of_packet
-
-
-class Packet(object):
-    def __init__(self, timestamps):
-        self.timestamps = timestamps
-
-clock_uuid = uuid.uuid4()
-
-# stream_descriptions is a list of lists of Packets.
-# Each stream description list is mapped to a single stream instance.
-def create_trace(path, clock_uuid, stream_descriptions):
-    trace = btw.Writer(path)
-    clock = btw.Clock('test_clock')
-    clock.uuid = clock_uuid
-    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('test_stream')
-    stream_class.add_event_class(event_class)
-    stream_class.clock = clock
-
-    streams = []
-    stream_entries = []
-    for stream_id, stream_packets in enumerate(stream_descriptions):
-        stream = trace.create_stream(stream_class)
-        streams.append(stream)
-
-        for packet in stream_packets:
-            for timestamp in packet.timestamps:
-                stream_entries.append(Entry(stream_id, timestamp))
-            # Mark the last inserted entry as the end of packet
-            stream_entries[len(stream_entries) - 1].end_of_packet = True
-
-    # Sort stream entries which will provide us with a time-ordered list of
-    # events to insert in the streams.
-    for entry in sorted(stream_entries, key=lambda entry: entry.timestamp):
-        clock.time = entry.timestamp
-        event = btw.Event(event_class)
-        event.payload('int_field').value = entry.stream_id
-        streams[entry.stream_id].append_event(event)
-        if entry.end_of_packet is True:
-            streams[entry.stream_id].flush()
-
-
-def check_trace_expected_timestamps(trace_paths, expected_timestamps):
-    traces = btr.TraceCollection(intersect_mode=True)
-    for trace_path in trace_paths:
-        trace_handle = traces.add_trace(trace_path, 'ctf')
-        if trace_handle is None:
-            print('Failed to open trace at {}'.format(trace_path))
-            return False
-    for event in traces.events:
-        expected_timestamp = expected_timestamps.pop(0)
-        if event.timestamp != expected_timestamp:
-            print('# Unexpected timestamp ({}), expected {}'.format(
-                event.timestamp, expected_timestamp))
-            return False
-    return True
-
-
-def print_test_result(test_number, result, description):
-    result_string = 'ok' if result else 'not ok'
-    result_string += ' {} - {}'.format(test_number, description)
-    print(result_string)
-
-TEST_COUNT = 3
-# TAP plan
-print('1..{}'.format(TEST_COUNT))
-
-trace_path_early = tempfile.mkdtemp()
-
-# The stream intersection of this trace is event timestamps 11, 12 and 13,
-# accounting for 9 events in stream-intersection mode
-print('# Creating early trace at {}'.format(trace_path_early))
-create_trace(trace_path_early, clock_uuid, [
-    [Packet(range(1, 7)), Packet(range(11, 18))],
-    [Packet(range(8, 15)), Packet(range(22, 24)), Packet(range(30, 60))],
-    [Packet(range(11, 14))]
-    ])
-
-trace_path_late = tempfile.mkdtemp()
-print('# Creating late trace at {}'.format(trace_path_late))
-# The stream intersection of this trace is event timestamps 100, 101, 102, 103
-# and 104 accounting for 15 events in stream-intersection mode
-create_trace(trace_path_late, clock_uuid, [
-    [Packet(range(100, 105)), Packet(range(109, 120))],
-    [Packet(range(88, 95)), Packet(range(96, 110)), Packet(range(112, 140))],
-    [Packet(range(99, 105))]
-    ])
-
-expected_timestamps_early = []
-for ts in range(11, 14):
-    for stream in range(3):
-        expected_timestamps_early.append(ts)
-
-expected_timestamps_late = []
-for ts in range(100, 105):
-    for stream in range(3):
-        expected_timestamps_late.append(ts)
-
-expected_timestamps_union = (expected_timestamps_early +
-                            expected_timestamps_late)
-
-# Validate that the stream-intersection mode on a single trace returns only
-# the events that are in overlapping packets across all of the trace's streams.
-result = check_trace_expected_timestamps([trace_path_early],
-                                            expected_timestamps_early)
-print_test_result(1, result, 'Validating expected event timestamps of "early" trace')
-
-result = check_trace_expected_timestamps([trace_path_late],
-                                            expected_timestamps_late)
-print_test_result(2, result, 'Validating expected event timestamps of "late" trace')
-
-result = check_trace_expected_timestamps([trace_path_early, trace_path_late],
-                                            expected_timestamps_union)
-print_test_result(3, result, 'Validating expected event timestamps of the union of "early" and "late" traces')
-
-shutil.rmtree(trace_path_early)
-shutil.rmtree(trace_path_late)
index f4dc0813023c609db151b6ef2bd87b66da521fc4..9e20545d124a0f2e5d82c44308391393b6f1416e 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = writer .
+SUBDIRS=
 
 AM_CPPFLAGS += -I$(top_srcdir)/tests/utils
 
diff --git a/tests/lib/writer/Makefile.am b/tests/lib/writer/Makefile.am
deleted file mode 100644 (file)
index 3d3a320..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-check_SCRIPTS = test_ctf_writer_no_packet_context.py \
-       test_ctf_writer_empty_packet.py
diff --git a/tests/lib/writer/bt_python_helper.py.in b/tests/lib/writer/bt_python_helper.py.in
deleted file mode 100644 (file)
index 4b9fcaf..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python3
-#
-# The MIT License (MIT)
-#
-# Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# 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 sys
-
-# Point the Python interpreter to the builddir's library and Babeltrace
-# bindings
-bt_module_path = '@abs_top_builddir@/bindings/python'
-bt_lib_py_path = '@abs_top_builddir@/bindings/python/babeltrace/.libs'
-bt_lib_bt_path = '@abs_top_builddir@/lib/.libs'
-bt_lib_ctf_path = '@abs_top_builddir@/format/ctf/.libs'
-
-sys.path.insert(0, bt_module_path)
-sys.path.insert(1, bt_lib_py_path)
-sys.path.insert(2, bt_lib_bt_path)
-sys.path.insert(3, bt_lib_ctf_path)
diff --git a/tests/lib/writer/test_ctf_writer_empty_packet.py.in b/tests/lib/writer/test_ctf_writer_empty_packet.py.in
deleted file mode 100644 (file)
index c5b6acb..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/usr/bin/env python3
-#
-# The MIT License (MIT)
-#
-# Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# 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 bt_python_helper
-import tempfile
-import babeltrace.writer as btw
-import babeltrace.reader as btr
-import shutil
-import uuid
-
-TEST_COUNT = 4
-EXPECTED_EVENT_COUNT = 10
-trace_path = tempfile.mkdtemp()
-
-
-def print_test_result(test_number, result, description):
-        result_string = 'ok' if result else 'not ok'
-        result_string += ' {} - {}'.format(test_number, description)
-        print(result_string)
-
-def create_trace(path):
-        trace = btw.Writer(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 i in range(EXPECTED_EVENT_COUNT):
-                event = btw.Event(event_class)
-                event.payload('int_field').value = i
-                stream.append_event(event)
-        stream.flush()
-        print_test_result(1, True,
-                          'Flush a packet containing {} events'.format(EXPECTED_EVENT_COUNT))
-
-        # The CTF writer will not be able to populate the packet context's
-        # timestamp_begin and timestamp_end fields if it is asked to flush
-        # without any queued events.
-        try:
-            stream.flush()
-            empty_flush_succeeded = True
-        except ValueError:
-            empty_flush_succeeded = False
-
-        print_test_result(2, not empty_flush_succeeded,
-                          'Flushing an empty packet without explicitly setting packet time bounds should fail')
-        packet_context = stream.packet_context
-        packet_context.field('timestamp_begin').value = 1
-        packet_context.field('timestamp_end').value = 123456
-        try:
-            stream.flush()
-            empty_flush_succeeded = True
-        except ValueError:
-            empty_flush_succeeded = False
-
-        print_test_result(3, empty_flush_succeeded,
-                          'Flushing an empty packet after explicitly setting packet time bounds should succeed')
-
-
-# TAP plan
-print('1..{}'.format(TEST_COUNT))
-print('# Creating trace at {}'.format(trace_path))
-create_trace(trace_path)
-
-traces = btr.TraceCollection()
-trace_handle = traces.add_trace(trace_path, 'ctf')
-if trace_handle is None:
-        print('Failed to open trace at {}'.format(trace_path))
-
-event_count = 0
-for event in traces.events:
-        event_count += 1
-
-print_test_result(4, EXPECTED_EVENT_COUNT == event_count,
-                  'Trace was found to contain {} events, expected {}'.format(
-                   event_count, EXPECTED_EVENT_COUNT))
-
-shutil.rmtree(trace_path)
diff --git a/tests/lib/writer/test_ctf_writer_no_packet_context.py.in b/tests/lib/writer/test_ctf_writer_no_packet_context.py.in
deleted file mode 100644 (file)
index 8d9a7a7..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/usr/bin/env python3
-#
-# The MIT License (MIT)
-#
-# Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
-#
-# 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 bt_python_helper
-import tempfile
-import babeltrace.writer as btw
-import babeltrace.reader as btr
-import shutil
-import uuid
-
-TEST_COUNT = 4
-EXPECTED_EVENT_COUNT = 10
-trace_path = tempfile.mkdtemp()
-
-
-def print_test_result(test_number, result, description):
-        result_string = 'ok' if result else 'not ok'
-        result_string += ' {} - {}'.format(test_number, description)
-        print(result_string)
-
-def create_trace(path):
-        trace = btw.Writer(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('test_stream')
-        stream_class.add_event_class(event_class)
-        stream_class.clock = clock
-
-        stream_class.packet_context_type = None
-        print_test_result(1, stream_class.packet_context_type is None,
-                          'Set stream class packet context type to None')
-
-        stream = trace.create_stream(stream_class)
-
-        for i in range(EXPECTED_EVENT_COUNT):
-                event = btw.Event(event_class)
-                event.payload('int_field').value = i
-                stream.append_event(event)
-        stream.flush()
-        print_test_result(2, True,
-                          'Flush a packet')
-
-        # It is not valid for a stream to contain more than one packet
-        # if it does not have content_size/packet_size info in its packet
-        # context
-        event = btw.Event(event_class)
-        event.payload('int_field').value = 42
-        stream.append_event(event)
-        try:
-            stream.flush()
-            second_flush_succeeded = True
-        except ValueError:
-            second_flush_succeeded = False
-
-        print_test_result(3, not second_flush_succeeded,
-                          'Flushing a second packet in a stream without a defined packet context fails')
-
-
-# TAP plan
-print('1..{}'.format(TEST_COUNT))
-print('# Creating trace at {}'.format(trace_path))
-create_trace(trace_path)
-
-traces = btr.TraceCollection()
-trace_handle = traces.add_trace(trace_path, 'ctf')
-if trace_handle is None:
-        print('Failed to open trace at {}'.format(trace_path))
-
-event_count = 0
-for event in traces.events:
-        event_count += 1
-
-print_test_result(4, EXPECTED_EVENT_COUNT == event_count,
-                  'Trace was found to contain {} events, expected {}'.format(
-                   event_count, EXPECTED_EVENT_COUNT))
-
-shutil.rmtree(trace_path)
This page took 0.036238 seconds and 4 git commands to generate.