Skip to content

Commit

Permalink
added tag list call to vamos test list and tag test
Browse files Browse the repository at this point in the history
  • Loading branch information
cnvogelg committed Jan 15, 2025
1 parent f01c8d8 commit 4a8a0f5
Show file tree
Hide file tree
Showing 28 changed files with 200 additions and 37 deletions.
1 change: 1 addition & 0 deletions amitools/data/fd/vamostest_lib.fd
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Swap(a,b)(d0,d1)
Dummy(a,b)(d0,d1)
RaiseError(str)(a0)
ExecutePy(argc,argv)(d0,a0)
MyFindTagData(tagVal,tagList)(d0/a0)
##end
10 changes: 10 additions & 0 deletions amitools/vamos/lib/VamosTestLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from amitools.vamos.error import VamosInternalError
from amitools.vamos.machine import InvalidMemoryAccessError
from amitools.vamos.astructs import CSTR
from amitools.vamos.libtypes import TagList, TagItem


class VamosTestLibrary(LibImpl):
Expand Down Expand Up @@ -51,6 +52,15 @@ def Swap(self, ctx, a, b):
"""define input values directly as function arguments"""
return b, a

def MyFindTagData(self, ctx, tag_val, tag_list: TagList):
if not tag_list:
return 0
tag = tag_list.find_tag(tag_val)
if tag:
return tag.get_data()
else:
return 0

def RaiseError(self, ctx, txt_ptr: CSTR):
txt = txt_ptr.str
if txt == "RuntimeError":
Expand Down
4 changes: 2 additions & 2 deletions amitools/vamos/lib/dos/Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(

self.ok = self.load_binary(self.cwd_lock, bin_file, shell)
if not self.ok:
self.free_cwd()
return
# setup stack
self.stack = Stack.alloc(self.ctx.alloc, stack_size)
Expand Down Expand Up @@ -73,8 +74,7 @@ def free(self):
self.free_shell_packet()
self.free_cli_struct()
self.free_args()
# stack is freed by scheduler
# self.stack.free()
self.stack.free()
self.unload_binary()

def __str__(self):
Expand Down
57 changes: 37 additions & 20 deletions amitools/vamos/libcore/proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from amitools.vamos.machine import Code, REG_D0, REG_D1
from amitools.vamos.libtypes import TagList


class LibProxy:
Expand Down Expand Up @@ -29,32 +30,46 @@ def __init__(self, ctx, args, arg_regs, kwargs):
self.kw_args = kwargs
# auto strings
self.auto_strings = []
self.auto_tag_lists = []

def input_reg_map(self):
reg_map = {}
for reg, val in zip(self.arg_regs, self.args):
# auto convert strings
if val is None:
val = 0
elif isinstance(val, int):
pass
elif isinstance(val, str):
str_mem = self.ctx.alloc.alloc_cstr(val, label="reg_auto_str")
val = str_mem.addr
self.auto_strings.append(str_mem)
# complex object? try to get its in memory address via "get_addr"
reg_map[reg] = self._map_value(val)
return reg_map

def _map_value(self, val):
if val is None:
val = 0
elif isinstance(val, int):
pass
# auto convert strings
elif isinstance(val, str):
str_mem = self.ctx.alloc.alloc_cstr(val, label="reg_auto_str")
val = str_mem.addr
self.auto_strings.append(str_mem)
# auto convert tag list: [(tag, data), (tag2, data2), ...]
elif isinstance(val, list):
map_list = self._map_tag_list(val)
tag_list = TagList.alloc(self.ctx.alloc, *map_list)
self.auto_tag_lists.append(tag_list)
val = tag_list.get_addr()
# complex object? try to get its in memory address via "get_addr"
else:
# has 'addr'?
get_addr = getattr(val, "get_addr", None)
if get_addr is not None:
val = get_addr()
else:
# has 'addr'?
get_addr = getattr(val, "get_addr", None)
if get_addr is not None:
val = get_addr()
else:
raise ValueError(
f"Invalid argument for proxy call reg={reg} val={val}"
)
raise ValueError(f"Invalid argument for proxy call reg={reg} val={val}")
return val

reg_map[reg] = val
return reg_map
def _map_tag_list(self, tag_list):
result = []
for tag, data in tag_list:
val = self._map_value(data)
result.append((tag, val))
return result

def output_reg_list(self):
regs = [REG_D0]
Expand All @@ -71,6 +86,8 @@ def wrap_result(self):
def cleanup(self):
for mem in self.auto_strings:
self.ctx.alloc.free_cstr(mem)
for tag_list in self.auto_tag_lists:
tag_list.free()


class LibProxyGen:
Expand Down
5 changes: 3 additions & 2 deletions amitools/vamos/mode/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create_proc(self, mode_ctx):
return None

# split command into binary and args
cmd_arg = self.get_cmd_args(cmd_cfg, args)
cmd_arg = self.get_cmd_args(mode_ctx, cmd_cfg, args)
if cmd_arg is None:
return None
cmd, arg_str = cmd_arg
Expand All @@ -52,7 +52,7 @@ def create_proc(self, mode_ctx):
return None
return proc

def get_cmd_args(self, cmd_cfg, args):
def get_cmd_args(self, mode_ctx, cmd_cfg, args):
# a single Amiga-like raw arg was passed
if cmd_cfg.raw_arg:
# check args
Expand All @@ -75,6 +75,7 @@ def get_cmd_args(self, cmd_cfg, args):
# if path exists on host system then make an ami path
if os.path.exists(binary):
sys_binary = binary
dos_ctx = mode_ctx.dos_ctx
binary = dos_ctx.path_mgr.from_sys_path(binary)
if not binary:
log_proc.error("can't map binary: %s", sys_binary)
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SOURCES_C += math_double.c math_double_trans.c
SOURCES_C += math_single.c math_single_trans.c
SOURCES_C += math_fast.c math_fast_trans.c
SOURCES_C += test_hello.c test_raise.c
SOURCES_C += test_devtimer.c test_execpy.c
SOURCES_C += test_devtimer.c test_execpy.c test_tags.c
SOURCES_C += lib_testnix.c lib_testsc.c
SOURCES_C += proc_args.c

Expand Down
Binary file added test/bin/test_tags_agcc
Binary file not shown.
Binary file added test/bin/test_tags_agcc_dbg
Binary file not shown.
Binary file added test/bin/test_tags_gcc
Binary file not shown.
Binary file added test/bin/test_tags_gcc_dbg
Binary file not shown.
Binary file added test/bin/test_tags_sc
Binary file not shown.
Binary file added test/bin/test_tags_sc_dbg
Binary file not shown.
Binary file added test/bin/test_tags_vc
Binary file not shown.
Binary file added test/bin/test_tags_vc_dbg
Binary file not shown.
10 changes: 10 additions & 0 deletions test/include/clib/vamostest_protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ extern "C" {
#include <exec/types.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

#ifndef CONST
#define CONST
#endif

VOID PrintHello(VOID);
VOID PrintString(STRPTR txt);
ULONG Add(ULONG a, ULONG b);
ULONG Swap(ULONG a, ULONG b);
ULONG Dummy(ULONG a, ULONG b);
VOID RaiseError(STRPTR error);
ULONG ExecutePy(ULONG argc, STRPTR *argv);
ULONG MyFindTagData(ULONG tagVal, CONST struct TagItem *tagList);
ULONG MyFindTagDataTags(ULONG tagVal, ULONG tag1Type, ...);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion test/include/defines/testnix.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Automatically generated header (sfdc 1.11)! Do not edit! */
/* Automatically generated header (sfdc 1.12)! Do not edit! */

#ifndef _INLINE_TESTNIX_H
#define _INLINE_TESTNIX_H
Expand Down
13 changes: 12 additions & 1 deletion test/include/defines/vamostest.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Automatically generated header (sfdc 1.11)! Do not edit! */
/* Automatically generated header (sfdc 1.12)! Do not edit! */

#ifndef _INLINE_VAMOSTEST_H
#define _INLINE_VAMOSTEST_H
Expand Down Expand Up @@ -58,4 +58,15 @@ typedef ULONG _sfdc_vararg;
AROS_LCA(STRPTR *, (___argv), A0), \
struct VamosTestBase *, VAMOSTEST_BASE_NAME, 11, Vamostest)

#define MyFindTagData(___tagVal, ___tagList) \
AROS_LC2(ULONG, MyFindTagData, \
AROS_LCA(ULONG, (___tagVal), D0), \
AROS_LCA(CONST struct TagItem *, (___tagList), A0), \
struct VamosTestBase *, VAMOSTEST_BASE_NAME, 12, Vamostest)

#ifndef NO_INLINE_STDARG
#define MyFindTagDataTags(___tagVal, ___tagList, ...) \
({_sfdc_vararg _tags[] = { ___tagList, __VA_ARGS__ }; MyFindTagData((___tagVal), (CONST struct TagItem *) _tags); })
#endif /* !NO_INLINE_STDARG */

#endif /* !_INLINE_VAMOSTEST_H */
21 changes: 21 additions & 0 deletions test/include/inline/vamostest.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif
#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

#ifndef VAMOSTEST_BASE_NAME
#define VAMOSTEST_BASE_NAME VamosTestBase
Expand Down Expand Up @@ -71,4 +74,22 @@
(_ExecutePy__bn - 66))(_ExecutePy__bn, _ExecutePy_argc, _ExecutePy_argv); \
});})

#define MyFindTagData(tagVal, tagList) ({ \
ULONG _MyFindTagData_tagVal = (tagVal); \
CONST struct TagItem * _MyFindTagData_tagList = (tagList); \
({ \
register char * _MyFindTagData__bn __asm("a6") = (char *) (VAMOSTEST_BASE_NAME);\
((ULONG (*)(char * __asm("a6"), ULONG __asm("d0"), CONST struct TagItem * __asm("a0"))) \
(_MyFindTagData__bn - 72))(_MyFindTagData__bn, _MyFindTagData_tagVal, _MyFindTagData_tagList); \
});})

#ifndef NO_INLINE_STDARG
static __inline__ ULONG ___MyFindTagDataTags(struct VamosTestBase * VamosTestBase, ULONG tagVal, ULONG tagList, ...)
{
return MyFindTagData(tagVal, (CONST struct TagItem *) &tagList);
}

#define MyFindTagDataTags(tagVal...) ___MyFindTagDataTags(VAMOSTEST_BASE_NAME, tagVal)
#endif

#endif /* _INLINE_VAMOSTEST_H */
8 changes: 8 additions & 0 deletions test/include/inline/vamostest_protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ VOID __RaiseError(__reg("a6") struct VamosTestBase *, __reg("a0") STRPTR str)="\
ULONG __ExecutePy(__reg("a6") struct VamosTestBase *, __reg("d0") ULONG argc, __reg("a0") STRPTR * argv)="\tjsr\t-66(a6)";
#define ExecutePy(argc, argv) __ExecutePy(VamosTestBase, (argc), (argv))

ULONG __MyFindTagData(__reg("a6") struct VamosTestBase *, __reg("d0") ULONG tagVal, __reg("a0") CONST struct TagItem * tagList)="\tjsr\t-72(a6)";
#define MyFindTagData(tagVal, tagList) __MyFindTagData(VamosTestBase, (tagVal), (tagList))

#if !defined(NO_INLINE_STDARG) && (__STDC__ == 1L) && (__STDC_VERSION__ >= 199901L)
ULONG __MyFindTagDataTags(__reg("a6") struct VamosTestBase *, __reg("d0") ULONG tagVal, ULONG tagList, ...)="\tmove.l\ta0,-(a7)\n\tlea\t4(a7),a0\n\tjsr\t-72(a6)\n\tmovea.l\t(a7)+,a0";
#define MyFindTagDataTags(tagVal, ...) __MyFindTagDataTags(VamosTestBase, (tagVal), __VA_ARGS__)
#endif

#endif /* _VBCCINLINE_VAMOSTEST_H */
8 changes: 8 additions & 0 deletions test/include/pragma/vamostest_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#pragma amicall(VamosTestBase,0x036,Dummy(d0,d1))
#pragma amicall(VamosTestBase,0x03c,RaiseError(a0))
#pragma amicall(VamosTestBase,0x042,ExecutePy(d0,a0))
#pragma amicall(VamosTestBase,0x048,MyFindTagData(d0,a0))
#endif
#if defined(_DCC) || defined(__SASC)
#pragma libcall VamosTestBase PrintHello 01e 00
Expand All @@ -22,6 +23,13 @@
#pragma libcall VamosTestBase Dummy 036 1002
#pragma libcall VamosTestBase RaiseError 03c 801
#pragma libcall VamosTestBase ExecutePy 042 8002
#pragma libcall VamosTestBase MyFindTagData 048 8002
#endif
#ifdef __STORM__
#pragma tagcall(VamosTestBase,0x048,MyFindTagDataTags(d0,a0))
#endif
#ifdef __SASC_60
#pragma tagcall VamosTestBase MyFindTagDataTags 048 8002
#endif

#endif /* _INCLUDE_PRAGMA_VAMOSTEST_LIB_H */
2 changes: 1 addition & 1 deletion test/include/sfd/testnix_lib.sfd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
==id $Id: testnix_lib.sfd,v 1.0 2021/03/17 22:04:32 noname Exp $
==id $Id: testnix_lib.sfd,v 1.0 2025/01/15 12:44:51 noname Exp $
* "testnix.library"
==base _TestNixBase
==basetype struct Library *
Expand Down
6 changes: 5 additions & 1 deletion test/include/sfd/vamostest_lib.sfd
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
==id $Id: vamostest_lib.sfd,v 1.0 2021/03/17 22:04:32 noname Exp $
==id $Id: vamostest_lib.sfd,v 1.0 2025/01/15 12:44:51 noname Exp $
* "vamostest.library"
==base _VamosTestBase
==basetype struct VamosTestBase *
==libname vamostest.library
==bias 30
==public
==include <exec/types.h>
==include <utility/tagitem.h>
VOID PrintHello() ()
VOID PrintString(STRPTR str) (a0)
ULONG Add(ULONG a, ULONG b) (d0,d1)
ULONG Swap(ULONG a, ULONG b) (d0,d1)
ULONG Dummy(ULONG a, ULONG b) (d0,d1)
VOID RaiseError(STRPTR str) (a0)
ULONG ExecutePy(ULONG argc, STRPTR * argv) (d0,a0)
ULONG MyFindTagData(ULONG tagVal, CONST struct TagItem * tagList) (d0,a0)
==varargs
ULONG MyFindTagDataTags(ULONG tagVal, ULONG tagList, ...) (d0,a0)
==end
36 changes: 36 additions & 0 deletions test/src/test_tags.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <libraries/vamostest.h>
#include <proto/vamostest.h>
#include <proto/exec.h>
#include <utility/tagitem.h>

struct VamosTestBase *VamosTestBase;

int main(int argc, char *argv[])
{
if ((VamosTestBase = (struct VamosTestBase *)OpenLibrary("vamostest.library", 23)))
{
int result = 0;
struct TagItem tag_list[] = {
{ TAG_USER, 21 },
{ TAG_USER+1, 42 },
{ TAG_USER+2, (ULONG)"hello world!" },
{ TAG_DONE }
};

ULONG tag_value = MyFindTagData(TAG_USER+1, tag_list);
if(tag_value != 42) {
result = 2;
}

tag_value = MyFindTagDataTags(TAG_USER+1, TAG_USER, 21, TAG_USER+1, 42,
TAG_USER+2, (ULONG)"hello world!", TAG_DONE);
if(tag_value != 42) {
result = 3;
}

CloseLibrary((struct Library *)VamosTestBase);
return result;
} else {
return 1;
}
}
5 changes: 5 additions & 0 deletions test/suite/test_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def test_tags_test(vamos):
retcode, stdout, stderr = vamos.run_prog("test_tags")
assert retcode == 0
assert stdout == []
assert stderr == []
6 changes: 3 additions & 3 deletions test/unit/fd_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def fd_format_generate_fd_num_call_test():
def fd_format_read_vamostest_lib_test():
fd = read_lib_fd("vamostest.library")
assert fd.get_base_name() == "_VamosTestBase"
assert fd.get_max_bias() == 66
assert fd.get_neg_size() == 72
assert fd.get_num_indices() == 11
assert fd.get_max_bias() == 72
assert fd.get_neg_size() == 78
assert fd.get_num_indices() == 12
# check entries
tab = fd.get_index_table()
assert len(tab) == fd.get_num_indices()
Expand Down
12 changes: 10 additions & 2 deletions test/unit/libcore_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def PrintHello(self, ctx, wrong):
assert res.get_name() == name
assert res.get_impl() == impl
assert res.get_fd() == fd
assert res.get_num_valid_funcs() == 5
assert res.get_num_valid_funcs() == 6
assert res.get_num_missing_funcs() == 1
assert res.get_num_error_funcs() == 1
assert res.get_num_invalid_funcs() == 1
Expand Down Expand Up @@ -78,9 +78,17 @@ def PrintHello(self, ctx, wrong):
"Swap": res.get_func_by_name("Swap"),
"RaiseError": res.get_func_by_name("RaiseError"),
"ExecutePy": res.get_func_by_name("ExecutePy"),
"MyFindTagData": res.get_func_by_name("MyFindTagData"),
}
valid_names = res.get_valid_func_names()
assert valid_names == ["Add", "ExecutePy", "PrintString", "RaiseError", "Swap"]
assert valid_names == [
"Add",
"ExecutePy",
"MyFindTagData",
"PrintString",
"RaiseError",
"Swap",
]
valid_func = res.get_func_by_name("ExecutePy")
assert valid_func.name == "ExecutePy"
assert valid_func.fd_func == fd.get_func_by_name("ExecutePy")
Expand Down
Loading

0 comments on commit 4a8a0f5

Please sign in to comment.