X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fdeadline.impure.lisp;h=10bae09a5fc8ff3c57b8b4e15501da073b6a0ee2;hb=f2db6743b1fadeea9e72cb583d857851c87efcd4;hp=32d19f63d2628a636b4ce3760f57c636d5aea603;hpb=fe962ba01d267b92f638c8f0d19be41054219f04;p=sbcl.git diff --git a/tests/deadline.impure.lisp b/tests/deadline.impure.lisp index 32d19f6..10bae09 100644 --- a/tests/deadline.impure.lisp +++ b/tests/deadline.impure.lisp @@ -9,14 +9,46 @@ (assert-timeout - (sb-impl::with-deadline (:seconds 1) - (run-program "sleep" '("5") :search t :wait t))) + (sb-sys:with-deadline (:seconds 1) + (run-program "sleep" '("3") :search t :wait t))) + +(let ((n 0) + (final nil)) + (handler-case + (handler-bind ((sb-sys:deadline-timeout (lambda (c) + (when (< n 2) + (incf n) + (sb-sys:defer-deadline 0.1 c))))) + (sb-sys:with-deadline (:seconds 1) + (run-program "sleep" '("2") :search t :wait t))) + (sb-sys:deadline-timeout (c) + (setf final c))) + (assert (= n 2)) + (assert final)) + +(let ((n 0) + (final nil)) + (handler-case + (handler-bind ((sb-sys:deadline-timeout (lambda (c) + (incf n) + (sb-sys:defer-deadline 0.1 c)))) + (sb-sys:with-deadline (:seconds 1) + (run-program "sleep" '("2") :search t :wait t))) + (sb-sys:deadline-timeout (c) + (setf final c))) + (assert (plusp n)) + (assert (not final))) #+(and sb-thread (not sb-lutex)) (progn (assert-timeout - (let ((lock (sb-thread:make-mutex))) - (sb-thread:make-thread (lambda () (sb-thread:get-mutex lock) (sleep 5))) + (let ((lock (sb-thread:make-mutex)) + (waitp t)) + (sb-thread:make-thread (lambda () + (sb-thread:get-mutex lock) + (setf waitp nil) + (sleep 5))) + (loop while waitp do (sleep 0.01)) (sb-impl::with-deadline (:seconds 1) (sb-thread:get-mutex lock)))) @@ -28,4 +60,30 @@ (assert-timeout (sb-impl::with-deadline (:seconds 1) (sb-thread:join-thread - (sb-thread:make-thread (lambda () (loop (sleep 1)))))))) + (sb-thread:make-thread (lambda () (loop (sleep 1))))))) + + (with-test (:name (:deadline :futex-wait-eintr)) + (let ((lock (sb-thread:make-mutex)) + (waitp t)) + (sb-thread:make-thread (lambda () + (sb-thread:get-mutex lock) + (setf waitp nil) + (sleep 5))) + (loop while waitp do (sleep 0.01)) + (let ((thread (sb-thread:make-thread + (lambda () + (let ((start (get-internal-real-time))) + (handler-case + (sb-impl::with-deadline (:seconds 1) + (sb-thread:get-mutex lock)) + (sb-sys:deadline-timeout (x) + (declare (ignore x)) + (let ((end (get-internal-real-time))) + (float (/ (- end start) + internal-time-units-per-second) + 0.0))))))))) + (sleep 0.3) + (sb-thread:interrupt-thread thread (lambda () 42)) + (let ((seconds-passed (sb-thread:join-thread thread))) + (format t "Deadline in ~S~%" seconds-passed) + (assert (< seconds-passed 1.2)))))))