Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
382:0c44e494ef58 | 383:173e20a47fda |
---|---|
6 from ppci.objectfile import ObjectFile, serialize, deserialize, load_object | 6 from ppci.objectfile import ObjectFile, serialize, deserialize, load_object |
7 from ppci import CompilerError | 7 from ppci import CompilerError |
8 from ppci.tasks import TaskRunner, TaskError | 8 from ppci.tasks import TaskRunner, TaskError |
9 from ppci.buildtasks import EmptyTask | 9 from ppci.buildtasks import EmptyTask |
10 from ppci.buildfunctions import link | 10 from ppci.buildfunctions import link |
11 from ppci import layout | |
11 | 12 |
12 | 13 |
13 class TaskTestCase(unittest.TestCase): | 14 class TaskTestCase(unittest.TestCase): |
14 @unittest.skip('api change') | 15 @unittest.skip('api change') |
15 def testCircular(self): | 16 def testCircular(self): |
57 o1 = ObjectFile() | 58 o1 = ObjectFile() |
58 o1.get_section('.text') | 59 o1.get_section('.text') |
59 o1.add_relocation('undefined_sym', 0, 'rel8', '.text') | 60 o1.add_relocation('undefined_sym', 0, 'rel8', '.text') |
60 o2 = ObjectFile() | 61 o2 = ObjectFile() |
61 with self.assertRaises(CompilerError): | 62 with self.assertRaises(CompilerError): |
62 o3 = link([o1, o2], {}) | 63 o3 = link([o1, o2], layout.Layout()) |
63 | 64 |
64 def testDuplicateSymbol(self): | 65 def testDuplicateSymbol(self): |
65 o1 = ObjectFile() | 66 o1 = ObjectFile() |
66 o1.get_section('.text') | 67 o1.get_section('.text') |
67 o1.add_symbol('a', 0, '.text') | 68 o1.add_symbol('a', 0, '.text') |
68 o2 = ObjectFile() | 69 o2 = ObjectFile() |
69 o2.get_section('.text') | 70 o2.get_section('.text') |
70 o2.add_symbol('a', 0, '.text') | 71 o2.add_symbol('a', 0, '.text') |
71 with self.assertRaises(CompilerError): | 72 with self.assertRaises(CompilerError): |
72 o3 = link([o1, o2], {}) | 73 o3 = link([o1, o2], layout.Layout()) |
73 | 74 |
74 def testRel8Relocation(self): | 75 def testRel8Relocation(self): |
75 o1 = ObjectFile() | 76 o1 = ObjectFile() |
76 o1.get_section('.text').add_data(bytes([0]*100)) | 77 o1.get_section('.text').add_data(bytes([0]*100)) |
77 o1.add_relocation('a', 0, 'rel8', '.text') | 78 o1.add_relocation('a', 0, 'rel8', '.text') |
78 o2 = ObjectFile() | 79 o2 = ObjectFile() |
79 o2.get_section('.text').add_data(bytes([0]*100)) | 80 o2.get_section('.text').add_data(bytes([0]*100)) |
80 o2.add_symbol('a', 24, '.text') | 81 o2.add_symbol('a', 24, '.text') |
81 o3 = link([o1, o2], {}) | 82 o3 = link([o1, o2], layout.Layout()) |
82 | 83 |
83 def testSymbolValues(self): | 84 def testSymbolValues(self): |
84 o1 = ObjectFile() | 85 o1 = ObjectFile() |
85 o1.get_section('.text').add_data(bytes([0]*108)) | 86 o1.get_section('.text').add_data(bytes([0]*108)) |
86 o1.add_symbol('b', 24, '.text') | 87 o1.add_symbol('b', 24, '.text') |
87 o2 = ObjectFile() | 88 o2 = ObjectFile() |
88 o2.get_section('.text').add_data(bytes([0]*100)) | 89 o2.get_section('.text').add_data(bytes([0]*100)) |
89 o2.add_symbol('a', 2, '.text') | 90 o2.add_symbol('a', 2, '.text') |
90 o3 = link([o1, o2], {}) | 91 o3 = link([o1, o2], layout.Layout()) |
91 self.assertEqual(110, o3.find_symbol('a').value) | 92 self.assertEqual(110, o3.find_symbol('a').value) |
92 self.assertEqual(24, o3.find_symbol('b').value) | 93 self.assertEqual(24, o3.find_symbol('b').value) |
93 self.assertEqual(208, o3.get_section('.text').Size) | 94 self.assertEqual(208, o3.get_section('.text').Size) |
94 | 95 |
95 def testMemoryLayout(self): | 96 def testMemoryLayout(self): |
96 memory_layout = {'.text': 0x08000000, '.data':0x20000000} | 97 spec = """ |
98 MEMORY flash LOCATION=0x08000000 SIZE=0x3000 { | |
99 SECTION(code) | |
100 } | |
101 MEMORY flash LOCATION=0x20000000 SIZE=0x3000 { | |
102 SECTION(data) | |
103 } | |
104 """ | |
105 memory_layout = layout.load_layout(io.StringIO(spec)) | |
97 o1 = ObjectFile() | 106 o1 = ObjectFile() |
98 o1.get_section('.text').add_data(bytes([0]*108)) | 107 o1.get_section('code').add_data(bytes([0]*108)) |
99 o1.add_symbol('b', 24, '.text') | 108 o1.add_symbol('b', 24, 'code') |
100 o2 = ObjectFile() | 109 o2 = ObjectFile() |
101 o2.get_section('.text').add_data(bytes([0]*100)) | 110 o2.get_section('code').add_data(bytes([0]*100)) |
102 o2.get_section('.data').add_data(bytes([0]*100)) | 111 o2.get_section('data').add_data(bytes([0]*100)) |
103 o2.add_symbol('a', 2, '.data') | 112 o2.add_symbol('a', 2, 'data') |
104 o2.add_symbol('c', 2, '.text') | 113 o2.add_symbol('c', 2, 'code') |
105 o3 = link([o1, o2], memory_layout) | 114 o3 = link([o1, o2], memory_layout) |
106 self.assertEqual(0x20000000+2, o3.find_symbol('a').value) | 115 self.assertEqual(0x20000000+2, o3.find_symbol('a').value) |
107 self.assertEqual(0x08000000+24, o3.find_symbol('b').value) | 116 self.assertEqual(0x08000000+24, o3.find_symbol('b').value) |
108 self.assertEqual(0x08000000+110, o3.find_symbol('c').value) | 117 self.assertEqual(0x08000000+110, o3.find_symbol('c').value) |
109 self.assertEqual(208, o3.get_section('.text').Size) | 118 self.assertEqual(208, o3.get_section('code').Size) |
110 self.assertEqual(100, o3.get_section('.data').Size) | 119 self.assertEqual(100, o3.get_section('data').Size) |
111 | 120 |
112 | 121 |
113 class ObjectFileTestCase(unittest.TestCase): | 122 class ObjectFileTestCase(unittest.TestCase): |
114 def makeTwins(self): | 123 def makeTwins(self): |
115 o1 = ObjectFile() | 124 o1 = ObjectFile() |
140 o1, o2 = self.makeTwins() | 149 o1, o2 = self.makeTwins() |
141 o3 = deserialize(serialize(o1)) | 150 o3 = deserialize(serialize(o1)) |
142 self.assertEqual(o3, o1) | 151 self.assertEqual(o3, o1) |
143 | 152 |
144 | 153 |
154 class LayoutFileTestCase(unittest.TestCase): | |
155 def testLayout1(self): | |
156 spec = """ | |
157 MEMORY flash LOCATION=0x1000 SIZE=0x3000 { | |
158 SECTION(code) | |
159 ALIGN(4) | |
160 } | |
161 """ | |
162 layout1 = layout.load_layout(io.StringIO(spec)) | |
163 layout2 = layout.Layout() | |
164 m = layout.Memory('flash') | |
165 m.location = 0x1000 | |
166 m.size = 0x3000 | |
167 m.add_input(layout.Section('code')) | |
168 m.add_input(layout.Align(4)) | |
169 layout2.add_memory(m) | |
170 self.assertEqual(layout2, layout1) | |
171 | |
172 | |
145 if __name__ == '__main__': | 173 if __name__ == '__main__': |
146 unittest.main() | 174 unittest.main() |
147 sys.exit() | 175 sys.exit() |