annotate test/testhexfile.py @ 314:38f5f298ce0e

Add log for interference graph
author Windel Bouwman
date Wed, 18 Dec 2013 20:22:20 +0100
parents e609d5296ee9
children b4ac28efcdf4
rev   line source
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
1 import unittest
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
2 import io
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
3 from utils import HexFile, HexFileException
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
4
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
5
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
6 class testHexFile(unittest.TestCase):
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
7 def saveload(self, hf):
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
8 f = io.StringIO()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
9 hf.save(f)
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
10 hf2 = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
11 hf2.load(io.StringIO(f.getvalue()))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
12 self.assertEqual(hf, hf2)
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
13
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
14 def testSave1(self):
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
15 hf = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
16 hf.addRegion(0x8000, bytes.fromhex('aabbcc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
17 self.saveload(hf)
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
18
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
19 def testSave2(self):
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
20 hf = HexFile()
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
21 hf.addRegion(0x8000, bytes.fromhex('aabbcc'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
22 hf.addRegion(0x118000, bytes.fromhex('aabbcc'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
23 self.saveload(hf)
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
24
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
25 def testSave3(self):
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
26 hf = HexFile()
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
27 hf.addRegion(0x8000, bytes.fromhex('aabbcc'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
28 hf.addRegion(0xFFFE, bytes.fromhex('aabbcc'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
29 self.saveload(hf)
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
30
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 292
diff changeset
31 @unittest.skip('Takes too long')
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
32 def testSave4(self):
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
33 hf = HexFile()
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 245
diff changeset
34 hf.addRegion(0xF000, bytes.fromhex('ab')*0x10000)
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
35 self.saveload(hf)
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
36
307
e609d5296ee9 Massive rewrite of codegenerator
Windel Bouwman
parents: 292
diff changeset
37 @unittest.skip('Takes too long')
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
38 def testSave5(self):
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
39 hf = HexFile()
251
6ed3d3a82a63 Added another c3 example. First import attempt
Windel Bouwman
parents: 245
diff changeset
40 hf.addRegion(0xF003, bytes.fromhex('ab')*0x10000)
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
41 self.saveload(hf)
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
42
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
43 def testTwoRegions(self):
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
44 hf = HexFile()
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
45 hf2 = HexFile()
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
46 hf.addRegion(0x100, bytes.fromhex('abcd'))
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
47 hf.addRegion(0x200, bytes.fromhex('beef'))
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
48 hf2.addRegion(0x200, bytes.fromhex('beef'))
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
49 hf2.addRegion(0x100, bytes.fromhex('abcd'))
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
50 self.assertEqual(hf, hf2)
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
51
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
52 def testMerge(self):
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
53 hf = HexFile()
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
54 hf.addRegion(0x10, bytes.fromhex('abcdab'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
55 hf.addRegion(0x13, bytes.fromhex('abcdab'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
56 self.assertEqual(1, len(hf.regions))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
57
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
58 def testOverlapped(self):
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
59 hf = HexFile()
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
60 hf.addRegion(0x10, bytes.fromhex('abcdab'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
61 with self.assertRaisesRegex(HexFileException, 'verlap'):
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
62 hf.addRegion(0x12, bytes.fromhex('abcdab'))
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
63
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
64 def testEqual(self):
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
65 hf1 = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
66 hf2 = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
67 hf1.addRegion(10, bytes.fromhex('aabbcc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
68 hf2.addRegion(10, bytes.fromhex('aabbcc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
69 self.assertEqual(hf1, hf2)
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
70
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
71 def testNotEqual(self):
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
72 hf1 = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
73 hf2 = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
74 hf1.addRegion(10, bytes.fromhex('aabbcc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
75 hf2.addRegion(10, bytes.fromhex('aabbdc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
76 self.assertNotEqual(hf1, hf2)
245
66912720d712 Added grinder
Windel Bouwman
parents: 244
diff changeset
77
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
78 def testNotEqual2(self):
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
79 hf1 = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
80 hf2 = HexFile()
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
81 hf1.addRegion(10, bytes.fromhex('aabbcc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
82 hf2.addRegion(10, bytes.fromhex('aabbcc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
83 hf2.addRegion(22, bytes.fromhex('aabbcc'))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
84 self.assertNotEqual(hf1, hf2)
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
85
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
86 def testLoad(self):
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
87 hf = HexFile()
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 284
diff changeset
88 dummyhex = """:01400000aa15"""
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
89 f = io.StringIO(dummyhex)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
90 hf.load(f)
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
91 self.assertEqual(1, len(hf.regions))
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
92 self.assertEqual(0x4000, hf.regions[0].address)
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
93 self.assertSequenceEqual(bytes.fromhex('aa'), hf.regions[0].data)
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
94
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
95 def testIncorrectCrc(self):
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
96 hf = HexFile()
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
97 txt = ":01400000aabb"
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
98 f = io.StringIO(txt)
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
99 with self.assertRaisesRegex(HexFileException, 'crc'):
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
100 hf.load(f)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
101
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
102 def testIncorrectLength(self):
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
103 hf = HexFile()
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
104 txt = ":0140002200aabb"
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
105 f = io.StringIO(txt)
244
58155c7c4a8e Add hexutil
Windel Bouwman
parents: 233
diff changeset
106 with self.assertRaisesRegex(HexFileException, 'count'):
233
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
107 hf.load(f)
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
108
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
109 if __name__ == '__main__':
d3dccf12ca88 Added hexfile tests
Windel Bouwman
parents:
diff changeset
110 unittest.main()