signals.test 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. (define-module (test-suite test-signals)
  20. #:use-module (ice-9 match)
  21. #:use-module (test-suite lib))
  22. (with-test-prefix "sigaction"
  23. (pass-if-exception "handler arg is an invalid integer"
  24. exception:out-of-range
  25. (sigaction SIGINT 51))
  26. )
  27. (define (time-pair->secs secs-usecs-pair)
  28. (match secs-usecs-pair
  29. ((secs . usecs)
  30. (+ secs (/ usecs 1e6)))))
  31. (when (defined? 'setitimer)
  32. (with-test-prefix "setitimer"
  33. (with-test-prefix "current itimers are 0"
  34. (pass-if "ITIMER_REAL"
  35. (equal? (setitimer ITIMER_REAL 0 0 0 0)
  36. '((0 . 0) (0 . 0))))
  37. (pass-if "ITIMER_VIRTUAL"
  38. (equal? (setitimer ITIMER_VIRTUAL 0 0 0 0)
  39. '((0 . 0) (0 . 0))))
  40. (pass-if "ITIMER_PROF"
  41. (equal? (setitimer ITIMER_PROF 0 0 0 0)
  42. '((0 . 0) (0 . 0)))))
  43. (with-test-prefix "setting values correctly"
  44. (pass-if "initial setting"
  45. (equal? (setitimer ITIMER_PROF 1 0 3 0)
  46. '((0 . 0) (0 . 0))))
  47. (pass-if "reset to zero"
  48. (match (setitimer ITIMER_PROF 0 0 0 0)
  49. ((interval value)
  50. ;; We don't presume that the timer is strictly lower than the
  51. ;; value at which we set it, given its limited internal
  52. ;; precision. Assert instead that the timer is between 2 and
  53. ;; 3.5 seconds.
  54. (and (<= 0.9 (time-pair->secs interval) 1.1)
  55. (<= 2.0 (time-pair->secs value) 3.5))))))
  56. (with-test-prefix "usecs > 1e6"
  57. (pass-if "initial setting"
  58. (equal? (setitimer ITIMER_PROF 1 0 0 #e3e6)
  59. '((0 . 0) (0 . 0))))
  60. (pass-if "reset to zero"
  61. (match (setitimer ITIMER_PROF 0 0 0 0)
  62. ((interval value)
  63. ;; We don't presume that the timer is strictly lower than the
  64. ;; value at which we set it, given its limited internal
  65. ;; precision. Assert instead that the timer is between 2 and
  66. ;; 3.5 seconds.
  67. (and (<= 0.9 (time-pair->secs interval) 1.1)
  68. (<= 2.0 (time-pair->secs value) 3.5)
  69. (match value
  70. ((secs . usecs)
  71. (<= 0 usecs 999999))))))))))