Mercurial > lcfOS
diff test/testbintools.py @ 383:173e20a47fda
Added linker description loader
author | Windel Bouwman |
---|---|
date | Sun, 27 Apr 2014 17:40:39 +0200 |
parents | 6df89163e114 |
children | d056b552d3f4 |
line wrap: on
line diff
--- a/test/testbintools.py Sun Apr 27 12:24:21 2014 +0200 +++ b/test/testbintools.py Sun Apr 27 17:40:39 2014 +0200 @@ -8,6 +8,7 @@ from ppci.tasks import TaskRunner, TaskError from ppci.buildtasks import EmptyTask from ppci.buildfunctions import link +from ppci import layout class TaskTestCase(unittest.TestCase): @@ -59,7 +60,7 @@ o1.add_relocation('undefined_sym', 0, 'rel8', '.text') o2 = ObjectFile() with self.assertRaises(CompilerError): - o3 = link([o1, o2], {}) + o3 = link([o1, o2], layout.Layout()) def testDuplicateSymbol(self): o1 = ObjectFile() @@ -69,7 +70,7 @@ o2.get_section('.text') o2.add_symbol('a', 0, '.text') with self.assertRaises(CompilerError): - o3 = link([o1, o2], {}) + o3 = link([o1, o2], layout.Layout()) def testRel8Relocation(self): o1 = ObjectFile() @@ -78,7 +79,7 @@ o2 = ObjectFile() o2.get_section('.text').add_data(bytes([0]*100)) o2.add_symbol('a', 24, '.text') - o3 = link([o1, o2], {}) + o3 = link([o1, o2], layout.Layout()) def testSymbolValues(self): o1 = ObjectFile() @@ -87,27 +88,35 @@ o2 = ObjectFile() o2.get_section('.text').add_data(bytes([0]*100)) o2.add_symbol('a', 2, '.text') - o3 = link([o1, o2], {}) + o3 = link([o1, o2], layout.Layout()) self.assertEqual(110, o3.find_symbol('a').value) self.assertEqual(24, o3.find_symbol('b').value) self.assertEqual(208, o3.get_section('.text').Size) def testMemoryLayout(self): - memory_layout = {'.text': 0x08000000, '.data':0x20000000} + spec = """ + MEMORY flash LOCATION=0x08000000 SIZE=0x3000 { + SECTION(code) + } + MEMORY flash LOCATION=0x20000000 SIZE=0x3000 { + SECTION(data) + } + """ + memory_layout = layout.load_layout(io.StringIO(spec)) o1 = ObjectFile() - o1.get_section('.text').add_data(bytes([0]*108)) - o1.add_symbol('b', 24, '.text') + o1.get_section('code').add_data(bytes([0]*108)) + o1.add_symbol('b', 24, 'code') o2 = ObjectFile() - o2.get_section('.text').add_data(bytes([0]*100)) - o2.get_section('.data').add_data(bytes([0]*100)) - o2.add_symbol('a', 2, '.data') - o2.add_symbol('c', 2, '.text') + o2.get_section('code').add_data(bytes([0]*100)) + o2.get_section('data').add_data(bytes([0]*100)) + o2.add_symbol('a', 2, 'data') + o2.add_symbol('c', 2, 'code') o3 = link([o1, o2], memory_layout) self.assertEqual(0x20000000+2, o3.find_symbol('a').value) self.assertEqual(0x08000000+24, o3.find_symbol('b').value) self.assertEqual(0x08000000+110, o3.find_symbol('c').value) - self.assertEqual(208, o3.get_section('.text').Size) - self.assertEqual(100, o3.get_section('.data').Size) + self.assertEqual(208, o3.get_section('code').Size) + self.assertEqual(100, o3.get_section('data').Size) class ObjectFileTestCase(unittest.TestCase): @@ -142,6 +151,25 @@ self.assertEqual(o3, o1) +class LayoutFileTestCase(unittest.TestCase): + def testLayout1(self): + spec = """ + MEMORY flash LOCATION=0x1000 SIZE=0x3000 { + SECTION(code) + ALIGN(4) + } + """ + layout1 = layout.load_layout(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)) + layout2.add_memory(m) + self.assertEqual(layout2, layout1) + + if __name__ == '__main__': unittest.main() sys.exit()