1 ;;;; tests of the system's ability to catch resource exhaustion problems
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (cl:in-package :cl-user)
16 (load "test-util.lisp")
17 (load "assertoid.lisp")
18 (use-package "TEST-UTIL")
19 (use-package "ASSERTOID")
22 ;;; Prior to sbcl-0.7.1.38, doing something like (RECURSE), even in
23 ;;; safe code, would crash the entire Lisp process. Then the soft
24 ;;; stack checking was introduced, which checked (in safe code) for
25 ;;; stack exhaustion at each lambda.
27 ;;; Post 0.7.6.1, this was rewritten to use mprotect()-based stack
28 ;;; protection which does not require lisp code to check anything,
29 ;;; and works at all optimization settings. However, it now signals a
30 ;;; STORAGE-CONDITION instead of an ERROR.
38 ;;; Base-case: detecting exhaustion
39 (with-test (:name (:exhaust :basic) :broken-on '(and :sunos :x86-64))
40 (assert (eq :exhausted
43 (storage-condition (c)
47 ;;; Check that non-local control transfers restore the stack
48 ;;; exhaustion checking after unwinding -- and that previous test
50 (with-test (:name (:exhaust :non-local-control) :broken-on '(and :sunos :x86-64))
51 (let ((exhaust-count 0)
55 (handler-bind ((storage-condition (lambda (c)
57 (if (= *count* (incf exhaust-count))
63 (assert (= exhaust-count recurse-count *count*))))
65 ;;; Check that we can safely use user-provided restarts to
67 (with-test (:name (:exhaust :restarts) :broken-on '(and :sunos :x86-64))
68 (let ((exhaust-count 0)
71 (handler-bind ((storage-condition (lambda (c)
73 (if (= *count* (incf exhaust-count))
75 (invoke-restart (find-restart 'ok))))))
77 (with-simple-restart (ok "ok")
80 (assert (= exhaust-count recurse-count *count*))))
82 (with-test (:name (:exhaust :binding-stack))
84 (symbols (loop repeat 1024 collect (gensym)))
85 (values (loop repeat 1024 collect nil)))
87 (labels ((exhaust-binding-stack (i)
89 (exhaust-binding-stack (1+ i)))))
91 (exhaust-binding-stack 0)
92 (sb-kernel::binding-stack-exhausted ()
96 (with-test (:name (:exhaust :alien-stack) :skipped-on '(not :c-stack-is-control-stack))
98 (labels ((exhaust-alien-stack (i)
99 (with-alien ((integer-array (array int 500)))
100 (+ (deref integer-array 0)
101 (exhaust-alien-stack (1+ i))))))
103 (exhaust-alien-stack 0)
104 (sb-kernel::alien-stack-exhausted ()