GOOPS cosmetics
[bpt/guile.git] / test-suite / tests / signals.test
1 ;;;; signals.test --- test suite for Guile's signal functions -*- scheme -*-
2 ;;;;
3 ;;;; Copyright (C) 2009, 2014 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
9 ;;;;
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free
17 ;;;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 USA
19
20 (define-module (test-suite test-signals)
21 #:use-module (ice-9 match)
22 #:use-module (test-suite lib))
23
24 (with-test-prefix "sigaction"
25
26 (pass-if-exception "handler arg is an invalid integer"
27 exception:out-of-range
28 (sigaction SIGINT 51))
29
30 )
31
32 (define (time-pair->secs secs-usecs-pair)
33 (match secs-usecs-pair
34 ((secs . usecs)
35 (+ secs (/ usecs 1e6)))))
36
37 (when (defined? 'setitimer)
38 (with-test-prefix "setitimer"
39 (with-test-prefix "current itimers are 0"
40 (pass-if "ITIMER_REAL"
41 (equal? (setitimer ITIMER_REAL 0 0 0 0)
42 '((0 . 0) (0 . 0))))
43 (pass-if "ITIMER_VIRTUAL"
44 (equal? (setitimer ITIMER_VIRTUAL 0 0 0 0)
45 '((0 . 0) (0 . 0))))
46 (pass-if "ITIMER_PROF"
47 (equal? (setitimer ITIMER_PROF 0 0 0 0)
48 '((0 . 0) (0 . 0)))))
49
50 (with-test-prefix "setting values correctly"
51 (pass-if "initial setting"
52 (equal? (setitimer ITIMER_PROF 1 0 3 0)
53 '((0 . 0) (0 . 0))))
54 (pass-if "reset to zero"
55 (match (setitimer ITIMER_PROF 0 0 0 0)
56 ((interval value)
57 ;; We don't presume that the timer is strictly lower than the
58 ;; value at which we set it, given its limited internal
59 ;; precision. Assert instead that the timer is between 2 and
60 ;; 3.5 seconds.
61 (and (<= 0.9 (time-pair->secs interval) 1.1)
62 (<= 2.0 (time-pair->secs value) 3.5))))))
63
64 (with-test-prefix "usecs > 1e6"
65 (pass-if "initial setting"
66 (equal? (setitimer ITIMER_PROF 1 0 0 #e3e6)
67 '((0 . 0) (0 . 0))))
68 (pass-if "reset to zero"
69 (match (setitimer ITIMER_PROF 0 0 0 0)
70 ((interval value)
71 ;; We don't presume that the timer is strictly lower than the
72 ;; value at which we set it, given its limited internal
73 ;; precision. Assert instead that the timer is between 2 and
74 ;; 3.5 seconds.
75 (and (<= 0.9 (time-pair->secs interval) 1.1)
76 (<= 2.0 (time-pair->secs value) 3.5)
77 (match value
78 ((secs . usecs)
79 (<= 0 usecs 999999))))))))))