signals.test 3.9 KB

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