def mem_alloc_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) assert alloc.is_all_free() addr = alloc.alloc_mem(1024) alloc.free_mem(addr, 1024) assert alloc.is_all_free()
def mem_alloc_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) assert alloc.is_all_free() addr = alloc.alloc_mem(1024) alloc.free_mem(addr, 1024) assert alloc.is_all_free()
def atypes_process_bptr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc proc proc = Process.alloc(alloc) # set list proc.seg_list = 0x100 assert proc.seg_list == BAddr(0x40) # check in mem seg list baddr struct = proc.get_type_struct() off = struct.pr_SegList_field.offset addr = proc.addr + off assert mem.r32(addr) == 0x40 # setup CLI cli = CLI.alloc(alloc) proc.cli = cli assert type(proc.cli) is CLI assert proc.cli == cli.addr # check in mem CLI baddr off = struct.pr_CLI_field.offset addr = proc.addr + off assert mem.r32(addr) == BAddr.from_addr(cli.addr).get_baddr() cli.free() # done proc.free() assert alloc.is_all_free()
def atypes_resident_setup_test(): mem = MockMemory(fill=23) alloc = MemoryAlloc(mem) # alloc res2 = Resident.alloc(alloc, "bla.library", "blub") res2.setup( flags=ResidentFlags.RTF_AUTOINIT, version=42, type=NodeType.NT_DEVICE, pri=-7, init=0xDEADBEEF, ) # find resource res = Resident.find(mem, 0, 1024) assert res.get_match_word() == res.RTC_MATCHWORD assert res.get_match_tag() == res.get_addr() assert res.get_end_skip() >= res.get_addr() + res.get_type_size() assert res.get_flags() == ResidentFlags.RTF_AUTOINIT assert res.get_version() == 42 assert res.get_type() == NodeType.NT_DEVICE assert res.get_pri() == -7 assert res.get_name() == "bla.library" assert res.get_id_string() == "blub" assert res.get_init() == 0xDEADBEEF # free res2.free() assert alloc.is_all_free()
def atypes_process_bptr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc proc proc = Process.alloc(alloc) # set list proc.seg_list = 0x100 assert proc.seg_list == BAddr(0x40) # check in mem seg list baddr struct = proc.get_type_struct() off = struct.pr_SegList_field.offset addr = proc.addr + off assert mem.r32(addr) == 0x40 # setup CLI cli = CLI.alloc(alloc) proc.cli = cli assert type(proc.cli) is CLI assert proc.cli == cli.addr # check in mem CLI baddr off = struct.pr_CLI_field.offset addr = proc.addr + off assert mem.r32(addr) == BAddr.from_addr(cli.addr).get_baddr() cli.free() # done proc.free() assert alloc.is_all_free()
def libcore_patch_multi_trap_test(capsys): name = 'vamostest.library' impl = VamosTestLibrary() fd = read_lib_fd(name) machine = MockMachine() ctx = LibCtx(machine) # create stub gen = LibStubGen() stub = gen.gen_stub(name, impl, fd, ctx) # now patcher alloc = MemoryAlloc(ctx.mem) traps = machine.get_traps() p = LibPatcherMultiTrap(alloc, traps, stub) base_addr = 0x100 p.patch_jump_table(base_addr) # lookup trap for function func = fd.get_func_by_name('PrintHello') bias = func.get_bias() func_addr = base_addr - bias # check that jump table has jump + addr op = ctx.mem.r16(func_addr) assert op == op_jmp trap_addr = ctx.mem.r32(func_addr + 2) # check jump target is trap op = ctx.mem.r16(trap_addr) assert op & 0xf000 == 0xa000 # trigger trap traps.trigger(op) captured = capsys.readouterr() assert captured.out.strip().split('\n') == ['VamosTest: PrintHello()'] # remove traps p.cleanup() assert traps.get_num_traps() == 0 assert alloc.is_all_free()
def libtypes_process_bptr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc proc proc = Process.alloc(alloc) # set list (as baddr) proc.seg_list.bptr = 0x40 assert proc.seg_list.bptr == 0x40 # check in mem seg list baddr off = proc.sdef.pr_SegList.offset addr = proc.addr + off assert mem.r32(addr) == 0x40 # setup CLI cli = CLI.alloc(alloc) proc.cli.ref = cli assert type(proc.cli.ref) is CLI assert proc.cli.aptr == cli.addr # check in mem CLI baddr off = proc.sdef.pr_CLI.offset addr = proc.addr + off assert mem.r32(addr) == cli.addr >> 2 cli.free() # done proc.free() assert alloc.is_all_free()
def astructs_astruct_class_test(): mem = MockMemory() alloc = MemoryAlloc(mem) pc = PlainClass.alloc(alloc) assert type(pc) == PlainClass assert pc.foo() == "" # alloc a name pc.name.alloc_str(alloc, "hello") assert pc.foo() == "hello" # another struct pc2 = PlainClass.alloc(alloc, name="world!") assert type(pc2) == PlainClass assert pc2.name.str == "world!" assert pc2.foo() == "world!" pc.next.ref = pc2 assert pc.foo() == "hello world!" # more struct pc3 = PlainClass.alloc(alloc, name="what:", bname="ugh!", next=pc2) assert pc3.foo() == "what: world!" assert pc3.next.ref is pc2 assert pc3.name.str == "what:" assert pc3.bname.str == "ugh!" pc3.free() pc2.free() # clean up pc pc.name.free_str() pc.free() assert alloc.is_all_free()
def libtypes_node_alloc_min_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = MinNode.alloc(alloc) assert node.get_size() == MinNodeStruct.get_size() node.free() assert alloc.is_all_free()
def atypes_node_alloc_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = Node.alloc(alloc) assert node.get_size() == NodeStruct.get_size() node.free() assert alloc.is_all_free()
def libtypes_resident_setup_test(): mem = MockMemory(fill=23) alloc = MemoryAlloc(mem) # alloc res2 = Resident.alloc(alloc, name="bla.library", id_string="blub") res2.new_resident( flags=ResidentFlags.RTF_AUTOINIT, version=42, type=NodeType.NT_DEVICE, pri=-7, init=0xDEADBEEF, ) # find resource res = Resident.find(mem, 0, 1024) assert res.match_word.val == res.RTC_MATCHWORD assert res.match_tag.aptr == res.get_addr() assert res.end_skip.aptr >= res.get_addr() + res.get_size() assert res.flags.val == ResidentFlags.RTF_AUTOINIT assert res.version.val == 42 assert res.type.val == NodeType.NT_DEVICE assert res.pri.val == -7 assert res.name.str == "bla.library" assert res.id_string.str == "blub" assert res.init.aptr == 0xDEADBEEF # free res2.free() assert alloc.is_all_free()
def atypes_execlib_alloc_test(): mem = MockMemory() alloc = MemoryAlloc(mem) el = ExecLibrary.alloc(alloc, "exec.library", "bla", 20) el.setup() el.fill_funcs() el.free() assert alloc.is_all_free()
def atypes_node_alloc_name_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = Node.alloc(alloc, "foobar") assert node.get_size() == NodeStruct.get_size() assert node.get_name() == "foobar" node.free() assert alloc.is_all_free()
def atypes_list_alloc_min_test(): mem = MockMemory() alloc = MemoryAlloc(mem) l = MinList.alloc(alloc) assert type(l) is MinList assert l.get_size() == MinListStruct.get_size() l.free() assert alloc.is_all_free()
def atypes_execlib_alloc_test(): mem = MockMemory() alloc = MemoryAlloc(mem) el = ExecLibrary.alloc(alloc, "exec.library", "bla", 20) el.setup() el.fill_funcs() el.free() assert alloc.is_all_free()
def atypes_resident_alloc_test(): mem = MockMemory(fill=23) alloc = MemoryAlloc(mem) # alloc res = Resident.alloc(alloc, "bla.library", "blub") # free res.free() assert alloc.is_all_free()
def libtypes_node_alloc_name_test(): mem = MockMemory() alloc = MemoryAlloc(mem) node = Node.alloc(alloc, name="foobar") assert node.get_size() == NodeStruct.get_size() assert node.name.str == "foobar" node.free() assert alloc.is_all_free()
def atypes_list_alloc_min_test(): mem = MockMemory() alloc = MemoryAlloc(mem) l = MinList.alloc(alloc) assert type(l) is MinList assert l.get_size() == MinListStruct.get_size() l.free() assert alloc.is_all_free()
def atypes_resident_alloc_test(): mem = MockMemory(fill=23) alloc = MemoryAlloc(mem) # alloc res = Resident.alloc(alloc, "bla.library", "blub") # free res.free() assert alloc.is_all_free()
def astructs_astruct_alloc_sub_test(): mem = MockMemory() alloc = MemoryAlloc(mem) res = SubStruct.alloc(alloc, ss_My={"ms_Word": 21, "ms_Pad": 42}) assert type(res) is SubStruct assert res.ss_My.ms_Word.val == 21 assert res.ss_My.ms_Pad.val == 42 res.free() assert alloc.is_all_free()
def astructs_astruct_class_subfield_alias_test(): mem = MockMemory() alloc = MemoryAlloc(mem) spc = SubPlainClass.alloc(alloc, name="abc", plain2={"name": "cde"}) assert type(spc) == SubPlainClass assert spc.plain.name.str == "abc" assert spc.plain2.name.str == "cde" spc.free() assert alloc.is_all_free()
def astructs_astruct_alloc_test(): mem = MockMemory() alloc = MemoryAlloc(mem) res = MyStruct.alloc(alloc, ms_Word=21, ms_Pad=42) assert type(res) is MyStruct assert res.ms_Word.val == 21 assert res.ms_Pad.val == 42 res.free() assert alloc.is_all_free()
def atypes_cstring_null_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string cs = CString.alloc(alloc, None) assert cs assert cs.get_addr() == 0 assert cs.get_string() is None cs.free() assert alloc.is_all_free()
def atypes_cstring_null_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string cs = CString.alloc(alloc, None) assert cs assert cs.get_addr() == 0 assert cs.get_string() is None cs.free() assert alloc.is_all_free()
def atypes_bstring_null_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string bs = BString.alloc(alloc, None) assert bs assert bs.get_baddr() << 2 == bs.get_addr() assert bs.get_addr() == 0 assert bs.get_string() is None bs.free() assert alloc.is_all_free()
def atypes_bstring_null_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string bs = BString.alloc(alloc, None) assert bs assert bs.get_baddr() << 2 == bs.get_addr() assert bs.get_addr() == 0 assert bs.get_string() is None bs.free() assert alloc.is_all_free()
def astructs_astruct_alloc_ptr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) MyStructPtr = APTR(MyStruct) ptr = MyStructPtr(mem, 0x10) assert ptr.aptr == 0 res = ptr.alloc_ref(alloc) assert type(res) is MyStruct assert ptr.aptr != 0 ptr.free_ref() assert ptr.aptr == 0 assert alloc.is_all_free()
def atypes_bstring_alloc_bstr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string bs = BString.alloc(alloc, "bla") bs2 = BString.alloc(alloc, bs) assert bs assert bs.get_string() == "bla" assert bs2 assert bs2.get_string() == "bla" bs.free() bs2.free() assert alloc.is_all_free()
def atypes_cstring_empty_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # empty string txt = "" cs = CString.alloc(alloc, txt) assert cs assert mem.r_cstr(cs.get_addr()) == txt assert cs.get_string() == txt assert cs == txt assert cs == cs.get_addr() cs.free() assert alloc.is_all_free()
def atypes_bstring_alloc_bstr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string bs = BString.alloc(alloc, "bla") bs2 = BString.alloc(alloc, bs) assert bs assert bs.get_string() == "bla" assert bs2 assert bs2.get_string() == "bla" bs.free() bs2.free() assert alloc.is_all_free()
def atypes_cstring_alloc_cstr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string cs = CString.alloc(alloc, "bla") cs2 = CString.alloc(alloc, cs) assert cs assert cs.get_string() == "bla" assert cs2 assert cs2.get_string() == "bla" cs.free() cs2.free() assert alloc.is_all_free()
def atypes_cstring_alloc_cstr_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # no string cs = CString.alloc(alloc, "bla") cs2 = CString.alloc(alloc, cs) assert cs assert cs.get_string() == "bla" assert cs2 assert cs2.get_string() == "bla" cs.free() cs2.free() assert alloc.is_all_free()
def atypes_cstring_empty_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # empty string txt = "" cs = CString.alloc(alloc, txt) assert cs assert mem.r_cstr(cs.get_addr()) == txt assert cs.get_string() == txt assert cs == txt assert cs == cs.get_addr() cs.free() assert alloc.is_all_free()
def atypes_bstring_empty_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # empty string txt = "" bs = BString.alloc(alloc, txt) assert bs assert bs.get_baddr() << 2 == bs.get_addr() assert mem.r_bstr(bs.get_addr()) == txt assert bs.get_string() == txt assert bs == txt assert bs == bs.get_addr() bs.free() assert alloc.is_all_free()
def atypes_cstring_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # simple string txt = "hello, world!" cs = CString.alloc(alloc, txt) assert cs assert mem.r_cstr(cs.get_addr()) == txt assert cs.get_string() == txt assert cs == txt assert cs == cs.get_addr() assert cs == CString(mem, cs.get_addr()) cs.free() assert alloc.is_all_free()
def atypes_bstring_empty_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # empty string txt = "" bs = BString.alloc(alloc, txt) assert bs assert bs.get_baddr() << 2 == bs.get_addr() assert mem.r_bstr(bs.get_addr()) == txt assert bs.get_string() == txt assert bs == txt assert bs == bs.get_addr() bs.free() assert alloc.is_all_free()
def atypes_cstring_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # simple string txt = "hello, world!" cs = CString.alloc(alloc, txt) assert cs assert mem.r_cstr(cs.get_addr()) == txt assert cs.get_string() == txt assert cs == txt assert cs == cs.get_addr() assert cs == CString(mem, cs.get_addr()) cs.free() assert alloc.is_all_free()
def atypes_process_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc proc name = "my_proc" proc = Process.alloc(alloc, name) assert proc.get_name() == name # proc setup proc.setup() node = proc.task.node assert node.type == NodeType.NT_PROCESS # done proc.free() assert alloc.is_all_free()
def libtypes_process_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc proc name = "my_proc" proc = Process.alloc(alloc, name=name) assert proc.name.str == name # proc setup proc.new_proc() node = proc.task.node assert node.type.val == NodeType.NT_PROCESS # done proc.free() assert alloc.is_all_free()
def atypes_bstring_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # simple string txt = "hello, world!" bs = BString.alloc(alloc, txt) assert bs assert bs.get_baddr() << 2 == bs.get_addr() assert mem.r_bstr(bs.get_addr()) == txt assert bs.get_string() == txt assert bs == txt assert bs == bs.get_addr() assert bs == BString(mem, bs.get_addr()) bs.free() assert alloc.is_all_free()
def libtypes_execlib_alloc_test(): mem = MockMemory() alloc = MemoryAlloc(mem) el = ExecLibrary.alloc(alloc, name="exec.library", id_string="bla", neg_size=20) assert el.name.str == "exec.library" assert el.id_string.str == "bla" assert el.neg_size.val == 20 assert el.pos_size.val == ExecLibrary.get_size() el.new_lib() el.fill_funcs() el.free() assert alloc.is_all_free()
def atypes_bstring_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # simple string txt = "hello, world!" bs = BString.alloc(alloc, txt) assert bs assert bs.get_baddr() << 2 == bs.get_addr() assert mem.r_bstr(bs.get_addr()) == txt assert bs.get_string() == txt assert bs == txt assert bs == bs.get_addr() assert bs == BString(mem, bs.get_addr()) bs.free() assert alloc.is_all_free()
def atypes_msg_msg_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc msg msg = Message.alloc(alloc) assert msg.name == 0 msg.setup(pri=-7, length=10) assert msg.node.pri == -7 assert msg.node.type == NodeType.NT_MESSAGE assert msg.length == 10 # with name msg2 = Message.alloc(alloc, "bla") assert msg2.name == "bla" # free msg.free() msg2.free() assert alloc.is_all_free()
def atypes_msg_msg_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc msg msg = Message.alloc(alloc) assert msg.name == 0 msg.setup(pri=-7, length=10) assert msg.node.pri == -7 assert msg.node.type == NodeType.NT_MESSAGE assert msg.length == 10 # with name msg2 = Message.alloc(alloc, "bla") assert msg2.name == "bla" # free msg.free() msg2.free() assert alloc.is_all_free()
def libtypes_msg_msg_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc msg msg = Message.alloc(alloc) assert msg.name.aptr == 0 msg.new_msg(pri=-7, length=10) assert msg.pri.val == -7 assert msg.type.val == NodeType.NT_MESSAGE assert msg.length.val == 10 # with name msg2 = Message.alloc(alloc, name="bla") assert msg2.name.str == "bla" # free msg.free() msg2.free() assert alloc.is_all_free()
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()
def atypes_libary_open_cnt_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # 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()
def atypes_task_base_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc task name = "my_task" task = Task.alloc(alloc, name) assert task.get_name() == name # task setup task.setup(pri=-5, flags=TaskFlags.TF_LAUNCH) node = task.get_node() assert node.get_type() == NodeType.NT_TASK assert node.get_pri() == -5 assert task.get_flags() == TaskFlags.TF_LAUNCH assert task.get_state() == TaskState.TS_INVALID assert len(task.mem_entry) == 0 assert task.mem_entry.type == NodeType.NT_MEMORY # done task.free() assert alloc.is_all_free()
def atypes_msg_msgport_test(): mem = MockMemory() alloc = MemoryAlloc(mem) # alloc msg port mp1 = MsgPort.alloc(alloc) assert mp1.name == 0 mp1.setup(pri=-5, flags=MsgPortFlags.PA_SOFTINT, sig_bit=5) assert mp1.node.pri == -5 assert mp1.node.type == NodeType.NT_MSGPORT assert mp1.flags == MsgPortFlags.PA_SOFTINT assert mp1.sig_bit == 5 assert mp1.sig_task == 0 assert len(mp1.msg_list) == 0 # with name mp2 = MsgPort.alloc(alloc, "bla") assert mp2.get_name() == "bla" # free mp1.free() mp2.free() assert alloc.is_all_free()
def atypes_atype_alloc_test(): @AmigaTypeDef(MyStruct, wrap={'pad': (Bla.getf, Bla.setf)}) class MyType(AmigaType): pass @AmigaTypeDef(SubStruct) class SubType(AmigaType): pass mem = MockMemory() alloc = MemoryAlloc(mem) # my type mt = MyType.alloc(alloc) assert mt assert mt.get_addr() != 0 mt.free() # sub st = SubType.alloc(alloc) assert st assert st.get_addr() != 0 st.free() assert alloc.is_all_free()
def atypes_resident_setup_test(): mem = MockMemory(fill=23) alloc = MemoryAlloc(mem) # alloc res2 = Resident.alloc(alloc, "bla.library", "blub") res2.setup(flags=ResidentFlags.RTF_AUTOINIT, version=42, type=NodeType.NT_DEVICE, pri=-7, init=0xdeadbeef) # find resource res = Resident.find(mem, 0, 1024) assert res.get_match_word() == res.RTC_MATCHWORD assert res.get_match_tag() == res.get_addr() assert res.get_end_skip() >= res.get_addr() + res.get_type_size() assert res.get_flags() == ResidentFlags.RTF_AUTOINIT assert res.get_version() == 42 assert res.get_type() == NodeType.NT_DEVICE assert res.get_pri() == -7 assert res.get_name() == "bla.library" assert res.get_id_string() == "blub" assert res.get_init() == 0xdeadbeef # free res2.free() assert alloc.is_all_free()
def libcore_patch_multi_trap_test(capsys): name = 'vamostest.library' impl = VamosTestLibrary() fd = read_lib_fd(name) machine = MockMachine() ctx = LibCtx(machine) # create stub scanner = LibImplScanner() scan = scanner.scan(name, impl, fd) gen = LibStubGen() stub = gen.gen_stub(scan, ctx) # now patcher alloc = MemoryAlloc(ctx.mem) traps = machine.get_traps() p = LibPatcherMultiTrap(alloc, traps, stub) base_addr = 0x100 p.patch_jump_table(base_addr) # lookup trap for function func = fd.get_func_by_name('PrintHello') bias = func.get_bias() func_addr = base_addr - bias # check that jump table has jump + addr op = ctx.mem.r16(func_addr) assert op == op_jmp trap_addr = ctx.mem.r32(func_addr + 2) # check jump target is trap op = ctx.mem.r16(trap_addr) assert op & 0xf000 == 0xa000 # trigger trap traps.trigger(op) captured = capsys.readouterr() assert captured.out.strip().split('\n') == [ 'VamosTest: PrintHello()' ] # remove traps p.cleanup() assert traps.get_num_traps() == 0 assert alloc.is_all_free()