view tests/dbg/test_dbg.py @ 42:792da050d8c4 tip

more dox
author james <jb302@eecs.qmul.ac.uk>
date Tue, 22 Apr 2014 14:25:14 +0100
parents 4411dee34085
children
line wrap: on
line source
#!/usr/bin/env python
import struct
from subprocess import Popen, PIPE, STDOUT
from dbg import controller
emu = controller()
emu.Emu = Popen(['../../bin/emu'], stdout=PIPE, stdin=PIPE, stderr=PIPE)

print 'testing register setting and getting...'
# fill registers with their index number
for r in range(16):
    emu.set_reg(r, r)
# ask for them back
regs = []
for r in range(16):
    regs.append(struct.unpack('>B', emu.get_reg(r))[0])

if set(regs) == set(range(16)):
    print 'passed'
else:
    print 'failed'
    print regs

print 'testing setting'
for f in range(8):
    emu.set_flag(f, 1)

if struct.unpack('>B', emu.get_flags())[0] == 0xFF:
    print 'passed'
else:
    print 'failed'

print 'clearing some flags and testing get flag function'
for f in range(4):
    emu.set_flag(f, 0)

if struct.unpack('>B', emu.get_flags())[0] == 0xF0:
    print 'passed'
else:
    print 'failed'
 
print 'fill entire memory space with SET C (0x08), execute the entire lot, and then check PC and IR...'
blk = [0x08 for x in range(0xFFFF)]
emu.set_block(0, 0, blk)
rblk = emu.get_block(0x00, 0x00, 0xFF, 0xFF)
ra = [struct.unpack('>B', c)[0] for c in rblk]
emu.set_reg(14, 0)
emu.set_reg(6, 0)
emu.run_len(0xFF, 0xFF)

if ( (struct.unpack('>B', emu.get_reg(14))[0] == 0xff) and \
        (struct.unpack('>B', emu.get_reg(6))[0] == 0xff) and \
        (struct.unpack('>B', emu.get_ir())[0] == 0x08) ):
    print 'passed'
else:
    print 'failed'
emu.Emu.kill()