tests/unix: Add ffi test for integer types.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
7842085434
commit
20a8f4f7ec
33
tests/unix/ffi_lib.c
Normal file
33
tests/unix/ffi_lib.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include <stdint.h>
|
||||
|
||||
int8_t f8i(int8_t x) {
|
||||
return x ^ 1;
|
||||
}
|
||||
|
||||
uint8_t f8u(uint8_t x) {
|
||||
return x ^ 1;
|
||||
}
|
||||
|
||||
int16_t f16i(int16_t x) {
|
||||
return x ^ 1;
|
||||
}
|
||||
|
||||
uint16_t f16u(uint16_t x) {
|
||||
return x ^ 1;
|
||||
}
|
||||
|
||||
int32_t f32i(int32_t x) {
|
||||
return x ^ 1;
|
||||
}
|
||||
|
||||
uint32_t f32u(uint32_t x) {
|
||||
return x ^ 1;
|
||||
}
|
||||
|
||||
int64_t f64i(int64_t x) {
|
||||
return x ^ 1;
|
||||
}
|
||||
|
||||
uint64_t f64u(uint64_t x) {
|
||||
return x ^ 1;
|
||||
}
|
51
tests/unix/ffi_types.py
Normal file
51
tests/unix/ffi_types.py
Normal file
@ -0,0 +1,51 @@
|
||||
# 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 uos, usys
|
||||
|
||||
try:
|
||||
import ffi
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
ffi_lib_filename = "./" + usys.argv[0].rsplit("/", 1)[0] + "/ffi_lib.so"
|
||||
try:
|
||||
uos.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)))
|
136
tests/unix/ffi_types.py.exp
Normal file
136
tests/unix/ffi_types.py.exp
Normal file
@ -0,0 +1,136 @@
|
||||
f8i(0) = 1
|
||||
f8i(7f) = 7e
|
||||
f8i(80) = -7f
|
||||
f8i(ff) = -2
|
||||
f8i(100) = 1
|
||||
f8i(7fff) = -2
|
||||
f8i(8000) = 1
|
||||
f8i(ffff) = -2
|
||||
f8i(10000) = 1
|
||||
f8i(7fffffff) = -2
|
||||
f8i(80000000) = 1
|
||||
f8i(ffffffff) = -2
|
||||
f8i(100000000) = 1
|
||||
f8i(7fffffffffffffff) = -2
|
||||
f8i(8000000000000000) = 1
|
||||
f8i(ffffffffffffffff) = -2
|
||||
f8i(10000000000000000) = 1
|
||||
f8u(0) = 1
|
||||
f8u(7f) = 7e
|
||||
f8u(80) = 81
|
||||
f8u(ff) = fe
|
||||
f8u(100) = 1
|
||||
f8u(7fff) = fe
|
||||
f8u(8000) = 1
|
||||
f8u(ffff) = fe
|
||||
f8u(10000) = 1
|
||||
f8u(7fffffff) = fe
|
||||
f8u(80000000) = 1
|
||||
f8u(ffffffff) = fe
|
||||
f8u(100000000) = 1
|
||||
f8u(7fffffffffffffff) = fe
|
||||
f8u(8000000000000000) = 1
|
||||
f8u(ffffffffffffffff) = fe
|
||||
f8u(10000000000000000) = 1
|
||||
f16i(0) = 1
|
||||
f16i(7f) = 7e
|
||||
f16i(80) = 81
|
||||
f16i(ff) = fe
|
||||
f16i(100) = 101
|
||||
f16i(7fff) = 7ffe
|
||||
f16i(8000) = -7fff
|
||||
f16i(ffff) = -2
|
||||
f16i(10000) = 1
|
||||
f16i(7fffffff) = -2
|
||||
f16i(80000000) = 1
|
||||
f16i(ffffffff) = -2
|
||||
f16i(100000000) = 1
|
||||
f16i(7fffffffffffffff) = -2
|
||||
f16i(8000000000000000) = 1
|
||||
f16i(ffffffffffffffff) = -2
|
||||
f16i(10000000000000000) = 1
|
||||
f16u(0) = 1
|
||||
f16u(7f) = 7e
|
||||
f16u(80) = 81
|
||||
f16u(ff) = fe
|
||||
f16u(100) = 101
|
||||
f16u(7fff) = 7ffe
|
||||
f16u(8000) = 8001
|
||||
f16u(ffff) = fffe
|
||||
f16u(10000) = 1
|
||||
f16u(7fffffff) = fffe
|
||||
f16u(80000000) = 1
|
||||
f16u(ffffffff) = fffe
|
||||
f16u(100000000) = 1
|
||||
f16u(7fffffffffffffff) = fffe
|
||||
f16u(8000000000000000) = 1
|
||||
f16u(ffffffffffffffff) = fffe
|
||||
f16u(10000000000000000) = 1
|
||||
f32i(0) = 1
|
||||
f32i(7f) = 7e
|
||||
f32i(80) = 81
|
||||
f32i(ff) = fe
|
||||
f32i(100) = 101
|
||||
f32i(7fff) = 7ffe
|
||||
f32i(8000) = 8001
|
||||
f32i(ffff) = fffe
|
||||
f32i(10000) = 10001
|
||||
f32i(7fffffff) = 7ffffffe
|
||||
f32i(80000000) = -7fffffff
|
||||
f32i(ffffffff) = -2
|
||||
f32i(100000000) = 1
|
||||
f32i(7fffffffffffffff) = -2
|
||||
f32i(8000000000000000) = 1
|
||||
f32i(ffffffffffffffff) = -2
|
||||
f32i(10000000000000000) = 1
|
||||
f32u(0) = 1
|
||||
f32u(7f) = 7e
|
||||
f32u(80) = 81
|
||||
f32u(ff) = fe
|
||||
f32u(100) = 101
|
||||
f32u(7fff) = 7ffe
|
||||
f32u(8000) = 8001
|
||||
f32u(ffff) = fffe
|
||||
f32u(10000) = 10001
|
||||
f32u(7fffffff) = 7ffffffe
|
||||
f32u(80000000) = 80000001
|
||||
f32u(ffffffff) = fffffffe
|
||||
f32u(100000000) = 1
|
||||
f32u(7fffffffffffffff) = fffffffe
|
||||
f32u(8000000000000000) = 1
|
||||
f32u(ffffffffffffffff) = fffffffe
|
||||
f32u(10000000000000000) = 1
|
||||
f64i(0) = 1
|
||||
f64i(7f) = 7e
|
||||
f64i(80) = 81
|
||||
f64i(ff) = fe
|
||||
f64i(100) = 101
|
||||
f64i(7fff) = 7ffe
|
||||
f64i(8000) = 8001
|
||||
f64i(ffff) = fffe
|
||||
f64i(10000) = 10001
|
||||
f64i(7fffffff) = 7ffffffe
|
||||
f64i(80000000) = 80000001
|
||||
f64i(ffffffff) = fffffffe
|
||||
f64i(100000000) = 100000001
|
||||
f64i(7fffffffffffffff) = 7ffffffffffffffe
|
||||
f64i(8000000000000000) = -7fffffffffffffff
|
||||
f64i(ffffffffffffffff) = -2
|
||||
f64i(10000000000000000) = 1
|
||||
f64u(0) = 1
|
||||
f64u(7f) = 7e
|
||||
f64u(80) = 81
|
||||
f64u(ff) = fe
|
||||
f64u(100) = 101
|
||||
f64u(7fff) = 7ffe
|
||||
f64u(8000) = 8001
|
||||
f64u(ffff) = fffe
|
||||
f64u(10000) = 10001
|
||||
f64u(7fffffff) = 7ffffffe
|
||||
f64u(80000000) = 80000001
|
||||
f64u(ffffffff) = fffffffe
|
||||
f64u(100000000) = 100000001
|
||||
f64u(7fffffffffffffff) = 7ffffffffffffffe
|
||||
f64u(8000000000000000) = 8000000000000001
|
||||
f64u(ffffffffffffffff) = fffffffffffffffe
|
||||
f64u(10000000000000000) = 1
|
10
tools/ci.sh
10
tools/ci.sh
@ -313,6 +313,10 @@ function ci_unix_build_helper {
|
||||
make ${MAKEOPTS} -C ports/unix "$@"
|
||||
}
|
||||
|
||||
function ci_unix_build_ffi_lib_helper {
|
||||
$1 $2 -shared -o tests/unix/ffi_lib.so tests/unix/ffi_lib.c
|
||||
}
|
||||
|
||||
function ci_unix_run_tests_helper {
|
||||
make -C ports/unix "$@" test
|
||||
}
|
||||
@ -359,6 +363,7 @@ function ci_unix_minimal_run_tests {
|
||||
|
||||
function ci_unix_standard_build {
|
||||
ci_unix_build_helper VARIANT=standard
|
||||
ci_unix_build_ffi_lib_helper gcc
|
||||
}
|
||||
|
||||
function ci_unix_standard_run_tests {
|
||||
@ -379,6 +384,7 @@ function ci_unix_coverage_setup {
|
||||
|
||||
function ci_unix_coverage_build {
|
||||
ci_unix_build_helper VARIANT=coverage
|
||||
ci_unix_build_ffi_lib_helper gcc
|
||||
}
|
||||
|
||||
function ci_unix_coverage_run_tests {
|
||||
@ -403,6 +409,7 @@ function ci_unix_32bit_setup {
|
||||
|
||||
function ci_unix_coverage_32bit_build {
|
||||
ci_unix_build_helper VARIANT=coverage MICROPY_FORCE_32BIT=1
|
||||
ci_unix_build_ffi_lib_helper gcc -m32
|
||||
}
|
||||
|
||||
function ci_unix_coverage_32bit_run_tests {
|
||||
@ -416,6 +423,7 @@ function ci_unix_coverage_32bit_run_native_mpy_tests {
|
||||
function ci_unix_nanbox_build {
|
||||
# Use Python 2 to check that it can run the build scripts
|
||||
ci_unix_build_helper PYTHON=python2 VARIANT=nanbox
|
||||
ci_unix_build_ffi_lib_helper gcc -m32
|
||||
}
|
||||
|
||||
function ci_unix_nanbox_run_tests {
|
||||
@ -424,6 +432,7 @@ function ci_unix_nanbox_run_tests {
|
||||
|
||||
function ci_unix_float_build {
|
||||
ci_unix_build_helper VARIANT=standard CFLAGS_EXTRA="-DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT"
|
||||
ci_unix_build_ffi_lib_helper gcc
|
||||
}
|
||||
|
||||
function ci_unix_float_run_tests {
|
||||
@ -521,6 +530,7 @@ function ci_unix_qemu_arm_setup {
|
||||
|
||||
function ci_unix_qemu_arm_build {
|
||||
ci_unix_build_helper "${CI_UNIX_OPTS_QEMU_ARM[@]}"
|
||||
ci_unix_build_ffi_lib_helper arm-linux-gnueabi-gcc
|
||||
}
|
||||
|
||||
function ci_unix_qemu_arm_run_tests {
|
||||
|
Loading…
Reference in New Issue
Block a user