10bc61378ea11b8520052ea48a794a10ce48e661
[sbcl.git] / tests / foreign.test.sh
1 #!/bin/sh
2
3 # tests related to foreign function interface and loading of shared
4 # libraries
5
6 # This software is part of the SBCL system. See the README file for
7 # more information.
8 #
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
11 # from CMU CL.
12
13 # This software is in the public domain and is provided with
14 # absolutely no warranty. See the COPYING and CREDITS files for
15 # more information.
16
17 echo //entering foreign.test.sh
18
19 testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$
20
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
25
26 # Test interaction with the shared object file.
27 ${SBCL:-sbcl} <<EOF
28   (define-alien-variable environ (* c-string))
29   (defvar *environ* environ)
30   (handler-case 
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
45 EOF
46 if [ $? != 52 ]; then
47     echo test failed: $?
48     exit 1
49 fi
50
51 echo //cleanup: removing $testfilestem.*
52 rm $testfilestem.*
53
54 # success convention for script
55 exit 104