Commit f5449b1a authored by John Zhang's avatar John Zhang

refactor

parent 09c2ba88
def test_add(): from test_harness import get_fncptr
src_c = "suite/test_add.c"
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
def test_add():
fn = get_fncptr("suite/test_add.c", "test_fnc")
assert fn() == 9 assert fn() == 9
def test_sub(): def test_sub():
src_c = "suite/test_sub.c" fn = get_fncptr("suite/test_sub.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 11 assert fn() == 11
def test_mul(): def test_mul():
src_c = "suite/test_mul.c" fn = get_fncptr("suite/test_mul.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 0xf6 assert fn() == 0xf6
def test_sdiv(): def test_sdiv():
src_c = "suite/test_sdiv.c" fn = get_fncptr("suite/test_sdiv.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 0xf4 assert fn() == 0xf4
def test_urem(): def test_urem():
src_c = "suite/test_urem.c" fn = get_fncptr("suite/test_urem.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 5 assert fn() == 5
def test_shl(): def test_shl():
src_c = "suite/test_shl.c" fn = get_fncptr("suite/test_shl.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 0x7e707560c92d5400 assert fn() == 0x7e707560c92d5400
def test_lshr(): def test_lshr():
src_c = "suite/test_shr.c" fn = get_fncptr("suite/test_lshr.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 0x2367e707560c92 assert fn() == 0x2367e707560c92
def test_and(): def test_and():
src_c = "suite/test_and.c" fn = get_fncptr("suite/test_and.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 0x8588901c10004b14 assert fn() == 0x8588901c10004b14
def test_xor(): def test_xor():
src_c = "suite/test_xor.c" fn = get_fncptr("suite/test_xor.c", "test_fnc")
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn() == 0x58376ec3e83fa0e1 assert fn() == 0x58376ec3e83fa0e1
...@@ -38,20 +38,14 @@ def get_lib(src_c): ...@@ -38,20 +38,14 @@ def get_lib(src_c):
return out.strip() return out.strip()
def test_constant_function(): def get_fncptr(src_c, entry_fnc):
src_c = "suite/test_constfunc.c"
entry_fnc = "test_fnc"
lib = ctypes.CDLL(get_lib(src_c)) lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc) return getattr(lib, entry_fnc)
def test_constant_function():
fn = get_fncptr("suite/test_constfunc.c", "test_fnc")
assert fn() == 0 assert fn() == 0
def test_factorial(): def test_factorial():
src_c = "suite/test_fib.c" fn = get_fncptr("suite/test_fib.c", "fib")
entry_fnc = "fib"
lib = ctypes.CDLL(get_lib(src_c))
fn = getattr(lib, entry_fnc)
assert fn(20) == 6765 assert fn(20) == 6765
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