0.7.1.38:
[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 # FIXME: At least on OpenBSD, the "make $testfilestem.o" puts the
21 # output file into the current directory, instead of the 
22 # target directory. E.g. "make /tmp/foo.o" causes "./foo.o" to be
23 # created (!). Since OpenBSD doesn't support LOAD-FOREIGN, this
24 # doesn't matter much, since it punts with UNSUPPORTED-OPERATOR
25 # instead of not finding the file. But it'd be nice to straighten
26 # this out, if only so that sbcl-foreign-test-*.o clutter
27 # doesn't pile up in this directory. Maybe some time when I have
28 # several test machines at hand to check the behavior of different
29 # versions of "make"...
30 echo 'int summish(int x, int y) { return 1 + x + y; }' > $testfilestem.c
31 make $testfilestem.o
32 ld -shared -o $testfilestem.so $testfilestem.o
33
34 ${SBCL:-sbcl} <<EOF
35   (handler-case 
36       (load-foreign '("$testfilestem.so"))
37     (sb-int:unsupported-operator ()
38      ;; At least as of sbcl-0.7.0.5, LOAD-FOREIGN isn't supported
39      ;; on every OS. In that case, there's nothing to test, and we
40      ;; can just fall through to success.
41      (sb-ext:quit :unix-status 52))) ; success convention for Lisp program
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 # FIXME: I rewrote the handling of ENV/ENVIRONMENT arguments for
52 # LOAD-FOREIGN, but I can't think of a nice way to test it. (Kent Beck
53 # would cry. If he didn't keel over on the spot and then commence
54 # rolling over in his grave.:-) It would be good to make a test case
55 # for it..
56
57 echo //cleanup: removing $testfilestem.*
58 rm $testfilestem.*
59
60 # success convention for script
61 exit 104