posix.test 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ;;;; posix.test --- Test suite for Guile POSIX functions. -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2003, 2004, 2006, 2007, 2010, 2012 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. (close-port port)
  61. (delete-file str)
  62. result)))
  63. ;;
  64. ;; putenv
  65. ;;
  66. (with-test-prefix "putenv"
  67. (pass-if "something"
  68. (putenv "FOO=something")
  69. (equal? "something" (getenv "FOO")))
  70. (pass-if "replacing"
  71. (putenv "FOO=one")
  72. (putenv "FOO=two")
  73. (equal? "two" (getenv "FOO")))
  74. (pass-if "empty"
  75. (putenv "FOO=")
  76. (equal? "" (getenv "FOO")))
  77. (pass-if "removing"
  78. (putenv "FOO=bar")
  79. (putenv "FOO")
  80. (not (getenv "FOO")))
  81. (pass-if "modifying string doesn't change env"
  82. (let ((s (string-copy "FOO=bar")))
  83. (putenv s)
  84. (string-set! s 5 #\x)
  85. (equal? "bar" (getenv "FOO")))))
  86. ;;
  87. ;; setenv
  88. ;;
  89. (with-test-prefix "setenv"
  90. (pass-if "something"
  91. (setenv "FOO" "something")
  92. (equal? "something" (getenv "FOO")))
  93. (pass-if "replacing"
  94. (setenv "FOO" "one")
  95. (setenv "FOO" "two")
  96. (equal? "two" (getenv "FOO")))
  97. (pass-if "empty"
  98. (setenv "FOO" "")
  99. (equal? "" (getenv "FOO")))
  100. (pass-if "removing"
  101. (setenv "FOO" "something")
  102. (setenv "FOO" #f)
  103. (not (getenv "FOO"))))
  104. ;;
  105. ;; unsetenv
  106. ;;
  107. (with-test-prefix "unsetenv"
  108. (pass-if "something"
  109. (putenv "FOO=something")
  110. (unsetenv "FOO")
  111. (not (getenv "FOO")))
  112. (pass-if "empty"
  113. (putenv "FOO=")
  114. (unsetenv "FOO")
  115. (not (getenv "FOO"))))
  116. ;;
  117. ;; ttyname
  118. ;;
  119. (with-test-prefix "ttyname"
  120. (pass-if-exception "non-tty argument" exception:system-error
  121. ;; This used to crash in 1.8.1 and earlier.
  122. (let ((file (false-if-exception
  123. (open-output-file "/dev/null"))))
  124. (if (not file)
  125. (throw 'unsupported)
  126. (ttyname file)))))
  127. ;;
  128. ;; utimes
  129. ;;
  130. (with-test-prefix "utime"
  131. (pass-if "valid argument (second resolution)"
  132. (let ((file "posix.test-utime"))
  133. (dynamic-wind
  134. (lambda ()
  135. (close-port (open-output-file file)))
  136. (lambda ()
  137. (let* ((accessed (+ (current-time) 3600))
  138. (modified (- accessed 1000)))
  139. (utime file accessed modified)
  140. (let ((info (stat file)))
  141. (and (= (stat:atime info) accessed)
  142. (= (stat:mtime info) modified)))))
  143. (lambda ()
  144. (delete-file file))))))
  145. ;;
  146. ;; affinity
  147. ;;
  148. (with-test-prefix "affinity"
  149. (pass-if "getaffinity"
  150. (if (defined? 'getaffinity)
  151. (> (bitvector-length (getaffinity (getpid))) 0)
  152. (throw 'unresolved)))
  153. (pass-if "setaffinity"
  154. (if (and (defined? 'setaffinity) (defined? 'getaffinity))
  155. (let ((mask (getaffinity (getpid))))
  156. (setaffinity (getpid) mask)
  157. (equal? mask (getaffinity (getpid))))
  158. (throw 'unresolved))))
  159. ;;
  160. ;; system*
  161. ;;
  162. (with-test-prefix "system*"
  163. (pass-if "http://bugs.gnu.org/13166"
  164. ;; With Guile up to 2.0.7 included, the child process launched by
  165. ;; `system*' would remain alive after an `execvp' failure.
  166. (let ((me (getpid)))
  167. (and (not (zero? (system* "something-that-does-not-exist")))
  168. (= me (getpid))))))