ea6e8953b674c6c9a3deb9cce3374f3afbb3afe9
[sbcl.git] / tests / signals.impure.lisp
1 ;;;; Tests for async signal safety.
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absoluely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
13
14 (use-package :test-util)
15
16 (with-test (:name (:async-unwind :specials) :fails-on :win32)
17   (let ((*x0* nil) (*x1* nil) (*x2* nil) (*x3* nil) (*x4* nil))
18     (declare (special *x0* *x1* *x2* *x3* *x4*))
19     (loop repeat 10 do
20           (loop repeat 10 do
21                 (catch 'again
22                   (sb-ext:schedule-timer (sb-ext:make-timer
23                                           (lambda ()
24                                             (throw 'again nil)))
25                                          (random 0.1))
26                   (loop
27                    (let ((*x0* (cons nil nil)) (*x1* (cons nil nil))
28                          (*x2* (cons nil nil)) (*x3* (cons nil nil))
29                          (*x4* (cons nil nil)))
30                      (declare (special *x0* *x1* *x2* *x3* *x4*)))))
31                 (when (not (and (null *x0*) (null *x1*) (null *x2*) (null *x3*)
32                                 (null *x4*)))
33                   (format t "~S ~S ~S ~S ~S~%" *x0* *x1* *x2* *x3* *x4*)
34                   (assert nil)))
35           (princ '*)
36           (force-output))
37     (terpri)))
38
39 (require :sb-posix)
40
41 (with-test (:name (:signal :errno) :fails-on :win32)
42   (let* (saved-errno
43          (returning nil)
44          (timer (make-timer (lambda ()
45                               (sb-unix:unix-open "~!@#$%^&*[]()/\\" 0 0)
46                               (assert (= sb-unix:enoent
47                                          (sb-unix::get-errno)))
48                               (setq returning t)))))
49     (schedule-timer timer 0.2)
50     ;; Fail and set errno.
51     (sb-unix:nanosleep -1 -1)
52     (setq saved-errno (sb-unix::get-errno))
53     (assert (= saved-errno sb-posix:einval))
54     ;; Wait, but not with sleep because that will be interrupted and
55     ;; we get EINTR.
56     (loop until returning)
57     (loop repeat 1000000000)
58     (assert (= saved-errno (sb-unix::get-errno)))))
59
60 (with-test (:name :handle-interactive-interrupt :fails-on :win32)
61   (assert (eq :condition
62               (handler-case
63                   (sb-thread::kill-safely
64                    (sb-thread::thread-os-thread sb-thread::*current-thread*)
65                    sb-unix:sigint)
66                 (sb-sys:interactive-interrupt ()
67                   :condition)))))
68
69 (with-test (:name :bug-640516)
70   ;; On Darwin interrupting a SLEEP so that it took longer than
71   ;; the requested amount caused it to hang.
72   (assert
73    (handler-case
74        (sb-ext:with-timeout 10
75          (let (to)
76            (handler-bind ((sb-ext:timeout (lambda (c)
77                                             (unless to
78                                               (setf to t)
79                                               (sleep 2)
80                                               (continue c)))))
81              (sb-ext:with-timeout 0.1 (sleep 1) t))))
82      (sb-ext:timeout ()
83        nil))))