test-stack-overflow 1.7 KB

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