From: Philippe Proulx Date: Fri, 22 Dec 2017 00:00:31 +0000 (-0500) Subject: Add test: no clock class in trace's packet header field type X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=1805e0b4b91b339a131f2463e241b706cad5a56f Add test: no clock class in trace's packet header field type This patch adds a test case which uses the Python bindings to test that it is not possible to set a trace's packet header field type containing an integer field type mapped to a clock class. The new tests/lib/ctf-ir directory is set so that future CTF IR test cases can be added easily if need be instead of going to tests/lib/test_ctf_writer.c. Signed-off-by: Philippe Proulx --- diff --git a/.gitignore b/.gitignore index edcf8edc..50a47ad7 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ /tests/lib/test_bt_notification_iterator /tests/lib/test_cc_prio_map /tests/lib/test_graph_topo +/tests/lib/ctf-ir/test_ctf_ir /tests/plugins/test-utils-muxer /tests/plugins/test-utils-muxer-complete /tests/plugins/test_lttng_utils_debug_info diff --git a/configure.ac b/configure.ac index 2f605658..27ec6ee2 100644 --- a/configure.ac +++ b/configure.ac @@ -739,6 +739,7 @@ AC_CONFIG_FILES([ tests/cli/intersection/Makefile tests/lib/Makefile tests/lib/test-plugin-plugins/Makefile + tests/lib/ctf-ir/Makefile tests/utils/common.sh tests/utils/Makefile tests/utils/tap/Makefile @@ -783,6 +784,7 @@ 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/ctf-ir/test_ctf_ir], [chmod +x tests/lib/ctf-ir/test_ctf_ir]) AC_CONFIG_FILES([tests/plugins/test-utils-muxer-complete], [chmod +x tests/plugins/test-utils-muxer-complete]) AC_CONFIG_FILES([tests/plugins/test_lttng_utils_debug_info], [chmod +x tests/plugins/test_lttng_utils_debug_info]) AC_CONFIG_FILES([tests/plugins/test_dwarf_complete], [chmod +x tests/plugins/test_dwarf_complete]) diff --git a/tests/Makefile.am b/tests/Makefile.am index a0f26a1f..a0d9dcc2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -39,6 +39,10 @@ if !ENABLE_BUILT_IN_PLUGINS TESTS_LIB += lib/test_plugin_complete endif +if ENABLE_PYTHON_BINDINGS +TESTS_LIB += lib/ctf-ir/test_ctf_ir +endif + TESTS_PLUGINS = if !ENABLE_BUILT_IN_PLUGINS @@ -66,8 +70,8 @@ endif LOG_DRIVER_FLAGS = '--merge' LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/config/tap-driver.sh -TESTS = $(TESTS_BINDINGS) $(TESTS_CLI) $(TESTS_LIB) $(TESTS_PLUGINS) \ - $(TESTS_PYTHON_PLUGIN_PROVIDER) +TESTS = $(TESTS_BINDINGS) $(TESTS_CLI) $(TESTS_LIB) \ + $(TESTS_PLUGINS) $(TESTS_PYTHON_PLUGIN_PROVIDER) define check_target check-$(1): diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 9e20545d..1bfc7222 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS= +SUBDIRS = ctf-ir AM_CPPFLAGS += -I$(top_srcdir)/tests/utils diff --git a/tests/lib/ctf-ir/Makefile.am b/tests/lib/ctf-ir/Makefile.am new file mode 100644 index 00000000..6d8c8792 --- /dev/null +++ b/tests/lib/ctf-ir/Makefile.am @@ -0,0 +1,5 @@ +if ENABLE_PYTHON_BINDINGS +check_SCRIPTS = test_ctf_ir +endif + +EXTRA_DIST = test_trace.py diff --git a/tests/lib/ctf-ir/test_ctf_ir.in b/tests/lib/ctf-ir/test_ctf_ir.in new file mode 100644 index 00000000..c3ff375c --- /dev/null +++ b/tests/lib/ctf-ir/test_ctf_ir.in @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright (C) 2017 - Philippe Proulx +# +# 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 +. "@abs_top_builddir@/tests/utils/common.sh" + +PYTHON_BUILD_DIR="${BT_BUILD_PATH}/bindings/python/bt2/build/build_lib" +TESTS_UTILS_PYTHON_DIR="${BT_SRC_PATH}/tests/utils/python" +TESTRUNNER_PY="${BT_SRC_PATH}/tests/utils/python/testrunner.py" +THIS_DIR="${BT_SRC_PATH}/tests/lib/ctf-ir" + +if [ "x${MSYSTEM}" != "x" ]; then + export PATH="${BT_BUILD_PATH}/lib/.libs:${PATH}" +else + export LD_LIBRARY_PATH="${BT_BUILD_PATH}/lib/.libs:${LD_LIBRARY_PATH}" +fi + +PYTHONPATH="${PYTHON_BUILD_DIR}:${TESTS_UTILS_PYTHON_DIR}" \ + "@PYTHON@" "${TESTRUNNER_PY}" "${THIS_DIR}" +exit $? diff --git a/tests/lib/ctf-ir/test_trace.py b/tests/lib/ctf-ir/test_trace.py new file mode 100644 index 00000000..14e94ec1 --- /dev/null +++ b/tests/lib/ctf-ir/test_trace.py @@ -0,0 +1,91 @@ +import unittest +import bt2 + + +class TraceTestCase(unittest.TestCase): + def setUp(self): + self._trace = bt2.Trace() + + def tearDown(self): + del self._trace + + def _add_stream_class(self): + sc = bt2.StreamClass() + self._trace.add_stream_class(sc) + + def test_packet_header_ft_no_clock_class_simple(self): + cc = bt2.ClockClass('hello', 1000) + phft = bt2.StructureFieldType() + ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) + phft.append_field('salut', ft) + self._trace.add_clock_class(cc) + self._trace.packet_header_field_type = phft + + with self.assertRaises(bt2.Error): + self._add_stream_class() + + def test_packet_header_ft_no_clock_class_struct(self): + cc = bt2.ClockClass('hello', 1000) + phft = bt2.StructureFieldType() + ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) + struct_ft = bt2.StructureFieldType() + struct_ft.append_field('salut', ft) + phft.append_field('boucane', struct_ft) + self._trace.add_clock_class(cc) + self._trace.packet_header_field_type = phft + + with self.assertRaises(bt2.Error): + self._add_stream_class() + + def test_packet_header_ft_no_clock_class_variant(self): + cc = bt2.ClockClass('hello', 1000) + phft = bt2.StructureFieldType() + ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) + tag_ft = bt2.EnumerationFieldType(size=32) + tag_ft.append_mapping('heille', 12) + variant_ft = bt2.VariantFieldType('tag', tag_ft) + variant_ft.append_field('heille', ft) + phft.append_field('tag', tag_ft) + phft.append_field('boucane', variant_ft) + self._trace.add_clock_class(cc) + self._trace.packet_header_field_type = phft + + with self.assertRaises(bt2.Error): + self._add_stream_class() + + def test_packet_header_ft_no_clock_class_array(self): + cc = bt2.ClockClass('hello', 1000) + phft = bt2.StructureFieldType() + ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) + array_ft = bt2.ArrayFieldType(ft, 23) + phft.append_field('boucane', array_ft) + self._trace.add_clock_class(cc) + self._trace.packet_header_field_type = phft + + with self.assertRaises(bt2.Error): + self._add_stream_class() + + def test_packet_header_ft_no_clock_class_sequence(self): + cc = bt2.ClockClass('hello', 1000) + phft = bt2.StructureFieldType() + ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) + len_ft = bt2.IntegerFieldType(32) + seq_ft = bt2.SequenceFieldType(ft, 'len') + phft.append_field('len', len_ft) + phft.append_field('boucane', seq_ft) + self._trace.add_clock_class(cc) + self._trace.packet_header_field_type = phft + + with self.assertRaises(bt2.Error): + self._add_stream_class() + + def test_packet_header_ft_no_clock_class_set_static(self): + cc = bt2.ClockClass('hello', 1000) + phft = bt2.StructureFieldType() + ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) + phft.append_field('salut', ft) + self._trace.add_clock_class(cc) + self._trace.packet_header_field_type = phft + + with self.assertRaises(bt2.Error): + self._trace.set_is_static()