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