3 # tests related to .core files
5 # This software is part of the SBCL system. See the README file for
8 # While most of SBCL is derived from the CMU CL system, the test
9 # files (like this one) were written from scratch after the fork
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
20 tmpcore
=$TEST_FILESTEM.core
21 tmpoutput
=$TEST_FILESTEM.txt
24 (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42))
26 run_sbcl_with_core
"$tmpcore" --no-userinit --no-sysinit \
27 --eval "(setf sb-ext:*evaluator-mode* :${TEST_SBCL_EVALUATOR_MODE:-compile})"
28 check_status_maybe_lose
"SAVE-LISP-AND-DIE :TOPLEVEL" $?
0 "(saved core ran)"
30 # In sbcl-0.7.7 SAVE-LISP-AND-DIE didn't work at all because of
31 # flakiness caused by consing/GC/purify twice-and-at-least-twice
34 # "serves yall right for fiddling with too much stuff"
35 # -- Eric Marsden, <http://tunes.org/~nef/logs/lisp/02.09.15>
37 # diagnosed and fixed by Dan Barlow in sbcl-0.7.7.29
39 (defun foo (x) (+ x 11))
40 (save-lisp-and-die "$tmpcore")
42 run_sbcl_with_core
"$tmpcore" --no-userinit --no-sysinit \
43 --eval "(setf sb-ext:*evaluator-mode* :${TEST_SBCL_EVALUATOR_MODE:-compile})" \
47 check_status_maybe_lose
"Basic SAVE-LISP-AND-DIE" $?
21 "(saved core ran)"
49 # Expose potential failure that could happen in save-lisp-and-die in an image
50 # that was restarted from one that underwent number coalescing during a
51 # previous save-lisp-and-die: A bignum as a layout bitmap can be forwarded
52 # while using that bignum as the bitmap to decide what to scan in that selfsame
53 # instance. Aside from random failure, this could be detected by enabling
54 # 'verify_gens' which printed "Ptr sees free page" after GC failed to scavenge
55 # all pointer slots. I believe that it was a coincidence that my test croaked
56 # specifically while scanning layout-of-layout. It could have been any
57 # structure having a slot holding a bignum EQ to its own layout-bitmap.
58 run_sbcl
--load ..
/heap-reloc
/embiggen.lisp
<<EOF
59 #+gencgc (setf (extern-alien "verify_gens" char) 0)
60 (save-lisp-and-die "$tmpcore")
62 run_sbcl_with_core
"$tmpcore" --no-userinit --no-sysinit --eval "(exit)"
63 check_status_maybe_lose
"Crash GC" $?
0 "(saved core ran)"
65 # In sbcl-0.9.8 saving cores with callbacks didn't work on gencgc platforms
68 (format t "~&Callbacks not supported, skipping~%")
72 (sb-alien::define-alien-callback foo int () 42)
73 (defun bar () (exit :code (alien-funcall foo))))
74 (save-lisp-and-die "$tmpcore")
76 run_sbcl_with_core
"$tmpcore" --no-userinit --no-sysinit \
77 --eval "(setf sb-ext:*evaluator-mode* :${TEST_SBCL_EVALUATOR_MODE:-compile})" \
81 check_status_maybe_lose
"Callbacks after SAVE-LISP-AND-DIE" $? \
82 42 "(callback function ran)"
84 # test suppression of banner in executable cores
86 (save-lisp-and-die "$tmpcore" :executable t)
89 .
/"$tmpcore" > "$tmpoutput" --no-userinit --no-sysinit --noprint <<EOF
93 if [ $status != 71 ]; then
94 echo "failure in banner suppression: $status"
96 elif [ -s "$tmpoutput" ]; then
97 echo "failure in banner suppression: nonempty output:"
102 elif [ -f "$tmpoutput" ]; then
103 echo "/Executable suppressed banner, good."
105 echo "failure in banner suppression: $tmpoutput was not created or something funny happened."
109 # saving runtime options _from_ executable cores
111 (save-lisp-and-die "$tmpcore" :executable t)
114 .
/"$tmpcore" --no-userinit <<EOF
115 (save-lisp-and-die "$tmpcore" :executable t :save-runtime-options t)
118 .
/"$tmpcore" --no-userinit --version --eval '(exit)' <<EOF
119 (when (equal *posix-argv* '("./$tmpcore" "--version" "--eval" "(exit)"))
124 if [ $status != 42 ]; then
125 echo "saving runtime options from executable failed"
129 # executable core used as "--core" option should not save the memory sizes
130 # that were originally saved, but the sizes in the process doing the save.
131 run_sbcl_with_args
--control-stack-size 160KB
--dynamic-space-size 200MB
--no-userinit --noprint <<EOF
132 (save-lisp-and-die "$tmpcore" :executable t :save-runtime-options t)
135 .
/"$tmpcore" --no-userinit <<EOF
136 (assert (eql (extern-alien "thread_control_stack_size" unsigned) (* 160 1024)))
137 (assert (eql (dynamic-space-size) (* 200 1048576)))
139 run_sbcl_with_core
"$tmpcore" --control-stack-size 200KB
--dynamic-space-size 250MB
<<EOF
140 (assert (eql (extern-alien "thread_control_stack_size" unsigned) (* 200 1024)))
141 (assert (eql (dynamic-space-size) (* 250 1048576)))
142 (save-lisp-and-die "${tmpcore}2" :executable t :save-runtime-options t)
144 chmod u
+x
"${tmpcore}2"
145 .
/"${tmpcore}2" --no-userinit <<EOF
146 (when (and (eql (extern-alien "thread_control_stack_size" unsigned) (* 200 1024))
147 (eql (dynamic-space-size) (* 250 1048576)))
151 rm "$tmpcore" "${tmpcore}2"
152 if [ $status != 42 ]; then
153 echo "re-saved executable used wrong memory size options"
158 (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42)
159 :compression (and (member :sb-core-compression *features*) t))
161 run_sbcl_with_core
"$tmpcore" --no-userinit --no-sysinit \
162 --eval "(setf sb-ext:*evaluator-mode* :${TEST_SBCL_EVALUATOR_MODE:-compile})"
163 check_status_maybe_lose
"SAVE-LISP-AND-DIE :COMPRESS" $?
0 "(compressed saved core ran)"
167 (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42) :executable t
168 :compression (and (member :sb-core-compression *features*) t))
171 .
/"$tmpcore" --no-userinit --no-sysinit
172 check_status_maybe_lose
"SAVE-LISP-AND-DIE :EXECUTABLE-COMPRESS" $?
0 "(executable compressed saved core ran)"