| 1 |
#!/bin/sh |
| 2 |
guild compile "$0" |
| 3 |
exec guile -q -s "$0" "$@" |
| 4 |
!# |
| 5 |
|
| 6 |
(unless (defined? 'setrlimit) |
| 7 |
;; Without an rlimit, this test can take down your system, as it |
| 8 |
;; consumes all of your memory in stack space. That doesn't seem like |
| 9 |
;; something we should run as part of an automated test suite. |
| 10 |
(exit 0)) |
| 11 |
|
| 12 |
(when (string-ci= "darwin" (vector-ref (uname) 0)) |
| 13 |
;; setrlimits are ignored in OS X (tested on 10.9 and 10.10). Proceeding |
| 14 |
;; with the test would fill all available memory and probably end in a crash. |
| 15 |
;; See also test-out-of-memory. |
| 16 |
(exit 77)) ; uresolved |
| 17 |
|
| 18 |
(when (string-ci= "GNU" (vector-ref (uname) 0)) |
| 19 |
;; setrlimits are not yet implemented on GNU/Hurd systems. Proceeding |
| 20 |
;; with the test would end in a crash. See |
| 21 |
;; <https://lists.gnu.org/archive/html/bug-hurd/2017-05/msg00013.html> |
| 22 |
(exit 77)) ; unresolved |
| 23 |
|
| 24 |
(when (string-contains-ci (vector-ref (uname) 0) "CYGWIN_NT") |
| 25 |
;; attempting to use setrlimits for memory RLIMIT_AS will always |
| 26 |
;; produce an invalid argument error on Cygwin (tested on |
| 27 |
;; CYGWIN_NT-10.0 DLL v2.7.0). Proceeding with the test would fill |
| 28 |
;; all available memory and probably end in a crash. See also |
| 29 |
;; test-out-of-memory. |
| 30 |
(exit 77)) ; unresolved |
| 31 |
|
| 32 |
;; 100 MB. |
| 33 |
(define *limit* (* 100 1024 1024)) |
| 34 |
|
| 35 |
(call-with-values (lambda () (getrlimit 'as)) |
| 36 |
(lambda (soft hard) |
| 37 |
(unless (and soft (< soft *limit*)) |
| 38 |
(setrlimit 'as (if hard (min *limit* hard) *limit*) hard)))) |
| 39 |
|
| 40 |
(define (test) |
| 41 |
(catch 'stack-overflow |
| 42 |
(lambda () |
| 43 |
(let lp () |
| 44 |
(lp) |
| 45 |
(error "should not be reached"))) |
| 46 |
(lambda _ |
| 47 |
#t))) |
| 48 |
|
| 49 |
;; Run the test a few times. The stack will only be enlarged and |
| 50 |
;; relocated on the first one. |
| 51 |
|
| 52 |
(test) |
| 53 |
(test) |
| 54 |
(test) |
| 55 |
(test) |
| 56 |
(test) |
| 57 |
|
| 58 |
;; Local Variables: |
| 59 |
;; mode: scheme |
| 60 |
;; End: |