+ (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 (= 1 (long-sap-test1 38 (+ 3 (ash 1 38)))))
+ (assert (= 1 (long-sap-test2 38 1 (+ 3 (ash 1 38)))))
+ (assert (= (ash 1 33) (return-long-long)))
+
+ (note "/initial assertions ok")
+
+ ;; test reloading object file with new definitions
+ (assert (= 13 foo))
+ (assert (= 42 (bar)))
+ (note "/original definitions ok")
+ (rename-file "$TEST_FILESTEM-b.so" "$TEST_FILESTEM-b.bak")
+ (rename-file "$TEST_FILESTEM-b2.so" "$TEST_FILESTEM-b.so")
+ (load-shared-object (truename "$TEST_FILESTEM-b.so"))
+ (note "/reloading ok")
+ (assert (= 42 foo))
+ (assert (= 13 (bar)))
+ (note "/redefined versions ok")
+ (rename-file "$TEST_FILESTEM-b.so" "$TEST_FILESTEM-b2.so")
+ (rename-file "$TEST_FILESTEM-b.bak" "$TEST_FILESTEM-b.so")
+ (note "/renamed back to originals")
+
+ ;; test late resolution
+ #+linkage-table
+ (progn
+ (note "/starting linkage table tests")
+ (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 (truename "$TEST_FILESTEM-c.so"))
+ (assert (= 43 late-foo))
+ (assert (= 14 (late-bar)))
+ (unload-shared-object (truename "$TEST_FILESTEM-c.so"))
+ (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)))
+ (note "/linkage table ok"))
+
+ (sb-ext:exit :code $EXIT_LISP_WIN) ; success convention for Lisp program
+EOF
+
+# Files are now set up; toggle errexit off, since we use a custom exit
+# convention.
+set +e
+
+test_compile() {
+ x="$1"
+ run_sbcl <<EOF
+(progn (load (compile-file "$TEST_FILESTEM.$x.lisp"))
+(sb-ext:exit :code $EXIT_LISP_WIN))
+EOF
+ check_status_maybe_lose "compile $1" $?
+}
+
+test_compile fast
+test_compile small
+
+test_use() {
+ run_sbcl --load $TEST_FILESTEM.$1.fasl --load $TEST_FILESTEM.test.lisp
+ check_status_maybe_lose "use $1" $? 22 "(load-shared-object not supported)"
+}
+
+test_use small
+test_use fast
+
+test_save() {
+ echo testing save $1
+ x="$1"
+ run_sbcl --load $TEST_FILESTEM.$1.fasl <<EOF
+#+linkage-table (save-lisp-and-die "$TEST_FILESTEM.$x.core")
+#-linkage-table nil
+(sb-ext:exit :code 22) ; catch this
+EOF
+ check_status_maybe_lose "save $1" $? \
+ 0 "(successful save)" 22 "(linkage table not available)"
+}
+
+test_save small
+test_save fast
+
+test_start() {
+ echo testing start $1
+ run_sbcl_with_core $TEST_FILESTEM.$1.core \
+ --no-sysinit --no-userinit --load $TEST_FILESTEM.test.lisp
+ check_status_maybe_lose "start $1" $?
+}
+
+test_start fast
+test_start small
+
+# missing object file
+rm $TEST_FILESTEM-b.so $TEST_FILESTEM-b2.so
+run_sbcl_with_core $TEST_FILESTEM.fast.core --no-sysinit --no-userinit <<EOF
+ (assert (= 22 (summish 10 11)))
+ (multiple-value-bind (val err) (ignore-errors (eval 'foo))
+ (assert (not val))
+ (assert (typep err 'undefined-alien-error)))
+ (multiple-value-bind (val err) (ignore-errors (eval '(bar)))
+ (assert (not val))
+ (assert (typep err 'undefined-alien-error)))
+ (exit :code $EXIT_LISP_WIN)
+EOF
+check_status_maybe_lose "missing-so" $?
+
+# ADDR of a heap-allocated object
+cat > $TEST_FILESTEM.addr.heap.c <<EOF
+ struct foo
+ {
+ int x, y;
+ } a, *b;
+EOF
+
+build_so $TEST_FILESTEM.addr.heap
+
+run_sbcl <<EOF
+ (load-shared-object (truename "$TEST_FILESTEM.addr.heap.so"))
+ (define-alien-type foo (struct foo (x int) (y int)))
+
+ (define-alien-variable a foo)
+ (define-alien-variable b (* foo))
+ (funcall (compile nil '(lambda () (setq b (addr a)))))
+ (assert (sb-sys:sap= (alien-sap a) (alien-sap (deref b))))
+ (exit :code $EXIT_LISP_WIN)
+EOF
+check_status_maybe_lose "ADDR of a heap-allocated object" $?
+
+run_sbcl <<EOF
+ (define-alien-type inner (struct inner (var (unsigned 32))))
+ (define-alien-type outer (struct outer (one inner) (two inner)))
+
+ (defvar *outer* (make-alien outer))
+ (defvar *inner* (make-alien inner))
+ (setf (slot *inner* 'var) 20)
+ (setf (slot *outer* 'one) *inner*)
+ (assert (= (slot (slot *outer* 'one) 'var) 20))
+ (setf (slot *inner* 'var) 40)
+ (setf (slot *outer* 'two) *inner*)
+ (assert (= (slot (slot *outer* 'two) 'var) 40))
+ (exit :code $EXIT_LISP_WIN)
+EOF
+check_status_maybe_lose "struct offsets" $?
+
+cat > $TEST_FILESTEM.alien.enum.lisp <<EOF
+(define-alien-type foo-flag
+ (enum foo-flag-
+ (:a 1)
+ (:b 2)))
+
+(define-alien-type bar
+ (struct bar
+ (foo-flag foo-flag)))
+
+(define-alien-type barp
+ (* bar))
+
+(defun foo (x)
+ (declare (type (alien barp) x))
+ x)
+
+(defun bar (x)
+ (declare (type (alien barp) x))
+ x)
+EOF
+expect_clean_compile $TEST_FILESTEM.alien.enum.lisp