annotate test/testbintools.py @ 342:86b02c98a717 devel

Moved target directory
author Windel Bouwman
date Sat, 01 Mar 2014 15:40:31 +0100
parents d1ecc493384e
children 9667d78ba79e
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
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
3 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
4 from ppci.linker import Linker
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
5 from ppci.objectfile import ObjectFile
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
6 from ppci import CompilerError
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
7 from ppci.tasks import EmptyTask, TaskRunner, TaskError
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
8
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
9
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
10 class TaskTestCase(unittest.TestCase):
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
11 def testCircular(self):
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
12 t1 = EmptyTask('t1')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
13 t2 = EmptyTask('t2')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
14 t1.add_dependency(t2)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
15 with self.assertRaises(TaskError):
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
16 t2.add_dependency(t1)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
17
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
18 def testCircularDeeper(self):
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
19 t1 = EmptyTask('t1')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
20 t2 = EmptyTask('t2')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
21 t3 = EmptyTask('t3')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
22 t1.add_dependency(t2)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
23 t2.add_dependency(t3)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
24 with self.assertRaises(TaskError):
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
25 t3.add_dependency(t1)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
26
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
27 def testSort(self):
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
28 t1 = EmptyTask('t1')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
29 t2 = EmptyTask('t2')
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
30 runner = TaskRunner()
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
31 t1.add_dependency(t2)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
32 runner.add_task(t1)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
33 runner.add_task(t2)
86b02c98a717 Moved target directory
Windel Bouwman
parents: 336
diff changeset
34 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
35
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
36
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
37 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
38 def testSetBits(self):
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
39 at = ArmToken()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
40 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
41 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
42
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[4:8] = 0b1100
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
46 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
47
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 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
50 def testUndefinedReference(self):
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
51 l = Linker()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
52 o1 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
53 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
54 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
55 o2 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
56 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
57 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
58
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
59 def testDuplicateSymbol(self):
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
60 l = Linker()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
61 o1 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
62 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
63 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
64 o2 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
65 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
66 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
67 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
68 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
69
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
70 def testRel8Relocation(self):
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
71 l = Linker()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
72 o1 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
73 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
74 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
75 o2 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
76 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
77 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
78 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
79
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
80 def testSymbolValues(self):
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
81 l = Linker()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
82 o1 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
83 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
84 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
85 o2 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
86 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
87 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
88 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
89 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
90 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
91 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
92
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
93 def testMemoryLayout(self):
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
94 l = Linker()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
95 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
96 o1 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
97 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
98 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
99 o2 = ObjectFile()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109 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
110
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 if __name__ == '__main__':
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
113 unittest.main()
d1ecc493384e Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
diff changeset
114 sys.exit()