3 # tests related to foreign function interface and LOAD-FOREIGN
5 # This software is part of the SBCL system. See the README file for
8 # While most of SBCL is derived from the CMU CL system, the test
9 # files (like this one) were written from scratch after the fork
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
16 echo //entering foreign.test.sh
18 testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$
20 # Make a little shared object file to test with.
21 echo 'int summish(int x, int y) { return 1 + x + y; }' > $testfilestem.c
22 cc -c $testfilestem.c -o $testfilestem.o
23 ld -shared -o $testfilestem.so $testfilestem.o
25 # Test interaction with the shared object file.
27 (define-alien-variable environ (* c-string))
28 (defvar *environ* environ)
30 (load-foreign '("$testfilestem.so"))
31 (sb-int:unsupported-operator ()
32 ;; At least as of sbcl-0.7.0.5, LOAD-FOREIGN isn't supported
33 ;; on every OS. In that case, there's nothing to test, and we
34 ;; can just fall through to success.
35 (sb-ext:quit :unix-status 52))) ; success convention for Lisp program
36 ;; Test that loading an object file didn't screw up our records
37 ;; of variables visible in runtime. (This was a bug until
38 ;; Nikodemus Siivola's patch in sbcl-0.8.5.50.)
39 (assert (= (sb-sys:sap-int (alien-sap *environ*))
40 (sb-sys:sap-int (alien-sap environ))))
41 (define-alien-routine summish int (x int) (y int))
42 (assert (= (summish 10 20) 31))
43 (sb-ext:quit :unix-status 52) ; success convention for Lisp program
50 # FIXME: I rewrote the handling of ENV/ENVIRONMENT arguments for
51 # LOAD-FOREIGN, but I can't think of a nice way to test it. (Kent Beck
52 # would cry. If he didn't keel over on the spot and then commence
53 # rolling over in his grave.:-) It would be good to make a test case
56 echo //cleanup: removing $testfilestem.*
59 # success convention for script