summaryrefslogtreecommitdiff
path: root/tests/ports/unix/ffi_int_base.py
blob: 906bc3c1e1467ee66f18c18be546ae8f82e41895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# common tests for ffi_int_types/long32/long64
# requires ffi_lib.c to be compiled as: $(CC) -shared -o ffi_lib.so ffi_lib.c

import os, sys

try:
    import ffi
except ImportError:
    print("SKIP")
    raise SystemExit

ffi_lib_filename = sys.argv[0].rsplit("/", 1)[0] + "/ffi_lib.so"
try:
    os.stat(ffi_lib_filename)
except OSError:
    print("SKIP")
    raise SystemExit

ffi_lib = ffi.open(ffi_lib_filename)


def test(funcs):
    for type, name in funcs:
        func = ffi_lib.func(type, name, type)
        for val in (
            0,
            0x7F,
            0x80,
            0xFF,
            0x100,
            0x7FFF,
            0x8000,
            0xFFFF,
            0x10000,
            0x7FFFFFFF,
            0x80000000,
            0xFFFFFFFF,
            0x100000000,
            0x7FFF_FFFF_FFFF_FFFF,
            0x8000_0000_0000_0000,
            0xFFFF_FFFF_FFFF_FFFF,
            0x1_0000_0000_0000_0000,
        ):
            print("{}({:x}) = {:x}".format(name, val, func(val)))


if __name__ == "__main__":
    print("SKIP")
    raise SystemExit