예제 #1
0
 def test_to_vtype_with_layout_with_one_field(self):
     layout_to_convert = layout.Layout(
         bit_size=32,
         bit_alignment=16,
         fields=[
             layout.Field(bit_offset=0,
                          name='x',
                          layout=layout.Layout(
                              bit_size=32,
                              bit_alignment=16,
                          ))
         ],
     )
     type_definition = c_ast.CStruct([
         c_ast.CField(
             name='x',
             type_definition=c_ast.CTypeReference('some_type'),
         ),
     ])
     self.type_description_visitor.get_description.return_value = (
         'some_description')
     actual = self.layout_to_vtype_converter.to_vtype(
         layout_to_convert,
         type_definition,
         'some_types',
     )
     self.type_description_visitor.get_description.assert_called_with(
         c_ast.CTypeReference('some_type'),
         'some_types',
     )
     expected = [4, {'x': [0, 'some_description']}]
     self.assertEqual(actual, expected)
예제 #2
0
 def test_to_vtype_with_layout_with_bit_field(self):
     layout_to_convert = layout.Layout(
         bit_size=48,
         bit_alignment=16,
         fields=[
             layout.Field(bit_offset=33,
                          name='x',
                          layout=layout.Layout(
                              bit_size=9,
                              bit_alignment=16,
                              bit_field=True,
                          ))
         ],
     )
     type_definition = c_ast.CStruct([
         c_ast.CField(
             name='x',
             type_definition=c_ast.CTypeReference('some_type'),
             bit_size=9,
         ),
     ])
     self.type_description_visitor.get_description.return_value = [
         'some_type'
     ]
     actual = self.layout_to_vtype_converter.to_vtype(
         layout_to_convert,
         type_definition,
         'some_types',
     )
     self.type_description_visitor.get_description.assert_called_with(
         c_ast.CTypeReference('some_type'),
         'some_types',
     )
     expected = [
         6,
         {
             'x': [
                 4,
                 [
                     'BitField', {
                         'start_bit': 1,
                         'end_bit': 10,
                         'target': 'some_type',
                     }
                 ],
             ],
         },
     ]
     self.assertEqual(actual, expected)
예제 #3
0
 def construct_bitfield(maybe_identifier, bit_size_string):
   bit_size = expression.parseString(bit_size_string, parseAll=True)[0]
   return c_ast.CField(
       name=maybe_identifier,
       bit_size=bit_size,
   )
예제 #4
0
 def test_to_vtype_with_layout_with_three_fields(self):
     layout_to_convert = layout.Layout(
         bit_size=48,
         bit_alignment=32,
         fields=[
             layout.Field(bit_offset=0,
                          name='x',
                          layout=layout.Layout(
                              bit_size=16,
                              bit_alignment=8,
                          )),
             layout.Field(bit_offset=16,
                          name='y',
                          layout=layout.Layout(
                              bit_size=8,
                              bit_alignment=32,
                          )),
             layout.Field(bit_offset=24,
                          name='z',
                          layout=layout.Layout(
                              bit_size=24,
                              bit_alignment=16,
                          )),
         ],
     )
     some_type = c_ast.CTypeReference('some_type')
     some_other_type = c_ast.CTypeReference('some_other_type')
     type_definition = c_ast.CStruct([
         c_ast.CField(
             name='x',
             type_definition=some_type,
         ),
         c_ast.CField(
             name='y',
             type_definition=some_other_type,
         ),
         c_ast.CField(
             name='z',
             type_definition=some_type,
         ),
     ])
     self.type_description_visitor.get_description.side_effect = (
         'some_description',
         'some_other_description',
         'some_description',
     )
     actual = self.layout_to_vtype_converter.to_vtype(
         layout_to_convert,
         type_definition,
         'some_types',
     )
     expected_get_description_calls = [
         mock.call(some_type, 'some_types'),
         mock.call(some_other_type, 'some_types'),
         mock.call(some_type, 'some_types'),
     ]
     self.assertEqual(
         self.type_description_visitor.get_description.call_args_list,
         expected_get_description_calls,
     )
     expected = [
         6, {
             'x': [0, 'some_description'],
             'y': [2, 'some_other_description'],
             'z': [3, 'some_description'],
         }
     ]
     self.assertEqual(actual, expected)
예제 #5
0
 def test_collect_types_with_field(self):
   field = c_ast.CField('name', 'type_definiiton')
   actual = self.type_collector.collect_types(field)
   self.assertEqual(actual, {})