mirror of
https://github.com/LIV2/amitools.git
synced 2025-12-06 06:32:47 +00:00
added dos/exec call test via ctx func
This commit is contained in:
parent
db8c72643b
commit
b64c758301
@ -569,6 +569,8 @@ class DosLibrary(LibImpl):
|
||||
f_mode = "rwb+"
|
||||
else:
|
||||
mode_name = "?"
|
||||
log_dos.warning("open: invalid mode=%d!", mode)
|
||||
f_mode = "wb+"
|
||||
|
||||
fh = self.file_mgr.open(self.get_current_dir(ctx), name, f_mode)
|
||||
log_dos.info(
|
||||
|
||||
@ -33,6 +33,9 @@ class LibProxyGen:
|
||||
def _gen_stub_call(self, arg_regs, stub_method):
|
||||
def stub_call(self, *args, **kwargs):
|
||||
"""proxy function to call lib stub directly"""
|
||||
# ensure that all positional args are given
|
||||
assert len(args) == len(arg_regs)
|
||||
|
||||
# fill registers with arg values
|
||||
for reg, val in zip(arg_regs, args):
|
||||
self.ctx.cpu.w_reg(reg, val)
|
||||
@ -55,6 +58,9 @@ class LibProxyGen:
|
||||
|
||||
def _gen_lib_call(self, arg_regs, bias, name=None):
|
||||
def lib_call(self, *args, **kwargs):
|
||||
# ensure that all positional args are given
|
||||
assert len(args) == len(arg_regs)
|
||||
|
||||
reg_map = {}
|
||||
for reg, val in zip(arg_regs, args):
|
||||
reg_map[reg] = val
|
||||
|
||||
@ -71,3 +71,51 @@ def test_execpy_vamos_ctx_func_checked_test(vamos):
|
||||
assert sorted(ctx.__dict__) == ["cpu", "machine", "mem", "proxies", "vlib"]
|
||||
|
||||
vamos.run_ctx_func_checked(test)
|
||||
|
||||
|
||||
def test_execpy_vamos_ctx_func_exec_test(vamos):
|
||||
"""call exec functions via proxy in ctx func"""
|
||||
|
||||
def test(ctx):
|
||||
# get exec lib proxy
|
||||
exec = ctx.proxies.get_exec_lib_proxy()
|
||||
assert exec
|
||||
# call exec functions
|
||||
size = 1024
|
||||
addr = exec.AllocMem(size, 0)
|
||||
assert addr
|
||||
exec.FreeMem(addr, size)
|
||||
|
||||
vamos.run_ctx_func_checked(test)
|
||||
|
||||
|
||||
def test_execpy_vamos_ctx_func_dos_test(vamos, tmpdir):
|
||||
"""call dos functions via proxy in ctx func"""
|
||||
sys_file_name = str(tmpdir / "test_file")
|
||||
ami_file_name = "root:" + sys_file_name[1:]
|
||||
ami_file_len = len(ami_file_name)
|
||||
|
||||
def test(ctx):
|
||||
# get dos, exec lib proxy
|
||||
exec = ctx.proxies.get_exec_lib_proxy()
|
||||
assert exec
|
||||
dos = ctx.proxies.get_dos_lib_proxy()
|
||||
assert dos
|
||||
# allocate name
|
||||
name_addr = exec.AllocMem(ami_file_len + 1, 0)
|
||||
assert name_addr
|
||||
ctx.mem.w_cstr(name_addr, ami_file_name)
|
||||
# call dos functions
|
||||
fh = dos.Open(name_addr, 1006)
|
||||
assert fh
|
||||
res = dos.Write(fh, name_addr, ami_file_len)
|
||||
assert res == ami_file_len
|
||||
# clean up
|
||||
dos.Close(fh)
|
||||
exec.FreeMem(name_addr, ami_file_len)
|
||||
|
||||
vamos.run_ctx_func_checked(test)
|
||||
# check file
|
||||
with open(sys_file_name, "r") as fobj:
|
||||
data = fobj.read()
|
||||
assert data == ami_file_name
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from amitools.vamos.libcore import LibCtx, LibProxyGen
|
||||
from amitools.vamos.lib.VamosTestLibrary import VamosTestLibrary
|
||||
from amitools.vamos.machine import MockMachine
|
||||
@ -104,6 +106,11 @@ def libcore_proxy_gen_stub_test():
|
||||
assert stub.string_kwargs == {"foo": "bar"}
|
||||
assert ctx.cpu.r_reg(REG_D0) == stub.string_count
|
||||
assert ctx.cpu.r_reg(REG_D1) == stub.string_count * 2
|
||||
# ensure that positional arguments are here
|
||||
with pytest.raises(AssertionError):
|
||||
proxy.PrintString()
|
||||
with pytest.raises(AssertionError):
|
||||
proxy.PrintString(1, 2)
|
||||
|
||||
|
||||
def libcore_proxy_gen_libcall_test():
|
||||
@ -131,3 +138,8 @@ def libcore_proxy_gen_libcall_test():
|
||||
assert ret == (23, 42)
|
||||
assert machine.set_regs == {REG_A0: 0x10}
|
||||
assert machine.get_regs == [REG_D0, REG_D1]
|
||||
# ensure that positional arguments are here
|
||||
with pytest.raises(AssertionError):
|
||||
proxy.PrintString()
|
||||
with pytest.raises(AssertionError):
|
||||
proxy.PrintString(1, 2)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user