0.9.12.10:
[sbcl.git] / tests / foreign.test.sh
index 2d7865f..ea05cbc 100644 (file)
@@ -9,7 +9,7 @@
 # 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.
@@ -23,22 +23,22 @@ PUNT=104
 
 testfilestem=${TMPDIR:-/tmp}/sbcl-foreign-test-$$
 
-## Make a little shared object files to test with.
+## Make some shared object files to test with.
 
 build_so() {
   echo building $1.so
-  if [ $(uname -m) = x86_64 ]; then
+  if [ "`uname -m`" = x86_64 ]; then
     CFLAGS="$CFLAGS -fPIC"
   fi
-  if [ $(uname) = Darwin ]; then
+  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
+  ld $SO_FLAGS -o $1.so $1.o  
 }
-    
+
 echo 'int summish(int x, int y) { return 1 + x + y; }' > $testfilestem.c
 echo 'int numberish = 42;' >> $testfilestem.c
 echo 'int nummish(int x) { return numberish + x; }' >> $testfilestem.c
@@ -84,8 +84,12 @@ cat > $testfilestem.def.lisp <<EOF
   (define-alien-routine "negative_int" int)
   (define-alien-routine "negative_long" long)
 
+  ;; 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 
+  ;; 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
@@ -93,8 +97,9 @@ cat > $testfilestem.def.lisp <<EOF
   (assert (= (sb-sys:sap-int (alien-sap *environ*))
              (sb-sys:sap-int (alien-sap environ))))
 
+  (enable-debugger)
   ;; automagic restarts
-  (setf *debugger-hook* 
+  (setf *debugger-hook*
         (lambda (condition hook)
           (print (list :debugger-hook condition))
           (let ((cont (find-restart 'continue condition)))
@@ -118,7 +123,7 @@ cat > $testfilestem.test.lisp <<EOF
 
   (print :stage-1)
 
-  ;; test realoading object file with new definitions
+  ;; test reloading object file with new definitions
   (assert (= 13 foo))
   (assert (= 42 (bar)))
   (rename-file "$testfilestem-b.so" "$testfilestem-b.bak")
@@ -132,25 +137,28 @@ cat > $testfilestem.test.lisp <<EOF
   (print :stage-2)
 
   ;; test late resolution
-  (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)))
+  #+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)
 
   (sb-ext:quit :unix-status 52) ; success convention for Lisp program
 EOF
 
-${SBCL:-sbcl} --eval "(progn (compile-file #p\"$testfilestem.def.lisp\") (sb-ext:quit :unix-status 52))"
-if [ $? = 52 ] ; then :
+${SBCL:-sbcl} --eval "(progn (load (compile-file #p\"$testfilestem.def.lisp\")) (sb-ext:quit :unix-status 52))"
+if [ $? = 52 ]; then
+    true # nop
 else
     # we can't compile the test file. something's wrong.
     rm $testfilestem.*
@@ -168,7 +176,7 @@ if [ $RET = 22 ]; then
 elif [ $RET != 52 ]; then
     rm $testfilestem.*
     echo test failed: $?
-    exit 1 
+    exit 1
 fi
 
 echo load ok
@@ -183,7 +191,7 @@ fi
 
 echo table ok
 
-$SBCL_ALLOWING_CORE --core $testfilestem.core --sysinit /dev/null --userinit /dev/null --load $testfilestem.test.lisp
+${SBCL_ALLOWING_CORE:-sbcl} --core $testfilestem.core --sysinit /dev/null --userinit /dev/null --load $testfilestem.test.lisp
 if [ $? != 52 ]; then
     rm $testfilestem.*
     echo test failed: $?
@@ -194,7 +202,7 @@ echo start ok
 
 # missing object file
 rm $testfilestem-b.so $testfilestem-b2.so
-$SBCL_ALLOWING_CORE --core $testfilestem.core --sysinit /dev/null --userinit /dev/null <<EOF
+${SBCL_ALLOWING_CORE:-sbcl} --core $testfilestem.core --sysinit /dev/null --userinit /dev/null <<EOF
   (assert (= 22 (summish 10 11)))
   (multiple-value-bind (val err) (ignore-errors (eval 'foo))
     (assert (not val))
@@ -212,7 +220,7 @@ fi
 
 echo missing ok
 
-rm $testfilestem.*
+rm -f $testfilestem.* $testfilestem-*
 
 # success convention for script
-exit 104 
+exit 104