Mercurial > lcfOS
comparison test/testbintools.py @ 336:d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
author | Windel Bouwman |
---|---|
date | Wed, 19 Feb 2014 22:32:15 +0100 |
parents | |
children | 86b02c98a717 |
comparison
equal
deleted
inserted
replaced
335:582a1aaa3983 | 336:d1ecc493384e |
---|---|
1 import unittest | |
2 import sys | |
3 from target.arminstructions import ArmToken | |
4 from ppci.linker import Linker | |
5 from ppci.objectfile import ObjectFile | |
6 from ppci import CompilerError | |
7 | |
8 | |
9 class TokenTestCase(unittest.TestCase): | |
10 def testSetBits(self): | |
11 at = ArmToken() | |
12 at[2:4] = 0b11 | |
13 self.assertEqual(0xc, at.bit_value) | |
14 | |
15 def testSetBits(self): | |
16 at = ArmToken() | |
17 at[4:8] = 0b1100 | |
18 self.assertEqual(0xc0, at.bit_value) | |
19 | |
20 | |
21 class LinkerTestCase(unittest.TestCase): | |
22 def testUndefinedReference(self): | |
23 l = Linker() | |
24 o1 = ObjectFile() | |
25 o1.get_section('.text') | |
26 o1.add_relocation('undefined_sym', 0, 'rel8', '.text') | |
27 o2 = ObjectFile() | |
28 with self.assertRaises(CompilerError): | |
29 o3 = l.link([o1, o2]) | |
30 | |
31 def testDuplicateSymbol(self): | |
32 l = Linker() | |
33 o1 = ObjectFile() | |
34 o1.get_section('.text') | |
35 o1.add_symbol('a', 0, '.text') | |
36 o2 = ObjectFile() | |
37 o2.get_section('.text') | |
38 o2.add_symbol('a', 0, '.text') | |
39 with self.assertRaises(CompilerError): | |
40 o3 = l.link([o1, o2]) | |
41 | |
42 def testRel8Relocation(self): | |
43 l = Linker() | |
44 o1 = ObjectFile() | |
45 o1.get_section('.text').add_data(bytes([0]*100)) | |
46 o1.add_relocation('a', 0, 'rel8', '.text') | |
47 o2 = ObjectFile() | |
48 o2.get_section('.text').add_data(bytes([0]*100)) | |
49 o2.add_symbol('a', 24, '.text') | |
50 o3 = l.link([o1, o2]) | |
51 | |
52 def testSymbolValues(self): | |
53 l = Linker() | |
54 o1 = ObjectFile() | |
55 o1.get_section('.text').add_data(bytes([0]*108)) | |
56 o1.add_symbol('b', 24, '.text') | |
57 o2 = ObjectFile() | |
58 o2.get_section('.text').add_data(bytes([0]*100)) | |
59 o2.add_symbol('a', 2, '.text') | |
60 o3 = l.link([o1, o2]) | |
61 self.assertEqual(110, o3.find_symbol('a').value) | |
62 self.assertEqual(24, o3.find_symbol('b').value) | |
63 self.assertEqual(208, o3.get_section('.text').Size) | |
64 | |
65 def testMemoryLayout(self): | |
66 l = Linker() | |
67 memory_layout = {'.text': 0x08000000, '.data':0x20000000} | |
68 o1 = ObjectFile() | |
69 o1.get_section('.text').add_data(bytes([0]*108)) | |
70 o1.add_symbol('b', 24, '.text') | |
71 o2 = ObjectFile() | |
72 o2.get_section('.text').add_data(bytes([0]*100)) | |
73 o2.get_section('.data').add_data(bytes([0]*100)) | |
74 o2.add_symbol('a', 2, '.data') | |
75 o2.add_symbol('c', 2, '.text') | |
76 o3 = l.link([o1, o2], layout=memory_layout) | |
77 self.assertEqual(0x20000000+2, o3.find_symbol('a').value) | |
78 self.assertEqual(0x08000000+24, o3.find_symbol('b').value) | |
79 self.assertEqual(0x08000000+110, o3.find_symbol('c').value) | |
80 self.assertEqual(208, o3.get_section('.text').Size) | |
81 self.assertEqual(100, o3.get_section('.data').Size) | |
82 | |
83 | |
84 if __name__ == '__main__': | |
85 unittest.main() | |
86 sys.exit() |