Debian Codegraph @

test-suite/standalone/test-out-of-memory

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
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. That doesn't seem like something we
9 ;; 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-stack-overflow.
16 (exit 77)) ; unresolved
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-stack-overflow.
30 (exit 77)) ; unresolved
31
32 (catch #t
33 ;; Silence GC warnings.
34 (lambda ()
35 (current-warning-port (open-output-file "/dev/null")))
36 (lambda (k . args)
37 (print-exception (current-error-port) #f k args)
38 (write "Skipping test.\n" (current-error-port))
39 (exit 0)))
40
41 ;; 50 MB.
42 (define *limit* (* 50 1024 1024))
43
44 (call-with-values (lambda () (getrlimit 'as))
45 (lambda (soft hard)
46 (unless (and soft (< soft *limit*))
47 (setrlimit 'as (if hard (min *limit* hard) *limit*) hard))))
48
49 (define (test thunk)
50 (catch 'out-of-memory
51 (lambda ()
52 (thunk)
53 (error "should not be reached"))
54 (lambda _
55 #t)))
56
57 (use-modules (rnrs bytevectors))
58
59 (test (lambda ()
60 ;; Unhappily, on 32-bit systems, vectors are limited to 16M
61 ;; elements. Boo. Anyway, a vector with 16M elements takes 64
62 ;; MB, which doesn't fit into 50 MB.
63 (make-vector (1- (ash 1 24)))))
64 (test (lambda ()
65 ;; Likewise for a bytevector. This is different from the above,
66 ;; as the elements of a bytevector are not traced by GC.
67 (make-bytevector #e1e9)))
68 ;; (test (lambda ()
69 ;; ;; This one is the kicker -- we allocate pairs until the heap
70 ;; ;; can't expand. This is the hardest test to deal with because
71 ;; ;; the error-handling machinery has no memory in which to work.
72 ;; (iota #e1e8)))
73 (test (lambda ()
74 ;; The same, but also causing allocating during the unwind
75 ;; (ouch!)
76 (dynamic-wind
77 (lambda () #t)
78 (lambda () (iota #e1e8))
79 (lambda () (iota #e1e8)))))
80
81 ;; Local Variables:
82 ;; mode: scheme
83 ;; End: