summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/ports/unix/ffi_int_base.py49
-rw-r--r--tests/ports/unix/ffi_int_long32.py16
-rw-r--r--tests/ports/unix/ffi_int_long32.py.exp34
-rw-r--r--tests/ports/unix/ffi_int_long64.py16
-rw-r--r--tests/ports/unix/ffi_int_long64.py.exp34
-rw-r--r--tests/ports/unix/ffi_int_types.py16
-rw-r--r--tests/ports/unix/ffi_int_types.py.exp (renamed from tests/ports/unix/ffi_types.py.exp)0
-rw-r--r--tests/ports/unix/ffi_lib.c8
-rw-r--r--tests/ports/unix/ffi_types.py51
9 files changed, 173 insertions, 51 deletions
diff --git a/tests/ports/unix/ffi_int_base.py b/tests/ports/unix/ffi_int_base.py
new file mode 100644
index 000000000..906bc3c1e
--- /dev/null
+++ b/tests/ports/unix/ffi_int_base.py
@@ -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
diff --git a/tests/ports/unix/ffi_int_long32.py b/tests/ports/unix/ffi_int_long32.py
new file mode 100644
index 000000000..32fdb8e0e
--- /dev/null
+++ b/tests/ports/unix/ffi_int_long32.py
@@ -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"),
+ ]
+)
diff --git a/tests/ports/unix/ffi_int_long32.py.exp b/tests/ports/unix/ffi_int_long32.py.exp
new file mode 100644
index 000000000..e0f1338a4
--- /dev/null
+++ b/tests/ports/unix/ffi_int_long32.py.exp
@@ -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
diff --git a/tests/ports/unix/ffi_int_long64.py b/tests/ports/unix/ffi_int_long64.py
new file mode 100644
index 000000000..55bf66052
--- /dev/null
+++ b/tests/ports/unix/ffi_int_long64.py
@@ -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"),
+ ]
+)
diff --git a/tests/ports/unix/ffi_int_long64.py.exp b/tests/ports/unix/ffi_int_long64.py.exp
new file mode 100644
index 000000000..904e6c3ed
--- /dev/null
+++ b/tests/ports/unix/ffi_int_long64.py.exp
@@ -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
diff --git a/tests/ports/unix/ffi_int_types.py b/tests/ports/unix/ffi_int_types.py
new file mode 100644
index 000000000..24fa2a721
--- /dev/null
+++ b/tests/ports/unix/ffi_int_types.py
@@ -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"),
+ ]
+)
diff --git a/tests/ports/unix/ffi_types.py.exp b/tests/ports/unix/ffi_int_types.py.exp
index d6324477d..d6324477d 100644
--- a/tests/ports/unix/ffi_types.py.exp
+++ b/tests/ports/unix/ffi_int_types.py.exp
diff --git a/tests/ports/unix/ffi_lib.c b/tests/ports/unix/ffi_lib.c
index 35340536a..dae4e04bc 100644
--- a/tests/ports/unix/ffi_lib.c
+++ b/tests/ports/unix/ffi_lib.c
@@ -31,3 +31,11 @@ int64_t f64i(int64_t x) {
uint64_t f64u(uint64_t x) {
return x ^ 1;
}
+
+long fli(long x) {
+ return x ^ 1;
+}
+
+unsigned long flu(unsigned long x) {
+ return x ^ 1;
+}
diff --git a/tests/ports/unix/ffi_types.py b/tests/ports/unix/ffi_types.py
deleted file mode 100644
index 06e9b89d3..000000000
--- a/tests/ports/unix/ffi_types.py
+++ /dev/null
@@ -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)))