47f434482c98258f7bfa77fe34abeb82232091c3
[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 testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$
17
18 echo 'int summish(int x, int y) { return 1 + x + y; }' > $testfilestem.c
19 make $testfilestem.o
20 ld -shared -o $testfilestem.so $testfilestem.o
21
22 ${SBCL:-sbcl} <<EOF
23   (handler-case 
24       (load-foreign '("$testfilestem.so"))
25     (sb-int:unsupported-operator ()
26      ;; At least as of sbcl-0.7.0.5, LOAD-FOREIGN isn't supported
27      ;; on every OS. In that case, there's nothing to test, and we
28      ;; can just fall through to success.
29      (sb-ext:quit :unix-status 52))) ; success convention for Lisp program
30   (define-alien-routine summish int (x int) (y int))
31   (assert (= (summish 10 20) 31))
32   (sb-ext:quit :unix-status 52) ; success convention for Lisp program
33 EOF
34 if [ $? != 52 ]; then
35     echo test failed: $?
36     exit 1
37 fi
38
39 # FIXME: I rewrote the handling of ENV/ENVIRONMENT arguments for
40 # LOAD-FOREIGN, but I can't think of a nice way to test it. (Kent Beck
41 # would cry. If he didn't keel over on the spot and then commence
42 # rolling over in his grave.:-) It would be good to make a test case
43 # for it..
44
45 rm $testfilestem.*
46
47 # success convention for script
48 exit 104