Esempio n. 1
0
def machine_mockcpu_rws_reg_test():
  cpu = MockCPU()
  cpu.ws_reg(REG_D0, -23)
  assert cpu.rs_reg(REG_D0) == -23
  # invalid values
  with pytest.raises(OverflowError):
    cpu.ws_reg(REG_D0, 0x80000000)
  with pytest.raises(OverflowError):
    cpu.ws_reg(REG_D0, -0x80000001)
  with pytest.raises(TypeError):
    cpu.ws_reg(REG_D0, 'hello, world!')
Esempio n. 2
0
def astructs_astruct_base_inst_reg_test():
    cpu = MockCPU()
    mem = MockMemory()
    ms = MyStruct(mem, 0x10)
    ms.ms_Word.val = 42
    # prepare pointer
    cpu.w_reg(REG_D0, 0x10)
    MyStructAPtr = APTR(MyStruct)
    ptr = MyStructAPtr(cpu=cpu, reg=REG_D0, mem=mem)
    assert ptr.aptr == 0x10
    ms2 = ptr.ref
    assert ms2.ms_Word.val == 42
Esempio n. 3
0
def setup():
    mem = MockMemory(fill=23)
    traps = MockTraps()
    cpu = MockCPU()
    alloc = MemoryAlloc(mem)
    ctx = LibCtx(cpu, mem)
    return mem, traps, alloc, ctx
Esempio n. 4
0
from amitools.vamos.astructs.typebase import TypeBase
from amitools.vamos.astructs.array import ARRAY, ArrayIter
from amitools.vamos.astructs.scalar import ULONG
from amitools.vamos.machine import MockMemory, MockCPU, REG_D0

cpu = MockCPU()
mem = MockMemory()


def astructs_array_test():
    ULONG_ARRAY = ARRAY(ULONG, 10)
    a = ULONG_ARRAY(mem, 0x40)
    assert a.get_array_size() == 10
    assert a.get_element_type() is ULONG
    assert a.get_byte_size() == 10 * 4
    e = a.get(0)
    assert type(e) is ULONG
    e.set(0xDEAD)
    assert mem.r32(0x40) == 0xDEAD
    e = a.get(9)
    e.set(0x1234)
    assert mem.r32(0x40 + 9 * 4) == 0x1234
    # signature
    assert a.get_signature() == "ULONG[10]"
    # access entry value
    a[0].val = 23
    assert a[0].val == 23
    assert a.get(0).val == 23


def astructs_array_iter_test():
Esempio n. 5
0
def _create_ctx():
    cpu = MockCPU()
    mem = MockMemory()
    return LibCtx(cpu, mem)
Esempio n. 6
0
def machine_mockcpu_rw_reg_test():
    cpu = MockCPU()
    cpu.w_reg(REG_D0, 0xDEADBEEF)
    assert cpu.r_reg(REG_D0) == 0xDEADBEEF
    cpu.w_reg(REG_A6, 0xCAFEBABE)
    assert cpu.r_reg(REG_A6) == 0xCAFEBABE
    cpu.w_pc(0x123456)
    assert cpu.r_pc() == 0x123456
    cpu.w_sr(0x4711)
    assert cpu.r_sr() == 0x4711
    # invalid values
    with pytest.raises(OverflowError):
        cpu.w_reg(REG_D0, 0xDEAFBEEF12)
    with pytest.raises(OverflowError):
        cpu.w_reg(REG_D0, -1)
    with pytest.raises(TypeError):
        cpu.w_reg(REG_D0, "hello, world!")
Esempio n. 7
0
def machine_mockcpu_rws_reg_test():
    cpu = MockCPU()
    cpu.ws_reg(REG_D0, -23)
    assert cpu.rs_reg(REG_D0) == -23
    # invalid values
    with pytest.raises(OverflowError):
        cpu.ws_reg(REG_D0, 0x80000000)
    with pytest.raises(OverflowError):
        cpu.ws_reg(REG_D0, -0x80000001)
    with pytest.raises(TypeError):
        cpu.ws_reg(REG_D0, "hello, world!")
Esempio n. 8
0
def machine_mockcpu_rw_reg_test():
    cpu = MockCPU()
    cpu.w_reg(REG_D0, 0xdeadbeef)
    assert cpu.r_reg(REG_D0) == 0xdeadbeef
    cpu.w_reg(REG_A6, 0xcafebabe)
    assert cpu.r_reg(REG_A6) == 0xcafebabe
    cpu.w_pc(0x123456)
    assert cpu.r_pc() == 0x123456
    cpu.w_sr(0x4711)
    assert cpu.r_sr() == 0x4711
    # invalid values
    with pytest.raises(OverflowError):
        cpu.w_reg(REG_D0, 0xdeafbeef12)
    with pytest.raises(OverflowError):
        cpu.w_reg(REG_D0, -1)
    with pytest.raises(TypeError):
        cpu.w_reg(REG_D0, 'hello, world!')
Esempio n. 9
0
def machine_mockcpu_rw_reg_test():
  cpu = MockCPU()
  cpu.w_reg(REG_D0, 0xdeadbeef)
  assert cpu.r_reg(REG_D0) == 0xdeadbeef
  cpu.w_reg(REG_A6, 0xcafebabe)
  assert cpu.r_reg(REG_A6) == 0xcafebabe
  cpu.w_pc(0x123456)
  assert cpu.r_pc() == 0x123456
  cpu.w_sr(0x4711)
  assert cpu.r_sr() == 0x4711
  # invalid values
  with pytest.raises(OverflowError):
    cpu.w_reg(REG_D0, 0xdeafbeef12)
  with pytest.raises(OverflowError):
    cpu.w_reg(REG_D0, -1)
  with pytest.raises(TypeError):
    cpu.w_reg(REG_D0, 'hello, world!')