comparison tests/dbg/test_dbg.py @ 34:4411dee34085

cleaned out docs (don't worry they are comming back) and added all my test files
author james <jb302@eecs.qmul.ac.uk>
date Wed, 16 Apr 2014 16:51:39 +0100
parents
children
comparison
equal deleted inserted replaced
33:02241452f397 34:4411dee34085
1 #!/usr/bin/env python
2 import struct
3 from subprocess import Popen, PIPE, STDOUT
4 from dbg import controller
5 emu = controller()
6 emu.Emu = Popen(['../../bin/emu'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
7
8 print 'testing register setting and getting...'
9 # fill registers with their index number
10 for r in range(16):
11 emu.set_reg(r, r)
12 # ask for them back
13 regs = []
14 for r in range(16):
15 regs.append(struct.unpack('>B', emu.get_reg(r))[0])
16
17 if set(regs) == set(range(16)):
18 print 'passed'
19 else:
20 print 'failed'
21 print regs
22
23 print 'testing setting'
24 for f in range(8):
25 emu.set_flag(f, 1)
26
27 if struct.unpack('>B', emu.get_flags())[0] == 0xFF:
28 print 'passed'
29 else:
30 print 'failed'
31
32 print 'clearing some flags and testing get flag function'
33 for f in range(4):
34 emu.set_flag(f, 0)
35
36 if struct.unpack('>B', emu.get_flags())[0] == 0xF0:
37 print 'passed'
38 else:
39 print 'failed'
40
41 print 'fill entire memory space with SET C (0x08), execute the entire lot, and then check PC and IR...'
42 blk = [0x08 for x in range(0xFFFF)]
43 emu.set_block(0, 0, blk)
44 rblk = emu.get_block(0x00, 0x00, 0xFF, 0xFF)
45 ra = [struct.unpack('>B', c)[0] for c in rblk]
46 emu.set_reg(14, 0)
47 emu.set_reg(6, 0)
48 emu.run_len(0xFF, 0xFF)
49
50 if ( (struct.unpack('>B', emu.get_reg(14))[0] == 0xff) and \
51 (struct.unpack('>B', emu.get_reg(6))[0] == 0xff) and \
52 (struct.unpack('>B', emu.get_ir())[0] == 0x08) ):
53 print 'passed'
54 else:
55 print 'failed'
56 emu.Emu.kill()