Make INFO's compiler-macro more forgiving.
[sbcl.git] / tests / signals.impure.lisp
blobc4f347e443d069ad1956fa3c943377f5bd2a0ee1
1 ;;;; Tests for async signal safety.
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.
14 (use-package :test-util)
16 (with-test (:name (:async-unwind :specials))
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)))
39 (require :sb-posix)
41 (with-test (:name (:signal :errno)
42 ;; This test asserts that nanosleep behaves correctly
43 ;; for invalid values and sets EINVAL. Well, we have
44 ;; nanosleep on Windows, but it depends on the caller
45 ;; (namely SLEEP) to produce known-good arguments, and
46 ;; even if we wanted to check argument validity,
47 ;; integration with `errno' is not to be expected.
48 :skipped-on :win32)
49 (let* (saved-errno
50 (returning nil)
51 (timer (make-timer (lambda ()
52 (sb-unix:unix-open "~!@#$%^&*[]()/\\" 0 0)
53 (assert (= sb-unix:enoent
54 (sb-unix::get-errno)))
55 (setq returning t)))))
56 (schedule-timer timer 0.2)
57 ;; Fail and set errno.
58 (sb-unix:nanosleep -1 -1)
59 (setq saved-errno (sb-unix::get-errno))
60 (assert (= saved-errno sb-posix:einval))
61 ;; Wait, but not with sleep because that will be interrupted and
62 ;; we get EINTR.
63 (loop until returning)
64 (loop repeat 1000000000)
65 (assert (= saved-errno (sb-unix::get-errno)))))
67 (with-test (:name :handle-interactive-interrupt
68 ;; It is desirable to support C-c on Windows, but SIGINT
69 ;; is not the mechanism to use on this platform.
70 :skipped-on :win32)
71 (assert (eq :condition
72 (handler-case
73 (progn
74 (sb-thread::kill-safely
75 (sb-thread::thread-os-thread sb-thread::*current-thread*)
76 sb-unix:sigint)
77 #+sb-safepoint-strictly
78 ;; In this case, the signals handler gets invoked
79 ;; indirectly through an INTERRUPT-THREAD. Give it
80 ;; enough time to hit.
81 (sleep 1))
82 (sb-sys:interactive-interrupt ()
83 :condition)))))
85 (with-test (:name :bug-640516)
86 ;; On Darwin interrupting a SLEEP so that it took longer than
87 ;; the requested amount caused it to hang.
88 (assert
89 (handler-case
90 (sb-ext:with-timeout 10
91 (let (to)
92 (handler-bind ((sb-ext:timeout (lambda (c)
93 (unless to
94 (setf to t)
95 (sleep 2)
96 (continue c)))))
97 (sb-ext:with-timeout 0.1 (sleep 1) t))))
98 (sb-ext:timeout ()
99 nil))))