Debian Codegraph @

test-suite/tests/signals.test

raw
1 ;;;; signals.test --- test suite for Guile's signal functions -*- scheme -*-
2 ;;;;
3 ;;;; Copyright (C) 2009, 2014, 2017, 2019 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
41 (pass-if "ITIMER_REAL"
42 ;; setitimer may have already been called in other tests. For
43 ;; some versions of Cygwin, the return value of setitimer is
44 ;; invalid after an alarm has occurred. See
45 ;; https://www.cygwin.com/ml/cygwin/2019-02/msg00395.html
46 (if (string-contains %host-type "cygwin")
47 (throw 'unresolved)
48 (equal? (setitimer ITIMER_REAL 0 0 0 0)
49 '((0 . 0) (0 . 0)))))
50
51 (pass-if "ITIMER_VIRTUAL"
52 (if (not (provided? 'ITIMER_VIRTUAL))
53 (throw 'unsupported)
54 (equal? (setitimer ITIMER_VIRTUAL 0 0 0 0)
55 '((0 . 0) (0 . 0)))))
56
57 (pass-if "ITIMER_PROF"
58 (if (not (provided? 'ITIMER_PROF))
59 (throw 'unsupported)
60 (equal? (setitimer ITIMER_PROF 0 0 0 0)
61 '((0 . 0) (0 . 0))))))
62
63 (with-test-prefix "setting values correctly"
64 (pass-if "initial setting"
65 (if (not (provided? 'ITIMER_PROF))
66 (throw 'unsupported)
67 (equal? (setitimer ITIMER_PROF 1 0 3 0)
68 '((0 . 0) (0 . 0)))))
69 (pass-if "reset to zero"
70 (if (not (provided? 'ITIMER_PROF))
71 (throw 'unsupported)
72 (match (setitimer ITIMER_PROF 0 0 0 0)
73 ((interval value)
74 ;; We don't presume that the timer is strictly lower than the
75 ;; value at which we set it, given its limited internal
76 ;; precision. Assert instead that the timer is between 2 and
77 ;; 3.5 seconds.
78 (and (<= 0.9 (time-pair->secs interval) 1.1)
79 (<= 2.0 (time-pair->secs value) 3.5)))))))
80
81 (with-test-prefix "usecs > 1e6"
82 (pass-if "initial setting"
83 (if (not (provided? 'ITIMER_PROF))
84 (throw 'unsupported)
85 (equal? (setitimer ITIMER_PROF 1 0 0 #e3e6)
86 '((0 . 0) (0 . 0)))))
87 (pass-if "reset to zero"
88 (if (not (provided? 'ITIMER_PROF))
89 (throw 'unsupported)
90 (match (setitimer ITIMER_PROF 0 0 0 0)
91 ((interval value)
92 ;; We don't presume that the timer is strictly lower than the
93 ;; value at which we set it, given its limited internal
94 ;; precision. Assert instead that the timer is between 2 and
95 ;; 3.5 seconds.
96 (and (<= 0.9 (time-pair->secs interval) 1.1)
97 (<= 2.0 (time-pair->secs value) 3.5)
98 (match value
99 ((secs . usecs)
100 (<= 0 usecs 999999)))))))))))