Mercurial > lcfOS
annotate test/testbintools.py @ 382:0c44e494ef58
Made lexer more generic
author | Windel Bouwman |
---|---|
date | Sun, 27 Apr 2014 12:24:21 +0200 |
parents | 6df89163e114 |
children | 173e20a47fda |
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 | |
381 | 10 from ppci.buildfunctions import link |
342 | 11 |
12 | |
13 class TaskTestCase(unittest.TestCase): | |
377 | 14 @unittest.skip('api change') |
342 | 15 def testCircular(self): |
16 t1 = EmptyTask('t1') | |
17 t2 = EmptyTask('t2') | |
18 t1.add_dependency(t2) | |
19 with self.assertRaises(TaskError): | |
20 t2.add_dependency(t1) | |
21 | |
377 | 22 @unittest.skip('api change') |
342 | 23 def testCircularDeeper(self): |
24 t1 = EmptyTask('t1') | |
25 t2 = EmptyTask('t2') | |
26 t3 = EmptyTask('t3') | |
27 t1.add_dependency(t2) | |
28 t2.add_dependency(t3) | |
29 with self.assertRaises(TaskError): | |
30 t3.add_dependency(t1) | |
31 | |
377 | 32 @unittest.skip('api change') |
342 | 33 def testSort(self): |
34 t1 = EmptyTask('t1') | |
35 t2 = EmptyTask('t2') | |
36 runner = TaskRunner() | |
37 t1.add_dependency(t2) | |
38 runner.add_task(t1) | |
39 runner.add_task(t2) | |
40 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
|
41 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
42 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
43 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
|
44 def testSetBits(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
45 at = ArmToken() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
46 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
|
47 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
|
48 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
49 def testSetBits(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
50 at = ArmToken() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
51 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
|
52 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
|
53 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
54 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
55 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
|
56 def testUndefinedReference(self): |
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): |
381 | 62 o3 = link([o1, o2], {}) |
336
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 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
66 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
|
67 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
|
68 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
69 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
|
70 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
|
71 with self.assertRaises(CompilerError): |
381 | 72 o3 = link([o1, o2], {}) |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
73 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
74 def testRel8Relocation(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
75 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
76 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
|
77 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
|
78 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
79 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
|
80 o2.add_symbol('a', 24, '.text') |
381 | 81 o3 = link([o1, o2], {}) |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
82 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
83 def testSymbolValues(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
84 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
85 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
|
86 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
|
87 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
88 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
|
89 o2.add_symbol('a', 2, '.text') |
381 | 90 o3 = link([o1, o2], {}) |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
95 def testMemoryLayout(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
96 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
|
97 o1 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
98 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
|
99 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
|
100 o2 = ObjectFile() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 o2.add_symbol('c', 2, '.text') |
381 | 105 o3 = link([o1, o2], memory_layout) |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
112 |
377 | 113 class ObjectFileTestCase(unittest.TestCase): |
114 def makeTwins(self): | |
115 o1 = ObjectFile() | |
116 o2 = ObjectFile() | |
117 o2.get_section('code').add_data(bytes(range(55))) | |
118 o1.get_section('code').add_data(bytes(range(55))) | |
119 o1.add_relocation('A', 0x2, 'imm12_dumm', 'code') | |
120 o2.add_relocation('A', 0x2, 'imm12_dumm', 'code') | |
121 o1.add_symbol('A2', 0x90, 'code') | |
122 o2.add_symbol('A2', 0x90, 'code') | |
123 o1.add_symbol('A3', 0x90, 'code') | |
124 o2.add_symbol('A3', 0x90, 'code') | |
125 return o1, o2 | |
126 | |
127 def testEquality(self): | |
128 o1, o2 = self.makeTwins() | |
129 self.assertEqual(o1, o2) | |
130 | |
131 def testSaveAndLoad(self): | |
132 o1, o2 = self.makeTwins() | |
133 f1 = io.StringIO() | |
134 o1.save(f1) | |
135 f2 = io.StringIO(f1.getvalue()) | |
136 o3 = load_object(f2) | |
137 self.assertEqual(o3, o1) | |
138 | |
139 def testSerialization(self): | |
140 o1, o2 = self.makeTwins() | |
141 o3 = deserialize(serialize(o1)) | |
142 self.assertEqual(o3, o1) | |
143 | |
144 | |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
145 if __name__ == '__main__': |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
146 unittest.main() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff
changeset
|
147 sys.exit() |