Ejemplo n.º 1
0
 def test_at_index(self):
     a_ft = bt2.IntegerFieldType(32)
     b_ft = bt2.StringFieldType()
     c_ft = bt2.FloatingPointNumberFieldType()
     self._ft.append_field('c', c_ft)
     self._ft.append_field('a', a_ft)
     self._ft.append_field('b', b_ft)
     self.assertEqual(self._ft.at_index(1), a_ft)
Ejemplo n.º 2
0
 def test_create_full(self):
     ft = bt2.FloatingPointNumberFieldType(alignment=16,
                                           byte_order=bt2.ByteOrder.BIG_ENDIAN,
                                           exponent_size=11,
                                           mantissa_size=53)
     self.assertEqual(ft.alignment, 16)
     self.assertEqual(ft.byte_order, bt2.ByteOrder.BIG_ENDIAN)
     self.assertEqual(ft.exponent_size, 11)
     self.assertEqual(ft.mantissa_size, 53)
Ejemplo n.º 3
0
 def setUp(self):
     self._packet_context_ft = bt2.StructureFieldType()
     self._packet_context_ft.append_field('menu', bt2.FloatingPointNumberFieldType())
     self._packet_context_ft.append_field('sticker', bt2.StringFieldType())
     self._event_header_ft = bt2.StructureFieldType()
     self._event_header_ft.append_field('id', bt2.IntegerFieldType(19))
     self._event_context_ft = bt2.StructureFieldType()
     self._event_context_ft.append_field('msg', bt2.StringFieldType())
     self._ec1, self._ec2 = self._create_event_classes()
     self._sc = bt2.StreamClass(name='my_stream_class', id=12,
                                packet_context_field_type=self._packet_context_ft,
                                event_header_field_type=self._event_header_ft,
                                event_context_field_type=self._event_context_ft,
                                event_classes=(self._ec1, self._ec2))
Ejemplo n.º 4
0
    def test_iter(self):
        a_ft = bt2.IntegerFieldType(32)
        b_ft = bt2.StringFieldType()
        c_ft = bt2.FloatingPointNumberFieldType()
        fields = (
            ('a', a_ft),
            ('b', b_ft),
            ('c', c_ft),
        )

        for field in fields:
            self._ft.append_field(*field)

        for (name, ft_field_type), field in zip(self._ft.items(), fields):
            self.assertEqual(name, field[0])
            self.assertEqual(ft_field_type, field[1])
Ejemplo n.º 5
0
 def _create_stream_class(self, name, id):
     ec1, ec2 = self._create_event_classes()
     packet_context_ft = bt2.StructureFieldType()
     packet_context_ft.append_field('menu',
                                    bt2.FloatingPointNumberFieldType())
     packet_context_ft.append_field('sticker', bt2.StringFieldType())
     event_header_ft = bt2.StructureFieldType()
     event_header_ft.append_field('id', bt2.IntegerFieldType(19))
     event_context_ft = bt2.StructureFieldType()
     event_context_ft.append_field('msg', bt2.StringFieldType())
     return bt2.StreamClass(name=name,
                            id=id,
                            packet_context_field_type=packet_context_ft,
                            event_header_field_type=event_header_ft,
                            event_context_field_type=event_context_ft,
                            event_classes=(ec1, ec2))
Ejemplo n.º 6
0
 def test_iadd(self):
     struct_ft = bt2.StructureFieldType()
     c_field_type = bt2.StringFieldType()
     d_field_type = bt2.EnumerationFieldType(size=32)
     e_field_type = bt2.StructureFieldType()
     struct_ft.append_field('c_string', c_field_type)
     struct_ft.append_field('d_enum', d_field_type)
     struct_ft.append_field('e_struct', e_field_type)
     a_field_type = bt2.FloatingPointNumberFieldType()
     b_field_type = bt2.IntegerFieldType(17)
     self._ft.append_field('a_float', a_field_type)
     self._ft.append_field('b_int', b_field_type)
     self._ft += struct_ft
     self.assertEqual(self._ft['a_float'], a_field_type)
     self.assertEqual(self._ft['b_int'], b_field_type)
     self.assertEqual(self._ft['c_string'], c_field_type)
     self.assertEqual(self._ft['d_enum'], d_field_type)
     self.assertEqual(self._ft['e_struct'], e_field_type)
    def test_type(self):
        int_ft = bt2.IntegerFieldType(32)

        enum_ft = bt2.EnumerationFieldType(int_ft)
        enum_ft.append_mapping('corner', 23)
        enum_ft.append_mapping('zoom', 17, 20)
        enum_ft.append_mapping('mellotron', 1001)
        enum_ft.append_mapping('giorgio', 2000, 3000)

        array_ft = bt2.ArrayFieldType(int_ft, 5)
        seq_ft = bt2.SequenceFieldType(int_ft, 'the_len_field')
        float_ft = bt2.FloatingPointNumberFieldType()

        struct_ft = bt2.StructureFieldType()
        struct_ft.append_field('a', int_ft)
        struct_ft.append_field('b', int_ft)
        struct_ft.append_field('c', int_ft)

        _string_ft = bt2.StringFieldType()

        variant_ft = bt2.VariantFieldType('tag', enum_ft)
        variant_ft.append_field('corner', int_ft)
        variant_ft.append_field('zoom', array_ft)
        variant_ft.append_field('mellotron', float_ft)
        variant_ft.append_field('giorgio', struct_ft)

        expected_types = {
            babeltrace.CTFTypeId.INTEGER: int_ft,
            babeltrace.CTFTypeId.FLOAT: float_ft,
            babeltrace.CTFTypeId.ENUM: enum_ft,
            babeltrace.CTFTypeId.STRING: _string_ft,
            babeltrace.CTFTypeId.STRUCT: struct_ft,
            babeltrace.CTFTypeId.VARIANT: variant_ft,
            babeltrace.CTFTypeId.ARRAY: array_ft,
            babeltrace.CTFTypeId.SEQUENCE: seq_ft,
        }

        for type_id, ft in expected_types.items():
            declaration = self._get_declaration(ft)
            self.assertIsNotNone(declaration)
            self.assertEqual(declaration.type, type_id)
Ejemplo n.º 8
0
 def test_create_from_invalid_ft(self):
     with self.assertRaises(TypeError):
         ft = bt2.FloatingPointNumberFieldType()
         self._ft = bt2.EnumerationFieldType(ft)
Ejemplo n.º 9
0
 def setUp(self):
     self._ft = bt2.FloatingPointNumberFieldType()
Ejemplo n.º 10
0
    def _create_packet(self, with_ph=True, with_pc=True):
        # event header
        eh = bt2.StructureFieldType()
        eh += OrderedDict((
            ('id', bt2.IntegerFieldType(8)),
            ('ts', bt2.IntegerFieldType(32)),
        ))

        # stream event context
        sec = bt2.StructureFieldType()
        sec += OrderedDict((
            ('cpu_id', bt2.IntegerFieldType(8)),
            ('stuff', bt2.FloatingPointNumberFieldType()),
        ))

        # packet context
        if with_pc:
            pc = bt2.StructureFieldType()
            pc += OrderedDict((
                ('something', bt2.IntegerFieldType(8)),
                ('something_else', bt2.FloatingPointNumberFieldType()),
            ))
        else:
            pc = None

        # stream class
        sc = bt2.StreamClass()
        sc.packet_context_field_type = pc
        sc.event_header_field_type = eh
        sc.event_context_field_type = sec

        # event context
        ec = bt2.StructureFieldType()
        ec += OrderedDict((
            ('ant', bt2.IntegerFieldType(16, is_signed=True)),
            ('msg', bt2.StringFieldType()),
        ))

        # event payload
        ep = bt2.StructureFieldType()
        ep += OrderedDict((
            ('giraffe', bt2.IntegerFieldType(32)),
            ('gnu', bt2.IntegerFieldType(8)),
            ('mosquito', bt2.IntegerFieldType(8)),
        ))

        # event class
        event_class = bt2.EventClass('ec')
        event_class.context_field_type = ec
        event_class.payload_field_type = ep
        sc.add_event_class(event_class)

        # packet header
        if with_ph:
            ph = bt2.StructureFieldType()
            ph += OrderedDict((
                ('magic', bt2.IntegerFieldType(32)),
                ('stream_id', bt2.IntegerFieldType(16)),
            ))
        else:
            ph = None

        # trace c;ass
        tc = bt2.Trace()
        tc.packet_header_field_type = ph
        tc.add_stream_class(sc)

        # stream
        stream = sc()

        # packet
        return stream.create_packet()