def test_at_index(self): a_fc = bt2.IntegerFieldClass(32) b_fc = bt2.StringFieldClass() c_fc = bt2.FloatingPointNumberFieldClass() self._fc.append_field('c', c_fc) self._fc.append_field('a', a_fc) self._fc.append_field('b', b_fc) self.assertEqual(self._fc.at_index(1), a_fc)
def test_create_full(self): fc = bt2.FloatingPointNumberFieldClass(alignment=16, byte_order=bt2.ByteOrder.BIG_ENDIAN, exponent_size=11, mantissa_size=53) self.assertEqual(fc.alignment, 16) self.assertEqual(fc.byte_order, bt2.ByteOrder.BIG_ENDIAN) self.assertEqual(fc.exponent_size, 11) self.assertEqual(fc.mantissa_size, 53)
def test_iter(self): a_fc = bt2.IntegerFieldClass(32) b_fc = bt2.StringFieldClass() c_fc = bt2.FloatingPointNumberFieldClass() fields = ( ('a', a_fc), ('b', b_fc), ('c', c_fc), ) for field in fields: self._fc.append_field(*field) for (name, fc_field_class), field in zip(self._fc.items(), fields): self.assertEqual(name, field[0]) self.assertEqual(fc_field_class, field[1])
def _create_stream_class(self, name, id): ec1, ec2 = self._create_event_classes() packet_context_fc = bt2.StructureFieldClass() packet_context_fc.append_field('menu', bt2.FloatingPointNumberFieldClass()) packet_context_fc.append_field('sticker', bt2.StringFieldClass()) event_header_fc = bt2.StructureFieldClass() event_header_fc.append_field('id', bt2.IntegerFieldClass(19)) event_context_fc = bt2.StructureFieldClass() event_context_fc.append_field('msg', bt2.StringFieldClass()) return bt2.StreamClass(name=name, id=id, packet_context_field_class=packet_context_fc, event_header_field_class=event_header_fc, event_context_field_class=event_context_fc, event_classes=(ec1, ec2))
def setUp(self): self._packet_context_fc = bt2.StructureFieldClass() self._packet_context_fc.append_field( 'menu', bt2.FloatingPointNumberFieldClass()) self._packet_context_fc.append_field('sticker', bt2.StringFieldClass()) self._event_header_fc = bt2.StructureFieldClass() self._event_header_fc.append_field('id', bt2.IntegerFieldClass(19)) self._event_context_fc = bt2.StructureFieldClass() self._event_context_fc.append_field('msg', bt2.StringFieldClass()) self._ec1, self._ec2 = self._create_event_classes() self._sc = bt2.StreamClass( name='my_stream_class', id=12, packet_context_field_class=self._packet_context_fc, event_header_field_class=self._event_header_fc, event_context_field_class=self._event_context_fc, event_classes=(self._ec1, self._ec2))
def test_iadd(self): struct_fc = bt2.StructureFieldClass() c_field_class = bt2.StringFieldClass() d_field_class = bt2.EnumerationFieldClass(size=32) e_field_class = bt2.StructureFieldClass() struct_fc.append_field('c_string', c_field_class) struct_fc.append_field('d_enum', d_field_class) struct_fc.append_field('e_struct', e_field_class) a_field_class = bt2.FloatingPointNumberFieldClass() b_field_class = bt2.IntegerFieldClass(17) self._fc.append_field('a_float', a_field_class) self._fc.append_field('b_int', b_field_class) self._fc += struct_fc self.assertEqual(self._fc['a_float'], a_field_class) self.assertEqual(self._fc['b_int'], b_field_class) self.assertEqual(self._fc['c_string'], c_field_class) self.assertEqual(self._fc['d_enum'], d_field_class) self.assertEqual(self._fc['e_struct'], e_field_class)
def test_create_from_invalid_fc(self): with self.assertRaises(TypeError): fc = bt2.FloatingPointNumberFieldClass() self._fc = bt2.EnumerationFieldClass(fc)
def setUp(self): self._fc = bt2.FloatingPointNumberFieldClass()
def _create_packet(self, with_ph=True, with_pc=True): # event header eh = bt2.StructureFieldClass() eh += OrderedDict(( ('id', bt2.IntegerFieldClass(8)), ('ts', bt2.IntegerFieldClass(32)), )) # stream event context sec = bt2.StructureFieldClass() sec += OrderedDict(( ('cpu_id', bt2.IntegerFieldClass(8)), ('stuff', bt2.FloatingPointNumberFieldClass()), )) # packet context if with_pc: pc = bt2.StructureFieldClass() pc += OrderedDict(( ('something', bt2.IntegerFieldClass(8)), ('something_else', bt2.FloatingPointNumberFieldClass()), )) else: pc = None # stream class sc = bt2.StreamClass() sc.packet_context_field_class = pc sc.event_header_field_class = eh sc.event_context_field_class = sec # event context ec = bt2.StructureFieldClass() ec += OrderedDict(( ('ant', bt2.IntegerFieldClass(16, is_signed=True)), ('msg', bt2.StringFieldClass()), )) # event payload ep = bt2.StructureFieldClass() ep += OrderedDict(( ('giraffe', bt2.IntegerFieldClass(32)), ('gnu', bt2.IntegerFieldClass(8)), ('mosquito', bt2.IntegerFieldClass(8)), )) # event class event_class = bt2.EventClass('ec') event_class.context_field_class = ec event_class.payload_field_class = ep sc.add_event_class(event_class) # packet header if with_ph: ph = bt2.StructureFieldClass() ph += OrderedDict(( ('magic', bt2.IntegerFieldClass(32)), ('stream_id', bt2.IntegerFieldClass(16)), )) else: ph = None # trace c;ass tc = bt2.Trace() tc.packet_header_field_class = ph tc.add_stream_class(sc) # stream stream = sc() # packet return stream.create_packet()
def _create_ec(self, with_eh=True, with_sec=True, with_ec=True, with_ep=True): # event header if with_eh: eh = bt2.StructureFieldClass() eh += OrderedDict(( ('id', bt2.IntegerFieldClass(8)), ('ts', bt2.IntegerFieldClass(32)), )) else: eh = None # stream event context if with_sec: sec = bt2.StructureFieldClass() sec += OrderedDict(( ('cpu_id', bt2.IntegerFieldClass(8)), ('stuff', bt2.FloatingPointNumberFieldClass()), )) else: sec = None # packet context pc = bt2.StructureFieldClass() pc += OrderedDict(( ('something', bt2.IntegerFieldClass(8)), ('something_else', bt2.FloatingPointNumberFieldClass()), )) # stream class sc = bt2.StreamClass() sc.packet_context_field_class = pc sc.event_header_field_class = eh sc.event_context_field_class = sec # event context if with_ec: ec = bt2.StructureFieldClass() ec += OrderedDict(( ('ant', bt2.IntegerFieldClass(16, is_signed=True)), ('msg', bt2.StringFieldClass()), )) else: ec = None # event payload if with_ep: ep = bt2.StructureFieldClass() ep += OrderedDict(( ('giraffe', bt2.IntegerFieldClass(32)), ('gnu', bt2.IntegerFieldClass(8)), ('mosquito', bt2.IntegerFieldClass(8)), )) else: ep = None # event class event_class = bt2.EventClass('ec') event_class.context_field_class = ec event_class.payload_field_class = ep sc.add_event_class(event_class) return event_class