def test_ne_packet_header_field_type(self): cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={ 'the_string': 'value', 'the_int': 23 }, packet_header_field_type=header_ft, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() header_ft.append_field('yes', bt2.StringFieldType()) tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={ 'the_string': 'value', 'the_int': 23 }, packet_header_field_type=header_ft, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertNotEqual(tc1, tc2)
def test_create_full(self): header_ft = bt2.StructureFieldType() header_ft.append_field('magic', bt2.IntegerFieldType(32)) clock_classes = bt2.ClockClass('cc1'), bt2.ClockClass('cc2') sc = self._create_stream_class('sc1', 3) tc = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={ 'the_string': 'value', 'the_int': 23 }, packet_header_field_type=header_ft, clock_classes=clock_classes, stream_classes=(sc, )) self.assertEqual(tc.name, 'my name') self.assertEqual(tc.native_byte_order, bt2.ByteOrder.LITTLE_ENDIAN) self.assertEqual(tc.env['the_string'], 'value') self.assertEqual(tc.env['the_int'], 23) self.assertEqual(tc.packet_header_field_type, header_ft) self.assertEqual(tc.clock_classes['cc1'], clock_classes[0]) self.assertEqual(tc.clock_classes['cc2'], clock_classes[1]) self.assertEqual(tc[3], sc)
def _create_stream(self, name='my_stream', stream_id=None): # 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 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 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 ph = bt2.StructureFieldClass() ph += OrderedDict(( ('magic', bt2.IntegerFieldClass(32)), ('stream_id', bt2.IntegerFieldClass(16)), )) # trace c;ass tc = bt2.Trace() tc.packet_header_field_class = ph tc.add_stream_class(sc) # stream return sc(name=name, id=stream_id)