Trust non-returning functions during sb-xc.
[sbcl.git] / tests / save8.test.sh
blobc6b692b4e6d05c13aec4ca638e4ee7719905dd36
1 . ./subr.sh
3 use_test_subdirectory
5 tmpcore=$TEST_FILESTEM.core
7 # Regression test for https://bugs.launchpad.net/sbcl/+bug/1857920
8 # saving a finalizer would crash you into ldb.
9 # (Sadly, saved finalizers mean nothing to gencgc since it will never
10 # actually free the object which the finalizer watches)
12 run_sbcl <<EOF
13 (defvar *x* (cons 1 2))
14 (finalize *x* (lambda () (print 'ran)))
15 (save-lisp-and-die "$tmpcore" :executable t)
16 EOF
17 set -e
18 ./"$tmpcore" --disable-ldb --no-userinit --no-sysinit --noprint
19 echo "Saved finalizer smoke test: PASS"
21 # Assert that >1 finalizer on an object are correctly saved/restored.
22 run_sbcl <<EOF
23 (defvar *x* "hi")
24 (defun a () (print 1))
25 (defun b () (print 2))
26 (defun c () (print 3))
27 (finalize *x* #'a)
28 (finalize *x* #'b :dont-save t)
29 (finalize *x* #'c)
30 (save-lisp-and-die "$tmpcore")
31 EOF
32 # this would crash in finalizers-reinit
33 run_sbcl_with_core "$tmpcore" --noinform --disable-ldb --no-userinit --no-sysinit --noprint <<EOF
34 (sb-sys:with-pinned-objects (*x*)
35 (let ((list (sb-lockless:so-data
36 (sb-lockless:so-find sb-impl::**finalizer-store**
37 (sb-kernel:%make-lisp-obj
38 (logandc2 (sb-kernel:get-lisp-obj-address *x*)
39 sb-vm:lowtag-mask))))))
40 (assert (= (length list) 2))
41 (assert (find #'a list))
42 (assert (find #'c list))))
43 EOF
44 rm "$tmpcore"
45 echo "One obj, three finalizers: PASS"
47 # Assert that :DONT-SAVE finalizers which were triggered during the DEINITIALIZE flow
48 # and placed in the triggered list do not act as though they were saved.
49 # i.e. They're ineligible for running on restart, but also - as a design choice -
50 # not run during saving of the core even when the object died.
51 run_sbcl <<EOF
52 (progn (sb-ext:finalize (make-array 1) (lambda () (format t "RAN~%")) :dont-save t) nil)
53 (save-lisp-and-die "$tmpcore" :executable t)
54 EOF
55 result=`./"$tmpcore" --disable-ldb --no-userinit --no-sysinit --noprint \
56 --eval '(sleep .0125)' --eval '(quit)'`
57 if [ "x$result" = "x" ]
58 then
59 echo "Triggered DONT-SAVE finalizer: PASS"
60 else
61 echo "Triggered DONT-SAVE finalizer: FAIL"
62 exit 1
64 rm "$tmpcore"
65 exit $EXIT_TEST_WIN