posix.test 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. ;;;; posix.test --- Test suite for Guile POSIX functions. -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2003, 2004, 2006, 2007, 2010 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 Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-suite test-posix)
  19. :use-module (test-suite lib))
  20. ;; FIXME: The following exec tests are disabled since on an i386 debian with
  21. ;; glibc 2.3.2 they seem to interact badly with threads.test, the latter
  22. ;; dies with signal 32 (one of the SIGRTs). Don't know how or why, or who's
  23. ;; at fault (though it seems to happen with or without the recent memory
  24. ;; leak fix in these error cases).
  25. ;;
  26. ;; execl
  27. ;;
  28. ;; (with-test-prefix "execl"
  29. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  30. ;; (execl "./nosuchprog" "./nosuchprog" "some arg")))
  31. ;;
  32. ;; execlp
  33. ;;
  34. ;; (with-test-prefix "execlp"
  35. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  36. ;; (execlp "./nosuchprog" "./nosuchprog" "some arg")))
  37. ;;
  38. ;; execle
  39. ;;
  40. ;; (with-test-prefix "execle"
  41. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  42. ;; (execle "./nosuchprog" '() "./nosuchprog" "some arg"))
  43. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  44. ;; (execle "./nosuchprog" '("FOO=1" "BAR=2") "./nosuchprog" "some arg")))
  45. ;;
  46. ;; mkstemp!
  47. ;;
  48. (with-test-prefix "mkstemp!"
  49. ;; the temporary names used in the tests here are kept to 8 characters so
  50. ;; they'll work on a DOS 8.3 file system
  51. (define (string-copy str)
  52. (list->string (string->list str)))
  53. (pass-if-exception "number arg" exception:wrong-type-arg
  54. (mkstemp! 123))
  55. (pass-if "filename string modified"
  56. (let* ((template "T-XXXXXX")
  57. (str (string-copy template))
  58. (port (mkstemp! str))
  59. (result (not (string=? str template))))
  60. (delete-file str)
  61. result)))
  62. ;;
  63. ;; putenv
  64. ;;
  65. (with-test-prefix "putenv"
  66. (pass-if "something"
  67. (putenv "FOO=something")
  68. (equal? "something" (getenv "FOO")))
  69. (pass-if "replacing"
  70. (putenv "FOO=one")
  71. (putenv "FOO=two")
  72. (equal? "two" (getenv "FOO")))
  73. (pass-if "empty"
  74. (putenv "FOO=")
  75. (equal? "" (getenv "FOO")))
  76. (pass-if "removing"
  77. (putenv "FOO=bar")
  78. (putenv "FOO")
  79. (not (getenv "FOO")))
  80. (pass-if "modifying string doesn't change env"
  81. (let ((s (string-copy "FOO=bar")))
  82. (putenv s)
  83. (string-set! s 5 #\x)
  84. (equal? "bar" (getenv "FOO")))))
  85. ;;
  86. ;; setenv
  87. ;;
  88. (with-test-prefix "setenv"
  89. (pass-if "something"
  90. (setenv "FOO" "something")
  91. (equal? "something" (getenv "FOO")))
  92. (pass-if "replacing"
  93. (setenv "FOO" "one")
  94. (setenv "FOO" "two")
  95. (equal? "two" (getenv "FOO")))
  96. (pass-if "empty"
  97. (setenv "FOO" "")
  98. (equal? "" (getenv "FOO")))
  99. (pass-if "removing"
  100. (setenv "FOO" "something")
  101. (setenv "FOO" #f)
  102. (not (getenv "FOO"))))
  103. ;;
  104. ;; unsetenv
  105. ;;
  106. (with-test-prefix "unsetenv"
  107. (pass-if "something"
  108. (putenv "FOO=something")
  109. (unsetenv "FOO")
  110. (not (getenv "FOO")))
  111. (pass-if "empty"
  112. (putenv "FOO=")
  113. (unsetenv "FOO")
  114. (not (getenv "FOO"))))
  115. ;;
  116. ;; ttyname
  117. ;;
  118. (with-test-prefix "ttyname"
  119. (pass-if-exception "non-tty argument" exception:system-error
  120. ;; This used to crash in 1.8.1 and earlier.
  121. (let ((file (false-if-exception
  122. (open-output-file "/dev/null"))))
  123. (if (not file)
  124. (throw 'unsupported)
  125. (ttyname file)))))
  126. ;;
  127. ;; utimes
  128. ;;
  129. (with-test-prefix "utime"
  130. (pass-if "valid argument (second resolution)"
  131. (let ((file "posix.test-utime"))
  132. (dynamic-wind
  133. (lambda ()
  134. (close-port (open-output-file file)))
  135. (lambda ()
  136. (let* ((accessed (+ (current-time) 3600))
  137. (modified (- accessed 1000)))
  138. (utime file accessed modified)
  139. (let ((info (stat file)))
  140. (and (= (stat:atime info) accessed)
  141. (= (stat:mtime info) modified)))))
  142. (lambda ()
  143. (delete-file file))))))
  144. ;;
  145. ;; affinity
  146. ;;
  147. (with-test-prefix "affinity"
  148. (pass-if "getaffinity"
  149. (if (defined? 'getaffinity)
  150. (> (bitvector-length (getaffinity (getpid))) 0)
  151. (throw 'unresolved)))
  152. (pass-if "setaffinity"
  153. (if (and (defined? 'setaffinity) (defined? 'getaffinity))
  154. (let ((mask (getaffinity (getpid))))
  155. (setaffinity (getpid) mask)
  156. (equal? mask (getaffinity (getpid))))
  157. (throw 'unresolved))))