signals.test 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;;; signals.test --- test suite for Guile's signal functions -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2009, 2014, 2017 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. (if (not (provided? 'ITIMER_VIRTUAL))
  39. (throw 'unsupported)
  40. (equal? (setitimer ITIMER_VIRTUAL 0 0 0 0)
  41. '((0 . 0) (0 . 0)))))
  42. (pass-if "ITIMER_PROF"
  43. (if (not (provided? 'ITIMER_PROF))
  44. (throw 'unsupported)
  45. (equal? (setitimer ITIMER_PROF 0 0 0 0)
  46. '((0 . 0) (0 . 0))))))
  47. (with-test-prefix "setting values correctly"
  48. (pass-if "initial setting"
  49. (if (not (provided? 'ITIMER_PROF))
  50. (throw 'unsupported)
  51. (equal? (setitimer ITIMER_PROF 1 0 3 0)
  52. '((0 . 0) (0 . 0)))))
  53. (pass-if "reset to zero"
  54. (if (not (provided? 'ITIMER_PROF))
  55. (throw 'unsupported)
  56. (match (setitimer ITIMER_PROF 0 0 0 0)
  57. ((interval value)
  58. ;; We don't presume that the timer is strictly lower than the
  59. ;; value at which we set it, given its limited internal
  60. ;; precision. Assert instead that the timer is between 2 and
  61. ;; 3.5 seconds.
  62. (and (<= 0.9 (time-pair->secs interval) 1.1)
  63. (<= 2.0 (time-pair->secs value) 3.5)))))))
  64. (with-test-prefix "usecs > 1e6"
  65. (pass-if "initial setting"
  66. (if (not (provided? 'ITIMER_PROF))
  67. (throw 'unsupported)
  68. (equal? (setitimer ITIMER_PROF 1 0 0 #e3e6)
  69. '((0 . 0) (0 . 0)))))
  70. (pass-if "reset to zero"
  71. (if (not (provided? 'ITIMER_PROF))
  72. (throw 'unsupported)
  73. (match (setitimer ITIMER_PROF 0 0 0 0)
  74. ((interval value)
  75. ;; We don't presume that the timer is strictly lower than the
  76. ;; value at which we set it, given its limited internal
  77. ;; precision. Assert instead that the timer is between 2 and
  78. ;; 3.5 seconds.
  79. (and (<= 0.9 (time-pair->secs interval) 1.1)
  80. (<= 2.0 (time-pair->secs value) 3.5)
  81. (match value
  82. ((secs . usecs)
  83. (<= 0 usecs 999999)))))))))))