Skip to content

Commit

Permalink
Merge 39f47e0 into a4dea0d
Browse files Browse the repository at this point in the history
  • Loading branch information
snim2 committed Jul 31, 2016
2 parents a4dea0d + 39f47e0 commit 9bb302d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
16 changes: 4 additions & 12 deletions revelation/condition_codes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
try:
from rpython.rlib.objectmodel import we_are_translated
except ImportError:
we_are_translated = lambda : False

from pydgin.misc import FatalError

def condition_passed(s, cond):
conditions = { 0b0000: s.AZ, # BEQ
Expand All @@ -22,11 +18,7 @@ def condition_passed(s, cond):
0b1110: True, # B (unconditional branch)
0b1111: True, # BL (branch and link)
}
if cond in conditions:
try:
return conditions[cond]
else:
if we_are_translated():
raise ValueError
else:
raise ValueError('Invalid condition, should be unreachable: ' +
str(bin(cond)))
except KeyError:
raise FatalError('Unknown condition code: %x' % cond)
5 changes: 3 additions & 2 deletions revelation/execute_interrupt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pydgin.misc import FatalError

from revelation.utils import trim_32
import revelation.isa

Expand Down Expand Up @@ -165,8 +167,7 @@ def execute_trap16(s, inst):
s.rf[0] = trim_32(retval)
s.rf[3] = errno
else:
print('WARNING: syscall not implemented: %d. Should be unreachable' %
inst.t5)
raise FatalError('Unknown argument to trap instruction: %d' % inst.t5)
s.pc += 2


Expand Down
4 changes: 3 additions & 1 deletion revelation/execute_load_store.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pydgin.misc import FatalError

from revelation.utils import trim_32


Expand Down Expand Up @@ -162,7 +164,7 @@ def testset32(s, inst):
The absolute address used for the test and set instruction must be located
within the on-chip local memory and must be greater than 0x00100000 (2^20).
""" % str(hex(address))
raise ValueError(fail_msg)
raise FatalError(fail_msg)
size = {0:1, 1:2, 2:4, 3:8}[inst.size] # Size in bytes.
value = s.mem.read(address, size, from_core=s.coreid)
if value:
Expand Down
20 changes: 11 additions & 9 deletions revelation/test/test_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,21 @@ def test_testset32():
expected.check(revelation.states[0], memory=[(0x100004, 4, 0xffff)])


def test_testset32_fail():
def test_testset32_fail(capfd):
"""Check that the testset32 instruction fails if the memory address it
is given is too low..
"""
elf_filename = os.path.join(elf_dir, 'testset_fail.elf')
expected_text = """testset32 has failed to write to address %s.
expected_text = """Exception in execution (pc: 0x00000358), aborting!
Exception message: testset32 has failed to write to address %s.
The absolute address used for the test and set instruction must be located
within the on-chip local memory and must be greater than 0x00100000 (2^20).
""" % str(hex(0x4))
with pytest.raises(ValueError) as expected_exn:
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 100000
revelation.run()
assert expected_text == expected_exn.value.message
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 100000
revelation.run()
out, err = capfd.readouterr()
assert err == ''
assert expected_text in out
4 changes: 3 additions & 1 deletion revelation/test/test_condition_passed.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pydgin.misc import FatalError

from revelation.condition_codes import condition_passed
from revelation.test.machine import new_state

Expand Down Expand Up @@ -47,5 +49,5 @@ def test_condition_passed():
assert condition_passed(state, 0b1101)
assert condition_passed(state, 0b1110)
assert condition_passed(state, 0b1111)
with pytest.raises(ValueError):
with pytest.raises(FatalError):
condition_passed(state, 0b11111)
16 changes: 8 additions & 8 deletions revelation/test/test_execute_interrupt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pydgin.misc import FatalError

from revelation.instruction import Instruction
from revelation.isa import decode
from revelation.machine import RESET_ADDR
Expand Down Expand Up @@ -124,18 +126,16 @@ def test_execute_trap16_assert_failure():
expected_state.check(state)


def test_execute_trap_warning(capsys):
def test_execute_trap_warning():
state = new_state()
instr = opcode_factory.trap16(trap=0b11111)
name, executefn = decode(instr)
executefn(state, Instruction(instr, None))
out, err = capsys.readouterr()
expected_state = StateChecker(pc=(2 + RESET_ADDR))
expected_text = ('WARNING: syscall not implemented: 31')
with pytest.raises(FatalError) as exninfo:
executefn(state, Instruction(instr, None))
expected_state = StateChecker(pc=RESET_ADDR)
expected_text = ('Unknown argument to trap instruction: 31')
expected_state.check(state)
assert expected_text in out
assert err == ''
assert state.running
assert expected_text == exninfo.value.msg


@pytest.mark.parametrize('name,instr', [('mbkpt16', opcode_factory.mbkpt16()),
Expand Down
10 changes: 6 additions & 4 deletions revelation/test/test_execute_load_store.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pydgin.misc import FatalError

from revelation.instruction import Instruction
from revelation.isa import decode
from revelation.test.machine import StateChecker, new_state
Expand Down Expand Up @@ -264,15 +266,15 @@ def test_testset32_nonzero():


def test_testset32_fail():
expected_text = """testset32 has failed to write to address %s.
expected_text = """testset32 has failed to write to address 0x4.
The absolute address used for the test and set instruction must be located
within the on-chip local memory and must be greater than 0x00100000 (2^20).
""" % str(hex(0x4))
"""
state = new_state(rf0=0, rf1=0x2, rf2=0x2)
size = 0b10 # Word
state.mem.write(0x00100004, 4, 0xffff)
instr = opcode_factory.testset32(rd=0, rn=1, rm=2, sub=0, bb=size)
name, executefn = decode(instr)
with pytest.raises(ValueError) as exninfo:
with pytest.raises(FatalError) as exninfo:
executefn(state, Instruction(instr, None))
assert expected_text == exninfo.value.message
assert expected_text == exninfo.value.msg

0 comments on commit 9bb302d

Please sign in to comment.