| 1 | import unittest |
| 2 | import bt2 |
| 3 | |
| 4 | |
| 5 | class TraceTestCase(unittest.TestCase): |
| 6 | def setUp(self): |
| 7 | self._trace = bt2.Trace() |
| 8 | |
| 9 | def tearDown(self): |
| 10 | del self._trace |
| 11 | |
| 12 | def _add_stream_class(self): |
| 13 | sc = bt2.StreamClass() |
| 14 | self._trace.add_stream_class(sc) |
| 15 | |
| 16 | def test_packet_header_ft_no_clock_class_simple(self): |
| 17 | cc = bt2.ClockClass('hello', 1000) |
| 18 | phft = bt2.StructureFieldType() |
| 19 | ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) |
| 20 | phft.append_field('salut', ft) |
| 21 | self._trace.add_clock_class(cc) |
| 22 | self._trace.packet_header_field_type = phft |
| 23 | |
| 24 | with self.assertRaises(bt2.Error): |
| 25 | self._add_stream_class() |
| 26 | |
| 27 | def test_packet_header_ft_no_clock_class_struct(self): |
| 28 | cc = bt2.ClockClass('hello', 1000) |
| 29 | phft = bt2.StructureFieldType() |
| 30 | ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) |
| 31 | struct_ft = bt2.StructureFieldType() |
| 32 | struct_ft.append_field('salut', ft) |
| 33 | phft.append_field('boucane', struct_ft) |
| 34 | self._trace.add_clock_class(cc) |
| 35 | self._trace.packet_header_field_type = phft |
| 36 | |
| 37 | with self.assertRaises(bt2.Error): |
| 38 | self._add_stream_class() |
| 39 | |
| 40 | def test_packet_header_ft_no_clock_class_variant(self): |
| 41 | cc = bt2.ClockClass('hello', 1000) |
| 42 | phft = bt2.StructureFieldType() |
| 43 | ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) |
| 44 | tag_ft = bt2.EnumerationFieldType(size=32) |
| 45 | tag_ft.add_mapping('heille', 12) |
| 46 | variant_ft = bt2.VariantFieldType('tag', tag_ft) |
| 47 | variant_ft.append_field('heille', ft) |
| 48 | phft.append_field('tag', tag_ft) |
| 49 | phft.append_field('boucane', variant_ft) |
| 50 | self._trace.add_clock_class(cc) |
| 51 | self._trace.packet_header_field_type = phft |
| 52 | |
| 53 | with self.assertRaises(bt2.Error): |
| 54 | self._add_stream_class() |
| 55 | |
| 56 | def test_packet_header_ft_no_clock_class_array(self): |
| 57 | cc = bt2.ClockClass('hello', 1000) |
| 58 | phft = bt2.StructureFieldType() |
| 59 | ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) |
| 60 | array_ft = bt2.ArrayFieldType(ft, 23) |
| 61 | phft.append_field('boucane', array_ft) |
| 62 | self._trace.add_clock_class(cc) |
| 63 | self._trace.packet_header_field_type = phft |
| 64 | |
| 65 | with self.assertRaises(bt2.Error): |
| 66 | self._add_stream_class() |
| 67 | |
| 68 | def test_packet_header_ft_no_clock_class_sequence(self): |
| 69 | cc = bt2.ClockClass('hello', 1000) |
| 70 | phft = bt2.StructureFieldType() |
| 71 | ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) |
| 72 | len_ft = bt2.IntegerFieldType(32) |
| 73 | seq_ft = bt2.SequenceFieldType(ft, 'len') |
| 74 | phft.append_field('len', len_ft) |
| 75 | phft.append_field('boucane', seq_ft) |
| 76 | self._trace.add_clock_class(cc) |
| 77 | self._trace.packet_header_field_type = phft |
| 78 | |
| 79 | with self.assertRaises(bt2.Error): |
| 80 | self._add_stream_class() |
| 81 | |
| 82 | def test_packet_header_ft_no_clock_class_set_static(self): |
| 83 | cc = bt2.ClockClass('hello', 1000) |
| 84 | phft = bt2.StructureFieldType() |
| 85 | ft = bt2.IntegerFieldType(32, mapped_clock_class=cc) |
| 86 | phft.append_field('salut', ft) |
| 87 | self._trace.add_clock_class(cc) |
| 88 | self._trace.packet_header_field_type = phft |
| 89 | |
| 90 | with self.assertRaises(bt2.Error): |
| 91 | self._trace.set_is_static() |