Add test: no clock class in trace's packet header field type
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 22 Dec 2017 00:00:31 +0000 (19:00 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 03:32:02 +0000 (23:32 -0400)
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 <eeppeliteloop@gmail.com>
.gitignore
configure.ac
tests/Makefile.am
tests/lib/Makefile.am
tests/lib/ctf-ir/Makefile.am [new file with mode: 0644]
tests/lib/ctf-ir/test_ctf_ir.in [new file with mode: 0644]
tests/lib/ctf-ir/test_trace.py [new file with mode: 0644]

index edcf8edc9ce6eb1f93b561350e7de2c2bba47329..50a47ad708a74d0e29be3534afc346a42008fa7e 100644 (file)
@@ -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
index 2f60565886188ae5c3ec521a1b274b83df2aab82..27ec6ee2d379a12d1936721119c86360ee63f293 100644 (file)
@@ -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])
index a0f26a1fbf3506b0f6255733d6faba599be0ffa3..a0d9dcc28fc9f48922da8ea68a07aa55a8edac5f 100644 (file)
@@ -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):
index 9e20545d124a0f2e5d82c44308391393b6f1416e..1bfc722232a50e51200f3be2e364a664615053c8 100644 (file)
@@ -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 (file)
index 0000000..6d8c879
--- /dev/null
@@ -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 (file)
index 0000000..c3ff375
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Copyright (C) 2017 - Philippe Proulx <pproulx@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
+. "@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 (file)
index 0000000..14e94ec
--- /dev/null
@@ -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()
This page took 0.029715 seconds and 4 git commands to generate.