3 # tests related to foreign function interface and loading of shared
6 # This software is part of the SBCL system. See the README file for
9 # While most of SBCL is derived from the CMU CL system, the test
10 # files (like this one) were written from scratch after the fork
13 # This software is in the public domain and is provided with
14 # absolutely no warranty. See the COPYING and CREDITS files for
17 echo //entering foreign.test.sh
19 testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$
21 # Make a little shared object file to test with.
22 echo 'int summish(int x, int y) { return 1 + x + y; }' > $testfilestem.c
23 cc -c $testfilestem.c -o $testfilestem.o
24 ld -shared -o $testfilestem.so $testfilestem.o
26 # Test interaction with the shared object file.
28 (define-alien-variable environ (* c-string))
29 (defvar *environ* environ)
31 (load-shared-object "$testfilestem.so")
32 (sb-int:unsupported-operator ()
33 ;; At least as of sbcl-0.7.0.5, LOAD-SHARED-OBJECT isn't
34 ;; supported on every OS. In that case, there's nothing to test,
35 ;; and we can just fall through to success.
36 (sb-ext:quit :unix-status 52))) ; success convention for Lisp program
37 ;; Test that loading an object file didn't screw up our records
38 ;; of variables visible in runtime. (This was a bug until
39 ;; Nikodemus Siivola's patch in sbcl-0.8.5.50.)
40 (assert (= (sb-sys:sap-int (alien-sap *environ*))
41 (sb-sys:sap-int (alien-sap environ))))
42 (define-alien-routine summish int (x int) (y int))
43 (assert (= (summish 10 20) 31))
44 (sb-ext:quit :unix-status 52) ; success convention for Lisp program
51 echo //cleanup: removing $testfilestem.*
54 # success convention for script