Commit 6648dbf0 authored by John Zhang's avatar John Zhang

add may_spawn_proc to every test

parent 12f26146
from util import fncptr_from_c_script
from util import fncptr_from_c_script, may_spawn_proc
import ctypes
@may_spawn_proc
def test_add():
fn, _ = fncptr_from_c_script("test_add.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 9
@may_spawn_proc
def test_sub():
fn, _ = fncptr_from_c_script("test_sub.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 11
@may_spawn_proc
def test_mul():
fn, _ = fncptr_from_c_script("test_mul.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 0xf6
@may_spawn_proc
def test_sdiv():
fn, _ = fncptr_from_c_script("test_sdiv.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 0xf4
@may_spawn_proc
def test_udiv():
fn, _ = fncptr_from_c_script("test_udiv.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 12
@may_spawn_proc
def test_srem():
fn, _ = fncptr_from_c_script("test_srem.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 0xff # -1
@may_spawn_proc
def test_urem():
fn, _ = fncptr_from_c_script("test_urem.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 5
@may_spawn_proc
def test_shl():
fn, _ = fncptr_from_c_script("test_shl.c", "test_fnc", restype=ctypes.c_uint64)
assert fn() == 0x7e707560c92d5400
@may_spawn_proc
def test_ashr():
fn, _ = fncptr_from_c_script("test_ashr.c", "test_fnc", restype=ctypes.c_uint64)
assert fn() == 0xffe367e707560c92
@may_spawn_proc
def test_lshr():
fn, _ = fncptr_from_c_script("test_lshr.c", "test_fnc", restype=ctypes.c_uint64)
assert fn() == 0x2367e707560c92
@may_spawn_proc
def test_and():
fn, _ = fncptr_from_c_script("test_and.c", "test_fnc", restype=ctypes.c_uint64)
assert fn() == 0x8588901c10004b14
@may_spawn_proc
def test_or():
fn, _ = fncptr_from_c_script("test_or.c", "test_fnc", restype=ctypes.c_uint64)
assert fn() == 0xddbffedff83febf5
def test_xor():
fn, _ = fncptr_from_c_script("test_xor.c", "test_fnc", restype=ctypes.c_uint64)
assert fn() == 0x58376ec3e83fa0e1
from util import fncptr_from_c_script, may_spawn_proc, mu_instance_via_ctyeps
import ctypes
@may_spawn_proc
def test_eq_int():
fn, _ = fncptr_from_c_script("test_eq_int.c", "test_fnc")
assert fn() == 0
......@@ -11,6 +12,7 @@ def test_eq_ref():
fn, _ = fncptr_from_c_script("test_eq_ref.c", "test_fnc")
assert fn() == 0
@may_spawn_proc
def test_ne_int():
fn, _ = fncptr_from_c_script("test_ne_int.c", "test_fnc")
assert fn() == 1
......@@ -21,26 +23,32 @@ def test_ne_ref():
fn, _ = fncptr_from_c_script("test_ne_ref.c", "test_fnc")
assert fn() == 1
@may_spawn_proc
def test_sge():
fn, _ = fncptr_from_c_script("test_sge.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 1
@may_spawn_proc
def test_sgt():
fn, _ = fncptr_from_c_script("test_sgt.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 0
@may_spawn_proc
def test_sle():
fn, _ = fncptr_from_c_script("test_sle.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 1
@may_spawn_proc
def test_ule():
fn, _ = fncptr_from_c_script("test_ule.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 1
@may_spawn_proc
def test_slt():
fn, _ = fncptr_from_c_script("test_slt.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 0
@may_spawn_proc
def test_ult():
fn, _ = fncptr_from_c_script("test_ult.c", "test_fnc", restype=ctypes.c_uint8)
assert fn() == 0
from util import fncptr_from_c_script
from util import fncptr_from_c_script, may_spawn_proc
import ctypes, ctypes.util
@may_spawn_proc
def test_branch():
fn, _ = fncptr_from_c_script("test_branch.c", "test_fnc")
assert fn() == 30
@may_spawn_proc
def test_branch2():
fn, _ = fncptr_from_c_script("test_branch2.c", "test_fnc", [ctypes.c_byte])
assert fn(1) == 30
assert fn(0) == 200
@may_spawn_proc
def test_ccall():
fn, _ = fncptr_from_c_script("test_ccall.c", "test_ccall", [ctypes.c_ulonglong])
assert fn(0x7e707560c92d5400) == 0x7e707560c92d5400
@may_spawn_proc
def test_extern_func():
# libc = ctypes.CDLL(ctypes.util.find_library('c'), ctypes.RTLD_GLOBAL)
fn, _ = fncptr_from_c_script("test_extern_func.c", "test_write", [ctypes.c_void_p, ctypes.c_size_t], ctypes.c_int64)
......
from util import fncptr_from_c_script
from util import fncptr_from_c_script, may_spawn_proc
import ctypes
@may_spawn_proc
def test_trunc():
fn, _ = fncptr_from_c_script("test_trunc.c", "test_fnc", restype=ctypes.c_uint32)
assert fn() == 0x58324b55
@may_spawn_proc
def test_sext():
fn, _ = fncptr_from_c_script("test_sext.c", "test_fnc")
assert fn() == 0xffffffffa8324b55
@may_spawn_proc
def test_zext():
fn, _ = fncptr_from_c_script("test_zext.c", "test_fnc")
assert fn() == 0x00000000a8324b55
from util import fncptr_from_c_script
from util import fncptr_from_c_script, may_spawn_proc
import ctypes
import pytest
......@@ -6,79 +6,82 @@ def within_err(res, exp, err=1e15):
return abs(res - exp) < err
@may_spawn_proc
def test_double_add():
fnp, _ = fncptr_from_c_script("test_double_add.c", "test_fnc", restype=ctypes.c_double)
assert fnp() == 5.859873
@may_spawn_proc
def test_double_sub():
fnp, _ = fncptr_from_c_script("test_double_sub.c", "test_fnc", restype=ctypes.c_double)
assert within_err(fnp(), 0.423313)
@may_spawn_proc
def test_double_mul():
fnp, _ = fncptr_from_c_script("test_double_mul.c", "test_fnc", restype=ctypes.c_double)
assert fnp() == 8.53972942004
@may_spawn_proc
def test_double_div():
fnp, _ = fncptr_from_c_script("test_double_div.c", "test_fnc", restype=ctypes.c_double)
assert within_err(fnp(), 1.1557282546316052)
@may_spawn_proc
def test_double_ordered_eq():
fnp, _ = fncptr_from_c_script("test_double_ordered_eq.c", "test_fnc")
assert fnp() == 0
@may_spawn_proc
def test_double_ordered_ne():
fnp, _ = fncptr_from_c_script("test_double_ordered_ne.c", "test_fnc")
assert fnp() == 1
@may_spawn_proc
def test_double_ordered_lt():
fnp, _ = fncptr_from_c_script("test_double_ordered_lt.c", "test_fnc")
assert fnp() == 1
@may_spawn_proc
def test_double_ordered_le():
fnp, _ = fncptr_from_c_script("test_double_ordered_le.c", "test_fnc")
assert fnp() == 1
@may_spawn_proc
def test_double_ordered_ge():
fnp, _ = fncptr_from_c_script("test_double_ordered_ge.c", "test_fnc")
assert fnp() == 1
@may_spawn_proc
def test_double_ordered_gt():
fnp, _ = fncptr_from_c_script("test_double_ordered_gt.c", "test_fnc")
assert fnp() == 1
@may_spawn_proc
def test_double_arg_pass():
fnp, _ = fncptr_from_c_script("test_double_arg_pass.c", "test_fnc",
[ctypes.c_double, ctypes.c_double], ctypes.c_double)
assert fnp(3.141593, 2.71828) == 5.859873
@may_spawn_proc
def test_double_sitofp():
fnp, _ = fncptr_from_c_script("test_double_sitofp.c", "test_fnc", restype=ctypes.c_double)
assert fnp() == -42.0
@pytest.mark.xfail(reason='not implemented yet')
@may_spawn_proc
def test_double_uitofp():
fnp, _ = fncptr_from_c_script("test_double_uitofp.c", "test_fnc", restype=ctypes.c_double)
assert fnp() == 42.0
@may_spawn_proc
def test_double_fptosi():
fnp, _ = fncptr_from_c_script("test_double_fptosi.c", "test_fnc", restype=ctypes.c_int64)
assert fnp() == -3
@pytest.mark.xfail(reason='not implemented yet')
@may_spawn_proc
def test_double_fptoui():
fnp, _ = fncptr_from_c_script("test_double_fptoui.c", "test_fnc", restype=ctypes.c_uint64)
assert fnp() == 3
......
from util import fncptr_from_c_script
from util import fncptr_from_c_script, may_spawn_proc
import ctypes
@may_spawn_proc
def test_uptr_bytestore_load():
fn, _ = fncptr_from_c_script("test_uptr_bytestore_load.c", "test_fnc",
argtypes=[ctypes.POINTER(ctypes.c_uint32)],
......@@ -12,7 +13,7 @@ def test_uptr_bytestore_load():
assert fn(ctypes.byref(ui32)) == 0x8d9f9c1d
assert ui32.value == 0x8d9f9c1d
@may_spawn_proc
def test_getfieldiref():
class Stt(ctypes.Structure):
_fields_ = [('ui8', ctypes.c_uint8),
......@@ -30,7 +31,7 @@ def test_getfieldiref():
res = fn(ctypes.byref(stt))
assert res == 0xcafebabe, "result: %s" % hex(res)
@may_spawn_proc
def test_getelemiref():
Arr = ctypes.ARRAY(ctypes.c_int64, 5)
fn, _ = fncptr_from_c_script("test_getelemiref.c", "test_fnc",
......@@ -46,7 +47,7 @@ def test_getelemiref():
res = fn(ctypes.byref(arr), 2)
assert res == 42, "result: %d" % res
@may_spawn_proc
def test_getvarpartiref():
class Stt(ctypes.Structure):
_fields_ = [('ui8', ctypes.c_uint8),
......@@ -64,7 +65,7 @@ def test_getvarpartiref():
res = fn(ctypes.byref(stt))
assert res == 0xcafebabe, "result: %s" % hex(res)
@may_spawn_proc
def test_getvarpartiref_nofix():
Arr = ctypes.ARRAY(ctypes.c_uint32, 3)
......
"""
Harness JIT tests using py.test framework
"""
from util import fncptr_from_c_script
from util import fncptr_from_c_script, may_spawn_proc
import ctypes
@may_spawn_proc
def test_constant_function():
fn, _ = fncptr_from_c_script("test_constfunc.c", 'test_fnc')
assert fn() == 0
@may_spawn_proc
def test_milsum():
fn, _ = fncptr_from_c_script("test_milsum.c", "milsum", [ctypes.c_ulonglong])
assert fn(1000000) == 500000500000
@may_spawn_proc
def test_factorial():
fn, _ = fncptr_from_c_script("test_fac.c", "fac", [ctypes.c_ulonglong])
assert fn(20) == 2432902008176640000
@may_spawn_proc
def test_fibonacci():
fn, _ = fncptr_from_c_script("test_fib.c", "fib", [ctypes.c_ulonglong])
assert fn(20) == 6765
@may_spawn_proc
def test_multifunc():
fn, _ = fncptr_from_c_script("test_multifunc.c", "entry")
assert fn() == 6765
from util import fncptr_from_c_script, mu_instance_via_ctyeps, may_spawn_proc
import ctypes
@may_spawn_proc
def test_select():
fnp, _ = fncptr_from_c_script('test_select.c', 'test_fnc', [ctypes.c_byte])
assert fnp(0) == 20
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment