X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=inline;f=tests%2Fforeign.test.sh;h=045d36bb63f1e900d40a3665d6645df8459570bf;hb=1dc3a468ba32755c51747d6e85ed32d989f2dd49;hp=3fa04e8e2dfd1a42d0f0bb60355be33c01d132b1;hpb=63fcb94b875a97e468d9add229e220ecceec2352;p=sbcl.git diff --git a/tests/foreign.test.sh b/tests/foreign.test.sh index 3fa04e8..045d36b 100644 --- a/tests/foreign.test.sh +++ b/tests/foreign.test.sh @@ -1,6 +1,7 @@ #!/bin/sh -# tests related to foreign function interface and LOAD-FOREIGN +# tests related to foreign function interface and loading of shared +# libraries # This software is part of the SBCL system. See the README file for # more information. @@ -8,34 +9,284 @@ # While most of SBCL is derived from the CMU CL system, the test # files (like this one) were written from scratch after the fork # from CMU CL. -# +# # This software is in the public domain and is provided with # absolutely no warranty. See the COPYING and CREDITS files for # more information. -testfilestem=$TMPDIR/sbcl-foreign-test-$$ +echo //entering foreign.test.sh + +# simple way to make sure we're not punting by accident: +# setting PUNT to anything other than 104 will make non-dlopen +# and non-linkage-table platforms fail this +PUNT=104 + +testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$ + +## Make some shared object files to test with. + +build_so() { + echo building $1.so + if [ "`uname -m`" = x86_64 ]; then + CFLAGS="$CFLAGS -fPIC" + fi + if [ "`uname`" = Darwin ]; then + SO_FLAGS="-bundle" + else + SO_FLAGS="-shared" + fi + cc -c $1.c -o $1.o $CFLAGS + ld $SO_FLAGS -o $1.so $1.o +} + +cat > $testfilestem.c < $testfilestem-b.c +echo 'int bar() { return 42; }' >> $testfilestem-b.c +build_so $testfilestem-b + +echo 'int foo = 42;' > $testfilestem-b2.c +echo 'int bar() { return 13; }' >> $testfilestem-b2.c +build_so $testfilestem-b2 + +echo 'int late_foo = 43;' > $testfilestem-c.c +echo 'int late_bar() { return 14; }' >> $testfilestem-c.c +build_so $testfilestem-c + +## Foreign definitions & load + +cat > $testfilestem.def.lisp < $testfilestem.test.lisp < $testfilestem.c -make $testfilestem.o -ld -shared -o $testfilestem.so $testfilestem.o + (assert (= -1 (negative-short))) + (assert (= -2 (negative-int))) + (assert (= -3 (negative-long))) + + (assert (= 9.0s0 (return9th 1.0s0 2.0s0 3.0s0 4.0s0 5.0s0 6.0s0 7.0s0 8.0s0 9.0s0 10.0s0 11.0s0 12.0s0))) + (assert (= 9.0d0 (return9thd 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0 6.0d0 7.0d0 8.0d0 9.0d0 10.0d0 11.0d0 12.0d0))) + + (assert (= 1 (long-test8 1 2 3 4 5 6 7 (ash 1 34)))) + (assert (= 1 (long-test9 1 2 3 4 5 6 7 (ash 1 35) 8))) + (assert (= 1 (long-test2 1 2 3 4 5 6 7 8 9 (+ 1 (ash 1 37)) 15))) + (assert (= (ash 1 33) (return-long-long))) + + (print :stage-1) + + ;; test reloading object file with new definitions + (assert (= 13 foo)) + (assert (= 42 (bar))) + (rename-file "$testfilestem-b.so" "$testfilestem-b.bak") + (rename-file "$testfilestem-b2.so" "$testfilestem-b.so") + (load-shared-object "$testfilestem-b.so") + (assert (= 42 foo)) + (assert (= 13 (bar))) + (rename-file "$testfilestem-b.so" "$testfilestem-b2.so") + (rename-file "$testfilestem-b.bak" "$testfilestem-b.so") + + (print :stage-2) + + ;; test late resolution + #+linkage-table + (progn + (define-alien-variable late-foo int) + (define-alien-routine late-bar int) + (multiple-value-bind (val err) (ignore-errors late-foo) + (assert (not val)) + (assert (typep err 'undefined-alien-error))) + (multiple-value-bind (val err) (ignore-errors (late-bar)) + (assert (not val)) + (assert (typep err 'undefined-alien-error))) + (load-shared-object "$testfilestem-c.so") + (assert (= 43 late-foo)) + (assert (= 14 (late-bar)))) + + (print :stage-3) -${SBCL:-sbcl} <