From: notaz Date: Sat, 28 Mar 2015 21:37:37 +0000 (+0200) Subject: start some tests X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19b07b62484f19ec2d59e7489e96f4ec877d3fbd;p=ia32rtools.git start some tests --- diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..607ebe3 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,20 @@ + +TESTS = reg_call1 reg_call2 reg_call3 reg_call_tail reg_save + +all: $(addsuffix .ok,$(TESTS)) + +%.ok: %.expect.c %.out.c + diff -u $^ + touch $@ + +%.out.h: %.asm %.seed.h ../stdc.list + ../tools/translate -hdr $@ $^ + +%.out.c: %.asm %.out.h ../stdc.list + ../tools/translate $@ $^ + +clean: + $(RM) *.ok *.out.c *.out.h + +.PHONY: all clean +.PRECIOUS: %.out.c diff --git a/tests/new.sh b/tests/new.sh new file mode 100755 index 0000000..b718c8d --- /dev/null +++ b/tests/new.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "usage:" + echo "$0 " + exit 1 +fi + +cp -v reg_call1.asm $1.asm +touch $1.expect.c +touch $1.seed.h diff --git a/tests/reg_call1.asm b/tests/reg_call1.asm new file mode 100644 index 0000000..06ab74c --- /dev/null +++ b/tests/reg_call1.asm @@ -0,0 +1,15 @@ + +_text segment para public 'CODE' use32 + +sub_test proc near + push ebp + mov ebp, esp + call fastcall_func + and eax, 0 + pop ebp + retn +sub_test endp + +_text ends + +; vim:expandtab diff --git a/tests/reg_call1.expect.c b/tests/reg_call1.expect.c new file mode 100644 index 0000000..5637de9 --- /dev/null +++ b/tests/reg_call1.expect.c @@ -0,0 +1,10 @@ +int __fastcall sub_test(int a1) +{ + u32 ecx = (u32)a1; + u32 eax; + + fastcall_func(ecx); + eax = 0; + return eax; +} + diff --git a/tests/reg_call1.seed.h b/tests/reg_call1.seed.h new file mode 100644 index 0000000..52ca086 --- /dev/null +++ b/tests/reg_call1.seed.h @@ -0,0 +1 @@ +int __fastcall fastcall_func(int a1); diff --git a/tests/reg_call2.asm b/tests/reg_call2.asm new file mode 100644 index 0000000..6a3c94a --- /dev/null +++ b/tests/reg_call2.asm @@ -0,0 +1,15 @@ + +_text segment para public 'CODE' use32 + +sub_test proc near + push ebp + mov ebp, esp + call fastcall_func + inc ecx + pop ebp + retn +sub_test endp + +_text ends + +; vim:expandtab diff --git a/tests/reg_call2.expect.c b/tests/reg_call2.expect.c new file mode 100644 index 0000000..b6de512 --- /dev/null +++ b/tests/reg_call2.expect.c @@ -0,0 +1,11 @@ +int __fastcall sub_test(int a1, int a2) +{ + u32 ecx = (u32)a1; + // edx = a2; // unused + u32 eax; + + eax = fastcall_func(ecx); + ecx++; + return eax; +} + diff --git a/tests/reg_call2.seed.h b/tests/reg_call2.seed.h new file mode 100644 index 0000000..c8834cb --- /dev/null +++ b/tests/reg_call2.seed.h @@ -0,0 +1,2 @@ +int __fastcall fastcall_func(int a1); +int __fastcall sub_test(int a1, int a2); // a2 unused diff --git a/tests/reg_call3.asm b/tests/reg_call3.asm new file mode 100644 index 0000000..1438637 --- /dev/null +++ b/tests/reg_call3.asm @@ -0,0 +1,15 @@ +; sub_test() has no args +; need this to be able to call fastcall funcs anywhere, as fastcall may +; sit in some fastcall table even when it doesn't use reg args + +_text segment para public 'CODE' use32 + +sub_test proc near + xor ebx, ebx + push 1 + jmp fastcall_func +sub_test endp + +_text ends + +; vim:expandtab diff --git a/tests/reg_call3.expect.c b/tests/reg_call3.expect.c new file mode 100644 index 0000000..41d7d2b --- /dev/null +++ b/tests/reg_call3.expect.c @@ -0,0 +1,10 @@ +void __fastcall sub_test() +{ + u32 ebx; + u32 ecx = 0; + u32 edx = 0; + + ebx = 0; + fastcall_func(ecx, edx, 1); // tailcall +} + diff --git a/tests/reg_call3.seed.h b/tests/reg_call3.seed.h new file mode 100644 index 0000000..1393f4c --- /dev/null +++ b/tests/reg_call3.seed.h @@ -0,0 +1,2 @@ +int __fastcall fastcall_func(int a1, int a2, int a3); +void __fastcall sub_test(); diff --git a/tests/reg_call_tail.asm b/tests/reg_call_tail.asm new file mode 100644 index 0000000..6fde801 --- /dev/null +++ b/tests/reg_call_tail.asm @@ -0,0 +1,11 @@ + +_text segment para public 'CODE' use32 + +sub_test proc near + mov ebx, 1 + jmp fastcall_func +sub_test endp + +_text ends + +; vim:expandtab diff --git a/tests/reg_call_tail.expect.c b/tests/reg_call_tail.expect.c new file mode 100644 index 0000000..eeb805b --- /dev/null +++ b/tests/reg_call_tail.expect.c @@ -0,0 +1,10 @@ +int __fastcall sub_test(int a1, int a2) +{ + u32 ecx = (u32)a1; + u32 edx = (u32)a2; + u32 ebx; + + ebx = 1; + return fastcall_func(ecx, edx); // tailcall +} + diff --git a/tests/reg_call_tail.seed.h b/tests/reg_call_tail.seed.h new file mode 100644 index 0000000..26e90ae --- /dev/null +++ b/tests/reg_call_tail.seed.h @@ -0,0 +1 @@ +int __fastcall fastcall_func(int a1, int a2); diff --git a/tests/reg_save.asm b/tests/reg_save.asm new file mode 100644 index 0000000..b3ad571 --- /dev/null +++ b/tests/reg_save.asm @@ -0,0 +1,20 @@ + +_text segment para public 'CODE' use32 + +sub_test proc near + push ebp + mov ebp, esp + push ebx + mov ebx, 1 + push ebx + mov ebx, 2 + pop ebx + or eax, 0FFFFFFFFh + pop ebx + pop ebp + retn +sub_test endp + +_text ends + +; vim:expandtab diff --git a/tests/reg_save.expect.c b/tests/reg_save.expect.c new file mode 100644 index 0000000..86e4d85 --- /dev/null +++ b/tests/reg_save.expect.c @@ -0,0 +1,14 @@ +int sub_test() +{ + u32 eax; + u32 ebx; + u32 s_ebx; + + ebx = 1; + s_ebx = ebx; + ebx = 2; + ebx = s_ebx; + eax = 0xffffffff; + return eax; +} + diff --git a/tests/reg_save.seed.h b/tests/reg_save.seed.h new file mode 100644 index 0000000..e69de29