Mercurial > lcfOS
annotate test/testbintools.py @ 377:9667d78ba79e
Switched to xml for project description
author | Windel Bouwman |
---|---|
date | Fri, 11 Apr 2014 15:47:50 +0200 |
parents | 86b02c98a717 |
children | 6df89163e114 |
rev | line source |
---|---|
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
1 import unittest |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
2 import sys |
377 | 3 import io |
342 | 4 from ppci.target.arm.token import ArmToken |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
5 from ppci.linker import Linker |
377 | 6 from ppci.objectfile import ObjectFile, serialize, deserialize, load_object |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
7 from ppci import CompilerError |
377 | 8 from ppci.tasks import TaskRunner, TaskError |
9 from ppci.buildtasks import EmptyTask | |
342 | 10 |
11 | |
12 class TaskTestCase(unittest.TestCase): | |
377 | 13 @unittest.skip('api change') |
342 | 14 def testCircular(self): |
15 t1 = EmptyTask('t1') | |
16 t2 = EmptyTask('t2') | |
17 t1.add_dependency(t2) | |
18 with self.assertRaises(TaskError): | |
19 t2.add_dependency(t1) | |
20 | |
377 | 21 @unittest.skip('api change') |
342 | 22 def testCircularDeeper(self): |
23 t1 = EmptyTask('t1') | |
24 t2 = EmptyTask('t2') | |
25 t3 = EmptyTask('t3') | |
26 t1.add_dependency(t2) | |
27 t2.add_dependency(t3) | |
28 with self.assertRaises(TaskError): | |
29 t3.add_dependency(t1) | |
30 | |
377 | 31 @unittest.skip('api change') |
342 | 32 def testSort(self): |
33 t1 = EmptyTask('t1') | |
34 t2 = EmptyTask('t2') | |
35 runner = TaskRunner() | |
36 t1.add_dependency(t2) | |
37 runner.add_task(t1) | |
38 runner.add_task(t2) | |
39 runner.run_tasks() | |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
40 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
41 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
42 class TokenTestCase(unittest.TestCase): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
43 def testSetBits(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
44 at = ArmToken() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
45 at[2:4] = 0b11 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
46 self.assertEqual(0xc, at.bit_value) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
47 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
48 def testSetBits(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
49 at = ArmToken() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
50 at[4:8] = 0b1100 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
51 self.assertEqual(0xc0, at.bit_value) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
52 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
53 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
54 class LinkerTestCase(unittest.TestCase): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
55 def testUndefinedReference(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
56 l = Linker() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
57 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
58 o1.get_section('.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
59 o1.add_relocation('undefined_sym', 0, 'rel8', '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
60 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
61 with self.assertRaises(CompilerError): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
62 o3 = l.link([o1, o2]) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
63 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
64 def testDuplicateSymbol(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
65 l = Linker() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
66 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
67 o1.get_section('.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
68 o1.add_symbol('a', 0, '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
69 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
70 o2.get_section('.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
71 o2.add_symbol('a', 0, '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
72 with self.assertRaises(CompilerError): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
73 o3 = l.link([o1, o2]) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
74 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
75 def testRel8Relocation(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
76 l = Linker() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
77 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
78 o1.get_section('.text').add_data(bytes([0]*100)) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
79 o1.add_relocation('a', 0, 'rel8', '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
80 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
81 o2.get_section('.text').add_data(bytes([0]*100)) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
82 o2.add_symbol('a', 24, '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
83 o3 = l.link([o1, o2]) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
84 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
85 def testSymbolValues(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
86 l = Linker() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
87 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
88 o1.get_section('.text').add_data(bytes([0]*108)) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
89 o1.add_symbol('b', 24, '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
90 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
91 o2.get_section('.text').add_data(bytes([0]*100)) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
92 o2.add_symbol('a', 2, '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
93 o3 = l.link([o1, o2]) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
94 self.assertEqual(110, o3.find_symbol('a').value) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
95 self.assertEqual(24, o3.find_symbol('b').value) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
96 self.assertEqual(208, o3.get_section('.text').Size) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
97 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
98 def testMemoryLayout(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
99 l = Linker() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
100 memory_layout = {'.text': 0x08000000, '.data':0x20000000} |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
101 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
102 o1.get_section('.text').add_data(bytes([0]*108)) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
103 o1.add_symbol('b', 24, '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
104 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
105 o2.get_section('.text').add_data(bytes([0]*100)) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
106 o2.get_section('.data').add_data(bytes([0]*100)) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
107 o2.add_symbol('a', 2, '.data') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
108 o2.add_symbol('c', 2, '.text') |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
109 o3 = l.link([o1, o2], layout=memory_layout) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
110 self.assertEqual(0x20000000+2, o3.find_symbol('a').value) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
111 self.assertEqual(0x08000000+24, o3.find_symbol('b').value) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
112 self.assertEqual(0x08000000+110, o3.find_symbol('c').value) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
113 self.assertEqual(208, o3.get_section('.text').Size) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
114 self.assertEqual(100, o3.get_section('.data').Size) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
115 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
116 |
377 | 117 class ObjectFileTestCase(unittest.TestCase): |
118 def makeTwins(self): | |
119 o1 = ObjectFile() | |
120 o2 = ObjectFile() | |
121 o2.get_section('code').add_data(bytes(range(55))) | |
122 o1.get_section('code').add_data(bytes(range(55))) | |
123 o1.add_relocation('A', 0x2, 'imm12_dumm', 'code') | |
124 o2.add_relocation('A', 0x2, 'imm12_dumm', 'code') | |
125 o1.add_symbol('A2', 0x90, 'code') | |
126 o2.add_symbol('A2', 0x90, 'code') | |
127 o1.add_symbol('A3', 0x90, 'code') | |
128 o2.add_symbol('A3', 0x90, 'code') | |
129 return o1, o2 | |
130 | |
131 def testEquality(self): | |
132 o1, o2 = self.makeTwins() | |
133 self.assertEqual(o1, o2) | |
134 | |
135 def testSaveAndLoad(self): | |
136 o1, o2 = self.makeTwins() | |
137 f1 = io.StringIO() | |
138 o1.save(f1) | |
139 f2 = io.StringIO(f1.getvalue()) | |
140 o3 = load_object(f2) | |
141 self.assertEqual(o3, o1) | |
142 | |
143 def testSerialization(self): | |
144 o1, o2 = self.makeTwins() | |
145 o3 = deserialize(serialize(o1)) | |
146 self.assertEqual(o3, o1) | |
147 | |
148 | |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
149 if __name__ == '__main__': |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
150 unittest.main() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
151 sys.exit() |