Mercurial > hg > ede
annotate 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 |
rev | line source |
---|---|
jb302@34 | 1 #!/usr/bin/env python |
jb302@34 | 2 import struct |
jb302@34 | 3 from subprocess import Popen, PIPE, STDOUT |
jb302@34 | 4 from dbg import controller |
jb302@34 | 5 emu = controller() |
jb302@34 | 6 emu.Emu = Popen(['../../bin/emu'], stdout=PIPE, stdin=PIPE, stderr=PIPE) |
jb302@34 | 7 |
jb302@34 | 8 print 'testing register setting and getting...' |
jb302@34 | 9 # fill registers with their index number |
jb302@34 | 10 for r in range(16): |
jb302@34 | 11 emu.set_reg(r, r) |
jb302@34 | 12 # ask for them back |
jb302@34 | 13 regs = [] |
jb302@34 | 14 for r in range(16): |
jb302@34 | 15 regs.append(struct.unpack('>B', emu.get_reg(r))[0]) |
jb302@34 | 16 |
jb302@34 | 17 if set(regs) == set(range(16)): |
jb302@34 | 18 print 'passed' |
jb302@34 | 19 else: |
jb302@34 | 20 print 'failed' |
jb302@34 | 21 print regs |
jb302@34 | 22 |
jb302@34 | 23 print 'testing setting' |
jb302@34 | 24 for f in range(8): |
jb302@34 | 25 emu.set_flag(f, 1) |
jb302@34 | 26 |
jb302@34 | 27 if struct.unpack('>B', emu.get_flags())[0] == 0xFF: |
jb302@34 | 28 print 'passed' |
jb302@34 | 29 else: |
jb302@34 | 30 print 'failed' |
jb302@34 | 31 |
jb302@34 | 32 print 'clearing some flags and testing get flag function' |
jb302@34 | 33 for f in range(4): |
jb302@34 | 34 emu.set_flag(f, 0) |
jb302@34 | 35 |
jb302@34 | 36 if struct.unpack('>B', emu.get_flags())[0] == 0xF0: |
jb302@34 | 37 print 'passed' |
jb302@34 | 38 else: |
jb302@34 | 39 print 'failed' |
jb302@34 | 40 |
jb302@34 | 41 print 'fill entire memory space with SET C (0x08), execute the entire lot, and then check PC and IR...' |
jb302@34 | 42 blk = [0x08 for x in range(0xFFFF)] |
jb302@34 | 43 emu.set_block(0, 0, blk) |
jb302@34 | 44 rblk = emu.get_block(0x00, 0x00, 0xFF, 0xFF) |
jb302@34 | 45 ra = [struct.unpack('>B', c)[0] for c in rblk] |
jb302@34 | 46 emu.set_reg(14, 0) |
jb302@34 | 47 emu.set_reg(6, 0) |
jb302@34 | 48 emu.run_len(0xFF, 0xFF) |
jb302@34 | 49 |
jb302@34 | 50 if ( (struct.unpack('>B', emu.get_reg(14))[0] == 0xff) and \ |
jb302@34 | 51 (struct.unpack('>B', emu.get_reg(6))[0] == 0xff) and \ |
jb302@34 | 52 (struct.unpack('>B', emu.get_ir())[0] == 0x08) ): |
jb302@34 | 53 print 'passed' |
jb302@34 | 54 else: |
jb302@34 | 55 print 'failed' |
jb302@34 | 56 emu.Emu.kill() |