コード例 #1
0
ファイル: test_memops.py プロジェクト: jstnlef/zebu-vm
def test_uptr_bytestore_load():
    fn, _ = fncptr_from_c_script("test_uptr_bytestore_load.c",
                                 "test_fnc",
                                 argtypes=[ctypes.POINTER(ctypes.c_uint32)],
                                 restype=ctypes.c_uint32)

    # allocate memory through ctypes
    ui32 = ctypes.c_uint32()
    assert fn(ctypes.byref(ui32)) == 0x8d9f9c1d
    assert ui32.value == 0x8d9f9c1d
コード例 #2
0
ファイル: test_memops.py プロジェクト: jstnlef/zebu-vm
def test_getvarpartiref_nofix():
    Arr = ctypes.ARRAY(ctypes.c_uint32, 3)

    fn, _ = fncptr_from_c_script("test_getvarpartiref_nofix.c",
                                 "test_fnc",
                                 argtypes=[ctypes.POINTER(Arr)],
                                 restype=ctypes.c_uint32)
    arr = Arr()
    arr[0] = 0xcafebabe
    arr[1] = 0xbecca
    arr[2] = 0xfaebee

    res = fn(ctypes.byref(arr))
    assert res == 0xcafebabe, "result: %s" % hex(res)
コード例 #3
0
ファイル: test_memops.py プロジェクト: jstnlef/zebu-vm
def test_getelemiref():
    Arr = ctypes.ARRAY(ctypes.c_int64, 5)
    fn, _ = fncptr_from_c_script("test_getelemiref.c",
                                 "test_fnc",
                                 argtypes=[ctypes.POINTER(Arr)],
                                 restype=ctypes.c_int64)
    arr = Arr()
    arr[0] = -23
    arr[1] = 35
    arr[2] = 42
    arr[3] = 0
    arr[4] = 152

    res = fn(ctypes.byref(arr), 2)
    assert res == 42, "result: %d" % res
コード例 #4
0
ファイル: test_memops.py プロジェクト: jstnlef/zebu-vm
def test_getvarpartiref():
    class Stt(ctypes.Structure):
        _fields_ = [('ui8', ctypes.c_uint8), ('ui64', ctypes.c_uint64),
                    ('ui32s', ctypes.ARRAY(ctypes.c_uint32, 5))]

    fn, _ = fncptr_from_c_script("test_getvarpartiref.c",
                                 "test_fnc",
                                 argtypes=[ctypes.POINTER(Stt)],
                                 restype=ctypes.c_uint32)
    stt = Stt()
    stt.ui8 = 25
    stt.ui64 = 0xabcdef0123456789
    stt.ui32s[0] = 0xcafebabe

    res = fn(ctypes.byref(stt))
    assert res == 0xcafebabe, "result: %s" % hex(res)
コード例 #5
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_div():
    fnp, _ = fncptr_from_c_script("test_double_div.c",
                                  "test_fnc",
                                  restype=ctypes.c_double)
    assert within_err(fnp(), 1.1557282546316052)
コード例 #6
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_sub():
    fnp, _ = fncptr_from_c_script("test_double_sub.c",
                                  "test_fnc",
                                  restype=ctypes.c_double)
    assert within_err(fnp(), 0.423313)
コード例 #7
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_mul():
    fnp, _ = fncptr_from_c_script("test_double_mul.c",
                                  "test_fnc",
                                  restype=ctypes.c_double)
    assert fnp() == 8.53972942004
コード例 #8
0
ファイル: test_binops.py プロジェクト: jstnlef/zebu-vm
def test_xor():
    fn, _ = fncptr_from_c_script("test_xor.c",
                                 "test_fnc",
                                 restype=ctypes.c_uint64)
    assert fn() == 0x58376ec3e83fa0e1
コード例 #9
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_add():
    fnp, _ = fncptr_from_c_script("test_double_add.c",
                                  "test_fnc",
                                  restype=ctypes.c_double)
    assert fnp() == 5.859873
コード例 #10
0
ファイル: test_milestones.py プロジェクト: jstnlef/zebu-vm
def test_constant_function():
    fn, _ = fncptr_from_c_script("test_constfunc.c", 'test_fnc')
    assert fn() == 0
コード例 #11
0
ファイル: test_binops.py プロジェクト: jstnlef/zebu-vm
def test_and():
    fn, _ = fncptr_from_c_script("test_and.c",
                                 "test_fnc",
                                 restype=ctypes.c_uint64)
    assert fn() == 0x8588901c10004b14
コード例 #12
0
ファイル: test_binops.py プロジェクト: jstnlef/zebu-vm
def test_srem():
    fn, _ = fncptr_from_c_script("test_srem.c",
                                 "test_fnc",
                                 restype=ctypes.c_uint8)
    assert fn() == 0xff  # -1
コード例 #13
0
ファイル: test_milestones.py プロジェクト: jstnlef/zebu-vm
def test_factorial():
    fn, _ = fncptr_from_c_script("test_fac.c", "fac", [ctypes.c_ulonglong])
    assert fn(20) == 2432902008176640000
コード例 #14
0
def test_commoninst_pin():
    mu = mu_instance_via_ctyeps()
    fnp, _ = fncptr_from_c_script("test_commoninst_pin.c", 'test_pin')
    assert fnp() == 6
コード例 #15
0
ファイル: test_binops.py プロジェクト: jstnlef/zebu-vm
def test_shl():
    fn, _ = fncptr_from_c_script("test_shl.c",
                                 "test_fnc",
                                 restype=ctypes.c_uint64)
    assert fn() == 0x7e707560c92d5400
コード例 #16
0
def test_select():
    fnp, _ = fncptr_from_c_script('test_select.c', 'test_fnc', [ctypes.c_byte])
    assert fnp(0) == 20
    assert fnp(1) == 10
コード例 #17
0
ファイル: test_convops.py プロジェクト: jstnlef/zebu-vm
def test_zext():
    fn, _ = fncptr_from_c_script("test_zext.c", "test_fnc")
    assert fn() == 0x00000000a8324b55
コード例 #18
0
ファイル: test_convops.py プロジェクト: jstnlef/zebu-vm
def test_trunc():
    fn, _ = fncptr_from_c_script("test_trunc.c", "test_fnc", restype=ctypes.c_uint32)
    assert fn() == 0x58324b55
コード例 #19
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_ordered_gt():
    fnp, _ = fncptr_from_c_script("test_double_ordered_gt.c", "test_fnc")
    assert fnp() == 1
コード例 #20
0
ファイル: test_milestones.py プロジェクト: jstnlef/zebu-vm
def test_multifunc():
    fn, _ = fncptr_from_c_script("test_multifunc.c", "entry")
    assert fn() == 6765
コード例 #21
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_arg_pass():
    fnp, _ = fncptr_from_c_script("test_double_arg_pass.c", "test_fnc",
                                  [ctypes.c_double, ctypes.c_double],
                                  ctypes.c_double)
    assert fnp(3.141593, 2.71828) == 5.859873
コード例 #22
0
def test_ne_ref():
    mu = mu_instance_via_ctyeps()
    fn, _ = fncptr_from_c_script("test_ne_ref.c", "test_fnc")
    assert fn() == 1
コード例 #23
0
ファイル: test_milestones.py プロジェクト: jstnlef/zebu-vm
def test_milsum():
    fn, _ = fncptr_from_c_script("test_milsum.c", "milsum", [ctypes.c_ulonglong])
    assert fn(1000000) == 500000500000
コード例 #24
0
ファイル: test_binops.py プロジェクト: jstnlef/zebu-vm
def test_lshr():
    fn, _ = fncptr_from_c_script("test_lshr.c",
                                 "test_fnc",
                                 restype=ctypes.c_uint64)
    assert fn() == 0x2367e707560c92
コード例 #25
0
ファイル: test_milestones.py プロジェクト: jstnlef/zebu-vm
def test_fibonacci():
    fn, _ = fncptr_from_c_script("test_fib.c", "fib", [ctypes.c_ulonglong])
    assert fn(20) == 6765
コード例 #26
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_uitofp():
    fnp, _ = fncptr_from_c_script("test_double_uitofp.c",
                                  "test_fnc",
                                  restype=ctypes.c_double)
    assert fnp() == 42.0
コード例 #27
0
def test_ne_int():
    fn, _ = fncptr_from_c_script("test_ne_int.c", "test_fnc")
    assert fn() == 1
コード例 #28
0
ファイル: test_double.py プロジェクト: jstnlef/zebu-vm
def test_double_fptoui():
    fnp, _ = fncptr_from_c_script("test_double_fptoui.c",
                                  "test_fnc",
                                  restype=ctypes.c_uint64)
    assert fnp() == 3
コード例 #29
0
def test_ult():
    fn, _ = fncptr_from_c_script("test_ult.c",
                                 "test_fnc",
                                 restype=ctypes.c_uint8)
    assert fn() == 0
コード例 #30
0
ファイル: test_binops.py プロジェクト: jstnlef/zebu-vm
def test_or():
    fn, _ = fncptr_from_c_script("test_or.c",
                                 "test_fnc",
                                 restype=ctypes.c_uint64)
    assert fn() == 0xddbffedff83febf5