Signal floating-point-overflow from bignum-to-float.
[sbcl.git] / tests / core.test.sh
blobcad0bd5afd4e391c32fa0ea547e6c2d93a43e731
1 #!/bin/sh
3 # tests related to .core files
5 # This software is part of the SBCL system. See the README file for
6 # more information.
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
10 # from CMU CL.
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
14 # more information.
16 . ./subr.sh
18 use_test_subdirectory
20 tmpcore=$TEST_FILESTEM.core
21 tmpoutput=$TEST_FILESTEM.txt
23 run_sbcl <<EOF
24 (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42))
25 EOF
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
32 # mismatch grot.
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
38 run_sbcl <<EOF
39 (defun foo (x) (+ x 11))
40 (save-lisp-and-die "$tmpcore")
41 EOF
42 run_sbcl_with_core "$tmpcore" --no-userinit --no-sysinit \
43 --eval "(setf sb-ext:*evaluator-mode* :${TEST_SBCL_EVALUATOR_MODE:-compile})" \
44 <<EOF
45 (exit :code (foo 10))
46 EOF
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")
61 EOF
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
66 run_sbcl <<EOF
67 (defun bar ()
68 (format t "~&Callbacks not supported, skipping~%")
69 (exit :code 42))
70 #+alien-callbacks
71 (progn
72 (sb-alien::define-alien-callback foo int () 42)
73 (defun bar () (exit :code (alien-funcall foo))))
74 (save-lisp-and-die "$tmpcore")
75 EOF
76 run_sbcl_with_core "$tmpcore" --no-userinit --no-sysinit \
77 --eval "(setf sb-ext:*evaluator-mode* :${TEST_SBCL_EVALUATOR_MODE:-compile})" \
78 <<EOF
79 (bar)
80 EOF
81 check_status_maybe_lose "Callbacks after SAVE-LISP-AND-DIE" $? \
82 42 "(callback function ran)"
84 # test suppression of banner in executable cores
85 run_sbcl <<EOF
86 (save-lisp-and-die "$tmpcore" :executable t)
87 EOF
88 chmod u+x "$tmpcore"
89 ./"$tmpcore" > "$tmpoutput" --no-userinit --no-sysinit --noprint <<EOF
90 (exit :code 71)
91 EOF
92 status=$?
93 if [ $status != 71 ]; then
94 echo "failure in banner suppression: $status"
95 exit 1
96 elif [ -s "$tmpoutput" ]; then
97 echo "failure in banner suppression: nonempty output:"
98 echo ---
99 cat "$tmpoutput"
100 echo ---
101 exit 1
102 elif [ -f "$tmpoutput" ]; then
103 echo "/Executable suppressed banner, good."
104 else
105 echo "failure in banner suppression: $tmpoutput was not created or something funny happened."
106 exit 1
109 # saving runtime options _from_ executable cores
110 run_sbcl <<EOF
111 (save-lisp-and-die "$tmpcore" :executable t)
113 chmod u+x "$tmpcore"
114 ./"$tmpcore" --no-userinit --no-sysinit <<EOF
115 (save-lisp-and-die "$tmpcore" :executable t :save-runtime-options t)
117 chmod u+x "$tmpcore"
118 ./"$tmpcore" --no-userinit --no-sysinit --version --eval '(exit)' <<EOF
119 (when (equal *posix-argv* '("./$tmpcore" "--version" "--eval" "(exit)"))
120 (exit :code 42))
122 status=$?
123 rm "$tmpcore"
124 if [ $status != 42 ]; then
125 echo "saving runtime options from executable failed"
126 exit 1
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 --disable-debugger --no-userinit --no-sysinit --noprint <<EOF
132 (save-lisp-and-die "$tmpcore" :executable t :save-runtime-options t)
134 chmod u+x "$tmpcore"
135 ./"$tmpcore" --no-userinit --no-sysinit <<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 --no-userinit --no-sysinit <<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 --no-sysinit <<EOF
146 (when (and (eql (extern-alien "thread_control_stack_size" unsigned) (* 200 1024))
147 (eql (dynamic-space-size) (* 250 1048576)))
148 (exit :code 42))
150 status=$?
151 rm "$tmpcore" "${tmpcore}2"
152 if [ $status != 42 ]; then
153 echo "re-saved executable used wrong memory size options"
154 exit 1
157 run_sbcl <<EOF
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)"
165 rm "$tmpcore"
166 run_sbcl <<EOF
167 (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42) :executable t
168 :compression (and (member :sb-core-compression *features*) t))
170 chmod u+x "$tmpcore"
171 ./"$tmpcore" --no-userinit --no-sysinit
172 check_status_maybe_lose "SAVE-LISP-AND-DIE :EXECUTABLE-COMPRESS" $? 0 "(executable compressed saved core ran)"
174 exit $EXIT_TEST_WIN