--- /dev/null
+#!/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 $?
--- /dev/null
+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()