예제 #1
0
def libnative_mgr_test(buildlibnix):
  if buildlibnix.flavor not in ('gcc', 'gcc-dbg'):
    pytest.skip("only single base lib supported")
  log_libmgr.setLevel(logging.INFO)
  machine, alloc, sp, mem, exec_lib = setup()
  # load
  lib_file = buildlibnix.make_lib('testnix')

  class PathMgrMock:
    def ami_to_sys_path(self, lock, ami_path, mustExist=True):
      if ami_path == 'LIBS:testnix.library':
        return lib_file

  pm = PathMgrMock()
  segload = SegmentLoader(alloc, pm)
  mgr = ALibManager(machine, alloc, segload)
  # open_lib
  lib_base = mgr.open_lib("testnix.library", run_sp=sp)
  assert lib_base > 0
  assert mgr.is_base_addr(lib_base)
  lib_info = mgr.get_lib_info_for_name("testnix.library")
  assert lib_info
  assert lib_info.is_base_addr(lib_base)
  # close lib
  seglist = mgr.close_lib(lib_base, run_sp=sp)
  assert seglist == 0
  lib_info = mgr.get_lib_info_for_name("testnix.library")
  assert lib_info
  assert not lib_info.is_base_addr(lib_base)
  # expunge lib
  left = mgr.shutdown(run_sp=sp)
  assert left == 0
  assert not mgr.is_base_addr(lib_base)
  lib_info = mgr.get_lib_info_for_name("testnix.library")
  assert not lib_info
  # we have to manually clean the lib here (as Exec FreeMem() does not work)
  lib = Library(mem, lib_base, alloc)
  lib.free()
  # cleanup
  exec_lib.free()
  assert alloc.is_all_free()
예제 #2
0
def libnative_mgr_test(buildlibnix):
    if buildlibnix.flavor not in ("gcc", "gcc-dbg"):
        pytest.skip("only single base lib supported")
    log_libmgr.setLevel(logging.INFO)
    machine, alloc, sp, mem, exec_lib = setup()
    # load
    lib_file = buildlibnix.make_lib("testnix")

    class PathMgrMock:
        def ami_to_sys_path(self, lock, ami_path, mustExist=True):
            if ami_path == "LIBS:testnix.library":
                return lib_file

    pm = PathMgrMock()
    segload = SegmentLoader(alloc, pm)
    mgr = ALibManager(machine, alloc, segload)
    # open_lib
    lib_base = mgr.open_lib("testnix.library", run_sp=sp)
    assert lib_base > 0
    assert mgr.is_base_addr(lib_base)
    lib_info = mgr.get_lib_info_for_name("testnix.library")
    assert lib_info
    assert lib_info.is_base_addr(lib_base)
    assert lib_info.get_lib_fd()
    # close lib
    seglist = mgr.close_lib(lib_base, run_sp=sp)
    assert seglist == 0
    lib_info = mgr.get_lib_info_for_name("testnix.library")
    assert lib_info
    assert not lib_info.is_base_addr(lib_base)
    # expunge lib
    left = mgr.shutdown(run_sp=sp)
    assert left == 0
    assert not mgr.is_base_addr(lib_base)
    lib_info = mgr.get_lib_info_for_name("testnix.library")
    assert not lib_info
    # we have to manually clean the lib here (as Exec FreeMem() does not work)
    free_lib(mem, alloc, lib_base)
    # cleanup
    exec_lib.free()
    assert alloc.is_all_free()
예제 #3
0
def setup(path_mgr=None):
    log_libmgr.setLevel(logging.INFO)
    log_exec.setLevel(logging.INFO)
    machine = Machine()
    # machine.show_instr(True)
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)
    segloader = SegmentLoader(alloc, path_mgr)
    cfg = LibMgrCfg()
    mgr = LibManager(machine, alloc, segloader, cfg)
    # setup ctx map
    cpu = machine.get_cpu()
    mem = machine.get_mem()
    cpu_type = machine.get_cpu_type()
    exec_ctx = ExecLibCtx(machine, alloc, segloader, path_mgr, mgr)
    mgr.add_ctx("exec.library", exec_ctx)
    mgr.add_impl_cls("exec.library", ExecLibrary)
    dos_ctx = DosLibCtx(machine, alloc, segloader, path_mgr, None, None)
    mgr.add_ctx("dos.library", dos_ctx)
    mgr.add_impl_cls("dos.library", DosLibrary)
    mgr.add_impl_cls("vamostest.library", VamosTestLibrary)
    mgr.add_impl_cls("vamostestdev.device", VamosTestDevice)
    return machine, alloc, mgr, sp, cfg
예제 #4
0
def setup(path_mgr=None):
  log_libmgr.setLevel(logging.INFO)
  log_exec.setLevel(logging.INFO)
  machine = Machine()
  # machine.show_instr(True)
  sp = machine.get_ram_begin() - 4
  alloc = MemoryAlloc.for_machine(machine)
  segloader = SegmentLoader(alloc, path_mgr)
  cfg = LibMgrCfg()
  mgr = LibManager(machine, alloc, segloader, cfg)
  # setup ctx map
  cpu = machine.get_cpu()
  mem = machine.get_mem()
  cpu_type = machine.get_cpu_type()
  exec_ctx = ExecLibCtx(machine, alloc, segloader, path_mgr)
  mgr.add_ctx('exec.library', exec_ctx)
  mgr.add_impl_cls('exec.library', ExecLibrary)
  dos_ctx = DosLibCtx(machine, alloc, segloader, path_mgr, None, None)
  mgr.add_ctx('dos.library', dos_ctx)
  mgr.add_impl_cls('dos.library', DosLibrary)
  mgr.add_impl_cls('vamostest.library', VamosTestLibrary)
  mgr.add_impl_cls('vamostestdev.device', VamosTestDevice)
  return machine, alloc, mgr, sp, cfg