summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-13 19:01:53 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-13 19:01:53 -0700
commit9bed01c59d5f5fe0bbc9d025ae95cf3b9518d5a7 (patch)
tree8900b2665c83354fbab2cc206bb2843d2e2dcad5
parent7872378ee23adf65c2bed5819a74811ed6e954fc (diff)
downloadtxr-9bed01c59d5f5fe0bbc9d025ae95cf3b9518d5a7.tar.gz
txr-9bed01c59d5f5fe0bbc9d025ae95cf3b9518d5a7.tar.bz2
txr-9bed01c59d5f5fe0bbc9d025ae95cf3b9518d5a7.zip
tests: first FFI regression test case.
* tests/017/qsort.expected: New file. * tests/017/qsort.tl: New file. * tests/common.tl (libc): New function. * Makefile (tst/tests/017/%): Clear TXR_DBG_OPTS so the GC stress test isn't applied to tests in this directory.
-rw-r--r--Makefile1
-rw-r--r--tests/017/qsort.expected10
-rw-r--r--tests/017/qsort.tl38
-rw-r--r--tests/common.tl5
4 files changed, 54 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 70c41fe5..681fbede 100644
--- a/Makefile
+++ b/Makefile
@@ -339,6 +339,7 @@ tst/tests/013/%: TXR_DBG_OPTS :=
tst/tests/014/%: TXR_DBG_OPTS :=
tst/tests/015/%: TXR_DBG_OPTS :=
tst/tests/016/%: TXR_DBG_OPTS :=
+tst/tests/017/%: TXR_DBG_OPTS :=
.PRECIOUS: tst/%.out
tst/%.out: %.txr
diff --git a/tests/017/qsort.expected b/tests/017/qsort.expected
new file mode 100644
index 00000000..a92d6c0e
--- /dev/null
+++ b/tests/017/qsort.expected
@@ -0,0 +1,10 @@
+#("the" "quick" "brown" "fox" "jumped" "over" "the" "lazy" "dogs")
+#("brown" "dogs" "fox" "jumped" "lazy" "over" "quick" "the" "the")
+#("the" "quick" "brown" "fox" "jumped" "over" "the" "lazy" "dogs")
+#("brown" "dogs" "fox" "jumped" "lazy" "over" "quick" "the" "the")
+#("the" "quick" "brown" "fox" "jumped" "over" "the" "lazy" "dogs")
+42
+#(nil nil nil nil nil nil nil nil nil)
+#("the" "quick")
+42
+#(nil nil)
diff --git a/tests/017/qsort.tl b/tests/017/qsort.tl
new file mode 100644
index 00000000..c6e5960f
--- /dev/null
+++ b/tests/017/qsort.tl
@@ -0,0 +1,38 @@
+(load "../common")
+
+(with-dyn-lib (libc)
+ ;; FFI for sorting char *array[] with qsort.
+ (deffi qsort "qsort" void ((ptr (array str)) size-t size-t closure))
+ (deffi-cb qsort-cb int ((ptr str-d) (ptr str-d)))
+
+ ;; FFI for sorting wchar_t *array[] with qsort.
+ (deffi qsortw "qsort" void ((ptr (array wstr)) size-t size-t closure))
+ (deffi-cb qsortw-cb int ((ptr wstr-d) (ptr wstr-d))))
+
+;; sort vector of strings as char *
+(let ((vec #("the" "quick" "brown" "fox" "jumped" "over" "the" "lazy" "dogs")))
+ (prinl vec)
+ (qsort vec (length vec) (sizeof str) [qsort-cb cmp-str])
+ (prinl vec))
+
+;; sort vector of strings as wchar_t *
+(let ((vec #("the" "quick" "brown" "fox" "jumped" "over" "the" "lazy" "dogs")))
+ (prinl vec)
+ (qsortw vec (length vec) (sizeof str) [qsortw-cb cmp-str])
+ (prinl vec))
+
+;; abort callback with non-local transfer
+(let ((vec #("the" "quick" "brown" "fox" "jumped" "over" "the" "lazy" "dogs")))
+ (prinl vec)
+ (prinl (block foo
+ (qsort vec (length vec) (sizeof str)
+ [qsort-cb (lambda (x y) (return-from foo 42))])))
+ (prinl vec))
+
+;; abort callback with non-local transfer
+(let ((vec #("the" "quick")))
+ (prinl vec)
+ (prinl (block foo
+ (qsortw vec (length vec) (sizeof str)
+ [qsortw-cb (lambda (x y) (return-from foo 42))])))
+ (prinl vec))
diff --git a/tests/common.tl b/tests/common.tl
index a61c0ff1..3cd5df63 100644
--- a/tests/common.tl
+++ b/tests/common.tl
@@ -32,3 +32,8 @@
(iff (f^ #/Darwin/) (ret :macos))
(ret :unknown))
u.sysname]))
+
+(defun libc ()
+ (caseql (os-symbol)
+ ((:linux :solaris :macos) (dlopen nil))
+ ((:cygwin) (dlopen "cygwin1.dll"))))