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)
51 :broken-on '(and :sunos :x86-64)
53 (let ((exhaust-count 0)
57 (handler-bind ((storage-condition (lambda (c)
59 (if (= *count* (incf exhaust-count))
65 (assert (= exhaust-count recurse-count *count*))))
67 ;;; Check that we can safely use user-provided restarts to
69 (with-test (:name (:exhaust :restarts)
70 :broken-on '(and :sunos :x86-64)
72 (let ((exhaust-count 0)
75 (handler-bind ((storage-condition (lambda (c)
77 (if (= *count* (incf exhaust-count))
79 (invoke-restart (find-restart 'ok))))))
81 (with-simple-restart (ok "ok")
84 (assert (= exhaust-count recurse-count *count*))))
86 (with-test (:name (:exhaust :binding-stack) :skipped-on :win32)
88 (symbols (loop repeat 1024 collect (gensym)))
89 (values (loop repeat 1024 collect nil)))
91 (labels ((exhaust-binding-stack (i)
93 (exhaust-binding-stack (1+ i)))))
95 (exhaust-binding-stack 0)
96 (sb-kernel::binding-stack-exhausted ()
100 (with-test (:name (:exhaust :alien-stack)
101 :skipped-on '(not :c-stack-is-control-stack)
104 (labels ((exhaust-alien-stack (i)
105 (with-alien ((integer-array (array int 500)))
106 (+ (deref integer-array 0)
107 (exhaust-alien-stack (1+ i))))))
109 (exhaust-alien-stack 0)
110 (sb-kernel::alien-stack-exhausted ()