def setUp(self): self.ctx = addrxlat.Context() def first_step(step, addr): step.base = addrxlat.FullAddress(addrxlat.NOADDR, 0xabcdef) step.idx = (addr & 0xff, addr >> 8) step.remain = 2 def next_step(step): step.base.addr = 0x123456 + step.idx[1] step.elemsz = 0x100 self.meth = addrxlat.CustomMethod() self.meth.target_as = addrxlat.KPHYSADDR self.meth.cb_first_step = first_step self.meth.cb_next_step = next_step import _test_addrxlat self.meth_ext = _test_addrxlat.getCustomMethod(addrxlat.convert) self.assertEqual(self.meth_ext.kind, addrxlat.CUSTOM) self.assertEqual(self.meth_ext.target_as, addrxlat.NOADDR) self.meth_ext.target_as = addrxlat.KPHYSADDR self.meth_extmod = _test_addrxlat.getCustomMethod(addrxlat.convert) self.meth_extmod.target_as = addrxlat.KPHYSADDR self.meth_extmod.cb_next_step = next_step
def test_err(self): ctx = addrxlat.Context() ctx.clear_err() self.assertIs(ctx.get_err(), None) status = ctx.err(addrxlat.ERR_CUSTOM_BASE, 'An error message') self.assertEqual(status, addrxlat.ERR_CUSTOM_BASE) self.assertEqual(ctx.get_err(), 'An error message') ctx.clear_err() self.assertIs(ctx.get_err(), None)
def test_custom_notimpl(self): meth = addrxlat.CustomMethod(addrxlat.MACHPHYSADDR) self.assertEqual(meth.kind, addrxlat.CUSTOM) self.assertEqual(meth.target_as, addrxlat.MACHPHYSADDR) ctx = addrxlat.Context() step = addrxlat.Step(ctx=ctx, meth=meth) with self.assertRaisesRegexp(BaseException, "NULL callback"): meth.cb_first_step(step, 0x1234) with self.assertRaisesRegexp(BaseException, "NULL callback"): meth.cb_next_step(step)
def setUp(self): def read32(addr): # Page table level 2 @ 0 if addr.addr == 0x10000: return 0x101 # Page table level 1 @ 0x65 if addr.addr == 0x10100 + 0x65 * 4: return 0x1c0 # Page table level 1 @ 0x41 if addr.addr == 0x10100 + 0x41 * 4: return 0x1a9 # Memory array at 0x40 if addr.addr == 0x11000 + 0x40 * 4: return 0xaa self.ctx = addrxlat.Context() self.ctx.read_caps = addrxlat.CAPS(addrxlat.MACHPHYSADDR) self.ctx.cb_read32 = read32 self.sys = addrxlat.System() map = addrxlat.Map() self.sys.set_map(addrxlat.SYS_MAP_HW, map) meth = addrxlat.PageTableMethod(addrxlat.MACHPHYSADDR) meth.root = addrxlat.FullAddress(addrxlat.MACHPHYSADDR, 0x10000) meth.pte_format = addrxlat.PTE_PFN32 meth.fields = (8, 8, 8) self.sys.set_meth(addrxlat.SYS_METH_PGT, meth) map.set(0, addrxlat.Range(0xffff, addrxlat.SYS_METH_PGT)) map = addrxlat.Map() self.sys.set_map(addrxlat.SYS_MAP_KV_PHYS, map) meth = addrxlat.LinearMethod(addrxlat.KPHYSADDR, 0x1000) self.sys.set_meth(addrxlat.SYS_METH_DIRECT, meth) map.set(0, addrxlat.Range(0x1fff, addrxlat.SYS_METH_DIRECT)) meth = addrxlat.LookupMethod(addrxlat.KPHYSADDR) meth.endoff = 0xff meth.tbl = ((0x2000, 0xfa00), (0x3000, 0xfb00), (0x3100, 0xff00)) self.sys.set_meth(addrxlat.SYS_METH_CUSTOM, meth) map.set(0x2000, addrxlat.Range(0x1fff, addrxlat.SYS_METH_CUSTOM)) meth = addrxlat.MemoryArrayMethod(addrxlat.KPHYSADDR) meth.base = addrxlat.FullAddress(addrxlat.KVADDR, 0) meth.shift = 8 meth.elemsz = 4 meth.valsz = 4 self.sys.set_meth(addrxlat.SYS_METH_CUSTOM + 1, meth) map.set(0x4000, addrxlat.Range(0x1fff, addrxlat.SYS_METH_CUSTOM + 1)) map.set(0x6000, addrxlat.Range(0x9fff, addrxlat.SYS_METH_PGT)) map = addrxlat.Map() self.sys.set_map(addrxlat.SYS_MAP_KPHYS_DIRECT, map) meth = addrxlat.LinearMethod(addrxlat.KVADDR, -0x1000) self.sys.set_meth(addrxlat.SYS_METH_RDIRECT, meth) map.set(0x1000, addrxlat.Range(0x1fff, addrxlat.SYS_METH_RDIRECT)) map = addrxlat.Map() self.sys.set_map(addrxlat.SYS_MAP_MACHPHYS_KPHYS, map) meth = addrxlat.LinearMethod(addrxlat.KPHYSADDR, -0x10000) self.sys.set_meth(addrxlat.SYS_METH_MACHPHYS_KPHYS, meth) map.set(0x10000, addrxlat.Range(0xffff, addrxlat.SYS_METH_MACHPHYS_KPHYS)) map = addrxlat.Map() self.sys.set_map(addrxlat.SYS_MAP_KPHYS_MACHPHYS, map) meth = addrxlat.LinearMethod(addrxlat.MACHPHYSADDR, 0x10000) self.sys.set_meth(addrxlat.SYS_METH_KPHYS_MACHPHYS, meth) map.set(0, addrxlat.Range(0xffff, addrxlat.SYS_METH_KPHYS_MACHPHYS))
def setUp(self): self.ctx = addrxlat.Context()
def get_addrxlat_ctx(self): return addrxlat.Context()