Ejemplo n.º 1
0
def setup_tm():
  machine = MockMachine()
  lm = machine.get_label_mgr()
  tm = TraceManager(machine)
  lm.add_label(LabelRange("range", 0x100, 0x100))
  lm.add_label(LabelStruct("node", 0x200, NodeStruct))
  lm.add_label(LabelLib("fake.library", 0x320, 0x20,
                        LibraryStruct.get_size(), LibraryStruct))
  fd = read_lib_fd("vamostest.library")
  neg_size = fd.get_neg_size()
  lm.add_label(LabelLib("vamostest.library", 0x400, neg_size,
                        LibraryStruct.get_size(), LibraryStruct, fd))
  return tm
Ejemplo n.º 2
0
def setup_tm():
    machine = MockMachine()
    lm = machine.get_label_mgr()
    tm = TraceManager(machine)
    lm.add_label(LabelRange("range", 0x100, 0x100))
    lm.add_label(LabelStruct("node", 0x200, NodeStruct))
    lm.add_label(
        LabelLib("fake.library", 0x320, 0x20, LibraryStruct.get_size(),
                 LibraryStruct))
    fd = read_lib_fd("vamostest.library")
    neg_size = fd.get_neg_size()
    lm.add_label(
        LabelLib("vamostest.library", 0x400, neg_size,
                 LibraryStruct.get_size(), LibraryStruct, fd))
    return tm
Ejemplo n.º 3
0
def libnative_makelib_test():
    machine = Machine()
    mem = machine.get_mem()
    sp = machine.get_ram_begin() - 4
    alloc = MemoryAlloc.for_machine(machine)

    # build lib info in memory
    vectors = 0x100
    mem.w32(vectors, 0x400)
    mem.w32(vectors + 4, 0x600)
    mem.w32(vectors + 8, 0x800)
    mem.w32(vectors + 12, 0xFFFFFFFF)
    name_addr = 0x1F0
    mem.w_cstr(name_addr, "bla.library")

    init_tab = 0x200
    ib = InitStructBuilder(mem, init_tab)
    name_off = LibraryStruct.get_field_offset_for_path("lib_Node.ln_Name")
    ib.init_long(name_off, name_addr)
    ib.end()

    init_func = 0x300
    mem.w16(init_func, op_rts)

    pos_size = LibraryStruct.get_size()

    # make library
    ml = MakeLib(machine, alloc)
    lib_base, mem_obj = ml.make_library(vectors,
                                        init_tab,
                                        init_func,
                                        pos_size,
                                        0,
                                        run_sp=sp)
    assert lib_base != 0

    # check library
    lib = Library(mem, lib_base)
    assert lib.get_name() == "bla.library"
    assert lib.get_pos_size() == 36
    assert lib.get_neg_size() == 20  # round_long(3*6)
    assert mem.r32(lib_base - 4) == 0x400
    assert mem.r32(lib_base - 10) == 0x600
    assert mem.r32(lib_base - 16) == 0x800

    # cleanup
    alloc.free_memory(mem_obj)
    assert alloc.is_all_free()
Ejemplo n.º 4
0
 def setup(self, pos_size=0, functions=0, init_struct=0, init_func=0):
     if pos_size == 0:
         pos_size = LibraryStruct.get_size()
     self.pos_size = pos_size
     self.functions = functions
     self.init_struct = init_struct
     self.init_func = init_func
Ejemplo n.º 5
0
 def setup(self, pos_size=0, functions=0, init_struct=0, init_func=0):
   if pos_size == 0:
     pos_size = LibraryStruct.get_size()
   self.pos_size = pos_size
   self.functions = functions
   self.init_struct = init_struct
   self.init_func = init_func
Ejemplo n.º 6
0
def libnative_makelib_test():
  machine = Machine()
  mem = machine.get_mem()
  sp = machine.get_ram_begin() - 4
  alloc = MemoryAlloc.for_machine(machine)

  # build lib info in memory
  vectors = 0x100
  mem.w32(vectors, 0x400)
  mem.w32(vectors+4, 0x600)
  mem.w32(vectors+8, 0x800)
  mem.w32(vectors+12, 0xffffffff)
  name_addr = 0x1f0
  mem.w_cstr(name_addr, "bla.library")

  init_tab = 0x200
  ib = InitStructBuilder(mem, init_tab)
  name_off = LibraryStruct.get_field_offset_for_path("lib_Node.ln_Name")
  ib.init_long(name_off, name_addr)
  ib.end()

  init_func = 0x300
  mem.w16(init_func, op_rts)

  pos_size = LibraryStruct.get_size()

  # make library
  ml = MakeLib(machine, alloc)
  lib_base, mem_obj = ml.make_library(
      vectors, init_tab, init_func, pos_size, 0,
      run_sp=sp)
  assert lib_base != 0

  # check library
  lib = Library(mem, lib_base)
  assert lib.get_name() == "bla.library"
  assert lib.get_pos_size() == 36
  assert lib.get_neg_size() == 20 # round_long(3*6)
  assert mem.r32(lib_base - 4) == 0x400
  assert mem.r32(lib_base - 10) == 0x600
  assert mem.r32(lib_base - 16) == 0x800

  # cleanup
  alloc.free_memory(mem_obj)
  assert alloc.is_all_free()
Ejemplo n.º 7
0
def setup_tmem():
  machine = MockMachine()
  mem = machine.get_mem()
  lm = machine.get_label_mgr()
  tm = TraceManager(machine)
  lm.add_label(LabelRange("range", 0x100, 0x100))
  lm.add_label(LabelStruct("node", 0x200, NodeStruct))
  lm.add_label(LabelLib("fake.library", 0x320, 0x20,
                        LibraryStruct.get_size(), LibraryStruct))
  return TraceMemory(mem, tm)
Ejemplo n.º 8
0
def setup_tmem():
    machine = MockMachine()
    mem = machine.get_mem()
    lm = machine.get_label_mgr()
    tm = TraceManager(machine)
    lm.add_label(LabelRange("range", 0x100, 0x100))
    lm.add_label(LabelStruct("node", 0x200, NodeStruct))
    lm.add_label(
        LabelLib("fake.library", 0x320, 0x20, LibraryStruct.get_size(),
                 LibraryStruct))
    return TraceMemory(mem, tm)
Ejemplo n.º 9
0
def atypes_libary_open_cnt_test(mem_alloc):
  mem, alloc = mem_alloc
  # alloc lib
  name = "my.library"
  id_str = "my.library 1.2"
  neg_size = 30
  pos_size = LibraryStruct.get_size()
  lib = Library.alloc(alloc, name, id_str, neg_size)
  # test open cnt
  assert lib.get_open_cnt() == 0
  lib.inc_open_cnt()
  assert lib.get_open_cnt() == 1
  lib.dec_open_cnt()
  assert lib.get_open_cnt() == 0
  # done
  lib.free()
  assert alloc.is_all_free()
Ejemplo n.º 10
0
def atypes_libary_open_cnt_test(mem_alloc):
    mem, alloc = mem_alloc
    # alloc lib
    name = "my.library"
    id_str = "my.library 1.2"
    neg_size = 30
    pos_size = LibraryStruct.get_size()
    lib = Library.alloc(alloc, name, id_str, neg_size)
    # test open cnt
    assert lib.get_open_cnt() == 0
    lib.inc_open_cnt()
    assert lib.get_open_cnt() == 1
    lib.dec_open_cnt()
    assert lib.get_open_cnt() == 0
    # done
    lib.free()
    assert alloc.is_all_free()
Ejemplo n.º 11
0
def atypes_library_base_test():
    mem = MockMemory()
    alloc = MemoryAlloc(mem)
    # alloc lib
    name = "my.library"
    id_str = "my.library 1.2"
    neg_size = 36
    pos_size = LibraryStruct.get_size()
    lib = Library.alloc(alloc, name, id_str, neg_size)
    assert lib.get_name() == name
    assert lib.get_id_string() == id_str
    size = lib.get_size()
    assert pos_size == lib.get_pos_size()
    assert neg_size == lib.get_neg_size()
    assert size == pos_size + neg_size
    # lib setup
    flags = LibFlags(LibFlags.LIBF_SUMMING, LibFlags.LIBF_CHANGED)
    ltype = NodeType(NodeType.NT_DEVICE)
    pri = -3
    ver = 1
    rev = 2
    lib.setup(version=ver, revision=rev, pri=pri, flags=flags, type=ltype)
    # check lib
    node = lib.get_node()
    assert node.get_succ() is None
    assert node.get_pred() is None
    assert node.get_type() == ltype
    assert node.get_pri() == pri
    assert lib.get_flags() == flags
    assert lib.get_pad() == 0
    assert lib.get_neg_size() == neg_size
    assert lib.get_pos_size() == pos_size
    assert lib.get_version() == ver
    assert lib.get_revision() == rev
    assert lib.get_sum() == 0
    assert lib.get_open_cnt() == 0
    assert lib.get_name() == name
    assert lib.get_id_string() == id_str
    # fill funcs
    lib.fill_funcs()
    lib_base = lib.get_addr()
    assert mem.r16(lib_base - 6) == op_rts
    # done
    lib.free()
    assert alloc.is_all_free()
Ejemplo n.º 12
0
def atypes_library_base_test(mem_alloc):
  mem, alloc = mem_alloc
  # alloc lib
  name = "my.library"
  id_str = "my.library 1.2"
  neg_size = 36
  pos_size = LibraryStruct.get_size()
  lib = Library.alloc(alloc, name, id_str, neg_size)
  assert lib.get_name() == name
  assert lib.get_id_string() == id_str
  size = lib.get_size()
  assert pos_size == lib.get_pos_size()
  assert neg_size == lib.get_neg_size()
  assert size == pos_size + neg_size
  # lib setup
  flags = LibFlags(LibFlags.LIBF_SUMMING, LibFlags.LIBF_CHANGED)
  ltype = NodeType(NodeType.NT_DEVICE)
  pri = -3
  ver = 1
  rev = 2
  lib.setup(version=ver, revision=rev, pri=pri, flags=flags, type=ltype)
  # check lib
  node = lib.get_node()
  assert node.get_succ() is None
  assert node.get_pred() is None
  assert node.get_type() == ltype
  assert node.get_pri() == pri
  assert lib.get_flags() == flags
  assert lib.get_pad() == 0
  assert lib.get_neg_size() == neg_size
  assert lib.get_pos_size() == pos_size
  assert lib.get_version() == ver
  assert lib.get_revision() == rev
  assert lib.get_sum() == 0
  assert lib.get_open_cnt() == 0
  assert lib.get_name() == name
  assert lib.get_id_string() == id_str
  # fill funcs
  lib.fill_funcs()
  lib_base = lib.get_addr()
  assert mem.r16(lib_base - 6) == op_rts
  # done
  lib.free()
  assert alloc.is_all_free()
Ejemplo n.º 13
0
def atypes_library_sum_test(mem_alloc):
  mem, alloc = mem_alloc
  # alloc lib
  name = "my.library"
  id_str = "my.library 1.2"
  neg_size = 30
  pos_size = LibraryStruct.get_size()
  lib = Library.alloc(alloc, name, id_str, neg_size)
  # assume rounded neg size
  assert lib.get_neg_size() == 32
  mem.w32(lib.addr-32, 0xdeadbeef)
  mem.w32(lib.addr-28, 0xcafebabe)
  my_sum = (0xdeadbeef + 0xcafebabe) & 0xffffffff
  lib_sum = lib.calc_sum()
  assert lib_sum == my_sum
  lib.update_sum()
  assert lib.get_sum() == my_sum
  assert lib.check_sum()
  # done
  lib.free()
  assert alloc.is_all_free()
Ejemplo n.º 14
0
def atypes_library_sum_test(mem_alloc):
    mem, alloc = mem_alloc
    # alloc lib
    name = "my.library"
    id_str = "my.library 1.2"
    neg_size = 30
    pos_size = LibraryStruct.get_size()
    lib = Library.alloc(alloc, name, id_str, neg_size)
    # assume rounded neg size
    assert lib.get_neg_size() == 32
    mem.w32(lib.addr - 32, 0xdeadbeef)
    mem.w32(lib.addr - 28, 0xcafebabe)
    my_sum = (0xdeadbeef + 0xcafebabe) & 0xffffffff
    lib_sum = lib.calc_sum()
    assert lib_sum == my_sum
    lib.update_sum()
    assert lib.get_sum() == my_sum
    assert lib.check_sum()
    # done
    lib.free()
    assert alloc.is_all_free()