GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

test_controlflow.py 811 Bytes
Newer Older
John Zhang's avatar
John Zhang committed
1
from util import fncptr_from_c_script
2
import ctypes, ctypes.util
3 4


John Zhang's avatar
John Zhang committed
5
def test_branch():
John Zhang's avatar
John Zhang committed
6
    fn, _ = fncptr_from_c_script("test_branch.c", "test_fnc")
John Zhang's avatar
John Zhang committed
7 8 9
    assert fn() == 30

def test_branch2():
John Zhang's avatar
John Zhang committed
10
    fn, _ = fncptr_from_c_script("test_branch2.c", "test_fnc", [ctypes.c_byte])
John Zhang's avatar
John Zhang committed
11 12 13
    assert fn(1) == 30
    assert fn(0) == 200

14
def test_ccall():
John Zhang's avatar
John Zhang committed
15
    fn, _ = fncptr_from_c_script("test_ccall.c", "test_ccall", [ctypes.c_ulonglong])
16
    assert fn(0x7e707560c92d5400) == 0x7e707560c92d5400
17 18 19

def test_extern_func():
    # libc = ctypes.CDLL(ctypes.util.find_library('c'), ctypes.RTLD_GLOBAL)
John Zhang's avatar
John Zhang committed
20
    fn, _ = fncptr_from_c_script("test_extern_func.c", "test_write", [ctypes.c_void_p, ctypes.c_size_t], ctypes.c_int64)
21 22
    buf = ctypes.create_string_buffer('hello world!\n')
    assert fn(ctypes.byref(buf), len(buf)) == len(buf)