1 ;;;; signals.test --- test suite for Guile's signal functions -*- scheme -*-
3 ;;;; Copyright (C) 2009, 2014 Free Software Foundation, Inc.
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.
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.
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
20 (define-module (test-suite test-signals)
21 #:use-module (ice-9 match)
22 #:use-module (test-suite lib))
24 (with-test-prefix "sigaction"
26 (pass-if-exception "handler arg is an invalid integer"
27 exception:out-of-range
28 (sigaction SIGINT 51))
32 (when (defined? 'setitimer)
33 (with-test-prefix "setitimer"
34 (with-test-prefix "current itimers are 0"
35 (pass-if "ITIMER_REAL"
36 (equal? (setitimer ITIMER_REAL 0 0 0 0)
38 (pass-if "ITIMER_VIRTUAL"
39 (equal? (setitimer ITIMER_VIRTUAL 0 0 0 0)
41 (pass-if "ITIMER_PROF"
42 (equal? (setitimer ITIMER_PROF 0 0 0 0)
45 (with-test-prefix "setting values correctly"
46 (pass-if "initial setting"
47 (equal? (setitimer ITIMER_PROF 1 0 3 0)
49 (pass-if "reset to zero"
50 (match (setitimer ITIMER_PROF 0 0 0 0)
51 (((1 . 0) (val-secs . val-usecs))
52 ;; We don't presume that the timer is strictly lower than the
53 ;; value at which we set it, given its limited internal
54 ;; precision. Assert instead that the timer is between 2 and
56 (<= #e2e6 (+ (* val-secs #e1e6) val-usecs) #e3.5e6)))))
58 (with-test-prefix "usecs > 1e6"
59 (pass-if "initial setting"
60 (equal? (setitimer ITIMER_PROF 1 0 0 #e3e6)
62 (pass-if "reset to zero"
63 (match (setitimer ITIMER_PROF 0 0 0 0)
64 (((1 . 0) (val-secs . val-usecs))
65 ;; We don't presume that the timer is strictly lower than the
66 ;; value at which we set it, given its limited internal
67 ;; precision. Assert instead that the timer is between 2 and
69 (and (<= #e2e6 (+ (* val-secs #e1e6) val-usecs) #e3.5e6)
70 (<= 0 val-usecs 999999))))))))