Browse Source
Added the "long" modffi tests. The tests could not be added to the existing ffi_types test because two .exp files were required for the 32-bit and 64-bit results. Code common to both the ffi_types and type "long" tests was factored into ffi_int_base. ffi_types was renamed to ffi_int_types to group the related tests under the "ffi_int" prefix. Signed-off-by: Michael Sawyer <mjfsawyer@gmail.com>pull/15225/head
Michael Sawyer
2 months ago
committed by
Damien George
9 changed files with 173 additions and 51 deletions
@ -0,0 +1,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 |
@ -0,0 +1,16 @@ |
|||
# test 32-bit long arguments and return types for ffi functions |
|||
|
|||
import struct |
|||
|
|||
import ffi_int_base |
|||
|
|||
if struct.calcsize("l") != 4: |
|||
print("SKIP") |
|||
raise SystemExit |
|||
|
|||
ffi_int_base.test( |
|||
[ |
|||
("l", "fli"), |
|||
("L", "flu"), |
|||
] |
|||
) |
@ -0,0 +1,34 @@ |
|||
fli(0) = 1 |
|||
fli(7f) = 7e |
|||
fli(80) = 81 |
|||
fli(ff) = fe |
|||
fli(100) = 101 |
|||
fli(7fff) = 7ffe |
|||
fli(8000) = 8001 |
|||
fli(ffff) = fffe |
|||
fli(10000) = 10001 |
|||
fli(7fffffff) = 7ffffffe |
|||
fli(80000000) = -7fffffff |
|||
fli(ffffffff) = -2 |
|||
fli(100000000) = 1 |
|||
fli(7fffffffffffffff) = -2 |
|||
fli(8000000000000000) = 1 |
|||
fli(ffffffffffffffff) = -2 |
|||
fli(10000000000000000) = 1 |
|||
flu(0) = 1 |
|||
flu(7f) = 7e |
|||
flu(80) = 81 |
|||
flu(ff) = fe |
|||
flu(100) = 101 |
|||
flu(7fff) = 7ffe |
|||
flu(8000) = 8001 |
|||
flu(ffff) = fffe |
|||
flu(10000) = 10001 |
|||
flu(7fffffff) = 7ffffffe |
|||
flu(80000000) = 80000001 |
|||
flu(ffffffff) = fffffffe |
|||
flu(100000000) = 1 |
|||
flu(7fffffffffffffff) = fffffffe |
|||
flu(8000000000000000) = 1 |
|||
flu(ffffffffffffffff) = fffffffe |
|||
flu(10000000000000000) = 1 |
@ -0,0 +1,16 @@ |
|||
# test 64-bit long arguments and return types for ffi functions |
|||
|
|||
import struct |
|||
|
|||
import ffi_int_base |
|||
|
|||
if struct.calcsize("l") != 8: |
|||
print("SKIP") |
|||
raise SystemExit |
|||
|
|||
ffi_int_base.test( |
|||
[ |
|||
("l", "fli"), |
|||
("L", "flu"), |
|||
] |
|||
) |
@ -0,0 +1,34 @@ |
|||
fli(0) = 1 |
|||
fli(7f) = 7e |
|||
fli(80) = 81 |
|||
fli(ff) = fe |
|||
fli(100) = 101 |
|||
fli(7fff) = 7ffe |
|||
fli(8000) = 8001 |
|||
fli(ffff) = fffe |
|||
fli(10000) = 10001 |
|||
fli(7fffffff) = 7ffffffe |
|||
fli(80000000) = 80000001 |
|||
fli(ffffffff) = fffffffe |
|||
fli(100000000) = 100000001 |
|||
fli(7fffffffffffffff) = 7ffffffffffffffe |
|||
fli(8000000000000000) = -7fffffffffffffff |
|||
fli(ffffffffffffffff) = -2 |
|||
fli(10000000000000000) = 1 |
|||
flu(0) = 1 |
|||
flu(7f) = 7e |
|||
flu(80) = 81 |
|||
flu(ff) = fe |
|||
flu(100) = 101 |
|||
flu(7fff) = 7ffe |
|||
flu(8000) = 8001 |
|||
flu(ffff) = fffe |
|||
flu(10000) = 10001 |
|||
flu(7fffffff) = 7ffffffe |
|||
flu(80000000) = 80000001 |
|||
flu(ffffffff) = fffffffe |
|||
flu(100000000) = 100000001 |
|||
flu(7fffffffffffffff) = 7ffffffffffffffe |
|||
flu(8000000000000000) = 8000000000000001 |
|||
flu(ffffffffffffffff) = fffffffffffffffe |
|||
flu(10000000000000000) = 1 |
@ -0,0 +1,16 @@ |
|||
# test 8/16/32/64 bit signed/unsigned integer arguments and return types for ffi functions |
|||
|
|||
import ffi_int_base |
|||
|
|||
ffi_int_base.test( |
|||
[ |
|||
("b", "f8i"), |
|||
("B", "f8u"), |
|||
("h", "f16i"), |
|||
("H", "f16u"), |
|||
("i", "f32i"), |
|||
("I", "f32u"), |
|||
("q", "f64i"), |
|||
("Q", "f64u"), |
|||
] |
|||
) |
@ -1,51 +0,0 @@ |
|||
# test 8/16/32/64 bit signed/unsigned integer arguments and return types for ffi functions |
|||
# 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) |
|||
|
|||
f8i = ffi_lib.func("b", "f8i", "b") |
|||
f8u = ffi_lib.func("B", "f8u", "B") |
|||
f16i = ffi_lib.func("h", "f16i", "h") |
|||
f16u = ffi_lib.func("H", "f16u", "H") |
|||
f32i = ffi_lib.func("i", "f32i", "i") |
|||
f32u = ffi_lib.func("I", "f32u", "I") |
|||
f64i = ffi_lib.func("q", "f64i", "q") |
|||
f64u = ffi_lib.func("Q", "f64u", "Q") |
|||
|
|||
for func_name in ("f8i", "f8u", "f16i", "f16u", "f32i", "f32u", "f64i", "f64u"): |
|||
func = globals()[func_name] |
|||
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(func_name, val, func(val))) |
Loading…
Reference in new issue