1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- io.multiplexer test suite.
6 (in-package :iolib-tests
)
8 (in-suite* :io.multiplex
:in
:iolib
)
10 (defmacro with-event-base
/for-each-mux
((base &rest initargs
) &body body
)
12 (dolist (mux (mapcar #'cdr
*available-multiplexers
*) failed-list
)
14 (with-event-base (,base
:mux mux
,@initargs
)
17 (push (cons mux err
) failed-list
))))))
21 (with-event-base/for-each-mux
(base)
22 (event-dispatch base
:timeout
0))))
26 (with-event-base/for-each-mux
(base)
28 (add-timer base
(lambda () (setq cb
:timeout
)) 30)
29 (event-dispatch base
:timeout
0)
30 (assert (null cb
))))))
34 (with-event-base/for-each-mux
(base)
36 (add-timer base
(lambda () (setq cb
:timeout
)) 0)
37 (event-dispatch base
:one-shot t
)
38 (assert (eq cb
:timeout
))))))
40 ;;; regression test: timeouts' absolute times used used to be
41 ;;; incremented with the relative time ad infinitum.
44 (with-event-base/for-each-mux
(base)
46 (add-timer base
(lambda () (setq cb
:timeout
)) 1.5)
47 (event-dispatch base
:one-shot t
:timeout
2)
48 (assert (eq cb
:timeout
))))))
50 (defun timeout-cb (fd event
)
51 (declare (ignore fd event
))
54 (defmacro waiting-for-event
((base fd event-type
) &body body
)
55 (with-gensyms (fd-arg event-arg
)
58 (add-fd ,base
,fd
,event-type
59 (lambda (,fd-arg
,event-arg
)
60 (when (eq ,event-arg
:error
)
61 (error "error with ~A" ,fd-arg
))
64 (event-dispatch ,base
:one-shot t
)))))
66 ;;; FIXME: doesn't work with SELECT.
67 ;;; where ? it works here, on Linux. SIONESCU 2007.12.02
68 (test event-base-with-open-sockets
70 (with-event-base (base)
71 (with-open-socket (passive :address-family
:ipv4
:connect
:passive
72 :local-host
+ipv4-unspecified
+)
73 (with-open-socket (active :address-family
:ipv4
74 :remote-port
(local-port passive
)
75 :remote-host
#(127 0 0 1))
76 (add-timer base
#'timeout-cb
5)
78 (waiting-for-event (base (fd-of passive
) :read
)
79 (setq peer
(accept-connection passive
)))
80 (assert (socket-open-p peer
)))
81 ;; TODO: send and receive some stuff