1.0.21.26: bullet-proof (?) use of LOAD-SHARED-OBJECT in tests
[sbcl.git] / tests / foreign-stack-alignment.impure.lisp
index 2ed55a3..128d21f 100644 (file)
 
 (defvar *required-alignment*
   #+(and ppc darwin) 16
-  #+(and ppc linux) 16
-  #+(or mips x86-64) 8
-  #+x86 4
+  #+(and ppc linux) 8
+  #+x86-64 16
+  #+mips 8
+  #+(and x86 (not darwin)) 4
+  #+(and x86 darwin) 16
   #-(or x86 x86-64 mips (and ppc (or darwin linux))) (error "Unknown platform"))
 
 ;;;; Build the offset-tool as regular excutable, and run it with
 ;;;; fork/exec, so that no lisp is on the stack. This is our known-good
 ;;;; number.
 
-(run "cc" "stack-alignment-offset.c" "-o" "stack-alignment-offset")
+(run "cc"
+     #+(and (or linux freebsd) (or x86-64 ppc mips)) "-fPIC"
+     #+(and x86-64 darwin) "-arch" #+(and x86-64 darwin) "x86_64"
+     "stack-alignment-offset.c" "-o" "stack-alignment-offset")
 
 (defparameter *good-offset*
   (parse-integer (run "./stack-alignment-offset"
 ;;;; Build the tool again, this time as a shared object, and load it
 
 (run "cc" "stack-alignment-offset.c"
+     #+(and (or linux freebsd) (or x86-64 ppc mips)) "-fPIC"
+     #+(and x86-64 darwin) "-arch" #+(and x86-64 darwin) "x86_64"
      #+darwin "-bundle" #-darwin "-shared"
      "-o" "stack-alignment-offset.so")
 
-(load-shared-object "stack-alignment-offset.so")
+(load-shared-object (truename "stack-alignment-offset.so"))
 
 (define-alien-routine stack-alignment-offset int (alignment int))
 (define-alien-routine trampoline int (callback (function int)))
 ;;;; Now get the offset by calling from lisp, first with a regular foreign function
 ;;;; call, then with an intervening callback.
 
-(assert (= *good-offset* (stack-alignment-offset *required-alignment*)))
+(with-test (:name :regular)
+  (assert (= *good-offset* (stack-alignment-offset *required-alignment*))))
 
-(assert (= *good-offset* (trampoline (alien-lambda int ()
-                                       (stack-alignment-offset *required-alignment*)))))
+(with-test (:name :callback)
+  (assert (= *good-offset* (trampoline (alien-lambda int ()
+                                       (stack-alignment-offset *required-alignment*))))))
+
+(delete-file "stack-alignment-offset")
+(delete-file "stack-alignment-offset.so")
 
 ;;;; success!