Esempio n. 1
0
def machine_mem_rw_test():
    mem = MockMemory()

    mem.w8(0x100, 42)
    assert mem.r8(0x100) == 42

    mem.w16(0x200, 0xDEAD)
    assert mem.r16(0x200) == 0xDEAD

    mem.w32(0x300, 0xCAFEBABE)
    assert mem.r32(0x300) == 0xCAFEBABE

    mem.write(0, 0x101, 43)
    assert mem.read(0, 0x101) == 43

    mem.write(1, 0x202, 0x1234)
    assert mem.read(1, 0x202) == 0x1234

    mem.write(2, 0x304, 0x11223344)
    assert mem.read(2, 0x304) == 0x11223344

    # invalid values
    with pytest.raises(ValueError):
        mem.w8(0x100, 0x100)
    with pytest.raises(ValueError):
        mem.w8(0x100, -1)
    # invalid values
    with pytest.raises(struct.error):
        mem.w16(0x100, 0x10000)
    with pytest.raises(struct.error):
        mem.w16(0x100, -2)
    # invalid values
    with pytest.raises(struct.error):
        mem.w32(0x100, 0x100000000)
    with pytest.raises(struct.error):
        mem.w32(0x100, -3)
    # invalid type
    with pytest.raises(TypeError):
        mem.w8(0x100, "hello")
    # invalid type
    with pytest.raises(struct.error):
        mem.w16(0x100, "hello")
    # invalid type
    with pytest.raises(struct.error):
        mem.w32(0x100, "hello")
    # invalid width
    with pytest.raises(ValueError):
        mem.write(7, 0x202, 12)
    with pytest.raises(ValueError):
        mem.read(7, 0x202)
Esempio n. 2
0
def mem_cache_rwx_read_test():
    mem = MockMemory()
    # build main mem contents
    mem.w8(0x100, 42)
    assert mem.r8(0x100) == 42
    mem.w16(0x200, 0xdead)
    assert mem.r16(0x200) == 0xdead
    mem.w32(0x300, 0xcafebabe)
    assert mem.r32(0x300) == 0xcafebabe
    mem.write(0, 0x101, 43)
    assert mem.read(0, 0x101) == 43
    mem.write(1, 0x202, 0x1234)
    assert mem.read(1, 0x202) == 0x1234
    mem.write(2, 0x304, 0x11223344)
    assert mem.read(2, 0x304) == 0x11223344
    # write to cache
    cmem = MemoryCache(0x100, 0x210)
    cmem.read_cache(mem)
    # check cache mem
    assert cmem.r8(0x100) == 42
    assert cmem.r16(0x200) == 0xdead
    assert cmem.r32(0x300) == 0xcafebabe
    assert cmem.read(0, 0x101) == 43
    assert cmem.read(1, 0x202) == 0x1234
    assert cmem.read(2, 0x304) == 0x11223344
Esempio n. 3
0
def mem_cache_rwx_read_test():
  mem = MockMemory()
  # build main mem contents
  mem.w8(0x100, 42)
  assert mem.r8(0x100) == 42
  mem.w16(0x200, 0xdead)
  assert mem.r16(0x200) == 0xdead
  mem.w32(0x300, 0xcafebabe)
  assert mem.r32(0x300) == 0xcafebabe
  mem.write(0, 0x101, 43)
  assert mem.read(0, 0x101) == 43
  mem.write(1, 0x202, 0x1234)
  assert mem.read(1, 0x202) == 0x1234
  mem.write(2, 0x304, 0x11223344)
  assert mem.read(2, 0x304) == 0x11223344
  # write to cache
  cmem = MemoryCache(0x100, 0x210)
  cmem.read_cache(mem)
  # check cache mem
  assert cmem.r8(0x100) == 42
  assert cmem.r16(0x200) == 0xdead
  assert cmem.r32(0x300) == 0xcafebabe
  assert cmem.read(0, 0x101) == 43
  assert cmem.read(1, 0x202) == 0x1234
  assert cmem.read(2, 0x304) == 0x11223344
Esempio n. 4
0
def machine_mem_rw_test():
  mem = MockMemory()

  mem.w8(0x100, 42)
  assert mem.r8(0x100) == 42

  mem.w16(0x200, 0xdead)
  assert mem.r16(0x200) == 0xdead

  mem.w32(0x300, 0xcafebabe)
  assert mem.r32(0x300) == 0xcafebabe

  mem.write(0, 0x101, 43)
  assert mem.read(0, 0x101) == 43

  mem.write(1, 0x202, 0x1234)
  assert mem.read(1, 0x202) == 0x1234

  mem.write(2, 0x304, 0x11223344)
  assert mem.read(2, 0x304) == 0x11223344

  # invalid values
  with pytest.raises(ValueError):
    mem.w8(0x100, 0x100)
  with pytest.raises(ValueError):
    mem.w8(0x100, -1)
  # invalid values
  with pytest.raises(struct.error):
    mem.w16(0x100, 0x10000)
  with pytest.raises(struct.error):
    mem.w16(0x100, -2)
  # invalid values
  with pytest.raises(struct.error):
    mem.w32(0x100, 0x100000000)
  with pytest.raises(struct.error):
    mem.w32(0x100, -3)
  # invalid type
  with pytest.raises(ValueError):
    mem.w8(0x100, 'hello')
  # invalid type
  with pytest.raises(struct.error):
    mem.w16(0x100, 'hello')
  # invalid type
  with pytest.raises(struct.error):
    mem.w32(0x100, 'hello')
  # invalid width
  with pytest.raises(ValueError):
    mem.write(7, 0x202, 12)
  with pytest.raises(ValueError):
    mem.read(7, 0x202)