From 9bed01c59d5f5fe0bbc9d025ae95cf3b9518d5a7 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 13 May 2017 19:01:53 -0700 Subject: 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. --- tests/017/qsort.expected | 10 ++++++++++ tests/017/qsort.tl | 38 ++++++++++++++++++++++++++++++++++++++ tests/common.tl | 5 +++++ 3 files changed, 53 insertions(+) create mode 100644 tests/017/qsort.expected create mode 100644 tests/017/qsort.tl (limited to 'tests') 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")))) -- cgit v1.2.3