Example #1
0
 def test_code_exceeds_memory(self):
     """ Check the error that is given when code exceeds memory size """
     arch = ExampleArch()
     layout2 = layout.Layout()
     m = layout.Memory('flash')
     m.location = 0x0
     m.size = 0x10
     m.add_input(layout.Section('code'))
     layout2.add_memory(m)
     object1 = ObjectFile(arch)
     object1.get_section('code', create=True).add_data(bytes([0] * 22))
     with self.assertRaisesRegex(CompilerError, 'exceeds'):
         link([object1], layout2)
Example #2
0
 def test_layout(self):
     spec = """
         MEMORY flash LOCATION=0x1000 SIZE=0x3000 {
           SECTION(code)
           ALIGN(4)
           DEFINESYMBOL(x)
         }
     """
     layout1 = layout.Layout.load(io.StringIO(spec))
     layout2 = layout.Layout()
     m = layout.Memory('flash')
     m.location = 0x1000
     m.size = 0x3000
     m.add_input(layout.Section('code'))
     m.add_input(layout.Align(4))
     m.add_input(layout.SymbolDefinition('x'))
     layout2.add_memory(m)
     self.assertEqual(layout2, layout1)
     self.assertEqual(str(layout1), str(layout2))
Example #3
0
 def test_symbol_values(self):
     """ Check if values are correctly resolved """
     arch = get_arch('arm')
     object1 = ObjectFile(arch)
     object1.get_section('.text', create=True).add_data(bytes([0] * 108))
     object1.add_symbol(0, 'b', 'global', 24, '.text', 'object', 0)
     object2 = ObjectFile(arch)
     object2.get_section('.text', create=True).add_data(bytes([0] * 100))
     object2.add_symbol(0, 'a', 'global', 2, '.text', 'object', 0)
     layout1 = layout.Layout()
     flash_mem = layout.Memory('flash')
     flash_mem.location = 0x0
     flash_mem.size = 0x1000
     flash_mem.add_input(layout.SymbolDefinition('code_start'))
     flash_mem.add_input(layout.Section('.text'))
     flash_mem.add_input(layout.SymbolDefinition('code_end'))
     layout1.add_memory(flash_mem)
     object3 = link([object1, object2], layout1)
     self.assertEqual(110, object3.get_symbol_value('a'))
     self.assertEqual(24, object3.get_symbol_value('b'))
     self.assertEqual(208, object3.get_section('.text').size)
     self.assertEqual(0, object3.get_symbol_value('code_start'))
     self.assertEqual(208, object3.get_symbol_value('code_end'))