X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fforeign.test.sh;h=59e28cde20304f01647ccc2b1e48981f30991e1d;hb=fe962ba01d267b92f638c8f0d19be41054219f04;hp=ae735b22a2e42c5c415c8dcfa409f925ab743be3;hpb=53e7a02c819090af8e6db7e47d29cdbb5296814f;p=sbcl.git diff --git a/tests/foreign.test.sh b/tests/foreign.test.sh index ae735b2..59e28cd 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,35 +9,307 @@ # 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. -sbcl="$1" +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.base.lisp < $testfilestem.c -make $testfilestem.o -ld -shared -o $testfilestem.so $testfilestem.o + ;; compiling this gets us the FOP-FOREIGN-DATAREF-FIXUP on + ;; linkage-table ports + (defvar *extern* (extern-alien "negative_short" short)) + + ;; Test that loading an object file didn't screw up our records + ;; of variables visible in runtime. (This was a bug until + ;; Nikodemus Siivola's patch in sbcl-0.8.5.50.) + ;; + ;; This cannot be tested in a saved core, as there is no guarantee + ;; that the location will be the same. + (assert (= (sb-sys:sap-int (alien-sap *environ*)) + (sb-sys:sap-int (alien-sap environ)))) + (enable-debugger) + ;; automagic restarts + (setf *debugger-hook* + (lambda (condition hook) + (princ condition) + (let ((cont (find-restart 'continue condition))) + (when cont + (invoke-restart cont))) + (print :fell-through) + (invoke-debugger condition))) +EOF + +echo "(declaim (optimize speed))" > $testfilestem.fast.lisp +cat $testfilestem.base.lisp >> $testfilestem.fast.lisp + +echo "(declaim (optimize space))" > $testfilestem.small.lisp +cat $testfilestem.base.lisp >> $testfilestem.small.lisp + +# Test code +cat > $testfilestem.test.lisp <