To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

test_milestones.py 2.34 KB
Newer Older
1
2
3
4
5
6
"""
Harness JIT tests using py.test framework
"""
import subprocess as subp
import os, sys
import ctypes
7
import py
8
9

CC = 'clang'
John Zhang's avatar
John Zhang committed
10
11
12
13
14
15
proj_dir = py.path.local(__file__).join('..', '..', '..')
test_jit_dir = proj_dir.join('tests', 'test_jit')
testsuite_dir = test_jit_dir.join('suite')
bin_dir = test_jit_dir.join('temp')
if not bin_dir.exists():
    bin_dir.mkdir()
16
17
18
19

def compile_lib(testname):
    src_c = testsuite_dir.join(testname + '.c')
    bin_path = bin_dir.join(testname)
John Zhang's avatar
John Zhang committed
20
21
22
23
24
25
    CFLAGS = [
        "-std=c99",
        "-I%(proj_dir)s/src/vm/api" % globals(),
        "-L%(proj_dir)s/target/debug" % globals(),
        "-lmu",
    ]
26
    cmd = [CC] + CFLAGS + ['-o', str(bin_path)] + [str(src_c)]
27
28
29
30
31
32
33
34

    # compile
    p = subp.Popen(cmd, stdout=subp.PIPE, stderr=subp.PIPE, env=os.environ)
    out, err = p.communicate()
    if p.returncode != 0:  # failed
        sys.stdout.write(out + '\n')
        sys.stderr.write(err + '\n')
        raise subp.CalledProcessError(p.returncode, cmd)
35
36
     
    os.environ['LD_LIBRARY_PATH'] = "%s:%s" % ("%(proj_dir)s/target/debug" % globals(),
37
                                               os.environ['LD_LIBRARY_PATH'] if 'LD_LIBRARY_PATH' in os.environ else "")
38
    # run
39
    p = subp.Popen([str(bin_path)], stdout=subp.PIPE, stderr=subp.PIPE, cwd=str(bin_dir), env=os.environ)
40
41
42
43
44
45
    out, err = p.communicate()
    if p.returncode != 0:  # failed
        sys.stdout.write(out + '\n')
        sys.stderr.write(err + '\n')
        raise subp.CalledProcessError(p.returncode, bin_path)

46
    return str(bin_dir.join('emit', testname + '.dylib'))
47

48
def get_fncptr(testname, entry_fnc, argtypes=[], restype=ctypes.c_ulonglong):
49
50
    lib_path = compile_lib(testname)
    lib = ctypes.CDLL(lib_path)
51
52
53
54
    fncptr = getattr(lib, entry_fnc)
    fncptr.restype = restype
    fncptr.argtypes = argtypes
    return fncptr
55

John Zhang's avatar
John Zhang committed
56
def test_constant_function():
57
    fn = get_fncptr("test_constfunc", 'test_fnc')
58
59
    assert fn() == 0

60
def test_milsum():
61
    fn = get_fncptr("test_milsum", "milsum", [ctypes.c_ulonglong])
62
63
    assert fn(1000000) == 500000500000

John Zhang's avatar
John Zhang committed
64
65
66
67
def test_factorial():
    fn = get_fncptr("test_fac", "fac", [ctypes.c_ulonglong])
    assert fn(20) == 2432902008176640000

68
def test_fibonacci():
69
    fn = get_fncptr("test_fib", "fib", [ctypes.c_ulonglong])
70
    assert fn(20) == 6765
71
72

def test_multifunc():
73
    fn = get_fncptr("test_multifunc", "entry")
74
    assert fn() == 6765