test_milestones.py 830 Bytes
Newer Older
1
2
3
"""
Harness JIT tests using py.test framework
"""
John Zhang's avatar
John Zhang committed
4
from util import fncptr_from_c_script, may_spawn_proc
5
6
import ctypes

John Zhang's avatar
John Zhang committed
7
@may_spawn_proc
John Zhang's avatar
John Zhang committed
8
def test_constant_function():
John Zhang's avatar
John Zhang committed
9
    fn, _ = fncptr_from_c_script("test_constfunc.c", 'test_fnc')
10
11
    assert fn() == 0

John Zhang's avatar
John Zhang committed
12
@may_spawn_proc
13
def test_milsum():
John Zhang's avatar
John Zhang committed
14
    fn, _ = fncptr_from_c_script("test_milsum.c", "milsum", [ctypes.c_ulonglong])
15
16
    assert fn(1000000) == 500000500000

John Zhang's avatar
John Zhang committed
17
@may_spawn_proc
John Zhang's avatar
John Zhang committed
18
def test_factorial():
John Zhang's avatar
John Zhang committed
19
    fn, _ = fncptr_from_c_script("test_fac.c", "fac", [ctypes.c_ulonglong])
John Zhang's avatar
John Zhang committed
20
21
    assert fn(20) == 2432902008176640000

John Zhang's avatar
John Zhang committed
22
@may_spawn_proc
23
def test_fibonacci():
John Zhang's avatar
John Zhang committed
24
    fn, _ = fncptr_from_c_script("test_fib.c", "fib", [ctypes.c_ulonglong])
25
    assert fn(20) == 6765
26

John Zhang's avatar
John Zhang committed
27
@may_spawn_proc
28
def test_multifunc():
John Zhang's avatar
John Zhang committed
29
30
    fn, _ = fncptr_from_c_script("test_multifunc.c", "entry")
    assert fn() == 6765