diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-12-15 02:18:12 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-12-15 02:18:54 +0200 |
commit | 7a4765dbeb1176efc2679aeb66ce8b21a8e1fd08 (patch) | |
tree | 5e45ba46f3f50d0b83ae57e78b15e07c3a9aca72 | |
parent | b62371e8fb0b3f8123920eb82270f42bab3ce657 (diff) | |
download | micropython-7a4765dbeb1176efc2679aeb66ce8b21a8e1fd08.tar.gz micropython-7a4765dbeb1176efc2679aeb66ce8b21a8e1fd08.zip |
tests: Add testcase for ffi callbacks.
-rw-r--r-- | tests/unix/ffi_callback.py | 23 | ||||
-rw-r--r-- | tests/unix/ffi_callback.py.exp | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/unix/ffi_callback.py b/tests/unix/ffi_callback.py new file mode 100644 index 0000000000..1d610365c7 --- /dev/null +++ b/tests/unix/ffi_callback.py @@ -0,0 +1,23 @@ +import sys +try: + import ffi +except ImportError: + print("SKIP") + sys.exit() + +libc = ffi.open("libc.so.6") + +qsort = libc.func("v", "qsort", "piip") + +def cmp(pa, pb): + a = ffi.as_bytearray(pa, 1) + b = ffi.as_bytearray(pb, 1) + #print("cmp:", a, b) + return a[0] - b[0] + +cmp_c = ffi.callback("i", cmp, "pp") + +s = bytearray(b"foobar") +print("org string:", s) +qsort(s, len(s), 1, cmp_c) +print("qsort'ed:", s) diff --git a/tests/unix/ffi_callback.py.exp b/tests/unix/ffi_callback.py.exp new file mode 100644 index 0000000000..d06fec52fb --- /dev/null +++ b/tests/unix/ffi_callback.py.exp @@ -0,0 +1,2 @@ +org string: bytearray(b'foobar') +qsort'ed: bytearray(b'abfoor') |