Use immobile_space_p() in gc_managed_addr_p()
[sbcl.git] / tests / core.test.sh
blob6b19cab427b9bcfe614c620b24688bf4bb11f495
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 <<EOF
115 (save-lisp-and-die "$tmpcore" :executable t :save-runtime-options t)
117 chmod u+x "$tmpcore"
118 ./"$tmpcore" --no-userinit --version --eval '(exit)' <<EOF
119 (when (equal *posix-argv* '("./$tmpcore" "--version" "--eval" "(exit)"))
120 (exit :code 42))
122 status=$?
123 if [ $status != 42 ]; then
124 echo "saving runtime options from executable failed"
125 exit 1
128 rm "$tmpcore"
129 run_sbcl <<EOF
130 (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42)
131 :compression (and (member :sb-core-compression *features*) t))
133 run_sbcl_with_core "$tmpcore" --no-userinit --no-sysinit \
134 --eval "(setf sb-ext:*evaluator-mode* :${TEST_SBCL_EVALUATOR_MODE:-compile})"
135 check_status_maybe_lose "SAVE-LISP-AND-DIE :COMPRESS" $? 0 "(compressed saved core ran)"
137 rm "$tmpcore"
138 run_sbcl <<EOF
139 (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42) :executable t
140 :compression (and (member :sb-core-compression *features*) t))
142 chmod u+x "$tmpcore"
143 ./"$tmpcore" --no-userinit --no-sysinit
144 check_status_maybe_lose "SAVE-LISP-AND-DIE :EXECUTABLE-COMPRESS" $? 0 "(executable compressed saved core ran)"
146 exit $EXIT_TEST_WIN