Fix make-array transforms.
[sbcl.git] / tests / core.test.sh
1 #!/bin/sh
2
3 # tests related to .core files
4
5 # This software is part of the SBCL system. See the README file for
6 # more information.
7 #
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.
11 #
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.
15
16 . ./subr.sh
17
18 use_test_subdirectory
19
20 tmpcore=$TEST_FILESTEM.core
21 tmpoutput=$TEST_FILESTEM.txt
22
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 check_status_maybe_lose "SAVE-LISP-AND-DIE :TOPLEVEL" $? 0 "(saved core ran)"
28
29 # In sbcl-0.7.7 SAVE-LISP-AND-DIE didn't work at all because of
30 # flakiness caused by consing/GC/purify twice-and-at-least-twice
31 # mismatch grot.
32 #
33 # "serves yall right for fiddling with too much stuff"
34 #   -- Eric Marsden, <http://tunes.org/~nef/logs/lisp/02.09.15>
35 #
36 # diagnosed and fixed by Dan Barlow in sbcl-0.7.7.29
37 run_sbcl <<EOF
38   (defun foo (x) (+ x 11))
39   (save-lisp-and-die "$tmpcore")
40 EOF
41 run_sbcl_with_core "$tmpcore" --no-userinit --no-sysinit <<EOF
42   (exit :code (foo 10))
43 EOF
44 check_status_maybe_lose "Basic SAVE-LISP-AND-DIE" $? 21 "(saved core ran)"
45
46 # In sbcl-0.9.8 saving cores with callbacks didn't work on gencgc platforms
47 run_sbcl <<EOF
48   (defun bar ()
49     (format t "~&Callbacks not supported, skipping~%")
50     (exit :code 42))
51   #+alien-callbacks
52   (progn
53     (sb-alien::define-alien-callback foo int () 42)
54     (defun bar () (exit :code (alien-funcall foo))))
55   (save-lisp-and-die "$tmpcore")
56 EOF
57 run_sbcl_with_core "$tmpcore" --no-userinit --no-sysinit <<EOF
58   (bar)
59 EOF
60 check_status_maybe_lose "Callbacks after SAVE-LISP-AND-DIE" $? \
61     42 "(callback function ran)"
62
63 # test suppression of banner in executable cores
64 run_sbcl <<EOF
65   (save-lisp-and-die "$tmpcore" :executable t)
66 EOF
67 chmod u+x "$tmpcore"
68 ./"$tmpcore" > "$tmpoutput" --no-userinit --no-sysinit --noprint <<EOF 
69   (exit :code 71)
70 EOF
71 status=$?
72 if [ $status != 71 ]; then
73   echo "failure in banner suppression: $status"
74   exit 1
75 elif [ -s "$tmpoutput" ]; then
76   echo "failure in banner suppression: nonempty output:"
77   echo ---
78   cat "$tmpoutput"
79   echo ---
80   exit 1
81 elif [ -f "$tmpoutput" ]; then
82   echo "/Executable suppressed banner, good."
83 else
84   echo "failure in banner suppression: $tmpoutput was not created or something funny happened."
85   exit 1
86 fi
87
88 # saving runtime options _from_ executable cores
89 run_sbcl <<EOF
90   (save-lisp-and-die "$tmpcore" :executable t)
91 EOF
92 chmod u+x "$tmpcore"
93 ./"$tmpcore" --no-userinit <<EOF 
94   (save-lisp-and-die "$tmpcore" :executable t :save-runtime-options t)
95 EOF
96 chmod u+x "$tmpcore"
97 ./"$tmpcore" --no-userinit --version --eval '(exit)' <<EOF
98   (when (equal *posix-argv* '("./$tmpcore" "--version" "--eval" "(exit)"))
99     (exit :code 42))
100 EOF
101 status=$?
102 if [ $status != 42 ]; then
103     echo "saving runtime options from executable failed"
104     exit 1
105 fi
106
107 rm "$tmpcore"
108 run_sbcl <<EOF
109   (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42)
110                       :compression (and (member :sb-core-compression *features*) t))
111 EOF
112 run_sbcl_with_core "$tmpcore" --no-userinit --no-sysinit
113 check_status_maybe_lose "SAVE-LISP-AND-DIE :COMPRESS" $? 0 "(compressed saved core ran)"
114
115 rm "$tmpcore"
116 run_sbcl <<EOF
117   (save-lisp-and-die "$tmpcore" :toplevel (lambda () 42) :executable t
118                      :compression (and (member :sb-core-compression *features*) t))
119 EOF
120 chmod u+x "$tmpcore"
121 ./"$tmpcore" --no-userinit --no-sysinit
122 check_status_maybe_lose "SAVE-LISP-AND-DIE :EXECUTABLE-COMPRESS" $? 0 "(executable compressed saved core ran)"
123
124 exit $EXIT_TEST_WIN