3 (use-package :test-util
)
5 (defmacro assert-timeout
(form)
6 (let ((ok (gensym "OK")))
12 (error "No timeout from form:~% ~S" ',form
)))))
14 (defun run-sleep (seconds)
15 (sb-ext:run-program
"sleep" (list (format nil
"~D" seconds
))
18 (with-test (:name
(:deadline sb-ext
:run-program
:trivial
) :fails-on
:win32
)
19 (assert-timeout (sb-sys:with-deadline
(:seconds
1)
22 (with-test (:name
(:deadline sb-sys
:defer-deadline
1) :fails-on
:win32
)
26 (handler-bind ((sb-sys:deadline-timeout
30 (sb-sys:defer-deadline
0.1 c
)))))
31 (sb-sys:with-deadline
(:seconds
1)
33 (sb-sys:deadline-timeout
(c)
38 (with-test (:name
(:deadline sb-sys
:defer-deadline
2) :fails-on
:win32
)
42 (handler-bind ((sb-sys:deadline-timeout
45 (sb-sys:defer-deadline
0.1 c
))))
46 (sb-sys:with-deadline
(:seconds
1)
48 (sb-sys:deadline-timeout
(c)
51 (assert (not final
))))
53 (with-test (:name
(:deadline sb-sys
:cancel-deadline
) :fails-on
:win32
)
57 (handler-bind ((sb-sys:deadline-timeout
60 (sb-sys:cancel-deadline c
))))
61 (sb-sys:with-deadline
(:seconds
1)
63 (sb-sys:deadline-timeout
(c)
66 (assert (not final
))))
68 (with-test (:name
(:deadline sb-thread
:grab-mutex
)
69 :skipped-on
'(not :sb-thread
))
71 (let ((lock (sb-thread:make-mutex
))
73 (make-join-thread (lambda ()
74 (sb-thread:grab-mutex lock
)
77 (loop while waitp do
(sleep 0.01))
78 (sb-sys:with-deadline
(:seconds
1)
79 (sb-thread:grab-mutex lock
)))))
81 (with-test (:name
(:deadline sb-thread
:wait-on-semaphore
)
82 :skipped-on
'(not :sb-thread
))
84 (let ((sem (sb-thread:make-semaphore
:count
0)))
85 (sb-sys:with-deadline
(:seconds
1)
86 (sb-thread:wait-on-semaphore sem
)))))
88 (with-test (:name
(:deadline sb-thread
:join-thread
)
89 :skipped-on
'(not :sb-thread
))
91 (sb-sys:with-deadline
(:seconds
1)
92 (sb-thread:join-thread
93 (make-kill-thread (lambda () (loop (sleep 1))))))))
95 (with-test (:name
(:deadline
:futex-wait-eintr
) :skipped-on
'(not :sb-thread
))
96 (let ((lock (sb-thread:make-mutex
))
98 (make-join-thread (lambda ()
99 (sb-thread:grab-mutex lock
)
102 (loop while waitp do
(sleep 0.01))
103 (let ((thread (make-join-thread
105 (let ((start (get-internal-real-time)))
107 (sb-sys:with-deadline
(:seconds
1)
108 (sb-thread:grab-mutex lock
))
109 (sb-sys:deadline-timeout
(x)
111 (let ((end (get-internal-real-time)))
112 (float (/ (- end start
)
113 internal-time-units-per-second
)
116 (sb-thread:interrupt-thread thread
(lambda () 42))
117 (let ((seconds-passed (sb-thread:join-thread thread
)))
118 (assert (< seconds-passed
1.2))))))