To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit a3f6e910 authored by John Zhang's avatar John Zhang
Browse files

set argument types and result type of c function pointer

parent 8fe2188a
from test_milestones import get_fncptr from test_milestones import get_fncptr
import subprocess as subp import ctypes
def test_ccall(): def test_ccall():
fn = get_fncptr("test_ccall", "test_ccall") fn = get_fncptr("test_ccall", "test_ccall", [ctypes.c_ulonglong])
assert fn(0x7e707560c92d5400) == 0x7e707560c92d5400 assert fn(0x7e707560c92d5400) == 0x7e707560c92d5400
...@@ -45,21 +45,24 @@ def compile_lib(testname): ...@@ -45,21 +45,24 @@ def compile_lib(testname):
return str(bin_dir.join('emit', testname + '.dylib')) return str(bin_dir.join('emit', testname + '.dylib'))
def get_fncptr(testname, entry_fnc): def get_fncptr(testname, entry_fnc, argtypes=[], restype=ctypes.c_ulonglong):
lib_path = compile_lib(testname) lib_path = compile_lib(testname)
lib = ctypes.CDLL(lib_path) lib = ctypes.CDLL(lib_path)
return getattr(lib, entry_fnc) fncptr = getattr(lib, entry_fnc)
fncptr.restype = restype
fncptr.argtypes = argtypes
return fncptr
def test_constant_function(): def test_constant_function():
fn = get_fncptr("test_constfunc", 'test_fnc') fn = get_fncptr("test_constfunc", 'test_fnc')
assert fn() == 0 assert fn() == 0
def test_milsum(): def test_milsum():
fn = get_fncptr("test_milsum", "milsum") fn = get_fncptr("test_milsum", "milsum", [ctypes.c_ulonglong])
assert fn(1000000) == 500000500000 assert fn(1000000) == 500000500000
def test_fibonacci(): def test_fibonacci():
fn = get_fncptr("test_fib", "fib") fn = get_fncptr("test_fib", "fib", [ctypes.c_ulonglong])
assert fn(20) == 6765 assert fn(20) == 6765
def test_multifunc(): def test_multifunc():
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