From 1805e0b4b91b339a131f2463e241b706cad5a56f Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 21 Dec 2017 19:00:31 -0500 Subject: [PATCH] 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 --- .gitignore | 1 + configure.ac | 2 + tests/Makefile.am | 8 ++- tests/lib/Makefile.am | 2 +- tests/lib/ctf-ir/Makefile.am | 5 ++ tests/lib/ctf-ir/test_ctf_ir.in | 36 +++++++++++++ tests/lib/ctf-ir/test_trace.py | 91 +++++++++++++++++++++++++++++++++ 7 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 tests/lib/ctf-ir/Makefile.am create mode 100644 tests/lib/ctf-ir/test_ctf_ir.in create mode 100644 tests/lib/ctf-ir/test_trace.py diff --git a/.gitignore b/.gitignore index edcf8edc9..50a47ad70 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 2f6056588..27ec6ee2d 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 a0f26a1fb..a0d9dcc28 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 9e20545d1..1bfc72223 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 000000000..6d8c87924 --- /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 000000000..c3ff375c2 --- /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 000000000..14e94ec16 --- /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() -- 2.34.1