From 295f45813164f58d40e4b98ceba9182b691be83b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 17 Sep 2017 18:01:03 -0400 Subject: [PATCH] Tests babeltrace: adapt python tests to use unittest MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- configure.ac | 5 - tests/bindings/python/babeltrace/.gitignore | 3 + tests/bindings/python/babeltrace/Makefile.am | 5 +- .../test_ctf_writer_empty_packet.py} | 70 +++----- .../test_ctf_writer_no_packet_context.py} | 73 +++----- .../python/babeltrace/test_python_babeltrace | 57 ------- .../babeltrace/test_python_babeltrace.in | 1 + .../test_reader_trace_intersection.py | 147 ++++++++++++++++ tests/cli/intersection/Makefile.am | 7 +- tests/cli/intersection/bt_python_helper.py.in | 37 ---- .../test_multi_trace_intersection.py | 160 ------------------ tests/lib/Makefile.am | 2 +- tests/lib/writer/Makefile.am | 2 - tests/lib/writer/bt_python_helper.py.in | 37 ---- 14 files changed, 206 insertions(+), 400 deletions(-) create mode 100644 tests/bindings/python/babeltrace/.gitignore rename tests/{lib/writer/test_ctf_writer_empty_packet.py.in => bindings/python/babeltrace/test_ctf_writer_empty_packet.py} (53%) rename tests/{lib/writer/test_ctf_writer_no_packet_context.py.in => bindings/python/babeltrace/test_ctf_writer_no_packet_context.py} (57%) delete mode 100755 tests/bindings/python/babeltrace/test_python_babeltrace create mode 100644 tests/bindings/python/babeltrace/test_reader_trace_intersection.py delete mode 100644 tests/cli/intersection/bt_python_helper.py.in delete mode 100755 tests/cli/intersection/test_multi_trace_intersection.py delete mode 100644 tests/lib/writer/Makefile.am delete mode 100644 tests/lib/writer/bt_python_helper.py.in diff --git a/configure.ac b/configure.ac index 137582ec..6bfbd69f 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 00000000..530df6e2 --- /dev/null +++ b/tests/bindings/python/babeltrace/.gitignore @@ -0,0 +1,3 @@ +htmlcov +.coverage +test_python_babeltrace diff --git a/tests/bindings/python/babeltrace/Makefile.am b/tests/bindings/python/babeltrace/Makefile.am index 6111cb98..7303d1ca 100644 --- a/tests/bindings/python/babeltrace/Makefile.am +++ b/tests/bindings/python/babeltrace/Makefile.am @@ -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/lib/writer/test_ctf_writer_empty_packet.py.in b/tests/bindings/python/babeltrace/test_ctf_writer_empty_packet.py similarity index 53% rename from tests/lib/writer/test_ctf_writer_empty_packet.py.in rename to tests/bindings/python/babeltrace/test_ctf_writer_empty_packet.py index c5b6acb4..f62d9ae0 100644 --- a/tests/lib/writer/test_ctf_writer_empty_packet.py.in +++ b/tests/bindings/python/babeltrace/test_ctf_writer_empty_packet.py @@ -22,25 +22,23 @@ # 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 +import unittest -TEST_COUNT = 4 -EXPECTED_EVENT_COUNT = 10 -trace_path = tempfile.mkdtemp() +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 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) + def _create_trace(self): + trace = btw.Writer(self._trace_path) clock = btw.Clock('test_clock') trace.add_clock(clock) @@ -55,54 +53,30 @@ def create_trace(path): 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) + 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() - 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: + with self.assertRaises(ValueError): 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') + stream.flush() -# 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 + def test_trace_empty_packet(self): + self._create_trace() -print_test_result(4, EXPECTED_EVENT_COUNT == event_count, - 'Trace was found to contain {} events, expected {}'.format( - event_count, EXPECTED_EVENT_COUNT)) + traces = btr.TraceCollection() + trace_handle = traces.add_trace(self._trace_path, 'ctf') + self.assertIsNotNone(trace_handle) -shutil.rmtree(trace_path) + event_count = sum(1 for event in traces.events) + self.assertEqual(self._expected_event_count, event_count) diff --git a/tests/lib/writer/test_ctf_writer_no_packet_context.py.in b/tests/bindings/python/babeltrace/test_ctf_writer_no_packet_context.py similarity index 57% rename from tests/lib/writer/test_ctf_writer_no_packet_context.py.in rename to tests/bindings/python/babeltrace/test_ctf_writer_no_packet_context.py index 8d9a7a71..fb7b8bd0 100644 --- a/tests/lib/writer/test_ctf_writer_no_packet_context.py.in +++ b/tests/bindings/python/babeltrace/test_ctf_writer_no_packet_context.py @@ -22,25 +22,23 @@ # 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 +import unittest -TEST_COUNT = 4 -EXPECTED_EVENT_COUNT = 10 -trace_path = tempfile.mkdtemp() +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 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) + def _write_trace(self): + trace = btw.Writer(self._trace_path) clock = btw.Clock('test_clock') trace.add_clock(clock) @@ -54,18 +52,13 @@ def create_trace(path): 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) + 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() - 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 @@ -73,32 +66,20 @@ def create_trace(path): event = btw.Event(event_class) event.payload('int_field').value = 42 stream.append_event(event) + + flush_raises = False 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) + 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 index bcf0df4a..00000000 --- a/tests/bindings/python/babeltrace/test_python_babeltrace +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2017 - Philippe Proulx -# 2017 - Jérémie Galarneau -# -# 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 diff --git a/tests/bindings/python/babeltrace/test_python_babeltrace.in b/tests/bindings/python/babeltrace/test_python_babeltrace.in index fec9e033..9bce63f6 100644 --- a/tests/bindings/python/babeltrace/test_python_babeltrace.in +++ b/tests/bindings/python/babeltrace/test_python_babeltrace.in @@ -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 index 00000000..250d6c23 --- /dev/null +++ b/tests/bindings/python/babeltrace/test_reader_trace_intersection.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# +# The MIT License (MIT) +# +# Copyright (C) 2016 - 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 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) diff --git a/tests/cli/intersection/Makefile.am b/tests/cli/intersection/Makefile.am index 6c7330e5..efbe74a1 100644 --- a/tests/cli/intersection/Makefile.am +++ b/tests/cli/intersection/Makefile.am @@ -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 index 4b9fcaf7..00000000 --- a/tests/cli/intersection/bt_python_helper.py.in +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python3 -# -# The MIT License (MIT) -# -# Copyright (C) 2016 - 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 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 index b4368a11..00000000 --- a/tests/cli/intersection/test_multi_trace_intersection.py +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env python3 -# -# The MIT License (MIT) -# -# Copyright (C) 2016 - 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 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) diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index f4dc0813..9e20545d 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -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 index 3d3a320a..00000000 --- a/tests/lib/writer/Makefile.am +++ /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 index 4b9fcaf7..00000000 --- a/tests/lib/writer/bt_python_helper.py.in +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python3 -# -# The MIT License (MIT) -# -# Copyright (C) 2016 - 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 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) -- 2.34.1