From: Taylor R Campbell Date: Thu, 3 Jan 2019 16:33:31 +0000 (+0000) Subject: Test detectable screw case of delay-force infinite recursion. X-Git-Tag: mit-scheme-pucked-10.1.9~3^2~28 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=23704145f986dcbb9e5e271d50a5f81986244433;p=mit-scheme.git Test detectable screw case of delay-force infinite recursion. --- diff --git a/tests/runtime/test-promise.scm b/tests/runtime/test-promise.scm index 703baba85..c8af319e7 100644 --- a/tests/runtime/test-promise.scm +++ b/tests/runtime/test-promise.scm @@ -28,6 +28,59 @@ USA. (declare (usual-integrations)) +(define (carefully procedure if-overflow if-timeout) + (let ((thread #f) + (mutex (make-thread-mutex)) + (condvar (make-condition-variable)) + (gc-env (->environment '(runtime garbage-collector)))) + (define (start-it) + (with-thread-mutex-lock mutex + (lambda () + (do () (thread) + (condition-variable-wait! condvar mutex)))) + (let ((default/stack-overflow (access default/stack-overflow gc-env))) + (define (give-up) + (if (eq? thread (current-thread)) + (exit-current-thread (if-overflow)) + (default/stack-overflow))) + (call-with-current-continuation + (lambda (abort) + (fluid-let (((access hook/stack-overflow gc-env) + (lambda () (within-continuation abort give-up)))) + (exit-current-thread (procedure))))))) + (define (stop-it) + (assert thread) + (signal-thread-event thread + (lambda () + (exit-current-thread (if-timeout))))) + (let ((t (create-thread #f start-it))) + (with-thread-mutex-lock mutex + (lambda () + (set! thread t) + (condition-variable-broadcast! condvar)))) + (let ((result #f)) + (define (done-it thread* value) + (assert (eq? thread* thread)) + (set! result value)) + (join-thread thread done-it) + (let ((timer)) + (dynamic-wind + (lambda () (set! timer (register-timer-event 1000 stop-it))) + (lambda () (do () (result) (suspend-current-thread))) + (lambda () (deregister-timer-event (set! timer)))))))) + +(define-test 'delay-force-loop + (lambda () + (expect-failure + (lambda () + (assert-error + (lambda () + (carefully (lambda () + (define p (delay-force p)) + (force p)) + (lambda () 'stack-overflow) + (lambda () 'timeout)))))))) + (define-test 'force-force-delay-delay (lambda () (assert-eqv (force (force (delay (delay 0)))) 0)))